Skip to content

Commit

Permalink
[2.3] papd: Use cupsGetOptions() to get printer URI
Browse files Browse the repository at this point in the history
Use cupsGetOptions() to get the printer URI from CUPS instead of hard coding it.
  • Loading branch information
NJRoadfan committed Jan 14, 2024
1 parent 15f7c66 commit be28439
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions etc/papd/print_cups.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include "print_cups.h"

#define MAXCHOOSERLEN 31
#define HTTP_MAX_URI 1024

static const char* cups_status_msg[] = {
"status: busy; info: \"%s\" is rejecting jobs; ",
Expand Down Expand Up @@ -97,7 +96,6 @@ cups_printername_ok(char *name) /* I - Name of printer */
cups_dest_t *dest = NULL; /* Destination */
ipp_t *request, /* IPP Request */
*response; /* IPP Response */
char uri[HTTP_MAX_URI]; /* printer-uri attribute */

/*
* Make sure we don't ask for passwords...
Expand All @@ -123,7 +121,7 @@ cups_printername_ok(char *name) /* I - Name of printer */
"Unable to connect to destination \"%s\": %s", dest->name, cupsLastErrorString());
return (0);
}
cupsFreeDests(1, dest);


/*
* Build an IPP_GET_PRINTER_ATTRS request, which requires the following
Expand All @@ -139,7 +137,7 @@ cups_printername_ok(char *name) /* I - Name of printer */
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
"requested-attributes", NULL, "printer-uri");

sprintf(uri, "ipp://localhost/printers/%s", name);
const char *uri = cupsGetOption("printer-uri-supported", dest->num_options, dest->options);

ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
"printer-uri", NULL, uri);
Expand All @@ -152,10 +150,11 @@ cups_printername_ok(char *name) /* I - Name of printer */
{
LOG(log_error, logtype_papd, "Unable to get printer status for %s - %s", name,
ippErrorString(cupsLastError()));
cupsFreeDests(1, dest);
httpClose(http);
return (0);
}

cupsFreeDests(1, dest);
httpClose(http);

if (cupsLastError() >= IPP_STATUS_OK_CONFLICTING)
Expand All @@ -182,7 +181,6 @@ cups_get_printer_ppd ( char * name)
cups_dest_t *dests; /* Destination List */
ipp_t *request, /* IPP Request */
*response; /* IPP Response */
char uri[HTTP_MAX_URI]; /* printer-uri attribute */
const char *pattrs[] = /* Requested printer attributes */
{
"printer-make-and-model",
Expand Down Expand Up @@ -226,7 +224,7 @@ cups_get_printer_ppd ( char * name)
* Generate the printer URI...
*/

sprintf(uri, "ipp://localhost/printers/%s", name);
const char *uri = cupsGetOption("printer-uri-supported", dest->num_options, dest->options);

/*
* Build an IPP_OP_GET_PRINTER_ATTRIBUTES request, which requires the
Expand Down Expand Up @@ -373,7 +371,6 @@ cups_get_printer_status (struct printer *pr)
ipp_t *request, /* IPP Request */
*response; /* IPP Response */
ipp_attribute_t *attr; /* Current attribute */
char uri[HTTP_MAX_URI]; /* printer-uri attribute */
int status = -1;

static const char *pattrs[] = /* Requested printer attributes */
Expand All @@ -394,7 +391,6 @@ cups_get_printer_status (struct printer *pr)
*/

dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, pr->p_printer, NULL);

if (!dest)
{
LOG(log_error, logtype_papd,
Expand All @@ -407,13 +403,12 @@ cups_get_printer_status (struct printer *pr)
"Unable to connect to destination \"%s\": %s", dest->name, cupsLastErrorString());
return (0);
}
cupsFreeDests(1, dest);

/*
* Generate the printer URI...
*/

sprintf(uri, "ipp://localhost/printers/%s", pr->p_printer);
const char *uri = cupsGetOption("printer-uri-supported", dest->num_options, dest->options);



Expand Down Expand Up @@ -445,6 +440,7 @@ cups_get_printer_status (struct printer *pr)
{
LOG(log_error, logtype_papd, "Unable to get printer status for %s - %s", pr->p_printer,
ippErrorString(cupsLastError()));
cupsFreeDests(1, dest);
httpClose(http);
return (0);
}
Expand All @@ -454,6 +450,7 @@ cups_get_printer_status (struct printer *pr)
LOG(log_error, logtype_papd, "Unable to get printer status for %s - %s", pr->p_printer,
ippErrorString(cupsLastError()));
ippDelete(response);
cupsFreeDests(1, dest);
httpClose(http);
return (0);
}
Expand Down Expand Up @@ -490,7 +487,7 @@ cups_get_printer_status (struct printer *pr)
/*
* Return the print status ...
*/

cupsFreeDests(1, dest);
httpClose(http);

return (status);
Expand Down

0 comments on commit be28439

Please sign in to comment.