--------------------- PatchSet 10419 Date: 2008/01/20 10:26:03 Author: adri Branch: s27_adri Tag: (none) Log: Use the buf_t buffer in the client-side code to parse headers into reference-counted string buffers. Members: src/HttpMsg.c:1.12.12.3->1.12.12.4 src/client_side.c:1.202.2.9.4.43->1.202.2.9.4.44 src/protos.h:1.146.2.4.4.39->1.146.2.4.4.40 Index: squid/src/HttpMsg.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/HttpMsg.c,v retrieving revision 1.12.12.3 retrieving revision 1.12.12.4 diff -u -r1.12.12.3 -r1.12.12.4 --- squid/src/HttpMsg.c 20 Jan 2008 01:22:28 -0000 1.12.12.3 +++ squid/src/HttpMsg.c 20 Jan 2008 10:26:05 -0000 1.12.12.4 @@ -1,6 +1,6 @@ /* - * $Id: HttpMsg.c,v 1.12.12.3 2008/01/20 01:22:28 adri Exp $ + * $Id: HttpMsg.c,v 1.12.12.4 2008/01/20 10:26:05 adri Exp $ * * DEBUG: section 74 HTTP Message * AUTHOR: Alex Rousskov @@ -44,6 +44,13 @@ return httpHeaderParse(&req->header, s, e); } +int +httpMsgParseRequestHeaderBuf(request_t *req, HttpMsgBuf *hmsg) +{ + return httpHeaderParseBuf(&req->header, hmsg->nb, hmsg->h_start); +} + + /* find end of headers */ int httpMsgIsolateHeaders(const char **parse_start, int l, const char **blk_start, const char **blk_end) @@ -128,9 +135,12 @@ /* Adrian's replacement message buffer code to parse the request/reply line */ void -HttpMsgBufInit(HttpMsgBuf * hmsg, const char *buf, int offset, size_t size) +HttpMsgBufInit(HttpMsgBuf * hmsg, buf_t *buf, int offset, size_t size) { - hmsg->buf = buf; + assert(offset <= buf_len(buf)); + assert(size <= buf_len(buf)); + hmsg->nb = buf_ref(buf); + hmsg->buf = buf_buf(hmsg->nb); hmsg->size = size; hmsg->req_start = hmsg->req_end = -1; hmsg->h_start = hmsg->h_end = -1; @@ -141,7 +151,7 @@ void httpMsgBufDone(HttpMsgBuf * hmsg) { - (void) 0; + hmsg->nb = buf_deref(hmsg->nb); } Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.202.2.9.4.43 retrieving revision 1.202.2.9.4.44 diff -u -r1.202.2.9.4.43 -r1.202.2.9.4.44 --- squid/src/client_side.c 20 Jan 2008 01:22:29 -0000 1.202.2.9.4.43 +++ squid/src/client_side.c 20 Jan 2008 10:26:03 -0000 1.202.2.9.4.44 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.202.2.9.4.43 2008/01/20 01:22:29 adri Exp $ + * $Id: client_side.c,v 1.202.2.9.4.44 2008/01/20 10:26:03 adri Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -4004,7 +4004,7 @@ * <0 : error; stop parsing */ static int -clientTryParseRequest(ConnStateData * conn, int *cbytes, clientHttpRequest **chttp, const char *sbuf, int slen) +clientTryParseRequest(ConnStateData * conn, int *cbytes, clientHttpRequest **chttp, buf_t *b, int offset, int len) { int fd = conn->fd; int nrequests; @@ -4017,13 +4017,10 @@ HttpMsgBuf msg; int ret = -1; - const char *buf = sbuf; - int len = slen; - *chttp = NULL; *cbytes = 0; - HttpMsgBufInit(&msg, buf, 0, len); + HttpMsgBufInit(&msg, b, 0, len); /* Limit the number of concurrent requests to 2 */ for (n = conn->reqs.head, nrequests = 0; n; n = n->next, nrequests++); if (nrequests >= (Config.onoff.pipeline_prefetch ? 2 : 1)) { @@ -4073,7 +4070,7 @@ debug(33, 1) ("clientReadRequest: FD %d (%s:%d) Invalid Request\n", fd, fd_table[fd].ipaddr, fd_table[fd].remote_port); err = errorCon(ERR_INVALID_REQ, HTTP_BAD_REQUEST, NULL); err->src_addr = conn->peer.sin_addr; - err->request_hdrs = xstrndup(buf, len); + err->request_hdrs = xstrndup(buf_buf(b) + offset, buf_len(b) - offset); http->log_type = LOG_TCP_DENIED; http->entry = clientCreateStoreEntry(http, method, null_request_flags); errorAppendEntry(http->entry, err); @@ -4092,7 +4089,7 @@ } /* compile headers */ /* we should skip request line! */ - if ((http->http_ver.major >= 1) && !httpMsgParseRequestHeader(request, &msg)) { + if ((http->http_ver.major >= 1) && !httpMsgParseRequestHeaderBuf(request, &msg)) { debug(33, 1) ("Failed to parse request headers: %s\n%s\n", http->uri, msg.buf + msg.req_end); err = errorCon(ERR_INVALID_URL, HTTP_BAD_REQUEST, request); @@ -4296,7 +4293,7 @@ ret = 0; break; } - ret = clientTryParseRequest(conn, &cbytes, &chttp, clientConnBuf(&conn->in), clientConnBufLen(&conn->in)); + ret = clientTryParseRequest(conn, &cbytes, &chttp, conn->in.inbuf, 0, clientConnBufLen(&conn->in)); if (cbytes > 0) { /* If we read past the end of this request, move the remaining data to the beginning */ Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.146.2.4.4.39 retrieving revision 1.146.2.4.4.40 diff -u -r1.146.2.4.4.39 -r1.146.2.4.4.40 --- squid/src/protos.h 20 Jan 2008 01:22:29 -0000 1.146.2.4.4.39 +++ squid/src/protos.h 20 Jan 2008 10:26:05 -0000 1.146.2.4.4.40 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.146.2.4.4.39 2008/01/20 01:22:29 adri Exp $ + * $Id: protos.h,v 1.146.2.4.4.40 2008/01/20 10:26:05 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1407,10 +1407,11 @@ vary_id_t storeAddVary(const char *url, const method_t method, const cache_key * key, String *etag, String *vary, String *vary_headers, String *accept_encoding); /* New HTTP message parsing support */ -extern void HttpMsgBufInit(HttpMsgBuf * hmsg, const char *buf, int offset, size_t size); +extern void HttpMsgBufInit(HttpMsgBuf * hmsg, buf_t *buf, int offset, size_t size); extern void httpMsgBufDone(HttpMsgBuf * hmsg); extern int httpMsgParseRequestLine(HttpMsgBuf * hmsg); extern int httpMsgParseRequestHeader(request_t * req, HttpMsgBuf * hmsg); +extern int httpMsgParseRequestHeaderBuf(request_t *req, HttpMsgBuf *hmsg); extern int httpMsgFindHeadersEnd(HttpMsgBuf * hmsg); extern const char *xinet_ntoa(const struct in_addr addr);