]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
cfGetPrinterAttributes(): Poll "media-col-database" separately if needed
authorTill Kamppeter <till.kamppeter@gmail.com>
Thu, 12 Jan 2023 04:17:01 +0000 (01:17 -0300)
committerTill Kamppeter <till.kamppeter@gmail.com>
Thu, 12 Jan 2023 04:17:01 +0000 (01:17 -0300)
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:

    https://github.com/OpenPrinting/cups-filters/issues/492

Backported from libcupsfilters (2.x), commit 789cca62da

cupsfilters/ipp.c

index d7033272d27dcc1a1c58a2dd594afb0c091816da..5c53704a32463f70b6c0ce3abbeb589b4a978c53 100644 (file)
@@ -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;