From: adrian <> Date: Tue, 26 Sep 2006 19:30:09 +0000 (+0000) Subject: Do some small changes to the HTTP parser and client side code to (eventually) save... X-Git-Tag: SQUID_3_0_PRE5~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=666f514b0b99b05f6b8dce995844946dbacc9426;p=thirdparty%2Fsquid.git Do some small changes to the HTTP parser and client side code to (eventually) save on strlen() and similar calls --- diff --git a/src/HttpMsg.cc b/src/HttpMsg.cc index 070855121d..20e720ab32 100644 --- a/src/HttpMsg.cc +++ b/src/HttpMsg.cc @@ -1,6 +1,6 @@ /* - * $Id: HttpMsg.cc,v 1.31 2006/09/20 11:38:14 adrian Exp $ + * $Id: HttpMsg.cc,v 1.32 2006/09/26 13:30:09 adrian Exp $ * * DEBUG: section 74 HTTP Message * AUTHOR: Alex Rousskov @@ -56,13 +56,12 @@ HttpMsgParseState &operator++ (HttpMsgParseState &aState) /* find end of headers */ int -httpMsgIsolateHeaders(const char **parse_start, const char **blk_start, const char **blk_end) +httpMsgIsolateHeaders(const char **parse_start, int l, const char **blk_start, const char **blk_end) { /* * parse_start points to the first line of HTTP message *headers*, * not including the request or status lines */ - size_t l = strlen(*parse_start); size_t end = headersEnd(*parse_start, l); int nnl; @@ -177,7 +176,7 @@ bool HttpMsg::parse(MemBuf *buf, bool eof, http_status *error) return false; } - const int res = httpMsgParseStep(buf->content(), eof); + const int res = httpMsgParseStep(buf->content(), buf->contentSize(), eof); if (res < 0) { // error debugs(58, 3, "HttpMsg::parse: cannot parse isolated headers " << @@ -223,7 +222,7 @@ HttpMsg::parseCharBuf(const char *buf, ssize_t end) mb.init(); mb.append(buf, end); mb.terminate(); - success = httpMsgParseStep(mb.buf, 0); + success = httpMsgParseStep(mb.buf, mb.size, 0); mb.clean(); return success == 1; } @@ -236,9 +235,10 @@ HttpMsg::parseCharBuf(const char *buf, ssize_t end) * -1 -- parse error */ int -HttpMsg::httpMsgParseStep(const char *buf, int atEnd) +HttpMsg::httpMsgParseStep(const char *buf, int len, int atEnd) { const char *parse_start = buf; + int parse_len = len; const char *blk_start, *blk_end; const char **parse_end_ptr = &blk_end; assert(parse_start); @@ -263,12 +263,18 @@ HttpMsg::httpMsgParseStep(const char *buf, int atEnd) *parse_end_ptr = parse_start; hdr_sz = *parse_end_ptr - buf; + parse_len = parse_len - hdr_sz; ++pstate; } + /* + * XXX This code uses parse_start; but if we're incrementally parsing then + * this code might not actually be given parse_start at the right spot (just + * after headers.) Grr. + */ if (pstate == psReadyToParseHeaders) { - if (!httpMsgIsolateHeaders(&parse_start, &blk_start, &blk_end)) { + if (!httpMsgIsolateHeaders(&parse_start, parse_len, &blk_start, &blk_end)) { if (atEnd) { blk_start = parse_start, blk_end = blk_start + strlen(blk_start); } else { diff --git a/src/HttpMsg.h b/src/HttpMsg.h index 44d7af5fc1..1ddf444d1b 100644 --- a/src/HttpMsg.h +++ b/src/HttpMsg.h @@ -1,6 +1,6 @@ /* - * $Id: HttpMsg.h,v 1.9 2006/04/18 12:25:50 robertc Exp $ + * $Id: HttpMsg.h,v 1.10 2006/09/26 13:30:09 adrian Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -79,7 +79,7 @@ public: bool parseCharBuf(const char *buf, ssize_t end); - int httpMsgParseStep(const char *buf, int atEnd); + int httpMsgParseStep(const char *buf, int len, int atEnd); virtual int httpMsgParseError(); @@ -101,7 +101,7 @@ protected: }; -SQUIDCEXTERN int httpMsgIsolateHeaders(const char **parse_start, const char **blk_start, const char **blk_end); +SQUIDCEXTERN int httpMsgIsolateHeaders(const char **parse_start, int len, const char **blk_start, const char **blk_end); #define HTTPMSGUNLOCK(a) if(a){(a)->_unlock();(a)=NULL;} #define HTTPMSGLOCK(a) (a)->_lock() diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index afa7703236..b8d23f2234 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -1,6 +1,6 @@ /* - * $Id: HttpRequest.cc,v 1.67 2006/05/29 21:44:18 robertc Exp $ + * $Id: HttpRequest.cc,v 1.68 2006/09/26 13:30:09 adrian Exp $ * * DEBUG: section 73 HTTP Request * AUTHOR: Duane Wessels @@ -208,11 +208,11 @@ HttpRequest::parseFirstLine(const char *start, const char *end) } int -HttpRequest::parseHeader(const char *parse_start) +HttpRequest::parseHeader(const char *parse_start, int len) { const char *blk_start, *blk_end; - if (!httpMsgIsolateHeaders(&parse_start, &blk_start, &blk_end)) + if (!httpMsgIsolateHeaders(&parse_start, len, &blk_start, &blk_end)) return 0; int result = header.parse(blk_start, blk_end); diff --git a/src/HttpRequest.h b/src/HttpRequest.h index 7327fdd294..9fd3e6c3d3 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -1,6 +1,6 @@ /* - * $Id: HttpRequest.h,v 1.23 2006/05/29 21:44:18 robertc Exp $ + * $Id: HttpRequest.h,v 1.24 2006/09/26 13:30:09 adrian Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -136,7 +136,7 @@ public: bool parseFirstLine(const char *start, const char *end); - int parseHeader(const char *parse_start); + int parseHeader(const char *parse_start, int len); virtual bool expectingBody(method_t unused, ssize_t&) const; diff --git a/src/client_side.cc b/src/client_side.cc index fa403dbd3e..033ca00705 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.736 2006/09/25 15:04:06 adrian Exp $ + * $Id: client_side.cc,v 1.737 2006/09/26 13:30:09 adrian Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -2286,7 +2286,8 @@ clientProcessRequest(ConnStateData::Pointer &conn, ClientSocketContext *context, /* compile headers */ /* we should skip request line! */ - if (!request->parseHeader(prefix + req_line_sz)) { + /* XXX should actually know the damned buffer size here */ + if (!request->parseHeader(prefix + req_line_sz, strlen(prefix + req_line_sz))) { clientStreamNode *node = context->getClientReplyContext(); debug(33, 5) ("Failed to parse request headers:\n%s\n", prefix); clientReplyContext *repContext = dynamic_cast(node->data.getRaw());