Skip to content

Commit

Permalink
cfGetPrinterAttributes(): Poll "media-col-database" separately if needed
Browse files Browse the repository at this point in the history
To get the full set of printer properties from a driverless IPP
printer one does a "get-printer-attributes" IPP request with the
attribute "requested-attributes" set to "all,media-col-database" (note
that "all" does not include "media-col-database" because this
attribute is often very long, it contains all valid combinations of
media size, media type, media source, and margins). For some printers
this fails and we fall back to just "all" and lose valuable
information.

But some of those printers which do not support "requested-attributes"
set to "all,media-col-database" support "requested-attributes" set to
"media-col-database" alone and this we now make use of, by polling
"media-col-database" separately and adding it to the IPP response of
"all" if needed.

We discovered such a printer here:

    #492

Backported from libcupsfilters (2.x), commit 789cca62da
  • Loading branch information
tillkamppeter committed Jan 12, 2023
1 parent 7086599 commit 54608f9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cupsfilters/ipp.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,38 @@ get_printer_attributes5(http_t *http_printer,
ippDelete(response);
} else {
/* Suitable response, we are done */
// if we did not succeed to obtain the "media-col-database" attribute
// try to get it separately
if (cap &&
ippFindAttribute(response, "media-col-database", IPP_TAG_ZERO) ==
NULL)
{
ipp_t *response2 = NULL;

log_printf(get_printer_attributes_log,
"Polling \"media-col-database\" attribute separately.\n");
request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
ippSetVersion(request, 2, 0);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
"printer-uri", NULL, uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
"requested-attributes", NULL, "media-col-database");
response2 = cupsDoRequest(http_printer, request, resource);
ipp_status = cupsLastError();
if (response2)
{
if ((attr = ippFindAttribute(response2, "media-col-database",
IPP_TAG_ZERO)) != NULL)
{
// Copy "media-col-database" attribute into the original
// IPP response
log_printf(get_printer_attributes_log,
"\"media-col-database\" attribute found.\n");
ippCopyAttribute(response, attr, 0);
}
ippDelete(response2);
}
}
if (have_http == 0) httpClose(http_printer);
if (uri) free(uri);
return response;
Expand Down

0 comments on commit 54608f9

Please sign in to comment.