]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
PPD for driverless IPP: Poll "media-col-database" separately if needed
authorTill Kamppeter <till.kamppeter@gmail.com>
Sun, 22 Jan 2023 00:28:02 +0000 (21:28 -0300)
committerTill Kamppeter <till.kamppeter@gmail.com>
Sun, 22 Jan 2023 00:28:02 +0000 (21:28 -0300)
In the create_local_bg_thread() function for auto-generating a PPD
file for a CUPS queue for a driverless printer, either via the
"everywhere" model selection or an auto-created temporary queue we
need to query the full capabilities information from the printer.

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

scheduler/ipp.c

index c6df281a92249517e886bf4294268908b735bed5..f048a000ee5e058c6503000e5aeef56e65850117 100644 (file)
@@ -5385,6 +5385,43 @@ create_local_bg_thread(
     cupsdLogMessage(CUPSD_LOG_DEBUG, "%s: IPP/1.1 Get-Printer-Attributes returned %s (%s)", printer->name, ippErrorString(cupsLastError()), cupsLastErrorString());
   }
 
+ /*
+  * If we did not succeed to obtain the "media-col-database" attribute
+  * try to get it separately
+  */
+  if (ippFindAttribute(response, "media-col-database", IPP_TAG_ZERO) ==
+      NULL)
+  {
+    ipp_t *response2 = NULL;
+
+    cupsdLogMessage(CUPSD_LOG_DEBUG,
+                   "Polling \"media-col-database\" attribute separately.");
+    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, 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
+       */
+
+       cupsdLogMessage(CUPSD_LOG_DEBUG,
+                       "\"media-col-database\" attribute found.");
+       ippCopyAttribute(response, attr, 0);
+      }
+      ippDelete(response2);
+    }
+  }
+
   // TODO: Grab printer icon file...
   httpClose(http);