summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2021-04-19 08:44:48 -0400
committerMichael R Sweet <michael.r.sweet@gmail.com>2021-04-19 08:44:48 -0400
commit14a52682f82c17045fe99415f81ebfefe2100fa4 (patch)
tree83b8b177cc803ddaf84951e2666b806aa3eb8187 /backend
parent811e6226bb9140c2d3eb0732af3ba1176143c77a (diff)
downloadcups-14a52682f82c17045fe99415f81ebfefe2100fa4.tar.gz
Some USB printers (notably DYMO printers) report a bogus serial number in their
IEEE-1284 device ID. This change forces the USB backend to prefer the USB serial number string over the one in the 1284 ID so that we can properly handle printing to different USB-connected printers of the same model.
Diffstat (limited to 'backend')
-rw-r--r--backend/usb-darwin.c51
1 files changed, 37 insertions, 14 deletions
diff --git a/backend/usb-darwin.c b/backend/usb-darwin.c
index 3a8feffb6..ee75b9e0d 100644
--- a/backend/usb-darwin.c
+++ b/backend/usb-darwin.c
@@ -1669,11 +1669,34 @@ static CFStringRef copy_printer_interface_deviceid(printer_interface_t printer,
CFStringAppendFormat(extras, NULL, CFSTR("MDL:%@;"), model);
}
- if (serial == NULL && desc.iSerialNumber != 0)
+ if (desc.iSerialNumber != 0)
{
- serial = copy_printer_interface_indexed_description(printer, desc.iSerialNumber, kUSBLanguageEnglish);
- if (serial && CFStringGetLength(serial) > 0)
- CFStringAppendFormat(extras, NULL, CFSTR("SERN:%@;"), serial);
+ // Always look at the USB serial number since some printers
+ // incorrectly include a bogus static serial number in their
+ // IEEE-1284 device ID string...
+ CFStringRef userial = copy_printer_interface_indexed_description(printer, desc.iSerialNumber, kUSBLanguageEnglish);
+ if (userial && CFStringGetLength(userial) > 0 && (serial == NULL || CFStringCompare(serial, userial, kCFCompareCaseInsensitive) != kCFCompareEqualTo))
+ {
+ if (serial != NULL)
+ {
+ // 1284 serial number doesn't match USB serial number, so replace the existing SERN: in device ID
+ CFRange range = CFStringFind(ret, serial, 0);
+ CFMutableStringRef deviceIDString = CFStringCreateMutableCopy(NULL, 0, ret);
+ CFStringReplace(deviceIDString, range, userial);
+ CFRelease(ret);
+ ret = deviceIDString;
+
+ CFRelease(serial);
+ }
+ else
+ {
+ // No 1284 serial number so add SERN: with USB serial number to device ID
+ CFStringAppendFormat(extras, NULL, CFSTR("SERN:%@;"), userial);
+ }
+ serial = userial;
+ }
+ else if (userial != NULL)
+ CFRelease(userial);
}
if (ret != NULL)
@@ -1692,18 +1715,18 @@ static CFStringRef copy_printer_interface_deviceid(printer_interface_t printer,
if (ret != NULL)
{
- /* Remove special characters from the serial number */
- CFRange range = (serial != NULL ? CFStringFind(serial, CFSTR("+"), 0) : CFRangeMake(0, 0));
- if (range.length == 1)
- {
- range = CFStringFind(ret, serial, 0);
+ /* Remove special characters from the serial number */
+ CFRange range = (serial != NULL ? CFStringFind(serial, CFSTR("+"), 0) : CFRangeMake(0, 0));
+ if (range.length == 1)
+ {
+ range = CFStringFind(ret, serial, 0);
- CFMutableStringRef deviceIDString = CFStringCreateMutableCopy(NULL, 0, ret);
- CFRelease(ret);
+ CFMutableStringRef deviceIDString = CFStringCreateMutableCopy(NULL, 0, ret);
+ CFRelease(ret);
- ret = deviceIDString;
- CFStringFindAndReplace(deviceIDString, CFSTR("+"), CFSTR(""), range, 0);
- }
+ ret = deviceIDString;
+ CFStringFindAndReplace(deviceIDString, CFSTR("+"), CFSTR(""), range, 0);
+ }
}
if (manufacturer != NULL)