]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Do some small changes to the HTTP parser and client side code to (eventually) save...
authoradrian <>
Tue, 26 Sep 2006 19:30:09 +0000 (19:30 +0000)
committeradrian <>
Tue, 26 Sep 2006 19:30:09 +0000 (19:30 +0000)
src/HttpMsg.cc
src/HttpMsg.h
src/HttpRequest.cc
src/HttpRequest.h
src/client_side.cc

index 070855121d4d8189b2e2f99631118ea46e545c62..20e720ab32a2085f9c3d97ccd0eb7200a1827833 100644 (file)
@@ -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 {
index 44d7af5fc1493288f7f26a78c4b861fa56716ce5..1ddf444d1b6e41798fce993d096737419fc802f8 100644 (file)
@@ -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()
index afa77032360caa4da0b6f1c8e9d40161628d6cec..b8d23f2234064e269e168bb5bc171a311de89b8d 100644 (file)
@@ -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);
index 7327fdd294b5a4665d1bae3f3b214cbf08cadbc4..9fd3e6c3d3c51ab9d5c6123984f3e4bec187d734 100644 (file)
@@ -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;
 
index fa403dbd3edaf9113dbbb551dbc566ae3844384d..033ca00705942a6f5095570b30774829b5b7c8d6 100644 (file)
@@ -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<clientReplyContext *>(node->data.getRaw());