From: Michael R Sweet Date: Mon, 3 May 2021 12:34:51 +0000 (-0400) Subject: Fix printer instances (Issue #71) X-Git-Tag: v2.4b1~124 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b53ad5bf3e78e852bac68f82db0d03b479e68026;p=thirdparty%2Fcups.git Fix printer instances (Issue #71) --- diff --git a/CHANGES.md b/CHANGES.md index a0e12d67fc..9a1a07078c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,8 @@ CUPS v2.4rc1 (Pending) be found. - Fixed Kerberos authentication for the web interface (Issue #19) - The ZPL sample driver now supports more "standard" label sizes (Issue #70) +- Fixed reporting of printer instances when enumerating and when no options are + set for the main instance (Issue #71) - Reverted USB read limit enforcement change from CUPS 2.2.12 (Issue #72) - The IPP backend did not return the correct status code when a job was canceled at the printer/server (Issue #74) diff --git a/cups/dest.c b/cups/dest.c index c1746da9c4..50dcc0e567 100644 --- a/cups/dest.c +++ b/cups/dest.c @@ -272,7 +272,11 @@ cupsAddDest(const char *name, /* I - Destination name */ if (!cupsGetDest(name, instance, num_dests, *dests)) { if (instance && !cupsGetDest(name, NULL, num_dests, *dests)) - return (num_dests); + { + // Add destination first... + if ((dest = cups_add_dest(name, NULL, &num_dests, dests)) == NULL) + return (num_dests); + } if ((dest = cups_add_dest(name, instance, &num_dests, dests)) == NULL) return (num_dests); @@ -3378,7 +3382,7 @@ cups_enum_dests( cups_dest_cb_t cb, /* I - Callback function */ void *user_data) /* I - User data */ { - int i, j, /* Looping vars */ + int i, j, k, /* Looping vars */ num_dests; /* Number of destinations */ cups_dest_t *dests = NULL, /* Destinations */ *dest; /* Current destination */ @@ -3523,17 +3527,31 @@ cups_enum_dests( const char *device_uri; /* Device URI */ #endif /* HAVE_DNSSD */ - if ((user_dest = cupsGetDest(dest->name, dest->instance, data.num_dests, data.dests)) != NULL) + if ((user_dest = cupsGetDest(dest->name, NULL, data.num_dests, data.dests)) != NULL) { /* - * Apply user defaults to this destination... + * Apply user defaults to this destination for all instances... */ - for (j = user_dest->num_options, option = user_dest->options; j > 0; j --, option ++) - dest->num_options = cupsAddOption(option->name, option->value, dest->num_options, &dest->options); - } + for (j = user_dest - data.dests; j < data.num_dests; j ++, user_dest ++) + { + if (_cups_strcasecmp(user_dest->name, dest->name)) + { + j = data.num_dests; + break; + } - if (!(*cb)(user_data, i > 1 ? CUPS_DEST_FLAGS_MORE : CUPS_DEST_FLAGS_NONE, dest)) + for (k = dest->num_options, option = dest->options; k > 0; k --, option ++) + user_dest->num_options = cupsAddOption(option->name, option->value, user_dest->num_options, &user_dest->options); + + if (!(*cb)(user_data, i > 1 ? CUPS_DEST_FLAGS_MORE : CUPS_DEST_FLAGS_NONE, user_dest)) + break; + } + + if (j < data.num_dests) + break; + } + else if (!(*cb)(user_data, i > 1 ? CUPS_DEST_FLAGS_MORE : CUPS_DEST_FLAGS_NONE, dest)) break; #ifdef HAVE_DNSSD @@ -3796,25 +3814,45 @@ cups_enum_dests( if ((user_dest = cupsGetDest(dest->name, dest->instance, data.num_dests, data.dests)) != NULL) { /* - * Apply user defaults to this destination... + * Apply user defaults to this destination for all instances... */ - for (j = user_dest->num_options, option = user_dest->options; j > 0; j --, option ++) - dest->num_options = cupsAddOption(option->name, option->value, dest->num_options, &dest->options); - } + for (j = user_dest - data.dests; j < data.num_dests; j ++, user_dest ++) + { + if (_cups_strcasecmp(user_dest->name, dest->name)) + { + j = data.num_dests; + break; + } - if (!strcasecmp(dest->name, data.def_name) && !data.def_instance) - { - DEBUG_printf(("1cups_enum_dests: Setting is_default on discovered \"%s\".", dest->name)); - dest->is_default = 1; + for (k = dest->num_options, option = dest->options; k > 0; k --, option ++) + user_dest->num_options = cupsAddOption(option->name, option->value, user_dest->num_options, &user_dest->options); + + if (!(*cb)(user_data, CUPS_DEST_FLAGS_NONE, user_dest)) + break; + } + + if (j < data.num_dests) + { + remaining = -1; + break; + } } + else + { + if (!strcasecmp(dest->name, data.def_name) && !data.def_instance) + { + DEBUG_printf(("1cups_enum_dests: Setting is_default on discovered \"%s\".", dest->name)); + dest->is_default = 1; + } - DEBUG_printf(("1cups_enum_dests: Add callback for \"%s\".", device->dest.name)); - if (!(*cb)(user_data, CUPS_DEST_FLAGS_NONE, dest)) - { - remaining = -1; - break; - } + DEBUG_printf(("1cups_enum_dests: Add callback for \"%s\".", device->dest.name)); + if (!(*cb)(user_data, CUPS_DEST_FLAGS_NONE, dest)) + { + remaining = -1; + break; + } + } } device->state = _CUPS_DNSSD_ACTIVE; @@ -4185,7 +4223,7 @@ cups_get_dests( * Out of memory! */ - DEBUG_puts("9cups_get_dests: Out of memory!"); + DEBUG_puts("9cups_get_dests: Could not find destination after adding, must be out of memory."); break; } }