From: Michael R Sweet Date: Thu, 15 Apr 2021 20:06:01 +0000 (-0400) Subject: Use the device serial number if the 1284 serial number is empty (Issue #170) X-Git-Tag: v2.4b1~141 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75ee54aca34af20fb29ac1612238da1b62658a04;p=thirdparty%2Fcups.git Use the device serial number if the 1284 serial number is empty (Issue #170) --- diff --git a/CHANGES.md b/CHANGES.md index d8abcd4c48..63f6b66861 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/backend/usb-libusb.c b/backend/usb-libusb.c index 89b5182f70..0f81f0b23f 100644 --- a/backend/usb-libusb.c +++ b/backend/usb-libusb.c @@ -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);