]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Default constructor for HttpParser
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 31 Mar 2011 22:47:06 +0000 (16:47 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 31 Mar 2011 22:47:06 +0000 (16:47 -0600)
rev11314 added an no-op default constructor. But that could allow creation
with broken state.

Add a clear() function to perform the default constructor initialization.
That can also be shared by the other init code.

src/HttpMsg.cc
src/HttpMsg.h

index 7f1db0176f41d8cb68893925fcefb67e40c7542d..874a1a3221db9884bcb27eb5b14b7b167124c82a 100644 (file)
@@ -379,17 +379,11 @@ HttpMsg::_unlock()
 void
 HttpParserInit(HttpParser *hdr, const char *buf, int bufsiz)
 {
+    hdr->clear();
     hdr->state = 1;
-    hdr->request_parse_status = HTTP_STATUS_NONE;
     hdr->buf = buf;
     hdr->bufsiz = bufsiz;
-    hdr->req_start = hdr->req_end = -1;
-    hdr->hdr_start = hdr->hdr_end = -1;
     debugs(74, 5, "httpParseInit: Request buffer is " << buf);
-    hdr->m_start = hdr->m_end = -1;
-    hdr->u_start = hdr->u_end = -1;
-    hdr->v_start = hdr->v_end = -1;
-    hdr->v_maj = hdr->v_min = 0;
 }
 
 #if MSGDODEBUG
@@ -439,6 +433,21 @@ HttpParser::HttpParser(const char *buf, int len)
     HttpParserInit(this, buf, len);
 }
 
+void
+HttpParser::clear()
+{
+    state = 0;
+    request_parse_status = HTTP_STATUS_NONE;
+    buf = NULL; // NP: we do not own the buffer, merely reference to it.
+    bufsiz = 0;
+    req_start = req_end = -1;
+    hdr_start = hdr_end = -1;
+    m_start = m_end = -1;
+    u_start = u_end = -1;
+    v_start = v_end = -1;
+    v_maj = v_min = 0;
+}
+
 int
 HttpParser::parseRequestFirstLine()
 {
index 72a932473c8f2511ef06fdf565924932b5f671a8..37f1307f0fb01fcf9e9ef9e72601819ff6f38c35 100644 (file)
@@ -136,9 +136,13 @@ protected:
 class HttpParser
 {
 public:
-    HttpParser() {};
+    HttpParser() { clear(); }
     HttpParser(const char *buf, int len);
 
+    /// Set this parser back to a default state.
+    /// Will DROP any reference to a buffer (does not free).
+    void clear();
+
     /**
      * Attempt to parse the first line of a new request message.
      *