]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
scheduler/ipp.c: Polish mDNS resolving
authorZdenek Dohnal <zdohnal@redhat.com>
Fri, 4 Mar 2022 07:23:22 +0000 (08:23 +0100)
committerZdenek Dohnal <zdohnal@redhat.com>
Fri, 4 Mar 2022 07:23:22 +0000 (08:23 +0100)
- no need to include http-private.h, cupsd.h has cups-private.h, which
  includes http-private.h
- call _httpResolve() only for mDNS hostnames and then pass the pointer
  to original printer->device_uri instead of copying
- add logging messages

scheduler/ipp.c

index 35d2a06aed679f2bb8decd0f9f2f64bf62e77a14..14cadb02a741fb3e6d5f158df1f606d5d0ec6608 100644 (file)
@@ -17,7 +17,6 @@
  */
 
 #include "cupsd.h"
-#include <cups/http-private.h>
 #include <cups/ppd-private.h>
 
 #ifdef __APPLE__
@@ -5272,7 +5271,7 @@ create_local_bg_thread(
                userpass[256],          /* User:pass */
                host[256],              /* Hostname */
                resource[1024],         /* Resource path */
-               uri[1024],              /* Resolved URI, unused */
+               uri[1024],              /* Resolved URI, if needed */
                line[1024];             /* Line from PPD */
   int          port;                   /* Port number */
   http_encryption_t encryption;                /* Type of encryption to use */
@@ -5294,7 +5293,21 @@ create_local_bg_thread(
 
   cupsdLogMessage(CUPSD_LOG_DEBUG, "%s: Generating PPD file from \"%s\"...", printer->name, printer->device_uri);
 
-  if (httpSeparateURI(HTTP_URI_CODING_ALL, _httpResolveURI(printer->device_uri, uri, sizeof(uri), _HTTP_RESOLVE_DEFAULT, NULL, NULL), scheme, sizeof(scheme), userpass, sizeof(userpass), host, sizeof(host), &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK)
+
+  if (strstr(printer->device_uri, "._tcp"))
+  {
+    cupsdLogMessage(CUPSD_LOG_DEBUG2, "%s: Resolving mDNS URI \"%s\".", printer->name, printer->device_uri);
+
+    if (!_httpResolveURI(printer->device_uri, uri, sizeof(uri), _HTTP_RESOLVE_DEFAULT, NULL, NULL))
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR, "%s: Couldn't resolve mDNS URI \"%s\".", printer->name, printer->device_uri);
+      return (NULL);
+    }
+
+    printer->device_uri = uri;
+  }
+
+  if (httpSeparateURI(HTTP_URI_CODING_ALL, printer->device_uri, scheme, sizeof(scheme), userpass, sizeof(userpass), host, sizeof(host), &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK)
   {
     cupsdLogMessage(CUPSD_LOG_ERROR, "%s: Bad device URI \"%s\".", printer->name, printer->device_uri);
     return (NULL);