--------------------- PatchSet 6333 Date: 2004/10/19 08:51:13 Author: oliv3 Branch: icap-2_5 Tag: (none) Log: preparing new merge Members: src/HttpReply.c:1.10.52.2->1.10.52.3 src/HttpRequest.c:1.7.72.1->1.7.72.2 src/MemBuf.c:1.5.44.5->1.5.44.6 src/carp.c:1.5.88.2->1.5.88.3 src/cf.data.pre:1.49.2.33.2.19->1.49.2.33.2.20 src/client_db.c:1.6.88.2->1.6.88.3 src/client_side.c:1.47.2.28.2.22->1.47.2.28.2.23 src/enums.h:1.29.2.8.2.8->1.29.2.8.2.9 src/forward.c:1.13.6.3.2.6->1.13.6.3.2.7 src/ftp.c:1.18.6.7.2.5->1.18.6.7.2.6 src/http.c:1.17.6.3.6.25->1.17.6.3.6.26 src/icap_common.c:1.1.2.30->1.1.2.31 src/icap_reqmod.c:1.1.2.32->1.1.2.33 src/icap_respmod.c:1.1.2.42->1.1.2.43 src/protos.h:1.41.6.13.2.26->1.41.6.13.2.27 src/structs.h:1.48.2.9.2.31->1.48.2.9.2.32 src/typedefs.h:1.25.6.1.6.8->1.25.6.1.6.9 Index: squid/src/HttpReply.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/HttpReply.c,v retrieving revision 1.10.52.2 retrieving revision 1.10.52.3 diff -u -r1.10.52.2 -r1.10.52.3 --- squid/src/HttpReply.c 15 Oct 2004 15:24:03 -0000 1.10.52.2 +++ squid/src/HttpReply.c 19 Oct 2004 08:51:13 -0000 1.10.52.3 @@ -1,6 +1,6 @@ /* - * $Id: HttpReply.c,v 1.10.52.2 2004/10/15 15:24:03 oliv3 Exp $ + * $Id: HttpReply.c,v 1.10.52.3 2004/10/19 08:51:13 oliv3 Exp $ * * DEBUG: section 58 HTTP Reply (Response) * AUTHOR: Alex Rousskov @@ -143,17 +143,16 @@ * becuase somebody may feed a non NULL-terminated buffer to * us. */ - MemBuf mb = MemBufNull; + char *headers = memAllocate(MEM_4K_BUF); int success; + size_t s = XMIN(end + 1, 4096); /* reset current state, because we are not used in incremental fashion */ httpReplyReset(rep); /* put a string terminator. s is how many bytes to touch in * 'buf' including the terminating NULL. */ - memBufDefInit(&mb); - memBufAppend(&mb, buf, end); - memBufAppend(&mb, "\0", 1); - success = httpReplyParseStep(rep, mb.buf, 0); - memBufClean(&mb); + xstrncpy(headers, buf, s); + success = httpReplyParseStep(rep, headers, 0); + memFree(headers, MEM_4K_BUF); return success == 1; } Index: squid/src/HttpRequest.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/HttpRequest.c,v retrieving revision 1.7.72.1 retrieving revision 1.7.72.2 diff -u -r1.7.72.1 -r1.7.72.2 --- squid/src/HttpRequest.c 15 Oct 2004 15:24:04 -0000 1.7.72.1 +++ squid/src/HttpRequest.c 19 Oct 2004 08:51:13 -0000 1.7.72.2 @@ -1,6 +1,6 @@ /* - * $Id: HttpRequest.c,v 1.7.72.1 2004/10/15 15:24:04 oliv3 Exp $ + * $Id: HttpRequest.c,v 1.7.72.2 2004/10/19 08:51:13 oliv3 Exp $ * * DEBUG: section 73 HTTP Request * AUTHOR: Duane Wessels @@ -55,8 +55,8 @@ requestDestroy(request_t * req) { assert(req); - if (req->body_reader) - requestAbortBody(req); + if (req->body_connection) + clientAbortBody(req); if (req->auth_user_request) authenticateAuthUserRequestUnlock(req->auth_user_request); safe_free(req->canonical); @@ -158,41 +158,3 @@ return 0; return 1; } - -/* - * Read request body contents - */ -void -requestReadBody(request_t * request, char *buf, size_t size, CBCB * callback, void *cbdata) -{ - if (request->body_reader) { - if (cbdataValid(request->body_reader_data)) { - request->body_reader(request, buf, size, callback, cbdata); - } else { - debug(73, 1) ("requestReadBody: Aborted\n"); - request->body_reader = NULL; - cbdataUnlock(request->body_reader_data); - request->body_reader_data = NULL; - callback(buf, 0, cbdata); /* Signal end of body */ - } - } else { - callback(buf, 0, cbdata); /* Signal end of body */ - } -} - -void -requestAbortBody(request_t * request) -{ - if (!request) - return; - if (request->body_reader) { - if (cbdataValid(request->body_reader_data)) { - request->body_reader(request, NULL, -1, NULL, NULL); - } else { - debug(73, 2) ("requestAbortBody: Aborted\n"); - request->body_reader = NULL; - cbdataUnlock(request->body_reader_data); - request->body_reader_data = NULL; - } - } -} Index: squid/src/MemBuf.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/MemBuf.c,v retrieving revision 1.5.44.5 retrieving revision 1.5.44.6 diff -u -r1.5.44.5 -r1.5.44.6 --- squid/src/MemBuf.c 15 Oct 2004 15:24:04 -0000 1.5.44.5 +++ squid/src/MemBuf.c 19 Oct 2004 08:51:13 -0000 1.5.44.6 @@ -1,6 +1,6 @@ /* - * $Id: MemBuf.c,v 1.5.44.5 2004/10/15 15:24:04 oliv3 Exp $ + * $Id: MemBuf.c,v 1.5.44.6 2004/10/19 08:51:13 oliv3 Exp $ * * DEBUG: section 59 auto-growing Memory Buffer with printf * AUTHOR: Alex Rousskov @@ -158,7 +158,7 @@ (*mb->freefunc) (mb->buf); /* free */ mb->freefunc = NULL; /* freeze */ mb->buf = NULL; - mb->size = mb->capacity = mb->max_capacity = 0; + mb->size = mb->capacity = 0; } /* cleans the buffer without changing its capacity Index: squid/src/carp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/carp.c,v retrieving revision 1.5.88.2 retrieving revision 1.5.88.3 diff -u -r1.5.88.2 -r1.5.88.3 --- squid/src/carp.c 15 Oct 2004 15:24:04 -0000 1.5.88.2 +++ squid/src/carp.c 19 Oct 2004 08:51:14 -0000 1.5.88.3 @@ -1,6 +1,6 @@ /* - * $Id: carp.c,v 1.5.88.2 2004/10/15 15:24:04 oliv3 Exp $ + * $Id: carp.c,v 1.5.88.3 2004/10/19 08:51:14 oliv3 Exp $ * * DEBUG: section 39 Cache Array Routing Protocol * AUTHOR: Eric Stern @@ -119,7 +119,7 @@ for (tp = Config.peers; tp; tp = tp->next) { if (0.0 == tp->carp.load_factor) continue; - if (!peerHTTPOkay(tp, request)) + if (tp->tcp_up != PEER_TCP_MAGIC_COUNT) continue; assert(tp->type == PEER_PARENT); combined_hash = (url_hash ^ tp->carp.hash); Index: squid/src/cf.data.pre =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cf.data.pre,v retrieving revision 1.49.2.33.2.19 retrieving revision 1.49.2.33.2.20 diff -u -r1.49.2.33.2.19 -r1.49.2.33.2.20 --- squid/src/cf.data.pre 15 Oct 2004 15:24:04 -0000 1.49.2.33.2.19 +++ squid/src/cf.data.pre 19 Oct 2004 08:51:15 -0000 1.49.2.33.2.20 @@ -1,6 +1,6 @@ # -# $Id: cf.data.pre,v 1.49.2.33.2.19 2004/10/15 15:24:04 oliv3 Exp $ +# $Id: cf.data.pre,v 1.49.2.33.2.20 2004/10/19 08:51:15 oliv3 Exp $ # # # SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -2366,19 +2366,6 @@ matching line. DOC_END -NAME: reply_header_max_size -COMMENT: (KB) -TYPE: b_size_t -DEFAULT: 20 KB -LOC: Config.maxReplyHeaderSize -DOC_START - This specifies the maximum size for HTTP headers in a reply. - Reply headers are usually relatively small (about 512 bytes). - Placing a limit on the reply header size will catch certain - bugs (for example with persistent connections) and possibly - buffer-overflow or denial-of-service attacks. -DOC_END - NAME: reply_body_max_size COMMENT: bytes allow|deny acl acl... TYPE: body_size_t @@ -2918,7 +2905,7 @@ NAME: memory_pools_limit COMMENT: (bytes) TYPE: b_size_t -DEFAULT: 5 MB +DEFAULT: none LOC: Config.MemPools.limit DOC_START Used only with memory_pools on: Index: squid/src/client_db.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_db.c,v retrieving revision 1.6.88.2 retrieving revision 1.6.88.3 diff -u -r1.6.88.2 -r1.6.88.3 --- squid/src/client_db.c 15 Oct 2004 15:24:06 -0000 1.6.88.2 +++ squid/src/client_db.c 19 Oct 2004 08:51:17 -0000 1.6.88.3 @@ -1,6 +1,6 @@ /* - * $Id: client_db.c,v 1.6.88.2 2004/10/15 15:24:06 oliv3 Exp $ + * $Id: client_db.c,v 1.6.88.3 2004/10/19 08:51:17 oliv3 Exp $ * * DEBUG: section 0 Client Database * AUTHOR: Duane Wessels @@ -39,7 +39,6 @@ static ClientInfo *clientdbAdd(struct in_addr addr); static FREE clientdbFreeItem; static void clientdbStartGC(void); -static void clientdbScheduledGC(void *); static int max_clients = 32; static int cleanup_running = 0; @@ -57,10 +56,8 @@ c->addr = addr; hash_join(client_table, &c->hash); statCounter.client_http.clients++; - if ((statCounter.client_http.clients > max_clients) && !cleanup_running && cleanup_scheduled < 2) { - cleanup_scheduled++; - eventAdd("client_db garbage collector", clientdbScheduledGC, NULL, 90, 0); - } + if ((statCounter.client_http.clients > max_clients) && !cleanup_running) + clientdbStartGC(); return c; } @@ -283,9 +280,9 @@ max_clients = statCounter.client_http.clients * 3 / 2; if (!cleanup_scheduled) { cleanup_scheduled = 1; - eventAdd("client_db garbage collector", clientdbScheduledGC, NULL, 3 * 3600, 0); + eventAdd("client_db garbage collector", clientdbScheduledGC, NULL, 6 * 3600, 0); } - debug(49, 2) ("clientdbGC: Removed %d entries\n", cleanup_removed); + debug(49, 1) ("clientdbGC: Removed %d entries\n", cleanup_removed); } } Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.47.2.28.2.22 retrieving revision 1.47.2.28.2.23 diff -u -r1.47.2.28.2.22 -r1.47.2.28.2.23 --- squid/src/client_side.c 15 Oct 2004 15:24:07 -0000 1.47.2.28.2.22 +++ squid/src/client_side.c 19 Oct 2004 08:51:17 -0000 1.47.2.28.2.23 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.47.2.28.2.22 2004/10/15 15:24:07 oliv3 Exp $ + * $Id: client_side.c,v 1.47.2.28.2.23 2004/10/19 08:51:17 oliv3 Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -132,8 +132,6 @@ #if HS_FEAT_ICAP static int clientIcapReqMod(clientHttpRequest * http); #endif -static BODY_HANDLER clientReadBody; -static void clientAbortBody(request_t * req); static int checkAccelOnly(clientHttpRequest * http) @@ -365,11 +363,9 @@ new_request->auth_user_request = old_request->auth_user_request; authenticateAuthUserRequestLock(new_request->auth_user_request); } - if (old_request->body_reader) { - new_request->body_reader = old_request->body_reader; - new_request->body_reader_data = old_request->body_reader_data; - old_request->body_reader = NULL; - old_request->body_reader_data = NULL; + if (old_request->body_connection) { + new_request->body_connection = old_request->body_connection; + old_request->body_connection = NULL; } new_request->content_length = old_request->content_length; new_request->flags.proxy_keepalive = old_request->flags.proxy_keepalive; @@ -824,7 +820,10 @@ MemObject *mem = NULL; debug(33, 3) ("httpRequestFree: %s\n", storeUrl(http->entry)); if (!clientCheckTransferDone(http)) { - requestAbortBody(request); /* abort request body transter */ + if (request && request->body_connection) { + clientAbortBody(request); /* abort request body transter */ + request->body_connection = NULL; + } /* HN: This looks a bit odd.. why should client_side care about * the ICP selection status? */ @@ -2236,7 +2235,7 @@ } else if (clientGotNotEnough(http)) { debug(33, 5) ("clientWriteComplete: client didn't get all it expected\n"); comm_close(fd); - } else if (http->request->body_reader == clientReadBody) { + } else if (http->request->body_connection) { debug(33, 5) ("clientWriteComplete: closing, but first we need to read the rest of the request\n"); /* XXX We assumes the reply does fit in the TCP transmit window. * If not the connection may stall while sending the reply @@ -2902,11 +2901,10 @@ } static int -clientReadDefer(int fd, void *data) +clientReadDefer(int fdnotused, void *data) { - fde *F = &fd_table[fd]; ConnStateData *conn = data; - if (conn->body.size_left && !F->flags.socket_eof) + if (conn->body.size_left) return conn->in.offset >= conn->in.size - 1; else return conn->defer.until > squid_curtime; @@ -3135,15 +3133,9 @@ /* Do we expect a request-body? */ if (request->content_length > 0) { conn->body.size_left = request->content_length; -/*<<<<<<< client_side.c request->body_connection = conn; request->body_reader = clientReadBody; request->body_reader_data = request; - =======*/ - request->body_reader = clientReadBody; - request->body_reader_data = conn; - cbdataLock(conn); - /* Is it too large? */ if (clientRequestBodyTooLarge(request->content_length)) { err = errorCon(ERR_TOO_BIG, HTTP_REQUEST_ENTITY_TOO_LARGE); @@ -3199,20 +3191,16 @@ } /* file_read like function, for reading body content */ -static void -clientReadBody(request_t * request, char *buf, size_t size, CBCB * callback, void *cbdata) +void +clientReadBody(void *data, char *buf, size_t size, CBCB * callback, void *cbdata) { - ConnStateData *conn = request->body_reader_data; - if (!callback) { - clientAbortBody(request); - return; - } + request_t *request = data; + ConnStateData *conn = request->body_connection; if (!conn) { debug(33, 5) ("clientReadBody: no body to read, request=%p\n", request); callback(buf, 0, cbdata); /* Signal end of body */ return; } - assert(cbdataValid(conn)); debug(33, 2) ("clientReadBody: start fd=%d body_size=%lu in.offset=%ld cb=%p req=%p\n", conn->fd, (unsigned long int) conn->body.size_left, (long int) conn->in.offset, callback, request); conn->body.callback = callback; conn->body.cbdata = cbdata; @@ -3254,7 +3242,7 @@ ConnStateData *conn = http->conn; cbdataLock(conn); if (conn->body.request) - requestAbortBody(conn->body.request); + clientAbortBody(conn->body.request); if (cbdataValid(conn)) clientEatRequestBodyHandler(NULL, -1, http); cbdataUnlock(conn); @@ -3297,12 +3285,8 @@ xmemmove(conn->in.buf, conn->in.buf + size, conn->in.offset); /* Remove request link if this is the last part of the body, as * clientReadRequest automatically continues to process next request */ - if (conn->body.size_left <= 0 && request != NULL) { - request->body_reader = NULL; - if (request->body_reader_data) - cbdataUnlock(request->body_reader_data); - request->body_reader_data = NULL; - } + if (conn->body.size_left <= 0 && request != NULL) + request->body_connection = NULL; /* Remove clientReadBody arguments (the call is completed) */ conn->body.request = NULL; conn->body.callback = NULL; @@ -3323,16 +3307,14 @@ } /* Abort a body request */ -static void +void clientAbortBody(request_t * request) { - ConnStateData *conn = request->body_reader_data; + ConnStateData *conn = request->body_connection; char *buf; CBCB *callback; void *cbdata; int valid; - if (!cbdataValid(conn)) - return; if (!conn->body.callback || conn->body.request != request) return; buf = conn->body.buf; Index: squid/src/enums.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/enums.h,v retrieving revision 1.29.2.8.2.8 retrieving revision 1.29.2.8.2.9 diff -u -r1.29.2.8.2.8 -r1.29.2.8.2.9 --- squid/src/enums.h 15 Oct 2004 15:24:10 -0000 1.29.2.8.2.8 +++ squid/src/enums.h 19 Oct 2004 08:51:20 -0000 1.29.2.8.2.9 @@ -1,6 +1,6 @@ /* - * $Id: enums.h,v 1.29.2.8.2.8 2004/10/15 15:24:10 oliv3 Exp $ + * $Id: enums.h,v 1.29.2.8.2.9 2004/10/19 08:51:20 oliv3 Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -487,8 +487,7 @@ HTTP_GATEWAY_TIMEOUT = 504, HTTP_HTTP_VERSION_NOT_SUPPORTED = 505, HTTP_INSUFFICIENT_STORAGE = 507, /* RFC2518 section 10.6 */ - HTTP_INVALID_HEADER = 600, /* Squid header parsing error */ - HTTP_HEADER_TOO_LARGE = 601 /* Header too large to process */ + HTTP_INVALID_HEADER = 600 /* Squid header parsing error */ } http_status; /* Index: squid/src/forward.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/forward.c,v retrieving revision 1.13.6.3.2.6 retrieving revision 1.13.6.3.2.7 diff -u -r1.13.6.3.2.6 -r1.13.6.3.2.7 --- squid/src/forward.c 15 Oct 2004 15:24:10 -0000 1.13.6.3.2.6 +++ squid/src/forward.c 19 Oct 2004 08:51:20 -0000 1.13.6.3.2.7 @@ -1,6 +1,6 @@ /* - * $Id: forward.c,v 1.13.6.3.2.6 2004/10/15 15:24:10 oliv3 Exp $ + * $Id: forward.c,v 1.13.6.3.2.7 2004/10/19 08:51:20 oliv3 Exp $ * * DEBUG: section 17 Request Forwarding * AUTHOR: Duane Wessels @@ -152,7 +152,7 @@ /* If there is a request body then Squid can only try once * even if the method is indempotent */ - if (fwdState->request->body_reader) + if (fwdState->request->body_connection) return 0; /* RFC2616 9.1 Safe and Idempotent Methods */ Index: squid/src/ftp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ftp.c,v retrieving revision 1.18.6.7.2.5 retrieving revision 1.18.6.7.2.6 diff -u -r1.18.6.7.2.5 -r1.18.6.7.2.6 --- squid/src/ftp.c 15 Oct 2004 15:24:10 -0000 1.18.6.7.2.5 +++ squid/src/ftp.c 19 Oct 2004 08:51:21 -0000 1.18.6.7.2.6 @@ -1,6 +1,6 @@ /* - * $Id: ftp.c,v 1.18.6.7.2.5 2004/10/15 15:24:10 oliv3 Exp $ + * $Id: ftp.c,v 1.18.6.7.2.6 2004/10/19 08:51:21 oliv3 Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -2309,7 +2309,7 @@ return; if (!err) { /* Shedule the rest of the request */ - requestReadBody(ftpState->request, ftpState->data.buf, ftpState->data.size, ftpRequestBody, ftpState); + clientReadBody(ftpState->request, ftpState->data.buf, ftpState->data.size, ftpRequestBody, ftpState); } else { debug(9, 1) ("ftpDataWriteCallback: write error: %s\n", xstrerror()); ftpFailed(ftpState, ERR_WRITE_ERROR); @@ -2322,7 +2322,7 @@ FtpStateData *ftpState = (FtpStateData *) data; debug(9, 3) ("ftpDataWrite\n"); /* This starts the body transfer */ - requestReadBody(ftpState->request, ftpState->data.buf, ftpState->data.size, ftpRequestBody, ftpState); + clientReadBody(ftpState->request, ftpState->data.buf, ftpState->data.size, ftpRequestBody, ftpState); } static void Index: squid/src/http.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/http.c,v retrieving revision 1.17.6.3.6.25 retrieving revision 1.17.6.3.6.26 diff -u -r1.17.6.3.6.25 -r1.17.6.3.6.26 --- squid/src/http.c 15 Oct 2004 15:24:12 -0000 1.17.6.3.6.25 +++ squid/src/http.c 19 Oct 2004 08:51:22 -0000 1.17.6.3.6.26 @@ -1,6 +1,6 @@ /* - * $Id: http.c,v 1.17.6.3.6.25 2004/10/15 15:24:12 oliv3 Exp $ + * $Id: http.c,v 1.17.6.3.6.26 2004/10/19 08:51:22 oliv3 Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -67,15 +67,18 @@ return; debug(11, 3) ("httpStateFree: FD %d, httpState = %p\n", fd, data); if (httpState->body_buf) { - requestAbortBody(httpState->orig_request); + if (httpState->orig_request->body_connection) { + clientAbortBody(httpState->orig_request); + } if (httpState->body_buf) { memFree(httpState->body_buf, MEM_8K_BUF); httpState->body_buf = NULL; } } storeUnlockObject(httpState->entry); - if (!memBufIsNull(&httpState->reply_hdr)) { - memBufClean(&httpState->reply_hdr); + if (httpState->reply_hdr) { + memFree(httpState->reply_hdr, MEM_8K_BUF); + httpState->reply_hdr = NULL; } requestUnlink(httpState->request); requestUnlink(httpState->orig_request); @@ -322,7 +325,6 @@ case HTTP_UNAUTHORIZED: case HTTP_PROXY_AUTHENTICATION_REQUIRED: case HTTP_INVALID_HEADER: /* Squid header parsing error */ - case HTTP_HEADER_TOO_LARGE: default: /* Unknown status code */ return 0; /* NOTREACHED */ @@ -374,7 +376,6 @@ } stringClean(&vary); #if X_ACCELERATOR_VARY - pos = NULL; vary = httpHeaderGetList(&reply->header, HDR_X_ACCELERATOR_VARY); while (strListGetItem(&vary, ',', &item, &ilen, &pos)) { char *name = xmalloc(ilen + 1); @@ -402,58 +403,47 @@ void httpProcessReplyHeader(HttpStateData * httpState, const char *buf, int size) { + char *t = NULL; StoreEntry *entry = httpState->entry; + int room; size_t hdr_len; - size_t hdr_size = headersEnd(buf, size); HttpReply *reply = entry->mem_obj->reply; Ctx ctx; debug(11, 3) ("httpProcessReplyHeader: key '%s'\n", storeKeyText(entry->hash.key)); - if (memBufIsNull(&httpState->reply_hdr)) - memBufDefInit(&httpState->reply_hdr); + if (httpState->reply_hdr == NULL) + httpState->reply_hdr = memAllocate(MEM_8K_BUF); assert(httpState->reply_hdr_state == 0); - if (hdr_size) - memBufAppend(&httpState->reply_hdr, buf, hdr_size); - else - memBufAppend(&httpState->reply_hdr, buf, size); - hdr_len = httpState->reply_hdr.size; - if (hdr_len > 4 && strncmp(httpState->reply_hdr.buf, "HTTP/", 5)) { - debug(11, 3) ("httpProcessReplyHeader: Non-HTTP-compliant header: '%s'\n", httpState->reply_hdr.buf); + hdr_len = httpState->reply_hdr_size; + room = 8191 - hdr_len; + xmemcpy(httpState->reply_hdr + hdr_len, buf, room < size ? room : size); + hdr_len += room < size ? room : size; + httpState->reply_hdr[hdr_len] = '\0'; + httpState->reply_hdr_size = hdr_len; + if (hdr_len > 4 && strncmp(httpState->reply_hdr, "HTTP/", 5)) { + debug(11, 3) ("httpProcessReplyHeader: Non-HTTP-compliant header: '%s'\n", httpState->reply_hdr); httpState->reply_hdr_state += 2; - memBufClean(&httpState->reply_hdr); reply->sline.status = HTTP_INVALID_HEADER; return; } - if (hdr_size != hdr_len) - hdr_size = headersEnd(httpState->reply_hdr.buf, hdr_len); - if (hdr_size) - hdr_len = hdr_size; - if (hdr_len > Config.maxReplyHeaderSize) { - debug(11, 1) ("httpProcessReplyHeader: Too large reply header\n"); - if (!memBufIsNull(&httpState->reply_hdr)) - memBufClean(&httpState->reply_hdr); - reply->sline.status = HTTP_HEADER_TOO_LARGE; - return; - } + t = httpState->reply_hdr + hdr_len; /* headers can be incomplete only if object still arriving */ - if (!hdr_size) { - if (httpState->eof) - hdr_size = hdr_len; - else + if (!httpState->eof) { + size_t k = headersEnd(httpState->reply_hdr, 8192); + if (0 == k) return; /* headers not complete */ + t = httpState->reply_hdr + k; } - /* Cut away any excess body data (only needed for debug?) */ - memBufAppend(&httpState->reply_hdr, "\0", 1); - httpState->reply_hdr.buf[hdr_size] = '\0'; + *t = '\0'; httpState->reply_hdr_state++; assert(httpState->reply_hdr_state == 1); ctx = ctx_enter(entry->mem_obj->url); httpState->reply_hdr_state++; debug(11, 9) ("GOT HTTP REPLY HDR:\n---------\n%s\n----------\n", - httpState->reply_hdr.buf); + httpState->reply_hdr); /* Parse headers into reply structure */ /* what happens if we fail to parse here? */ - httpReplyParse(reply, httpState->reply_hdr.buf, hdr_size); + httpReplyParse(reply, httpState->reply_hdr, hdr_len); storeTimestampsSet(entry); /* Check if object is cacheable or not based on reply code */ debug(11, 3) ("httpProcessReplyHeader: HTTP CODE: %d\n", reply->sline.status); @@ -504,7 +494,7 @@ if (Config.onoff.detect_broken_server_pconns && httpReplyBodySize(httpState->request->method, reply) == -1) { debug(11, 1) ("httpProcessReplyHeader: Impossible keep-alive header from '%s'\n", storeUrl(entry)); debug(11, 2) ("GOT HTTP REPLY HDR:\n---------\n%s\n----------\n", - httpState->reply_hdr.buf); + httpState->reply_hdr); httpState->flags.keepalive_broken = 1; } } @@ -664,14 +654,13 @@ clen >>= 1; IOStats.Http.read_hist[bin]++; } - #ifdef HS_FEAT_ICAP if (httpState->icap_writer) (void) 0; else #endif - if (!httpState->reply_hdr.size && len > 0 && fd_table[fd].uses > 1) { + if (!httpState->reply_hdr && len > 0 && fd_table[fd].uses > 1) { /* Skip whitespace */ while (len > 0 && xisspace(*buf)) xmemmove(buf, buf + 1, len--); @@ -689,7 +678,7 @@ commSetSelect(fd, COMM_SELECT_READ, httpReadReply, httpState, 0); } else if (entry->mem_obj->inmem_hi == 0) { ErrorState *err; - err = errorCon(ERR_READ_ERROR, HTTP_BAD_GATEWAY); + err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR); err->request = requestLink((request_t *) request); err->xerrno = errno; fwdFail(httpState->fwd, err); @@ -707,7 +696,7 @@ #endif } else if (len == 0 && entry->mem_obj->inmem_hi == 0) { ErrorState *err; - err = errorCon(ERR_ZERO_SIZE_OBJECT, HTTP_BAD_GATEWAY); + err = errorCon(ERR_ZERO_SIZE_OBJECT, HTTP_SERVICE_UNAVAILABLE); err->xerrno = errno; err->request = requestLink((request_t *) request); fwdFail(httpState->fwd, err); @@ -724,18 +713,8 @@ * we want to process the reply headers. */ httpProcessReplyHeader(httpState, buf, len); - if (entry->mem_obj->reply->sline.status == HTTP_HEADER_TOO_LARGE) { - ErrorState *err; - storeEntryReset(entry); - err = errorCon(ERR_TOO_BIG, HTTP_BAD_GATEWAY); - err->request = requestLink((request_t *) request); - fwdFail(httpState->fwd, err); - httpState->fwd->flags.dont_retry = 1; - } else { - fwdComplete(httpState->fwd); - } + fwdComplete(httpState->fwd); comm_close(fd); - return; } else { #ifdef HS_FEAT_ICAP @@ -760,16 +739,6 @@ if (httpState->reply_hdr_state < 2) { httpProcessReplyHeader(httpState, buf, len); - if (entry->mem_obj->reply->sline.status == HTTP_HEADER_TOO_LARGE) { - ErrorState *err; - storeEntryReset(entry); - err = errorCon(ERR_TOO_BIG, HTTP_BAD_GATEWAY); - err->request = requestLink((request_t *) request); - fwdFail(httpState->fwd, err); - httpState->fwd->flags.dont_retry = 1; - comm_close(fd); - return; - } if (httpState->reply_hdr_state == 2) { http_status s = entry->mem_obj->reply->sline.status; #if WIP_FWD_LOG @@ -881,7 +850,7 @@ return; if (errflag) { if (entry->mem_obj->inmem_hi == 0) { - err = errorCon(ERR_WRITE_ERROR, HTTP_BAD_GATEWAY); + err = errorCon(ERR_WRITE_ERROR, HTTP_INTERNAL_SERVER_ERROR); err->xerrno = errno; err->request = requestLink(httpState->orig_request); errorAppendEntry(entry, err); @@ -1417,7 +1386,7 @@ return; if (errflag) { if (entry->mem_obj->inmem_hi == 0) { - err = errorCon(ERR_WRITE_ERROR, HTTP_BAD_GATEWAY); + err = errorCon(ERR_WRITE_ERROR, HTTP_INTERNAL_SERVER_ERROR); err->xerrno = errno; err->request = requestLink(httpState->orig_request); errorAppendEntry(entry, err); @@ -1430,7 +1399,9 @@ return; } httpState->body_buf = memAllocate(MEM_8K_BUF); - requestReadBody(httpState->orig_request, httpState->body_buf, 8192, httpRequestBodyHandler, httpState); + httpState->orig_request->body_reader( + httpState->orig_request->body_reader_data, + httpState->body_buf, 8192, httpRequestBodyHandler, httpState); } void Index: squid/src/icap_common.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/icap_common.c,v retrieving revision 1.1.2.30 retrieving revision 1.1.2.31 diff -u -r1.1.2.30 -r1.1.2.31 --- squid/src/icap_common.c 15 Oct 2004 15:24:13 -0000 1.1.2.30 +++ squid/src/icap_common.c 19 Oct 2004 08:51:22 -0000 1.1.2.31 @@ -1,5 +1,5 @@ /* - * $Id: icap_common.c,v 1.1.2.30 2004/10/15 15:24:13 oliv3 Exp $ + * $Id: icap_common.c,v 1.1.2.31 2004/10/19 08:51:22 oliv3 Exp $ * * DEBUG: section 81 Internet Content Adaptation Protocol (ICAP) Client * AUTHOR: Geetha Manjunath, Hewlett Packard Company @@ -35,7 +35,6 @@ #include "squid.h" extern PF httpStateFree; -extern char *strcasestr (const char *, const char *); #define EXPECTED_ICAP_HEADER_LEN 256 #define ICAP_OPTIONS_REQUEST Index: squid/src/icap_reqmod.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/icap_reqmod.c,v retrieving revision 1.1.2.32 retrieving revision 1.1.2.33 diff -u -r1.1.2.32 -r1.1.2.33 --- squid/src/icap_reqmod.c 15 Oct 2004 15:24:13 -0000 1.1.2.32 +++ squid/src/icap_reqmod.c 19 Oct 2004 08:51:22 -0000 1.1.2.33 @@ -1,6 +1,6 @@ /* - * $Id: icap_reqmod.c,v 1.1.2.32 2004/10/15 15:24:13 oliv3 Exp $ + * $Id: icap_reqmod.c,v 1.1.2.33 2004/10/19 08:51:22 oliv3 Exp $ * * DEBUG: section 81 Internet Content Adaptation Protocol (ICAP) Client * AUTHOR: Geetha Manjunath, Hewlett Packard Company @@ -50,9 +50,7 @@ static PF icapReqModReadHttpBody; static CWCB icapReqModSendBodyChunk; static CBCB icapReqModBodyHandler; -/*static CB icapReqModPassHttpBody;*/ -static BODY_HANDLER icapReqModPassHttpBody; -/*static void icapReqModPassHttpBody(void *data, char *buf, size_t size, CBCB * callback, void *cbdata);*/ +static CB icapReqModPassHttpBody; static STRCB icapReqModMemBufAppend; #define EXPECTED_ICAP_HEADER_LEN 256 @@ -722,18 +720,11 @@ comm_close(fd); return; } -/* clientReadBody(icap->request, memAllocate(MEM_8K_BUF), 8192, icapReqModBodyHandler, icap); -*/ - requestReadBody(icap->request, - memAllocate(MEM_8K_BUF), - 8192, - icapReqModBodyHandler, - icap); } /* @@ -807,7 +798,7 @@ debug(81, 3) ("%s:%d http_entity.callback=%p\n", __FILE__, __LINE__, icap->reqmod.http_entity.callback); debug(81, 3) ("%s:%d http_entity.buf.size=%d\n", __FILE__, __LINE__, icap->reqmod.http_entity.buf.size); if (icap->reqmod.http_entity.callback && icap->reqmod.http_entity.buf.size) { - icapReqModPassHttpBody(icap->request, + icapReqModPassHttpBody(icap, icap->reqmod.http_entity.callback_buf, icap->reqmod.http_entity.callback_bufsize, icap->reqmod.http_entity.callback, @@ -825,9 +816,9 @@ * body that were stored in the http_entity.buf MemBuf. */ static void -icapReqModPassHttpBody(request_t *req, char *buf, size_t size, CBCB * callback, void *cbdata) +icapReqModPassHttpBody(void *data, char *buf, size_t size, CBCB * callback, void *cbdata) { - IcapStateData *icap = (IcapStateData *)req->body_reader_data; + IcapStateData *icap = data; debug(81, 3) ("icapReqModPassHttpBody: called\n"); if (!cbdataValid(cbdata)) { debug(81, 1) ("icapReqModPassHttpBody: FD %d callback data invalid, closing\n", icap->icap_fd); Index: squid/src/icap_respmod.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/icap_respmod.c,v retrieving revision 1.1.2.42 retrieving revision 1.1.2.43 diff -u -r1.1.2.42 -r1.1.2.43 --- squid/src/icap_respmod.c 15 Oct 2004 15:24:13 -0000 1.1.2.42 +++ squid/src/icap_respmod.c 19 Oct 2004 08:51:23 -0000 1.1.2.43 @@ -1,6 +1,6 @@ /* - * $Id: icap_respmod.c,v 1.1.2.42 2004/10/15 15:24:13 oliv3 Exp $ + * $Id: icap_respmod.c,v 1.1.2.43 2004/10/19 08:51:23 oliv3 Exp $ * * DEBUG: section 81 Internet Content Adaptation Protocol (ICAP) Client * AUTHOR: Geetha Manjunath, Hewlett Packard Company @@ -42,9 +42,6 @@ static int icapReadReply2(IcapStateData * icap); static void icapReadReply3(IcapStateData * icap); -extern void -httpProcessReplyHeader(HttpStateData * httpState, const char *buf, int size); - #define EXPECTED_ICAP_HEADER_LEN 256 const char *crlf = "\r\n"; Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.41.6.13.2.26 retrieving revision 1.41.6.13.2.27 diff -u -r1.41.6.13.2.26 -r1.41.6.13.2.27 --- squid/src/protos.h 15 Oct 2004 15:24:13 -0000 1.41.6.13.2.26 +++ squid/src/protos.h 19 Oct 2004 08:51:23 -0000 1.41.6.13.2.27 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.41.6.13.2.26 2004/10/15 15:24:13 oliv3 Exp $ + * $Id: protos.h,v 1.41.6.13.2.27 2004/10/19 08:51:23 oliv3 Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -141,6 +141,8 @@ extern void clientHttpConnectionsClose(void); extern StoreEntry *clientCreateStoreEntry(clientHttpRequest *, method_t, request_flags); extern int isTcpHit(log_type); +extern CB clientReadBody; +extern void clientAbortBody(request_t * req); extern int commSetNonBlocking(int fd); extern int commUnsetNonBlocking(int fd); @@ -302,6 +304,8 @@ /* http.c */ extern int httpCachable(method_t); extern void httpStart(FwdState *); +extern void httpParseReplyHeaders(const char *, http_reply *); +extern void httpProcessReplyHeader(HttpStateData *, const char *, int); extern mb_size_t httpBuildRequestPrefix(request_t * request, request_t * orig_request, StoreEntry * entry, @@ -517,8 +521,6 @@ extern int httpRequestPrefixLen(const request_t * req); extern int httpRequestHdrAllowed(const HttpHeaderEntry * e, String * strConnection); extern int httpRequestHdrAllowedByName(http_hdr_type id); -extern void requestReadBody(request_t * request, char *buf, size_t size, CBCB * callback, void *cbdata); -extern void requestAbortBody(request_t * request); extern void icmpOpen(void); extern void icmpClose(void); Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.48.2.9.2.31 retrieving revision 1.48.2.9.2.32 diff -u -r1.48.2.9.2.31 -r1.48.2.9.2.32 --- squid/src/structs.h 15 Oct 2004 15:24:14 -0000 1.48.2.9.2.31 +++ squid/src/structs.h 19 Oct 2004 08:51:24 -0000 1.48.2.9.2.32 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.48.2.9.2.31 2004/10/15 15:24:14 oliv3 Exp $ + * $Id: structs.h,v 1.48.2.9.2.32 2004/10/19 08:51:24 oliv3 Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -447,7 +447,6 @@ } Timeout; size_t maxRequestHeaderSize; size_t maxRequestBodySize; - size_t maxReplyHeaderSize; dlink_list ReplyBodySize; struct { u_short icp; @@ -1127,7 +1126,8 @@ struct _HttpStateData { StoreEntry *entry; request_t *request; - MemBuf reply_hdr; + char *reply_hdr; + size_t reply_hdr_size; int reply_hdr_state; peer *peer; /* peer request made to */ int eof; /* reached end-of-object? */ @@ -1821,6 +1821,7 @@ struct in_addr my_addr; unsigned short my_port; HttpHeader header; + ConnStateData *body_connection; /* used by clientReadBody() */ int content_length; HierarchyLogEntry hier; err_type err_type; @@ -1830,7 +1831,7 @@ #if HS_FEAT_ICAP icap_class *class; #endif - BODY_HANDLER *body_reader; + CB *body_reader; void *body_reader_data; }; Index: squid/src/typedefs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/typedefs.h,v retrieving revision 1.25.6.1.6.8 retrieving revision 1.25.6.1.6.9 diff -u -r1.25.6.1.6.8 -r1.25.6.1.6.9 --- squid/src/typedefs.h 15 Oct 2004 15:24:15 -0000 1.25.6.1.6.8 +++ squid/src/typedefs.h 19 Oct 2004 08:51:25 -0000 1.25.6.1.6.9 @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.25.6.1.6.8 2004/10/15 15:24:15 oliv3 Exp $ + * $Id: typedefs.h,v 1.25.6.1.6.9 2004/10/19 08:51:25 oliv3 Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -245,7 +245,7 @@ typedef int READ_HANDLER(int, char *, int); typedef int WRITE_HANDLER(int, const char *, int); typedef void CBCB(char *buf, ssize_t size, void *data); -typedef void BODY_HANDLER(request_t * req, char *, size_t, CBCB *, void *); +typedef void CB(void *, char *, size_t, CBCB *, void *); typedef void STIOCB(void *their_data, int errflag, storeIOState *); typedef void STFNCB(void *their_data, int errflag, storeIOState *);