From d40085f19417c88ca7b927b3ab4f7da5b06137db Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 13 Mar 2003 05:45:30 +0000 Subject: [PATCH] Cookie support and sync with 1.1.x. git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/branches/branch-1.2@3467 7a7537e8-13f0-0310-91df-b6672ffda945 --- CHANGES-1.1.txt | 2 ++ cups/http.c | 70 +++++++++++++++++++++++++++++++++++++++++++++---- cups/http.h | 17 +++++++----- cups/ppd.h | 27 +++++++++++++------ cups/testhttp.c | 5 ++-- 5 files changed, 100 insertions(+), 21 deletions(-) diff --git a/CHANGES-1.1.txt b/CHANGES-1.1.txt index b3dbbdf4e..c58fe88b6 100644 --- a/CHANGES-1.1.txt +++ b/CHANGES-1.1.txt @@ -3,6 +3,8 @@ CHANGES-1.1.txt CHANGES IN CUPS V1.1.19 + - The CUPS API now supports HTTP cookies and the Expect: + field. - The cancel command now correctly supports the "-u user" option to cancel all jobs for the named user. - The Purge-Jobs operation now supports the my-jobs diff --git a/cups/http.c b/cups/http.c index 6656d7f92..c4b6c257e 100644 --- a/cups/http.c +++ b/cups/http.c @@ -1,5 +1,5 @@ /* - * "$Id: http.c,v 1.82.2.28 2003/03/03 18:01:07 mike Exp $" + * "$Id: http.c,v 1.82.2.29 2003/03/13 05:45:28 mike Exp $" * * HTTP routines for the Common UNIX Printing System (CUPS). * @@ -29,6 +29,7 @@ * default HTTP proxy (if any). * httpCheck() - Check to see if there is a pending response from * the server. + * httpClearCookie() - Clear the cookie value(s). * httpClose() - Close an HTTP connection... * httpConnect() - Connect to a HTTP server. * httpConnectEncrypt() - Connect to a HTTP server using encryption. @@ -44,6 +45,7 @@ * httpTrace() - Send an TRACE request to the server. * httpFlush() - Flush data from a HTTP connection. * httpRead() - Read data from a HTTP connection. + * httpSetCookie() - Set the cookie value(s)... * httpWait() - Wait for data available on a connection. * httpWrite() - Write data to a HTTP connection. * httpGets() - Get a line of text from a HTTP connection. @@ -255,6 +257,24 @@ httpCheck(http_t *http) /* I - HTTP connection */ } +/* + * 'httpClearCookie()' - Clear the cookie value(s). + */ + +void +httpClearCookie(http_t *http) /* I - Connection */ +{ + if (!http) + return; + + if (http->cookie) + { + free(http->cookie); + http->cookie = NULL; + } +} + + /* * 'httpClose()' - Close an HTTP connection... */ @@ -268,6 +288,9 @@ httpClose(http_t *http) /* I - Connection to close */ if (http->input_set) free(http->input_set); + if (http->cookie) + free(http->cookie); + #ifdef HAVE_SSL if (http->tls) http_shutdown_ssl(http); @@ -995,6 +1018,27 @@ httpRead(http_t *http, /* I - HTTP data */ } +/* + * 'httpSetCookie()' - Set the cookie value(s)... + */ + +void +httpSetCookie(http_t *http, /* I - Connection */ + const char *cookie) /* I - Cookie string */ +{ + if (!http) + return; + + if (http->cookie) + free(http->cookie); + + if (cookie) + http->cookie = strdup(cookie); + else + http->cookie = NULL; +} + + /* * 'httpWait()' - Wait for data available on a connection. */ @@ -1628,13 +1672,29 @@ httpUpdate(http_t *http) /* I - HTTP data */ * Be tolerants of servers that send unknown attribute fields... */ - if ((field = http_field(line)) == HTTP_FIELD_UNKNOWN) + if (!strcasecmp(line, "expect")) + { + /* + * "Expect: 100-continue" or similar... + */ + + http->expect = (http_status_t)atoi(value); + } + else if (!strcasecmp(line, "cookie")) + { + /* + * "Cookie: name=value[; name=value ...]" - replaces previous cookies... + */ + + httpSetCookie(http, value); + } + else if ((field = http_field(line)) == HTTP_FIELD_UNKNOWN) { DEBUG_printf(("httpUpdate: unknown field %s seen!\n", line)); continue; } - - httpSetField(http, field, value); + else + httpSetField(http, field, value); } else { @@ -2320,5 +2380,5 @@ CDSAWriteFunc(SSLConnectionRef connection, /* I - SSL/TLS connection */ /* - * End of "$Id: http.c,v 1.82.2.28 2003/03/03 18:01:07 mike Exp $". + * End of "$Id: http.c,v 1.82.2.29 2003/03/13 05:45:28 mike Exp $". */ diff --git a/cups/http.h b/cups/http.h index 7d085a145..362e23086 100644 --- a/cups/http.h +++ b/cups/http.h @@ -1,5 +1,5 @@ /* - * "$Id: http.h,v 1.33.2.16 2003/03/13 05:11:55 mike Exp $" + * "$Id: http.h,v 1.33.2.17 2003/03/13 05:45:29 mike Exp $" * * Hyper-Text Transport Protocol definitions for the Common UNIX Printing * System (CUPS). @@ -318,12 +318,11 @@ typedef struct int nonce_count; /* Nonce count */ void *tls; /* TLS state information */ http_encryption_t encryption; /* Encryption requirements */ - /* ADDED IN CUPS 1.1.19 */ + /**** New in CUPS 1.1.19 ****/ fd_set *input_set; /* select() set for httpWait() */ http_status_t expect; /* Expect: header */ - char cookie[HTTP_MAX_VALUE * 2]; - /* Cookie value(s) */ - /* ADDED IN CUPS 1.2 */ + char *cookie; /* Cookie value(s) */ + /**** New in CUPS 1.2 ****/ http_addr_t hostaddr; /* Host address and port */ } http_t; @@ -383,6 +382,12 @@ extern char *httpMD5Final(const char *, const char *, const char *, char [33]); extern char *httpMD5String(const md5_byte_t *, char [33]); +/**** New in CUPS 1.1.19 ****/ +extern void httpClearCookie(http_t *http); +#define httpGetCookie(http) ((http)->cookie) +extern void httpSetCookie(http_t *http, const char *cookie); + +/**** New in CUPS 1.2 ****/ extern int httpAddrEqual(const http_addr_t *addr1, const http_addr_t *addr2); extern void httpAddrLoad(const struct hostent *host, int port, @@ -404,5 +409,5 @@ extern char *httpAddrString(const http_addr_t *addr, #endif /* !_IPP_HTTP_H_ */ /* - * End of "$Id: http.h,v 1.33.2.16 2003/03/13 05:11:55 mike Exp $". + * End of "$Id: http.h,v 1.33.2.17 2003/03/13 05:45:29 mike Exp $". */ diff --git a/cups/ppd.h b/cups/ppd.h index 8a0e96932..218cc15c9 100644 --- a/cups/ppd.h +++ b/cups/ppd.h @@ -1,5 +1,5 @@ /* - * "$Id: ppd.h,v 1.24.2.15 2003/02/28 21:07:34 mike Exp $" + * "$Id: ppd.h,v 1.24.2.16 2003/03/13 05:45:29 mike Exp $" * * PostScript Printer Description definitions for the Common UNIX Printing * System (CUPS). @@ -78,13 +78,15 @@ typedef enum /**** UI types ****/ PPD_UI_BOOLEAN, /* True or False option */ PPD_UI_PICKONE, /* Pick one from a list */ PPD_UI_PICKMANY, /* Pick zero or more from a list */ + /**** New in CUPS 1.2 ****/ PPD_UI_CUPS_TEXT, /* Specify a string */ PPD_UI_CUPS_INTEGER, /* Specify an integer number */ PPD_UI_CUPS_REAL, /* Specify a real number */ PPD_UI_CUPS_GAMMA, /* Specify a gamma number */ PPD_UI_CUPS_CURVE, /* Specify start, end, and gamma numbers */ PPD_UI_CUPS_INTEGER_ARRAY, /* Specify an array of integer numbers */ - PPD_UI_CUPS_REAL_ARRAY /* Specify an array of real numbers */ + PPD_UI_CUPS_REAL_ARRAY, /* Specify an array of real numbers */ + PPD_UI_CUPS_XY_ARRAY /* Specify an array of X/Y real numbers */ } ppd_ui_t; typedef enum /**** Order dependency sections ****/ @@ -191,6 +193,13 @@ typedef union /**** Extended Values ****/ int integer; /* Integer value */ float real; /* Real value */ float gamma; /* Gamma value */ + /**** New in CUPS 1.2 ****/ + struct + { + float start, /* Linear (density) start value for curve */ + end, /* Linear (density) end value for curve */ + gamma; /* Gamma correction */ + } curve; /* Curve values */ struct { int num_elements, /* Number of array elements */ @@ -203,12 +212,12 @@ typedef union /**** Extended Values ****/ } real_array; /* Real array value */ struct { - float start, /* Linear (density) start value for curve */ - end, /* Linear (density) end value for curve */ - gamma; /* Gamma correction */ - } curve; /* Curve values */ + int num_elements; /* Number of array elements */ + float *elements; /* Array of XY values */ + } xy_array; /* XY array value */ } ppd_ext_value_t; +/**** New in CUPS 1.2 ****/ typedef struct /**** Extended Options ****/ { char keyword[PPD_MAX_NAME]; @@ -317,7 +326,7 @@ typedef struct /**** Files ****/ cur_attr; /* Current attribute */ ppd_attr_t **attrs; /* Attributes */ - /**** New for CUPS 1.2 ****/ + /**** New in CUPS 1.2 ****/ int num_extended; /* Number of extended options */ ppd_ext_option_t **extended; /* Extended options */ } ppd_file_t; @@ -376,6 +385,8 @@ extern int ppdMarkRealArray(ppd_file_t *ppd, const char *keyword, int num_values, const float *values); extern int ppdMarkText(ppd_file_t *ppd, const char *keyword, const char *value); +extern int ppdMarkXYArray(ppd_file_t *ppd, const char *keyword, + int num_values, const float *values); extern int ppdSave(ppd_file_t *ppd, FILE *fp); extern int ppdSaveFd(ppd_file_t *ppd, int fd); extern int ppdSaveFile(ppd_file_t *ppd, const char *filename); @@ -391,5 +402,5 @@ extern int ppdSaveFile(ppd_file_t *ppd, const char *filename); #endif /* !_CUPS_PPD_H_ */ /* - * End of "$Id: ppd.h,v 1.24.2.15 2003/02/28 21:07:34 mike Exp $". + * End of "$Id: ppd.h,v 1.24.2.16 2003/03/13 05:45:29 mike Exp $". */ diff --git a/cups/testhttp.c b/cups/testhttp.c index cce3d3633..808553f01 100644 --- a/cups/testhttp.c +++ b/cups/testhttp.c @@ -1,5 +1,5 @@ /* - * "$Id: testhttp.c,v 1.11.2.5 2003/01/07 18:26:30 mike Exp $" + * "$Id: testhttp.c,v 1.11.2.6 2003/03/13 05:45:30 mike Exp $" * * HTTP test program for the Common UNIX Printing System (CUPS). * @@ -33,6 +33,7 @@ */ #include +#include #include "http.h" @@ -122,5 +123,5 @@ main(int argc, /* I - Number of command-line arguments */ /* - * End of "$Id: testhttp.c,v 1.11.2.5 2003/01/07 18:26:30 mike Exp $". + * End of "$Id: testhttp.c,v 1.11.2.6 2003/03/13 05:45:30 mike Exp $". */ -- 2.39.5