From: Michael R Sweet Date: Fri, 5 Apr 2024 16:54:18 +0000 (-0400) Subject: Fix cupsCopyDestInfo device connection detection (Issue #586) X-Git-Tag: v2.4.8~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d5deb744e6061cd276fba44afc7aa4458c6a5e5;p=thirdparty%2Fcups.git Fix cupsCopyDestInfo device connection detection (Issue #586) --- diff --git a/CHANGES.md b/CHANGES.md index c3dd08ec9c..e69ee8ac18 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/cups/dest-options.c b/cups/dest-options.c index be0be72e55..d89dbc81d0 100644 --- a/cups/dest-options.c +++ b/cups/dest-options.c @@ -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...