]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
SourceLayout: generic AnyP::ProtocolVersion tag class
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 29 Jul 2011 13:12:29 +0000 (07:12 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 29 Jul 2011 13:12:29 +0000 (07:12 -0600)
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

src/HttpVersion.h
src/anyp/Makefile.am
src/anyp/ProtocolVersion.h [new file with mode: 0644]
src/client_side_request.cc
src/errorpage.cc
src/http.cc
src/log/FormatHttpdCombined.cc
src/log/FormatHttpdCommon.cc
src/tunnel.cc

index 145a4802d3ca9387484d5dad9e311831fc4d0336..b13bcd62c848f91c5e9088a17443df835deadf26 100644 (file)
 #ifndef SQUID_HTTPVERSION_H
 #define SQUID_HTTPVERSION_H
 
-#if HAVE_OSTREAM
-#include <ostream>
-#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 */
index c8cd4a85672f19c8fb83c21b8461d608baf0eb35..33ac48af41139579eda25d19d322918b08487a29 100644 (file)
@@ -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 (file)
index 0000000..b3d2bb9
--- /dev/null
@@ -0,0 +1,89 @@
+#ifndef SQUID_ANYP_PROTOCOLVERSION_H
+#define SQUID_ANYP_PROTOCOLVERSION_H
+
+#include "anyp/ProtocolType.h"
+
+#if HAVE_OSTREAM
+#include <ostream>
+#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 */
index 2139479107f07cd7427024c74d43910e7df6a90f..df7cf5f0daa246cc6249b26368e63857df20a4af 100644 (file)
@@ -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;
             }
         }
index 095bd2781cf79f21f072e95ef436205b05c6e59f..b484af41e2b8e050e898293ebbaab3fde39fa92e 100644 (file)
@@ -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);
index 780b7b73ed7ea25edbfdd88c08d7d3788a09c403..4d9e8d99c582d43911a715a7dfd6f5e3a1470ccf 100644 (file)
@@ -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 */
     {
index 1679be3dfada6c8a6419bb6aaeaa2cfe3680a6f1..db4638957b94fdfcbdc34e3deeaf62ba6d15e588 100644 (file)
@@ -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,
index 7bfa35a5e68670d8af028f0b534f398f43c44754..1f8ad8566ff52b03944d92619d63782d78c76fbc 100644 (file)
@@ -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,
index 2f1f6697e1094a8e787a9d0a49ead608f0141965..47516b4cbcdf2a02da4a9e46708d69ce5b2f79bb 100644 (file)
@@ -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++;