]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Use the device serial number if the 1284 serial number is empty (Issue #170)
authorMichael R Sweet <michael.r.sweet@gmail.com>
Thu, 15 Apr 2021 20:06:01 +0000 (16:06 -0400)
committerMichael R Sweet <michael.r.sweet@gmail.com>
Thu, 15 Apr 2021 20:06:01 +0000 (16:06 -0400)
CHANGES.md
backend/usb-libusb.c

index d8abcd4c48ca4395dc5e56aeba32956217b8fb70..63f6b668618042a4a4b5ca5592b984ffa26e1088 100644 (file)
@@ -36,6 +36,7 @@ CUPS v2.4rc1 (Pending)
 - The IPP backend now retries Validate-Job requests (Issue #132)
 - Reverted USB read limit enforcement change from CUPS 2.2.12 (Issue #72)
 - Now use a 60 second timeout for reading USB backchannel data (Issue #160)
+- The USB backend now tries harder to find a serial number (Issue #170)
 - Documentation fixes (Issue #92, Issue #163)
 - Localization updates (Issue #123, Issue #129, Issue #134, Issue #146,
   Issue #164)
index 89b5182f701fffd2449bd206389f3890000da005..0f81f0b23faa7f7e2ac53f3da1bf5ce6a7ea42a7 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * LIBUSB interface code for CUPS.
  *
- * Copyright 2007-2019 by Apple Inc.
+ * Copyright © 2021 by OpenPrinting.
+ * Copyright © 2007-2019 by Apple Inc.
  *
  * Licensed under Apache License v2.0.  See the file "LICENSE" for more
  * information.
@@ -1274,25 +1275,21 @@ make_device_uri(
 
   if ((sern = cupsGetOption("SERIALNUMBER", num_values, values)) == NULL)
     if ((sern = cupsGetOption("SERN", num_values, values)) == NULL)
-      if ((sern = cupsGetOption("SN", num_values, values)) == NULL &&
-         ((libusb_get_device_descriptor(printer->device, &devdesc) >= 0) &&
-          devdesc.iSerialNumber))
-      {
-       /*
-        * Try getting the serial number from the device itself...
-       */
+      sern = cupsGetOption("SN", num_values, values);
 
-        int length =
-         libusb_get_string_descriptor_ascii(printer->handle,
-                                            devdesc.iSerialNumber,
-                                            (unsigned char *)tempsern,
-                                            sizeof(tempsern) - 1);
-        if (length > 0)
-       {
-         tempsern[length] = '\0';
-         sern             = tempsern;
-       }
-      }
+  if ((!sern || !*sern) && ((libusb_get_device_descriptor(printer->device, &devdesc) >= 0) && devdesc.iSerialNumber))
+  {
+   /*
+    * Try getting the serial number from the device itself...
+    */
+
+    int length = libusb_get_string_descriptor_ascii(printer->handle, devdesc.iSerialNumber, (unsigned char *)tempsern, sizeof(tempsern) - 1);
+    if (length > 0)
+    {
+      tempsern[length] = '\0';
+      sern             = tempsern;
+    }
+  }
 
   if ((mfg = cupsGetOption("MANUFACTURER", num_values, values)) == NULL)
     mfg = cupsGetOption("MFG", num_values, values);