From: Amos Jeffries Date: Fri, 29 Jul 2011 13:12:29 +0000 (-0600) Subject: SourceLayout: generic AnyP::ProtocolVersion tag class X-Git-Tag: take08~55^2~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c9fd01b4b829bc16d2691a84cdc103ac5dd15333;p=thirdparty%2Fsquid.git SourceLayout: generic AnyP::ProtocolVersion tag class Protocol agnostic class to store the request-line version details. HTTP/1.0, HTTP/1.1, ICY/1.0, WebSockets/1.0 etc For patch reduction leaves HttpVersion as a child class for HTTP/*.* tags --- diff --git a/src/HttpVersion.h b/src/HttpVersion.h index 145a4802d3..b13bcd62c8 100644 --- a/src/HttpVersion.h +++ b/src/HttpVersion.h @@ -35,64 +35,14 @@ #ifndef SQUID_HTTPVERSION_H #define SQUID_HTTPVERSION_H -#if HAVE_OSTREAM -#include -#endif +#include "anyp/ProtocolVersion.h" -class HttpVersion +class HttpVersion : public AnyP::ProtocolVersion { - public: - HttpVersion() { - major = 0; - minor = 0; - } - - HttpVersion(unsigned int aMajor, unsigned int aMinor) { - major = aMajor; - minor = aMinor; - } - - unsigned int major; - unsigned int minor; - - bool operator==(const HttpVersion& that) const { - if (this->major != that.major) - return false; - - if (this->minor != that.minor) - return false; - - return true; - } + HttpVersion() : AnyP::ProtocolVersion(AnyP::PROTO_HTTP,0,0) {} - bool operator!=(const HttpVersion& that) const { - return ((this->major != that.major) || (this->minor != that.minor)); - } - - bool operator <(const HttpVersion& that) const { - return (this->major < that.major || - (this->major == that.major && this->minor < that.minor)); - } - - bool operator >(const HttpVersion& that) const { - return (this->major > that.major || - (this->major == that.major && this->minor > that.minor)); - } - - bool operator <=(const HttpVersion& that) const { - return !(*this > that); - } - - bool operator >=(const HttpVersion& that) const { - return !(*this < that); - } + HttpVersion(unsigned int aMajor, unsigned int aMinor) : AnyP::ProtocolVersion(AnyP::PROTO_HTTP,aMajor,aMinor) {} }; -inline std::ostream & -operator << (std::ostream &os, const HttpVersion &v) -{ - return (os << v.major << '.' << v.minor); -} - #endif /* SQUID_HTTPVERSION_H */ diff --git a/src/anyp/Makefile.am b/src/anyp/Makefile.am index c8cd4a8567..33ac48af41 100644 --- a/src/anyp/Makefile.am +++ b/src/anyp/Makefile.am @@ -5,7 +5,8 @@ noinst_LTLIBRARIES = libanyp.la libanyp_la_SOURCES = \ ProtocolType.cc \ - ProtocolType.h + ProtocolType.h \ + ProtocolVersion.h ProtocolType.cc: ProtocolType.h $(top_srcdir)/src/mk-string-arrays.awk ($(AWK) -f $(top_srcdir)/src/mk-string-arrays.awk <$(srcdir)/ProtocolType.h | sed -e 's%PROTO_%%' >$@) || ($(RM) -f $@ && exit 1) diff --git a/src/anyp/ProtocolVersion.h b/src/anyp/ProtocolVersion.h new file mode 100644 index 0000000000..b3d2bb9e77 --- /dev/null +++ b/src/anyp/ProtocolVersion.h @@ -0,0 +1,89 @@ +#ifndef SQUID_ANYP_PROTOCOLVERSION_H +#define SQUID_ANYP_PROTOCOLVERSION_H + +#include "anyp/ProtocolType.h" + +#if HAVE_OSTREAM +#include +#endif + +namespace AnyP +{ + +class ProtocolVersion +{ + +public: + // BUG: major() and minor() are macros. + // we can't use a fast constructor syntax without renaming them globally + ProtocolVersion() : protocol(PROTO_NONE) { + major = 0; + minor = 0; + } + + ProtocolVersion(ProtocolType which, unsigned int aMajor, unsigned int aMinor) : protocol(which) { + major = aMajor; + minor = aMinor; + } + + ProtocolType protocol; + unsigned int major; + unsigned int minor; + + bool operator==(const ProtocolVersion& that) const { + if (this->protocol != that.protocol) + return false; + + if (this->major != that.major) + return false; + + if (this->minor != that.minor) + return false; + + return true; + } + + bool operator!=(const ProtocolVersion& that) const { + return (((this->protocol != that.protocol) || this->major != that.major) || (this->minor != that.minor)); + } + + bool operator <(const ProtocolVersion& that) const { + if (this->protocol != that.protocol) + return false; // throw? + + return (this->major < that.major || + (this->major == that.major && this->minor < that.minor)); + } + + bool operator >(const ProtocolVersion& that) const { + if (this->protocol != that.protocol) + return false; // throw? + + return (this->major > that.major || + (this->major == that.major && this->minor > that.minor)); + } + + bool operator <=(const ProtocolVersion& that) const { + if (this->protocol != that.protocol) + return false; // throw? + + return !(*this > that); + } + + bool operator >=(const ProtocolVersion& that) const { + if (this->protocol != that.protocol) + return false; // throw? + + return !(*this < that); + } +}; + +} // namespace AnyP + +inline std::ostream & +operator << (std::ostream &os, const AnyP::ProtocolVersion &v) +{ + return (os << AnyP::ProtocolType_str[v.protocol] << v.major << '.' << v.minor); +} + +#endif /* SQUID_ANYP_PROTOCOLVERSION_H */ diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 2139479107..df7cf5f0da 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -1067,7 +1067,7 @@ ClientRequestContext::clientRedirectDone(char *result) http->request = HTTPMSGLOCK(new_request); } else { debugs(85, DBG_CRITICAL, "ERROR: URL-rewrite produces invalid request: " << - old_request->method << " " << result << " HTTP/1.1"); + old_request->method << " " << result << " " << old_request->http_ver); delete new_request; } } diff --git a/src/errorpage.cc b/src/errorpage.cc index 095bd2781c..b484af41e2 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -747,9 +747,10 @@ ErrorState::Dump(MemBuf * mb) else urlpath_or_slash = "/"; - str.Printf("%s " SQUIDSTRINGPH " HTTP/%d.%d\n", + str.Printf("%s " SQUIDSTRINGPH " %s/%d.%d\n", RequestMethodStr(request->method), SQUIDSTRINGPRINT(urlpath_or_slash), + AnyP::ProtocolType_str[request->http_ver.protocol], request->http_ver.major, request->http_ver.minor); packerToMemInit(&pck, &str); request->header.packInto(&pck); @@ -964,9 +965,10 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion else urlpath_or_slash = "/"; - mb.Printf("%s " SQUIDSTRINGPH " HTTP/%d.%d\n", + mb.Printf("%s " SQUIDSTRINGPH " %s/%d.%d\n", RequestMethodStr(request->method), SQUIDSTRINGPRINT(urlpath_or_slash), + AnyP::ProtocolType_str[request->http_ver.protocol], request->http_ver.major, request->http_ver.minor); packerToMemInit(&pck, &mb); request->header.packInto(&pck); diff --git a/src/http.cc b/src/http.cc index 780b7b73ed..4d9e8d99c5 100644 --- a/src/http.cc +++ b/src/http.cc @@ -2011,9 +2011,10 @@ HttpStateData::buildRequestPrefix(MemBuf * mb) url = entry->url(); else url = request->urlpath.termedBuf(); - mb->Printf("%s %s HTTP/%d.%d\r\n", + mb->Printf("%s %s %s/%d.%d\r\n", RequestMethodStr(request->method), url && *url ? url : "/", + AnyP::ProtocolType_str[httpver.protocol], httpver.major,httpver.minor); /* build and pack headers */ { diff --git a/src/log/FormatHttpdCombined.cc b/src/log/FormatHttpdCombined.cc index 1679be3dfa..db4638957b 100644 --- a/src/log/FormatHttpdCombined.cc +++ b/src/log/FormatHttpdCombined.cc @@ -58,13 +58,14 @@ Log::Format::HttpdCombined(AccessLogEntry * al, Logfile * logfile) if (!agent || *agent == '\0') agent = "-"; - logfilePrintf(logfile, "%s %s %s [%s] \"%s %s HTTP/%d.%d\" %d %"PRId64" \"%s\" \"%s\" %s%s:%s%s", + logfilePrintf(logfile, "%s %s %s [%s] \"%s %s %s/%d.%d\" %d %"PRId64" \"%s\" \"%s\" %s%s:%s%s", al->cache.caddr.NtoA(clientip,MAX_IPSTRLEN), user_ident ? user_ident : dash_str, user_auth ? user_auth : dash_str, Time::FormatHttpd(squid_curtime), al->_private.method_str, al->url, + AnyP::ProtocolType_str[al->http.version.protocol], al->http.version.major, al->http.version.minor, al->http.code, al->cache.replySize, diff --git a/src/log/FormatHttpdCommon.cc b/src/log/FormatHttpdCommon.cc index 7bfa35a5e6..1f8ad8566f 100644 --- a/src/log/FormatHttpdCommon.cc +++ b/src/log/FormatHttpdCommon.cc @@ -47,13 +47,14 @@ Log::Format::HttpdCommon(AccessLogEntry * al, Logfile * logfile) const char *user_auth = FormatName(al->cache.authuser); const char *user_ident = FormatName(al->cache.rfc931); - logfilePrintf(logfile, "%s %s %s [%s] \"%s %s HTTP/%d.%d\" %d %"PRId64" %s%s:%s%s", + logfilePrintf(logfile, "%s %s %s [%s] \"%s %s %s/%d.%d\" %d %"PRId64" %s%s:%s%s", al->cache.caddr.NtoA(clientip,MAX_IPSTRLEN), user_ident ? user_ident : dash_str, user_auth ? user_auth : dash_str, Time::FormatHttpd(squid_curtime), al->_private.method_str, al->url, + AnyP::ProtocolType_str[al->http.version.protocol], al->http.version.major, al->http.version.minor, al->http.code, al->cache.replySize, diff --git a/src/tunnel.cc b/src/tunnel.cc index 2f1f6697e1..47516b4cbc 100644 --- a/src/tunnel.cc +++ b/src/tunnel.cc @@ -643,7 +643,7 @@ tunnelStart(ClientHttpRequest * http, int64_t * size_ptr, int *status_ptr) } } - debugs(26, 3, HERE << "'" << RequestMethodStr(request->method) << " " << url << " HTTP/" << request->http_ver << "'"); + debugs(26, 3, HERE << "'" << RequestMethodStr(request->method) << " " << url << " " << request->http_ver << "'"); statCounter.server.all.requests++; statCounter.server.other.requests++;