--------------------- PatchSet 4941 Date: 2002/09/09 22:18:59 Author: rbcollins Branch: esi Tag: (none) Log: indent Members: src/client_side.c:1.65.2.18->1.65.2.19 src/client_side_reply.c:1.1.2.22->1.1.2.23 src/client_side_request.c:1.1.2.15->1.1.2.16 src/http.c:1.21.2.4->1.21.2.5 Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.65.2.18 retrieving revision 1.65.2.19 diff -u -r1.65.2.18 -r1.65.2.19 --- squid/src/client_side.c 28 Aug 2002 06:11:30 -0000 1.65.2.18 +++ squid/src/client_side.c 9 Sep 2002 22:18:59 -0000 1.65.2.19 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.65.2.18 2002/08/28 06:11:30 rbcollins Exp $ + * $Id: client_side.c,v 1.65.2.19 2002/09/09 22:18:59 rbcollins Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -125,22 +125,28 @@ */ /* our socket-related context */ -typedef struct _clientSocketContext { - clientHttpRequest *http; /* we own this */ +typedef struct _clientSocketContext +{ + clientHttpRequest *http; /* we own this */ char reqbuf[HTTP_REQBUF_SZ]; struct _clientSocketContext *next; - struct { - int deferred:1; /* This is a pipelined request waiting for the - * current object to complete */ - } flags; - struct { + struct + { + int deferred:1; /* This is a pipelined request waiting for the + * current object to complete */ + } + flags; + struct + { clientStreamNode *node; HttpReply *rep; const char *body_data; ssize_t body_size; - } deferredparams; -} clientSocketContext; -CBDATA_TYPE (clientSocketContext); + } + deferredparams; +} +clientSocketContext; +CBDATA_TYPE(clientSocketContext); /* Local functions */ /* clientSocketContext */ @@ -154,29 +160,31 @@ static PF requestTimeout; static PF clientLifetimeTimeout; static void checkFailureRatio(err_type, hier_code); -static clientSocketContext *parseHttpRequestAbort(ConnStateData * conn, const char *uri); -static clientSocketContext *parseHttpRequest(ConnStateData *, method_t *, int *, char **, size_t *); +static clientSocketContext *parseHttpRequestAbort(ConnStateData * conn, + const char *uri); +static clientSocketContext *parseHttpRequest(ConnStateData *, method_t *, int *, + char **, size_t *); #if USE_IDENT static IDCB clientIdentDone; #endif static CSCB clientSocketRecipient; -static CSD clientSocketDetach; +static CSD clientSocketDetach; static void clientSetKeepaliveFlag(clientHttpRequest *); static int clientCheckContentLength(request_t * r); static DEFER httpAcceptDefer; static int clientRequestBodyTooLarge(int clen); static void clientProcessBody(ConnStateData * conn); -void -clientSocketContextFree (void *data) +void +clientSocketContextFree(void *data) { clientSocketContext *context = data; ConnStateData *conn = context->http->conn; clientStreamNode *node = context->http->client_stream.tail->data; /* We are *always* the tail - prevent recursive free */ - assert (context == node->data); + assert(context == node->data); node->data = NULL; - httpRequestFree (context->http); + httpRequestFree(context->http); /* clean up connection links to us */ assert(context != context->next); if (conn) { @@ -185,7 +193,7 @@ assert(conn->currentobject != NULL); /* Unlink us from the connection request list */ p = &conn->currentobject; - S = (clientSocketContext **)p; + S = (clientSocketContext **) p; while (*S) { if (*S == context) break; @@ -198,12 +206,12 @@ } clientSocketContext * -clientSocketContextNew (clientHttpRequest *http) +clientSocketContextNew(clientHttpRequest * http) { clientSocketContext *rv; - assert (http != NULL); + assert(http != NULL); CBDATA_INIT_TYPE_FREECB(clientSocketContext, clientSocketContextFree); - rv = cbdataAlloc (clientSocketContext); + rv = cbdataAlloc(clientSocketContext); rv->http = http; return rv; } @@ -289,7 +297,7 @@ ConnStateData *conn; request_t *request = NULL; MemObject *mem = NULL; - assert (http != NULL); + assert(http != NULL); conn = http->conn; request = http->request; debug(33, 3) ("httpRequestFree: %s\n", http->uri); @@ -326,7 +334,9 @@ http->al.headers.request = xstrdup(mb.buf); http->al.hier = request->hier; if (request->auth_user_request) { - http->al.cache.authuser = xstrdup(authenticateUserRequestUsername(request->auth_user_request)); + http->al.cache.authuser = + xstrdup(authenticateUserRequestUsername(request-> + auth_user_request)); authenticateAuthUserRequestUnlock(request->auth_user_request); request->auth_user_request = NULL; } @@ -338,7 +348,8 @@ accessLogLog(&http->al); clientUpdateCounters(http); if (conn) - clientdbUpdate(conn->peer.sin_addr, http->log_type, PROTO_HTTP, http->out.size); + clientdbUpdate(conn->peer.sin_addr, http->log_type, PROTO_HTTP, + http->out.size); } if (request) checkFailureRatio(request->err_type, http->al.hier.code); @@ -350,8 +361,8 @@ safe_free(http->redirect.location); requestUnlink(http->request); if (http->client_stream.tail) - clientStreamAbort (http->client_stream.tail->data, http); - /* moving to the next connection is handled by the context free */ + clientStreamAbort(http->client_stream.tail->data, http); + /* moving to the next connection is handled by the context free */ dlinkDelete(&http->active, &ClientActiveRequests); cbdataFree(http); } @@ -367,8 +378,9 @@ clientdbEstablished(connState->peer.sin_addr, -1); /* decrement */ while ((context = connState->currentobject) != NULL) { assert(context->http->conn == connState); - assert(connState->currentobject != ((clientSocketContext *)connState->currentobject)->next); - cbdataFree (context); + assert(connState->currentobject != + ((clientSocketContext *) connState->currentobject)->next); + cbdataFree(context); } if (connState->auth_user_request) authenticateAuthUserRequestUnlock(connState->auth_user_request); @@ -473,21 +485,22 @@ * There are no more entries in the stream chain. */ static void -clientSocketRecipient (clientStreamNode *node, clientHttpRequest *http, HttpReply *rep, const char *body_data, ssize_t body_size) +clientSocketRecipient(clientStreamNode * node, clientHttpRequest * http, + HttpReply * rep, const char *body_data, ssize_t body_size) { int fd; clientSocketContext *context; /* Test preconditions */ - assert (node != NULL); + assert(node != NULL); /* TODO: handle this rather than asserting - it should only ever happen if we cause an abort and * the callback chain loops back to here, so we can simply return. * However, that itself shouldn't happen, so it stays as an assert for now. */ - assert (cbdataReferenceValid (node)); - assert (node->data != NULL); - assert (node->node.next == NULL); + assert(cbdataReferenceValid(node)); + assert(node->data != NULL); + assert(node->node.next == NULL); context = node->data; - assert (http->conn && http->conn->fd != -1); + assert(http->conn && http->conn->fd != -1); fd = http->conn->fd; if (http->conn->currentobject != context) { /* there is another object in progress, defer this one */ @@ -509,7 +522,8 @@ assert(rep == NULL); /* Avoid copying to MemBuf if we know "rep" is NULL, and we only have a body */ http->out.offset += body_size; - comm_write(fd, body_data, body_size, clientWriteBodyComplete, context, NULL); + comm_write(fd, body_data, body_size, clientWriteBodyComplete, context, + NULL); /* NULL because its a static buffer */ return; } else { @@ -543,24 +557,24 @@ * only */ void -clientSocketDetach (clientStreamNode *node, clientHttpRequest *http) +clientSocketDetach(clientStreamNode * node, clientHttpRequest * http) { clientSocketContext *context; /* Test preconditions */ - assert (node != NULL); + assert(node != NULL); /* TODO: handle this rather than asserting - it should only ever happen if we cause an abort and * the callback chain loops back to here, so we can simply return. * However, that itself shouldn't happen, so it stays as an assert for now. */ - assert (cbdataReferenceValid (node)); + assert(cbdataReferenceValid(node)); /* Set null by ContextFree */ - assert (node->data == NULL); - assert (node->node.next == NULL); + assert(node->data == NULL); + assert(node->node.next == NULL); context = node->data; /* We are only called when the client socket shutsdown. * Tell the prev pipeline member we're finished */ - clientStreamDetach (node, http); + clientStreamDetach(node, http); } /* @@ -580,9 +594,9 @@ } static void -clientKeepaliveNextRequest(clientSocketContext *context) +clientKeepaliveNextRequest(clientSocketContext * context) { - clientHttpRequest * http = context->http; + clientHttpRequest *http = context->http; ConnStateData *conn = http->conn; debug(33, 3) ("clientKeepaliveNextRequest: FD %d\n", conn->fd); @@ -595,7 +609,8 @@ /* * Set the timeout BEFORE calling clientReadRequest(). */ - commSetTimeout(conn->fd, Config.Timeout.persistent_request, requestTimeout, conn); + commSetTimeout(conn->fd, Config.Timeout.persistent_request, + requestTimeout, conn); /* * CYGWIN has a problem and is blocking on read() requests when there * is no data present. @@ -616,11 +631,11 @@ /* If the client stream is waiting on a socket write to occur, then */ if (context->flags.deferred) { /* NO data is allowed to have been sent */ - assert (http->out.size == 0); - clientSocketRecipient (context->deferredparams.node, http, - context->deferredparams.rep, - context->deferredparams.body_data, - context->deferredparams.body_size); + assert(http->out.size == 0); + clientSocketRecipient(context->deferredparams.node, http, + context->deferredparams.rep, + context->deferredparams.body_data, + context->deferredparams.body_size); } /* otherwise, the request is still active in a callbacksomewhere, * and we are done @@ -633,7 +648,8 @@ * */ static void -clientWriteComplete(int fd, char *bufnotused, size_t size, int errflag, void *data) +clientWriteComplete(int fd, char *bufnotused, size_t size, int errflag, + void *data) { clientSocketContext *context = data; clientHttpRequest *http = context->http; @@ -641,8 +657,9 @@ /* cheating: we are always the tail */ clientStreamNode *node = http->client_stream.tail->data; http->out.size += size; - debug(33, 5) ("clientWriteComplete: FD %d, sz %ld, err %d, off %ld, len %d\n", - fd, (long int) size, errflag, (long int) http->out.size, entry ? objectLen(entry) : 0); + debug(33,5) ("clientWriteComplete: FD %d, sz %ld, err %d, off %ld, len %d\n", + fd, (long int) size, errflag, (long int) http->out.size, + entry ? objectLen(entry) : 0); if (size > 0 && fd > -1) { kb_incr(&statCounter.client_http.kbytes_out, size); if (isTcpHit(http->log_type)) @@ -653,34 +670,34 @@ * just close the socket, httpRequestFree will abort if needed. * errflag is only EVER set by the comms callbacks */ - assert (fd != -1); + assert(fd != -1); comm_close(fd); return; } if (clientHttpRequestStatus(fd, http)) { if (fd != -1) - comm_close (fd); - /* Do we leak here ?*/ + comm_close(fd); + /* Do we leak here ? */ return; } - switch (clientStreamStatus (node, http)) { - case STREAM_NONE: - /* More data will be coming from the stream. */ - clientStreamRead (http->client_stream.tail->data, http, http->out.offset, - HTTP_REQBUF_SZ, - context->reqbuf); + switch (clientStreamStatus(node, http)) { + case STREAM_NONE: + /* More data will be coming from the stream. */ + clientStreamRead(http->client_stream.tail->data, http, http->out.offset, + HTTP_REQBUF_SZ, context->reqbuf); break; - case STREAM_COMPLETE: + case STREAM_COMPLETE: debug(33, 5) ("clientWriteComplete: FD %d Keeping Alive\n", fd); clientKeepaliveNextRequest(context); return; - case STREAM_UNPLANNED_COMPLETE: + case STREAM_UNPLANNED_COMPLETE: /* fallthrough */ - case STREAM_FAILED: - if (fd != -1) - comm_close (fd); + case STREAM_FAILED: + if (fd != -1) + comm_close(fd); return; - default:fatal ("Hit unreachable code in clientWriteComplete\n"); + default: + fatal("Hit unreachable code in clientWriteComplete\n"); } } @@ -699,15 +716,18 @@ http->req_sz = conn->in.offset; http->uri = xstrdup(uri); http->log_uri = xstrndup(uri, MAX_URL); - context = clientSocketContextNew (http); - clientStreamInit (&http->client_stream, clientGetMoreData, clientReplyDetach, clientReplyStatus, clientReplyNewContext (http), clientSocketRecipient, clientSocketDetach, context, context->reqbuf, HTTP_REQBUF_SZ); + context = clientSocketContextNew(http); + clientStreamInit(&http->client_stream, clientGetMoreData, clientReplyDetach, + clientReplyStatus, clientReplyNewContext(http), clientSocketRecipient, + clientSocketDetach, context, context->reqbuf, HTTP_REQBUF_SZ); dlinkAdd(http, &http->active, &ClientActiveRequests); return context; } /* Utility function to perform part of request parsing */ static clientSocketContext * -clientParseHttpRequestLine (char *inbuf, size_t req_sz, ConnStateData * conn, method_t *method_p, char **url_p, http_version_t *http_ver_p) +clientParseHttpRequestLine(char *inbuf, size_t req_sz, ConnStateData * conn, + method_t * method_p, char **url_p, http_version_t * http_ver_p) { char *mstr = NULL; char *url = NULL; @@ -733,37 +753,39 @@ /* look for URL+HTTP/x.x */ if ((url = strtok(NULL, "\n")) == NULL) { - debug(33, 1) ("parseHttpRequest: Missing URL\n"); - return parseHttpRequestAbort(conn, "error:missing-url"); + debug(33, 1) ("parseHttpRequest: Missing URL\n"); + return parseHttpRequestAbort(conn, "error:missing-url"); } while (xisspace(*url)) - url++; + url++; t = url + strlen(url); assert(*t == '\0'); while (t > url) { - t--; - if (xisspace(*t) && !strncmp(t + 1, "HTTP/", 5)) { - token = t + 1; - break; - } + t--; + if (xisspace(*t) && !strncmp(t + 1, "HTTP/", 5)) { + token = t + 1; + break; + } } while (t > url && xisspace(*t)) - *(t--) = '\0'; + *(t--) = '\0'; debug(33, 5) ("parseHttpRequest: URI is '%s'\n", url); *url_p = url; if (token == NULL) { - debug(33, 3) ("parseHttpRequest: Missing HTTP identifier\n"); + debug(33, 3) ("parseHttpRequest: Missing HTTP identifier\n"); #if RELAXED_HTTP_PARSER - httpBuildVersion(http_ver_p, 0, 9); /* wild guess */ + httpBuildVersion(http_ver_p, 0, 9); /* wild guess */ #else - return parseHttpRequestAbort(conn, "error:missing-http-ident"); + return parseHttpRequestAbort(conn, "error:missing-http-ident"); #endif } else { - if (sscanf(token + 5, "%d.%d", &http_ver_p->major, &http_ver_p->minor) != 2) { - debug(33, 3) ("parseHttpRequest: Invalid HTTP identifier.\n"); - return parseHttpRequestAbort(conn, "error: invalid HTTP-ident"); - } - debug(33, 6) ("parseHttpRequest: Client HTTP version %d.%d.\n", http_ver_p->major, http_ver_p->minor); + if (sscanf(token + 5, "%d.%d", &http_ver_p->major, + &http_ver_p->minor) != 2) { + debug(33, 3) ("parseHttpRequest: Invalid HTTP identifier.\n"); + return parseHttpRequestAbort(conn, "error: invalid HTTP-ident"); + } + debug(33, 6) ("parseHttpRequest: Client HTTP version %d.%d.\n", + http_ver_p->major, http_ver_p->minor); } /* everything was ok */ @@ -824,7 +846,9 @@ *(inbuf + req_sz) = '\0'; /* Is there a legitimate first line to the headers ? */ - if ((context = clientParseHttpRequestLine (inbuf, req_sz, conn, method_p, &url, &http_ver))) { + if ((context = + clientParseHttpRequestLine(inbuf, req_sz, conn, method_p, &url, + &http_ver))) { /* something wrong, abort */ xfree(inbuf); return context; @@ -858,16 +882,19 @@ http->conn = conn; http->start = current_time; http->req_sz = prefix_sz; - context = clientSocketContextNew (http); - clientStreamInit (&http->client_stream, clientGetMoreData, clientReplyDetach, clientReplyStatus, clientReplyNewContext (http), clientSocketRecipient, clientSocketDetach, context, context->reqbuf, HTTP_REQBUF_SZ); + context = clientSocketContextNew(http); + clientStreamInit(&http->client_stream, clientGetMoreData, clientReplyDetach, + clientReplyStatus, clientReplyNewContext(http), clientSocketRecipient, + clientSocketDetach, context, context->reqbuf, HTTP_REQBUF_SZ); *prefix_p = xmalloc(prefix_sz + 1); xmemcpy(*prefix_p, conn->in.buf, prefix_sz); *(*prefix_p + prefix_sz) = '\0'; dlinkAdd(http, &http->active, &ClientActiveRequests); /* XXX this function is still way to long. here is a natural point for further simplification */ - - debug(33, 5) ("parseHttpRequest: Request Header is\n%s\n", (*prefix_p) + *req_line_sz_p); + + debug(33, 5) ("parseHttpRequest: Request Header is\n%s\n", + (*prefix_p) + *req_line_sz_p); #if THIS_VIOLATES_HTTP_SPECS_ON_URL_TRANSFORMATION if ((t = strchr(url, '#'))) /* remove HTML anchors */ *t = '\0'; @@ -906,8 +933,7 @@ if (vport_mode) vport = atoi(q); } - url_sz = strlen(url) + 32 + Config.appendDomainLen + - strlen(t); + url_sz = strlen(url) + 32 + Config.appendDomainLen + strlen(t); http->uri = xcalloc(url_sz, 1); #if SSL_FORWARDING_NOT_YET_DONE @@ -968,17 +994,16 @@ natfd = -1; cbdataFree(context); xfree(inbuf); - return parseHttpRequestAbort(conn, "error:nat-lookup-failed"); + return parseHttpRequestAbort(conn, + "error:nat-lookup-failed"); } else snprintf(http->uri, url_sz, "http://%s:%d%s", - inet_ntoa(http->conn->me.sin_addr), - vport, url); + inet_ntoa(http->conn->me.sin_addr), vport, url); } else { if (vport_mode) vport = ntohs(natLookup.nl_realport); snprintf(http->uri, url_sz, "http://%s:%d%s", - inet_ntoa(natLookup.nl_realip), - vport, url); + inet_ntoa(natLookup.nl_realip), vport, url); } #elif PF_TRANSPARENT if (pffd < 0) @@ -1005,26 +1030,25 @@ pffd = -1; cbdataFree(context); xfree(inbuf); - return parseHttpRequestAbort(conn, "error:pf-lookup-failed"); + return parseHttpRequestAbort(conn, + "error:pf-lookup-failed"); } else snprintf(http->uri, url_sz, "http://%s:%d%s", - inet_ntoa(http->conn->me.sin_addr), - vport, url); + inet_ntoa(http->conn->me.sin_addr), vport, url); } else snprintf(http->uri, url_sz, "http://%s:%d%s", - inet_ntoa(nl.rdaddr.v4), - ntohs(nl.rdport), url); + inet_ntoa(nl.rdaddr.v4), ntohs(nl.rdport), url); #else #if LINUX_NETFILTER /* If the call fails the address structure will be unchanged */ getsockopt(conn->fd, SOL_IP, SO_ORIGINAL_DST, &conn->me, &sock_sz); - debug(33, 5) ("parseHttpRequest: addr = %s", inet_ntoa(conn->me.sin_addr)); + debug(33, 5) ("parseHttpRequest: addr = %s", + inet_ntoa(conn->me.sin_addr)); if (vport_mode) vport = (int) ntohs(http->conn->me.sin_port); #endif snprintf(http->uri, url_sz, "http://%s:%d%s", - inet_ntoa(http->conn->me.sin_addr), - vport, url); + inet_ntoa(http->conn->me.sin_addr), vport, url); #endif debug(33, 5) ("VHOST REWRITE: '%s'\n", http->uri); } else { @@ -1077,7 +1101,8 @@ commSetSelect(fd, COMM_SELECT_READ, clientReadRequest, conn, 0); if (len == 0) { /* Grow the request memory area to accomodate for a large request */ - conn->in.buf = memReallocBuf(conn->in.buf, conn->in.size * 2, &conn->in.size); + conn->in.buf = + memReallocBuf(conn->in.buf, conn->in.size * 2, &conn->in.size); debug(33, 2) ("growing request buffer: offset=%ld size=%ld\n", (long) conn->in.offset, (long) conn->in.size); len = conn->in.size - conn->in.offset - 1; @@ -1106,7 +1131,8 @@ return; } else if (!Config.onoff.half_closed_clients) { /* admin doesn't want to support half-closed client sockets */ - debug(33, 3) ("clientReadRequest: FD %d aborted (half_closed_clients disabled)\n", fd); + debug(33, 3) ("clientReadRequest: FD %d aborted (half_closed_clients disabled)\n", + fd); comm_close(fd); return; } @@ -1127,7 +1153,8 @@ comm_close(fd); return; } else if (conn->in.offset == 0) { - debug(50, 2) ("clientReadRequest: FD %d: no data to process (%s)\n", fd, xstrerror()); + debug(50, 2) ("clientReadRequest: FD %d: no data to process (%s)\n", + fd, xstrerror()); } /* Continue to process previously read data */ } @@ -1148,10 +1175,13 @@ if (conn->in.offset == 0) break; /* Limit the number of concurrent requests to 2 */ - for (S = (clientSocketContext **)&conn->currentobject, nrequests = 0; *S; S = &(*S)->next, nrequests++); + for (S = (clientSocketContext **) & conn->currentobject, nrequests = 0; + *S; S = &(*S)->next, nrequests++); if (nrequests >= (Config.onoff.pipeline_prefetch ? 2 : 1)) { - debug(33, 3) ("clientReadRequest: FD %d max concurrent requests reached\n", fd); - debug(33, 5) ("clientReadRequest: FD %d defering new request until one is done\n", fd); + debug(33, 3) ("clientReadRequest: FD %d max concurrent requests reached\n", + fd); + debug(33, 5) ("clientReadRequest: FD %d defering new request until one is done\n", + fd); conn->defer.until = squid_curtime + 100; /* Reset when a request is complete */ conn->defer.n++; return; @@ -1161,10 +1191,7 @@ fd_note(conn->fd, "Reading next request"); /* Process request */ context = parseHttpRequest(conn, - &method, - &parser_return_code, - &prefix, - &req_line_sz); + &method, &parser_return_code, &prefix, &req_line_sz); if (!context) safe_free(prefix); if (context) { @@ -1180,33 +1207,34 @@ * data to the beginning */ if (conn->in.offset > 0) - xmemmove(conn->in.buf, conn->in.buf + http->req_sz, conn->in.offset); + xmemmove(conn->in.buf, conn->in.buf + http->req_sz, + conn->in.offset); /* add to the client request queue */ - for (S = (clientSocketContext **)&conn->currentobject; *S; S = &(*S)->next); + for (S = (clientSocketContext **) & conn->currentobject; *S; + S = &(*S)->next); *S = context; conn->nrequests++; - commSetTimeout(fd, Config.Timeout.lifetime, clientLifetimeTimeout, http); + commSetTimeout(fd, Config.Timeout.lifetime, clientLifetimeTimeout, + http); if (parser_return_code < 0) { clientStreamNode *node = http->client_stream.tail->prev->data; debug(33, 1) ("clientReadRequest: FD %d Invalid Request\n", fd); - clientSetReplyToError (node->data, - ERR_INVALID_REQ, HTTP_BAD_REQUEST, method, NULL, &conn->peer.sin_addr, - NULL, conn->in.buf, NULL); - clientStreamRead (http->client_stream.tail->data, http, 0, - HTTP_REQBUF_SZ, - context->reqbuf); + clientSetReplyToError(node->data, + ERR_INVALID_REQ, HTTP_BAD_REQUEST, method, NULL, + &conn->peer.sin_addr, NULL, conn->in.buf, NULL); + clientStreamRead(http->client_stream.tail->data, http, 0, + HTTP_REQBUF_SZ, context->reqbuf); safe_free(prefix); break; } if ((request = urlParse(method, http->uri)) == NULL) { clientStreamNode *node = http->client_stream.tail->prev->data; debug(33, 5) ("Invalid URL: %s\n", http->uri); - clientSetReplyToError (node->data, - ERR_INVALID_URL, HTTP_BAD_REQUEST, method, http->uri, - &conn->peer.sin_addr, NULL, NULL, NULL); - clientStreamRead (http->client_stream.tail->data, http, 0, - HTTP_REQBUF_SZ, - context->reqbuf); + clientSetReplyToError(node->data, + ERR_INVALID_URL, HTTP_BAD_REQUEST, method, http->uri, + &conn->peer.sin_addr, NULL, NULL, NULL); + clientStreamRead(http->client_stream.tail->data, http, 0, + HTTP_REQBUF_SZ, context->reqbuf); safe_free(prefix); break; } else { @@ -1224,7 +1252,8 @@ request->port == getMyPort()) { http->flags.internal = 1; } else if (internalStaticCheck(strBuf(request->urlpath))) { - xstrncpy(request->host, internalHostname(), SQUIDHOSTNAMELEN); + xstrncpy(request->host, internalHostname(), + SQUIDHOSTNAMELEN); request->port = getMyPort(); http->flags.internal = 1; } @@ -1246,18 +1275,20 @@ if (!urlCheckRequest(request) || httpHeaderHas(&request->header, HDR_TRANSFER_ENCODING)) { clientStreamNode *node = http->client_stream.tail->prev->data; - clientSetReplyToError (node->data,ERR_UNSUP_REQ, HTTP_NOT_IMPLEMENTED, request->method, - NULL, &conn->peer.sin_addr, request, NULL, NULL); - clientStreamRead (http->client_stream.tail->data, http, 0, - HTTP_REQBUF_SZ, - context->reqbuf); + clientSetReplyToError(node->data, ERR_UNSUP_REQ, + HTTP_NOT_IMPLEMENTED, request->method, NULL, + &conn->peer.sin_addr, request, NULL, NULL); + clientStreamRead(http->client_stream.tail->data, http, 0, + HTTP_REQBUF_SZ, context->reqbuf); break; } if (!clientCheckContentLength(request)) { clientStreamNode *node = http->client_stream.tail->prev->data; - clientSetReplyToError (node->data,ERR_INVALID_REQ, HTTP_LENGTH_REQUIRED, request->method, - NULL, &conn->peer.sin_addr, request, NULL, NULL); - clientStreamRead (http->client_stream.tail->data, http, 0,HTTP_REQBUF_SZ,context->reqbuf); + clientSetReplyToError(node->data, ERR_INVALID_REQ, + HTTP_LENGTH_REQUIRED, request->method, NULL, + &conn->peer.sin_addr, request, NULL, NULL); + clientStreamRead(http->client_stream.tail->data, http, 0, + HTTP_REQBUF_SZ, context->reqbuf); break; } http->request = requestLink(request); @@ -1268,10 +1299,13 @@ request->body_connection = conn; /* Is it too large? */ if (clientRequestBodyTooLarge(request->content_length)) { - clientStreamNode *node = http->client_stream.tail->prev->data; - clientSetReplyToError (node->data,ERR_TOO_BIG, HTTP_REQUEST_ENTITY_TOO_LARGE,METHOD_NONE, NULL, - &conn->peer.sin_addr, http->request, NULL, NULL); - clientStreamRead (http->client_stream.tail->data, http, 0,HTTP_REQBUF_SZ,context->reqbuf); + clientStreamNode *node = + http->client_stream.tail->prev->data; + clientSetReplyToError(node->data, ERR_TOO_BIG, + HTTP_REQUEST_ENTITY_TOO_LARGE, METHOD_NONE, NULL, + &conn->peer.sin_addr, http->request, NULL, NULL); + clientStreamRead(http->client_stream.tail->data, http, 0, + HTTP_REQBUF_SZ, context->reqbuf); break; } } @@ -1285,18 +1319,22 @@ if (conn->in.offset >= Config.maxRequestHeaderSize) { /* The request is too large to handle */ clientStreamNode *node; - context = parseHttpRequestAbort(conn, "error:request-too-large"); + context = + parseHttpRequestAbort(conn, "error:request-too-large"); node = context->http->client_stream.tail->prev->data; debug(33, 1) ("Request header is too large (%d bytes)\n", (int) conn->in.offset); debug(33, 1) ("Config 'request_header_max_size'= %ld bytes.\n", (long int) Config.maxRequestHeaderSize); - clientSetReplyToError (node->data,ERR_TOO_BIG, HTTP_REQUEST_ENTITY_TOO_LARGE,METHOD_NONE, NULL, - &conn->peer.sin_addr, NULL, NULL, NULL); + clientSetReplyToError(node->data, ERR_TOO_BIG, + HTTP_REQUEST_ENTITY_TOO_LARGE, METHOD_NONE, NULL, + &conn->peer.sin_addr, NULL, NULL, NULL); /* add to the client request queue */ - for (S = (clientSocketContext **)&conn->currentobject; *S; S = &(*S)->next); + for (S = (clientSocketContext **) & conn->currentobject; *S; + S = &(*S)->next); *S = context; - clientStreamRead (context->http->client_stream.tail->data, context->http, 0,HTTP_REQBUF_SZ,context->reqbuf); + clientStreamRead(context->http->client_stream.tail->data, + context->http, 0, HTTP_REQBUF_SZ, context->reqbuf); return; } break; @@ -1306,7 +1344,8 @@ if (F->flags.socket_eof) { if (conn->in.offset != conn->body.size_left) { /* != 0 when no request body */ /* Partial request received. Abort client connection! */ - debug(33, 3) ("clientReadRequest: FD %d aborted, partial request\n", fd); + debug(33, 3) ("clientReadRequest: FD %d aborted, partial request\n", + fd); comm_close(fd); return; } @@ -1315,7 +1354,8 @@ /* file_read like function, for reading body content */ void -clientReadBody(request_t * request, char *buf, size_t size, CBCB * callback, void *cbdata) +clientReadBody(request_t * request, char *buf, size_t size, CBCB * callback, + void *cbdata) { ConnStateData *conn = request->body_connection; if (!conn) { @@ -1323,7 +1363,9 @@ callback(buf, 0, cbdata); /* Signal end of body */ return; } - 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); + 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; conn->body.buf = buf; @@ -1342,7 +1384,9 @@ CBCB *callback = conn->body.callback; request_t *request = conn->body.request; /* Note: request is null while eating "aborted" transfers */ - debug(33, 2) ("clientProcessBody: 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); + debug(33, 2) ("clientProcessBody: 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); if (conn->in.offset) { /* Some sanity checks... */ assert(conn->body.size_left > 0); @@ -1377,7 +1421,9 @@ callback(buf, size, cbdata); if (request != NULL) requestUnlink(request); /* Linked in clientReadBody */ - debug(33, 2) ("clientProcessBody: end fd=%d size=%d body_size=%lu in.offset=%ld cb=%p req=%p\n", conn->fd, size, (unsigned long int) conn->body.size_left, (long int) conn->in.offset, callback, request); + debug(33, 2) ("clientProcessBody: end fd=%d size=%d body_size=%lu in.offset=%ld cb=%p req=%p\n", + conn->fd, size, (unsigned long int) conn->body.size_left, + (long int) conn->in.offset, callback, request); } } @@ -1387,9 +1433,12 @@ clientReadBodyAbortHandler(char *buf, size_t size, void *data) { ConnStateData *conn = (ConnStateData *) data; - debug(33, 2) ("clientReadBodyAbortHandler: fd=%d body_size=%lu in.offset=%ld\n", conn->fd, (unsigned long int) conn->body.size_left, (long int) conn->in.offset); + debug(33, 2) ("clientReadBodyAbortHandler: fd=%d body_size=%lu in.offset=%ld\n", + conn->fd, (unsigned long int) conn->body.size_left, + (long int) conn->in.offset); if (size != 0 && conn->body.size_left != 0) { - debug(33, 3) ("clientReadBodyAbortHandler: fd=%d shedule next read\n", conn->fd); + debug(33, 3) ("clientReadBodyAbortHandler: fd=%d shedule next read\n", + conn->fd); conn->body.callback = clientReadBodyAbortHandler; conn->body.buf = bodyAbortBuf; conn->body.bufsize = sizeof(bodyAbortBuf); @@ -1420,7 +1469,7 @@ callback(buf, -1, cbdata); /* Signal abort to clientReadBody caller */ requestUnlink(request); } - clientReadBodyAbortHandler(NULL, -1, conn); /* Install abort handler */ + clientReadBodyAbortHandler(NULL, -1, conn); /* Install abort handler */ /* clientProcessBody() */ return 1; /* Aborted */ } @@ -1448,16 +1497,20 @@ */ clientHttpRequest **H; clientStreamNode *node; - clientHttpRequest *http = parseHttpRequestAbort(conn, "error:Connection%20lifetime%20expired"); + clientHttpRequest *http = + parseHttpRequestAbort(conn, + "error:Connection%20lifetime%20expired"); node = http->client_stream.tail->prev->data; - clientSetReplyToError (node->data,ERR_LIFETIME_EXP, HTTP_REQUEST_TIMEOUT,METHOD_NONE, "N/A", - &conn->peer.sin_addr, NULL, NULL, NULL); + clientSetReplyToError(node->data, ERR_LIFETIME_EXP, + HTTP_REQUEST_TIMEOUT, METHOD_NONE, "N/A", &conn->peer.sin_addr, + NULL, NULL, NULL); /* No requests can be outstanded */ assert(conn->chr == NULL); /* add to the client request queue */ for (H = &conn->chr; *H; H = &(*H)->next); *H = http; - clientStreamRead (http->client_stream.tail->data, http, 0,HTTP_REQBUF_SZ,context->reqbuf); + clientStreamRead(http->client_stream.tail->data, http, 0, + HTTP_REQBUF_SZ, context->reqbuf); /* * if we don't close() here, we still need a timeout handler! */ @@ -1486,7 +1539,8 @@ { clientHttpRequest *http = data; ConnStateData *conn = http->conn; - debug(33, 1) ("WARNING: Closing client %s connection due to lifetime timeout\n", + debug(33, + 1) ("WARNING: Closing client %s connection due to lifetime timeout\n", inet_ntoa(conn->peer.sin_addr)); debug(33, 1) ("\t%s\n", http->uri); comm_close(fd); @@ -1572,7 +1626,8 @@ } ret = ERR_get_error(); if (ret) { - debug(83, 1) ("clientNegotiateSSL: Error negotiating SSL connection on FD %d: %s\n", + debug(83, 1) + ("clientNegotiateSSL: Error negotiating SSL connection on FD %d: %s\n", fd, ERR_error_string(ret, NULL)); } comm_close(fd); @@ -1583,11 +1638,11 @@ client_cert = SSL_get_peer_certificate(fd_table[fd].ssl); if (client_cert != NULL) { - debug(83, 5) ("clientNegotiateSSL: FD %d client certificate: subject: %s\n", fd, - X509_NAME_oneline(X509_get_subject_name(client_cert), 0, 0)); + debug(83, 5) ("clientNegotiateSSL: FD %d client certificate: subject: %s\n", + fd, X509_NAME_oneline(X509_get_subject_name(client_cert), 0, 0)); - debug(83, 5) ("clientNegotiateSSL: FD %d client certificate: issuer: %s\n", fd, - X509_NAME_oneline(X509_get_issuer_name(client_cert), 0, 0)); + debug(83, 5) ("clientNegotiateSSL: FD %d client certificate: issuer: %s\n", + fd, X509_NAME_oneline(X509_get_issuer_name(client_cert), 0, 0)); X509_free(client_cert); } else { @@ -1597,7 +1652,8 @@ commSetSelect(fd, COMM_SELECT_READ, clientReadRequest, conn, 0); } -struct _https_port_data { +struct _https_port_data +{ SSL_CTX *sslContext; }; typedef struct _https_port_data https_port_data; @@ -1729,9 +1785,7 @@ fd = comm_open(SOCK_STREAM, 0, s->s.sin_addr, - ntohs(s->s.sin_port), - COMM_NONBLOCKING, - "HTTP Socket"); + ntohs(s->s.sin_port), COMM_NONBLOCKING, "HTTP Socket"); leave_suid(); if (fd < 0) continue; @@ -1743,9 +1797,7 @@ */ commSetDefer(fd, httpAcceptDefer, NULL); debug(1, 1) ("Accepting HTTP connections at %s, port %d, FD %d.\n", - inet_ntoa(s->s.sin_addr), - (int) ntohs(s->s.sin_port), - fd); + inet_ntoa(s->s.sin_addr), (int) ntohs(s->s.sin_port), fd); HttpSockets[NHttpSockets++] = fd; } } @@ -1767,22 +1819,20 @@ fd = comm_open(SOCK_STREAM, 0, s->s.sin_addr, - ntohs(s->s.sin_port), - COMM_NONBLOCKING, - "HTTPS Socket"); + ntohs(s->s.sin_port), COMM_NONBLOCKING, "HTTPS Socket"); leave_suid(); if (fd < 0) continue; CBDATA_INIT_TYPE(https_port_data); https_port = cbdataAlloc(https_port_data); - https_port->sslContext = sslCreateContext(s->cert, s->key, s->version, s->cipher, s->options); + https_port->sslContext = + sslCreateContext(s->cert, s->key, s->version, s->cipher, + s->options); comm_listen(fd); commSetSelect(fd, COMM_SELECT_READ, httpsAccept, https_port, 0); commSetDefer(fd, httpAcceptDefer, NULL); debug(1, 1) ("Accepting HTTPS connections at %s, port %d, FD %d.\n", - inet_ntoa(s->s.sin_addr), - (int) ntohs(s->s.sin_port), - fd); + inet_ntoa(s->s.sin_addr), (int) ntohs(s->s.sin_port), fd); HttpSockets[NHttpSockets++] = fd; } } @@ -1799,6 +1849,7 @@ if (NHttpSockets < 1) fatal("Cannot open HTTP Port"); } + void clientHttpConnectionsClose(void) { @@ -1819,12 +1870,15 @@ const char *vary = request->vary_headers; int has_vary = httpHeaderHas(&entry->mem_obj->reply->header, HDR_VARY); #if X_ACCELERATOR_VARY - has_vary |= httpHeaderHas(&entry->mem_obj->reply->header, HDR_X_ACCELERATOR_VARY); + has_vary |= + httpHeaderHas(&entry->mem_obj->reply->header, HDR_X_ACCELERATOR_VARY); #endif if (!has_vary || !entry->mem_obj->vary_headers) { if (vary) { /* Oops... something odd is going on here.. */ - debug(33, 1) ("varyEvaluateMatch: Oops. Not a Vary object on second attempt, '%s' '%s'\n", + debug(33, + 1) + ("varyEvaluateMatch: Oops. Not a Vary object on second attempt, '%s' '%s'\n", entry->mem_obj->url, vary); safe_free(request->vary_headers); return VARY_CANCEL; Index: squid/src/client_side_reply.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/client_side_reply.c,v retrieving revision 1.1.2.22 retrieving revision 1.1.2.23 diff -u -r1.1.2.22 -r1.1.2.23 --- squid/src/client_side_reply.c 9 Sep 2002 12:47:05 -0000 1.1.2.22 +++ squid/src/client_side_reply.c 9 Sep 2002 22:22:28 -0000 1.1.2.23 @@ -1,6 +1,6 @@ /* - * $Id: client_side_reply.c,v 1.1.2.22 2002/09/09 12:47:05 rbcollins Exp $ + * $Id: client_side_reply.c,v 1.1.2.23 2002/09/09 22:22:28 rbcollins Exp $ * * DEBUG: section 88 Client-side Reply Routines * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c) @@ -35,26 +35,30 @@ #include "squid.h" -typedef struct _clientReplyContext { +typedef struct _clientReplyContext +{ clientHttpRequest *http; int headers_sz; - store_client *sc; /* The store_client we're using */ - store_client *old_sc; /* ... for entry to be validated */ - int old_reqofs; /* ... for the buffer */ - int old_reqsize; /* ... again, for the buffer */ + store_client *sc; /* The store_client we're using */ + store_client *old_sc; /* ... for entry to be validated */ + int old_reqofs; /* ... for the buffer */ + int old_reqsize; /* ... again, for the buffer */ size_t reqsize; off_t reqofs; - char tempbuf[HTTP_REQBUF_SZ]; /* a temporary buffer if we need working storage */ + char tempbuf[HTTP_REQBUF_SZ]; /* a temporary buffer if we need working storage */ #if USE_CACHE_DIGESTS - const char *lookup_type; /* temporary hack: storeGet() result: HIT/MISS/NONE */ + const char *lookup_type; /* temporary hack: storeGet() result: HIT/MISS/NONE */ #endif - struct { + struct + { int storelogiccomplete:1; - int complete:1; /* we have read all we can from upstream */ - } flags; - clientStreamNode *ourNode; /* This will go away if/when this file gets refactored some more */ -} clientReplyContext; -CBDATA_TYPE (clientReplyContext); + int complete:1; /* we have read all we can from upstream */ + } + flags; + clientStreamNode *ourNode; /* This will go away if/when this file gets refactored some more */ +} +clientReplyContext; +CBDATA_TYPE(clientReplyContext); static const char *const crlf = "\r\n"; @@ -66,74 +70,83 @@ static void clientProcessMiss(clientReplyContext *); static STCB clientCacheHit; static void clientProcessOnlyIfCachedMiss(clientReplyContext *); -static int clientGetsOldEntry(StoreEntry * new, StoreEntry * old, request_t * request); +static int clientGetsOldEntry(StoreEntry * new, StoreEntry * old, + request_t * request); static STCB clientHandleIMSReply; static int modifiedSince(StoreEntry *, request_t *); static log_type clientIdentifyStoreObject(clientHttpRequest * http); static void clientPurgeRequest(clientReplyContext *); -static void clientTraceReply(clientStreamNode *,clientReplyContext *); -static StoreEntry *clientCreateStoreEntry(clientReplyContext *, method_t, request_flags); +static void clientTraceReply(clientStreamNode *, clientReplyContext *); +static StoreEntry *clientCreateStoreEntry(clientReplyContext *, method_t, + request_flags); static STCB clientSendMoreData; -static void clientRemoveStoreReference (clientReplyContext *, store_client **, StoreEntry **); -static void clientReplyContextSaveState (clientReplyContext *, clientHttpRequest *); -static void clientReplyContextRestoreState (clientReplyContext *, clientHttpRequest *); +static void clientRemoveStoreReference(clientReplyContext *, store_client **, + StoreEntry **); +static void clientReplyContextSaveState(clientReplyContext *, + clientHttpRequest *); +static void clientReplyContextRestoreState(clientReplyContext *, + clientHttpRequest *); extern CSS clientReplyStatus; -extern ErrorState *clientBuildError (err_type, http_status, char const *, struct in_addr *, request_t *); +extern ErrorState *clientBuildError(err_type, http_status, char const *, + struct in_addr *, request_t *); /* The clientReply clean interface */ /* privates */ static FREE clientReplyFree; void -clientReplyFree (void *data) +clientReplyFree(void *data) { clientReplyContext *this = data; - clientRemoveStoreReference (this, &this->sc, &this->http->entry); + clientRemoveStoreReference(this, &this->sc, &this->http->entry); /* old_entry might still be set if we didn't yet get the reply * code in clientHandleIMSReply() */ - clientRemoveStoreReference (this, &this->old_sc, &this->http->old_entry); - cbdataReferenceDone (this->http); + clientRemoveStoreReference(this, &this->old_sc, &this->http->old_entry); + cbdataReferenceDone(this->http); } void * -clientReplyNewContext (clientHttpRequest *clientContext) +clientReplyNewContext(clientHttpRequest * clientContext) { clientReplyContext *context; - CBDATA_INIT_TYPE_FREECB (clientReplyContext, clientReplyFree); - context = cbdataAlloc (clientReplyContext); - context->http = cbdataReference (clientContext); + CBDATA_INIT_TYPE_FREECB(clientReplyContext, clientReplyFree); + context = cbdataAlloc(clientReplyContext); + context->http = cbdataReference(clientContext); return context; } /* create an error in the store awaiting the client side to read it. */ void -clientSetReplyToError (void *data, - err_type err, http_status status, method_t method, char const *uri, - struct in_addr *addr, request_t *failedrequest, char *unparsedrequest, - auth_user_request_t *auth_user_request) +clientSetReplyToError(void *data, + err_type err, http_status status, method_t method, char const *uri, + struct in_addr *addr, request_t * failedrequest, char *unparsedrequest, + auth_user_request_t * auth_user_request) { clientReplyContext *context = data; - ErrorState *errstate = clientBuildError(err, status, uri, addr, failedrequest); + ErrorState *errstate = + clientBuildError(err, status, uri, addr, failedrequest); if (unparsedrequest) - errstate->request_hdrs = xstrdup (unparsedrequest); + errstate->request_hdrs = xstrdup(unparsedrequest); if (status == HTTP_NOT_IMPLEMENTED && context->http->request) /* prevent confusion over whether we default to persistent or not */ context->http->request->flags.proxy_keepalive = 0; context->http->al.http.code = errstate->http_status; - context->http->entry = clientCreateStoreEntry(context, method, null_request_flags); + context->http->entry = + clientCreateStoreEntry(context, method, null_request_flags); if (auth_user_request) { errstate->auth_user_request = auth_user_request; - authenticateAuthUserRequestLock (errstate->auth_user_request); + authenticateAuthUserRequestLock(errstate->auth_user_request); } - assert (errstate->callback_data == NULL); - errorAppendEntry (context->http->entry, errstate); + assert(errstate->callback_data == NULL); + errorAppendEntry(context->http->entry, errstate); /* Now the caller reads to get this */ } void -clientRemoveStoreReference (clientReplyContext *context, store_client **scp, StoreEntry **ep) +clientRemoveStoreReference(clientReplyContext * context, store_client ** scp, + StoreEntry ** ep) { StoreEntry *e; store_client *sc = *scp; @@ -146,26 +159,27 @@ } void -clientReplyContextSaveState (clientReplyContext *this, clientHttpRequest *http) +clientReplyContextSaveState(clientReplyContext * this, clientHttpRequest * http) { - assert (this->old_sc == NULL); - debug (88,1)("clientReplyContextSaveState: saving store context\n"); - http->old_entry = http->entry; - this->old_sc = this->sc; - this->old_reqsize = this->reqsize; - this->old_reqofs = this->reqofs; - /* Prevent accessing the now saved entries */ - http->entry = NULL; - this->sc = NULL; - this->reqsize = 0; - this->reqofs = 0; + assert(this->old_sc == NULL); + debug(88, 1) ("clientReplyContextSaveState: saving store context\n"); + http->old_entry = http->entry; + this->old_sc = this->sc; + this->old_reqsize = this->reqsize; + this->old_reqofs = this->reqofs; + /* Prevent accessing the now saved entries */ + http->entry = NULL; + this->sc = NULL; + this->reqsize = 0; + this->reqofs = 0; } void -clientReplyContextRestoreState (clientReplyContext *this, clientHttpRequest *http) +clientReplyContextRestoreState(clientReplyContext * this, + clientHttpRequest * http) { - assert (this->old_sc != NULL); - debug (88,1)("clientReplyContextRestoreState: Restoring store context\n"); + assert(this->old_sc != NULL); + debug(88, 1) ("clientReplyContextRestoreState: Restoring store context\n"); http->entry = http->old_entry; this->sc = this->old_sc; this->reqsize = this->old_reqsize; @@ -182,7 +196,7 @@ * setup a temporary buffer area and perform an IMS to the origin */ static void -clientProcessExpired(clientReplyContext *context) +clientProcessExpired(clientReplyContext * context) { clientHttpRequest *http = context->http; char *url = http->uri; @@ -195,8 +209,8 @@ * a stale entry *if* it matches client requirements */ if (clientOnlyIfCached(http)) { - clientProcessOnlyIfCachedMiss(context); - return; + clientProcessOnlyIfCachedMiss(context); + return; } http->request->flags.refresh = 1; #if STORE_CLIENT_LIST_DEBUG @@ -208,11 +222,9 @@ assert(http->sc->owner == context); #endif /* Prepare to make a new temporary request */ - clientReplyContextSaveState (context, http); + clientReplyContextSaveState(context, http); entry = storeCreateEntry(url, - http->log_uri, - http->request->flags, - http->request->method); + http->log_uri, http->request->flags, http->request->method); /* NOTE, don't call storeLockObject(), storeCreateEntry() does it */ context->sc = storeClientListAdd(entry, context); #if DELAY_POOLS @@ -220,20 +232,17 @@ delaySetStoreClient(context->sc, delayClient(http)); #endif http->request->lastmod = http->old_entry->lastmod; - debug(88, 5) ("clientProcessExpired: lastmod %ld\n", (long int) entry->lastmod); + debug(88, 5) ("clientProcessExpired: lastmod %ld\n", + (long int) entry->lastmod); http->entry = entry; - http->out.offset = 0; /* FIXME Not needed - we have not written anything anyway */ + http->out.offset = 0; /* FIXME Not needed - we have not written anything anyway */ fwdStart(http->conn ? http->conn->fd : -1, http->entry, http->request); /* Register with storage manager to receive updates when data comes in. */ if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) - debug(88, 0) ("clientProcessExpired: found ENTRY_ABORTED object\n"); + debug(88, 0) ("clientProcessExpired: found ENTRY_ABORTED object\n"); /* start counting the length from 0 */ storeClientCopy(context->sc, entry, - 0, - HTTP_REQBUF_SZ, - context->tempbuf, - clientHandleIMSReply, - context); + 0, HTTP_REQBUF_SZ, context->tempbuf, clientHandleIMSReply, context); } int @@ -244,63 +253,65 @@ time_t mod_time = entry->lastmod; debug(88, 3) ("modifiedSince: '%s'\n", storeUrl(entry)); if (mod_time < 0) - mod_time = entry->timestamp; + mod_time = entry->timestamp; debug(88, 3) ("modifiedSince: mod_time = %ld\n", (long int) mod_time); if (mod_time < 0) - return 1; + return 1; /* Find size of the object */ object_length = mem->reply->content_length; if (object_length < 0) - object_length = contentLen(entry); + object_length = contentLen(entry); if (mod_time > request->ims) { - debug(88, 3) ("--> YES: entry newer than client\n"); - return 1; + debug(88, 3) ("--> YES: entry newer than client\n"); + return 1; } else if (mod_time < request->ims) { - debug(88, 3) ("--> NO: entry older than client\n"); - return 0; + debug(88, 3) ("--> NO: entry older than client\n"); + return 0; } else if (request->imslen < 0) { - debug(88, 3) ("--> NO: same LMT, no client length\n"); - return 0; + debug(88, 3) ("--> NO: same LMT, no client length\n"); + return 0; } else if (request->imslen == object_length) { - debug(88, 3) ("--> NO: same LMT, same length\n"); - return 0; + debug(88, 3) ("--> NO: same LMT, same length\n"); + return 0; } else { - debug(88, 3) ("--> YES: same LMT, different length\n"); - return 1; + debug(88, 3) ("--> YES: same LMT, different length\n"); + return 1; } } static int -clientGetsOldEntry(StoreEntry * new_entry, StoreEntry * old_entry, request_t * request){ +clientGetsOldEntry(StoreEntry * new_entry, StoreEntry * old_entry, + request_t * request) +{ const http_status status = new_entry->mem_obj->reply->sline.status; if (0 == status) { - debug(88, 5) ("clientGetsOldEntry: YES, broken HTTP reply\n"); - return 1; + debug(88, 5) ("clientGetsOldEntry: YES, broken HTTP reply\n"); + return 1; } /* If the reply is a failure then send the old object as a last * resort */ if (status >= 500 && status < 600) { - debug(88, 3) ("clientGetsOldEntry: YES, failure reply=%d\n", status); - return 1; + debug(88, 3) ("clientGetsOldEntry: YES, failure reply=%d\n", status); + return 1; } /* If the reply is anything but "Not Modified" then * we must forward it to the client */ if (HTTP_NOT_MODIFIED != status) { - debug(88, 5) ("clientGetsOldEntry: NO, reply=%d\n", status); - return 0; + debug(88, 5) ("clientGetsOldEntry: NO, reply=%d\n", status); + return 0; } /* If the client did not send IMS in the request, then it * must get the old object, not this "Not Modified" reply */ if (!request->flags.ims) { - debug(88, 5) ("clientGetsOldEntry: YES, no client IMS\n"); - return 1; + debug(88, 5) ("clientGetsOldEntry: YES, no client IMS\n"); + return 1; } /* If the client IMS time is prior to the entry LASTMOD time we * need to send the old object */ if (modifiedSince(old_entry, request)) { - debug(88, 5) ("clientGetsOldEntry: YES, modified since %ld\n", - (long int) request->ims); - return 1; + debug(88, 5) ("clientGetsOldEntry: YES, modified since %ld\n", + (long int) request->ims); + return 1; } debug(88, 5) ("clientGetsOldEntry: NO, new one is fine\n"); return 0; @@ -317,12 +328,13 @@ int unlink_request = 0; StoreEntry *oldentry; http_status status; - debug(88, 3) ("clientHandleIMSReply: %s, %ld bytes\n", url, (long int) size); + debug(88, 3) ("clientHandleIMSReply: %s, %ld bytes\n", url, + (long int) size); if (entry == NULL) { - return; + return; } if (size < 0 && !EBIT_TEST(entry->flags, ENTRY_ABORTED)) { - return; + return; } /* update size of the request */ context->reqsize = size + context->reqofs; @@ -330,76 +342,79 @@ mem = entry->mem_obj; status = mem->reply->sline.status; if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) { - debug(88, 3) ("clientHandleIMSReply: ABORTED '%s'\n", url); - /* We have an existing entry, but failed to validate it */ - /* Its okay to send the old one anyway */ - http->log_type = LOG_TCP_REFRESH_FAIL_HIT; - clientRemoveStoreReference (context, &context->sc, &entry); + debug(88, 3) ("clientHandleIMSReply: ABORTED '%s'\n", url); + /* We have an existing entry, but failed to validate it */ + /* Its okay to send the old one anyway */ + http->log_type = LOG_TCP_REFRESH_FAIL_HIT; + clientRemoveStoreReference(context, &context->sc, &entry); /* Get the old request back */ - clientReplyContextRestoreState (context, http); + clientReplyContextRestoreState(context, http); entry = http->entry; } else if (STORE_PENDING == entry->store_status && 0 == status) { /* more headers needed to decide */ - debug(88, 3) ("clientHandleIMSReply: Incomplete headers for '%s'\n", url); - if (size + context->reqofs >= HTTP_REQBUF_SZ) { - /* will not get any bigger than that */ - debug(88, 3) ("clientHandleIMSReply: Reply is too large '%s', using old entry\n", url); - /* use old entry, this repeats the code abovez */ - http->log_type = LOG_TCP_REFRESH_FAIL_HIT; - clientRemoveStoreReference (context, &context->sc, &entry); - entry = http->entry = http->old_entry; + debug(88, 3) ("clientHandleIMSReply: Incomplete headers for '%s'\n", + url); + if (size + context->reqofs >= HTTP_REQBUF_SZ) { + /* will not get any bigger than that */ + debug(88, + 3) + ("clientHandleIMSReply: Reply is too large '%s', using old entry\n", + url); + /* use old entry, this repeats the code abovez */ + http->log_type = LOG_TCP_REFRESH_FAIL_HIT; + clientRemoveStoreReference(context, &context->sc, &entry); + entry = http->entry = http->old_entry; /* Get the old request back */ - clientReplyContextRestoreState (context, http); + clientReplyContextRestoreState(context, http); entry = http->entry; - /* continue */ - } else { - storeClientCopy(context->sc, entry, - context->reqofs, - HTTP_REQBUF_SZ - context->reqofs, - context->tempbuf + context->reqofs, - clientHandleIMSReply, - context); - return; - } + /* continue */ + } else { + storeClientCopy(context->sc, entry, + context->reqofs, + HTTP_REQBUF_SZ - context->reqofs, + context->tempbuf + context->reqofs, + clientHandleIMSReply, context); + return; + } } else if (clientGetsOldEntry(entry, http->old_entry, http->request)) { - /* We initiated the IMS request, the client is not expecting - * 304, so put the good one back. First, make sure the old entry - * headers have been loaded from disk. */ + /* We initiated the IMS request, the client is not expecting + * 304, so put the good one back. First, make sure the old entry + * headers have been loaded from disk. */ clientStreamNode *next = context->http->client_stream.head->next->data; - oldentry = http->old_entry; - http->log_type = LOG_TCP_REFRESH_HIT; - if (oldentry->mem_obj->request == NULL) { - oldentry->mem_obj->request = requestLink(mem->request); - unlink_request = 1; - } - /* Don't memcpy() the whole reply structure here. For example, - * www.thegist.com (Netscape/1.13) returns a content-length for - * 304's which seems to be the length of the 304 HEADERS!!! and - * not the body they refer to. */ - httpReplyUpdateOnNotModified(oldentry->mem_obj->reply, mem->reply); - storeTimestampsSet(oldentry); - clientRemoveStoreReference (context, &context->sc, &entry); - oldentry->timestamp = squid_curtime; - if (unlink_request) { - requestUnlink(oldentry->mem_obj->request); - oldentry->mem_obj->request = NULL; - } + oldentry = http->old_entry; + http->log_type = LOG_TCP_REFRESH_HIT; + if (oldentry->mem_obj->request == NULL) { + oldentry->mem_obj->request = requestLink(mem->request); + unlink_request = 1; + } + /* Don't memcpy() the whole reply structure here. For example, + * www.thegist.com (Netscape/1.13) returns a content-length for + * 304's which seems to be the length of the 304 HEADERS!!! and + * not the body they refer to. */ + httpReplyUpdateOnNotModified(oldentry->mem_obj->reply, mem->reply); + storeTimestampsSet(oldentry); + clientRemoveStoreReference(context, &context->sc, &entry); + oldentry->timestamp = squid_curtime; + if (unlink_request) { + requestUnlink(oldentry->mem_obj->request); + oldentry->mem_obj->request = NULL; + } /* Get the old request back */ - clientReplyContextRestoreState (context, http); + clientReplyContextRestoreState(context, http); entry = http->entry; /* here the data to send is in the next nodes buffers already */ assert(!EBIT_TEST(entry->flags, ENTRY_ABORTED)); clientSendMoreData(context, next->readbuf, context->reqsize); } else { - /* the client can handle this reply, whatever it is */ - http->log_type = LOG_TCP_REFRESH_MISS; - if (HTTP_NOT_MODIFIED == mem->reply->sline.status) { - httpReplyUpdateOnNotModified(http->old_entry->mem_obj->reply, - mem->reply); - storeTimestampsSet(http->old_entry); - http->log_type = LOG_TCP_REFRESH_HIT; - } - clientRemoveStoreReference (context, &context->old_sc, &http->old_entry); + /* the client can handle this reply, whatever it is */ + http->log_type = LOG_TCP_REFRESH_MISS; + if (HTTP_NOT_MODIFIED == mem->reply->sline.status) { + httpReplyUpdateOnNotModified(http->old_entry->mem_obj->reply, + mem->reply); + storeTimestampsSet(http->old_entry); + http->log_type = LOG_TCP_REFRESH_HIT; + } + clientRemoveStoreReference(context, &context->old_sc, &http->old_entry); /* here the data to send is the data we just recieved */ context->old_reqofs = 0; context->old_reqsize = 0; @@ -429,15 +444,15 @@ request_t *r = http->request; debug(88, 3) ("clientCacheHit: %s, %d bytes\n", http->uri, (int) size); if (http->entry == NULL) { - debug(88, 3) ("clientCacheHit: request aborted\n"); - return; + debug(88, 3) ("clientCacheHit: request aborted\n"); + return; } else if (size < 0) { - /* swap in failure */ - debug(88, 3) ("clientCacheHit: swapin failure for %s\n", http->uri); - http->log_type = LOG_TCP_SWAPFAIL_MISS; - clientRemoveStoreReference (context, &context->sc, &http->entry); - clientProcessMiss(context); - return; + /* swap in failure */ + debug(88, 3) ("clientCacheHit: swapin failure for %s\n", http->uri); + http->log_type = LOG_TCP_SWAPFAIL_MISS; + clientRemoveStoreReference(context, &context->sc, &http->entry); + clientProcessMiss(context); + return; } assert(size > 0); mem = e->mem_obj; @@ -445,29 +460,28 @@ /* update size of the request */ context->reqsize = size + context->reqofs; if (mem->reply->sline.status == 0) { - /* - * we don't have full reply headers yet; either wait for more or - * punt to clientProcessMiss. - */ - if (e->mem_status == IN_MEMORY || e->store_status == STORE_OK) { - clientProcessMiss(context); - } else if (size + context->reqofs >= HTTP_REQBUF_SZ && http->out.offset == 0) { - clientProcessMiss(context); - } else { + /* + * we don't have full reply headers yet; either wait for more or + * punt to clientProcessMiss. + */ + if (e->mem_status == IN_MEMORY || e->store_status == STORE_OK) { + clientProcessMiss(context); + } else if (size + context->reqofs >= HTTP_REQBUF_SZ + && http->out.offset == 0) { + clientProcessMiss(context); + } else { clientStreamNode *next; - debug(88, 3) ("clientCacheHit: waiting for HTTP reply headers\n"); - context->reqofs += size; - assert(context->reqofs <= HTTP_REQBUF_SZ); + debug(88, 3) ("clientCacheHit: waiting for HTTP reply headers\n"); + context->reqofs += size; + assert(context->reqofs <= HTTP_REQBUF_SZ); /* get the next users' buffer */ next = context->http->client_stream.head->next->data; - storeClientCopy(context->sc, e, - http->out.offset + context->reqofs, - HTTP_REQBUF_SZ, - next->readbuf + context->reqofs, - clientCacheHit, - context); - } - return; + storeClientCopy(context->sc, e, + http->out.offset + context->reqofs, + HTTP_REQBUF_SZ, + next->readbuf + context->reqofs, clientCacheHit, context); + } + return; } /* * Got the headers, now grok them @@ -475,119 +489,120 @@ assert(http->log_type == LOG_TCP_HIT); switch (varyEvaluateMatch(e, r)) { case VARY_NONE: - /* No variance detected. Continue as normal */ - break; + /* No variance detected. Continue as normal */ + break; case VARY_MATCH: - /* This is the correct entity for this request. Continue */ - debug(88, 2) ("clientProcessHit: Vary MATCH!\n"); - break; + /* This is the correct entity for this request. Continue */ + debug(88, 2) ("clientProcessHit: Vary MATCH!\n"); + break; case VARY_OTHER: - /* This is not the correct entity for this request. We need - * to requery the cache. - */ - clientRemoveStoreReference (context, &context->sc, &http->entry); + /* This is not the correct entity for this request. We need + * to requery the cache. + */ + clientRemoveStoreReference(context, &context->sc, &http->entry); e = NULL; - /* Note: varyEvalyateMatch updates the request with vary information - * so we only get here once. (it also takes care of cancelling loops) - */ - debug(88, 2) ("clientProcessHit: Vary detected!\n"); - clientGetMoreData (context->ourNode, http); -// clientProcessRequest(http); - return; + /* Note: varyEvalyateMatch updates the request with vary information + * so we only get here once. (it also takes care of cancelling loops) + */ + debug(88, 2) ("clientProcessHit: Vary detected!\n"); + clientGetMoreData(context->ourNode, http); + return; case VARY_CANCEL: - /* varyEvaluateMatch found a object loop. Process as miss */ - debug(88, 1) ("clientProcessHit: Vary object loop!\n"); - clientProcessMiss(context); - return; + /* varyEvaluateMatch found a object loop. Process as miss */ + debug(88, 1) ("clientProcessHit: Vary object loop!\n"); + clientProcessMiss(context); + return; } if (r->method == METHOD_PURGE) { - clientRemoveStoreReference (context, &context->sc, &http->entry); + clientRemoveStoreReference(context, &context->sc, &http->entry); e = NULL; - clientPurgeRequest(context); - return; + clientPurgeRequest(context); + return; } if (storeCheckNegativeHit(e)) { - http->log_type = LOG_TCP_NEGATIVE_HIT; - clientSendMoreData(context, buf, size); + http->log_type = LOG_TCP_NEGATIVE_HIT; + clientSendMoreData(context, buf, size); } else if (r->method == METHOD_HEAD) { - /* - * RFC 2068 seems to indicate there is no "conditional HEAD" - * request. We cannot validate a cached object for a HEAD - * request, nor can we return 304. - */ - if (e->mem_status == IN_MEMORY) - http->log_type = LOG_TCP_MEM_HIT; - clientSendMoreData(context, buf, size); + /* + * RFC 2068 seems to indicate there is no "conditional HEAD" + * request. We cannot validate a cached object for a HEAD + * request, nor can we return 304. + */ + if (e->mem_status == IN_MEMORY) + http->log_type = LOG_TCP_MEM_HIT; + clientSendMoreData(context, buf, size); } else if (refreshCheckHTTP(e, r) && !http->flags.internal) { - debug(88, 5) ("clientCacheHit: in refreshCheck() block\n"); - /* - * We hold a stale copy; it needs to be validated - */ - /* - * The 'need_validation' flag is used to prevent forwarding - * loops between siblings. If our copy of the object is stale, - * then we should probably only use parents for the validation - * request. Otherwise two siblings could generate a loop if - * both have a stale version of the object. - */ - r->flags.need_validation = 1; - if (e->lastmod < 0) { - /* - * Previous reply didn't have a Last-Modified header, - * we cannot revalidate it. - */ - http->log_type = LOG_TCP_MISS; - clientProcessMiss(context); - } else if (r->flags.nocache) { - /* - * This did not match a refresh pattern that overrides no-cache - * we should honour the client no-cache header. - */ - http->log_type = LOG_TCP_CLIENT_REFRESH_MISS; - clientProcessMiss(context); - } else if (r->protocol == PROTO_HTTP) { - /* - * Object needs to be revalidated - * XXX This could apply to FTP as well, if Last-Modified is known. - */ - http->log_type = LOG_TCP_REFRESH_MISS; - clientProcessExpired(context); - } else { - /* - * We don't know how to re-validate other protocols. Handle - * them as if the object has expired. - */ - http->log_type = LOG_TCP_MISS; - clientProcessMiss(context); - } + debug(88, 5) ("clientCacheHit: in refreshCheck() block\n"); + /* + * We hold a stale copy; it needs to be validated + */ + /* + * The 'need_validation' flag is used to prevent forwarding + * loops between siblings. If our copy of the object is stale, + * then we should probably only use parents for the validation + * request. Otherwise two siblings could generate a loop if + * both have a stale version of the object. + */ + r->flags.need_validation = 1; + if (e->lastmod < 0) { + /* + * Previous reply didn't have a Last-Modified header, + * we cannot revalidate it. + */ + http->log_type = LOG_TCP_MISS; + clientProcessMiss(context); + } else if (r->flags.nocache) { + /* + * This did not match a refresh pattern that overrides no-cache + * we should honour the client no-cache header. + */ + http->log_type = LOG_TCP_CLIENT_REFRESH_MISS; + clientProcessMiss(context); + } else if (r->protocol == PROTO_HTTP) { + /* + * Object needs to be revalidated + * XXX This could apply to FTP as well, if Last-Modified is known. + */ + http->log_type = LOG_TCP_REFRESH_MISS; + clientProcessExpired(context); + } else { + /* + * We don't know how to re-validate other protocols. Handle + * them as if the object has expired. + */ + http->log_type = LOG_TCP_MISS; + clientProcessMiss(context); + } } else if (r->flags.ims) { - /* - * Handle If-Modified-Since requests from the client - */ - if (mem->reply->sline.status != HTTP_OK) { - debug(88, 4) ("clientCacheHit: Reply code %d != 200\n", - mem->reply->sline.status); - http->log_type = LOG_TCP_MISS; - clientProcessMiss(context); - } else if (modifiedSince(e, http->request)) { - http->log_type = LOG_TCP_IMS_HIT; - clientSendMoreData(context, buf, size); - } else { + /* + * Handle If-Modified-Since requests from the client + */ + if (mem->reply->sline.status != HTTP_OK) { + debug(88, 4) ("clientCacheHit: Reply code %d != 200\n", + mem->reply->sline.status); + http->log_type = LOG_TCP_MISS; + clientProcessMiss(context); + } else if (modifiedSince(e, http->request)) { + http->log_type = LOG_TCP_IMS_HIT; + clientSendMoreData(context, buf, size); + } else { clientStreamNode *next; - time_t timestamp = e->timestamp; - MemBuf mb = httpPacked304Reply(e->mem_obj->reply); - http->log_type = LOG_TCP_IMS_HIT; - clientRemoveStoreReference (context, &context->sc, &http->entry); - http->entry = e = clientCreateStoreEntry(context, http->request->method, null_request_flags); - /* - * Copy timestamp from the original entry so the 304 - * reply has a meaningful Age: header. - */ - e->timestamp = timestamp; - httpReplyParse(e->mem_obj->reply, mb.buf, mb.size); - storeAppend(e, mb.buf, mb.size); - memBufClean(&mb); - storeComplete(e); + time_t timestamp = e->timestamp; + MemBuf mb = httpPacked304Reply(e->mem_obj->reply); + http->log_type = LOG_TCP_IMS_HIT; + clientRemoveStoreReference(context, &context->sc, &http->entry); + http->entry = e = + clientCreateStoreEntry(context, http->request->method, + null_request_flags); + /* + * Copy timestamp from the original entry so the 304 + * reply has a meaningful Age: header. + */ + e->timestamp = timestamp; + httpReplyParse(e->mem_obj->reply, mb.buf, mb.size); + storeAppend(e, mb.buf, mb.size); + memBufClean(&mb); + storeComplete(e); /* TODO: why put this in the store and then serialise it and then parse it again. * Simply mark the request complete in our context and * write the reply struct to the client side @@ -595,19 +610,19 @@ /* now write this back to the requester */ /* get the next chain members buffer */ - next = http->client_stream.head->next->data; - storeClientCopy(context->sc, e, next->readoff, next->readlen, next->readbuf, - clientSendMoreData, context); - } + next = http->client_stream.head->next->data; + storeClientCopy(context->sc, e, next->readoff, next->readlen, + next->readbuf, clientSendMoreData, context); + } } else { - /* - * plain ol' cache hit - */ - if (e->mem_status == IN_MEMORY) - http->log_type = LOG_TCP_MEM_HIT; - else if (Config.onoff.offline) - http->log_type = LOG_TCP_OFFLINE_HIT; - clientSendMoreData(context, buf, size); + /* + * plain ol' cache hit + */ + if (e->mem_status == IN_MEMORY) + http->log_type = LOG_TCP_MEM_HIT; + else if (Config.onoff.offline) + http->log_type = LOG_TCP_OFFLINE_HIT; + clientSendMoreData(context, buf, size); } } @@ -615,64 +630,68 @@ * Prepare to fetch the object as it's a cache miss of some kind. */ void -clientProcessMiss(clientReplyContext *context) +clientProcessMiss(clientReplyContext * context) { - clientHttpRequest * http=context->http; + clientHttpRequest *http = context->http; char *url = http->uri; request_t *r = http->request; ErrorState *err = NULL; debug(88, 4) ("clientProcessMiss: '%s %s'\n", - RequestMethodStr[r->method], url); + RequestMethodStr[r->method], url); /* * We might have a left-over StoreEntry from a failed cache hit * or IMS request. */ if (http->entry) { - if (EBIT_TEST(http->entry->flags, ENTRY_SPECIAL)) { - debug(88, 0) ("clientProcessMiss: miss on a special object (%s).\n", url); - debug(88, 0) ("\tlog_type = %s\n", log_tags[http->log_type]); - storeEntryDump(http->entry, 1); - } - clientRemoveStoreReference (context, &context->sc, &http->entry); + if (EBIT_TEST(http->entry->flags, ENTRY_SPECIAL)) { + debug(88, 0) ("clientProcessMiss: miss on a special object (%s).\n", + url); + debug(88, 0) ("\tlog_type = %s\n", log_tags[http->log_type]); + storeEntryDump(http->entry, 1); + } + clientRemoveStoreReference(context, &context->sc, &http->entry); } if (r->method == METHOD_PURGE) { - clientPurgeRequest(context); - return; + clientPurgeRequest(context); + return; } if (clientOnlyIfCached(http)) { - clientProcessOnlyIfCachedMiss(context); - return; + clientProcessOnlyIfCachedMiss(context); + return; } /* * Deny loops when running in accelerator/transproxy mode. */ if (http->flags.accel && r->flags.loopdetect) { clientStreamNode *next; - http->al.http.code = HTTP_FORBIDDEN; - err = clientBuildError(ERR_ACCESS_DENIED, HTTP_FORBIDDEN, NULL, &http->conn->peer.sin_addr, - http->request); - http->entry = clientCreateStoreEntry(context, r->method, null_request_flags); - errorAppendEntry(http->entry, err); + http->al.http.code = HTTP_FORBIDDEN; + err = + clientBuildError(ERR_ACCESS_DENIED, HTTP_FORBIDDEN, NULL, + &http->conn->peer.sin_addr, http->request); + http->entry = + clientCreateStoreEntry(context, r->method, null_request_flags); + errorAppendEntry(http->entry, err); /* and trigger a read of the resulting object */ - next = http->client_stream.head->next->data; - storeClientCopy(context->sc, http->entry, next->readoff, next->readlen, next->readbuf, - clientSendMoreData, context); - return; + next = http->client_stream.head->next->data; + storeClientCopy(context->sc, http->entry, next->readoff, next->readlen, + next->readbuf, clientSendMoreData, context); + return; } else { clientStreamNode *next; assert(http->out.offset == 0); http->entry = clientCreateStoreEntry(context, r->method, r->flags); /* And trigger a read of the resultant object */ - next = http->client_stream.head->next->data; - storeClientCopy(context->sc, http->entry, next->readoff, next->readlen, next->readbuf, - clientSendMoreData, context); + next = http->client_stream.head->next->data; + storeClientCopy(context->sc, http->entry, next->readoff, next->readlen, + next->readbuf, clientSendMoreData, context); if (http->redirect.status) { HttpReply *rep = httpReplyCreate(); #if LOG_TCP_REDIRECTS http->log_type = LOG_TCP_REDIRECT; #endif storeReleaseRequest(http->entry); - httpRedirectReply(rep, http->redirect.status, http->redirect.location); + httpRedirectReply(rep, http->redirect.status, + http->redirect.location); httpReplySwapOut(rep, http->entry); httpReplyDestroy(rep); storeComplete(http->entry); @@ -691,49 +710,54 @@ * respond with a 504 (Gateway Timeout) as suggested in [RFC 2068] */ static void -clientProcessOnlyIfCachedMiss(clientReplyContext *context) +clientProcessOnlyIfCachedMiss(clientReplyContext * context) { - clientHttpRequest * http = context->http; + clientHttpRequest *http = context->http; char *url = http->uri; request_t *r = http->request; ErrorState *err = NULL; clientStreamNode *next; debug(88, 4) ("clientProcessOnlyIfCachedMiss: '%s %s'\n", - RequestMethodStr[r->method], url); + RequestMethodStr[r->method], url); http->al.http.code = HTTP_GATEWAY_TIMEOUT; - err = clientBuildError (ERR_ONLY_IF_CACHED_MISS, HTTP_GATEWAY_TIMEOUT, NULL, - &http->conn->peer.sin_addr, http->request); - clientRemoveStoreReference (context, &context->sc, &http->entry); - http->entry = clientCreateStoreEntry(context, r->method, null_request_flags); + err = clientBuildError(ERR_ONLY_IF_CACHED_MISS, HTTP_GATEWAY_TIMEOUT, NULL, + &http->conn->peer.sin_addr, http->request); + clientRemoveStoreReference(context, &context->sc, &http->entry); + http->entry = + clientCreateStoreEntry(context, r->method, null_request_flags); /* And trigger a read of the resultant object */ - next = http->client_stream.head->next->data; - storeClientCopy(context->sc, http->entry, next->readoff, next->readlen, next->readbuf, - clientSendMoreData, context); + next = http->client_stream.head->next->data; + storeClientCopy(context->sc, http->entry, next->readoff, next->readlen, + next->readbuf, clientSendMoreData, context); errorAppendEntry(http->entry, err); } void -clientPurgeRequest(clientReplyContext *context) +clientPurgeRequest(clientReplyContext * context) { - clientHttpRequest * http = context->http; + clientHttpRequest *http = context->http; StoreEntry *entry; ErrorState *err = NULL; HttpReply *r; http_status status = HTTP_NOT_FOUND; clientStreamNode *next; http_version_t version; - debug(88, 3) ("Config2.onoff.enable_purge = %d\n", Config2.onoff.enable_purge); - next = http->client_stream.head->next->data; + debug(88, 3) ("Config2.onoff.enable_purge = %d\n", + Config2.onoff.enable_purge); + next = http->client_stream.head->next->data; if (!Config2.onoff.enable_purge) { - http->log_type = LOG_TCP_DENIED; - err = clientBuildError(ERR_ACCESS_DENIED, HTTP_FORBIDDEN, NULL, &http->conn->peer.sin_addr, - http->request); - http->entry = clientCreateStoreEntry(context, http->request->method, null_request_flags); - /* And trigger a read of the resultant object */ - storeClientCopy(context->sc, http->entry, next->readoff, next->readlen, next->readbuf, - clientSendMoreData, context); - errorAppendEntry(http->entry, err); - return; + http->log_type = LOG_TCP_DENIED; + err = + clientBuildError(ERR_ACCESS_DENIED, HTTP_FORBIDDEN, NULL, + &http->conn->peer.sin_addr, http->request); + http->entry = + clientCreateStoreEntry(context, http->request->method, + null_request_flags); + /* And trigger a read of the resultant object */ + storeClientCopy(context->sc, http->entry, next->readoff, next->readlen, + next->readbuf, clientSendMoreData, context); + errorAppendEntry(http->entry, err); + return; } /* Release both IP cache */ ipcacheInvalidate(http->request->host); @@ -742,70 +766,68 @@ * requests! */ if (!http->flags.purging) { - /* Try to find a base entry */ - http->flags.purging = 1; - entry = storeGetPublicByRequestMethod(http->request, METHOD_GET); - if (!entry) - entry = storeGetPublicByRequestMethod(http->request, METHOD_HEAD); - if (entry) { - /* Swap in the metadata */ - http->entry = entry; - storeLockObject(http->entry); - storeCreateMemObject(http->entry, http->uri, http->log_uri); - http->entry->mem_obj->method = http->request->method; - context->sc = storeClientListAdd(http->entry, context); - http->log_type = LOG_TCP_HIT; - context->reqofs = 0; - storeClientCopy(context->sc, http->entry, - http->out.offset, - next->readlen, - next->readbuf, - clientCacheHit, - context); - return; - } + /* Try to find a base entry */ + http->flags.purging = 1; + entry = storeGetPublicByRequestMethod(http->request, METHOD_GET); + if (!entry) + entry = storeGetPublicByRequestMethod(http->request, METHOD_HEAD); + if (entry) { + /* Swap in the metadata */ + http->entry = entry; + storeLockObject(http->entry); + storeCreateMemObject(http->entry, http->uri, http->log_uri); + http->entry->mem_obj->method = http->request->method; + context->sc = storeClientListAdd(http->entry, context); + http->log_type = LOG_TCP_HIT; + context->reqofs = 0; + storeClientCopy(context->sc, http->entry, + http->out.offset, + next->readlen, next->readbuf, clientCacheHit, context); + return; + } } http->log_type = LOG_TCP_MISS; /* Release the cached URI */ entry = storeGetPublicByRequestMethod(http->request, METHOD_GET); if (entry) { - debug(88, 4) ("clientPurgeRequest: GET '%s'\n", - storeUrl(entry)); - storeRelease(entry); - status = HTTP_OK; + debug(88, 4) ("clientPurgeRequest: GET '%s'\n", storeUrl(entry)); + storeRelease(entry); + status = HTTP_OK; } entry = storeGetPublicByRequestMethod(http->request, METHOD_HEAD); if (entry) { - debug(88, 4) ("clientPurgeRequest: HEAD '%s'\n", - storeUrl(entry)); - storeRelease(entry); - status = HTTP_OK; + debug(88, 4) ("clientPurgeRequest: HEAD '%s'\n", storeUrl(entry)); + storeRelease(entry); + status = HTTP_OK; } /* And for Vary, release the base URI if none of the headers was included in the request */ - if (http->request->vary_headers && !strstr(http->request->vary_headers, "=")) { - entry = storeGetPublic(urlCanonical(http->request), METHOD_GET); - if (entry) { - debug(88, 4) ("clientPurgeRequest: Vary GET '%s'\n", - storeUrl(entry)); - storeRelease(entry); - status = HTTP_OK; - } - entry = storeGetPublic(urlCanonical(http->request), METHOD_HEAD); - if (entry) { - debug(88, 4) ("clientPurgeRequest: Vary HEAD '%s'\n", - storeUrl(entry)); - storeRelease(entry); - status = HTTP_OK; - } + if (http->request->vary_headers + && !strstr(http->request->vary_headers, "=")) { + entry = storeGetPublic(urlCanonical(http->request), METHOD_GET); + if (entry) { + debug(88, 4) ("clientPurgeRequest: Vary GET '%s'\n", + storeUrl(entry)); + storeRelease(entry); + status = HTTP_OK; + } + entry = storeGetPublic(urlCanonical(http->request), METHOD_HEAD); + if (entry) { + debug(88, 4) ("clientPurgeRequest: Vary HEAD '%s'\n", + storeUrl(entry)); + storeRelease(entry); + status = HTTP_OK; + } } /* * Make a new entry to hold the reply to be written * to the client. */ - http->entry = clientCreateStoreEntry(context, http->request->method, null_request_flags); + http->entry = + clientCreateStoreEntry(context, http->request->method, + null_request_flags); /* And trigger a read of the resultant object */ - storeClientCopy(context->sc, http->entry, next->readoff, next->readlen, next->readbuf, - clientSendMoreData, context); + storeClientCopy(context->sc, http->entry, next->readoff, next->readlen, + next->readbuf, clientSendMoreData, context); httpReplyReset(r = http->entry->mem_obj->reply); httpBuildVersion(&version, 1, 0); httpReplySetHeaders(r, version, status, NULL, NULL, 0, 0, -1); @@ -814,22 +836,24 @@ } void -clientTraceReply (clientStreamNode *node, clientReplyContext *context) +clientTraceReply(clientStreamNode * node, clientReplyContext * context) { HttpReply *rep; http_version_t version; clientStreamNode *next = node->node.next->data; - assert (context->http->request->max_forwards == 0); - context->http->entry = clientCreateStoreEntry(context, context->http->request->method, - null_request_flags); - storeClientCopy(context->sc, context->http->entry, next->readoff + context->headers_sz, - next->readlen, next->readbuf, clientSendMoreData, context); + assert(context->http->request->max_forwards == 0); + context->http->entry = + clientCreateStoreEntry(context, context->http->request->method, + null_request_flags); + storeClientCopy(context->sc, context->http->entry, + next->readoff + context->headers_sz, next->readlen, next->readbuf, + clientSendMoreData, context); storeReleaseRequest(context->http->entry); storeBuffer(context->http->entry); rep = httpReplyCreate(); httpBuildVersion(&version, 1, 0); httpReplySetHeaders(rep, version, HTTP_OK, NULL, "text/plain", - httpRequestPrefixLen(context->http->request), 0, squid_curtime); + httpRequestPrefixLen(context->http->request), 0, squid_curtime); httpReplySwapOut(rep, context->http->entry); httpReplyDestroy(rep); httpRequestSwapOut(context->http->request, context->http->entry); @@ -839,7 +863,7 @@ #define SENDING_BODY 0 #define SENDING_HDRSONLY 1 int -clientCheckTransferDone(clientHttpRequest const * http) +clientCheckTransferDone(clientHttpRequest const *http) { int sending = SENDING_BODY; StoreEntry *entry = http->entry; @@ -847,23 +871,23 @@ http_reply *reply; int sendlen; if (entry == NULL) - return 0; + return 0; /* * For now, 'done_copying' is used for special cases like * Range and HEAD requests. - */ + */ if (http->flags.done_copying) - return 1; + return 1; /* * Handle STORE_OK objects. * objectLen(entry) will be set proprely. * RC: Does objectLen(entry) include the Headers? */ if (entry->store_status == STORE_OK) { - if (http->out.offset >= objectLen(entry)) - return 1; - else - return 0; + if (http->out.offset >= objectLen(entry)) + return 1; + else + return 0; } /* * Now, handle STORE_PENDING objects @@ -873,49 +897,50 @@ assert(http->request != NULL); reply = mem->reply; if (reply->hdr_sz == 0) - return 0; /* haven't found end of headers yet */ + return 0; /* haven't found end of headers yet */ else if (reply->sline.status == HTTP_OK) - sending = SENDING_BODY; + sending = SENDING_BODY; else if (reply->sline.status == HTTP_NO_CONTENT) - sending = SENDING_HDRSONLY; + sending = SENDING_HDRSONLY; else if (reply->sline.status == HTTP_NOT_MODIFIED) - sending = SENDING_HDRSONLY; + sending = SENDING_HDRSONLY; else if (reply->sline.status < HTTP_OK) - sending = SENDING_HDRSONLY; + sending = SENDING_HDRSONLY; else if (http->request->method == METHOD_HEAD) - sending = SENDING_HDRSONLY; + sending = SENDING_HDRSONLY; else - sending = SENDING_BODY; + sending = SENDING_BODY; /* * Figure out how much data we are supposed to send. * If we are sending a body and we don't have a content-length, * then we must wait for the object to become STORE_OK. */ if (sending == SENDING_HDRSONLY) - sendlen = reply->hdr_sz; + sendlen = reply->hdr_sz; else if (reply->content_length < 0) - return 0; + return 0; else - sendlen = reply->content_length + reply->hdr_sz; + sendlen = reply->content_length + reply->hdr_sz; /* * Now that we have the expected length, did we send it all? */ if (http->out.offset < sendlen) - return 0; + return 0; else - return 1; + return 1; } int -clientGotNotEnough(clientHttpRequest const * http) +clientGotNotEnough(clientHttpRequest const *http) { - int cl = httpReplyBodySize(http->request->method, http->entry->mem_obj->reply); + int cl = + httpReplyBodySize(http->request->method, http->entry->mem_obj->reply); int hs = http->entry->mem_obj->reply->hdr_sz; assert(cl >= 0); if (http->out.offset < cl + hs) - return 1; + return 1; return 0; } @@ -927,12 +952,14 @@ * */ int -clientHttpRequestStatus (int fd, clientHttpRequest const *http) +clientHttpRequestStatus(int fd, clientHttpRequest const *http) { #if SIZEOF_SIZE_T == 4 if (http->out.size > 0x7FFF0000) { - debug(88, 1) ("WARNING: closing FD %d to prevent counter overflow\n", fd); - debug(88, 1) ("\tclient %s\n", inet_ntoa(http->conn ? http->conn->peer.sin_addr : no_addr)); + debug(88, 1) ("WARNING: closing FD %d to prevent counter overflow\n", + fd); + debug(88, 1) ("\tclient %s\n", + inet_ntoa(http->conn ? http->conn->peer.sin_addr : no_addr)); debug(88, 1) ("\treceived %d bytes\n", (int) http->out.size); debug(88, 1) ("\tURI %s\n", http->log_uri); return 1; @@ -940,9 +967,12 @@ #endif #if SIZEOF_OFF_T == 4 if (http->out.offset > 0x7FFF0000) { - debug(88, 1) ("WARNING: closing FD %d to prevent counter overflow\n", fd); - debug(88, 1) ("\tclient %s\n", inet_ntoa(http->conn ? http->conn->peer.sin_addr : no_addr)); - debug(88, 1) ("\treceived %d bytes (offset %d)\n", (int) http->out.size, (int) http->out.offset); + debug(88, 1) ("WARNING: closing FD %d to prevent counter overflow\n", + fd); + debug(88, 1) ("\tclient %s\n", + inet_ntoa(http->conn ? http->conn->peer.sin_addr : no_addr)); + debug(88, 1) ("\treceived %d bytes (offset %d)\n", (int) http->out.size, + (int) http->out.offset); debug(88, 1) ("\tURI %s\n", http->log_uri); return 1; } @@ -960,13 +990,13 @@ * of the object. */ clientStream_status_t -clientReplyStatus (clientStreamNode *this, clientHttpRequest *http) +clientReplyStatus(clientStreamNode * this, clientHttpRequest * http) { clientReplyContext *context = this->data; int done; /* Here because lower nodes don't need it */ if (http->entry == NULL) - return STREAM_FAILED; /* yuck, but what can we do? */ + return STREAM_FAILED; /* yuck, but what can we do? */ if (EBIT_TEST(http->entry->flags, ENTRY_ABORTED)) /* TODO: Could upstream read errors (retsize < 0) be * lost, and result in undersize requests being considered @@ -976,7 +1006,8 @@ if ((done = clientCheckTransferDone(http)) != 0 || context->flags.complete) { debug(88, 5) ("clientReplyStatus: transfer is DONE\n"); /* Ok we're finished, but how? */ - if (httpReplyBodySize(http->request->method, http->entry->mem_obj->reply) < 0) { + if (httpReplyBodySize(http->request->method, + http->entry->mem_obj->reply) < 0) { debug(88, 5) ("clientWriteComplete: closing, content_length < 0\n"); return STREAM_FAILED; } else if (!done) { @@ -989,7 +1020,7 @@ return STREAM_COMPLETE; } return STREAM_UNPLANNED_COMPLETE; - + } if (clientReplyBodyTooLarge(http->entry->mem_obj->reply, http->out.offset)) return STREAM_FAILED; @@ -1014,11 +1045,11 @@ case HTTP_PROCESSING: case HTTP_NO_CONTENT: case HTTP_NOT_MODIFIED: - return 1; - /* unreached */ - break; + return 1; + /* unreached */ + break; default: - return 0; + return 0; } } @@ -1029,7 +1060,7 @@ */ static void clientBuildReplyHeader(clientHttpRequest * http, HttpReply * rep) -{ +{ HttpHeader *hdr = &rep->header; int is_hit = isTcpHit(http->log_type); request_t *request = http->request; @@ -1043,76 +1074,80 @@ httpHeaderDelByName(hdr, "Keep-Alive"); /* remove Set-Cookie if a hit */ if (is_hit) - httpHeaderDelById(hdr, HDR_SET_COOKIE); + httpHeaderDelById(hdr, HDR_SET_COOKIE); /* handle Connection header */ if (httpHeaderHas(hdr, HDR_CONNECTION)) { - /* anything that matches Connection list member will be deleted */ - String strConnection = httpHeaderGetList(hdr, HDR_CONNECTION); - const HttpHeaderEntry *e; - HttpHeaderPos pos = HttpHeaderInitPos; - /* - * think: on-average-best nesting of the two loops (hdrEntry - * and strListItem) @?@ - */ - /* - * maybe we should delete standard stuff ("keep-alive","close") - * from strConnection first? - */ - while ((e = httpHeaderGetEntry(hdr, &pos))) { - if (strListIsMember(&strConnection, strBuf(e->name), ',')) - httpHeaderDelAt(hdr, pos); - } - httpHeaderDelById(hdr, HDR_CONNECTION); - stringClean(&strConnection); + /* anything that matches Connection list member will be deleted */ + String strConnection = httpHeaderGetList(hdr, HDR_CONNECTION); + const HttpHeaderEntry *e; + HttpHeaderPos pos = HttpHeaderInitPos; + /* + * think: on-average-best nesting of the two loops (hdrEntry + * and strListItem) @?@ + */ + /* + * maybe we should delete standard stuff ("keep-alive","close") + * from strConnection first? + */ + while ((e = httpHeaderGetEntry(hdr, &pos))) { + if (strListIsMember(&strConnection, strBuf(e->name), ',')) + httpHeaderDelAt(hdr, pos); + } + httpHeaderDelById(hdr, HDR_CONNECTION); + stringClean(&strConnection); } /* * Add a estimated Age header on cache hits. */ if (is_hit) { - /* - * Remove any existing Age header sent by upstream caches - * (note that the existing header is passed along unmodified - * on cache misses) - */ - httpHeaderDelById(hdr, HDR_AGE); - /* - * This adds the calculated object age. Note that the details of the - * age calculation is performed by adjusting the timestamp in - * storeTimestampsSet(), not here. - * - * BROWSER WORKAROUND: IE sometimes hangs when receiving a 0 Age - * header, so don't use it unless there is a age to report. Please - * note that Age is only used to make a conservative estimation of - * the objects age, so a Age: 0 header does not add any useful - * information to the reply in any case. - */ - if (NULL == http->entry) - (void) 0; - else if (http->entry->timestamp < 0) - (void) 0; - else if (http->entry->timestamp < squid_curtime) - httpHeaderPutInt(hdr, HDR_AGE, - squid_curtime - http->entry->timestamp); + /* + * Remove any existing Age header sent by upstream caches + * (note that the existing header is passed along unmodified + * on cache misses) + */ + httpHeaderDelById(hdr, HDR_AGE); + /* + * This adds the calculated object age. Note that the details of the + * age calculation is performed by adjusting the timestamp in + * storeTimestampsSet(), not here. + * + * BROWSER WORKAROUND: IE sometimes hangs when receiving a 0 Age + * header, so don't use it unless there is a age to report. Please + * note that Age is only used to make a conservative estimation of + * the objects age, so a Age: 0 header does not add any useful + * information to the reply in any case. + */ + if (NULL == http->entry) + (void) 0; + else if (http->entry->timestamp < 0) + (void) 0; + else if (http->entry->timestamp < squid_curtime) + httpHeaderPutInt(hdr, HDR_AGE, + squid_curtime - http->entry->timestamp); } /* Handle authentication headers */ if (request->auth_user_request) - authenticateFixHeader(rep, request->auth_user_request, request, http->flags.accel, 0); + authenticateFixHeader(rep, request->auth_user_request, request, + http->flags.accel, 0); /* Append X-Cache */ httpHeaderPutStrf(hdr, HDR_X_CACHE, "%s from %s", - is_hit ? "HIT" : "MISS", getMyHostname()); + is_hit ? "HIT" : "MISS", getMyHostname()); #if USE_CACHE_DIGESTS /* Append X-Cache-Lookup: -- temporary hack, to be removed @?@ @?@ */ httpHeaderPutStrf(hdr, HDR_X_CACHE_LOOKUP, "%s from %s:%d", - context->lookup_type ? context->lookup_type : "NONE", - getMyHostname(), getMyPort()); + context->lookup_type ? context->lookup_type : "NONE", + getMyHostname(), getMyPort()); #endif if (httpReplyBodySize(request->method, rep) < 0) { - debug(88, 3) ("clientBuildReplyHeader: can't keep-alive, unknown body size\n"); request->flags.proxy_keepalive = 0; + debug(88, + 3) + ("clientBuildReplyHeader: can't keep-alive, unknown body size\n"); + request->flags.proxy_keepalive = 0; } /* Signal keep-alive if needed */ httpHeaderPutStr(hdr, - http->flags.accel ? HDR_CONNECTION : HDR_PROXY_CONNECTION, - request->flags.proxy_keepalive ? "keep-alive" : "close"); + http->flags.accel ? HDR_CONNECTION : HDR_PROXY_CONNECTION, + request->flags.proxy_keepalive ? "keep-alive" : "close"); #if ADD_X_REQUEST_URI /* * Knowing the URI of the request is useful when debugging persistent @@ -1121,7 +1156,7 @@ * debugger [hdr->entries.count-1]. */ httpHeaderPutStr(hdr, HDR_X_REQUEST_URI, - http->entry->mem_obj->url ? http->entry->mem_obj->url : http->uri); + http->entry->mem_obj->url ? http->entry->mem_obj->url : http->uri); #endif httpHdrMangleList(hdr, request); } @@ -1133,14 +1168,14 @@ HttpReply *rep = httpReplyCreate(); size_t k = headersEnd(buf, size); if (k && httpReplyParse(rep, buf, k)) { - /* enforce 1.0 reply version */ - httpBuildVersion(&rep->sline.version, 1, 0); - /* do header conversions */ - clientBuildReplyHeader(http, rep); + /* enforce 1.0 reply version */ + httpBuildVersion(&rep->sline.version, 1, 0); + /* do header conversions */ + clientBuildReplyHeader(http, rep); } else { - /* parsing failure, get rid of the invalid reply */ - httpReplyDestroy(rep); - rep = NULL; + /* parsing failure, get rid of the invalid reply */ + httpReplyDestroy(rep); + rep = NULL; } return rep; } @@ -1151,64 +1186,64 @@ request_t *r = http->request; StoreEntry *e; if (r->flags.cachable || r->flags.internal) - e = http->entry = storeGetPublicByRequest(r); + e = http->entry = storeGetPublicByRequest(r); else - e = http->entry = NULL; + e = http->entry = NULL; /* Release negatively cached IP-cache entries on reload */ if (r->flags.nocache) - ipcacheInvalidate(r->host); + ipcacheInvalidate(r->host); #if HTTP_VIOLATIONS else if (r->flags.nocache_hack) - ipcacheInvalidate(r->host); + ipcacheInvalidate(r->host); #endif #if USE_CACHE_DIGESTS context->lookup_type = e ? "HIT" : "MISS"; #endif if (NULL == e) { - /* this object isn't in the cache */ - debug(85, 3) ("clientProcessRequest2: storeGet() MISS\n"); - return LOG_TCP_MISS; + /* this object isn't in the cache */ + debug(85, 3) ("clientProcessRequest2: storeGet() MISS\n"); + return LOG_TCP_MISS; } if (Config.onoff.offline) { - debug(85, 3) ("clientProcessRequest2: offline HIT\n"); - http->entry = e; - return LOG_TCP_HIT; + debug(85, 3) ("clientProcessRequest2: offline HIT\n"); + http->entry = e; + return LOG_TCP_HIT; } if (http->redirect.status) { - /* force this to be a miss */ - http->entry = NULL; - return LOG_TCP_MISS; + /* force this to be a miss */ + http->entry = NULL; + return LOG_TCP_MISS; } if (!storeEntryValidToSend(e)) { - debug(85, 3) ("clientProcessRequest2: !storeEntryValidToSend MISS\n"); - http->entry = NULL; - return LOG_TCP_MISS; + debug(85, 3) ("clientProcessRequest2: !storeEntryValidToSend MISS\n"); + http->entry = NULL; + return LOG_TCP_MISS; } if (EBIT_TEST(e->flags, ENTRY_SPECIAL)) { - /* Special entries are always hits, no matter what the client says */ - debug(85, 3) ("clientProcessRequest2: ENTRY_SPECIAL HIT\n"); - http->entry = e; - return LOG_TCP_HIT; + /* Special entries are always hits, no matter what the client says */ + debug(85, 3) ("clientProcessRequest2: ENTRY_SPECIAL HIT\n"); + http->entry = e; + return LOG_TCP_HIT; } #if HTTP_VIOLATIONS if (e->store_status == STORE_PENDING) { - if (r->flags.nocache || r->flags.nocache_hack) { - debug(85, 3) ("Clearing no-cache for STORE_PENDING request\n\t%s\n", - storeUrl(e)); - r->flags.nocache = 0; - r->flags.nocache_hack = 0; - } + if (r->flags.nocache || r->flags.nocache_hack) { + debug(85, 3) ("Clearing no-cache for STORE_PENDING request\n\t%s\n", + storeUrl(e)); + r->flags.nocache = 0; + r->flags.nocache_hack = 0; + } } #endif if (r->flags.nocache) { - debug(85, 3) ("clientProcessRequest2: no-cache REFRESH MISS\n"); - http->entry = NULL; - return LOG_TCP_CLIENT_REFRESH_MISS; + debug(85, 3) ("clientProcessRequest2: no-cache REFRESH MISS\n"); + http->entry = NULL; + return LOG_TCP_CLIENT_REFRESH_MISS; } /* We don't cache any range requests (for now!) -- adrian */ if (r->flags.range) { - http->entry = NULL; - return LOG_TCP_MISS; + http->entry = NULL; + return LOG_TCP_MISS; } debug(85, 3) ("clientProcessRequest2: default HIT\n"); http->entry = e; @@ -1224,39 +1259,40 @@ * data context is not null */ void -clientGetMoreData (clientStreamNode *this, clientHttpRequest *http) +clientGetMoreData(clientStreamNode * this, clientHttpRequest * http) { clientStreamNode *next; clientReplyContext *context; /* Test preconditions */ - assert (this != NULL); - assert (cbdataReferenceValid (this)); - assert (this->data != NULL); - assert (this->node.prev == NULL); - assert (this->node.next != NULL); + assert(this != NULL); + assert(cbdataReferenceValid(this)); + assert(this->data != NULL); + assert(this->node.prev == NULL); + assert(this->node.next != NULL); context = this->data; - assert (context->http == http); + assert(context->http == http); next = this->node.next->data; if (!context->ourNode) - context->ourNode = this; /* no cbdatareference, this is only used once, and safely */ + context->ourNode = this; /* no cbdatareference, this is only used once, and safely */ if (context->flags.storelogiccomplete) { - storeClientCopy(context->sc, http->entry, next->readoff + context->headers_sz, - next->readlen, next->readbuf, clientSendMoreData, context); + storeClientCopy(context->sc, http->entry, + next->readoff + context->headers_sz, next->readlen, next->readbuf, + clientSendMoreData, context); return; } if (context->http->request->method == METHOD_PURGE) { - clientPurgeRequest (context); + clientPurgeRequest(context); return; } if (context->http->request->method == METHOD_TRACE) { if (context->http->request->max_forwards == 0) { - clientTraceReply (this, context); + clientTraceReply(this, context); return; } /* continue forwarding, not finished yet. */ http->log_type = LOG_TCP_MISS; - } else + } else http->log_type = clientIdentifyStoreObject(http); /* We still have to do store logic processing - vary, cache hit etc */ if (context->http->entry != NULL) { @@ -1270,8 +1306,10 @@ * is a cache hit for a GET response, we want to keep * the method as GET. */ - storeCreateMemObject(context->http->entry, context->http->uri, context->http->log_uri); - context->http->entry->mem_obj->method = context->http->request->method; + storeCreateMemObject(context->http->entry, context->http->uri, + context->http->log_uri); + context->http->entry->mem_obj->method = + context->http->request->method; } context->sc = storeClientListAdd(context->http->entry, context); #if DELAY_POOLS @@ -1279,13 +1317,10 @@ #endif assert(context->http->log_type == LOG_TCP_HIT); context->reqofs = 0; - assert (http->out.offset == http->out.size && http->out.offset == 0); + assert(http->out.offset == http->out.size && http->out.offset == 0); storeClientCopy(context->sc, http->entry, - context->reqofs, - next->readlen, - next->readbuf, - clientCacheHit, - context); + context->reqofs, + next->readlen, next->readbuf, clientCacheHit, context); } else { /* MISS CASE, http->log_type is already set! */ clientProcessMiss(context); @@ -1294,14 +1329,14 @@ /* the next node has removed itself from the stream. */ void -clientReplyDetach(clientStreamNode *node, clientHttpRequest *http) +clientReplyDetach(clientStreamNode * node, clientHttpRequest * http) { /* detach from the stream */ /* NB: This cbdataFrees our context, * so the clientSendMoreData callback (if any) * pending in the store will not trigger */ - clientStreamDetach (node, http); + clientStreamDetach(node, http); } /* @@ -1325,42 +1360,45 @@ if (buf != retbuf) { /* we've got to copy some data */ - assert (retsize <= next->readlen); - xmemcpy (buf, retbuf, retsize); + assert(retsize <= next->readlen); + xmemcpy(buf, retbuf, retsize); body_buf = buf; } /* We've got the final data to start pushing... */ context->flags.storelogiccomplete = 1; - - debug(88, 5) ("clientSendMoreData: %s, %d bytes (%d new bytes)\n", http->uri, (int) size, retsize); + + debug(88, 5) ("clientSendMoreData: %s, %d bytes (%d new bytes)\n", + http->uri, (int) size, retsize); assert(size <= HTTP_REQBUF_SZ); assert(http->request != NULL); /* ESI TODO: remove this assert once everything is stable */ - assert(http->client_stream.head->data && cbdataReferenceValid(http->client_stream.head->data)); + assert(http->client_stream.head->data + && cbdataReferenceValid(http->client_stream.head->data)); dlinkDelete(&http->active, &ClientActiveRequests); dlinkAdd(http, &http->active, &ClientActiveRequests); debug(88, 5) ("clientSendMoreData: FD %d '%s', out.offset=%ld \n", - fd, storeUrl(entry), (long int) http->out.offset); + fd, storeUrl(entry), (long int) http->out.offset); /* update size of the request */ context->reqsize = size; if (http->request->flags.reset_tcp) { /* yuck. FIXME: move to client_side.c */ - if (fd != -1) - comm_reset_close(fd); - return; - } else if (/* aborted request */ - (entry && EBIT_TEST(entry->flags, ENTRY_ABORTED)) || - /* Upstream read error */ (retsize < 0) || - /* Upstream EOF */ (body_size == 0)) { - /* call clientWriteComplete so the client socket gets closed */ - /* We call into the stream, because we don't know that there is a - * client socket! - */ + if (fd != -1) + comm_reset_close(fd); + return; + } else if ( /* aborted request */ + (entry && EBIT_TEST(entry->flags, ENTRY_ABORTED)) || + /* Upstream read error */ (retsize < 0) || + /* Upstream EOF */ (body_size == 0)) { + /* call clientWriteComplete so the client socket gets closed */ + /* We call into the stream, because we don't know that there is a + * client socket! + */ context->flags.complete = 1; - clientStreamCallback (http->client_stream.head->data, http, NULL, NULL, 0); - /* clientWriteComplete(fd, NULL, 0, COMM_OK, http); */ - return; + clientStreamCallback(http->client_stream.head->data, http, NULL, NULL, + 0); + /* clientWriteComplete(fd, NULL, 0, COMM_OK, http); */ + return; } /* FIXME: Adrian says this is a dodgy artifact from the rearrangement of * HEAD and may not be true for pipelining. @@ -1368,129 +1406,135 @@ if (http->out.offset != 0) { if (retsize == 0) context->flags.complete = 1; - clientStreamCallback (http->client_stream.head->data, http, NULL, buf, size); - return; + clientStreamCallback(http->client_stream.head->data, http, NULL, buf, + size); + return; } /* handle headers */ if (Config.onoff.log_mime_hdrs) { - size_t k; - if ((k = headersEnd(buf, size))) { - safe_free(http->al.headers.reply); - http->al.headers.reply = xcalloc(k + 1, 1); - xstrncpy(http->al.headers.reply, buf, k); - } + size_t k; + if ((k = headersEnd(buf, size))) { + safe_free(http->al.headers.reply); + http->al.headers.reply = xcalloc(k + 1, 1); + xstrncpy(http->al.headers.reply, buf, k); + } } rep = clientBuildReply(http, buf, size); if (rep) { - aclCheck_t *ch; - int rv; - httpReplyBodyBuildSize(http->request, rep, &Config.ReplyBodySize); - if (clientReplyBodyTooLarge(rep, rep->content_length)) { - ErrorState *err = clientBuildError(ERR_TOO_BIG, HTTP_FORBIDDEN, NULL, - http->conn ? &http->conn->peer.sin_addr : &no_addr, http->request); + aclCheck_t *ch; + int rv; + httpReplyBodyBuildSize(http->request, rep, &Config.ReplyBodySize); + if (clientReplyBodyTooLarge(rep, rep->content_length)) { + ErrorState *err = + clientBuildError(ERR_TOO_BIG, HTTP_FORBIDDEN, NULL, + http->conn ? &http->conn->peer.sin_addr : &no_addr, + http->request); clientStreamNode *next; - clientRemoveStoreReference (context, &context->sc, &http->entry); - http->entry = clientCreateStoreEntry(context, http->request->method, - null_request_flags); - /* And trigger a read of the resultant object */ - next = http->client_stream.head->next->data; - storeClientCopy(context->sc, http->entry, next->readoff, next->readlen, next->readbuf, - clientSendMoreData, context); - errorAppendEntry(http->entry, err); - httpReplyDestroy(rep); - return; - } + clientRemoveStoreReference(context, &context->sc, &http->entry); + http->entry = clientCreateStoreEntry(context, http->request->method, + null_request_flags); + /* And trigger a read of the resultant object */ + next = http->client_stream.head->next->data; + storeClientCopy(context->sc, http->entry, next->readoff, + next->readlen, next->readbuf, clientSendMoreData, context); + errorAppendEntry(http->entry, err); + httpReplyDestroy(rep); + return; + } context->headers_sz = rep->hdr_sz; - body_size = size - rep->hdr_sz; - assert(body_size >= 0); - body_buf = buf + rep->hdr_sz; - debug(88, 3) ("clientSendMoreData: Appending %d bytes after %d bytes of headers\n", - (int) body_size, rep->hdr_sz); - ch = aclChecklistCreate(Config.accessList.reply, http->request, NULL); - ch->reply = rep; - rv = aclCheckFast(Config.accessList.reply, ch); - aclChecklistFree(ch); - ch = NULL; - debug(88, 2) ("The reply for %s %s is %s, because it matched '%s'\n", - RequestMethodStr[http->request->method], http->uri, - rv ? "ALLOWED" : "DENIED", - AclMatchedName ? AclMatchedName : "NO ACL's"); - if (!rv && rep->sline.status != HTTP_FORBIDDEN - && !clientAlwaysAllowResponse(rep->sline.status)) { - /* the if above is slightly broken, but there is no way - * to tell if this is a squid generated error page, or one from - * upstream at this point. */ - ErrorState *err; - clientStreamNode *next; - err = clientBuildError(ERR_ACCESS_DENIED, HTTP_FORBIDDEN, NULL, http->conn ? &http->conn->peer.sin_addr : &no_addr, - http->request); - clientRemoveStoreReference (context, &context->sc, &http->entry); - http->entry = clientCreateStoreEntry(context, http->request->method, - null_request_flags); - /* And trigger a read of the resultant object */ - next = http->client_stream.head->next->data; - storeClientCopy(context->sc, http->entry, next->readoff, next->readlen, next->readbuf, - clientSendMoreData, context); - errorAppendEntry(http->entry, err); - httpReplyDestroy(rep); - return; - } + body_size = size - rep->hdr_sz; + assert(body_size >= 0); + body_buf = buf + rep->hdr_sz; + debug(88, + 3) + ("clientSendMoreData: Appending %d bytes after %d bytes of headers\n", + (int) body_size, rep->hdr_sz); + ch = aclChecklistCreate(Config.accessList.reply, http->request, NULL); + ch->reply = rep; + rv = aclCheckFast(Config.accessList.reply, ch); + aclChecklistFree(ch); + ch = NULL; + debug(88, 2) ("The reply for %s %s is %s, because it matched '%s'\n", + RequestMethodStr[http->request->method], http->uri, + rv ? "ALLOWED" : "DENIED", + AclMatchedName ? AclMatchedName : "NO ACL's"); + if (!rv && rep->sline.status != HTTP_FORBIDDEN + && !clientAlwaysAllowResponse(rep->sline.status)) { + /* the if above is slightly broken, but there is no way + * to tell if this is a squid generated error page, or one from + * upstream at this point. */ + ErrorState *err; + clientStreamNode *next; + err = + clientBuildError(ERR_ACCESS_DENIED, HTTP_FORBIDDEN, NULL, + http->conn ? &http->conn->peer.sin_addr : &no_addr, + http->request); + clientRemoveStoreReference(context, &context->sc, &http->entry); + http->entry = clientCreateStoreEntry(context, http->request->method, + null_request_flags); + /* And trigger a read of the resultant object */ + next = http->client_stream.head->next->data; + storeClientCopy(context->sc, http->entry, next->readoff, + next->readlen, next->readbuf, clientSendMoreData, context); + errorAppendEntry(http->entry, err); + httpReplyDestroy(rep); + return; + } #if ESI - if (http->flags.accel && rep->sline.status != HTTP_FORBIDDEN && - !clientAlwaysAllowResponse(rep->sline.status) && + if (http->flags.accel && rep->sline.status != HTTP_FORBIDDEN && + !clientAlwaysAllowResponse(rep->sline.status) && esiEnableProcessing(rep)) { - debug(88, 0) ("Enabling ESI processing for %s\n", http->uri); - clientStreamInsertHead (&http->client_stream, esiStreamRead, - esiProcessStream, esiStreamDetach, esiStreamStatus,NULL); - } + debug(88, 0) ("Enabling ESI processing for %s\n", http->uri); + clientStreamInsertHead(&http->client_stream, esiStreamRead, + esiProcessStream, esiStreamDetach, esiStreamStatus, NULL); + } #endif } else if (size < HTTP_REQBUF_SZ && entry->store_status == STORE_PENDING) { - /* wait for more to arrive */ - context->reqofs += retsize; - assert(context->reqofs <= HTTP_REQBUF_SZ); + /* wait for more to arrive */ + context->reqofs += retsize; + assert(context->reqofs <= HTTP_REQBUF_SZ); /* TODO: copy into the supplied buffer */ - storeClientCopy(context->sc, entry, - context->reqofs, - next->readlen - context->reqofs, - next->readbuf + context->reqofs, - clientSendMoreData, - context); - return; + storeClientCopy(context->sc, entry, + context->reqofs, + next->readlen - context->reqofs, + next->readbuf + context->reqofs, clientSendMoreData, context); + return; } if (http->request->method == METHOD_HEAD) { - if (rep) { - /* do not forward body for HEAD replies */ - /* ESI TODO: Can ESI affect headers on the master document */ - body_size = 0; - http->flags.done_copying = 1; + if (rep) { + /* do not forward body for HEAD replies */ + /* ESI TODO: Can ESI affect headers on the master document */ + body_size = 0; + http->flags.done_copying = 1; context->flags.complete = 1; - } else { - /* - * If we are here, then store_status == STORE_OK and it - * seems we have a HEAD repsponse which is missing the - * empty end-of-headers line (home.mira.net, phttpd/0.99.72 - * does this). Because clientBuildReply() fails we just - * call this reply a body, set the done_copying flag and - * continue... - */ - http->flags.done_copying = 1; + } else { + /* + * If we are here, then store_status == STORE_OK and it + * seems we have a HEAD repsponse which is missing the + * empty end-of-headers line (home.mira.net, phttpd/0.99.72 + * does this). Because clientBuildReply() fails we just + * call this reply a body, set the done_copying flag and + * continue... + */ + http->flags.done_copying = 1; context->flags.complete = 1; - } + } } assert(rep || (body_buf && body_size)); /* TODO: move the data in the buffer back by the request header size */ - clientStreamCallback (http->client_stream.head->data, http, rep, body_buf, body_size); + clientStreamCallback(http->client_stream.head->data, http, rep, body_buf, + body_size); } int clientReplyBodyTooLarge(HttpReply * rep, ssize_t clen) { if (0 == rep->maxBodySize) - return 0; /* disabled */ + return 0; /* disabled */ if (clen < 0) - return 0; /* unknown */ + return 0; /* unknown */ if (clen > rep->maxBodySize) - return 1; /* too large */ + return 1; /* too large */ return 0; } @@ -1504,23 +1548,24 @@ const request_t *r = http->request; assert(r); return r->cache_control && - EBIT_TEST(r->cache_control->mask, CC_ONLY_IF_CACHED); + EBIT_TEST(r->cache_control->mask, CC_ONLY_IF_CACHED); } /* Using this breaks the client layering just a little! */ StoreEntry * -clientCreateStoreEntry(clientReplyContext *context, method_t m, request_flags flags) +clientCreateStoreEntry(clientReplyContext * context, method_t m, + request_flags flags) { clientHttpRequest *h = context->http; StoreEntry *e; - assert (h != NULL); + assert(h != NULL); /* * For erroneous requests, we might not have a h->request, * so make a fake one. */ if (h->request == NULL) - h->request = requestLink(requestCreate(m, PROTO_NONE, null_string)); + h->request = requestLink(requestCreate(m, PROTO_NONE, null_string)); e = storeCreateEntry(h->uri, h->log_uri, flags, m); context->sc = storeClientListAdd(e, context); #if DELAY_POOLS @@ -1546,14 +1591,14 @@ } ErrorState * -clientBuildError (err_type page_id, http_status status, char const *url, struct in_addr *src_addr, request_t *request) -{ +clientBuildError(err_type page_id, http_status status, char const *url, + struct in_addr * src_addr, request_t * request) +{ ErrorState *err = errorCon(page_id, status); err->src_addr = *src_addr; if (url) - err->url = xstrdup (url); + err->url = xstrdup(url); if (request) - err->request = requestLink (request); + err->request = requestLink(request); return err; } - Index: squid/src/client_side_request.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/client_side_request.c,v retrieving revision 1.1.2.15 retrieving revision 1.1.2.16 diff -u -r1.1.2.15 -r1.1.2.16 --- squid/src/client_side_request.c 9 Sep 2002 13:58:06 -0000 1.1.2.15 +++ squid/src/client_side_request.c 9 Sep 2002 22:25:07 -0000 1.1.2.16 @@ -1,6 +1,6 @@ /* - * $Id: client_side_request.c,v 1.1.2.15 2002/09/09 13:58:06 adri Exp $ + * $Id: client_side_request.c,v 1.1.2.16 2002/09/09 22:25:07 rbcollins Exp $ * * DEBUG: section 85 Client-side Request Routines * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c) @@ -49,21 +49,24 @@ static const char *const crlf = "\r\n"; -typedef struct _clientRequestContext { - aclCheck_t *acl_checklist; /* need ptr back so we can unreg if needed */ +typedef struct _clientRequestContext +{ + aclCheck_t *acl_checklist; /* need ptr back so we can unreg if needed */ int redirect_state; clientHttpRequest *http; -} clientRequestContext; -CBDATA_TYPE (clientRequestContext); +} +clientRequestContext; +CBDATA_TYPE(clientRequestContext); /* Local functions */ /* clientRequestContext */ -clientRequestContext *clientRequestContextNew (clientHttpRequest *); +clientRequestContext *clientRequestContextNew(clientHttpRequest *); FREE clientRequestContextFree; /* other */ static int checkAccelOnly(clientHttpRequest *); static void clientAccessCheckDone(int, void *); -/*static*/ aclCheck_t * clientAclChecklistCreate(const acl_access * acl, const clientHttpRequest * http); +/*static*/ aclCheck_t *clientAclChecklistCreate(const acl_access * acl, + const clientHttpRequest * http); static int clientCachable(clientHttpRequest * http); static int clientHierarchical(clientHttpRequest * http); static void clientInterpretRequestHeaders(clientHttpRequest * http); @@ -76,22 +79,22 @@ extern CSD clientReplyDetach; void -clientRequestContextFree (void *data) +clientRequestContextFree(void *data) { clientRequestContext *context = data; - cbdataReferenceDone (context->http); + cbdataReferenceDone(context->http); if (context->acl_checklist) aclChecklistFree(context->acl_checklist); } clientRequestContext * -clientRequestContextNew (clientHttpRequest *http) +clientRequestContextNew(clientHttpRequest * http) { clientRequestContext *rv; - assert (http != NULL); - CBDATA_INIT_TYPE_FREECB (clientRequestContext, clientRequestContextFree); - rv = cbdataAlloc (clientRequestContext); - rv->http = cbdataReference (http); + assert(http != NULL); + CBDATA_INIT_TYPE_FREECB(clientRequestContext, clientRequestContextFree); + rv = cbdataAlloc(clientRequestContext); + rv->http = cbdataReference(http); return rv; } @@ -99,12 +102,13 @@ /* TODO: Pass in the buffers to be used in the inital Read request, * as they are determined by the user */ -int /* returns nonzero on failure */ -clientBeginRequest (method_t method, char const *url, CSCB *streamcallback, CSD *streamdetach, void *streamdata, HttpHeader const *header, - char *tailbuf, size_t taillen) +int /* returns nonzero on failure */ +clientBeginRequest(method_t method, char const *url, CSCB * streamcallback, + CSD * streamdetach, void *streamdata, HttpHeader const *header, + char *tailbuf, size_t taillen) { size_t url_sz; - http_version_t http_ver = {1,0}; + http_version_t http_ver = { 1, 0 }; clientHttpRequest *http = cbdataAlloc(clientHttpRequest); request_t *request; http->http_ver = http_ver; @@ -113,12 +117,14 @@ /* this is only used to adjust the connection offset in client_side.c */ http->req_sz = 0; /* client stream setup */ - clientStreamInit (&http->client_stream, clientGetMoreData, clientReplyDetach, clientReplyStatus, clientReplyNewContext (http), streamcallback, streamdetach, streamdata, tailbuf, taillen); + clientStreamInit(&http->client_stream, clientGetMoreData, clientReplyDetach, + clientReplyStatus, clientReplyNewContext(http), streamcallback, + streamdetach, streamdata, tailbuf, taillen); /* make it visible in the 'current acctive requests list' */ dlinkAdd(http, &http->active, &ClientActiveRequests); /* Set flags */ - http->flags.accel = 1; /* internal requests only makes sense in an - accelerator today. TODO: accept flags ? */ + http->flags.accel = 1; /* internal requests only makes sense in an + * accelerator today. TODO: accept flags ? */ /* allow size for url rewriting */ url_sz = strlen(url) + Config.appendDomainLen + 5; http->uri = xcalloc(url_sz, 1); @@ -141,22 +147,22 @@ * TODO */ request->flags.accelerated = http->flags.accel; - request->flags.internalclient = 1; /* this is an internally created request, not subject - to acceleration target overrides - */ + request->flags.internalclient = 1; /* this is an internally created request, not subject + * to acceleration target overrides + */ /* FIXME? Do we want to detect and handle internal requests of internal * objects ? */ /* Internally created requests cannot have bodies today */ - request->content_length =0; + request->content_length = 0; request->client_addr = no_addr; - request->my_addr = no_addr; /* undefined for internal requests */ + request->my_addr = no_addr; /* undefined for internal requests */ request->my_port = 0; request->http_ver = http_ver; http->request = requestLink(request); /* optional - skip the access check ? */ - clientAccessCheck (http); + clientAccessCheck(http); return 0; } @@ -172,7 +178,7 @@ if (http->request->protocol == PROTO_CACHEOBJ) return 0; if (http->flags.accel) - return 0; + return 0; if (http->request->method == METHOD_PURGE) return 0; return 1; @@ -183,10 +189,8 @@ { aclCheck_t *ch; ConnStateData *conn = http->conn; - ch = aclChecklistCreate(acl, - http->request, - conn ? conn->rfc931 : dash_str); - + ch = aclChecklistCreate(acl, http->request, conn ? conn->rfc931 : dash_str); + /* * hack for ident ACL. It needs to get full addresses, and a * place to store the ident result on persistent connections... @@ -198,8 +202,8 @@ * B) they are internal - any limiting on them should be done on the server end. */ if (conn) - ch->conn = cbdataReference(conn); /* unreferenced in acl.c */ - + ch->conn = cbdataReference(conn); /* unreferenced in acl.c */ + return ch; } @@ -208,14 +212,16 @@ clientAccessCheck(void *data) { clientHttpRequest *http = data; - clientRequestContext *context = clientRequestContextNew (http); + clientRequestContext *context = clientRequestContextNew(http); if (checkAccelOnly(http)) { /* deny proxy requests in accel_only mode */ - debug(85, 1) ("clientAccessCheck: proxy request denied in accel_only mode\n"); + debug(85, + 1) ("clientAccessCheck: proxy request denied in accel_only mode\n"); clientAccessCheckDone(ACCESS_DENIED, context); return; } - context->acl_checklist = clientAclChecklistCreate(Config.accessList.http, http); + context->acl_checklist = + clientAclChecklistCreate(Config.accessList.http, http); aclNBCheck(context->acl_checklist, clientAccessCheckDone, context); } @@ -228,55 +234,60 @@ http_status status; char *proxy_auth_msg = NULL; debug(85, 2) ("The request %s %s is %s, because it matched '%s'\n", - RequestMethodStr[http->request->method], http->uri, - answer == ACCESS_ALLOWED ? "ALLOWED" : "DENIED", - AclMatchedName ? AclMatchedName : "NO ACL's"); - proxy_auth_msg = authenticateAuthUserRequestMessage((http->conn && http->conn->auth_user_request) ? http->conn->auth_user_request : http->request->auth_user_request); + RequestMethodStr[http->request->method], http->uri, + answer == ACCESS_ALLOWED ? "ALLOWED" : "DENIED", + AclMatchedName ? AclMatchedName : "NO ACL's"); + proxy_auth_msg = authenticateAuthUserRequestMessage((http->conn + && http->conn->auth_user_request) ? http->conn-> + auth_user_request : http->request->auth_user_request); context->acl_checklist = NULL; if (answer == ACCESS_ALLOWED) { - safe_free(http->uri); - http->uri = xstrdup(urlCanonical(http->request)); - assert(context->redirect_state == REDIRECT_NONE); - context->redirect_state = REDIRECT_PENDING; - redirectStart(http, clientRedirectDone, context); + safe_free(http->uri); + http->uri = xstrdup(urlCanonical(http->request)); + assert(context->redirect_state == REDIRECT_NONE); + context->redirect_state = REDIRECT_PENDING; + redirectStart(http, clientRedirectDone, context); } else { /* Send an error */ clientStreamNode *node = http->client_stream.tail->prev->data; - cbdataFree (context); - debug(85, 5) ("Access Denied: %s\n", http->uri); - debug(85, 5) ("AclMatchedName = %s\n", - AclMatchedName ? AclMatchedName : ""); - debug(85, 5) ("Proxy Auth Message = %s\n", - proxy_auth_msg ? proxy_auth_msg : ""); - /* - * NOTE: get page_id here, based on AclMatchedName because - * if USE_DELAY_POOLS is enabled, then AclMatchedName gets - * clobbered in the clientCreateStoreEntry() call - * just below. Pedro Ribeiro - */ - page_id = aclGetDenyInfoPage(&Config.denyInfoList, AclMatchedName); - http->log_type = LOG_TCP_DENIED; - if (answer == ACCESS_REQ_PROXY_AUTH || aclIsProxyAuth(AclMatchedName)) { - if (!http->flags.accel) { - /* Proxy authorisation needed */ - status = HTTP_PROXY_AUTHENTICATION_REQUIRED; - } else { - /* WWW authorisation needed */ - status = HTTP_UNAUTHORIZED; - } - if (page_id == ERR_NONE) - page_id = ERR_CACHE_ACCESS_DENIED; - } else { - status = HTTP_FORBIDDEN; - if (page_id == ERR_NONE) - page_id = ERR_ACCESS_DENIED; - } - clientSetReplyToError (node->data,page_id, status, http->request->method, NULL, - http->conn ? &http->conn->peer.sin_addr : &no_addr, http->request, NULL, - http->conn && http->conn->auth_user_request ? - http->conn->auth_user_request : http->request->auth_user_request); + cbdataFree(context); + debug(85, 5) ("Access Denied: %s\n", http->uri); + debug(85, 5) ("AclMatchedName = %s\n", + AclMatchedName ? AclMatchedName : ""); + debug(85, 5) ("Proxy Auth Message = %s\n", + proxy_auth_msg ? proxy_auth_msg : ""); + /* + * NOTE: get page_id here, based on AclMatchedName because + * if USE_DELAY_POOLS is enabled, then AclMatchedName gets + * clobbered in the clientCreateStoreEntry() call + * just below. Pedro Ribeiro + */ + page_id = aclGetDenyInfoPage(&Config.denyInfoList, AclMatchedName); + http->log_type = LOG_TCP_DENIED; + if (answer == ACCESS_REQ_PROXY_AUTH || aclIsProxyAuth(AclMatchedName)) { + if (!http->flags.accel) { + /* Proxy authorisation needed */ + status = HTTP_PROXY_AUTHENTICATION_REQUIRED; + } else { + /* WWW authorisation needed */ + status = HTTP_UNAUTHORIZED; + } + if (page_id == ERR_NONE) + page_id = ERR_CACHE_ACCESS_DENIED; + } else { + status = HTTP_FORBIDDEN; + if (page_id == ERR_NONE) + page_id = ERR_ACCESS_DENIED; + } + clientSetReplyToError(node->data, page_id, status, + http->request->method, NULL, + http->conn ? &http->conn->peer.sin_addr : &no_addr, http->request, + NULL, http->conn + && http->conn->auth_user_request ? http->conn-> + auth_user_request : http->request->auth_user_request); node = http->client_stream.tail->data; - clientStreamRead (node, http, node->readoff,node->readlen,node->readbuf); + clientStreamRead(node, http, node->readoff, node->readlen, + node->readbuf); } } @@ -286,26 +297,26 @@ request_t *req = http->request; method_t method = req->method; if (req->protocol == PROTO_HTTP) - return httpCachable(method); + return httpCachable(method); /* FTP is always cachable */ if (req->protocol == PROTO_WAIS) - return 0; + return 0; /* The below looks questionable: what non HTTP * protocols use connect, trace, put and post? * RC */ - if (method == METHOD_CONNECT) - return 0; + if (method == METHOD_CONNECT) + return 0; if (method == METHOD_TRACE) - return 0; + return 0; if (method == METHOD_PUT) - return 0; + return 0; if (method == METHOD_POST) - return 0; /* XXX POST may be cached sometimes.. ignored for now */ + return 0; /* XXX POST may be cached sometimes.. ignored for now */ if (req->protocol == PROTO_GOPHER) - return gopherCachable(req); + return gopherCachable(req); if (req->protocol == PROTO_CACHEOBJ) - return 0; + return 0; return 1; } @@ -320,32 +331,32 @@ /* IMS needs a private key, so we can use the hierarchy for IMS only * if our neighbors support private keys */ if (request->flags.ims && !neighbors_do_private_keys) - return 0; + return 0; /* This is incorrect: authenticating requests * can be sent via a hierarchy (they can even * be cached if the correct headers are set on * the reply */ if (request->flags.auth) - return 0; + return 0; if (method == METHOD_TRACE) - return 1; + return 1; if (method != METHOD_GET) - return 0; + return 0; /* scan hierarchy_stoplist */ for (p = Config.hierarchy_stoplist; p; p = p->next) - if (strstr(url, p->key)) - return 0; + if (strstr(url, p->key)) + return 0; if (request->flags.loopdetect) - return 0; + return 0; if (request->protocol == PROTO_HTTP) - return httpCachable(method); + return httpCachable(method); if (request->protocol == PROTO_GOPHER) - return gopherCachable(request); + return gopherCachable(request); if (request->protocol == PROTO_WAIS) - return 0; + return 0; if (request->protocol == PROTO_CACHEOBJ) - return 0; + return 0; return 1; } @@ -362,22 +373,22 @@ request->imslen = -1; request->ims = httpHeaderGetTime(req_hdr, HDR_IF_MODIFIED_SINCE); if (request->ims > 0) - request->flags.ims = 1; + request->flags.ims = 1; #if ESI /* We ignore Cache-Control as per the Edge Architecture * Section 3. See www.esi.org for more information. */ #else if (httpHeaderHas(req_hdr, HDR_PRAGMA)) { - String s = httpHeaderGetList(req_hdr, HDR_PRAGMA); - if (strListIsMember(&s, "no-cache", ',')) - no_cache++; - stringClean(&s); + String s = httpHeaderGetList(req_hdr, HDR_PRAGMA); + if (strListIsMember(&s, "no-cache", ',')) + no_cache++; + stringClean(&s); } request->cache_control = httpHeaderGetCc(req_hdr); if (request->cache_control) - if (EBIT_TEST(request->cache_control->mask, CC_NO_CACHE)) - no_cache++; + if (EBIT_TEST(request->cache_control->mask, CC_NO_CACHE)) + no_cache++; /* Work around for supporting the Reload button in IE browsers * when Squid is used as an accelerator or transparent proxy, * by turning accelerated IMS request to no-cache requests. @@ -386,94 +397,95 @@ * all 5.5 versions are treated 'normally'). */ if (Config.onoff.ie_refresh) { - if (http->flags.accel && request->flags.ims) { - if ((str = httpHeaderGetStr(req_hdr, HDR_USER_AGENT))) { - if (strstr(str, "MSIE 5.01") != NULL) - no_cache++; - else if (strstr(str, "MSIE 5.0") != NULL) - no_cache++; - else if (strstr(str, "MSIE 4.") != NULL) - no_cache++; - else if (strstr(str, "MSIE 3.") != NULL) - no_cache++; - } - } + if (http->flags.accel && request->flags.ims) { + if ((str = httpHeaderGetStr(req_hdr, HDR_USER_AGENT))) { + if (strstr(str, "MSIE 5.01") != NULL) + no_cache++; + else if (strstr(str, "MSIE 5.0") != NULL) + no_cache++; + else if (strstr(str, "MSIE 4.") != NULL) + no_cache++; + else if (strstr(str, "MSIE 3.") != NULL) + no_cache++; + } + } } #endif if (no_cache) { #if HTTP_VIOLATIONS - if (Config.onoff.reload_into_ims) - request->flags.nocache_hack = 1; - else if (refresh_nocache_hack) - request->flags.nocache_hack = 1; - else + if (Config.onoff.reload_into_ims) + request->flags.nocache_hack = 1; + else if (refresh_nocache_hack) + request->flags.nocache_hack = 1; + else #endif - request->flags.nocache = 1; + request->flags.nocache = 1; } /* ignore range header in non-GETs */ if (request->method == METHOD_GET) { - /* - * Since we're not doing ranges atm, just set the flag if - * the header exists, and then free the range header info - * -- adrian - */ - request->range = httpHeaderGetRange(req_hdr); - if (request->range) { - request->flags.range = 1; - httpHdrRangeDestroy(request->range); - request->range = NULL; - } + /* + * Since we're not doing ranges atm, just set the flag if + * the header exists, and then free the range header info + * -- adrian + */ + request->range = httpHeaderGetRange(req_hdr); + if (request->range) { + request->flags.range = 1; + httpHdrRangeDestroy(request->range); + request->range = NULL; + } } if (httpHeaderHas(req_hdr, HDR_AUTHORIZATION)) - request->flags.auth = 1; + request->flags.auth = 1; if (request->login[0] != '\0') - request->flags.auth = 1; + request->flags.auth = 1; if (httpHeaderHas(req_hdr, HDR_VIA)) { - String s = httpHeaderGetList(req_hdr, HDR_VIA); - /* - * ThisCache cannot be a member of Via header, "1.0 ThisCache" can. - * Note ThisCache2 has a space prepended to the hostname so we don't - * accidentally match super-domains. - */ - if (strListIsSubstr(&s, ThisCache2, ',')) { - debugObj(33, 1, "WARNING: Forwarding loop detected for:\n", - request, (ObjPackMethod) & httpRequestPack); - request->flags.loopdetect = 1; - } + String s = httpHeaderGetList(req_hdr, HDR_VIA); + /* + * ThisCache cannot be a member of Via header, "1.0 ThisCache" can. + * Note ThisCache2 has a space prepended to the hostname so we don't + * accidentally match super-domains. + */ + if (strListIsSubstr(&s, ThisCache2, ',')) { + debugObj(33, 1, "WARNING: Forwarding loop detected for:\n", + request, (ObjPackMethod) & httpRequestPack); + request->flags.loopdetect = 1; + } #if FORW_VIA_DB - fvdbCountVia(strBuf(s)); + fvdbCountVia(strBuf(s)); #endif - stringClean(&s); + stringClean(&s); } #if USE_USERAGENT_LOG if ((str = httpHeaderGetStr(req_hdr, HDR_USER_AGENT))) - logUserAgent(fqdnFromAddr(http->conn ? http->conn->log_addr.sin_addr : &noaddr), str); + logUserAgent(fqdnFromAddr(http->conn ? http->conn->log_addr. + sin_addr : &noaddr), str); #endif #if USE_REFERER_LOG if ((str = httpHeaderGetStr(req_hdr, HDR_REFERER))) - logReferer(fqdnFromAddr(http->conn ? http->conn->log_addr.sin_addr : &noaddr), str, - http->log_uri); + logReferer(fqdnFromAddr(http->conn ? http->conn->log_addr. + sin_addr : &noaddr), str, http->log_uri); #endif #if FORW_VIA_DB if (httpHeaderHas(req_hdr, HDR_X_FORWARDED_FOR)) { - String s = httpHeaderGetList(req_hdr, HDR_X_FORWARDED_FOR); - fvdbCountForw(strBuf(s)); - stringClean(&s); + String s = httpHeaderGetList(req_hdr, HDR_X_FORWARDED_FOR); + fvdbCountForw(strBuf(s)); + stringClean(&s); } #endif if (request->method == METHOD_TRACE) { - request->max_forwards = httpHeaderGetInt(req_hdr, HDR_MAX_FORWARDS); + request->max_forwards = httpHeaderGetInt(req_hdr, HDR_MAX_FORWARDS); } if (clientCachable(http)) - request->flags.cachable = 1; + request->flags.cachable = 1; if (clientHierarchical(http)) - request->flags.hierarchical = 1; + request->flags.hierarchical = 1; debug(85, 5) ("clientInterpretRequestHeaders: REQ_NOCACHE = %s\n", - request->flags.nocache ? "SET" : "NOT SET"); + request->flags.nocache ? "SET" : "NOT SET"); debug(85, 5) ("clientInterpretRequestHeaders: REQ_CACHABLE = %s\n", - request->flags.cachable ? "SET" : "NOT SET"); + request->flags.cachable ? "SET" : "NOT SET"); debug(85, 5) ("clientInterpretRequestHeaders: REQ_HIERARCHICAL = %s\n", - request->flags.hierarchical ? "SET" : "NOT SET"); + request->flags.hierarchical ? "SET" : "NOT SET"); } void @@ -484,44 +496,45 @@ request_t *new_request = NULL; request_t *old_request = http->request; debug(85, 5) ("clientRedirectDone: '%s' result=%s\n", http->uri, - result ? result : "NULL"); + result ? result : "NULL"); assert(context->redirect_state == REDIRECT_PENDING); context->redirect_state = REDIRECT_DONE; if (result) { - http_status status = (http_status) atoi(result); - if (status == HTTP_MOVED_PERMANENTLY || status == HTTP_MOVED_TEMPORARILY) { - char *t = result; - if ((t = strchr(result, ':')) != NULL) { - http->redirect.status = status; - http->redirect.location = xstrdup(t + 1); - } else { - debug(85, 1) ("clientRedirectDone: bad input: %s\n", result); - } - } - if (strcmp(result, http->uri)) - new_request = urlParse(old_request->method, result); + http_status status = (http_status) atoi(result); + if (status == HTTP_MOVED_PERMANENTLY + || status == HTTP_MOVED_TEMPORARILY) { + char *t = result; + if ((t = strchr(result, ':')) != NULL) { + http->redirect.status = status; + http->redirect.location = xstrdup(t + 1); + } else { + debug(85, 1) ("clientRedirectDone: bad input: %s\n", result); + } + } + if (strcmp(result, http->uri)) + new_request = urlParse(old_request->method, result); } if (new_request) { - safe_free(http->uri); - http->uri = xstrdup(urlCanonical(new_request)); - new_request->http_ver = old_request->http_ver; - httpHeaderAppend(&new_request->header, &old_request->header); - new_request->client_addr = old_request->client_addr; - new_request->my_addr = old_request->my_addr; - new_request->my_port = old_request->my_port; - new_request->flags.redirected = 1; - if (old_request->auth_user_request) { - new_request->auth_user_request = old_request->auth_user_request; - authenticateAuthUserRequestLock(new_request->auth_user_request); - } - 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; - requestUnlink(old_request); - http->request = requestLink(new_request); + safe_free(http->uri); + http->uri = xstrdup(urlCanonical(new_request)); + new_request->http_ver = old_request->http_ver; + httpHeaderAppend(&new_request->header, &old_request->header); + new_request->client_addr = old_request->client_addr; + new_request->my_addr = old_request->my_addr; + new_request->my_port = old_request->my_port; + new_request->flags.redirected = 1; + if (old_request->auth_user_request) { + new_request->auth_user_request = old_request->auth_user_request; + authenticateAuthUserRequestLock(new_request->auth_user_request); + } + 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; + requestUnlink(old_request); + http->request = requestLink(new_request); } clientInterpretRequestHeaders(http); #if HEADERS_LOG @@ -529,7 +542,7 @@ #endif /* FIXME PIPELINE: This is innacurate during pipelining */ if (http->conn) - fd_note(http->conn->fd, http->uri); + fd_note(http->conn->fd, http->uri); clientCheckNoCache(context); } @@ -538,21 +551,22 @@ { clientHttpRequest *http = context->http; if (Config.accessList.noCache && http->request->flags.cachable) { - context->acl_checklist = clientAclChecklistCreate(Config.accessList.noCache, http); - aclNBCheck(context->acl_checklist, clientCheckNoCacheDone, context); + context->acl_checklist = + clientAclChecklistCreate(Config.accessList.noCache, http); + aclNBCheck(context->acl_checklist, clientCheckNoCacheDone, context); } else { - clientCheckNoCacheDone(http->request->flags.cachable, context); + clientCheckNoCacheDone(http->request->flags.cachable, context); } } void clientCheckNoCacheDone(int answer, void *data) { - clientRequestContext * context = data; + clientRequestContext *context = data; clientHttpRequest *http = context->http; http->request->flags.cachable = answer; context->acl_checklist = NULL; - cbdataFree (context); + cbdataFree(context); clientProcessRequest(http); } @@ -566,21 +580,19 @@ request_t *r = http->request; clientStreamNode *node; debug(85, 4) ("clientProcessRequest: %s '%s'\n", - RequestMethodStr[r->method], - http->uri); + RequestMethodStr[r->method], http->uri); if (r->method == METHOD_CONNECT) { - http->log_type = LOG_TCP_MISS; - sslStart(http, &http->out.size, &http->al.http.code); - return; + http->log_type = LOG_TCP_MISS; + sslStart(http, &http->out.size, &http->al.http.code); + return; } else { http->log_type = LOG_TAG_NONE; } debug(85, 4) ("clientProcessRequest: %s for '%s'\n", - log_tags[http->log_type], - http->uri); + log_tags[http->log_type], http->uri); /* no one should have touched this */ - assert (http->out.offset == 0); + assert(http->out.offset == 0); /* Use the Stream Luke */ node = http->client_stream.tail->data; - clientStreamRead (node, http, node->readoff,node->readlen,node->readbuf); + clientStreamRead(node, http, node->readoff, node->readlen, node->readbuf); } Index: squid/src/http.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/http.c,v retrieving revision 1.21.2.4 retrieving revision 1.21.2.5 diff -u -r1.21.2.4 -r1.21.2.5 --- squid/src/http.c 27 Aug 2002 13:42:11 -0000 1.21.2.4 +++ squid/src/http.c 9 Sep 2002 22:26:20 -0000 1.21.2.5 @@ -1,6 +1,6 @@ /* - * $Id: http.c,v 1.21.2.4 2002/08/27 13:42:11 rbcollins Exp $ + * $Id: http.c,v 1.21.2.5 2002/09/09 22:26:20 rbcollins Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -332,8 +332,7 @@ const char *item; const char *value; int ilen; - static String vstr = - {0, 0, NULL}; + static String vstr = { 0, 0, NULL }; stringClean(&vstr); vary = httpHeaderGetList(&reply->header, HDR_VARY); @@ -401,7 +400,8 @@ 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); + debug(11, 3) ("httpProcessReplyHeader: Non-HTTP-compliant header: '%s'\n", + httpState->reply_hdr); httpState->reply_hdr_state += 2; reply->sline.status = HTTP_INVALID_HEADER; return; @@ -426,7 +426,8 @@ 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); + debug(11, 3) ("httpProcessReplyHeader: HTTP CODE: %d\n", + reply->sline.status); if (neighbors_do_private_keys) httpMaybeRemovePublic(entry, reply->sline.status); switch (httpCachableReply(httpState)) { @@ -460,11 +461,14 @@ } #if ESI if (httpState->request->flags.accelerated && reply->surrogate_control) { - HttpHdrScTarget *sctusable = httpHdrScGetMergedTarget (reply->surrogate_control, Config.Accel.surrogate_id); + HttpHdrScTarget *sctusable = + httpHdrScGetMergedTarget(reply->surrogate_control, + Config.Accel.surrogate_id); if (sctusable) { if (EBIT_TEST(sctusable->mask, SC_NO_STORE) || - (Config.onoff.surrogate_is_remote && EBIT_TEST(sctusable->mask, SC_NO_STORE_REMOTE))) - httpMakePrivate (entry); + (Config.onoff.surrogate_is_remote + && EBIT_TEST(sctusable->mask, SC_NO_STORE_REMOTE))) + httpMakePrivate(entry); /* The HttpHeader logic cannot tell if the header it's parsing is a reply to an * accelerated request or not... * Still, this is an abtraction breach. - RC @@ -479,7 +483,7 @@ } /* We ignore cache-control directives as per the Surrogate specification */ ignore_cc = 1; - httpHdrScTargetDestroy (sctusable); + httpHdrScTargetDestroy(sctusable); } } #endif @@ -745,10 +749,7 @@ void httpBuildRequestHeader(request_t * request, request_t * orig_request, - StoreEntry * entry, - HttpHeader * hdr_out, - int cfd, - http_state_flags flags) + StoreEntry * entry, HttpHeader * hdr_out, int cfd, http_state_flags flags) { /* building buffer for complex strings */ #define BBUF_SZ (MAX_URL+32) @@ -769,7 +770,8 @@ debug(11, 5) ("httpBuildRequestHeader: %s: %s\n", strBuf(e->name), strBuf(e->value)); if (!httpRequestHdrAllowed(e, &strConnection)) { - debug(11, 2) ("'%s' header denied by anonymize_headers configuration\n", + debug(11, + 2) ("'%s' header denied by anonymize_headers configuration\n", strBuf(e->name)); continue; } @@ -839,8 +841,7 @@ /* append Via */ strVia = httpHeaderGetList(hdr_in, HDR_VIA); snprintf(bbuf, BBUF_SZ, "%d.%d %s", - orig_request->http_ver.major, - orig_request->http_ver.minor, ThisCache); + orig_request->http_ver.major, orig_request->http_ver.minor, ThisCache); strListAdd(&strVia, bbuf, ','); httpHeaderPutStr(hdr_out, HDR_VIA, strBuf(strVia)); stringClean(&strVia); @@ -849,7 +850,7 @@ /* Append Surrogate-Capabilities */ strVia = httpHeaderGetList(hdr_in, HDR_SURROGATE_CAPABILITY); snprintf(bbuf, BBUF_SZ, "%s=Surrogate/1.0 ESI/1.0", - Config.Accel.surrogate_id); + Config.Accel.surrogate_id); strListAdd(&strVia, bbuf, ','); httpHeaderPutStr(hdr_out, HDR_SURROGATE_CAPABILITY, strBuf(strVia)); stringClean(&strVia); @@ -887,8 +888,11 @@ char loginbuf[256]; const char *username = "-"; if (orig_request->auth_user_request) - username = authenticateUserRequestUsername(orig_request->auth_user_request); - snprintf(loginbuf, sizeof(loginbuf), "%s%s", username, orig_request->peer_login + 1); + username = + authenticateUserRequestUsername(orig_request-> + auth_user_request); + snprintf(loginbuf, sizeof(loginbuf), "%s%s", username, + orig_request->peer_login + 1); httpHeaderPutStrf(hdr_out, HDR_PROXY_AUTHORIZATION, "Basic %s", base64_encode(loginbuf)); } else { @@ -902,7 +906,8 @@ if (!cc) cc = httpHdrCcCreate(); if (!EBIT_TEST(cc->mask, CC_MAX_AGE)) { - const char *url = entry ? storeUrl(entry) : urlCanonical(orig_request); + const char *url = + entry ? storeUrl(entry) : urlCanonical(orig_request); httpHdrCcSetMaxAge(cc, getMaxAge(url)); if (strLen(request->urlpath)) assert(strstr(url, strBuf(request->urlpath))); @@ -930,10 +935,7 @@ mb_size_t httpBuildRequestPrefix(request_t * request, request_t * orig_request, - StoreEntry * entry, - MemBuf * mb, - int cfd, - http_state_flags flags) + StoreEntry * entry, MemBuf * mb, int cfd, http_state_flags flags) { const int offset = mb->size; memBufPrintf(mb, "%s %s HTTP/1.0\r\n", @@ -953,6 +955,7 @@ memBufAppend(mb, crlf, 2); return mb->size - offset; } + /* This will be called when connect completes. Write request. */ static void httpSendRequest(HttpStateData * httpState) @@ -964,7 +967,8 @@ peer *p = httpState->peer; CWCB *sendHeaderDone; - debug(11, 5) ("httpSendRequest: FD %d: httpState %p.\n", httpState->fd, httpState); + debug(11, 5) ("httpSendRequest: FD %d: httpState %p.\n", httpState->fd, + httpState); if (httpState->orig_request->body_connection) sendHeaderDone = httpSendRequestEntity; @@ -991,7 +995,8 @@ httpState->flags.keepalive = 1; else if (p->stats.n_keepalives_sent < 10) httpState->flags.keepalive = 1; - else if ((double) p->stats.n_keepalives_recv / (double) p->stats.n_keepalives_sent > 0.50) + else if ((double) p->stats.n_keepalives_recv / + (double) p->stats.n_keepalives_sent > 0.50) httpState->flags.keepalive = 1; if (httpState->peer) if (neighborType(httpState->peer, httpState->request) == PEER_SIBLING && @@ -999,11 +1004,7 @@ httpState->flags.only_if_cached = 1; memBufDefInit(&mb); httpBuildRequestPrefix(req, - httpState->orig_request, - entry, - &mb, - cfd, - httpState->flags); + httpState->orig_request, entry, &mb, cfd, httpState->flags); debug(11, 6) ("httpSendRequest: FD %d:\n%s\n", httpState->fd, mb.buf); comm_write_mbuf(httpState->fd, mb, sendHeaderDone, httpState); } @@ -1016,8 +1017,7 @@ request_t *proxy_req; request_t *orig_req = fwd->request; debug(11, 3) ("httpStart: \"%s %s\"\n", - RequestMethodStr[orig_req->method], - storeUrl(fwd->entry)); + RequestMethodStr[orig_req->method], storeUrl(fwd->entry)); httpState = cbdataAlloc(HttpStateData); storeLockObject(fwd->entry); httpState->fwd = fwd; @@ -1070,8 +1070,7 @@ { HttpStateData *httpState = data; aclCheck_t ch; - debug(11, 5) ("httpSendRequestEntityDone: FD %d\n", - fd); + debug(11, 5) ("httpSendRequestEntityDone: FD %d\n", fd); memset(&ch, '\0', sizeof(ch)); ch.request = httpState->request; if (!Config.accessList.brokenPosts) { @@ -1091,7 +1090,8 @@ { HttpStateData *httpState = (HttpStateData *) data; if (size > 0) { - comm_write(httpState->fd, buf, size, httpSendRequestEntity, data, memFree8K); + comm_write(httpState->fd, buf, size, httpSendRequestEntity, data, + memFree8K); } else if (size == 0) { /* End of body */ memFree8K(buf); @@ -1104,7 +1104,8 @@ } static void -httpSendRequestEntity(int fd, char *bufnotused, size_t size, int errflag, void *data) +httpSendRequestEntity(int fd, char *bufnotused, size_t size, int errflag, + void *data) { HttpStateData *httpState = data; StoreEntry *entry = httpState->entry; @@ -1130,11 +1131,13 @@ comm_close(fd); return; } - clientReadBody(httpState->orig_request, memAllocate(MEM_8K_BUF), 8192, httpRequestBodyHandler, httpState); + clientReadBody(httpState->orig_request, memAllocate(MEM_8K_BUF), 8192, + httpRequestBodyHandler, httpState); } void -httpBuildVersion(http_version_t * version, unsigned int major, unsigned int minor) +httpBuildVersion(http_version_t * version, unsigned int major, + unsigned int minor) { version->major = major; version->minor = minor;