]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Polish: class file shuffling for guidelines
authorAmos Jeffries <squid3@treenet.co.nz>
Tue, 20 May 2014 10:21:14 +0000 (03:21 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 20 May 2014 10:21:14 +0000 (03:21 -0700)
12 files changed:
configure.ac
src/HttpRequest.cc
src/client_side.cc
src/http/Makefile.am
src/http/forward.h
src/http/one/Makefile.am [new file with mode: 0644]
src/http/one/Parser.cc [new file with mode: 0644]
src/http/one/Parser.h [moved from src/http/Http1Parser.h with 60% similarity]
src/http/one/RequestParser.cc [moved from src/http/Http1Parser.cc with 90% similarity]
src/http/one/RequestParser.h [new file with mode: 0644]
src/http/one/forward.h [new file with mode: 0644]
src/tests/testHttp1Parser.cc

index 3dfa4cb162e622f243f9800866e9ceafa90a7248..31187c6f9406e651fd02cd79889ef36058072802 100644 (file)
@@ -3460,6 +3460,7 @@ AC_CONFIG_FILES([
        src/eui/Makefile
        src/format/Makefile
        src/http/Makefile
+       src/http/one/Makefile
        src/icmp/Makefile
        src/ident/Makefile
        src/ip/Makefile
index 6ceeeb63da9f7b7558e0d382320f9f0e7b939ebf..1640473b93b4c2ab9a06562446c7837b72fdd748 100644 (file)
@@ -41,7 +41,7 @@
 #include "globals.h"
 #include "gopher.h"
 #include "http.h"
-#include "http/Http1Parser.h"
+#include "http/one/RequestParser.h"
 #include "HttpHdrCc.h"
 #include "HttpHeaderRange.h"
 #include "HttpRequest.h"
index 7ee97a8fd395d88996f9bcc4044e3dc3bda98f9c..95aeef8095411352d06b8c108ec93447015ba2b6 100644 (file)
 #include "FwdState.h"
 #include "globals.h"
 #include "http.h"
-#include "http/Http1Parser.h"
+#include "http/one/RequestParser.h"
 #include "HttpHdrContRange.h"
 #include "HttpHeaderTools.h"
 #include "HttpReply.h"
index 0d6573136facf365b72d3ed3c97306d8a1b9ad64..bb603342731472810c5e26d69d5e08980d3e5e80 100644 (file)
@@ -1,12 +1,15 @@
 include $(top_srcdir)/src/Common.am
 include $(top_srcdir)/src/TestHeaders.am
 
+AUTOMAKE_OPTIONS = subdir-objects
+
+SUBDIRS = one
+DIST_SUBDIRS = one
+
 noinst_LTLIBRARIES = libsquid-http.la
 
 libsquid_http_la_SOURCES = \
        forward.h \
-       Http1Parser.cc \
-       Http1Parser.h \
        MethodType.cc \
        MethodType.h \
        ProtocolVersion.h \
@@ -18,6 +21,8 @@ libsquid_http_la_SOURCES = \
        StatusLine.cc \
        StatusLine.h
 
+libsquid_http_la_LIBADD= one/libhttp1.la
+
 MethodType.cc: MethodType.h $(top_srcdir)/src/mk-string-arrays.awk
        ($(AWK) -f $(top_srcdir)/src/mk-string-arrays.awk sbuf=1 < $(srcdir)/MethodType.h | \
                sed -e 's%METHOD_%%' -e 's%_C%-C%' >$@) || ($(RM) -f $@ && exit 1)
index adee4c3e85823c6a9eb4d9ba7f3b12fb61443a6b..3ae78ba0e353715e9194d8e9b4240aebf1d99c7d 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef SQUID_SRC_HTTP_FORWARD_H
 #define SQUID_SRC_HTTP_FORWARD_H
 
-#include "base/RefCount.h"
+#include "http/one/forward.h"
 
 // TODO move these classes into Http namespace
 class HttpRequestMethod;
@@ -13,15 +13,4 @@ typedef RefCount<HttpRequest> HttpRequestPointer;
 class HttpReply;
 typedef RefCount<HttpReply> HttpReplyPointer;
 
-namespace Http {
-
-namespace One {
-class RequestParser;
-typedef RefCount<Http::One::RequestParser> RequestParserPointer;
-} // namespace One
-
-} // namespace Http
-
-namespace Http1 = Http::One;
-
 #endif /* SQUID_SRC_HTTP_FORWARD_H */
diff --git a/src/http/one/Makefile.am b/src/http/one/Makefile.am
new file mode 100644 (file)
index 0000000..17ac590
--- /dev/null
@@ -0,0 +1,11 @@
+include $(top_srcdir)/src/Common.am
+include $(top_srcdir)/src/TestHeaders.am
+
+noinst_LTLIBRARIES = libhttp1.la
+
+libhttp1_la_SOURCES = \
+       forward.h \
+       Parser.cc \
+       Parser.h \
+       RequestParser.cc \
+       RequestParser.h
diff --git a/src/http/one/Parser.cc b/src/http/one/Parser.cc
new file mode 100644 (file)
index 0000000..3b2fd19
--- /dev/null
@@ -0,0 +1,75 @@
+#include "squid.h"
+#include "Debug.h"
+#include "http/one/Parser.h"
+
+void
+Http::One::Parser::clear()
+{
+    parsingStage_ = HTTP_PARSE_NONE;
+    buf = NULL;
+    parsedCount_ = 0;
+    msgProtocol_ = AnyP::ProtocolVersion();
+    mimeHeaderBlock_.clear();
+}
+
+// arbitrary maximum-length for headers which can be found by Http1Parser::getHeaderField()
+#define GET_HDR_SZ     1024
+
+char *
+Http::One::Parser::getHeaderField(const char *name)
+{
+    LOCAL_ARRAY(char, header, GET_HDR_SZ);
+    const char *p = NULL;
+    char *q = NULL;
+    char got = 0;
+    const int namelen = name ? strlen(name) : 0;
+
+    if (!headerBlockSize() || !name)
+        return NULL;
+
+    debugs(25, 5, "looking for '" << name << "'");
+
+    for (p = mimeHeader().c_str(); *p; p += strcspn(p, "\n\r")) {
+        if (strcmp(p, "\r\n\r\n") == 0 || strcmp(p, "\n\n") == 0)
+            return NULL;
+
+        while (xisspace(*p))
+            ++p;
+
+        if (strncasecmp(p, name, namelen))
+            continue;
+
+        if (!xisspace(p[namelen]) && p[namelen] != ':')
+            continue;
+
+        int l = strcspn(p, "\n\r") + 1;
+
+        if (l > GET_HDR_SZ)
+            l = GET_HDR_SZ;
+
+        xstrncpy(header, p, l);
+
+        debugs(25, 5, "checking '" << header << "'");
+
+        q = header;
+
+        q += namelen;
+
+        if (*q == ':') {
+            ++q;
+            got = 1;
+        }
+
+        while (xisspace(*q)) {
+            ++q;
+            got = 1;
+        }
+
+        if (got) {
+            debugs(25, 5, "returning '" << q << "'");
+            return q;
+        }
+    }
+
+    return NULL;
+}
similarity index 60%
rename from src/http/Http1Parser.h
rename to src/http/one/Parser.h
index c75774eddbaefd1076da7b46805e1d52941b2fca..98ec0b4270bf8de0291c9224cb22768bfbb528b9 100644 (file)
@@ -1,11 +1,8 @@
 #ifndef _SQUID_SRC_HTTP_ONEREQUESTPARSER_H
 #define _SQUID_SRC_HTTP_ONEREQUESTPARSER_H
 
-#include "base/RefCount.h"
-#include "http/forward.h"
-#include "http/ProtocolVersion.h"
-#include "http/RequestMethod.h"
-#include "http/StatusCode.h"
+#include "anyp/ProtocolVersion.h"
+#include "http/one/forward.h"
 #include "SBuf.h"
 
 namespace Http {
@@ -29,7 +26,7 @@ enum ParseState {
  */
 class Parser : public RefCountable
 {
-    Parser(const Parser&); // do not implement
+    explicit Parser(const Parser&); // do not implement
     Parser& operator =(const Parser&); // do not implement
 
 public:
@@ -91,59 +88,6 @@ protected:
     SBuf mimeHeaderBlock_;
 };
 
-/** HTTP/1.x protocol request parser
- *
- * Works on a raw character I/O buffer and tokenizes the content into
- * the major CRLF delimited segments of an HTTP/1 request message:
- *
- * \item request-line (method, URL, protocol, version)
- * \item mime-header (set of RFC2616 syntax header fields)
- */
-class RequestParser : public Http1::Parser
-{
-    RequestParser(const RequestParser&); // do not implement
-    RequestParser& operator =(const RequestParser&); // do not implement
-
-public:
-    /* Http::One::Parser API */
-    RequestParser() : Parser() {}
-    virtual ~RequestParser() {}
-    virtual void clear();
-    virtual int64_t firstLineSize() const {return req.end - req.start + 1;}
-    virtual bool parse(const SBuf &aBuf);
-
-    /// the HTTP method if this is a request message
-    const HttpRequestMethod & method() const {return method_;}
-
-    /// the request-line URI if this is a request message, or an empty string.
-    const SBuf &requestUri() const {return uri_;}
-
-    /** HTTP status code to be used on the invalid-request error page.
-     * Http::scNone indicates incomplete parse,
-     * Http::scOkay indicates no error.
-     */
-    Http::StatusCode request_parse_status;
-
-private:
-    void skipGarbageLines();
-    int parseRequestFirstLine();
-
-    /// Offsets for pieces of the (HTTP request) Request-Line as per RFC 2616
-    /// only valid before and during parse stage HTTP_PARSE_FIRST
-    struct request_offsets {
-        int start, end;
-        int m_start, m_end; // method
-        int u_start, u_end; // url
-        int v_start, v_end; // version (full text)
-    } req;
-
-    /// what request method has been found on the first line
-    HttpRequestMethod method_;
-
-    /// raw copy of the origina client reqeust-line URI field
-    SBuf uri_;
-};
-
 } // namespace One
 } // namespace Http
 
similarity index 90%
rename from src/http/Http1Parser.cc
rename to src/http/one/RequestParser.cc
index 4fd2b7a17c26600065bca66b8ca70acef7ff87d5..e5ecd1665daaaad3ab0c59fc77fe4ef7bd063b26 100644 (file)
@@ -1,21 +1,11 @@
 #include "squid.h"
 #include "Debug.h"
-#include "http/Http1Parser.h"
-#include "http/RequestMethod.h"
+#include "http/one/RequestParser.h"
+#include "http/ProtocolVersion.h"
 #include "mime_header.h"
 #include "profiler/Profiler.h"
 #include "SquidConfig.h"
 
-void
-Http::One::Parser::clear()
-{
-    parsingStage_ = HTTP_PARSE_NONE;
-    buf = NULL;
-    parsedCount_ = 0;
-    msgProtocol_ = AnyP::ProtocolVersion();
-    mimeHeaderBlock_.clear();
-}
-
 void
 Http::One::RequestParser::clear()
 {
@@ -412,65 +402,3 @@ Http::One::RequestParser::parse(const SBuf &aBuf)
 
     return !needsMoreData();
 }
-
-// arbitrary maximum-length for headers which can be found by Http1Parser::getHeaderField()
-#define GET_HDR_SZ     1024
-
-char *
-Http::One::Parser::getHeaderField(const char *name)
-{
-    LOCAL_ARRAY(char, header, GET_HDR_SZ);
-    const char *p = NULL;
-    char *q = NULL;
-    char got = 0;
-    const int namelen = name ? strlen(name) : 0;
-
-    if (!headerBlockSize() || !name)
-        return NULL;
-
-    debugs(25, 5, "looking for '" << name << "'");
-
-    for (p = mimeHeader().c_str(); *p; p += strcspn(p, "\n\r")) {
-        if (strcmp(p, "\r\n\r\n") == 0 || strcmp(p, "\n\n") == 0)
-            return NULL;
-
-        while (xisspace(*p))
-            ++p;
-
-        if (strncasecmp(p, name, namelen))
-            continue;
-
-        if (!xisspace(p[namelen]) && p[namelen] != ':')
-            continue;
-
-        int l = strcspn(p, "\n\r") + 1;
-
-        if (l > GET_HDR_SZ)
-            l = GET_HDR_SZ;
-
-        xstrncpy(header, p, l);
-
-        debugs(25, 5, "checking '" << header << "'");
-
-        q = header;
-
-        q += namelen;
-
-        if (*q == ':') {
-            ++q;
-            got = 1;
-        }
-
-        while (xisspace(*q)) {
-            ++q;
-            got = 1;
-        }
-
-        if (got) {
-            debugs(25, 5, "returning '" << q << "'");
-            return q;
-        }
-    }
-
-    return NULL;
-}
diff --git a/src/http/one/RequestParser.h b/src/http/one/RequestParser.h
new file mode 100644 (file)
index 0000000..c2da507
--- /dev/null
@@ -0,0 +1,67 @@
+#ifndef _SQUID_SRC_HTTP_ONE_REQUESTPARSER_H
+#define _SQUID_SRC_HTTP_ONE_REQUESTPARSER_H
+
+#include "http/one/Parser.h"
+#include "http/RequestMethod.h"
+#include "http/StatusCode.h"
+
+namespace Http {
+namespace One {
+
+/** HTTP/1.x protocol request parser
+ *
+ * Works on a raw character I/O buffer and tokenizes the content into
+ * the major CRLF delimited segments of an HTTP/1 request message:
+ *
+ * \item request-line (method, URL, protocol, version)
+ * \item mime-header (set of RFC2616 syntax header fields)
+ */
+class RequestParser : public Http1::Parser
+{
+    explicit RequestParser(const RequestParser&); // do not implement
+    RequestParser& operator =(const RequestParser&); // do not implement
+
+public:
+    /* Http::One::Parser API */
+    RequestParser() : Parser() {}
+    virtual ~RequestParser() {}
+    virtual void clear();
+    virtual int64_t firstLineSize() const {return req.end - req.start + 1;}
+    virtual bool parse(const SBuf &aBuf);
+
+    /// the HTTP method if this is a request message
+    const HttpRequestMethod & method() const {return method_;}
+
+    /// the request-line URI if this is a request message, or an empty string.
+    const SBuf &requestUri() const {return uri_;}
+
+    /** HTTP status code to be used on the invalid-request error page.
+     * Http::scNone indicates incomplete parse,
+     * Http::scOkay indicates no error.
+     */
+    Http::StatusCode request_parse_status;
+
+private:
+    void skipGarbageLines();
+    int parseRequestFirstLine();
+
+    /// Offsets for pieces of the (HTTP request) Request-Line as per RFC 2616
+    /// only valid before and during parse stage HTTP_PARSE_FIRST
+    struct request_offsets {
+        int start, end;
+        int m_start, m_end; // method
+        int u_start, u_end; // url
+        int v_start, v_end; // version (full text)
+    } req;
+
+    /// what request method has been found on the first line
+    HttpRequestMethod method_;
+
+    /// raw copy of the origina client reqeust-line URI field
+    SBuf uri_;
+};
+
+} // namespace One
+} // namespace Http
+
+#endif /*  _SQUID_SRC_HTTP_ONE_REQUESTPARSER_H */
diff --git a/src/http/one/forward.h b/src/http/one/forward.h
new file mode 100644 (file)
index 0000000..b3e6c11
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef SQUID_SRC_HTTP_ONE_FORWARD_H
+#define SQUID_SRC_HTTP_ONE_FORWARD_H
+
+#include "base/RefCount.h"
+
+namespace Http {
+namespace One {
+
+class RequestParser;
+typedef RefCount<Http::One::RequestParser> RequestParserPointer;
+
+} // namespace One
+} // namespace Http
+
+namespace Http1 = Http::One;
+
+#endif /* SQUID_SRC_HTTP_ONE_FORWARD_H */
index f38b05f791f73abf94a2ae0dbf4399f25ad85db5..b5127866ac01b2b60da7325b7762f36f80618ff9 100644 (file)
@@ -7,7 +7,7 @@
 #define protected public
 
 #include "testHttp1Parser.h"
-#include "http/Http1Parser.h"
+#include "http/one/RequestParser.h"
 #include "http/RequestMethod.h"
 #include "Mem.h"
 #include "MemBuf.h"