]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix printer instances (Issue #71)
authorMichael R Sweet <michael.r.sweet@gmail.com>
Mon, 3 May 2021 12:34:51 +0000 (08:34 -0400)
committerMichael R Sweet <michael.r.sweet@gmail.com>
Mon, 3 May 2021 12:34:51 +0000 (08:34 -0400)
CHANGES.md
cups/dest.c

index a0e12d67fcb8ee62208bff15f57b6681eadbe6dd..9a1a07078c741e18c559e7b2e273f925529001da 100644 (file)
@@ -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)
index c1746da9c43110a643f888154ff9172d123d7e03..50dcc0e567b32656c3ea1fc8f659aaf72b2a09d9 100644 (file)
@@ -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;
       }
     }