From f992395da39e0b8442150260536e5bd41b0271d6 Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 4 Feb 2004 19:06:49 +0000 Subject: [PATCH] Fix httpFlush() and friends when doing PUT or OPTION requests (STR #558) git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@4039 7a7537e8-13f0-0310-91df-b6672ffda945 --- CHANGES.txt | 4 ++- cups/getputfile.c | 23 ++++++++--------- cups/http.c | 65 +++++++++++++++++++++++++++++++---------------- cups/util.c | 20 +++++---------- 4 files changed, 63 insertions(+), 49 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d39c88a78..c4aba3281 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,8 +1,10 @@ -CHANGES.txt - 02/03/2004 +CHANGES.txt - 02/04/2004 ------------------------ CHANGES IN CUPS V1.1.21rc1 + - The httpFlush() function did not always flush the + remaining response data in requests (STR #558) - The scheduler could complete a job before it collected the exit status from all filters and the backend (STR #448) diff --git a/cups/getputfile.c b/cups/getputfile.c index e58803624..54e59b394 100644 --- a/cups/getputfile.c +++ b/cups/getputfile.c @@ -1,5 +1,5 @@ /* - * "$Id: getputfile.c,v 1.2 2004/02/04 02:32:27 mike Exp $" + * "$Id: getputfile.c,v 1.3 2004/02/04 19:06:49 mike Exp $" * * Get/put file functions for the Common UNIX Printing System (CUPS). * @@ -139,22 +139,16 @@ cupsGetFd(http_t *http, /* I - HTTP connection to server */ #ifdef HAVE_LIBSSL else if (status == HTTP_UPGRADE_REQUIRED) { - /* - * Flush any error message... - */ - + /* Flush any error message... */ httpFlush(http); - /* - * Upgrade with encryption... - */ + /* Reconnect... */ + httpReconnect(http); + /* Upgrade with encryption... */ httpEncryption(http, HTTP_ENCRYPT_REQUIRED); - /* - * Try again, this time with encryption enabled... - */ - + /* Try again, this time with encryption enabled... */ continue; } #endif /* HAVE_LIBSSL */ @@ -362,6 +356,9 @@ cupsPutFd(http_t *http, /* I - HTTP connection to server */ /* Flush any error message... */ httpFlush(http); + /* Reconnect... */ + httpReconnect(http); + /* Upgrade with encryption... */ httpEncryption(http, HTTP_ENCRYPT_REQUIRED); @@ -437,5 +434,5 @@ cupsPutFile(http_t *http, /* I - HTTP connection to server */ /* - * End of "$Id: getputfile.c,v 1.2 2004/02/04 02:32:27 mike Exp $". + * End of "$Id: getputfile.c,v 1.3 2004/02/04 19:06:49 mike Exp $". */ diff --git a/cups/http.c b/cups/http.c index bdf6966d0..07daf6bf8 100644 --- a/cups/http.c +++ b/cups/http.c @@ -1,5 +1,5 @@ /* - * "$Id: http.c,v 1.127 2003/11/19 18:05:55 mike Exp $" + * "$Id: http.c,v 1.128 2004/02/04 19:06:49 mike Exp $" * * HTTP routines for the Common UNIX Printing System (CUPS). * @@ -456,6 +456,8 @@ int /* O - -1 on error, 0 on success */ httpEncryption(http_t *http, /* I - HTTP data */ http_encryption_t e) /* I - New encryption preference */ { + DEBUG_printf(("httpEncryption(http=%p, e=%d)\n", http, e)); + #ifdef HAVE_SSL if (!http) return (0); @@ -487,6 +489,12 @@ httpReconnect(http_t *http) /* I - HTTP data */ { int val; /* Socket option value */ + + DEBUG_printf(("httpReconnect(http=%p)\n", http)); + + if (!http) + return (-1); + #ifdef HAVE_SSL if (http->tls) http_shutdown_ssl(http); @@ -620,7 +628,7 @@ httpGetSubField(http_t *http, /* I - HTTP data */ name == NULL || value == NULL) return (NULL); - DEBUG_printf(("httpGetSubField(%p, %d, \"%s\", %p)\n", + DEBUG_printf(("httpGetSubField(http=%p, field=%d, name=\"%s\", value=%p)\n", http, field, name, value)); for (fptr = http->fields[field]; *fptr;) @@ -648,7 +656,7 @@ httpGetSubField(http_t *http, /* I - HTTP data */ *ptr = '\0'; - DEBUG_printf(("name = \"%s\"\n", temp)); + DEBUG_printf(("httpGetSubField: name=\"%s\"\n", temp)); /* * Skip trailing chars up to the '='... @@ -706,7 +714,7 @@ httpGetSubField(http_t *http, /* I - HTTP data */ fptr ++; } - DEBUG_printf(("value = \"%s\"\n", value)); + DEBUG_printf(("httpGetSubField: value=\"%s\"\n", value)); /* * See if this is the one... @@ -834,15 +842,14 @@ httpTrace(http_t *http, /* I - HTTP data */ */ void -httpFlush(http_t *http) /* I - HTTP data */ +httpFlush(http_t *http) /* I - HTTP data */ { - char buffer[8192]; /* Junk buffer */ + char buffer[8192]; /* Junk buffer */ - if (http->state != HTTP_WAITING) - { - while (httpRead(http, buffer, sizeof(buffer)) > 0); - } + DEBUG_printf(("httpFlush(http=%p), state=%d\n", http, http->state)); + + while (httpRead(http, buffer, sizeof(buffer)) > 0); } @@ -859,7 +866,8 @@ httpRead(http_t *http, /* I - HTTP data */ char len[32]; /* Length string */ - DEBUG_printf(("httpRead(%p, %p, %d)\n", http, buffer, length)); + DEBUG_printf(("httpRead(http=%p, buffer=%p, length=%d)\n", + http, buffer, length)); if (http == NULL || buffer == NULL) return (-1); @@ -888,7 +896,7 @@ httpRead(http_t *http, /* I - HTTP data */ } } - DEBUG_printf(("httpRead: data_remaining = %d\n", http->data_remaining)); + DEBUG_printf(("httpRead: data_remaining=%d\n", http->data_remaining)); if (http->data_remaining <= 0) { @@ -905,6 +913,12 @@ httpRead(http_t *http, /* I - HTTP data */ else http->state = HTTP_WAITING; + /* + * Prevent future reads for this request... + */ + + http->data_encoding = HTTP_ENCODE_LENGTH; + return (0); } else if (length > http->data_remaining) @@ -1269,7 +1283,7 @@ httpGets(char *line, /* I - Line to read into */ int bytes; /* Number of bytes read */ - DEBUG_printf(("httpGets(%p, %d, %p)\n", line, length, http)); + DEBUG_printf(("httpGets(line=%p, length=%d, http=%p)\n", line, length, http)); if (http == NULL || line == NULL) return (NULL); @@ -1324,7 +1338,7 @@ httpGets(char *line, /* I - Line to read into */ continue; } - DEBUG_printf(("httpGets(): recv() error %d!\n", WSAGetLastError())); + DEBUG_printf(("httpGets: recv() error %d!\n", WSAGetLastError())); #else if (errno == EINTR) continue; @@ -1334,7 +1348,7 @@ httpGets(char *line, /* I - Line to read into */ continue; } - DEBUG_printf(("httpGets(): recv() error %d!\n", errno)); + DEBUG_printf(("httpGets: recv() error %d!\n", errno)); #endif /* WIN32 */ return (NULL); @@ -1391,11 +1405,11 @@ httpGets(char *line, /* I - Line to read into */ if (http->used > 0) memmove(http->buffer, bufptr, http->used); - DEBUG_printf(("httpGets(): Returning \"%s\"\n", line)); + DEBUG_printf(("httpGets: Returning \"%s\"\n", line)); return (line); } - DEBUG_puts("httpGets(): No new line available!"); + DEBUG_puts("httpGets: No new line available!"); return (NULL); } @@ -1418,6 +1432,8 @@ httpPrintf(http_t *http, /* I - HTTP data */ va_list ap; /* Variable argument pointer */ + DEBUG_printf(("httpPrintf(http=%p, format=\"%s\", ...)\n", http, format)); + va_start(ap, format); bytes = vsnprintf(buf, sizeof(buf), format, ap); va_end(ap); @@ -1531,7 +1547,7 @@ httpUpdate(http_t *http) /* I - HTTP data */ http_status_t status; /* Authorization status */ - DEBUG_printf(("httpUpdate(%p)\n", http)); + DEBUG_printf(("httpUpdate(http=%p), state=%d\n", http, http->state)); /* * If we haven't issued any commands, then there is nothing to "update"... @@ -1546,7 +1562,7 @@ httpUpdate(http_t *http) /* I - HTTP data */ while (httpGets(line, sizeof(line), http) != NULL) { - DEBUG_puts(line); + DEBUG_printf(("httpUpdate: Got \"%s\"\n", line)); if (line[0] == '\0') { @@ -1810,7 +1826,7 @@ httpEncode64(char *out, /* I - String to write to */ int /* O - Content length */ httpGetLength(http_t *http) /* I - HTTP data */ { - DEBUG_printf(("httpGetLength(%p), state = %d\n", http, http->state)); + DEBUG_printf(("httpGetLength(http=%p), state=%d\n", http, http->state)); if (strcasecmp(http->fields[HTTP_FIELD_TRANSFER_ENCODING], "chunked") == 0) { @@ -1836,7 +1852,7 @@ httpGetLength(http_t *http) /* I - HTTP data */ else http->data_remaining = atoi(http->fields[HTTP_FIELD_CONTENT_LENGTH]); - DEBUG_printf(("httpGetLength: content_length = %d\n", http->data_remaining)); + DEBUG_printf(("httpGetLength: content_length=%d\n", http->data_remaining)); } return (http->data_remaining); @@ -1893,6 +1909,9 @@ http_send(http_t *http, /* I - HTTP data */ /* Hex digits */ + DEBUG_printf(("http_send(http=%p, request=HTTP_%s, uri=\"%s\")\n", + http, codes[request], uri)); + if (http == NULL || uri == NULL) return (-1); @@ -1985,6 +2004,8 @@ http_wait(http_t *http, /* I - HTTP data */ int nfds; /* Result from select() */ + DEBUG_printf(("http_wait(http=%p, msec=%d)\n", http, msec)); + /* * Check the SSL/TLS buffers for data first... */ @@ -2420,5 +2441,5 @@ CDSAWriteFunc(SSLConnectionRef connection, /* I - SSL/TLS connection */ /* - * End of "$Id: http.c,v 1.127 2003/11/19 18:05:55 mike Exp $". + * End of "$Id: http.c,v 1.128 2004/02/04 19:06:49 mike Exp $". */ diff --git a/cups/util.c b/cups/util.c index 436045bdd..84f542012 100644 --- a/cups/util.c +++ b/cups/util.c @@ -1,5 +1,5 @@ /* - * "$Id: util.c,v 1.113 2003/10/30 15:45:20 mike Exp $" + * "$Id: util.c,v 1.114 2004/02/04 19:06:49 mike Exp $" * * Printing utilities for the Common UNIX Printing System (CUPS). * @@ -344,22 +344,16 @@ cupsDoFileRequest(http_t *http, /* I - HTTP connection to server */ #ifdef HAVE_SSL else if (status == HTTP_UPGRADE_REQUIRED) { - /* - * Flush any error message... - */ - + /* Flush any error message... */ httpFlush(http); - /* - * Upgrade with encryption... - */ + /* Reconnect... */ + httpReconnect(http); + /* Upgrade with encryption... */ httpEncryption(http, HTTP_ENCRYPT_REQUIRED); - /* - * Try again, this time with encryption enabled... - */ - + /* Try again, this time with encryption enabled... */ continue; } #endif /* HAVE_SSL */ @@ -1560,5 +1554,5 @@ cups_connect(const char *name, /* I - Destination (printer[@host]) */ /* - * End of "$Id: util.c,v 1.113 2003/10/30 15:45:20 mike Exp $". + * End of "$Id: util.c,v 1.114 2004/02/04 19:06:49 mike Exp $". */ -- 2.39.5