From: Amos Jeffries Date: Tue, 20 May 2014 10:21:14 +0000 (-0700) Subject: Polish: class file shuffling for guidelines X-Git-Tag: merge-candidate-3-v1~506^2~38 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c99510dd55d72944363979793d4f4606dd0e150b;p=thirdparty%2Fsquid.git Polish: class file shuffling for guidelines --- diff --git a/configure.ac b/configure.ac index 3dfa4cb162..31187c6f94 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index 6ceeeb63da..1640473b93 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -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" diff --git a/src/client_side.cc b/src/client_side.cc index 7ee97a8fd3..95aeef8095 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -104,7 +104,7 @@ #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" diff --git a/src/http/Makefile.am b/src/http/Makefile.am index 0d6573136f..bb60334273 100644 --- a/src/http/Makefile.am +++ b/src/http/Makefile.am @@ -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) diff --git a/src/http/forward.h b/src/http/forward.h index adee4c3e85..3ae78ba0e3 100644 --- a/src/http/forward.h +++ b/src/http/forward.h @@ -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 HttpRequestPointer; class HttpReply; typedef RefCount HttpReplyPointer; -namespace Http { - -namespace One { -class RequestParser; -typedef RefCount 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 index 0000000000..17ac59068f --- /dev/null +++ b/src/http/one/Makefile.am @@ -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 index 0000000000..3b2fd19874 --- /dev/null +++ b/src/http/one/Parser.cc @@ -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; +} diff --git a/src/http/Http1Parser.h b/src/http/one/Parser.h similarity index 60% rename from src/http/Http1Parser.h rename to src/http/one/Parser.h index c75774eddb..98ec0b4270 100644 --- a/src/http/Http1Parser.h +++ b/src/http/one/Parser.h @@ -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 diff --git a/src/http/Http1Parser.cc b/src/http/one/RequestParser.cc similarity index 90% rename from src/http/Http1Parser.cc rename to src/http/one/RequestParser.cc index 4fd2b7a17c..e5ecd1665d 100644 --- a/src/http/Http1Parser.cc +++ b/src/http/one/RequestParser.cc @@ -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 index 0000000000..c2da5077be --- /dev/null +++ b/src/http/one/RequestParser.h @@ -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 index 0000000000..b3e6c11d81 --- /dev/null +++ b/src/http/one/forward.h @@ -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 RequestParserPointer; + +} // namespace One +} // namespace Http + +namespace Http1 = Http::One; + +#endif /* SQUID_SRC_HTTP_ONE_FORWARD_H */ diff --git a/src/tests/testHttp1Parser.cc b/src/tests/testHttp1Parser.cc index f38b05f791..b5127866ac 100644 --- a/src/tests/testHttp1Parser.cc +++ b/src/tests/testHttp1Parser.cc @@ -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"