diff options
author | jlovell <jlovell@a1ca3aef-8c08-0410-bb20-df032aa958be> | 2006-01-29 16:52:03 +0000 |
---|---|---|
committer | jlovell <jlovell@a1ca3aef-8c08-0410-bb20-df032aa958be> | 2006-01-29 16:52:03 +0000 |
commit | a4d045870e17abe8840b77615c0d59f4b332ee31 (patch) | |
tree | 156a1bf6d89ea7d14d78d947a205f7317f4e0a9d /cups | |
parent | 09ec001812911f8890dad0f164ab9098e22208cf (diff) |
Load cups into easysw/current.
git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@39 a1ca3aef-8c08-0410-bb20-df032aa958be
Diffstat (limited to 'cups')
-rw-r--r-- | cups/Makefile | 5 | ||||
-rw-r--r-- | cups/backend.c | 67 | ||||
-rw-r--r-- | cups/backend.h | 11 | ||||
-rw-r--r-- | cups/getputfile.c | 10 | ||||
-rw-r--r-- | cups/http-support.c | 224 | ||||
-rw-r--r-- | cups/http.c | 68 | ||||
-rw-r--r-- | cups/http.h | 31 | ||||
-rw-r--r-- | cups/ipp.c | 29 | ||||
-rw-r--r-- | cups/ipp.h | 18 | ||||
-rw-r--r-- | cups/testhttp.c | 15 | ||||
-rw-r--r-- | cups/testipp.c | 16 | ||||
-rw-r--r-- | cups/util.c | 40 |
12 files changed, 356 insertions, 178 deletions
diff --git a/cups/Makefile b/cups/Makefile index 94ff53a29..e23017bf3 100644 --- a/cups/Makefile +++ b/cups/Makefile @@ -1,5 +1,5 @@ # -# "$Id: Makefile 5000 2006-01-26 23:38:43Z mike $" +# "$Id: Makefile 5023 2006-01-29 14:39:44Z mike $" # # API library Makefile for the Common UNIX Printing System (CUPS). # @@ -35,6 +35,7 @@ LIBOBJS = \ attr.o \ auth.o \ backchannel.o \ + backend.o \ custom.o \ dest.o \ dir.o \ @@ -356,5 +357,5 @@ include Dependencies # -# End of "$Id: Makefile 5000 2006-01-26 23:38:43Z mike $". +# End of "$Id: Makefile 5023 2006-01-29 14:39:44Z mike $". # diff --git a/cups/backend.c b/cups/backend.c new file mode 100644 index 000000000..68d234d12 --- /dev/null +++ b/cups/backend.c @@ -0,0 +1,67 @@ +/* + * "$Id: backend.c 5024 2006-01-29 14:58:15Z mike $" + * + * Backend functions for the Common UNIX Printing System (CUPS). + * + * Copyright 2006 by Easy Software Products. + * + * These coded instructions, statements, and computer programs are the + * property of Easy Software Products and are protected by Federal + * copyright law. Distribution and use rights are outlined in the file + * "LICENSE.txt" which should have been included with this file. If this + * file is missing or damaged please contact Easy Software Products + * at: + * + * Attn: CUPS Licensing Information + * Easy Software Products + * 44141 Airport View Drive, Suite 204 + * Hollywood, Maryland 20636 USA + * + * Voice: (301) 373-9600 + * EMail: cups-info@cups.org + * WWW: http://www.cups.org + * + * This file is subject to the Apple OS-Developed Software exception. + * + * Contents: + * + * cupsBackendDeviceURI() - Get the device URI for a backend. + */ + +/* + * Include necessary headers... + */ + +#include <stdlib.h> +#include "backend.h" +#include "string.h" + + +/* + * 'cupsBackendDeviceURI()' - Get the device URI for a backend. + * + * The "argv" argument is the argv argument passed to main(). This + * function returns the device URI passed in the DEVICE_URI environment + * variable or the device URI passed in argv[0], whichever is found + * first. + */ + +const char * /* O - Device URI or NULL */ +cupsBackendDeviceURI(char **argv) /* I - Command-line arguments */ +{ + const char *device_uri; /* Device URI */ + + + if ((device_uri = getenv("DEVICE_URI")) != NULL) + return (device_uri); + + if (!argv || !argv[0] || !strchr(argv[0], ':')) + return (NULL); + else + return (argv[0]); +} + + +/* + * End of "$Id: backend.c 5024 2006-01-29 14:58:15Z mike $". + */ diff --git a/cups/backend.h b/cups/backend.h index a816b2f07..ca107c93f 100644 --- a/cups/backend.h +++ b/cups/backend.h @@ -1,5 +1,5 @@ /* - * "$Id: backend.h 4973 2006-01-25 02:36:02Z mike $" + * "$Id: backend.h 5023 2006-01-29 14:39:44Z mike $" * * Backend definitions for the Common UNIX Printing System (CUPS). * @@ -43,8 +43,15 @@ typedef enum cups_backend_e /**** Backend exit codes ****/ } cups_backend_t; +/* + * Prototypes... + */ + +extern const char *cupsBackendDeviceURI(char **argv); + + #endif /* !_CUPS_BACKEND_H_ */ /* - * End of "$Id: backend.h 4973 2006-01-25 02:36:02Z mike $". + * End of "$Id: backend.h 5023 2006-01-29 14:39:44Z mike $". */ diff --git a/cups/getputfile.c b/cups/getputfile.c index 82c9bdf28..da1579fa8 100644 --- a/cups/getputfile.c +++ b/cups/getputfile.c @@ -1,5 +1,5 @@ /* - * "$Id: getputfile.c 4984 2006-01-25 21:55:36Z mike $" + * "$Id: getputfile.c 5023 2006-01-29 14:39:44Z mike $" * * Get/put file functions for the Common UNIX Printing System (CUPS). * @@ -166,7 +166,7 @@ cupsGetFd(http_t *http, /* I - HTTP connection to server */ * Yes, copy the file... */ - while ((bytes = httpRead(http, buffer, sizeof(buffer))) > 0) + while ((bytes = httpRead2(http, buffer, sizeof(buffer))) > 0) write(fd, buffer, bytes); } else @@ -322,11 +322,11 @@ cupsPutFd(http_t *http, /* I - HTTP connection to server */ break; } else - httpWrite(http, buffer, bytes); + httpWrite2(http, buffer, bytes); if (status == HTTP_CONTINUE) { - httpWrite(http, buffer, 0); + httpWrite2(http, buffer, 0); while ((status = httpUpdate(http)) == HTTP_CONTINUE); } @@ -447,5 +447,5 @@ cupsPutFile(http_t *http, /* I - HTTP connection to server */ /* - * End of "$Id: getputfile.c 4984 2006-01-25 21:55:36Z mike $". + * End of "$Id: getputfile.c 5023 2006-01-29 14:39:44Z mike $". */ diff --git a/cups/http-support.c b/cups/http-support.c index 0770f138a..3103007aa 100644 --- a/cups/http-support.c +++ b/cups/http-support.c @@ -1,5 +1,5 @@ /* - * "$Id: http-support.c 4961 2006-01-20 22:19:13Z mike $" + * "$Id: http-support.c 5023 2006-01-29 14:39:44Z mike $" * * HTTP support routines for the Common UNIX Printing System (CUPS) scheduler. * @@ -93,9 +93,11 @@ static const char * const http_months[12] = */ static const char *http_copy_decode(char *dst, const char *src, - int dstsize, const char *term); + int dstsize, const char *term, + int decode); static char *http_copy_encode(char *dst, const char *src, - char *dstend, const char *reserved); + char *dstend, const char *reserved, + const char *term, int encode); /* @@ -110,46 +112,18 @@ static char *http_copy_encode(char *dst, const char *src, */ http_uri_status_t /* O - URI status */ -httpAssembleURI(char *uri, /* I - URI buffer */ - int urilen, /* I - Size of URI buffer */ - const char *scheme, /* I - Scheme name */ - const char *username, /* I - Username */ - const char *host, /* I - Hostname or address */ - int port, /* I - Port number */ - const char *resource) /* I - Resource */ -{ - return (httpAssembleURIf(uri, urilen, scheme, username, host, port, "%s", - resource)); -} - - -/* - * 'httpAssembleURIf()' - Assemble a uniform resource identifier from its - * components with a formatted resource. - * - * This function creates a formatted version of the resource string - * argument "resourcef" and properly escapes all reserved characters - * in a URI. You should use this function in place of traditional - * string functions whenever you need to create a URI string. - * - * @since CUPS 1.2@ - */ - -http_uri_status_t /* O - URI status */ -httpAssembleURIf(char *uri, /* I - URI buffer */ - int urilen, /* I - Size of URI buffer */ - const char *scheme, /* I - Scheme name */ - const char *username, /* I - Username */ - const char *host, /* I - Hostname or address */ - int port, /* I - Port number */ - const char *resourcef, /* I - Printf-style resource */ - ...) /* I - Additional arguments as needed */ +httpAssembleURI( + http_uri_coding_t encoding, /* I - Encoding flags */ + char *uri, /* I - URI buffer */ + int urilen, /* I - Size of URI buffer */ + const char *scheme, /* I - Scheme name */ + const char *username, /* I - Username */ + const char *host, /* I - Hostname or address */ + int port, /* I - Port number */ + const char *resource) /* I - Resource */ { char *ptr, /* Pointer into URI buffer */ *end; /* End of URI buffer */ - va_list ap; /* Pointer to additional arguments */ - char resource[1024]; /* Formatted resource string */ - int bytes; /* Bytes in formatted string */ /* @@ -169,7 +143,7 @@ httpAssembleURIf(char *uri, /* I - URI buffer */ */ end = uri + urilen - 1; - ptr = http_copy_encode(uri, scheme, end, NULL); + ptr = http_copy_encode(uri, scheme, end, NULL, NULL, 0); if (!ptr) goto assemble_overflow; @@ -213,7 +187,8 @@ httpAssembleURIf(char *uri, /* I - URI buffer */ * Add username@ first... */ - ptr = http_copy_encode(ptr, username, end, "/?@"); + ptr = http_copy_encode(ptr, username, end, "/?@", NULL, + encoding & HTTP_URI_CODING_USERNAME); if (!ptr) goto assemble_overflow; @@ -294,7 +269,8 @@ httpAssembleURIf(char *uri, /* I - URI buffer */ * Otherwise, just copy the host string... */ - ptr = http_copy_encode(ptr, host, end, NULL); + ptr = http_copy_encode(ptr, host, end, NULL, NULL, + encoding & HTTP_URI_CODING_HOSTNAME); if (!ptr) goto assemble_overflow; @@ -318,26 +294,18 @@ httpAssembleURIf(char *uri, /* I - URI buffer */ * Last but not least, add the resource string... */ - if (resourcef) + if (resource) { char *query; /* Pointer to query string */ - va_start(ap, resourcef); - bytes = vsnprintf(resource, sizeof(resource), resourcef, ap); - va_end(ap); - - if (bytes >= sizeof(resource)) - goto assemble_overflow; - /* - * Temporarily remove query string if present... + * Copy the resource string up to the query string if present... */ - if ((query = strchr(resource, '?')) != NULL) - *query = '\0'; - - ptr = http_copy_encode(ptr, resource, end, NULL); + query = strchr(resource, '?'); + ptr = http_copy_encode(ptr, resource, end, NULL, "?", + encoding & HTTP_URI_CODING_RESOURCE); if (!ptr) goto assemble_overflow; @@ -347,9 +315,10 @@ httpAssembleURIf(char *uri, /* I - URI buffer */ * Copy query string without encoding... */ - *query = '?'; - strlcpy(ptr, query, end - ptr); - ptr += strlen(ptr); + ptr = http_copy_encode(ptr, query, end, NULL, NULL, + encoding & HTTP_URI_CODING_QUERY); + if (!ptr) + goto assemble_overflow; } } else if (ptr < end) @@ -378,6 +347,66 @@ httpAssembleURIf(char *uri, /* I - URI buffer */ /* + * 'httpAssembleURIf()' - Assemble a uniform resource identifier from its + * components with a formatted resource. + * + * This function creates a formatted version of the resource string + * argument "resourcef" and properly escapes all reserved characters + * in a URI. You should use this function in place of traditional + * string functions whenever you need to create a URI string. + * + * @since CUPS 1.2@ + */ + +http_uri_status_t /* O - URI status */ +httpAssembleURIf( + http_uri_coding_t encoding, /* I - Encoding flags */ + char *uri, /* I - URI buffer */ + int urilen, /* I - Size of URI buffer */ + const char *scheme, /* I - Scheme name */ + const char *username, /* I - Username */ + const char *host, /* I - Hostname or address */ + int port, /* I - Port number */ + const char *resourcef, /* I - Printf-style resource */ + ...) /* I - Additional arguments as needed */ +{ + va_list ap; /* Pointer to additional arguments */ + char resource[1024]; /* Formatted resource string */ + int bytes; /* Bytes in formatted string */ + + + /* + * Range check input... + */ + + if (!uri || urilen < 1 || !scheme || port < 0 || !resourcef) + { + if (uri) + *uri = '\0'; + + return (HTTP_URI_BAD_ARGUMENTS); + } + + /* + * Format the resource string and assemble the URI... + */ + + va_start(ap, resourcef); + bytes = vsnprintf(resource, sizeof(resource), resourcef, ap); + va_end(ap); + + if (bytes >= sizeof(resource)) + { + *uri = '\0'; + return (HTTP_URI_OVERFLOW); + } + else + return (httpAssembleURI(encoding, uri, urilen, scheme, username, host, + port, resource)); +} + + +/* * 'httpDecode64()' - Base64-decode a string. */ @@ -714,8 +743,9 @@ httpSeparate(const char *uri, /* I - Universal Resource Identifier */ int *port, /* O - Port number to use */ char *resource) /* O - Resource/filename [1024] */ { - httpSeparateURI(uri, scheme, 32, username, HTTP_MAX_URI, host, HTTP_MAX_URI, - port, resource, HTTP_MAX_URI); + httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, 32, username, + HTTP_MAX_URI, host, HTTP_MAX_URI, port, resource, + HTTP_MAX_URI); } @@ -738,8 +768,8 @@ httpSeparate2(const char *uri, /* I - Universal Resource Identifier */ char *resource, /* O - Resource/filename */ int resourcelen) /* I - Size of resource buffer */ { - httpSeparateURI(uri, scheme, schemelen, username, usernamelen, host, hostlen, - port, resource, resourcelen); + httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, schemelen, username, + usernamelen, host, hostlen, port, resource, resourcelen); } @@ -751,16 +781,18 @@ httpSeparate2(const char *uri, /* I - Universal Resource Identifier */ */ http_uri_status_t /* O - Result of separation */ -httpSeparateURI(const char *uri, /* I - Universal Resource Identifier */ - char *scheme, /* O - Scheme (http, https, etc.) */ - int schemelen, /* I - Size of scheme buffer */ - char *username, /* O - Username */ - int usernamelen, /* I - Size of username buffer */ - char *host, /* O - Hostname */ - int hostlen, /* I - Size of hostname buffer */ - int *port, /* O - Port number to use */ - char *resource, /* O - Resource/filename */ - int resourcelen) /* I - Size of resource buffer */ +httpSeparateURI( + http_uri_coding_t decoding, /* I - Decoding flags */ + const char *uri, /* I - Universal Resource Identifier */ + char *scheme, /* O - Scheme (http, https, etc.) */ + int schemelen, /* I - Size of scheme buffer */ + char *username, /* O - Username */ + int usernamelen, /* I - Size of username buffer */ + char *host, /* O - Hostname */ + int hostlen, /* I - Size of hostname buffer */ + int *port, /* O - Port number to use */ + char *resource, /* O - Resource/filename */ + int resourcelen) /* I - Size of resource buffer */ { char *ptr, /* Pointer into string... */ *end; /* End of string */ @@ -886,7 +918,8 @@ httpSeparateURI(const char *uri, /* I - Universal Resource Identifier */ * Get a username:password combo... */ - uri = http_copy_decode(username, uri, usernamelen, "@"); + uri = http_copy_decode(username, uri, usernamelen, "@", + decoding & HTTP_URI_CODING_USERNAME); if (!uri) { @@ -911,7 +944,8 @@ httpSeparateURI(const char *uri, /* I - Universal Resource Identifier */ if (!strncmp(uri, "v1.", 3)) uri += 3; /* Skip IPvN leader... */ - uri = http_copy_decode(host, uri, hostlen, "]"); + uri = http_copy_decode(host, uri, hostlen, "]", + decoding & HTTP_URI_CODING_HOSTNAME); if (!uri) { @@ -953,7 +987,8 @@ httpSeparateURI(const char *uri, /* I - Universal Resource Identifier */ * Grab hostname or IPv4 address... */ - uri = http_copy_decode(host, uri, hostlen, ":?/"); + uri = http_copy_decode(host, uri, hostlen, ":?/", + decoding & HTTP_URI_CODING_HOSTNAME); if (!uri) { @@ -1022,29 +1057,30 @@ httpSeparateURI(const char *uri, /* I - Universal Resource Identifier */ *resource = '/'; /* - * Copy any query string without decoding it... + * Copy any query string... */ if (*uri == '?') - { - strlcpy(resource + 1, uri, resourcelen - 1); - uri += strlen(uri); - } + uri = http_copy_decode(resource + 1, uri, resourcelen - 1, NULL, + decoding & HTTP_URI_CODING_QUERY); else resource[1] = '\0'; } else { - uri = http_copy_decode(resource, uri, resourcelen, "?"); + uri = http_copy_decode(resource, uri, resourcelen, "?", + decoding & HTTP_URI_CODING_RESOURCE); if (uri && *uri == '?') { /* - * Concatenate any query string without decoding it... + * Concatenate any query string... */ - strlcat(resource, uri, resourcelen); - uri += strlen(uri); + char *resptr = resource + strlen(resource); + + uri = http_copy_decode(resptr, uri, resourcelen - (resptr - resource), + NULL, decoding & HTTP_URI_CODING_QUERY); } } @@ -1143,7 +1179,8 @@ static const char * /* O - New source pointer or NULL on error */ http_copy_decode(char *dst, /* O - Destination buffer */ const char *src, /* I - Source pointer */ int dstsize, /* I - Destination size */ - const char *term) /* I - Terminating characters */ + const char *term, /* I - Terminating characters */ + int decode) /* I - Decode %-encoded values */ { char *ptr, /* Pointer into buffer */ *end; /* End of buffer */ @@ -1158,7 +1195,7 @@ http_copy_decode(char *dst, /* O - Destination buffer */ for (ptr = dst, end = dst + dstsize - 1; *src && !strchr(term, *src); src ++) if (ptr < end) { - if (*src == '%') + if (*src == '%' && decode) { if (isxdigit(src[1] & 255) && isxdigit(src[2] & 255)) { @@ -1208,15 +1245,20 @@ static char * /* O - End of current URI */ http_copy_encode(char *dst, /* O - Destination buffer */ const char *src, /* I - Source pointer */ char *dstend, /* I - End of destination buffer */ - const char *reserved) /* I - Extra reserved characters */ + const char *reserved, /* I - Extra reserved characters */ + const char *term, /* I - Terminating characters */ + int encode) /* I - %-encode reserved chars? */ { static const char *hex = "0123456789ABCDEF"; while (*src && dst < dstend) { - if (*src == '%' || *src <= ' ' || *src & 128 || - (reserved && strchr(reserved, *src))) + if (term && *src == *term) + return (dst); + + if (encode && (*src == '%' || *src <= ' ' || *src & 128 || + (reserved && strchr(reserved, *src)))) { /* * Hex encode reserved characters... @@ -1243,5 +1285,5 @@ http_copy_encode(char *dst, /* O - Destination buffer */ /* - * End of "$Id: http-support.c 4961 2006-01-20 22:19:13Z mike $". + * End of "$Id: http-support.c 5023 2006-01-29 14:39:44Z mike $". */ diff --git a/cups/http.c b/cups/http.c index b094a5d49..fc6a20d07 100644 --- a/cups/http.c +++ b/cups/http.c @@ -1,5 +1,5 @@ /* - * "$Id: http.c 4995 2006-01-26 20:14:42Z mike $" + * "$Id: http.c 5023 2006-01-29 14:39:44Z mike $" * * HTTP routines for the Common UNIX Printing System (CUPS). * @@ -50,6 +50,7 @@ * httpPrintf() - Print a formatted string to a HTTP connection. * httpPut() - Send a PUT request to the server. * httpRead() - Read data from a HTTP connection. + * httpRead2() - Read data from a HTTP connection. * _httpReadCDSA() - Read function for CDSA decryption code. * httpReconnect() - Reconnect to a HTTP server... * httpSetCookie() - Set the cookie value(s)... @@ -59,6 +60,7 @@ * httpUpdate() - Update the current HTTP state for incoming data. * httpWait() - Wait for data available on a connection. * httpWrite() - Write data to a HTTP connection. + * httpWrite2() - Write data to a HTTP connection. * _httpWriteCDSA() - Write function for CDSA encryption code. * http_field() - Return the field index for a field name. * http_read_ssl() - Read from a SSL/TLS connection. @@ -395,7 +397,7 @@ httpFlush(http_t *http) /* I - HTTP data */ * Read any data we can... */ - while (httpRead(http, buffer, sizeof(buffer)) > 0); + while (httpRead2(http, buffer, sizeof(buffer)) > 0); /* * Restore blocking and reset the connection if we didn't get all of @@ -988,6 +990,11 @@ httpPut(http_t *http, /* I - HTTP data */ /* * 'httpRead()' - Read data from a HTTP connection. + * + * This function is deprecated. Use the httpRead2() function which can + * read more than 2GB of data. + * + * @deprecated@ */ int /* O - Number of bytes read */ @@ -995,7 +1002,20 @@ httpRead(http_t *http, /* I - HTTP data */ char *buffer, /* I - Buffer for data */ int length) /* I - Maximum number of bytes */ { - int bytes; /* Bytes read */ + return ((int)httpRead2(http, buffer, length)); +} + + +/* + * 'httpRead2()' - Read data from a HTTP connection. + */ + +ssize_t /* O - Number of bytes read */ +httpRead2(http_t *http, /* I - HTTP data */ + char *buffer, /* I - Buffer for data */ + size_t length) /* I - Maximum number of bytes */ +{ + ssize_t bytes; /* Bytes read */ char len[32]; /* Length string */ @@ -1013,23 +1033,23 @@ httpRead(http_t *http, /* I - HTTP data */ if (http->data_encoding == HTTP_ENCODE_CHUNKED && http->data_remaining <= 0) { - DEBUG_puts("httpRead: Getting chunk length..."); + DEBUG_puts("httpRead2: Getting chunk length..."); if (httpGets(len, sizeof(len), http) == NULL) { - DEBUG_puts("httpRead: Could not get length!"); + DEBUG_puts("httpRead2: Could not get length!"); return (0); } http->data_remaining = strtoll(len, NULL, 16); if (http->data_remaining < 0) { - DEBUG_puts("httpRead: Negative chunk length!"); + DEBUG_puts("httpRead2: Negative chunk length!"); return (0); } } - DEBUG_printf(("httpRead: data_remaining=" CUPS_LLFMT "\n", + DEBUG_printf(("httpRead2: data_remaining=" CUPS_LLFMT "\n", CUPS_LLCAST http->data_remaining)); if (http->data_remaining <= 0) @@ -1078,12 +1098,12 @@ httpRead(http_t *http, /* I - HTTP data */ else #endif /* HAVE_SSL */ { - DEBUG_printf(("httpRead: reading %d bytes from socket into buffer...\n", + DEBUG_printf(("httpRead2: reading %d bytes from socket into buffer...\n", bytes)); bytes = recv(http->fd, http->buffer, bytes, 0); - DEBUG_printf(("httpRead: read %d bytes from socket into buffer...\n", + DEBUG_printf(("httpRead2: read %d bytes from socket into buffer...\n", bytes)); } @@ -1116,7 +1136,7 @@ httpRead(http_t *http, /* I - HTTP data */ bytes = length; - DEBUG_printf(("httpRead: grabbing %d bytes from input buffer...\n", bytes)); + DEBUG_printf(("httpRead2: grabbing %d bytes from input buffer...\n", bytes)); memcpy(buffer, http->buffer, length); http->used -= length; @@ -1138,13 +1158,13 @@ httpRead(http_t *http, /* I - HTTP data */ if (!http->blocking && !httpWait(http, 1000)) return (0); - DEBUG_printf(("httpRead: reading %d bytes from socket...\n", length)); + DEBUG_printf(("httpRead2: reading %d bytes from socket...\n", length)); while ((bytes = recv(http->fd, buffer, length, 0)) < 0) if (errno != EINTR) break; - DEBUG_printf(("httpRead: read %d bytes from socket...\n", bytes)); + DEBUG_printf(("httpRead2: read %d bytes from socket...\n", bytes)); } if (bytes > 0) @@ -1190,7 +1210,7 @@ httpRead(http_t *http, /* I - HTTP data */ #ifdef DEBUG { int i, j, ch; - printf("httpRead: Read %d bytes:\n", bytes); + printf("httpRead2: Read %d bytes:\n", bytes); for (i = 0; i < bytes; i += 16) { printf(" "); @@ -1635,6 +1655,11 @@ httpWait(http_t *http, /* I - HTTP data */ /* * 'httpWrite()' - Write data to a HTTP connection. + * + * This function is deprecated. Use the httpWrite2() function which can + * write more than 2GB of data. + * + * @deprecated@ */ int /* O - Number of bytes written */ @@ -1642,7 +1667,20 @@ httpWrite(http_t *http, /* I - HTTP data */ const char *buffer, /* I - Buffer for data */ int length) /* I - Number of bytes to write */ { - int bytes; /* Bytes written */ + return ((int)httpWrite2(http, buffer, length)); +} + + +/* + * 'httpWrite2()' - Write data to a HTTP connection. + */ + +ssize_t /* O - Number of bytes written */ +httpWrite2(http_t *http, /* I - HTTP data */ + const char *buffer, /* I - Buffer for data */ + size_t length) /* I - Number of bytes to write */ +{ + ssize_t bytes; /* Bytes written */ DEBUG_printf(("httpWrite(http=%p, buffer=%p, length=%d)\n", http, @@ -2535,5 +2573,5 @@ http_write_ssl(http_t *http, /* I - HTTP data */ /* - * End of "$Id: http.c 4995 2006-01-26 20:14:42Z mike $". + * End of "$Id: http.c 5023 2006-01-29 14:39:44Z mike $". */ diff --git a/cups/http.h b/cups/http.h index 1384e6d7d..9c346eebf 100644 --- a/cups/http.h +++ b/cups/http.h @@ -1,5 +1,5 @@ /* - * "$Id: http.h 4973 2006-01-25 02:36:02Z mike $" + * "$Id: http.h 5023 2006-01-29 14:39:44Z mike $" * * Hyper-Text Transport Protocol definitions for the Common UNIX Printing * System (CUPS). @@ -268,6 +268,17 @@ typedef enum http_uri_status_e /**** URI separation status @since CUPS1.2@ **** HTTP_URI_MISSING_RESOURCE /* Missing resource in URI (warning) */ } http_uri_status_t; +typedef enum http_uri_coding_e /**** URI en/decode flags ****/ +{ + HTTP_URI_CODING_NONE = 0, /* Don't en/decode anything */ + HTTP_URI_CODING_USERNAME = 1, /* En/decode the username portion */ + HTTP_URI_CODING_HOSTNAME = 2, /* En/decode the hostname portion */ + HTTP_URI_CODING_RESOURCE = 4, /* En/decode the resource portion */ + HTTP_URI_CODING_MOST = 7, /* En/decode all but the query */ + HTTP_URI_CODING_QUERY = 8, /* En/decode the query portion */ + HTTP_URI_CODING_ALL = 15 /* En/decode everything */ +} http_uri_coding_t; + typedef enum http_version_e /**** HTTP version numbers ****/ { HTTP_0_9 = 9, /* HTTP/0.9 */ @@ -384,7 +395,7 @@ __attribute__ ((__format__ (__printf__, 2, 3))) # endif /* __GNUC__ */ ; extern int httpPut(http_t *http, const char *uri); -extern int httpRead(http_t *http, char *buffer, int length); +extern int httpRead(http_t *http, char *buffer, int length) _HTTP_DEPRECATED; extern int httpReconnect(http_t *http); extern void httpSeparate(const char *uri, char *method, char *username, char *host, int *port, @@ -394,7 +405,7 @@ extern void httpSetField(http_t *http, http_field_t field, extern const char *httpStatus(http_status_t status); extern int httpTrace(http_t *http, const char *uri); extern http_status_t httpUpdate(http_t *http); -extern int httpWrite(http_t *http, const char *buffer, int length); +extern int httpWrite(http_t *http, const char *buffer, int length) _HTTP_DEPRECATED; extern char *httpEncode64(char *out, const char *in) _HTTP_DEPRECATED; extern char *httpDecode64(char *out, const char *in) _HTTP_DEPRECATED; extern int httpGetLength(http_t *http) _HTTP_DEPRECATED; @@ -434,12 +445,14 @@ extern char *httpAddrLookup(const http_addr_t *addr, char *name, int namelen); extern char *httpAddrString(const http_addr_t *addr, char *s, int slen); -extern http_uri_status_t httpAssembleURI(char *uri, int urilen, +extern http_uri_status_t httpAssembleURI(http_uri_coding_t encoding, + char *uri, int urilen, const char *scheme, const char *username, const char *host, int port, const char *resource); -extern http_uri_status_t httpAssembleURIf(char *uri, int urilen, +extern http_uri_status_t httpAssembleURIf(http_uri_coding_t encoding, + char *uri, int urilen, const char *scheme, const char *username, const char *host, int port, @@ -451,12 +464,16 @@ extern off_t httpGetLength2(http_t *http); extern char *httpGetSubField2(http_t *http, http_field_t field, const char *name, char *value, int valuelen); -extern http_uri_status_t httpSeparateURI(const char *uri, +extern ssize_t httpRead2(http_t *http, char *buffer, size_t length); +extern http_uri_status_t httpSeparateURI(http_uri_coding_t decoding, + const char *uri, char *scheme, int schemelen, char *username, int usernamelen, char *host, int hostlen, int *port, char *resource, int resourcelen); extern void httpSetLength(http_t *http, size_t length); +extern ssize_t httpWrite2(http_t *http, const char *buffer, + size_t length); /* @@ -469,5 +486,5 @@ extern void httpSetLength(http_t *http, size_t length); #endif /* !_CUPS_HTTP_H_ */ /* - * End of "$Id: http.h 4973 2006-01-25 02:36:02Z mike $". + * End of "$Id: http.h 5023 2006-01-29 14:39:44Z mike $". */ diff --git a/cups/ipp.c b/cups/ipp.c index fbe7e39de..be6f0bbc9 100644 --- a/cups/ipp.c +++ b/cups/ipp.c @@ -1,5 +1,5 @@ /* - * "$Id: ipp.c 4995 2006-01-26 20:14:42Z mike $" + * "$Id: ipp.c 5023 2006-01-29 14:39:44Z mike $" * * Internet Printing Protocol support functions for the Common UNIX * Printing System (CUPS). @@ -85,9 +85,12 @@ */ static size_t ipp_length(ipp_t *ipp, int collection); -static int ipp_read_http(http_t *http, ipp_uchar_t *buffer, int length); -static int ipp_read_file(int *fd, ipp_uchar_t *buffer, int length); -static int ipp_write_file(int *fd, ipp_uchar_t *buffer, int length); +static ssize_t ipp_read_http(http_t *http, ipp_uchar_t *buffer, + size_t length); +static ssize_t ipp_read_file(int *fd, ipp_uchar_t *buffer, + size_t length); +static ssize_t ipp_write_file(int *fd, ipp_uchar_t *buffer, + size_t length); /* @@ -1580,7 +1583,7 @@ ippWrite(http_t *http, /* I - HTTP connection */ if (http == NULL) return (IPP_ERROR); - return (ippWriteIO(http, (ipp_iocb_t)httpWrite, + return (ippWriteIO(http, (ipp_iocb_t)httpWrite2, http->blocking, NULL, ipp)); } @@ -2623,10 +2626,10 @@ ipp_length(ipp_t *ipp, /* I - IPP message or collection */ * 'ipp_read_http()' - Semi-blocking read on a HTTP connection... */ -static int /* O - Number of bytes read */ +static ssize_t /* O - Number of bytes read */ ipp_read_http(http_t *http, /* I - Client connection */ ipp_uchar_t *buffer, /* O - Buffer for data */ - int length) /* I - Total length */ + size_t length) /* I - Total length */ { int tbytes, /* Total bytes read */ bytes; /* Bytes read this pass */ @@ -2718,7 +2721,7 @@ ipp_read_http(http_t *http, /* I - Client connection */ } } - if ((bytes = httpRead(http, (char *)buffer, length - tbytes)) <= 0) + if ((bytes = httpRead2(http, (char *)buffer, length - tbytes)) <= 0) break; } } @@ -2740,10 +2743,10 @@ ipp_read_http(http_t *http, /* I - Client connection */ * 'ipp_read_file()' - Read IPP data from a file. */ -static int /* O - Number of bytes read */ +static ssize_t /* O - Number of bytes read */ ipp_read_file(int *fd, /* I - File descriptor */ ipp_uchar_t *buffer, /* O - Read buffer */ - int length) /* I - Number of bytes to read */ + size_t length) /* I - Number of bytes to read */ { return (read(*fd, buffer, length)); } @@ -2753,15 +2756,15 @@ ipp_read_file(int *fd, /* I - File descriptor */ * 'ipp_write_file()' - Write IPP data to a file. */ -static int /* O - Number of bytes written */ +static ssize_t /* O - Number of bytes written */ ipp_write_file(int *fd, /* I - File descriptor */ ipp_uchar_t *buffer, /* I - Data to write */ - int length) /* I - Number of bytes to write */ + size_t length) /* I - Number of bytes to write */ { return (write(*fd, buffer, length)); } /* - * End of "$Id: ipp.c 4995 2006-01-26 20:14:42Z mike $". + * End of "$Id: ipp.c 5023 2006-01-29 14:39:44Z mike $". */ diff --git a/cups/ipp.h b/cups/ipp.h index f011a35e4..4a337a84e 100644 --- a/cups/ipp.h +++ b/cups/ipp.h @@ -1,5 +1,5 @@ /* - * "$Id: ipp.h 4995 2006-01-26 20:14:42Z mike $" + * "$Id: ipp.h 5023 2006-01-29 14:39:44Z mike $" * * Internet Printing Protocol definitions for the Common UNIX Printing * System (CUPS). @@ -310,9 +310,9 @@ typedef enum /**** IPP status codes... ****/ typedef unsigned char ipp_uchar_t; /**** Unsigned 8-bit integer/character ****/ -/**** New in CUPS 1.1.19 ****/ -typedef int (*ipp_iocb_t)(void *, ipp_uchar_t *, int); - /**** IPP IO Callback Function ****/ +/**** New in CUPS 1.2 ****/ +typedef ssize_t (*ipp_iocb_t)(void *, ipp_uchar_t *, size_t); + /**** IPP IO Callback Function @since CUPS 1.2@ ****/ typedef union /**** Request Header ****/ { @@ -470,11 +470,7 @@ extern ipp_attribute_t *ippAddCollections(ipp_t *ipp, ipp_tag_t group, const ipp_t **values); extern void ippDeleteAttribute(ipp_t *ipp, ipp_attribute_t *attr); extern ipp_state_t ippReadFile(int fd, ipp_t *ipp); -extern ipp_state_t ippReadIO(void *src, ipp_iocb_t cb, int blocking, - ipp_t *parent, ipp_t *ipp); extern ipp_state_t ippWriteFile(int fd, ipp_t *ipp); -extern ipp_state_t ippWriteIO(void *dst, ipp_iocb_t cb, int blocking, - ipp_t *parent, ipp_t *ipp); /**** New in CUPS 1.2 ****/ extern ipp_attribute_t *ippAddOctetString(ipp_t *ipp, ipp_tag_t group, @@ -484,6 +480,10 @@ extern ipp_status_t ippErrorValue(const char *name); extern ipp_t *ippNewRequest(ipp_op_t op); extern const char *ippOpString(ipp_op_t op); extern ipp_op_t ippOpValue(const char *name); +extern ipp_state_t ippReadIO(void *src, ipp_iocb_t cb, int blocking, + ipp_t *parent, ipp_t *ipp); +extern ipp_state_t ippWriteIO(void *dst, ipp_iocb_t cb, int blocking, + ipp_t *parent, ipp_t *ipp); /* @@ -496,5 +496,5 @@ extern ipp_op_t ippOpValue(const char *name); #endif /* !_CUPS_IPP_H_ */ /* - * End of "$Id: ipp.h 4995 2006-01-26 20:14:42Z mike $". + * End of "$Id: ipp.h 5023 2006-01-29 14:39:44Z mike $". */ diff --git a/cups/testhttp.c b/cups/testhttp.c index 69f959541..71b8709f9 100644 --- a/cups/testhttp.c +++ b/cups/testhttp.c @@ -1,5 +1,5 @@ /* - * "$Id: testhttp.c 4943 2006-01-18 20:30:42Z mike $" + * "$Id: testhttp.c 5023 2006-01-29 14:39:44Z mike $" * * HTTP test program for the Common UNIX Printing System (CUPS). * @@ -325,7 +325,8 @@ main(int argc, /* I - Number of command-line arguments */ fputs("httpSeparateURI(): ", stdout); for (i = 0, j = 0; i < (int)(sizeof(uri_tests) / sizeof(uri_tests[0])); i ++) { - uri_status = httpSeparateURI(uri_tests[i].uri, scheme, sizeof(scheme), + uri_status = httpSeparateURI(HTTP_URI_CODING_MOST, + uri_tests[i].uri, scheme, sizeof(scheme), username, sizeof(username), hostname, sizeof(hostname), &port, resource, sizeof(resource)); @@ -390,7 +391,8 @@ main(int argc, /* I - Number of command-line arguments */ strstr(uri_tests[i].uri, "//")) { k ++; - uri_status = httpAssembleURI(buffer, sizeof(buffer), + uri_status = httpAssembleURI(HTTP_URI_CODING_MOST, + buffer, sizeof(buffer), uri_tests[i].scheme, uri_tests[i].username, uri_tests[i].hostname, @@ -459,7 +461,8 @@ main(int argc, /* I - Number of command-line arguments */ continue; } - httpSeparateURI(argv[i], scheme, sizeof(scheme), username, sizeof(username), + httpSeparateURI(HTTP_URI_CODING_MOST, argv[i], scheme, sizeof(scheme), + username, sizeof(username), hostname, sizeof(hostname), &port, resource, sizeof(resource)); @@ -485,7 +488,7 @@ main(int argc, /* I - Number of command-line arguments */ length = httpGetLength2(http); total = 0; - while ((bytes = httpRead(http, buffer, sizeof(buffer))) > 0) + while ((bytes = httpRead2(http, buffer, sizeof(buffer))) > 0) { total += bytes; fwrite(buffer, bytes, 1, out); @@ -512,5 +515,5 @@ main(int argc, /* I - Number of command-line arguments */ /* - * End of "$Id: testhttp.c 4943 2006-01-18 20:30:42Z mike $". + * End of "$Id: testhttp.c 5023 2006-01-29 14:39:44Z mike $". */ diff --git a/cups/testipp.c b/cups/testipp.c index dbe50b54d..07bcdffc0 100644 --- a/cups/testipp.c +++ b/cups/testipp.c @@ -1,5 +1,5 @@ /* - * "$Id: testipp.c 4731 2005-09-30 23:11:10Z mike $" + * "$Id: testipp.c 5023 2006-01-29 14:39:44Z mike $" * * IPP test program for the Common UNIX Printing System (CUPS). * @@ -144,8 +144,8 @@ ipp_uchar_t collection[] = /* Collection buffer */ void hex_dump(const char *title, ipp_uchar_t *buffer, int bytes); void print_attributes(ipp_t *ipp, int indent); -int read_cb(void *data, ipp_uchar_t *buffer, int bytes); -int write_cb(void *data, ipp_uchar_t *buffer, int bytes); +ssize_t read_cb(void *data, ipp_uchar_t *buffer, size_t bytes); +ssize_t write_cb(void *data, ipp_uchar_t *buffer, size_t bytes); /* @@ -594,10 +594,10 @@ print_attributes(ipp_t *ipp, /* I - IPP request */ * 'read_cb()' - Read data from a buffer. */ -int /* O - Number of bytes read */ +ssize_t /* O - Number of bytes read */ read_cb(void *data, /* I - Data */ ipp_uchar_t *buffer, /* O - Buffer to read */ - int bytes) /* I - Number of bytes to read */ + size_t bytes) /* I - Number of bytes to read */ { int count; /* Number of bytes */ @@ -621,10 +621,10 @@ read_cb(void *data, /* I - Data */ * 'write_cb()' - Write data into a buffer. */ -int /* O - Number of bytes written */ +ssize_t /* O - Number of bytes written */ write_cb(void *data, /* I - Data */ ipp_uchar_t *buffer, /* I - Buffer to write */ - int bytes) /* I - Number of bytes to write */ + size_t bytes) /* I - Number of bytes to write */ { int count; /* Number of bytes */ @@ -645,5 +645,5 @@ write_cb(void *data, /* I - Data */ /* - * End of "$Id: testipp.c 4731 2005-09-30 23:11:10Z mike $". + * End of "$Id: testipp.c 5023 2006-01-29 14:39:44Z mike $". */ diff --git a/cups/util.c b/cups/util.c index e26db23f2..b1108effb 100644 --- a/cups/util.c +++ b/cups/util.c @@ -1,5 +1,5 @@ /* - * "$Id: util.c 4987 2006-01-26 00:25:21Z mike $" + * "$Id: util.c 5023 2006-01-29 14:39:44Z mike $" * * Printing utilities for the Common UNIX Printing System (CUPS). * @@ -121,8 +121,8 @@ cupsCancelJob(const char *name, /* I - Name of printer or class */ * Create a printer URI... */ - if (httpAssembleURIf(uri, sizeof(uri), "ipp", NULL, "localhost", 0, - "/printers/%s", printer) != HTTP_URI_OK) + if (httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, + "localhost", 0, "/printers/%s", printer) != HTTP_URI_OK) { cups_set_error(IPP_INTERNAL_ERROR, NULL); @@ -336,7 +336,7 @@ cupsDoFileRequest(http_t *http, /* I - HTTP connection to server */ break; } - if (httpWrite(http, buffer, bytes) < bytes) + if (httpWrite2(http, buffer, bytes) < bytes) break; } } @@ -891,8 +891,8 @@ cupsGetJobs2(http_t *http, /* I - HTTP connection */ if (mydest) { - if (httpAssembleURIf(uri, sizeof(uri), "ipp", NULL, "localhost", 0, - "/printers/%s", mydest) != HTTP_URI_OK) + if (httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, + "localhost", 0, "/printers/%s", mydest) != HTTP_URI_OK) { cups_set_error(IPP_INTERNAL_ERROR, NULL); @@ -1552,8 +1552,8 @@ cupsPrintFiles2(http_t *http, /* I - HTTP connection */ * Setup the printer URI... */ - if (httpAssembleURIf(uri, sizeof(uri), "ipp", NULL, "localhost", 0, - "/printers/%s", name) != HTTP_URI_OK) + if (httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, + "localhost", 0, "/printers/%s", name) != HTTP_URI_OK) { cups_set_error(IPP_INTERNAL_ERROR, NULL); @@ -1816,8 +1816,8 @@ cups_get_printer_uri( * Setup the printer URI... */ - if (httpAssembleURIf(uri, sizeof(uri), "ipp", NULL, "localhost", 0, - "/printers/%s", name) != HTTP_URI_OK) + if (httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, + "localhost", 0, "/printers/%s", name) != HTTP_URI_OK) { cups_set_error(IPP_INTERNAL_ERROR, NULL); @@ -1877,9 +1877,9 @@ cups_get_printer_uri( for (i = 0; i < attr->num_values; i ++) { - httpSeparateURI(attr->values[i].string.text, scheme, sizeof(scheme), - username, sizeof(username), host, hostsize, - port, resource, resourcesize); + httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[i].string.text, + scheme, sizeof(scheme), username, sizeof(username), + host, hostsize, port, resource, resourcesize); if (!strncmp(resource, "/printers/", 10)) { /* @@ -1901,9 +1901,9 @@ cups_get_printer_uri( { for (i = 0; i < attr->num_values; i ++) { - httpSeparateURI(attr->values[i].string.text, scheme, sizeof(scheme), - username, sizeof(username), host, hostsize, - port, resource, resourcesize); + httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[i].string.text, + scheme, sizeof(scheme), username, sizeof(username), + host, hostsize, port, resource, resourcesize); if (!strncmp(resource, "/classes/", 9)) { /* @@ -1945,9 +1945,9 @@ cups_get_printer_uri( else if ((attr = ippFindAttribute(response, "printer-uri-supported", IPP_TAG_URI)) != NULL) { - httpSeparateURI(attr->values[0].string.text, scheme, sizeof(scheme), - username, sizeof(username), host, hostsize, - port, resource, resourcesize); + httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[0].string.text, + scheme, sizeof(scheme), username, sizeof(username), + host, hostsize, port, resource, resourcesize); ippDelete(response); return (1); @@ -1990,5 +1990,5 @@ cups_set_error(ipp_status_t status, /* I - IPP status code */ /* - * End of "$Id: util.c 4987 2006-01-26 00:25:21Z mike $". + * End of "$Id: util.c 5023 2006-01-29 14:39:44Z mike $". */ |