diff --git a/CHANGES.md b/CHANGES.md index 2309154bc..781a8a241 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -65,6 +65,8 @@ Changes in CUPS v2.3.5 - Fixed duplicate ColorModel entries for AirPrint printers (Issue 59) - Fixed crash bug in `ppdOpen` (OpenPrinting #64, OpenPrinting #78) - Fixed regression in `snprintf` emulation function (OpenPrinting #67) +- Fixed reporting of printer instances when enumerating and when no options are + set for the main instance (OpenPrinting #71) - Fixed segfault in help.cgi when searching in man pages (OpenPrinting #81) - Fixed a bug in ipptool that caused the reuse of request IDs when repeating a test (OpenPrinting #153) diff --git a/cups/dest.c b/cups/dest.c index 4d0c25032..984c6bddf 100644 --- a/cups/dest.c +++ b/cups/dest.c @@ -271,7 +271,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); @@ -3379,7 +3383,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 */ @@ -3524,17 +3528,31 @@ cups_enum_dests( const char *device_uri; /* Device URI */ #endif /* HAVE_DNSSD || HAVE_AVAHI */ - 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; #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) @@ -3797,25 +3815,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; @@ -4186,7 +4224,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; } }