From a29fd7ddb5d63688a4d44d08e4ab16428921c321 Mon Sep 17 00:00:00 2001 From: msweet Date: Wed, 23 May 2012 22:51:18 +0000 Subject: Merge changes from CUPS 1.6svn-r10510. git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@3833 a1ca3aef-8c08-0410-bb20-df032aa958be --- backend/dnssd.c | 16 ++++------- backend/ipp.c | 38 +++++++++++++++++-------- backend/snmp-supplies.c | 20 +++++++++++-- backend/usb-libusb.c | 75 +++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 109 insertions(+), 40 deletions(-) (limited to 'backend') diff --git a/backend/dnssd.c b/backend/dnssd.c index 2984407df..7cff1cb4f 100644 --- a/backend/dnssd.c +++ b/backend/dnssd.c @@ -331,7 +331,7 @@ main(int argc, /* I - Number of command-line args */ #ifdef HAVE_AVAHI if ((simple_poll = avahi_simple_poll_new()) == NULL) { - fputs("DEBUG: Unable to create avahi simple poll object.\n", stderr); + fputs("DEBUG: Unable to create Avahi simple poll object.\n", stderr); return (1); } @@ -341,7 +341,7 @@ main(int argc, /* I - Number of command-line args */ 0, client_callback, simple_poll, &error); if (!client) { - fputs("DEBUG: Unable to create avahi client.\n", stderr); + fputs("DEBUG: Unable to create Avahi client.\n", stderr); return (1); } @@ -587,10 +587,7 @@ browse_callback( "interfaceIndex=%d, errorCode=%d, serviceName=\"%s\", " "regtype=\"%s\", replyDomain=\"%s\", context=%p)\n", sdRef, flags, interfaceIndex, errorCode, - serviceName ? serviceName : "(null)", - regtype ? regtype : "(null)", - replyDomain ? replyDomain : "(null)", - context); + serviceName, regtype, replyDomain, context); /* * Only process "add" data... @@ -629,10 +626,7 @@ browse_local_callback( "interfaceIndex=%d, errorCode=%d, serviceName=\"%s\", " "regtype=\"%s\", replyDomain=\"%s\", context=%p)\n", sdRef, flags, interfaceIndex, errorCode, - serviceName ? serviceName : "(null)", - regtype ? regtype : "(null)", - replyDomain ? replyDomain : "(null)", - context); + serviceName, regtype, replyDomain, context); /* * Only process "add" data... @@ -907,7 +901,7 @@ get_device(cups_array_t *devices, /* I - Device array */ replyDomain); #else /* HAVE_AVAHI */ avahi_service_name_join(fullName, kDNSServiceMaxDomainName, - serviceName, regtype, replyDomain); + serviceName, regtype, replyDomain); #endif /* HAVE_DNSSD */ free(device->fullName); diff --git a/backend/ipp.c b/backend/ipp.c index 73491452d..a0736a8bb 100644 --- a/backend/ipp.c +++ b/backend/ipp.c @@ -66,7 +66,8 @@ typedef struct _cups_monitor_s /**** Monitoring data ****/ *resource; /* Resource path */ int port, /* Port number */ version, /* IPP version */ - job_id; /* Job ID for submitted job */ + job_id, /* Job ID for submitted job */ + get_job_attrs; /* Support Get-Job-Attributes? */ const char *job_name; /* Job name for submitted job */ http_encryption_t encryption; /* Use encryption? */ ipp_jstate_t job_state; /* Current job state */ @@ -241,6 +242,7 @@ main(int argc, /* I - Number of command-line args */ ipp_attribute_t *printer_state; /* printer-state attribute */ ipp_attribute_t *printer_accepting; /* printer-is-accepting-jobs */ int create_job = 0, /* Does printer support Create-Job? */ + get_job_attrs = 0, /* Does printer support Get-Job-Attributes? */ send_document = 0, /* Does printer support Send-Document? */ validate_job = 0; /* Does printer support Validate-Job? */ int copies, /* Number of copies for job */ @@ -1074,6 +1076,8 @@ main(int argc, /* I - Number of command-line args */ create_job = 1; else if (operations_sup->values[i].integer == IPP_SEND_DOCUMENT) send_document = 1; + else if (operations_sup->values[i].integer == IPP_GET_JOB_ATTRIBUTES) + get_job_attrs = 1; } if (!send_document) @@ -1081,6 +1085,9 @@ main(int argc, /* I - Number of command-line args */ fputs("DEBUG: Printer supports Create-Job but not Send-Document.\n", stderr); create_job = 0; + + update_reasons(NULL, "+cups-ipp-conformance-failure-report," + "cups-ipp-missing-send-document"); } if (!validate_job) @@ -1262,6 +1269,7 @@ main(int argc, /* I - Number of command-line args */ monitor.port = port; monitor.version = version; monitor.job_id = 0; + monitor.get_job_attrs = get_job_attrs; monitor.encryption = cupsEncryption(); monitor.job_state = IPP_JOB_PENDING; monitor.printer_state = IPP_PRINTER_IDLE; @@ -1305,6 +1313,8 @@ main(int argc, /* I - Number of command-line args */ _cupsLangPrintFilter(stderr, "INFO", _("The printer is in use.")); sleep(10); } + else if (ipp_status == IPP_DOCUMENT_FORMAT) + goto cleanup; else if (ipp_status == IPP_FORBIDDEN || ipp_status == IPP_AUTHENTICATION_CANCELED) { @@ -1328,7 +1338,8 @@ main(int argc, /* I - Number of command-line args */ "cups-ipp-missing-validate-job"); break; } - else if (ipp_status < IPP_REDIRECTION_OTHER_SITE) + else if (ipp_status < IPP_REDIRECTION_OTHER_SITE || + ipp_status == IPP_BAD_REQUEST) break; } @@ -1658,7 +1669,7 @@ main(int argc, /* I - Number of command-line args */ * Wait for the job to complete... */ - if (!job_id || !waitjob) + if (!job_id || !waitjob || !get_job_attrs) continue; _cupsLangPrintFilter(stderr, "INFO", _("Waiting for job to complete.")); @@ -1701,7 +1712,7 @@ main(int argc, /* I - Number of command-line args */ response = cupsDoRequest(http, request, resource); ipp_status = cupsLastError(); - if (ipp_status == IPP_NOT_FOUND) + if (ipp_status == IPP_NOT_FOUND || ipp_status == IPP_NOT_POSSIBLE) { /* * Job has gone away and/or the server has no job history... @@ -1723,7 +1734,6 @@ 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) { ippDelete(response); @@ -1871,13 +1881,16 @@ main(int argc, /* I - Number of command-line args */ return (CUPS_BACKEND_AUTH_REQUIRED); else if (ipp_status == IPP_INTERNAL_ERROR) return (CUPS_BACKEND_STOP); - else if (ipp_status == IPP_DOCUMENT_FORMAT || - ipp_status == IPP_CONFLICT) + else if (ipp_status == IPP_CONFLICT) return (CUPS_BACKEND_FAILED); - else if (ipp_status == IPP_REQUEST_VALUE || job_canceled < 0) + else if (ipp_status == IPP_REQUEST_VALUE || + ipp_status == IPP_DOCUMENT_FORMAT || job_canceled < 0) { if (ipp_status == IPP_REQUEST_VALUE) _cupsLangPrintFilter(stderr, "ERROR", _("Print job too large.")); + else if (ipp_status == IPP_DOCUMENT_FORMAT) + _cupsLangPrintFilter(stderr, "ERROR", + _("Printer cannot print supplied content.")); else _cupsLangPrintFilter(stderr, "ERROR", _("Print job canceled at printer.")); @@ -2123,7 +2136,8 @@ monitor_printer( * Check the status of the job itself... */ - job_op = monitor->job_id > 0 ? IPP_GET_JOB_ATTRIBUTES : IPP_GET_JOBS; + job_op = (monitor->job_id > 0 && monitor->get_job_attrs) ? + IPP_GET_JOB_ATTRIBUTES : IPP_GET_JOBS; request = ippNewRequest(job_op); request->request.op.version[0] = monitor->version / 10; request->request.op.version[1] = monitor->version % 10; @@ -2321,7 +2335,7 @@ new_request( fprintf(stderr, "DEBUG: job-name=\"%s\"\n", title); } - if (format) + if (format && op != IPP_CREATE_JOB) { ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format", NULL, format); @@ -2329,7 +2343,7 @@ new_request( } #ifdef HAVE_LIBZ - if (compression) + if (compression && op != IPP_CREATE_JOB) { ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "compression", NULL, compression); @@ -2569,7 +2583,7 @@ new_request( * When talking to another CUPS server, send all options... */ - cupsEncodeOptions(request, num_options, options); + cupsEncodeOptions2(request, num_options, options, IPP_TAG_JOB); } if (copies > 1 && (!pc || copies <= pc->max_copies)) diff --git a/backend/snmp-supplies.c b/backend/snmp-supplies.c index 75dc9dc7a..380dd793d 100644 --- a/backend/snmp-supplies.c +++ b/backend/snmp-supplies.c @@ -49,6 +49,9 @@ #define CUPS_CLEANER_NEAR_EOL 0x0400 /* Proposed JPS3 */ #define CUPS_CLEANER_LIFE_OVER 0x0800 /* Proposed JPS3 */ +#define CUPS_SNMP_NONE 0x0000 +#define CUPS_SNMP_CAPACITY 0x0001 /* Supply levels reported as percentages */ + /* * Local structures... @@ -79,6 +82,8 @@ static http_addr_t current_addr; /* Current address */ static int current_state = -1; /* Current device state bits */ static int charset = -1; /* Character set for supply names */ +static unsigned quirks = CUPS_SNMP_NONE; + /* Quirks we have to work around */ static int num_supplies = 0; /* Number of supplies found */ static backend_supplies_t supplies[CUPS_MAX_SUPPLIES]; @@ -246,6 +251,9 @@ backendSNMPSupplies( { if (supplies[i].max_capacity > 0 && supplies[i].level >= 0) percent = 100 * supplies[i].level / supplies[i].max_capacity; + else if (supplies[i].level >= 0 && supplies[i].level <= 100 && + (quirks & CUPS_SNMP_CAPACITY)) + percent = supplies[i].level; else percent = 50; @@ -308,7 +316,8 @@ backendSNMPSupplies( if (i) *ptr++ = ','; - if (supplies[i].max_capacity > 0 && supplies[i].level >= 0) + if ((supplies[i].max_capacity > 0 || (quirks & CUPS_SNMP_CAPACITY)) && + supplies[i].level >= 0) sprintf(ptr, "%d", percent); else strcpy(ptr, "-1"); @@ -506,6 +515,12 @@ backend_init_supplies( return; } + if ((ppdattr = ppdFindAttr(ppd, "cupsSNMPQuirks", NULL)) != NULL) + { + if (!_cups_strcasecmp(ppdattr->value, "capacity")) + quirks |= CUPS_SNMP_CAPACITY; + } + ppdClose(ppd); /* @@ -932,7 +947,8 @@ backend_walk_cb(cups_snmp_t *packet, /* I - SNMP packet */ supplies[i - 1].level = packet->object_value.integer; } - else if (_cupsSNMPIsOIDPrefixed(packet, prtMarkerSuppliesMaxCapacity)) + else if (_cupsSNMPIsOIDPrefixed(packet, prtMarkerSuppliesMaxCapacity) && + !(quirks & CUPS_SNMP_CAPACITY)) { /* * Get max capacity... diff --git a/backend/usb-libusb.c b/backend/usb-libusb.c index 103a0e30b..5811fde1f 100644 --- a/backend/usb-libusb.c +++ b/backend/usb-libusb.c @@ -537,10 +537,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; @@ -548,7 +548,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, @@ -602,8 +602,8 @@ close_device(usb_printer_t *printer) /* I - Printer */ int number; /* Interface number */ - libusb_get_device_descriptor (printer->device, &devdesc); - libusb_get_config_descriptor (printer->device, printer->conf, &confptr); + libusb_get_device_descriptor(printer->device, &devdesc); + libusb_get_config_descriptor(printer->device, printer->conf, &confptr); number = confptr->interface[printer->iface]. altsetting[printer->altset].bInterfaceNumber; libusb_release_interface(printer->handle, number); @@ -694,7 +694,7 @@ find_device(usb_cb_t cb, /* I - Callback function */ * a printer... */ - libusb_get_device_descriptor (device, &devdesc); + libusb_get_device_descriptor(device, &devdesc); if (!devdesc.bNumConfigurations || !devdesc.idVendor || !devdesc.idProduct) @@ -702,7 +702,7 @@ find_device(usb_cb_t cb, /* I - Callback function */ for (conf = 0; conf < devdesc.bNumConfigurations; conf ++) { - if (libusb_get_config_descriptor (device, conf, &confptr) < 0) + if (libusb_get_config_descriptor(device, conf, &confptr) < 0) continue; for (iface = 0, ifaceptr = confptr->interface; iface < confptr->bNumInterfaces; @@ -950,7 +950,7 @@ 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) && + ((libusb_get_device_descriptor(printer->device, &devdesc) >= 0) && devdesc.iSerialNumber)) { /* @@ -1089,9 +1089,45 @@ open_device(usb_printer_t *printer, /* I - Printer */ if (libusb_open(printer->device, &printer->handle) < 0) return (-1); + printer->usblp_attached = 0; + if (verbose) fputs("STATE: +connecting-to-device\n", stderr); + if ((errcode = libusb_get_device_descriptor (printer->device, &devdesc)) < 0) + { + fprintf(stderr, "DEBUG: Failed to get device descriptor, code: %d\n", + errcode); + goto error; + } + + /* + * Get the "usblp" kernel module out of the way. This backend only + * works without the module attached. + */ + + errcode = libusb_kernel_driver_active(printer->handle, printer->iface); + if (errcode == 0) + printer->usblp_attached = 0; + else if (errcode == 1) + { + printer->usblp_attached = 1; + if ((errcode = + libusb_detach_kernel_driver(printer->handle, printer->iface)) < 0) + { + fprintf(stderr, "DEBUG: Failed to detach \"usblp\" module from %04x:%04x\n", + devdesc.idVendor, devdesc.idProduct); + goto error; + } + } + else + { + printer->usblp_attached = 0; + fprintf(stderr, "DEBUG: Failed to check whether %04x:%04x has the \"usblp\" kernel module attached\n", + devdesc.idVendor, devdesc.idProduct); + goto error; + } + /* * Set the desired configuration, but only if it needs changing. Some * printers (e.g., Samsung) don't like libusb_set_configuration. It will @@ -1106,8 +1142,8 @@ open_device(usb_printer_t *printer, /* I - Printer */ 0, 0, (unsigned char *)¤t, 1, 5000) < 0) current = 0; /* Assume not configured */ - libusb_get_device_descriptor (printer->device, &devdesc); - libusb_get_config_descriptor (printer->device, printer->conf, &confptr); + libusb_get_device_descriptor(printer->device, &devdesc); + libusb_get_config_descriptor(printer->device, printer->conf, &confptr); number1 = confptr->bConfigurationValue; if (number1 != current) @@ -1148,9 +1184,14 @@ open_device(usb_printer_t *printer, /* I - Printer */ else { printer->usblp_attached = 0; - fprintf(stderr, "DEBUG: Failed to check whether %04x:%04x has the \"usblp\" kernel module attached\n", - devdesc.idVendor, devdesc.idProduct); - goto error; + + if (errcode != LIBUSB_ERROR_NOT_SUPPORTED) + { + fprintf(stderr, + "DEBUG: Failed to check whether %04x:%04x has the \"usblp\" " + "kernel module attached\n", devdesc.idVendor, devdesc.idProduct); + goto error; + } } /* @@ -1163,11 +1204,13 @@ open_device(usb_printer_t *printer, /* I - Printer */ while ((errcode = libusb_claim_interface(printer->handle, number1)) < 0) { if (errcode != LIBUSB_ERROR_BUSY) + { fprintf(stderr, "DEBUG: Failed to claim interface %d for %04x:%04x: %s\n", number1, devdesc.idVendor, devdesc.idProduct, strerror(errno)); - goto error; + goto error; + } } /* @@ -1187,12 +1230,14 @@ open_device(usb_printer_t *printer, /* I - Printer */ < 0) { if (errcode != LIBUSB_ERROR_BUSY) + { fprintf(stderr, "DEBUG: Failed to set alternate interface %d for %04x:%04x: " "%s\n", number2, devdesc.idVendor, devdesc.idProduct, strerror(errno)); - goto error; + goto error; + } } } -- cgit v1.2.3