From: msweet Date: Wed, 20 Aug 2008 00:21:51 +0000 (+0000) Subject: Merge changes from CUPS 1.4svn-r7851. X-Git-Tag: release-1.6.3~150 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1ff0402e472496cf5165dbd796df1bdc131a360b;p=thirdparty%2Fcups.git Merge changes from CUPS 1.4svn-r7851. git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@913 a1ca3aef-8c08-0410-bb20-df032aa958be --- diff --git a/cups/adminutil.c b/cups/adminutil.c index 3ea7e81af5..96354a1120 100644 --- a/cups/adminutil.c +++ b/cups/adminutil.c @@ -894,7 +894,58 @@ _cupsAdminGetServerSettings( */ if (!http) - http = _cupsConnect(); + { + /* + * See if we are connected to the same server... + */ + + if (cg->http) + { + /* + * Compare the connection hostname, port, and encryption settings to + * the cached defaults; these were initialized the first time we + * connected... + */ + + if (strcmp(cg->http->hostname, cg->server) || + cg->ipp_port != _httpAddrPort(cg->http->hostaddr) || + (cg->http->encryption != cg->encryption && + cg->http->encryption == HTTP_ENCRYPT_NEVER)) + { + /* + * Need to close the current connection because something has changed... + */ + + httpClose(cg->http); + cg->http = NULL; + } + } + + /* + * (Re)connect as needed... + */ + + if (!cg->http) + { + if ((cg->http = _httpCreate(cupsServer(), ippPort(), + cupsEncryption())) == NULL) + { + if (errno) + _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0); + else + _cupsSetError(IPP_SERVICE_UNAVAILABLE, + _("Unable to connect to host."), 1); + + if (num_settings) + *num_settings = 0; + + if (settings) + *settings = NULL; + + return (0); + } + } + } if (!http || !num_settings || !settings) { diff --git a/cups/cups.h b/cups/cups.h index 08aaf3479a..855442a380 100644 --- a/cups/cups.h +++ b/cups/cups.h @@ -295,7 +295,8 @@ extern ssize_t cupsReadResponseData(http_t *http, char *buffer, extern int cupsResolveConflicts(ppd_file_t *ppd, const char *option, const char *choice, int *num_options, - cups_option_t **options); + cups_option_t **options) + _CUPS_API_1_4; extern http_status_t cupsSendRequest(http_t *http, ipp_t *request, const char *resource, size_t length) _CUPS_API_1_4; diff --git a/cups/debug.c b/cups/debug.c index 76dec26ee5..80f28f1c21 100644 --- a/cups/debug.c +++ b/cups/debug.c @@ -15,6 +15,7 @@ * * Contents: * + * debug_vsnprintf() - Format a string into a fixed size buffer. * _cups_debug_printf() - Write a formatted line to the log. * _cups_debug_puts() - Write a single line to the log. */ diff --git a/cups/dest.c b/cups/dest.c index d2a9b34623..cc8f6a35aa 100644 --- a/cups/dest.c +++ b/cups/dest.c @@ -331,7 +331,10 @@ cupsGetDests2(http_t *http, /* I - Connection to server or @code CUPS_HTTP_ */ if (!dests) + { + _cupsSetError(IPP_INTERNAL_ERROR, _("Bad NULL dests pointer"), 1); return (0); + } /* * Initialize destination array... @@ -469,6 +472,9 @@ cupsGetDests2(http_t *http, /* I - Connection to server or @code CUPS_HTTP_ * Return the number of destinations... */ + if (num_dests > 0) + _cupsSetError(IPP_OK, NULL, 0); + return (num_dests); } diff --git a/cups/http-addr.c b/cups/http-addr.c index bde526ffe8..b16961886b 100644 --- a/cups/http-addr.c +++ b/cups/http-addr.c @@ -3,7 +3,7 @@ * * HTTP address routines for the Common UNIX Printing System (CUPS). * - * Copyright 2007 by Apple Inc. + * Copyright 2007-2008 by Apple Inc. * Copyright 1997-2006 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the @@ -18,6 +18,7 @@ * httpAddrEqual() - Compare two addresses. * httpAddrLocalhost() - Check for the local loopback address. * httpAddrLookup() - Lookup the hostname associated with the address. + * _httpAddrPort() - Get the port number associated with an address. * httpAddrString() - Convert an IP address to a dotted string. * httpGetHostByName() - Lookup a hostname or IP address, and return * address records for the specified name. @@ -241,6 +242,25 @@ httpAddrLookup( } +/* + * '_httpAddrPort()' - Get the port number associated with an address. + */ + +int /* O - Port number */ +_httpAddrPort(http_addr_t *addr) /* I - Address */ +{ +#ifdef AF_INET6 + if (addr->addr.sa_family == AF_INET6) + return (ntohs(addr->ipv6.sin6_port)); + else +#endif /* AF_INET6 */ + if (addr->addr.sa_family == AF_INET) + return (ntohs(addr->ipv4.sin_port)); + else + return (ippPort()); +} + + /* * 'httpAddrString()' - Convert an address to a numeric string. * diff --git a/cups/http-addrlist.c b/cups/http-addrlist.c index 265107af04..d5685312ef 100644 --- a/cups/http-addrlist.c +++ b/cups/http-addrlist.c @@ -27,6 +27,7 @@ #include "globals.h" #include "debug.h" #include +#include /* @@ -41,7 +42,18 @@ httpAddrConnect( int *sock) /* O - Socket */ { int val; /* Socket option value */ +#ifdef DEBUG + char temp[256]; /* Temporary address string */ +#endif /* DEBUG */ + + DEBUG_printf(("httpAddrConnect(addrlist=%p, sock=%p)\n", addrlist, sock)); + + if (!sock) + { + errno = EINVAL; + return (NULL); + } /* * Loop through each address until we connect or run out of addresses... @@ -53,7 +65,12 @@ httpAddrConnect( * Create the socket... */ - if ((*sock = (int)socket(addrlist->addr.addr.sa_family, SOCK_STREAM, 0)) < 0) + DEBUG_printf(("httpAddrConnect: Trying %s:%d...\n", + httpAddrString(&(addrlist->addr), temp, sizeof(temp)), + _httpAddrPort(&(addrlist->addr)))); + + if ((*sock = (int)socket(addrlist->addr.addr.sa_family, SOCK_STREAM, + 0)) < 0) { /* * Don't abort yet, as this could just be an issue with the local @@ -113,7 +130,16 @@ httpAddrConnect( if (!connect(*sock, &(addrlist->addr.addr), httpAddrLength(&(addrlist->addr)))) + { + DEBUG_printf(("httpAddrConnect: Connected to %s:%d...\n", + httpAddrString(&(addrlist->addr), temp, sizeof(temp)), + _httpAddrPort(&(addrlist->addr)))); break; + } + + DEBUG_printf(("httpAddrConnect: Unable to connect to %s:%d: %s\n", + httpAddrString(&(addrlist->addr), temp, sizeof(temp)), + _httpAddrPort(&(addrlist->addr)), strerror(errno))); /* * Close this socket and move to the next address... @@ -125,6 +151,7 @@ httpAddrConnect( close(*sock); #endif /* WIN32 */ + *sock = -1; addrlist = addrlist->next; } diff --git a/cups/http-private.h b/cups/http-private.h index f44266ccef..5f29097742 100644 --- a/cups/http-private.h +++ b/cups/http-private.h @@ -258,9 +258,12 @@ extern void _cups_freeifaddrs(struct ifaddrs *addrs); # endif /* !WIN32 */ /* - * Common URI functions... + * Prototypes... */ +extern int _httpAddrPort(http_addr_t *addr); +extern http_t *_httpCreate(const char *host, int port, + http_encryption_t encryption); extern char *_httpEncodeURI(char *dst, const char *src, size_t dstsize); extern const char *_httpResolveURI(const char *uri, char *resolved_uri, diff --git a/cups/http.c b/cups/http.c index 26f2107891..9543c22130 100644 --- a/cups/http.c +++ b/cups/http.c @@ -347,45 +347,79 @@ httpClose(http_t *http) /* I - Connection to server */ /* * 'httpConnect()' - Connect to a HTTP server. + * + * This function is deprecated - use @link httpConnectEncrypt@ instead. + * + * @deprecated@ */ http_t * /* O - New HTTP connection */ httpConnect(const char *host, /* I - Host to connect to */ int port) /* I - Port number */ { - http_encryption_t encryption; /* Type of encryption to use */ + return (httpConnectEncrypt(host, port, HTTP_ENCRYPT_IF_REQUESTED)); +} + + +/* + * 'httpConnectEncrypt()' - Connect to a HTTP server using encryption. + */ + +http_t * /* O - New HTTP connection */ +httpConnectEncrypt( + const char *host, /* I - Host to connect to */ + int port, /* I - Port number */ + http_encryption_t encryption) /* I - Type of encryption to use */ +{ + http_t *http; /* New HTTP connection */ + DEBUG_printf(("httpConnectEncrypt(host=\"%s\", port=%d, encryption=%d)\n", + host, port, encryption)); + /* - * Set the default encryption status... + * Create the HTTP structure... */ - if (port == 443) - encryption = HTTP_ENCRYPT_ALWAYS; - else - encryption = HTTP_ENCRYPT_IF_REQUESTED; + if ((http = _httpCreate(host, port, encryption)) == NULL) + return (NULL); - return (httpConnectEncrypt(host, port, encryption)); + /* + * Connect to the remote system... + */ + + if (!httpReconnect(http)) + return (http); + + /* + * Could not connect to any known address - bail out! + */ + + httpAddrFreeList(http->addrlist); + + free(http); + + return (NULL); } /* - * 'httpConnectEncrypt()' - Connect to a HTTP server using encryption. + * '_httpCreate()' - Create an unconnected HTTP connection. */ -http_t * /* O - New HTTP connection */ -httpConnectEncrypt( - const char *host, /* I - Host to connect to */ +http_t * /* O - HTTP connection */ +_httpCreate( + const char *host, /* I - Hostname */ int port, /* I - Port number */ - http_encryption_t encryption) /* I - Type of encryption to use */ + http_encryption_t encryption) /* I - Encryption to use */ { http_t *http; /* New HTTP connection */ http_addrlist_t *addrlist; /* Host address data */ char service[255]; /* Service name */ - DEBUG_printf(("httpConnectEncrypt(host=\"%s\", port=%d, encryption=%d)\n", - host ? host : "(null)", port, encryption)); + DEBUG_printf(("_httpCreate(host=\"%s\", port=%d, encryption=%d)\n", + host, port, encryption)); if (!host) return (NULL); @@ -411,19 +445,21 @@ httpConnectEncrypt( return (NULL); } - http->version = HTTP_1_1; - http->blocking = 1; + /* + * Initialize the HTTP data... + */ + http->activity = time(NULL); + http->addrlist = addrlist; + http->blocking = 1; http->fd = -1; - #ifdef HAVE_GSSAPI - http->gssctx = GSS_C_NO_CONTEXT; - http->gssname = GSS_C_NO_NAME; + http->gssctx = GSS_C_NO_CONTEXT; + http->gssname = GSS_C_NO_NAME; #endif /* HAVE_GSSAPI */ + http->version = HTTP_1_1; - /* - * Set the encryption status... - */ + strlcpy(http->hostname, host, sizeof(http->hostname)); if (port == 443) /* Always use encryption for https */ http->encryption = HTTP_ENCRYPT_ALWAYS; @@ -431,29 +467,10 @@ httpConnectEncrypt( http->encryption = encryption; /* - * Loop through the addresses we have until one of them connects... + * Return the new structure... */ - strlcpy(http->hostname, host, sizeof(http->hostname)); - - /* - * Connect to the remote system... - */ - - http->addrlist = addrlist; - - if (!httpReconnect(http)) - return (http); - - /* - * Could not connect to any known address - bail out! - */ - - httpAddrFreeList(addrlist); - - free(http); - - return (NULL); + return (http); } @@ -1603,6 +1620,10 @@ int /* O - 0 on success, non-zero on failure */ httpReconnect(http_t *http) /* I - Connection to server */ { http_addrlist_t *addr; /* Connected address */ +#ifdef DEBUG + http_addrlist_t *current; /* Current address */ + char temp[256]; /* Temporary address string */ +#endif /* DEBUG */ DEBUG_printf(("httpReconnect(http=%p)\n", http)); @@ -1612,7 +1633,10 @@ httpReconnect(http_t *http) /* I - Connection to server */ #ifdef HAVE_SSL if (http->tls) + { + DEBUG_puts("httpReconnect: Shutting down SSL/TLS..."); http_shutdown_ssl(http); + } #endif /* HAVE_SSL */ /* @@ -1621,12 +1645,16 @@ httpReconnect(http_t *http) /* I - Connection to server */ if (http->fd >= 0) { + DEBUG_printf(("httpReconnect: Closing socket %d...\n", http->fd)); + #ifdef WIN32 closesocket(http->fd); #else close(http->fd); #endif /* WIN32 */ + usleep(100000); + http->fd = -1; } @@ -1634,6 +1662,13 @@ httpReconnect(http_t *http) /* I - Connection to server */ * Connect to the server... */ +#ifdef DEBUG + for (current = http->addrlist; current; current = current->next) + DEBUG_printf(("httpReconnect: Address %s:%d\n", + httpAddrString(&(current->addr), temp, sizeof(temp)), + _httpAddrPort(&(current->addr)))); +#endif /* DEBUG */ + if ((addr = httpAddrConnect(http->addrlist, &(http->fd))) == NULL) { /* @@ -1647,9 +1682,14 @@ httpReconnect(http_t *http) /* I - Connection to server */ #endif /* WIN32 */ http->status = HTTP_ERROR; + DEBUG_printf(("httpReconnect: httpAddrConnect failed: %s\n", + strerror(http->error))); + return (-1); } + DEBUG_printf(("httpReconnect: New socket=%d\n", http->fd)); + http->hostaddr = &(addr->addr); http->error = 0; http->status = HTTP_CONTINUE; @@ -1676,6 +1716,10 @@ httpReconnect(http_t *http) /* I - Connection to server */ return (http_upgrade(http)); #endif /* HAVE_SSL */ + DEBUG_printf(("httpReconnect: Connected to %s:%d...\n", + httpAddrString(http->hostaddr, temp, sizeof(temp)), + _httpAddrPort(http->hostaddr))); + return (0); } diff --git a/cups/ipp-support.c b/cups/ipp-support.c index 47194d1332..6ab14b16e3 100644 --- a/cups/ipp-support.c +++ b/cups/ipp-support.c @@ -1,5 +1,5 @@ /* - * "$Id: ipp-support.c 7460 2008-04-16 02:19:54Z mike $" + * "$Id: ipp-support.c 7847 2008-08-19 04:22:14Z mike $" * * Internet Printing Protocol support functions for the Common UNIX * Printing System (CUPS). @@ -154,6 +154,90 @@ static char * const ipp_std_ops[] = * const ipp_cups_ops2[] = { "CUPS-Get-Document" + }, + * const ipp_tag_names[] = + { /* Value/group tag names */ + "zero", /* 0x00 */ + "operation-attributes-tag", + /* 0x01 */ + "job-attributes-tag", /* 0x02 */ + "end-of-attributes-tag", + /* 0x03 */ + "printer-attributes-tag", + /* 0x04 */ + "unsupported-attributes-tag", + /* 0x05 */ + "subscription-attributes-tag", + /* 0x06 */ + "event-notification-attributes-tag", + /* 0x07 */ + "unknown-08", /* 0x08 */ + "unknown-09", /* 0x09 */ + "unknown-0a", /* 0x0a */ + "unknown-0b", /* 0x0b */ + "unknown-0c", /* 0x0c */ + "unknown-0d", /* 0x0d */ + "unknown-0e", /* 0x0e */ + "unknown-0f", /* 0x0f */ + "unsupported", /* 0x10 */ + "default", /* 0x11 */ + "unknown", /* 0x12 */ + "no-value", /* 0x13 */ + "unknown-14", /* 0x14 */ + "not-settable", /* 0x15 */ + "delete-attribute", /* 0x16 */ + "admin-define", /* 0x17 */ + "unknown-18", /* 0x18 */ + "unknown-19", /* 0x19 */ + "unknown-1a", /* 0x1a */ + "unknown-1b", /* 0x1b */ + "unknown-1c", /* 0x1c */ + "unknown-1d", /* 0x1d */ + "unknown-1e", /* 0x1e */ + "unknown-1f", /* 0x1f */ + "unknown-20", /* 0x20 */ + "integer", /* 0x21 */ + "boolean", /* 0x22 */ + "enum", /* 0x23 */ + "unknown-24", /* 0x24 */ + "unknown-25", /* 0x25 */ + "unknown-26", /* 0x26 */ + "unknown-27", /* 0x27 */ + "unknown-28", /* 0x28 */ + "unknown-29", /* 0x29 */ + "unknown-2a", /* 0x2a */ + "unknown-2b", /* 0x2b */ + "unknown-2c", /* 0x2c */ + "unknown-2d", /* 0x2d */ + "unknown-2e", /* 0x2e */ + "unknown-2f", /* 0x2f */ + "octetString", /* 0x30 */ + "dateTime", /* 0x31 */ + "resolution", /* 0x32 */ + "rangeOfInteger", /* 0x33 */ + "begCollection", /* 0x34 */ + "textWithLanguage", /* 0x35 */ + "nameWithLanguage", /* 0x36 */ + "endCollection", /* 0x37 */ + "unknown-38", /* 0x38 */ + "unknown-39", /* 0x39 */ + "unknown-3a", /* 0x3a */ + "unknown-3b", /* 0x3b */ + "unknown-3c", /* 0x3c */ + "unknown-3d", /* 0x3d */ + "unknown-3e", /* 0x3e */ + "unknown-3f", /* 0x3f */ + "unknown-40", /* 0x40 */ + "textWithoutLanguage",/* 0x41 */ + "nameWithoutLanguage",/* 0x42 */ + "unknown-43", /* 0x43 */ + "keyword", /* 0x44 */ + "uri", /* 0x45 */ + "uriScheme", /* 0x46 */ + "charset", /* 0x47 */ + "naturalLanguage", /* 0x48 */ + "mimeMediaType", /* 0x49 */ + "memberAttrName" /* 0x4a */ }; @@ -371,5 +455,62 @@ ippSetPort(int p) /* I - Port number to use */ /* - * End of "$Id: ipp-support.c 7460 2008-04-16 02:19:54Z mike $". + * 'ippTagString()' - Return the tag name corresponding to a tag value. + * + * The returned names are defined in RFC 2911 and 3382. + * + * @since CUPS 1.4@ + */ + +const char * /* O - Tag name */ +ippTagString(ipp_tag_t tag) /* I - Tag value */ +{ + if (tag < (ipp_tag_t)(sizeof(ipp_tag_names) / sizeof(ipp_tag_names[0]))) + return (ipp_tag_names[tag]); + else + return ("UNKNOWN"); +} + + +/* + * 'ippTagValue()' - Return the tag value corresponding to a tag name. + * + * The tag names are defined in RFC 2911 and 3382. + * + * @since CUPS 1.4@ + */ + +ipp_tag_t /* O - Tag value */ +ippTagValue(const char *name) /* I - Tag name */ +{ + int i; /* Looping var */ + + + for (i = 0; i < (sizeof(ipp_tag_names) / sizeof(ipp_tag_names[0])); i ++) + if (!strcasecmp(name, ipp_tag_names[i])) + return ((ipp_tag_t)i); + + if (!strcasecmp(name, "operation")) + return (IPP_TAG_OPERATION); + else if (!strcasecmp(name, "job")) + return (IPP_TAG_JOB); + else if (!strcasecmp(name, "printer")) + return (IPP_TAG_PRINTER); + else if (!strcasecmp(name, "subscription")) + return (IPP_TAG_SUBSCRIPTION); + else if (!strcasecmp(name, "language")) + return (IPP_TAG_LANGUAGE); + else if (!strcasecmp(name, "mimetype")) + return (IPP_TAG_MIMETYPE); + else if (!strcasecmp(name, "name")) + return (IPP_TAG_NAME); + else if (!strcasecmp(name, "text")) + return (IPP_TAG_TEXT); + else + return (IPP_TAG_ZERO); +} + + +/* + * End of "$Id: ipp-support.c 7847 2008-08-19 04:22:14Z mike $". */ diff --git a/cups/ipp.c b/cups/ipp.c index 88a42f01c9..8627ad4fe7 100644 --- a/cups/ipp.c +++ b/cups/ipp.c @@ -97,9 +97,10 @@ ippAddBoolean(ipp_t *ipp, /* I - IPP message */ ipp_attribute_t *attr; /* New attribute */ - DEBUG_printf(("ippAddBoolean(%p, %02x, \'%s\', %d)\n", ipp, group, name, value)); + DEBUG_printf(("ippAddBoolean(ipp=%p, group=%02x(%s), name=\"%s\", value=%d)\n", + ipp, group, ippTagString(group), name, value)); - if (ipp == NULL || name == NULL) + if (!ipp || !name) return (NULL); if ((attr = _ippAddAttr(ipp, 1)) == NULL) @@ -130,10 +131,11 @@ ippAddBooleans(ipp_t *ipp, /* I - IPP message */ ipp_value_t *value; /* Current value */ - DEBUG_printf(("ippAddBooleans(%p, %02x, \'%s\', %d, %p)\n", ipp, - group, name, num_values, values)); + DEBUG_printf(("ippAddBooleans(ipp=%p, group=%02x(%s), name=\"%s\", " + "num_values=%d, values=%p)\n", ipp, group, ippTagString(group), + name, num_values, values)); - if (ipp == NULL || name == NULL || num_values < 1) + if (!ipp || !name || num_values < 1) return (NULL); if ((attr = _ippAddAttr(ipp, num_values)) == NULL) @@ -168,10 +170,10 @@ ippAddCollection(ipp_t *ipp, /* I - IPP message */ ipp_attribute_t *attr; /* New attribute */ - DEBUG_printf(("ippAddCollection(%p, %02x, \'%s\', %p)\n", ipp, group, name, - value)); + DEBUG_printf(("ippAddCollection(ipp=%p, group=%02x(%s), name=\"%s\", " + "value=%p)\n", ipp, group, ippTagString(group), name, value)); - if (ipp == NULL || name == NULL) + if (!ipp || !name) return (NULL); if ((attr = _ippAddAttr(ipp, 1)) == NULL) @@ -205,10 +207,11 @@ ippAddCollections( ipp_value_t *value; /* Current value */ - DEBUG_printf(("ippAddCollections(%p, %02x, \'%s\', %d, %p)\n", ipp, - group, name, num_values, values)); + DEBUG_printf(("ippAddCollections(ipp=%p, group=%02x(%s), name=\"%s\", " + "num_values=%d, values=%p)\n", ipp, group, ippTagString(group), + name, num_values, values)); - if (ipp == NULL || name == NULL || num_values < 1) + if (!ipp || !name || num_values < 1) return (NULL); if ((attr = _ippAddAttr(ipp, num_values)) == NULL) @@ -241,10 +244,10 @@ ippAddDate(ipp_t *ipp, /* I - IPP message */ ipp_attribute_t *attr; /* New attribute */ - DEBUG_printf(("ippAddDate(%p, %02x, \'%s\', %p)\n", ipp, group, name, - value)); + DEBUG_printf(("ippAddDate(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)\n", + ipp, group, ippTagString(group), name, value)); - if (ipp == NULL || name == NULL || value == NULL) + if (!ipp || !name || !value) return (NULL); if ((attr = _ippAddAttr(ipp, 1)) == NULL) @@ -273,10 +276,11 @@ ippAddInteger(ipp_t *ipp, /* I - IPP message */ ipp_attribute_t *attr; /* New attribute */ - DEBUG_printf(("ippAddInteger(%p, %d, \'%s\', %d)\n", ipp, group, name, - value)); + DEBUG_printf(("ippAddInteger(ipp=%p, group=%02x(%s), type=%02x(%s), " + "name=\"%s\", value=%d)\n", ipp, group, ippTagString(group), + type, ippTagString(type), name, value)); - if (ipp == NULL || name == NULL) + if (!ipp || !name) return (NULL); if ((attr = _ippAddAttr(ipp, 1)) == NULL) @@ -308,7 +312,12 @@ ippAddIntegers(ipp_t *ipp, /* I - IPP message */ ipp_value_t *value; /* Current value */ - if (ipp == NULL || name == NULL || num_values < 1) + DEBUG_printf(("ippAddIntegers(ipp=%p, group=%02x(%s), type=%02x(%s), " + "name=\"%s\", num_values=%d, values=%p)\n", ipp, + group, ippTagString(group), type, ippTagString(type), name, + num_values, values)); + + if (!ipp || !name || num_values < 1) return (NULL); if ((attr = _ippAddAttr(ipp, num_values)) == NULL) @@ -395,7 +404,12 @@ ippAddString(ipp_t *ipp, /* I - IPP message */ *bufptr; /* Pointer into buffer */ - if (ipp == NULL || name == NULL) + DEBUG_printf(("ippAddString(ipp=%p, group=%02x(%s), type=%02x(%s), " + "name=\"%s\", charset=\"%s\", value=\"%s\")\n", ipp, + group, ippTagString(group), type, ippTagString(type), name, + charset, value)); + + if (!ipp || !name) return (NULL); if ((attr = _ippAddAttr(ipp, 1)) == NULL) @@ -459,7 +473,12 @@ ippAddStrings( ipp_value_t *value; /* Current value */ - if (ipp == NULL || name == NULL || num_values < 1) + DEBUG_printf(("ippAddStrings(ipp=%p, group=%02x(%s), type=%02x(%s), " + "name=\"%s\", num_values=%d, charset=\"%s\", values=%p)\n", ipp, + group, ippTagString(group), type, ippTagString(type), name, + num_values, charset, values)); + + if (!ipp || !name || num_values < 1) return (NULL); if ((attr = _ippAddAttr(ipp, num_values)) == NULL) @@ -516,7 +535,11 @@ ippAddRange(ipp_t *ipp, /* I - IPP message */ ipp_attribute_t *attr; /* New attribute */ - if (ipp == NULL || name == NULL) + DEBUG_printf(("ippAddRange(ipp=%p, group=%02x(%s), name=\"%s\", lower=%d, " + "upper=%d)\n", ipp, group, ippTagString(group), name, lower, + upper)); + + if (!ipp || !name) return (NULL); if ((attr = _ippAddAttr(ipp, 1)) == NULL) @@ -549,7 +572,11 @@ ippAddRanges(ipp_t *ipp, /* I - IPP message */ ipp_value_t *value; /* Current value */ - if (ipp == NULL || name == NULL || num_values < 1) + DEBUG_printf(("ippAddRanges(ipp=%p, group=%02x(%s), name=\"%s\", " + "num_values=%d, lower=%p, upper=%p)\n", ipp, group, + ippTagString(group), name, num_values, lower, upper)); + + if (!ipp || !name || num_values < 1) return (NULL); if ((attr = _ippAddAttr(ipp, num_values)) == NULL) @@ -587,7 +614,11 @@ ippAddResolution(ipp_t *ipp, /* I - IPP message */ ipp_attribute_t *attr; /* New attribute */ - if (ipp == NULL || name == NULL) + DEBUG_printf(("ippAddResolution(ipp=%p, group=%02x(%s), name=\"%s\", " + "units=%d, xres=%d, yres=%d)\n", ipp, group, + ippTagString(group), name, units, xres, yres)); + + if (!ipp || !name) return (NULL); if ((attr = _ippAddAttr(ipp, 1)) == NULL) @@ -622,7 +653,11 @@ ippAddResolutions(ipp_t *ipp, /* I - IPP message */ ipp_value_t *value; /* Current value */ - if (ipp == NULL || name == NULL || num_values < 1) + DEBUG_printf(("ippAddResolutions(ipp=%p, group=%02x(%s), name=\"%s\", " + "num_value=%d, units=%d, xres=%p, yres=%p)\n", ipp, group, + ippTagString(group), name, num_values, units, xres, yres)); + + if (!ipp || !name || num_values < 1) return (NULL); if ((attr = _ippAddAttr(ipp, num_values)) == NULL) @@ -656,9 +691,9 @@ ippAddSeparator(ipp_t *ipp) /* I - IPP message */ ipp_attribute_t *attr; /* New attribute */ - DEBUG_printf(("ippAddSeparator(%p)\n", ipp)); + DEBUG_printf(("ippAddSeparator(ipp=%p)\n", ipp)); - if (ipp == NULL) + if (!ipp) return (NULL); if ((attr = _ippAddAttr(ipp, 0)) == NULL) @@ -683,6 +718,9 @@ ippDateToTime(const ipp_uchar_t *date) /* I - RFC 1903 date info */ time_t t; /* Computed time */ + if (!date) + return (0); + memset(&unixdate, 0, sizeof(unixdate)); /* @@ -731,9 +769,9 @@ ippDelete(ipp_t *ipp) /* I - IPP message */ *next; /* Next attribute */ - DEBUG_printf(("ippDelete(): %p\n", ipp)); + DEBUG_printf(("ippDelete(ipp=%p)\n", ipp)); - if (ipp == NULL) + if (!ipp) return; for (attr = ipp->attrs; attr != NULL; attr = next) @@ -761,6 +799,8 @@ ippDeleteAttribute( *prev; /* Previous attribute */ + DEBUG_printf(("ippDeleteAttribute(ipp=%p, attr=%p)\n", ipp, attr)); + /* * Find the attribute in the list... */ @@ -801,9 +841,10 @@ ippFindAttribute(ipp_t *ipp, /* I - IPP message */ const char *name, /* I - Name of attribute */ ipp_tag_t type) /* I - Type of attribute */ { - DEBUG_printf(("ippFindAttribute(%p, \'%s\')\n", ipp, name)); + DEBUG_printf(("ippFindAttribute(ipp=%p, name=\"%s\", type=%02x(%s))\n", ipp, + name, type, ippTagString(type))); - if (ipp == NULL || name == NULL) + if (!ipp || !name) return (NULL); /* @@ -833,9 +874,10 @@ ippFindNextAttribute(ipp_t *ipp, /* I - IPP message */ ipp_tag_t value_tag; /* Value tag */ - DEBUG_printf(("ippFindNextAttribute(%p, \'%s\')\n", ipp, name)); + DEBUG_printf(("ippFindNextAttribute(ipp=%p, name=\"%s\", type=%02x(%s))\n", + ipp, name, type, ippTagString(type))); - if (ipp == NULL || name == NULL) + if (!ipp || !name) return (NULL); if (ipp->current) @@ -851,7 +893,7 @@ ippFindNextAttribute(ipp_t *ipp, /* I - IPP message */ for (; attr != NULL; ipp->prev = attr, attr = attr->next) { - DEBUG_printf(("ippFindAttribute: attr = %p, name = \'%s\'\n", attr, + DEBUG_printf(("ippFindAttribute: attr=%p, name=\"%s\"\n", attr, attr->name)); value_tag = (ipp_tag_t)(attr->value_tag & IPP_TAG_MASK); @@ -930,6 +972,8 @@ ippNewRequest(ipp_op_t op) /* I - Operation code */ cups_lang_t *language; /* Current language localization */ + DEBUG_printf(("ippNewRequest(op=%02x(%s))\n", op, ippOpString(op))); + /* * Create a new IPP message... */ @@ -979,7 +1023,7 @@ ippRead(http_t *http, /* I - HTTP connection */ DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT "\n", http, ipp, CUPS_LLCAST (http ? http->data_remaining : -1))); - if (http == NULL) + if (!http) return (IPP_ERROR); DEBUG_printf(("ippRead: http->state=%d, http->used=%d\n", http->state, @@ -1000,7 +1044,7 @@ ipp_state_t /* O - Current state */ ippReadFile(int fd, /* I - HTTP data */ ipp_t *ipp) /* I - IPP data */ { - DEBUG_printf(("ippReadFile(%d, %p)\n", fd, ipp)); + DEBUG_printf(("ippReadFile(fd=%d, ipp=%p)\n", fd, ipp)); return (ippReadIO(&fd, (ipp_iocb_t)ipp_read_file, 1, NULL, ipp)); } @@ -1035,7 +1079,7 @@ ippReadIO(void *src, /* I - Data source */ src, cb, blocking, parent, ipp)); DEBUG_printf(("ippReadIO: ipp->state=%d\n", ipp->state)); - if (src == NULL || ipp == NULL) + if (!src || !ipp) return (IPP_ERROR); switch (ipp->state) @@ -1062,8 +1106,8 @@ ippReadIO(void *src, /* I - Data source */ if (buffer[0] != 1) { - DEBUG_printf(("ippReadIO: version number (%d.%d) is bad.\n", buffer[0], - buffer[1])); + DEBUG_printf(("ippReadIO: version number (%d.%d) is bad.\n", + buffer[0], buffer[1])); return (IPP_ERROR); } @@ -1135,12 +1179,13 @@ ippReadIO(void *src, /* I - Data source */ ipp->curtag = tag; ipp->current = NULL; - DEBUG_printf(("ippReadIO: group tag = %x, ipp->prev=%p\n", tag, - ipp->prev)); + DEBUG_printf(("ippReadIO: group tag=%x(%s), ipp->prev=%p\n", tag, + ippTagString(tag), ipp->prev)); continue; } - DEBUG_printf(("ippReadIO: value tag = %x\n", tag)); + DEBUG_printf(("ippReadIO: value tag=%x(%s)\n", tag, + ippTagString(tag))); /* * Get the name... @@ -1160,7 +1205,7 @@ ippReadIO(void *src, /* I - Data source */ return (IPP_ERROR); } - DEBUG_printf(("ippReadIO: name length = %d\n", n)); + DEBUG_printf(("ippReadIO: name length=%d\n", n)); if (n == 0 && tag != IPP_TAG_MEMBERNAME && tag != IPP_TAG_END_COLLECTION) @@ -1188,19 +1233,30 @@ ippReadIO(void *src, /* I - Data source */ attr->value_tag = tag; } - else if (value_tag >= IPP_TAG_TEXTLANG && - value_tag <= IPP_TAG_MIMETYPE) + else if ((value_tag >= IPP_TAG_TEXTLANG && + value_tag <= IPP_TAG_MIMETYPE)) { /* * String values can sometimes come across in different * forms; accept sets of differing values... */ - if (tag < IPP_TAG_TEXTLANG || tag > IPP_TAG_MIMETYPE) + if ((tag < IPP_TAG_TEXTLANG || tag > IPP_TAG_MIMETYPE) && + tag != IPP_TAG_NOVALUE) + { + DEBUG_printf(("ippReadIO: 1setOf value tag %x(%s) != %x(%s)\n", + value_tag, ippTagString(value_tag), tag, + ippTagString(tag))); return (IPP_ERROR); + } } else if (value_tag != tag) + { + DEBUG_printf(("ippReadIO: value tag %x(%s) != %x(%s)\n", + value_tag, ippTagString(value_tag), tag, + ippTagString(tag))); return (IPP_ERROR); + } /* * Finally, reallocate the attribute array as needed... @@ -1257,8 +1313,8 @@ ippReadIO(void *src, /* I - Data source */ attr = ipp->current = _ippAddAttr(ipp, 1); - DEBUG_printf(("ippReadIO: membername, ipp->current=%p, ipp->prev=%p\n", - ipp->current, ipp->prev)); + DEBUG_printf(("ippReadIO: membername, ipp->current=%p, " + "ipp->prev=%p\n", ipp->current, ipp->prev)); attr->group_tag = ipp->curtag; attr->value_tag = IPP_TAG_ZERO; @@ -1287,8 +1343,8 @@ ippReadIO(void *src, /* I - Data source */ return (IPP_ERROR); } - DEBUG_printf(("ippReadIO: name=\'%s\', ipp->current=%p, ipp->prev=%p\n", - buffer, ipp->current, ipp->prev)); + DEBUG_printf(("ippReadIO: name=\"%s\", ipp->current=%p, " + "ipp->prev=%p\n", buffer, ipp->current, ipp->prev)); attr->group_tag = ipp->curtag; attr->value_tag = tag; @@ -1310,7 +1366,7 @@ ippReadIO(void *src, /* I - Data source */ } n = (buffer[0] << 8) | buffer[1]; - DEBUG_printf(("ippReadIO: value length = %d\n", n)); + DEBUG_printf(("ippReadIO: value length=%d\n", n)); switch (tag) { @@ -1350,6 +1406,15 @@ ippReadIO(void *src, /* I - Data source */ value->boolean = buffer[0]; break; + case IPP_TAG_NOVALUE : + if (attr->value_tag == IPP_TAG_NOVALUE) + { + if (n == 0) + break; + + attr->value_tag = IPP_TAG_TEXT; + } + case IPP_TAG_TEXT : case IPP_TAG_NAME : case IPP_TAG_KEYWORD : @@ -1372,7 +1437,7 @@ ippReadIO(void *src, /* I - Data source */ buffer[n] = '\0'; value->string.text = _cupsStrAlloc((char *)buffer); - DEBUG_printf(("ippReadIO: value = \'%s\'\n", + DEBUG_printf(("ippReadIO: value=\"%s\"\n", value->string.text)); break; @@ -1496,7 +1561,8 @@ ippReadIO(void *src, /* I - Data source */ if (n > 0) { - DEBUG_puts("ippReadIO: begCollection tag with value length > 0!"); + DEBUG_puts("ippReadIO: begCollection tag with value length " + "> 0!"); return (IPP_ERROR); } @@ -1510,7 +1576,8 @@ ippReadIO(void *src, /* I - Data source */ case IPP_TAG_END_COLLECTION : if (n > 0) { - DEBUG_puts("ippReadIO: endCollection tag with value length > 0!"); + DEBUG_puts("ippReadIO: endCollection tag with value length " + "> 0!"); return (IPP_ERROR); } @@ -1547,7 +1614,7 @@ ippReadIO(void *src, /* I - Data source */ attr->num_values --; - DEBUG_printf(("ippReadIO: member name = \"%s\"\n", attr->name)); + DEBUG_printf(("ippReadIO: member name=\"%s\"\n", attr->name)); break; default : /* Other unsupported values */ @@ -1663,9 +1730,9 @@ ipp_state_t /* O - Current state */ ippWrite(http_t *http, /* I - HTTP connection */ ipp_t *ipp) /* I - IPP data */ { - DEBUG_printf(("ippWrite(%p, %p)\n", http, ipp)); + DEBUG_printf(("ippWrite(http=%p, ipp=%p)\n", http, ipp)); - if (http == NULL) + if (!http) return (IPP_ERROR); return (ippWriteIO(http, (ipp_iocb_t)httpWrite2, @@ -1683,7 +1750,7 @@ ipp_state_t /* O - Current state */ ippWriteFile(int fd, /* I - HTTP data */ ipp_t *ipp) /* I - IPP data */ { - DEBUG_printf(("ippWriteFile(%d, %p)\n", fd, ipp)); + DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)\n", fd, ipp)); ipp->state = IPP_IDLE; @@ -1713,10 +1780,10 @@ ippWriteIO(void *dst, /* I - Destination */ ipp_value_t *value; /* Current value */ - DEBUG_printf(("ippWriteIO(%p, %p, %d, %p, %p)\n", dst, cb, blocking, - parent, ipp)); + DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)\n", + dst, cb, blocking, parent, ipp)); - if (dst == NULL || ipp == NULL) + if (!dst || !ipp) return (IPP_ERROR); switch (ipp->state) @@ -1764,8 +1831,10 @@ ippWriteIO(void *dst, /* I - Destination */ ipp->curtag = IPP_TAG_ZERO; DEBUG_printf(("ippWriteIO: version=%d.%d\n", buffer[0], buffer[1])); - DEBUG_printf(("ippWriteIO: op_status=%04x\n", ipp->request.any.op_status)); - DEBUG_printf(("ippWriteIO: request_id=%d\n", ipp->request.any.request_id)); + DEBUG_printf(("ippWriteIO: op_status=%04x\n", + ipp->request.any.op_status)); + DEBUG_printf(("ippWriteIO: request_id=%d\n", + ipp->request.any.request_id)); /* * If blocking is disabled, stop here... @@ -1797,7 +1866,8 @@ ippWriteIO(void *dst, /* I - Destination */ if (attr->group_tag == IPP_TAG_ZERO) continue; - DEBUG_printf(("ippWriteIO: wrote group tag = %x\n", attr->group_tag)); + DEBUG_printf(("ippWriteIO: wrote group tag=%x(%s)\n", + attr->group_tag, ippTagString(attr->group_tag))); *bufptr++ = attr->group_tag; } else if (attr->group_tag == IPP_TAG_ZERO) @@ -1828,8 +1898,10 @@ ippWriteIO(void *dst, /* I - Destination */ * Write the value tag, name length, and name string... */ - DEBUG_printf(("ippWriteIO: writing value tag = %x\n", attr->value_tag)); - DEBUG_printf(("ippWriteIO: writing name = %d, \'%s\'\n", n, attr->name)); + DEBUG_printf(("ippWriteIO: writing value tag=%x(%s)\n", + attr->value_tag, ippTagString(attr->value_tag))); + DEBUG_printf(("ippWriteIO: writing name=%d,\"%s\"\n", n, + attr->name)); *bufptr++ = attr->value_tag; *bufptr++ = n >> 8; @@ -1852,11 +1924,13 @@ ippWriteIO(void *dst, /* I - Destination */ * and empty name for the collection member attribute... */ - DEBUG_printf(("ippWriteIO: writing value tag = %x\n", + DEBUG_printf(("ippWriteIO: writing value tag=%x(memberName)\n", IPP_TAG_MEMBERNAME)); - DEBUG_printf(("ippWriteIO: writing name = %d, \'%s\'\n", n, attr->name)); - DEBUG_printf(("ippWriteIO: writing value tag = %x\n", attr->value_tag)); - DEBUG_puts("ippWriteIO: writing name = 0, \'\'\n"); + DEBUG_printf(("ippWriteIO: writing name=%d,\"%s\"\n", n, + attr->name)); + DEBUG_printf(("ippWriteIO: writing value tag=%x(%s)\n", + attr->value_tag, ippTagString(attr->value_tag))); + DEBUG_puts("ippWriteIO: writing name=0,\"\"\n"); *bufptr++ = IPP_TAG_MEMBERNAME; *bufptr++ = 0; @@ -1887,7 +1961,8 @@ ippWriteIO(void *dst, /* I - Destination */ { if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0) { - DEBUG_puts("ippWriteIO: Could not write IPP attribute..."); + DEBUG_puts("ippWriteIO: Could not write IPP " + "attribute..."); return (IPP_ERROR); } @@ -1931,7 +2006,8 @@ ippWriteIO(void *dst, /* I - Destination */ { if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0) { - DEBUG_puts("ippWriteIO: Could not write IPP attribute..."); + DEBUG_puts("ippWriteIO: Could not write IPP " + "attribute..."); return (IPP_ERROR); } @@ -1981,15 +2057,17 @@ ippWriteIO(void *dst, /* I - Destination */ * values with a zero-length name... */ - DEBUG_printf(("ippWriteIO: writing value tag = %x\n", - attr->value_tag)); - DEBUG_printf(("ippWriteIO: writing name = 0, \'\'\n")); + DEBUG_printf(("ippWriteIO: writing value tag=%x(%s)\n", + attr->value_tag, + ippTagString(attr->value_tag))); + DEBUG_printf(("ippWriteIO: writing name=0,\"\"\n")); if ((sizeof(buffer) - (bufptr - buffer)) < 3) { if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0) { - DEBUG_puts("ippWriteIO: Could not write IPP attribute..."); + DEBUG_puts("ippWriteIO: Could not write IPP " + "attribute..."); return (IPP_ERROR); } @@ -2009,14 +2087,15 @@ ippWriteIO(void *dst, /* I - Destination */ if (n > (sizeof(buffer) - 2)) return (IPP_ERROR); - DEBUG_printf(("ippWriteIO: writing string = %d, \'%s\'\n", n, + DEBUG_printf(("ippWriteIO: writing string=%d,\"%s\"\n", n, value->string.text)); if ((int)(sizeof(buffer) - (bufptr - buffer)) < (n + 2)) { if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0) { - DEBUG_puts("ippWriteIO: Could not write IPP attribute..."); + DEBUG_puts("ippWriteIO: Could not write IPP " + "attribute..."); return (IPP_ERROR); } @@ -2053,7 +2132,8 @@ ippWriteIO(void *dst, /* I - Destination */ { if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0) { - DEBUG_puts("ippWriteIO: Could not write IPP attribute..."); + DEBUG_puts("ippWriteIO: Could not write IPP " + "attribute..."); return (IPP_ERROR); } @@ -2096,7 +2176,8 @@ ippWriteIO(void *dst, /* I - Destination */ { if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0) { - DEBUG_puts("ippWriteIO: Could not write IPP attribute..."); + DEBUG_puts("ippWriteIO: Could not write IPP " + "attribute..."); return (IPP_ERROR); } @@ -2147,7 +2228,8 @@ ippWriteIO(void *dst, /* I - Destination */ { if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0) { - DEBUG_puts("ippWriteIO: Could not write IPP attribute..."); + DEBUG_puts("ippWriteIO: Could not write IPP " + "attribute..."); return (IPP_ERROR); } @@ -2204,7 +2286,8 @@ ippWriteIO(void *dst, /* I - Destination */ { if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0) { - DEBUG_puts("ippWriteIO: Could not write IPP attribute..."); + DEBUG_puts("ippWriteIO: Could not write IPP " + "attribute..."); return (IPP_ERROR); } @@ -2241,7 +2324,8 @@ ippWriteIO(void *dst, /* I - Destination */ { if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0) { - DEBUG_puts("ippWriteIO: Could not write IPP attribute..."); + DEBUG_puts("ippWriteIO: Could not write IPP " + "attribute..."); return (IPP_ERROR); } @@ -2302,7 +2386,8 @@ ippWriteIO(void *dst, /* I - Destination */ { if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0) { - DEBUG_puts("ippWriteIO: Could not write IPP attribute..."); + DEBUG_puts("ippWriteIO: Could not write IPP " + "attribute..."); return (IPP_ERROR); } @@ -2330,7 +2415,8 @@ ippWriteIO(void *dst, /* I - Destination */ if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0) { - DEBUG_puts("ippWriteIO: Could not write IPP attribute..."); + DEBUG_puts("ippWriteIO: Could not write IPP " + "attribute..."); return (IPP_ERROR); } @@ -2363,7 +2449,8 @@ ippWriteIO(void *dst, /* I - Destination */ { if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0) { - DEBUG_puts("ippWriteIO: Could not write IPP attribute..."); + DEBUG_puts("ippWriteIO: Could not write IPP " + "attribute..."); return (IPP_ERROR); } @@ -2391,7 +2478,8 @@ ippWriteIO(void *dst, /* I - Destination */ { if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0) { - DEBUG_puts("ippWriteIO: Could not write IPP attribute..."); + DEBUG_puts("ippWriteIO: Could not write IPP " + "attribute..."); return (IPP_ERROR); } @@ -2487,9 +2575,9 @@ _ippAddAttr(ipp_t *ipp, /* I - IPP message */ ipp_attribute_t *attr; /* New attribute */ - DEBUG_printf(("_ippAddAttr(%p, %d)\n", ipp, num_values)); + DEBUG_printf(("_ippAddAttr(ipp=%p, num_values=%d)\n", ipp, num_values)); - if (ipp == NULL || num_values < 0) + if (!ipp || num_values < 0) return (NULL); attr = calloc(sizeof(ipp_attribute_t) + @@ -2524,7 +2612,7 @@ _ippFreeAttr(ipp_attribute_t *attr) /* I - Attribute to free */ ipp_value_t *value; /* Current value */ - DEBUG_printf(("_ippFreeAttr(): %p\n", attr)); + DEBUG_printf(("_ippFreeAttr(attr=%p)\n", attr)); switch (attr->value_tag) { diff --git a/cups/ipp.h b/cups/ipp.h index 9073c57757..98b494614b 100644 --- a/cups/ipp.h +++ b/cups/ipp.h @@ -483,6 +483,10 @@ extern ipp_state_t ippReadIO(void *src, ipp_iocb_t cb, int blocking, extern ipp_state_t ippWriteIO(void *dst, ipp_iocb_t cb, int blocking, ipp_t *parent, ipp_t *ipp) _CUPS_API_1_2; +/**** New in CUPS 1.4 ****/ +extern const char *ippTagString(ipp_tag_t tag) _CUPS_API_1_4; +extern ipp_tag_t ippTagValue(const char *name) _CUPS_API_1_4; + /* * C++ magic... diff --git a/cups/libcups.exp b/cups/libcups.exp index 3da3642b03..4908e8bbc3 100644 --- a/cups/libcups.exp +++ b/cups/libcups.exp @@ -41,6 +41,8 @@ __cupsStrFormatd __cupsStrFree __cupsStrScand __cupsStrStatistics +__httpAddrPort +__httpCreate __httpEncodeURI __httpReadCDSA __httpResolveURI diff --git a/cups/libcups_s.exp b/cups/libcups_s.exp index bb480e85d6..97aa9c0463 100644 --- a/cups/libcups_s.exp +++ b/cups/libcups_s.exp @@ -41,7 +41,9 @@ _cups_freeifaddrs _cups_strcpy _cups_strlcat _cups_strlcpy +_httpAddrPort _httpBIOMethods +_httpCreate _httpEncodeURI _httpResolveURI _ippAddAttr diff --git a/cups/request.c b/cups/request.c index 02098b4143..0523751a82 100644 --- a/cups/request.c +++ b/cups/request.c @@ -369,10 +369,12 @@ cupsGetResponse(http_t *http, /* I - Connection to server or @code CUPS_HTTP * Wait for a response from the server... */ - DEBUG_puts("cupsGetResponse: Update loop..."); + DEBUG_printf(("cupsGetResponse: Update loop, http->status=%d...\n", + http->status)); - while ((status = httpUpdate(http)) == HTTP_CONTINUE) - /* Do nothing but update */; + status = http->status; + while (status == HTTP_CONTINUE) + status = httpUpdate(http); DEBUG_printf(("cupsGetResponse: status=%d\n", status)); @@ -572,6 +574,14 @@ cupsSendRequest(http_t *http, /* I - Connection to server or @code CUPS_HTTP return (HTTP_SERVICE_UNAVAILABLE); #endif /* HAVE_SSL */ + /* + * Reconnect if the last response had a "Connection: close"... + */ + + if (!strcasecmp(http->fields[HTTP_FIELD_CONNECTION], "close")) + if (httpReconnect(http)) + return (HTTP_SERVICE_UNAVAILABLE); + /* * Loop until we can send the request without authorization problems. */ diff --git a/cups/snmp.c b/cups/snmp.c index 34e7e2a57d..943e8ed90b 100644 --- a/cups/snmp.c +++ b/cups/snmp.c @@ -715,6 +715,7 @@ _cupsSNMPWrite( unsigned char buffer[CUPS_SNMP_MAX_PACKET]; /* SNMP message buffer */ int bytes; /* Size of message */ + http_addr_t temp; /* Copy of address */ /* @@ -776,15 +777,17 @@ _cupsSNMPWrite( * Send the message... */ + temp = *address; + #ifdef AF_INET6 - if (address->addr.sa_family == AF_INET6) - address->ipv6.sin6_port = htons(CUPS_SNMP_PORT); + if (temp.addr.sa_family == AF_INET6) + temp.ipv6.sin6_port = htons(CUPS_SNMP_PORT); else #endif /* AF_INET6 */ - address->ipv4.sin_port = htons(CUPS_SNMP_PORT); + temp.ipv4.sin_port = htons(CUPS_SNMP_PORT); - return (sendto(fd, buffer, bytes, 0, (void *)address, - httpAddrLength(address)) == bytes); + return (sendto(fd, buffer, bytes, 0, (void *)&temp, + httpAddrLength(&temp)) == bytes); } diff --git a/cups/util.c b/cups/util.c index f52bbe7f08..c94c80b98b 100644 --- a/cups/util.c +++ b/cups/util.c @@ -949,7 +949,8 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL resource, sizeof(resource), 0)) return (HTTP_NOT_FOUND); - DEBUG_printf(("cupsGetPPD3: Printer hostname=\"%s\", port=%d\n", hostname, port)); + DEBUG_printf(("cupsGetPPD3: Printer hostname=\"%s\", port=%d\n", hostname, + port)); /* * Remap local hostname to localhost... @@ -957,7 +958,7 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL httpGetHostname(NULL, localhost, sizeof(localhost)); - DEBUG_printf(("Local hostname=\"%s\"\n", localhost)); + DEBUG_printf(("cupsGetPPD3: Local hostname=\"%s\"\n", localhost)); if (!strcasecmp(localhost, hostname)) strcpy(hostname, "localhost"); @@ -967,19 +968,10 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL */ httpGetHostname(http, http_hostname, sizeof(http_hostname)); + http_port = _httpAddrPort(http->hostaddr); -#ifdef AF_INET6 - if (http->hostaddr->addr.sa_family == AF_INET6) - http_port = ntohs(http->hostaddr->ipv6.sin6_port); - else -#endif /* AF_INET6 */ - if (http->hostaddr->addr.sa_family == AF_INET) - http_port = ntohs(http->hostaddr->ipv4.sin_port); - else - http_port = ippPort(); - - DEBUG_printf(("Connection hostname=\"%s\", port=%d\n", http_hostname, - http_port)); + DEBUG_printf(("cupsGetPPD3: Connection hostname=\"%s\", port=%d\n", + http_hostname, http_port)); /* * Reconnect to the correct server as needed... @@ -990,7 +982,7 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL else if ((http2 = httpConnectEncrypt(hostname, port, cupsEncryption())) == NULL) { - DEBUG_puts("Unable to connect to server!"); + DEBUG_puts("cupsGetPPD3: Unable to connect to server!"); return (HTTP_SERVICE_UNAVAILABLE); } @@ -1051,8 +1043,8 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL break; default : - DEBUG_printf(("HTTP error %d mapped to IPP_SERVICE_UNAVAILABLE!\n", - status)); + DEBUG_printf(("cupsGetPPD3: HTTP error %d mapped to " + "IPP_SERVICE_UNAVAILABLE!\n", status)); _cupsSetError(IPP_SERVICE_UNAVAILABLE, httpStatus(status), 0); break; } @@ -1539,30 +1531,14 @@ _cupsConnect(void) if (cg->http) { - int port; /* Port for connection */ - - - /* - * Get the port associated with the current connection... - */ - -#ifdef AF_INET6 - if (cg->http->hostaddr->addr.sa_family == AF_INET6) - port = ntohs(cg->http->hostaddr->ipv6.sin6_port); - else -#endif /* AF_INET6 */ - if (cg->http->hostaddr->addr.sa_family == AF_INET) - port = ntohs(cg->http->hostaddr->ipv4.sin_port); - else - port = cg->ipp_port; - /* * Compare the connection hostname, port, and encryption settings to * the cached defaults; these were initialized the first time we * connected... */ - if (strcmp(cg->http->hostname, cg->server) || cg->ipp_port != port || + if (strcmp(cg->http->hostname, cg->server) || + cg->ipp_port != _httpAddrPort(cg->http->hostaddr) || (cg->http->encryption != cg->encryption && cg->http->encryption == HTTP_ENCRYPT_NEVER)) { @@ -1662,16 +1638,7 @@ cups_get_printer_uri( */ httpGetHostname(http, http_hostname, sizeof(http_hostname)); - -#ifdef AF_INET6 - if (http->hostaddr->addr.sa_family == AF_INET6) - http_port = ntohs(http->hostaddr->ipv6.sin6_port); - else -#endif /* AF_INET6 */ - if (http->hostaddr->addr.sa_family == AF_INET) - http_port = ntohs(http->hostaddr->ipv4.sin_port); - else - http_port = ippPort(); + http_port = _httpAddrPort(http->hostaddr); /* * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the following diff --git a/scheduler/conf.c b/scheduler/conf.c index 78d5a413c0..b3fcbc3791 100644 --- a/scheduler/conf.c +++ b/scheduler/conf.c @@ -82,7 +82,9 @@ static const cupsd_var_t variables[] = { "BrowseInterval", &BrowseInterval, CUPSD_VARTYPE_INTEGER }, #ifdef HAVE_LDAP { "BrowseLDAPBindDN", &BrowseLDAPBindDN, CUPSD_VARTYPE_STRING }, +# ifdef HAVE_LDAP_SSL { "BrowseLDAPCACertFile", &BrowseLDAPCACertFile, CUPSD_VARTYPE_PATHNAME }, +# endif /* HAVE_LDAP_SSL */ { "BrowseLDAPDN", &BrowseLDAPDN, CUPSD_VARTYPE_STRING }, { "BrowseLDAPPassword", &BrowseLDAPPassword, CUPSD_VARTYPE_STRING }, { "BrowseLDAPServer", &BrowseLDAPServer, CUPSD_VARTYPE_STRING }, @@ -571,7 +573,9 @@ cupsdReadConfiguration(void) cupsdClearString(&BrowseLDAPDN); cupsdClearString(&BrowseLDAPPassword); cupsdClearString(&BrowseLDAPServer); +# ifdef HAVE_LDAP_SSL cupsdClearString(&BrowseLDAPCACertFile); +# endif /* HAVE_LDAP_SSL */ #endif /* HAVE_LDAP */ JobHistory = DEFAULT_HISTORY; diff --git a/scheduler/dirsvc.h b/scheduler/dirsvc.h index 7de4e2d56e..143a1ebac5 100644 --- a/scheduler/dirsvc.h +++ b/scheduler/dirsvc.h @@ -4,7 +4,7 @@ * Directory services definitions for the Common UNIX Printing System * (CUPS) scheduler. * - * Copyright 2007 by Apple Inc. + * Copyright 2007-2008 by Apple Inc. * Copyright 1997-2007 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the @@ -159,8 +159,6 @@ VAR time_t BrowseLDAPRefresh VALUE(0); /* Next LDAP refresh time */ VAR char *BrowseLDAPBindDN VALUE(NULL), /* LDAP login DN */ - *BrowseLDAPCACertFile VALUE(NULL), - /* LDAP CA cert file */ *BrowseLDAPDN VALUE(NULL), /* LDAP search DN */ *BrowseLDAPPassword VALUE(NULL), diff --git a/test/ipptest.c b/test/ipptest.c index f2bc6f714a..ebc8720990 100644 --- a/test/ipptest.c +++ b/test/ipptest.c @@ -16,7 +16,7 @@ * * main() - Parse options and do tests. * do_tests() - Do tests as specified in the test file. - * get_tag() - Get an IPP value or group tag from a name... + * ippTagValue() - Get an IPP value or group tag from a name... * get_token() - Get a token from a file. * print_attr() - Print an attribute on the screen. * usage() - Show program usage. @@ -41,50 +41,6 @@ */ int Verbosity = 0; /* Show all attributes? */ -const char * const TagNames[] = - { /* Value/group tag names */ - "zero", /* 0x00 */ - "operation", /* 0x01 */ - "job", /* 0x02 */ - "end", /* 0x03 */ - "printer", /* 0x04 */ - "unsupported-group", /* 0x05 */ - "subscription", /* 0x06 */ - "event-notification", /* 0x07 */ - "", "", "", "", "", "", "", "", - "unsupported-value", /* 0x10 */ - "default", /* 0x11 */ - "unknown", /* 0x12 */ - "novalue", /* 0x13 */ - "", - "notsettable", /* 0x15 */ - "deleteattr", /* 0x16 */ - "anyvalue", /* 0x17 */ - "", "", "", "", "", "", "", "", "", - "integer", /* 0x21 */ - "boolean", /* 0x22 */ - "enum", /* 0x23 */ - "", "", "", "", "", "", "", "", "", "", "", "", - "string", /* 0x30 */ - "date", /* 0x31 */ - "resolution", /* 0x32 */ - "range", /* 0x33 */ - "collection", /* 0x34 */ - "textlang", /* 0x35 */ - "namelang", /* 0x36 */ - "", "", "", "", "", "", "", "", "", "", - "text", /* 0x41 */ - "name", /* 0x42 */ - "", - "keyword", /* 0x44 */ - "uri", /* 0x45 */ - "urischeme", /* 0x46 */ - "charset", /* 0x47 */ - "language", /* 0x48 */ - "mimetype" /* 0x49 */ - }; - - /* @@ -94,8 +50,6 @@ const char * const TagNames[] = int do_tests(const char *, const char *); ipp_op_t ippOpValue(const char *); ipp_status_t ippErrorValue(const char *); -ipp_tag_t get_tag(const char *); -const char *get_tag_string(ipp_tag_t tag); char *get_token(FILE *, char *, int, int *linenum); void print_attr(ipp_attribute_t *); void usage(const char *option); @@ -366,7 +320,7 @@ do_tests(const char *uri, /* I - URI to connect on */ */ get_token(fp, token, sizeof(token), &linenum); - value = get_tag(token); + value = ippTagValue(token); if (value == group) ippAddSeparator(request); @@ -392,7 +346,7 @@ do_tests(const char *uri, /* I - URI to connect on */ */ get_token(fp, token, sizeof(token), &linenum); - value = get_tag(token); + value = ippTagValue(token); get_token(fp, attr, sizeof(attr), &linenum); get_token(fp, temp, sizeof(temp), &linenum); @@ -718,38 +672,6 @@ do_tests(const char *uri, /* I - URI to connect on */ } -/* - * 'get_tag()' - Get an IPP value or group tag from a name... - */ - -ipp_tag_t /* O - Value/group tag */ -get_tag(const char *name) /* I - Name of value/group tag */ -{ - int i; /* Looping var */ - - - for (i = 0; i < (sizeof(TagNames) / sizeof(TagNames[0])); i ++) - if (!strcasecmp(name, TagNames[i])) - return ((ipp_tag_t)i); - - return (IPP_TAG_ZERO); -} - - -/* - * 'get_tag_string()' - Get the string associated with a tag. - */ - -const char * /* O - Tag name string */ -get_tag_string(ipp_tag_t tag) /* I - IPP tag */ -{ - if (tag < (ipp_tag_t)(sizeof(TagNames) / sizeof(TagNames[0]))) - return (TagNames[tag]); - else - return ("UNKNOWN"); -} - - /* * 'get_token()' - Get a token from a file. */ @@ -860,7 +782,7 @@ print_attr(ipp_attribute_t *attr) /* I - Attribute to print */ printf(" %s (%s%s) = ", attr->name, attr->num_values > 1 ? "1setOf " : "", - get_tag_string(attr->value_tag)); + ippTagString(attr->value_tag)); switch (attr->value_tag) { diff --git a/test/run-stp-tests.sh b/test/run-stp-tests.sh index 5eae27cce5..ea505d462e 100755 --- a/test/run-stp-tests.sh +++ b/test/run-stp-tests.sh @@ -642,8 +642,8 @@ fi # Error log messages count=`grep '^E ' /tmp/cups-$user/log/error_log | wc -l | awk '{print $1}'` -if test $count != 9; then - echo "FAIL: $count error messages, expected 9." +if test $count != 17; then + echo "FAIL: $count error messages, expected 17." grep '^E ' /tmp/cups-$user/log/error_log echo "

FAIL: $count error messages, expected 9.

" >>$strfile echo "
" >>$strfile