diff -Naur cups-1.4.3/backend/dnssd.c cups-1.4.6/backend/dnssd.c --- cups-1.4.3/backend/dnssd.c 2011-03-23 11:39:56.329041923 +0000 +++ cups-1.4.6/backend/dnssd.c 2011-03-23 12:21:16.716546082 +0000 @@ -15,15 +15,21 @@ * * Contents: * + * next_txt_record() - Get next TXT record from a cups_txt_records_t. + * parse_txt_record_pair() - Read key/value pair in cups_txt_records_t. * main() - Browse for printers. * browse_callback() - Browse devices. * browse_local_callback() - Browse local devices. * compare_devices() - Compare two devices. * exec_backend() - Execute the backend that corresponds to the * resolved service name. + * device_type() - Get DNS-SD type enumeration from string. * get_device() - Create or update a device. -* find_device() * query_callback() - Process query data. + * avahi_client_callback() - Avahi client callback function. + * avahi_query_callback() - Avahi query callback function. + * avahi_browse_callback() - Avahi browse callback function. + * find_device() - Find a device from its name and domain. * sigterm_handler() - Handle termination signals... * unquote() - Unquote a name string. */ @@ -167,8 +173,9 @@ /* - * cups_txt_records_t access functions + * 'next_txt_record()' - Get next TXT record from a cups_txt_records_t. */ + static cups_txt_records_t * next_txt_record (cups_txt_records_t *txt) { @@ -183,6 +190,11 @@ return txt; } + +/* + * 'parse_txt_record_pair()' - Read key/value pair in cups_txt_records_t. + */ + static int parse_txt_record_pair (cups_txt_records_t *txt) { @@ -238,6 +250,7 @@ return 0; } + /* * 'main()' - Browse for printers. */ @@ -583,11 +596,11 @@ } +#ifdef HAVE_DNSSD /* * 'browse_callback()' - Browse devices. */ -#ifdef HAVE_DNSSD static void browse_callback( DNSServiceRef sdRef, /* I - Service reference */ @@ -621,14 +634,12 @@ get_device((cups_array_t *)context, serviceName, regtype, replyDomain); } -#endif /* HAVE_DNSSD */ /* * 'browse_local_callback()' - Browse local devices. */ -#ifdef HAVE_DNSSD static void browse_local_callback( DNSServiceRef sdRef, /* I - Service reference */ @@ -747,6 +758,11 @@ exit(CUPS_BACKEND_STOP); } + +/* + * 'device_type()' - Get DNS-SD type enumeration from string. + */ + static int device_type (const char *regtype) { @@ -865,11 +881,11 @@ } +#ifdef HAVE_DNSSD /* * 'query_callback()' - Process query data. */ -#ifdef HAVE_DNSSD static void query_callback( DNSServiceRef sdRef, /* I - Service reference */ @@ -933,7 +949,12 @@ } #endif /* HAVE_DNSSD */ + #ifdef HAVE_AVAHI +/* + * 'avahi_client_callback()' - Avahi client callback function. + */ + static void avahi_client_callback(AvahiClient *client, AvahiClientState state, @@ -950,6 +971,11 @@ } } + +/* + * 'avahi_query_callback()' - Avahi query callback function. + */ + static void avahi_query_callback(AvahiServiceResolver *resolver, AvahiIfIndex interface, @@ -1018,6 +1044,11 @@ avahi_service_resolver_free (resolver); } + +/* + * 'avahi_browse_callback()' - Avahi browse callback function. + */ + static void avahi_browse_callback(AvahiServiceBrowser *browser, AvahiIfIndex interface, @@ -1080,10 +1111,15 @@ case AVAHI_BROWSER_ALL_FOR_NOW: case AVAHI_BROWSER_CACHE_EXHAUSTED: break; - } + } } #endif /* HAVE_AVAHI */ + +/* + * 'find_device()' - Find a device from its name and domain. + */ + static cups_device_t * find_device (cups_array_t *devices, cups_txt_records_t *txt, diff -Naur cups-1.4.3/backend/ieee1284.c cups-1.4.6/backend/ieee1284.c --- cups-1.4.3/backend/ieee1284.c 2011-03-23 11:39:56.349045030 +0000 +++ cups-1.4.6/backend/ieee1284.c 2011-03-23 12:21:16.916542510 +0000 @@ -1,5 +1,5 @@ /* - * "$Id: ieee1284.c 8912 2009-12-08 02:13:42Z mike $" + * "$Id: ieee1284.c 9098 2010-04-09 22:42:09Z mike $" * * IEEE-1284 support functions for the Common UNIX Printing System (CUPS). * @@ -55,6 +55,7 @@ # if defined(__sun) && defined(ECPPIOC_GETDEVID) struct ecpp_device_id did; /* Device ID buffer */ # endif /* __sun && ECPPIOC_GETDEVID */ + char *c; DEBUG_printf(("backendGetDeviceID(fd=%d, device_id=%p, device_id_size=%d, " @@ -176,7 +177,7 @@ * and then limit the length to the size of our buffer... */ - if (length > device_id_size) + if ((length > device_id_size) || (length < 14)) length = (((unsigned)device_id[1] & 255) << 8) + ((unsigned)device_id[0] & 255); @@ -185,24 +186,44 @@ /* * The length field counts the number of bytes in the string - * including the length field itself (2 bytes). + * including the length field itself (2 bytes). The minimum + * length for a valid/usable device ID is 14 bytes: + * + * MFG: ;MDL: ; + * 2 + 4 + 1 + 5 + 1 + 1 */ - length -= 2; + if (length < 14) + { + /* + * Can't use this device ID, so don't try to copy it... + */ - /* - * Copy the device ID text to the beginning of the buffer and - * nul-terminate. - */ + device_id[0] = '\0'; + got_id = 0; + } + else + { + /* + * Copy the device ID text to the beginning of the buffer and + * nul-terminate. + */ - memmove(device_id, device_id + 2, length); - device_id[length] = '\0'; + length -= 2; + + memmove(device_id, device_id + 2, length); + device_id[length] = '\0'; + } } -# ifdef DEBUG else + { +# ifdef DEBUG DEBUG_printf(("backendGetDeviceID: ioctl failed - %s\n", strerror(errno))); # endif /* DEBUG */ + /* Clean up after failed attempt to get device ID */ + *device_id = '\0'; + } # endif /* __linux */ # if defined(__sun) && defined(ECPPIOC_GETDEVID) @@ -230,14 +251,24 @@ # endif /* __sun && ECPPIOC_GETDEVID */ } + /* + * Check whether device ID is valid. Turn line breaks and tabs to spaces + * and abort device IDs with non-printable characters + */ + for (c = device_id; *c; c++) + if (isspace(*c)) + *c = ' '; + else if (!isprint(*c)) + { + *device_id = '\0'; + break; + } + DEBUG_printf(("backendGetDeviceID: device_id=\"%s\"\n", device_id)); if (scheme && uri) *uri = '\0'; - if (!*device_id) - return (-1); - /* * Get the make and model... */ @@ -304,6 +335,9 @@ mfg = temp; } + if (!mdl) + mdl = ""; + if (!strncasecmp(mdl, mfg, strlen(mfg))) { mdl += strlen(mfg); @@ -395,7 +429,11 @@ char temp[1024]; /* Temporary make and model */ - snprintf(temp, sizeof(temp), "%s %s", mfg, mdl); + if (mfg) + snprintf(temp, sizeof(temp), "%s %s", mfg, mdl); + else + snprintf(temp, sizeof(temp), "%s", mdl); + _ppdNormalizeMakeAndModel(temp, make_model, make_model_size); } } @@ -450,5 +488,5 @@ /* - * End of "$Id: ieee1284.c 8912 2009-12-08 02:13:42Z mike $". + * End of "$Id: ieee1284.c 9098 2010-04-09 22:42:09Z mike $". */ diff -Naur cups-1.4.3/backend/runloop.c cups-1.4.6/backend/runloop.c --- cups-1.4.3/backend/runloop.c 2009-11-20 01:27:57.000000000 +0000 +++ cups-1.4.6/backend/runloop.c 2010-08-13 01:34:04.000000000 +0000 @@ -1,9 +1,9 @@ /* - * "$Id: runloop.c 8896 2009-11-20 01:27:57Z mike $" + * "$Id: runloop.c 9258 2010-08-13 01:34:04Z mike $" * - * Common run loop APIs for the Common UNIX Printing System (CUPS). + * Common run loop APIs for CUPS. * - * Copyright 2007-2008 by Apple Inc. + * Copyright 2007-2010 by Apple Inc. * Copyright 2006-2007 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the @@ -299,6 +299,8 @@ strerror(errno)); use_bc = 0; } + else if (bc_bytes == 0) + use_bc = 0; } /* @@ -420,5 +422,5 @@ /* - * End of "$Id: runloop.c 8896 2009-11-20 01:27:57Z mike $". + * End of "$Id: runloop.c 9258 2010-08-13 01:34:04Z mike $". */ diff -Naur cups-1.4.3/backend/serial.c cups-1.4.6/backend/serial.c --- cups-1.4.3/backend/serial.c 2009-08-31 18:45:43.000000000 +0000 +++ cups-1.4.6/backend/serial.c 2010-08-31 15:56:40.000000000 +0000 @@ -1,5 +1,5 @@ /* - * "$Id: serial.c 8807 2009-08-31 18:45:43Z mike $" + * "$Id: serial.c 9282 2010-08-31 15:56:40Z mike $" * * Serial port backend for the Common UNIX Printing System (CUPS). * @@ -502,7 +502,7 @@ * stdin (otherwise you can't cancel raw jobs...) */ - if (print_fd != 0) + if (!print_fd) { #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */ sigset(SIGTERM, SIG_IGN); @@ -1326,5 +1326,5 @@ /* - * End of "$Id: serial.c 8807 2009-08-31 18:45:43Z mike $". + * End of "$Id: serial.c 9282 2010-08-31 15:56:40Z mike $". */ diff -Naur cups-1.4.3/backend/snmp.c cups-1.4.6/backend/snmp.c --- cups-1.4.3/backend/snmp.c 2009-12-08 02:13:42.000000000 +0000 +++ cups-1.4.6/backend/snmp.c 2011-03-23 12:21:16.896544432 +0000 @@ -194,6 +194,8 @@ static const int LexmarkProductOID[] = { 1,3,6,1,4,1,641,2,1,2,1,2,1,-1 }; static const int LexmarkProductOID2[] = { 1,3,6,1,4,1,674,10898,100,2,1,2,1,2,1,-1 }; static const int LexmarkDeviceIdOID[] = { 1,3,6,1,4,1,641,2,1,2,1,3,1,-1 }; +static const int HPDeviceIdOID[] = { 1,3,6,1,4,1,11,2,3,9,1,1,7,0,-1 }; +static const int RicohDeviceIdOID[] = { 1,3,6,1,4,1,367,3,2,1,1,1,11,0,-1 }; static const int XeroxProductOID[] = { 1,3,6,1,4,1,128,2,1,3,1,2,0,-1 }; static cups_array_t *DeviceURIs = NULL; static int HostNameLookups = 0; @@ -1001,8 +1003,14 @@ packet.community, CUPS_ASN1_GET_REQUEST, DEVICE_ID, LexmarkDeviceIdOID); _cupsSNMPWrite(fd, &(packet.address), CUPS_SNMP_VERSION_1, + packet.community, CUPS_ASN1_GET_REQUEST, + DEVICE_ID, RicohDeviceIdOID); + _cupsSNMPWrite(fd, &(packet.address), CUPS_SNMP_VERSION_1, packet.community, CUPS_ASN1_GET_REQUEST, DEVICE_PRODUCT, XeroxProductOID); + _cupsSNMPWrite(fd, &(packet.address), CUPS_SNMP_VERSION_1, + packet.community, CUPS_ASN1_GET_REQUEST, + DEVICE_ID, HPDeviceIdOID); break; case DEVICE_DESCRIPTION : diff -Naur cups-1.4.3/backend/socket.c cups-1.4.6/backend/socket.c --- cups-1.4.3/backend/socket.c 2009-11-20 01:27:57.000000000 +0000 +++ cups-1.4.6/backend/socket.c 2010-03-30 22:07:33.000000000 +0000 @@ -1,9 +1,9 @@ /* - * "$Id: socket.c 8896 2009-11-20 01:27:57Z mike $" + * "$Id: socket.c 9061 2010-03-30 22:07:33Z mike $" * * AppSocket backend for the Common UNIX Printing System (CUPS). * - * Copyright 2007-2009 by Apple Inc. + * Copyright 2007-2010 by Apple Inc. * Copyright 1997-2007 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the @@ -406,6 +406,7 @@ CUPS_LLCAST tbytes); } +#ifdef __APPLE__ /* * Wait up to 5 seconds to get any pending back-channel data... */ @@ -414,6 +415,7 @@ while (wait_time >= time(¤t_time)) if (wait_bc(device_fd, wait_time - current_time) <= 0) break; +#endif /* __APPLE__ */ if (waiteof) { @@ -505,5 +507,5 @@ /* - * End of "$Id: socket.c 8896 2009-11-20 01:27:57Z mike $". + * End of "$Id: socket.c 9061 2010-03-30 22:07:33Z mike $". */ diff -Naur cups-1.4.3/backend/usb-darwin.c cups-1.4.6/backend/usb-darwin.c --- cups-1.4.3/backend/usb-darwin.c 2009-11-20 01:27:57.000000000 +0000 +++ cups-1.4.6/backend/usb-darwin.c 2010-09-28 19:10:26.000000000 +0000 @@ -1,7 +1,7 @@ /* -* "$Id: usb-darwin.c 8896 2009-11-20 01:27:57Z mike $" +* "$Id: usb-darwin.c 9319 2010-09-28 19:10:26Z mike $" * -* Copyright 2005-2009 Apple Inc. All rights reserved. +* Copyright 2005-2010 Apple Inc. All rights reserved. * * IMPORTANT: This Apple software is supplied to you by Apple Computer, * Inc. ("Apple") in consideration of your agreement to the following @@ -292,8 +292,8 @@ #if defined(__i386__) || defined(__x86_64__) static pid_t child_pid; /* Child PID */ static void run_legacy_backend(int argc, char *argv[], int fd); /* Starts child backend process running as a ppc executable */ -static void sigterm_handler(int sig); /* SIGTERM handler */ #endif /* __i386__ || __x86_64__ */ +static void sigterm_handler(int sig); /* SIGTERM handler */ #ifdef PARSE_PS_ERRORS static const char *next_line (const char *buffer); @@ -750,6 +750,22 @@ fprintf(stderr, "DEBUG: Sent %lld bytes...\n", (off_t)total_bytes); + if (!print_fd) + { + /* + * Re-enable the SIGTERM handler so pthread_kill() will work... + */ + + struct sigaction action; /* POSIX signal action */ + + memset(&action, 0, sizeof(action)); + + sigemptyset(&action.sa_mask); + sigaddset(&action.sa_mask, SIGTERM); + action.sa_handler = sigterm_handler; + sigaction(SIGTERM, &action, NULL); + } + /* * Wait for the side channel thread to exit... */ @@ -780,6 +796,7 @@ * Force the side-channel thread to exit... */ + fputs("DEBUG: Force the side-channel thread to exit...\n", stderr); pthread_kill(sidechannel_thread_id, SIGTERM); } } @@ -820,6 +837,7 @@ */ g.wait_eof = 0; + fputs("DEBUG: Force the read thread to exit...\n", stderr); pthread_kill(read_thread_id, SIGTERM); } } @@ -1379,7 +1397,10 @@ { fprintf(stderr, "DEBUG: Unable to load class driver \"%s\": %s\n", bundlestr, strerror(errno)); - return (kr); + if (errno == ENOENT) + return (load_classdriver(NULL, intf, printerDriver)); + else + return (kr); } else if (bundleinfo.st_mode & S_IWOTH) { @@ -2031,6 +2052,8 @@ exit(exitstatus); } +#endif /* __i386__ || __x86_64__ */ + /* * 'sigterm_handler()' - SIGTERM handler. @@ -2039,8 +2062,11 @@ static void sigterm_handler(int sig) /* I - Signal */ { - /* If we started a child process pass the signal on to it... - */ +#if defined(__i386__) || defined(__x86_64__) + /* + * If we started a child process pass the signal on to it... + */ + if (child_pid) { /* @@ -2062,9 +2088,8 @@ exit(CUPS_BACKEND_STOP); } } -} - #endif /* __i386__ || __x86_64__ */ +} #ifdef PARSE_PS_ERRORS @@ -2231,5 +2256,5 @@ /* - * End of "$Id: usb-darwin.c 8896 2009-11-20 01:27:57Z mike $". + * End of "$Id: usb-darwin.c 9319 2010-09-28 19:10:26Z mike $". */ diff -Naur cups-1.4.3/backend/usb-libusb.c cups-1.4.6/backend/usb-libusb.c --- cups-1.4.3/backend/usb-libusb.c 2011-03-23 11:39:56.349045030 +0000 +++ cups-1.4.6/backend/usb-libusb.c 2011-03-23 12:21:16.736543882 +0000 @@ -1,9 +1,9 @@ /* - * "$Id: usb-libusb.c 8813 2009-09-11 20:03:31Z mike $" + * "$Id: usb-libusb.c 9258 2010-08-13 01:34:04Z mike $" * - * Libusb interface code for the Common UNIX Printing System (CUPS). + * Libusb interface code for CUPS. * - * Copyright 2007-2009 by Apple Inc. + * Copyright 2007-2010 by Apple Inc. * * These coded instructions, statements, and computer programs are the * property of Apple Inc. and are protected by Federal copyright @@ -176,7 +176,7 @@ if ((bytes = read(print_fd, buffer, sizeof(buffer))) > 0) { if (usb_bulk_write(printer->handle, printer->write_endp, buffer, - bytes, 45000) < 0) + bytes, 3600000) < 0) { _cupsLangPrintf(stderr, _("ERROR: Unable to write %d bytes to printer!\n"), @@ -522,7 +522,8 @@ if ((sern = cupsGetOption("SERIALNUMBER", num_values, values)) == NULL) if ((sern = cupsGetOption("SERN", num_values, values)) == NULL) - if ((sern = cupsGetOption("SN", num_values, values)) == NULL) + if ((sern = cupsGetOption("SN", num_values, values)) == NULL && + printer->device->descriptor.iSerialNumber) { /* * Try getting the serial number from the device itself... @@ -896,6 +897,6 @@ /* - * End of "$Id: usb-libusb.c 8813 2009-09-11 20:03:31Z mike $". + * End of "$Id: usb-libusb.c 9258 2010-08-13 01:34:04Z mike $". */