diff options
Diffstat (limited to 'backend')
-rw-r--r-- | backend/ipp.c | 129 | ||||
-rw-r--r-- | backend/lpd.c | 29 | ||||
-rw-r--r-- | backend/snmp.c | 14 | ||||
-rw-r--r-- | backend/socket.c | 24 | ||||
-rw-r--r-- | backend/usb-libusb.c | 122 |
5 files changed, 266 insertions, 52 deletions
diff --git a/backend/ipp.c b/backend/ipp.c index 83074ebd..bc0e23a9 100644 --- a/backend/ipp.c +++ b/backend/ipp.c @@ -1,5 +1,5 @@ /* - * "$Id: ipp.c 10548 2012-07-16 18:21:43Z mike $" + * "$Id: ipp.c 10890 2013-03-08 18:42:09Z mike $" * * IPP backend for CUPS. * @@ -86,6 +86,7 @@ static int child_pid = 0; /* Child process ID */ #endif /* HAVE_GSSAPI && HAVE_XPC */ static const char * const jattrs[] = /* Job attributes we want */ { + "job-id", "job-impressions-completed", "job-media-sheets-completed", "job-name", @@ -203,6 +204,7 @@ main(int argc, /* I - Number of command-line args */ *value, /* Value of option */ sep; /* Separator character */ http_addrlist_t *addrlist; /* Address of printer */ + int snmp_enabled = 1; /* Is SNMP enabled? */ int snmp_fd, /* SNMP socket */ start_count, /* Page count via SNMP at start */ page_count, /* Page count via SNMP */ @@ -508,6 +510,16 @@ main(int argc, /* I - Number of command-line args */ value); } } + else if (!_cups_strcasecmp(name, "snmp")) + { + /* + * Enable/disable SNMP stuff... + */ + + snmp_enabled = !value[0] || !_cups_strcasecmp(value, "on") || + _cups_strcasecmp(value, "yes") || + _cups_strcasecmp(value, "true"); + } else if (!_cups_strcasecmp(name, "version")) { if (!strcmp(value, "1.0")) @@ -659,11 +671,14 @@ main(int argc, /* I - Number of command-line args */ * See if the printer supports SNMP... */ - if ((snmp_fd = _cupsSNMPOpen(addrlist->addr.addr.sa_family)) >= 0) - { + if (snmp_enabled) + snmp_fd = _cupsSNMPOpen(addrlist->addr.addr.sa_family); + else + snmp_fd = -1; + + if (snmp_fd >= 0) have_supplies = !backendSNMPSupplies(snmp_fd, &(addrlist->addr), &start_count, NULL); - } else have_supplies = start_count = 0; @@ -932,6 +947,8 @@ main(int argc, /* I - Number of command-line args */ _cupsLangPrintFilter(stderr, "ERROR", _("Unable to get printer status.")); sleep(10); + + httpReconnect(http); } ippDelete(supported); @@ -959,9 +976,15 @@ main(int argc, /* I - Number of command-line args */ if ((printer_state = ippFindAttribute(supported, "printer-state-reasons", - IPP_TAG_KEYWORD)) != NULL && !busy) + IPP_TAG_KEYWORD)) == NULL) + { + update_reasons(NULL, "+cups-ipp-conformance-failure-report," + "cups-ipp-missing-printer-state-reasons"); + } + else if (!busy) { for (i = 0; i < printer_state->num_values; i ++) + { if (!strcmp(printer_state->values[0].string.text, "spool-area-full") || !strncmp(printer_state->values[0].string.text, "spool-area-full-", @@ -970,10 +993,8 @@ main(int argc, /* I - Number of command-line args */ busy = 1; break; } + } } - else - update_reasons(NULL, "+cups-ipp-conformance-failure-report," - "cups-ipp-missing-printer-state-reasons"); if (busy) { @@ -1036,6 +1057,12 @@ main(int argc, /* I - Number of command-line args */ if ((operations_sup = ippFindAttribute(supported, "operations-supported", IPP_TAG_ENUM)) != NULL) { + fprintf(stderr, "DEBUG: operations-supported (%d values)\n", + operations_sup->num_values); + for (i = 0; i < operations_sup->num_values; i ++) + fprintf(stderr, "DEBUG: [%d] = %s\n", i, + ippOpString(operations_sup->values[i].integer)); + for (i = 0; i < operations_sup->num_values; i ++) if (operations_sup->values[i].integer == IPP_PRINT_JOB) break; @@ -1259,6 +1286,17 @@ main(int argc, /* I - Number of command-line args */ } /* + * If the printer only claims to support IPP/1.0, or if the user specifically + * included version=1.0 in the URI, then do not try to use Create-Job or + * Send-Document. This is another dreaded compatibility hack, but + * unfortunately there are enough broken printers out there that we need + * this for now... + */ + + if (version == 10) + create_job = send_document = 0; + + /* * Start monitoring the printer in the background... */ @@ -1474,10 +1512,9 @@ main(int argc, /* I - Number of command-line args */ goto cleanup; } } - else if (ipp_status == IPP_ERROR_JOB_CANCELED) + else if (ipp_status == IPP_ERROR_JOB_CANCELED || + ipp_status == IPP_NOT_AUTHORIZED) goto cleanup; - else if (ipp_status == IPP_NOT_AUTHORIZED) - continue; else { /* @@ -1578,6 +1615,10 @@ main(int argc, /* I - Number of command-line args */ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format", NULL, document_format); + if (compression) + ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, + "compression", NULL, compression); + fprintf(stderr, "DEBUG: Sending file %d using chunking...\n", i + 1); http_status = cupsSendRequest(http, request, resource, 0); if (http_status == HTTP_CONTINUE && request->state == IPP_DATA) @@ -1653,13 +1694,70 @@ main(int argc, /* I - Number of command-line args */ else if (ipp_status == IPP_SERVICE_UNAVAILABLE || ipp_status == IPP_NOT_POSSIBLE || ipp_status == IPP_PRINTER_BUSY) + { + if (argc == 6) + { + /* + * Need to reprocess the entire job; if we have a job ID, cancel the + * job first... + */ + + if (job_id > 0) + cancel_job(http, uri, job_id, resource, argv[2], version); + + goto cleanup; + } continue; - else if (ipp_status == IPP_REQUEST_VALUE) + } + else if (ipp_status == IPP_REQUEST_VALUE || + ipp_status == IPP_ERROR_JOB_CANCELED || + ipp_status == IPP_NOT_AUTHORIZED || + ipp_status == IPP_INTERNAL_ERROR) + { + /* + * Print file is too large, job was canceled, we need new + * authentication data, or we had some sort of error... + */ + + goto cleanup; + } + else if (ipp_status == IPP_UPGRADE_REQUIRED) { /* - * Print file is too large, abort this job... + * Server is configured incorrectly; the policy for Create-Job and + * Send-Document has to be the same (auth or no auth, encryption or + * no encryption). Force the queue to stop since printing will never + * work. */ + fputs("DEBUG: The server or printer is configured incorrectly.\n", + stderr); + fputs("DEBUG: The policy for Create-Job and Send-Document must have the " + "same authentication and encryption requirements.\n", stderr); + + ipp_status = IPP_INTERNAL_ERROR; + + if (job_id > 0) + cancel_job(http, uri, job_id, resource, argv[2], version); + + goto cleanup; + } + else if (ipp_status == IPP_NOT_FOUND) + { + /* + * Printer does not actually implement support for Create-Job/ + * Send-Document, so log the conformance issue and stop the printer. + */ + + fputs("DEBUG: This printer claims to support Create-Job and " + "Send-Document, but those operations failed.\n", stderr); + fputs("DEBUG: Add '?version=1.0' to the device URI to use legacy " + "compatibility mode.\n", stderr); + update_reasons(NULL, "+cups-ipp-conformance-failure-report," + "cups-ipp-missing-send-document"); + + ipp_status = IPP_INTERNAL_ERROR; /* Force queue to stop */ + goto cleanup; } else @@ -1826,7 +1924,8 @@ main(int argc, /* I - Number of command-line args */ */ if (have_supplies && - !backendSNMPSupplies(snmp_fd, http->hostaddr, &page_count, NULL) && + !backendSNMPSupplies(snmp_fd, &(http->addrlist->addr), &page_count, + NULL) && page_count > start_count) fprintf(stderr, "PAGE: total %d\n", page_count - start_count); @@ -3277,5 +3376,5 @@ update_reasons(ipp_attribute_t *attr, /* I - printer-state-reasons or NULL */ } /* - * End of "$Id: ipp.c 10548 2012-07-16 18:21:43Z mike $". + * End of "$Id: ipp.c 10890 2013-03-08 18:42:09Z mike $". */ diff --git a/backend/lpd.c b/backend/lpd.c index 160a83ef..37d6c87a 100644 --- a/backend/lpd.c +++ b/backend/lpd.c @@ -1,5 +1,5 @@ /* - * "$Id: lpd.c 10520 2012-05-31 02:53:59Z mike $" + * "$Id: lpd.c 10608 2012-09-15 19:42:21Z mike $" * * Line Printer Daemon backend for CUPS. * @@ -126,6 +126,7 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ int port; /* Port number */ char portname[256]; /* Port name (string) */ http_addrlist_t *addrlist; /* List of addresses for printer */ + int snmp_enabled = 1; /* Is SNMP enabled? */ int snmp_fd; /* SNMP socket */ int fd; /* Print file */ int status; /* Status of LPD job */ @@ -356,7 +357,8 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ */ if (!value[0] || !_cups_strcasecmp(value, "on") || - !_cups_strcasecmp(value, "yes") || !_cups_strcasecmp(value, "true") || + !_cups_strcasecmp(value, "yes") || + !_cups_strcasecmp(value, "true") || !_cups_strcasecmp(value, "rfc1179")) reserve = RESERVE_RFC1179; else if (!_cups_strcasecmp(value, "any")) @@ -371,7 +373,8 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ */ manual_copies = !value[0] || !_cups_strcasecmp(value, "on") || - !_cups_strcasecmp(value, "yes") || !_cups_strcasecmp(value, "true"); + !_cups_strcasecmp(value, "yes") || + !_cups_strcasecmp(value, "true"); } else if (!_cups_strcasecmp(name, "sanitize_title")) { @@ -380,7 +383,18 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ */ sanitize_title = !value[0] || !_cups_strcasecmp(value, "on") || - !_cups_strcasecmp(value, "yes") || !_cups_strcasecmp(value, "true"); + !_cups_strcasecmp(value, "yes") || + !_cups_strcasecmp(value, "true"); + } + else if (!_cups_strcasecmp(name, "snmp")) + { + /* + * Enable/disable SNMP stuff... + */ + + snmp_enabled = !value[0] || !_cups_strcasecmp(value, "on") || + _cups_strcasecmp(value, "yes") || + _cups_strcasecmp(value, "true"); } else if (!_cups_strcasecmp(name, "timeout")) { @@ -428,7 +442,10 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ } } - snmp_fd = _cupsSNMPOpen(addrlist->addr.addr.sa_family); + if (snmp_enabled) + snmp_fd = _cupsSNMPOpen(addrlist->addr.addr.sa_family); + else + snmp_fd = -1; /* * Wait for data from the filter... @@ -1314,5 +1331,5 @@ sigterm_handler(int sig) /* I - Signal */ /* - * End of "$Id: lpd.c 10520 2012-05-31 02:53:59Z mike $". + * End of "$Id: lpd.c 10608 2012-09-15 19:42:21Z mike $". */ diff --git a/backend/snmp.c b/backend/snmp.c index ca3a24fe..4a887989 100644 --- a/backend/snmp.c +++ b/backend/snmp.c @@ -1,5 +1,5 @@ /* - * "$Id: snmp.c 10535 2012-06-22 03:45:53Z mike $" + * "$Id: snmp.c 10643 2012-10-09 03:02:49Z mike $" * * SNMP discovery backend for CUPS. * @@ -1025,6 +1025,11 @@ read_snmp_response(int fd) /* I - SNMP socket file descriptor */ * Description is the IEEE-1284 device ID... */ + char *ptr; /* Pointer into device ID */ + + for (ptr = (char *)packet.object_value.string.bytes; *ptr; ptr ++) + if (*ptr == '\n') + *ptr = ';'; /* A lot of bad printers put a newline */ if (!device->id) device->id = strdup((char *)packet.object_value.string.bytes); @@ -1066,8 +1071,11 @@ read_snmp_response(int fd) /* I - SNMP socket file descriptor */ */ char make_model[256]; /* Make and model */ + char *ptr; /* Pointer into device ID */ - + for (ptr = (char *)packet.object_value.string.bytes; *ptr; ptr ++) + if (*ptr == '\n') + *ptr = ';'; /* A lot of bad printers put a newline */ if (device->id) free(device->id); @@ -1383,5 +1391,5 @@ update_cache(snmp_cache_t *device, /* I - Device */ /* - * End of "$Id: snmp.c 10535 2012-06-22 03:45:53Z mike $". + * End of "$Id: snmp.c 10643 2012-10-09 03:02:49Z mike $". */ diff --git a/backend/socket.c b/backend/socket.c index cde27b51..0c7fc75a 100644 --- a/backend/socket.c +++ b/backend/socket.c @@ -1,5 +1,5 @@ /* - * "$Id: socket.c 10431 2012-04-23 19:19:19Z mike $" + * "$Id: socket.c 10608 2012-09-15 19:42:21Z mike $" * * AppSocket backend for CUPS. * @@ -87,6 +87,7 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ http_addrlist_t *addrlist, /* Address list */ *addr; /* Connected address */ char addrname[256]; /* Address name */ + int snmp_enabled = 1; /* Is SNMP enabled? */ int snmp_fd, /* SNMP socket */ start_count, /* Page count via SNMP at start */ page_count, /* Page count via SNMP */ @@ -246,6 +247,16 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ waiteof = !value[0] || !_cups_strcasecmp(value, "on") || !_cups_strcasecmp(value, "yes") || !_cups_strcasecmp(value, "true"); } + else if (!_cups_strcasecmp(name, "snmp")) + { + /* + * Enable/disable SNMP stuff... + */ + + snmp_enabled = !value[0] || !_cups_strcasecmp(value, "on") || + _cups_strcasecmp(value, "yes") || + _cups_strcasecmp(value, "true"); + } else if (!_cups_strcasecmp(name, "contimeout")) { /* @@ -286,11 +297,14 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ * See if the printer supports SNMP... */ - if ((snmp_fd = _cupsSNMPOpen(addrlist->addr.addr.sa_family)) >= 0) - { + if (snmp_enabled) + snmp_fd = _cupsSNMPOpen(addrlist->addr.addr.sa_family); + else + snmp_fd = -1; + + if (snmp_fd >= 0) have_supplies = !backendSNMPSupplies(snmp_fd, &(addrlist->addr), &start_count, NULL); - } else have_supplies = start_count = 0; @@ -521,5 +535,5 @@ wait_bc(int device_fd, /* I - Socket */ /* - * End of "$Id: socket.c 10431 2012-04-23 19:19:19Z mike $". + * End of "$Id: socket.c 10608 2012-09-15 19:42:21Z mike $". */ diff --git a/backend/usb-libusb.c b/backend/usb-libusb.c index 542a07c4..e83d7097 100644 --- a/backend/usb-libusb.c +++ b/backend/usb-libusb.c @@ -1,9 +1,9 @@ /* - * "$Id: usb-libusb.c 10543 2012-07-16 17:10:55Z mike $" + * "$Id: usb-libusb.c 10908 2013-03-14 14:31:07Z mike $" * * LIBUSB interface code for CUPS. * - * Copyright 2007-2012 by Apple Inc. + * Copyright 2007-2013 by Apple Inc. * * These coded instructions, statements, and computer programs are the * property of Apple Inc. and are protected by Federal copyright @@ -70,7 +70,7 @@ typedef struct usb_printer_s /**** USB Printer Data ****/ read_endp, /* Read endpoint */ protocol, /* Protocol: 1 = Uni-di, 2 = Bi-di. */ usblp_attached, /* "usblp" kernel module attached? */ - opened_for_job; /* Set to 1 by print_device() */ + reset_after_job; /* Set to 1 by print_device() */ unsigned int quirks; /* Quirks flags */ struct libusb_device_handle *handle; /* Open handle to device */ } usb_printer_t; @@ -122,6 +122,9 @@ struct quirk_printer_struct { #define USBLP_QUIRK_USB_INIT 0x2 /* needs vendor USB init string */ #define USBLP_QUIRK_BAD_CLASS 0x4 /* descriptor uses vendor-specific Class or SubClass */ +#define USBLP_QUIRK_BLACKLIST 0x8 /* these printers do not conform to the USB print spec */ +#define USBLP_QUIRK_RESET 0x4000 /* After printing do a reset + for clean-up */ #define USBLP_QUIRK_NO_REATTACH 0x8000 /* After printing we cannot re-attach the usblp kernel module */ @@ -141,15 +144,78 @@ static const struct quirk_printer_struct quirk_printers[] = { { 0x0409, 0xf1be, USBLP_QUIRK_BIDIR }, /* NEC Picty800 (HP OEM) */ { 0x0482, 0x0010, USBLP_QUIRK_BIDIR }, /* Kyocera Mita FS 820, by zut <kernel@zut.de> */ + { 0x04a9, 0x10a2, USBLP_QUIRK_BIDIR }, /* Canon, Inc. PIXMA iP4200 + Printer, http://www.cups.org/str.php?L4155 */ + { 0x04a9, 0x10b6, USBLP_QUIRK_BIDIR }, /* Canon, Inc. PIXMA iP4300 + Printer, https://bugs.launchpad.net/bugs/1032385 */ + { 0x04a9, 0x1721, USBLP_QUIRK_BIDIR }, /* Canon, Inc. MP210 + https://bugzilla.redhat.com/show_bug.cgi?id=847923#c53 */ + { 0x04a9, 0x170c, USBLP_QUIRK_BIDIR }, /* Canon, Inc. MP500 + Printer, https://bugs.launchpad.net/bugs/1032456 */ + { 0x04a9, 0x1717, USBLP_QUIRK_BIDIR }, /* Canon, Inc. MP510 + Printer, https://bugs.launchpad.net/bugs/1050009 */ + { 0x04a9, 0x173d, USBLP_QUIRK_BIDIR }, /* Canon, Inc. MP550 + Printer, http://www.cups.org/str.php?L4155 */ + { 0x04a9, 0x173e, USBLP_QUIRK_BIDIR }, /* Canon, Inc. MP560 + Printer, http://www.cups.org/str.php?L4155 */ + { 0x04f9, 0x001a, USBLP_QUIRK_NO_REATTACH }, /* Brother Industries, Ltd + HL-1430 Laser Printer, + https://bugs.launchpad.net/bugs/1038695 */ { 0x04f9, 0x000d, USBLP_QUIRK_BIDIR | USBLP_QUIRK_NO_REATTACH }, /* Brother Industries, Ltd - HL-1440 Laser Printer */ + HL-1440 Laser Printer, + https://bugs.launchpad.net/bugs/1000253 */ + { 0x06bc, 0x000b, USBLP_QUIRK_NO_REATTACH }, /* Oki Data Corp. + Okipage 14ex Printer, + https://bugs.launchpad.net/bugs/872483 */ + { 0x06bc, 0x01c7, USBLP_QUIRK_NO_REATTACH }, /* Oki Data Corp. B410d, + https://bugs.launchpad.net/bugs/872483 */ + { 0x04b8, 0x0001, USBLP_QUIRK_BIDIR }, /* Seiko Epson Corp. Stylus Color 740 / Photo 750, + http://bugs.debian.org/697970 */ { 0x04b8, 0x0202, USBLP_QUIRK_BAD_CLASS }, /* Seiko Epson Receipt Printer M129C */ { 0x067b, 0x2305, USBLP_QUIRK_BIDIR | - USBLP_QUIRK_NO_REATTACH }, + USBLP_QUIRK_NO_REATTACH | + USBLP_QUIRK_RESET }, + { 0x0924, 0x3ce9, USBLP_QUIRK_NO_REATTACH }, /* Xerox Phaser 3124 + https://bugzilla.redhat.com/show_bug.cgi?id=867392 */ + { 0x0924, 0x4293, USBLP_QUIRK_NO_REATTACH }, /* Xerox WorkCentre 3210 + https://bugs.launchpad.net/bugs/1102470 */ /* Prolific Technology, Inc. PL2305 Parallel Port - (USB -> Parallel adapter) */ + (USB -> Parallel adapter), https://bugs.launchpad.net/bugs/987485 */ + { 0x04e8, 0x0000, USBLP_QUIRK_RESET }, /* All Samsung devices, + https://bugs.launchpad.net/bugs/1032456 */ + { 0x0a5f, 0x0000, USBLP_QUIRK_BIDIR }, /* All Zebra devices, + https://bugs.launchpad.net/bugs/1001028 */ + /* Canon */ + { 0x04a9, 0x304a, USBLP_QUIRK_BLACKLIST }, /* Canon CP-10 */ + { 0x04a9, 0x3063, USBLP_QUIRK_BLACKLIST }, /* Canon CP-100 */ + { 0x04a9, 0x307c, USBLP_QUIRK_BLACKLIST }, /* Canon CP-200 */ + { 0x04a9, 0x307d, USBLP_QUIRK_BLACKLIST }, /* Canon CP-300 */ + { 0x04a9, 0x30bd, USBLP_QUIRK_BLACKLIST }, /* Canon CP-220 */ + { 0x04a9, 0x30be, USBLP_QUIRK_BLACKLIST }, /* Canon CP-330 */ + { 0x04a9, 0x30f6, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY CP400 */ + { 0x04a9, 0x310b, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY CP600 */ + { 0x04a9, 0x3127, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY CP710 */ + { 0x04a9, 0x3128, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY CP510 */ + { 0x04a9, 0x3141, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY ES1 */ + { 0x04a9, 0x3142, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY CP730 */ + { 0x04a9, 0x3143, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY CP720 */ + { 0x04a9, 0x3170, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY CP750 */ + { 0x04a9, 0x3171, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY CP740 */ + { 0x04a9, 0x3185, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY ES2 */ + { 0x04a9, 0x3186, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY ES20 */ + { 0x04a9, 0x31aa, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY CP770 */ + { 0x04a9, 0x31ab, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY CP760 */ + { 0x04a9, 0x31b0, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY ES30 */ + { 0x04a9, 0x31dd, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY CP780 */ + { 0x04a9, 0x31ee, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY ES40 */ + { 0x04a9, 0x3214, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY CP800 */ + { 0x04a9, 0x3255, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY CP900 */ + { 0x04a9, 0x3256, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY CP810 */ + { 0x04a9, 0x30F5, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY CP500 */ + { 0x04a9, 0x31AF, USBLP_QUIRK_BLACKLIST }, /* Canon SELPHY ES3 */ + /* MISSING PIDs: CP520, CP530, CP790 */ { 0, 0 } }; @@ -256,7 +322,12 @@ print_device(const char *uri, /* I - Device URI */ } g.print_fd = print_fd; - g.printer->opened_for_job = 1; + + /* + * Some devices need a reset after finishing a job, these devices are + * marked with the USBLP_QUIRK_RESET quirk. + */ + g.printer->reset_after_job = (g.printer->quirks & USBLP_QUIRK_RESET ? 1 : 0); /* * If we are printing data from a print driver on stdin, ignore SIGTERM @@ -639,10 +710,10 @@ print_device(const char *uri, /* I - Device URI */ * If it didn't exit abort the pending read and wait an additional * second... */ - + if (!g.read_thread_done) { - fputs("DEBUG: Read thread still active, aborting the pending read...\n", + fputs("DEBUG: Read thread still active, aborting the pending read...\n", stderr); g.wait_eof = 0; @@ -650,7 +721,7 @@ print_device(const char *uri, /* I - Device URI */ gettimeofday(&tv, NULL); cond_timeout.tv_sec = tv.tv_sec + 1; cond_timeout.tv_nsec = tv.tv_usec * 1000; - + while (!g.read_thread_done) { if (pthread_cond_timedwait(&g.read_thread_cond, &g.read_thread_mutex, @@ -663,9 +734,6 @@ print_device(const char *uri, /* I - Device URI */ pthread_mutex_unlock(&g.read_thread_mutex); } - if (print_fd) - close(print_fd); - /* * Close the connection and input file and general clean up... */ @@ -725,7 +793,7 @@ close_device(usb_printer_t *printer) /* I - Printer */ */ if (printer->origconf > 0 && printer->origconf != number2) { - fprintf(stderr, "DEBUG: Restoring USB device configuration: %d -> %d\n", + fprintf(stderr, "DEBUG: Restoring USB device configuration: %d -> %d\n", number2, printer->origconf); if ((errcode = libusb_set_configuration(printer->handle, printer->origconf)) < 0) @@ -772,7 +840,7 @@ close_device(usb_printer_t *printer) /* I - Printer */ * Reset the device to clean up after the job */ - if (printer->opened_for_job == 1) + if (printer->reset_after_job == 1) { if ((errcode = libusb_reset_device(printer->handle)) < 0) fprintf(stderr, @@ -859,7 +927,14 @@ find_device(usb_cb_t cb, /* I - Callback function */ !devdesc.idProduct) continue; - printer.quirks = quirks(devdesc.idVendor, devdesc.idProduct); + printer.quirks = quirks(devdesc.idVendor, devdesc.idProduct); + + /* + * Ignore blacklisted printers... + */ + + if (printer.quirks & USBLP_QUIRK_BLACKLIST) + continue; for (conf = 0; conf < devdesc.bNumConfigurations; conf ++) { @@ -886,7 +961,7 @@ find_device(usb_cb_t cb, /* I - Callback function */ */ if (((altptr->bInterfaceClass != LIBUSB_CLASS_PRINTER || - altptr->bInterfaceSubClass != 1) && + altptr->bInterfaceSubClass != 1) && ((printer.quirks & USBLP_QUIRK_BAD_CLASS) == 0)) || (altptr->bInterfaceProtocol != 1 && /* Unidirectional */ altptr->bInterfaceProtocol != 2) || /* Bidirectional */ @@ -964,7 +1039,7 @@ find_device(usb_cb_t cb, /* I - Callback function */ bEndpointAddress; } else - fprintf(stderr, "DEBUG: Uni-directional USB communication " + fprintf(stderr, "DEBUG: Uni-directional USB communication " "only!\n"); printer.write_endp = confptr->interface[printer.iface]. altsetting[printer.altset]. @@ -1288,7 +1363,7 @@ open_device(usb_printer_t *printer, /* I - Printer */ } printer->usblp_attached = 0; - printer->opened_for_job = 0; + printer->reset_after_job = 0; if (verbose) fputs("STATE: +connecting-to-device\n", stderr); @@ -1343,7 +1418,7 @@ open_device(usb_printer_t *printer, /* I - Printer */ printer->origconf = current; - if ((errcode = + if ((errcode = libusb_get_config_descriptor (printer->device, printer->conf, &confptr)) < 0) { @@ -1355,7 +1430,7 @@ open_device(usb_printer_t *printer, /* I - Printer */ if (number1 != current) { - fprintf(stderr, "DEBUG: Switching USB device configuration: %d -> %d\n", + fprintf(stderr, "DEBUG: Switching USB device configuration: %d -> %d\n", current, number1); if ((errcode = libusb_set_configuration(printer->handle, number1)) < 0) { @@ -1586,7 +1661,8 @@ static unsigned int quirks(int vendor, int product) for (i = 0; quirk_printers[i].vendorId; i++) { if (vendor == quirk_printers[i].vendorId && - product == quirk_printers[i].productId) + (quirk_printers[i].productId == 0x0000 || + product == quirk_printers[i].productId)) return quirk_printers[i].quirks; } return 0; @@ -1881,6 +1957,6 @@ static void soft_reset(void) /* - * End of "$Id: usb-libusb.c 10543 2012-07-16 17:10:55Z mike $". + * End of "$Id: usb-libusb.c 10908 2013-03-14 14:31:07Z mike $". */ |