From 90c67342b60cf53b05e337376465841e7e7cd6a6 Mon Sep 17 00:00:00 2001 From: Michael Sweet Date: Tue, 20 Jun 2017 13:08:15 -0400 Subject: [PATCH] Add CUPS_DEST_FLAGS_DEVICE flag for cupsConnectDest. --- CHANGES.md | 14 +++++++++----- cups/cups.h | 2 ++ cups/dest.c | 25 ++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5d950f477..ad51b0deb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,12 +9,12 @@ CHANGES IN CUPS V2.2.4 (Issue #4989) - The CUPS build system now supports cross-compilation (Issue #4897) - Added a new CUPS Programming Manual to replace the aging API documentation. -- Added the cupsAddIntegerOption and cupsGetIntegerOption functions +- Added the `cupsAddIntegerOption` and `cupsGetIntegerOption` functions (Issue #4992) -- The cupsGetDests and cupsCreateJob functions now support Bonjour printers +- The `cupsGetDests` and `cupsCreateJob` functions now support Bonjour printers (Issue #4993) - Added a USB quirk rule for Lexmark E260dn printers (Issue #4994) -- Fixed a potential buffer overflow in the cupstestppd utility (Issue #4996) +- Fixed a potential buffer overflow in the `cupstestppd` utility (Issue #4996) - IPP Everywhere improvements (Issue #4998) - Fixed the "cancel all jobs" function in the web interface for several languages (Issue #4999) @@ -26,11 +26,15 @@ CHANGES IN CUPS V2.2.4 haven't yet been added (Issue #5006) - Fixed a typo in the mime.types file. - Fixed a bug in the Spanish web interface template (Issue #5016) -- The cupsEnumDests* and cupsGetDest* functions now report the value of the +- The `cupsEnumDests*` and `cupsGetDest*` functions now report the value of the "printer-is-temporary" Printer Status attribute (Issue #5028) - Added Chinese localization (Issue #5029) -- The cupsCheckDestSupported function did not support NULL values (Issue #5031) +- The `cupsCheckDestSupported` function did not support `NULL` values + (Issue #5031) - Fixed some issues in the RPM spec file (Issue #5032) +- The `cupsConnectDest` function now supports the `CUPS_DEST_FLAGS_DEVICE` flag + for explicitly connecting to the device (printer) associated with the + destination. CHANGES IN CUPS V2.2.3 diff --git a/cups/cups.h b/cups/cups.h index ce299da70..a73cf7aeb 100644 --- a/cups/cups.h +++ b/cups/cups.h @@ -92,6 +92,8 @@ extern "C" { /* A connection is being established */ # define CUPS_DEST_FLAGS_CANCELED 0x40 /* Operation was canceled */ +# define CUPS_DEST_FLAGS_DEVICE 0x80 + /* For @link cupsConnectDest@: Connect to device */ /* Flags for cupsGetDestMediaByName/Size */ # define CUPS_MEDIA_FLAGS_DEFAULT 0x00 diff --git a/cups/dest.c b/cups/dest.c index 3ff285d8c..5cc5c3d94 100644 --- a/cups/dest.c +++ b/cups/dest.c @@ -579,6 +579,11 @@ _cupsAppleSetUseLastPrinter( * returns 0. The caller is responsible for calling @link httpClose@ on the * returned connection. * + * Starting with CUPS 2.2.4, the caller can pass @code CUPS_DEST_FLAGS_DEVICE@ + * for the "flags" argument to connect directly to the device associated with + * the destination. Otherwise, the connection is made to the CUPS scheduler + * associated with the destination. + * * @since CUPS 1.6/macOS 10.8@ */ @@ -630,7 +635,20 @@ cupsConnectDest( * Grab the printer URI... */ - if ((uri = cupsGetOption("printer-uri-supported", dest->num_options, dest->options)) == NULL) + if (flags & CUPS_DEST_FLAGS_DEVICE) + { + if ((uri = cupsGetOption("resolved-device-uri", dest->num_options, dest->options)) == NULL) + { + if ((uri = cupsGetOption("device-uri", dest->num_options, dest->options)) != NULL) + { +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) + if (strstr(uri, "._tcp")) + uri = cups_dnssd_resolve(dest, uri, msec, cancel, cb, user_data); +#endif /* HAVE_DNSSD || HAVE_AVAHI */ + } + } + } + else if ((uri = cupsGetOption("printer-uri-supported", dest->num_options, dest->options)) == NULL) { if ((uri = cupsGetOption("resolved-device-uri", dest->num_options, dest->options)) == NULL) { @@ -755,6 +773,11 @@ cupsConnectDest( * pointed to by "cancel" is non-zero, or the block returns 0. The caller is * responsible for calling @link httpClose@ on the returned connection. * + * Starting with CUPS 2.2.4, the caller can pass @code CUPS_DEST_FLAGS_DEVICE@ + * for the "flags" argument to connect directly to the device associated with + * the destination. Otherwise, the connection is made to the CUPS scheduler + * associated with the destination. + * * @since CUPS 1.6/macOS 10.8@ @exclude all@ */ -- 2.39.5