]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix cupsCopyDestInfo device connection detection (Issue #586)
authorMichael R Sweet <msweet@msweet.org>
Fri, 5 Apr 2024 16:54:18 +0000 (12:54 -0400)
committerMichael R Sweet <msweet@msweet.org>
Fri, 5 Apr 2024 16:54:18 +0000 (12:54 -0400)
CHANGES.md
cups/dest-options.c

index c3dd08ec9c9f405380284169003a7a622672d139..e69ee8ac18e6fa7a7396e65c43dd31bba5eb5432 100644 (file)
@@ -18,6 +18,7 @@ Changes in CUPS v2.4.8 (TBA)
 - Fixed printing of jobs with job name longer than 255 chars on older printers
   (Issue #644)
 - Really backported fix for Issue #742
+- Fixed `cupsCopyDestInfo` device connection detection (Issue #586)
 - Fixed "Upgrade" header handling when there is no TLS support (Issue #775)
 - Fixed memory leak when unloading a job (Issue #813)
 - Fixed memory leak when creating color profiles (Issue #815)
index be0be72e556f3dd67809cdf48fa228ec7b7ea8e3..d89dbc81d08e6929eccf9b116676ccbd39149941 100644 (file)
@@ -685,7 +685,7 @@ cupsCopyDestInfo(
                delay,                  /* Current retry delay */
                prev_delay;             /* Next retry delay */
   const char   *uri;                   /* Printer URI */
-  char         resource[1024];         /* Resource path */
+  char         resource[1024];         /* URI resource path */
   int          version;                /* IPP version */
   ipp_status_t status;                 /* Status of request */
   _cups_globals_t *cg = _cupsGlobals();        /* Pointer to library globals */
@@ -699,6 +699,13 @@ cupsCopyDestInfo(
 
   DEBUG_printf(("cupsCopyDestInfo(http=%p, dest=%p(%s))", (void *)http, (void *)dest, dest ? dest->name : ""));
 
+ /*
+  * Range check input...
+  */
+
+  if (!dest)
+    return (NULL);
+
  /*
   * Get the default connection as needed...
   */
@@ -708,6 +715,9 @@ cupsCopyDestInfo(
     DEBUG_puts("1cupsCopyDestInfo: Default server connection.");
     http   = _cupsConnect();
     dflags = CUPS_DEST_FLAGS_NONE;
+
+    if (!http)
+      return (NULL);
   }
 #ifdef AF_LOCAL
   else if (httpAddrFamily(http->hostaddr) == AF_LOCAL)
@@ -716,23 +726,31 @@ cupsCopyDestInfo(
     dflags = CUPS_DEST_FLAGS_NONE;
   }
 #endif /* AF_LOCAL */
-  else if ((strcmp(http->hostname, cg->server) && cg->server[0] != '/') || cg->ipp_port != httpAddrPort(http->hostaddr))
-  {
-    DEBUG_printf(("1cupsCopyDestInfo: Connection to device (%s).", http->hostname));
-    dflags = CUPS_DEST_FLAGS_DEVICE;
-  }
   else
   {
-    DEBUG_printf(("1cupsCopyDestInfo: Connection to server (%s).", http->hostname));
-    dflags = CUPS_DEST_FLAGS_NONE;
-  }
+    // Guess the destination flags based on the printer URI's host and port...
+    char       scheme[32],             /* URI scheme */
+               userpass[256],          /* URI username:password */
+               host[256];              /* URI host */
+    int                port;                   /* URI port */
 
- /*
-  * Range check input...
-  */
+    if ((uri = cupsGetOption("printer-uri-supported", dest->num_options, dest->options)) == NULL || httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme), userpass, sizeof(userpass), host, sizeof(host), &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK)
+    {
+      strlcpy(host, "localhost", sizeof(host));
+      port = cg->ipp_port;
+    }
 
-  if (!http || !dest)
-    return (NULL);
+    if (strcmp(http->hostname, host) || port != httpAddrPort(http->hostaddr))
+    {
+      DEBUG_printf(("1cupsCopyDestInfo: Connection to device (%s).", http->hostname));
+      dflags = CUPS_DEST_FLAGS_DEVICE;
+    }
+    else
+    {
+      DEBUG_printf(("1cupsCopyDestInfo: Connection to server (%s).", http->hostname));
+      dflags = CUPS_DEST_FLAGS_NONE;
+    }
+  }
 
  /*
   * Get the printer URI and resource path...