]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
SourceLayout: Shuffle HttpVersion.h to http/ProtocolVersion.h
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 17 Mar 2013 12:19:16 +0000 (06:19 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 17 Mar 2013 12:19:16 +0000 (06:19 -0600)
* incluing Http namespace and rename HttpVersion to Http::ProtocolVersion

* use ProtocolVersion.h filename to avoid clashing with include/version.h
  on case-insensitive filesystems.

* add class and member documentation (also for Anyp::ProtocolVersion)

19 files changed:
src/AccessLogEntry.h
src/HttpMsg.cc
src/HttpMsg.h
src/HttpReply.cc
src/HttpReply.h
src/HttpRequest.cc
src/HttpStatusLine.cc
src/HttpStatusLine.h
src/HttpVersion.h [deleted file]
src/Makefile.am
src/anyp/ProtocolVersion.h
src/client_side.cc
src/client_side_reply.cc
src/client_side_request.cc
src/errorpage.cc
src/http.cc
src/http/Makefile.am
src/http/ProtocolVersion.h [new file with mode: 0644]
src/icmp/net_db.cc

index bea75087d00d7953317af230a6a47691bbba67d4..14c1d1b53e8f0ba90389b8fd6e7ae108b64ac54f 100644 (file)
@@ -34,7 +34,7 @@
 #include "base/RefCount.h"
 #include "comm/Connection.h"
 #include "HttpHeader.h"
-#include "HttpVersion.h"
+#include "http/ProtocolVersion.h"
 #include "HttpRequestMethod.h"
 #include "HierarchyLogEntry.h"
 #include "icp_opcode.h"
@@ -89,7 +89,7 @@ public:
         HttpRequestMethod method;
         int code;
         const char *content_type;
-        HttpVersion version;
+        Http::ProtocolVersion version;
         bool timedout; ///< terminated due to a lifetime or I/O timeout
         bool aborted; ///< other abnormal termination (e.g., I/O error)
 
index 33aae9461b83f54f1f2188723511e7725b46d2c4..3b8ca169b96971c1a65b1982ea5da3a912ff6b7e 100644 (file)
@@ -322,7 +322,7 @@ HttpMsg::setContentLength(int64_t clen)
 bool
 HttpMsg::persistent() const
 {
-    if (http_ver > HttpVersion(1, 0)) {
+    if (http_ver > Http::ProtocolVersion(1, 0)) {
         /*
          * for modern versions of HTTP: persistent unless there is
          * a "Connection: close" header.
index 02231eada6839e2d527069fe0c363b3d54421b01..6de4cfbd0ddb676da99c5e5aede064dfdceb29d6 100644 (file)
@@ -36,7 +36,7 @@
 #include "HttpHeader.h"
 #include "HttpRequestMethod.h"
 #include "http/StatusCode.h"
-#include "HttpVersion.h"
+#include "http/ProtocolVersion.h"
 #include "typedefs.h"
 
 /// common parts of HttpRequest and HttpReply
@@ -68,7 +68,7 @@ public:
     bool persistent() const;
 
 public:
-    HttpVersion http_ver;
+    Http::ProtocolVersion http_ver;
 
     HttpHeader header;
 
index ae9333a79f6437b87978539770a5bc912c043af1..7965ce5728cb4af993fda7bd19706547ad583537 100644 (file)
@@ -188,8 +188,7 @@ HttpReply::make304() const
     /* rv->cache_control */
     /* rv->content_range */
     /* rv->keep_alive */
-    HttpVersion ver(1,1);
-    httpStatusLineSet(&rv->sline, ver, Http::scNotModified, NULL);
+    httpStatusLineSet(&rv->sline, Http::ProtocolVersion(1,1), Http::scNotModified, NULL);
 
     for (t = 0; ImsEntries[t] != HDR_OTHER; ++t)
         if ((e = header.findEntry(ImsEntries[t])))
@@ -216,8 +215,7 @@ HttpReply::setHeaders(Http::StatusCode status, const char *reason,
                       const char *ctype, int64_t clen, time_t lmt, time_t expiresTime)
 {
     HttpHeader *hdr;
-    HttpVersion ver(1,1);
-    httpStatusLineSet(&sline, ver, status, reason);
+    httpStatusLineSet(&sline, Http::ProtocolVersion(1,1), status, reason);
     hdr = &header;
     hdr->putStr(HDR_SERVER, visible_appname_string);
     hdr->putStr(HDR_MIME_VERSION, "1.0");
@@ -251,8 +249,7 @@ void
 HttpReply::redirect(Http::StatusCode status, const char *loc)
 {
     HttpHeader *hdr;
-    HttpVersion ver(1,1);
-    httpStatusLineSet(&sline, ver, status, httpStatusString(status));
+    httpStatusLineSet(&sline, Http::ProtocolVersion(1,1), status, httpStatusString(status));
     hdr = &header;
     hdr->putStr(HDR_SERVER, APP_FULLNAME);
     hdr->putTime(HDR_DATE, squid_curtime);
index c1fc688a47cadc917677ca7be1ef7b080305a862..3718a0eaf81443e9625c3cbda54e9a75a262a95b 100644 (file)
@@ -39,7 +39,7 @@ void httpReplyInitModule(void);
 
 #if DEAD_CODE
 /** do everything in one call: init, set, pack, clean, return MemBuf */
-MemBuf *httpPackedReply(HttpVersion ver, Http::StatusCode status, const char *ctype, int64_t clen, time_t lmt, time_t expires);
+MemBuf *httpPackedReply(Http::ProtocolVersion ver, Http::StatusCode status, const char *ctype, int64_t clen, time_t lmt, time_t expires);
 #endif
 
 /* Sync changes here with HttpReply.cc */
index 09a0f6c4b8981389cb4a3f970d1f6142b5719aa2..4739572fc0859929823b206f31b1e7b4461493bd 100644 (file)
@@ -675,7 +675,7 @@ HttpRequest::canHandle1xx() const
 {
     // old clients do not support 1xx unless they sent Expect: 100-continue
     // (we reject all other HDR_EXPECT values so just check for HDR_EXPECT)
-    if (http_ver <= HttpVersion(1,0) && !header.has(HDR_EXPECT))
+    if (http_ver <= Http::ProtocolVersion(1,0) && !header.has(HDR_EXPECT))
         return false;
 
     // others must support 1xx control messages
index f888634d0a6b85a1504c02eb073289b0b54933ad..f3835fba8e27f993a3203e3fd8818173af44b15e 100644 (file)
@@ -44,20 +44,18 @@ const char *IcyStatusLineFormat = "ICY %3d %s\r\n";
 void
 httpStatusLineInit(HttpStatusLine * sline)
 {
-    HttpVersion version;
-    httpStatusLineSet(sline, version, Http::scNone, NULL);
+    httpStatusLineSet(sline, Http::ProtocolVersion(), Http::scNone, NULL);
 }
 
 void
 httpStatusLineClean(HttpStatusLine * sline)
 {
-    HttpVersion version;
-    httpStatusLineSet(sline, version, Http::scInternalServerError, NULL);
+    httpStatusLineSet(sline, Http::ProtocolVersion(), Http::scInternalServerError, NULL);
 }
 
 /* set values */
 void
-httpStatusLineSet(HttpStatusLine * sline, HttpVersion version, Http::StatusCode status, const char *reason)
+httpStatusLineSet(HttpStatusLine * sline, Http::ProtocolVersion version, Http::StatusCode status, const char *reason)
 {
     assert(sline);
     sline->protocol = AnyP::PROTO_HTTP;
index 5e95c209575120d4d41252262cda087dc3f48aec..f98586c771083e754cd28dc862f7126bfe7a7e4b 100644 (file)
@@ -31,9 +31,8 @@
 #ifndef SQUID_HTTPSTATUSLINE_H
 #define SQUID_HTTPSTATUSLINE_H
 
+#include "http/ProtocolVersion.h"
 #include "http/StatusCode.h"
-#include "HttpVersion.h"
-#include "anyp/ProtocolType.h"
 #include "SquidString.h"
 
 class Packer;
@@ -56,7 +55,7 @@ public:
      */
     AnyP::ProtocolType protocol;
 
-    HttpVersion version;     ///< breakdown of protocol version labels: 0.9 1.0 1.1
+    Http::ProtocolVersion version;     ///< breakdown of protocol version labels: 0.9 1.0 1.1
     Http::StatusCode status; ///< status code. ie 200 404
     const char *reason;             ///< points to a _constant_ string (default or supplied), never free()d */
 };
@@ -65,7 +64,7 @@ public:
 void httpStatusLineInit(HttpStatusLine * sline);
 void httpStatusLineClean(HttpStatusLine * sline);
 /* set/get values */
-void httpStatusLineSet(HttpStatusLine * sline, HttpVersion version,
+void httpStatusLineSet(HttpStatusLine * sline, Http::ProtocolVersion version,
                        Http::StatusCode status, const char *reason);
 const char *httpStatusLineReason(const HttpStatusLine * sline);
 /* parse/pack */
diff --git a/src/HttpVersion.h b/src/HttpVersion.h
deleted file mode 100644 (file)
index cbc7d1f..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-
-/*
- *
- * SQUID Web Proxy Cache          http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- *  Squid is the result of efforts by numerous individuals from
- *  the Internet community; see the CONTRIBUTORS file for full
- *  details.   Many organizations have provided support for Squid's
- *  development; see the SPONSORS file for full details.  Squid is
- *  Copyrighted (C) 2001 by the Regents of the University of
- *  California; see the COPYRIGHT file for full details.  Squid
- *  incorporates software developed and/or copyrighted by other
- *  sources; see the CREDITS file for full details.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
- *
- * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
- */
-
-#ifndef SQUID_HTTPVERSION_H
-#define SQUID_HTTPVERSION_H
-
-#include "anyp/ProtocolVersion.h"
-
-class HttpVersion : public AnyP::ProtocolVersion
-{
-public:
-    HttpVersion() : AnyP::ProtocolVersion(AnyP::PROTO_HTTP,0,0) {}
-
-    HttpVersion(unsigned int aMajor, unsigned int aMinor) : AnyP::ProtocolVersion(AnyP::PROTO_HTTP,aMajor,aMinor) {}
-};
-
-#endif /* SQUID_HTTPVERSION_H */
index 60c477dc797871e55f3a3e23421bfd743b303e82..050176fdba3059600e964b5d2e691b92febe9d25 100644 (file)
@@ -408,7 +408,6 @@ squid_SOURCES = \
        HttpRequest.h \
        HttpRequestMethod.cc \
        HttpRequestMethod.h \
-       HttpVersion.h \
        ICP.h \
        icp_opcode.h \
        icp_v2.cc \
index ecede005731bab325cc9dfc21d078f3b2e89c4b9..3ba01cd147538c20a97eb6453d0da56dd867672a 100644 (file)
 namespace AnyP
 {
 
+/**
+ * Stores a protocol version label.
+ * For example HTTP/1.1 or ICY/1.0 or FTP/2.0
+ */
 class ProtocolVersion
 {
 
@@ -26,9 +30,9 @@ public:
         minor = aMinor;
     }
 
-    ProtocolType protocol;
-    unsigned int major;
-    unsigned int minor;
+    ProtocolType protocol; ///< which protocol this version is for
+    unsigned int major;    ///< major version number
+    unsigned int minor;    ///< minor version number
 
     bool operator==(const ProtocolVersion& that) const {
         if (this->protocol != that.protocol)
index 7124461d9758a70adcc12ba7403a39149c1b1307..b2422fd574f46441c35aebb720b8325186a50465 100644 (file)
@@ -221,7 +221,7 @@ static IOACB httpsAccept;
 #endif
 static CTCB clientLifetimeTimeout;
 static ClientSocketContext *parseHttpRequestAbort(ConnStateData * conn, const char *uri);
-static ClientSocketContext *parseHttpRequest(ConnStateData *, HttpParser *, HttpRequestMethod *, HttpVersion *);
+static ClientSocketContext *parseHttpRequest(ConnStateData *, HttpParser *, HttpRequestMethod *, Http::ProtocolVersion *);
 #if USE_IDENT
 static IDCB clientIdentDone;
 #endif
@@ -2159,7 +2159,7 @@ prepareTransparentURL(ConnStateData * conn, ClientHttpRequest *http, char *url,
  *          a ClientSocketContext structure on success or failure.
  */
 static ClientSocketContext *
-parseHttpRequest(ConnStateData *csd, HttpParser *hp, HttpRequestMethod * method_p, HttpVersion *http_ver)
+parseHttpRequest(ConnStateData *csd, HttpParser *hp, HttpRequestMethod * method_p, Http::ProtocolVersion *http_ver)
 {
     char *req_hdr = NULL;
     char *end;
@@ -2196,7 +2196,7 @@ parseHttpRequest(ConnStateData *csd, HttpParser *hp, HttpRequestMethod * method_
     }
 
     /* Request line is valid here .. */
-    *http_ver = HttpVersion(hp->req.v_maj, hp->req.v_min);
+    *http_ver = Http::ProtocolVersion(hp->req.v_maj, hp->req.v_min);
 
     /* This call scans the entire request, not just the headers */
     if (hp->req.v_maj > 0) {
@@ -2584,7 +2584,7 @@ bool ConnStateData::serveDelayedError(ClientSocketContext *context)
 #endif // USE_SSL
 
 static void
-clientProcessRequest(ConnStateData *conn, HttpParser *hp, ClientSocketContext *context, const HttpRequestMethod& method, HttpVersion http_ver)
+clientProcessRequest(ConnStateData *conn, HttpParser *hp, ClientSocketContext *context, const HttpRequestMethod& method, Http::ProtocolVersion http_ver)
 {
     ClientHttpRequest *http = context->http;
     HttpRequest::Pointer request;
@@ -2887,7 +2887,6 @@ ConnStateData::clientParseRequests()
 {
     HttpRequestMethod method;
     bool parsed_req = false;
-    HttpVersion http_ver;
 
     debugs(33, 5, HERE << clientConnection << ": attempting to parse");
 
@@ -2914,6 +2913,7 @@ ConnStateData::clientParseRequests()
         HttpParserInit(&parser_, in.buf, in.notYetUsed);
 
         /* Process request */
+        Http::ProtocolVersion http_ver;
         ClientSocketContext *context = parseHttpRequest(this, &parser_, &method, &http_ver);
         PROF_stop(parseHttpRequest);
 
index 90459a4171f2e7c19f0491ef35b2f0131440cab4..e78b2132bc05acc84301596b2e1bf735c9f54f5c 100644 (file)
@@ -1458,7 +1458,7 @@ clientReplyContext::buildReplyHeader()
 
     const bool maySendChunkedReply = !request->multipartRangeRequest() &&
                                      reply->sline.protocol == AnyP::PROTO_HTTP && // response is HTTP
-                                     (request->http_ver >= HttpVersion(1, 1));
+                                     (request->http_ver >= Http::ProtocolVersion(1, 1));
 
     /* Check whether we should send keep-alive */
     if (!Config.onoff.error_pconns && reply->sline.status >= 400 && !request->flags.mustKeepalive) {
@@ -1547,7 +1547,7 @@ clientReplyContext::cloneReply()
 
     if (reply->sline.protocol == AnyP::PROTO_HTTP) {
         /* RFC 2616 requires us to advertise our 1.1 version (but only on real HTTP traffic) */
-        reply->sline.version = HttpVersion(1,1);
+        reply->sline.version = Http::ProtocolVersion(1,1);
     }
 
     /* do header conversions */
index 62f7418ade222c935f9640d5556d2d72213aea8a..88d535660a3252bb5bb775b02a168ae9a6f9c913 100644 (file)
@@ -419,8 +419,7 @@ clientBeginRequest(const HttpRequestMethod& method, char const *url, CSCB * stre
     request->my_addr.SetPort(0);
 
     /* Our version is HTTP/1.1 */
-    HttpVersion http_ver(1,1);
-    request->http_ver = http_ver;
+    request->http_ver = Http::ProtocolVersion(1,1);
 
     http->request = request;
     HTTPMSGLOCK(http->request);
index 90c95603082f358d1f007425f04e8430d0949132..ee12000f3f9a64963860c45f81a123e5f382359a 100644 (file)
@@ -1163,7 +1163,7 @@ ErrorState::BuildHttpReply()
             status = httpStatus;
         else {
             // Use 307 for HTTP/1.1 non-GET/HEAD requests.
-            if (request->method != Http::METHOD_GET && request->method != Http::METHOD_HEAD && request->http_ver >= HttpVersion(1,1))
+            if (request->method != Http::METHOD_GET && request->method != Http::METHOD_HEAD && request->http_ver >= Http::ProtocolVersion(1,1))
                 status = Http::scTemporaryRedirect;
         }
 
index 11739ff9d22240b3ca1c8aa4d3ec5b36692bcc4c..7dc88aa28e3e7c24d4db841362338a9acd3823ce 100644 (file)
@@ -714,7 +714,7 @@ HttpStateData::processReplyHeader()
         if (!parsed && error > 0) { // unrecoverable parsing error
             debugs(11, 3, "processReplyHeader: Non-HTTP-compliant header: '" <<  readBuf->content() << "'");
             flags.headers_parsed = true;
-            newrep->sline.version = HttpVersion(1,1);
+            newrep->sline.version = Http::ProtocolVersion(1,1);
             newrep->sline.status = error;
             HttpReply *vrep = setVirginReply(newrep);
             entry->replaceHttpReply(vrep);
@@ -1261,8 +1261,8 @@ HttpStateData::continueAfterParsingHeader()
         // check for header parsing errors
         if (HttpReply *vrep = virginReply()) {
             const Http::StatusCode s = vrep->sline.status;
-            const HttpVersion &v = vrep->sline.version;
-            if (s == Http::scInvalidHeader && v != HttpVersion(0,9)) {
+            const Http::ProtocolVersion &v = vrep->sline.version;
+            if (s == Http::scInvalidHeader && v != Http::ProtocolVersion(0,9)) {
                 debugs(11, DBG_IMPORTANT, "WARNING: HTTP: Invalid Response: Bad header encountered from " << entry->url() << " AKA " << request->GetHost() << request->urlpath.termedBuf() );
                 error = ERR_INVALID_RESP;
             } else if (s == Http::scHeaderTooLarge) {
@@ -2048,7 +2048,13 @@ mb_size_t
 HttpStateData::buildRequestPrefix(MemBuf * mb)
 {
     const int offset = mb->size;
-    HttpVersion httpver(1,1);
+    /* Uses a local httpver variable to print the HTTP/1.1 label
+     * since the HttpRequest may have an older version label.
+     * XXX: This could create protocol bugs as the headers sent and
+     * flow control should all be based on the HttpRequest version
+     * not the one we are sending. Needs checking.
+     */
+    Http::ProtocolVersion httpver(1,1);
     const char * url;
     if (_peer && !_peer->options.originserver)
         url = entry->url();
index 73dfc89f72286d2afd5074d0d9103069ba8748dd..a887316ff67ac5f786aea9e7fa2b00c4ae4fd787 100644 (file)
@@ -6,6 +6,7 @@ noinst_LTLIBRARIES = libsquid-http.la
 libsquid_http_la_SOURCES = \
        MethodType.cc \
        MethodType.h \
+       ProtocolVersion.h \
        StatusCode.h
 
 MethodType.cc: MethodType.h $(top_srcdir)/src/mk-string-arrays.awk
diff --git a/src/http/ProtocolVersion.h b/src/http/ProtocolVersion.h
new file mode 100644 (file)
index 0000000..9df8c24
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef SQUID_HTTP_PROTOCOLVERSION_H
+#define SQUID_HTTP_PROTOCOLVERSION_H
+
+#include "anyp/ProtocolVersion.h"
+
+namespace Http
+{
+
+/**
+ * Stores HTTP version label information.
+ * For example HTTP/1.0
+ */
+class ProtocolVersion : public AnyP::ProtocolVersion
+{
+public:
+    ProtocolVersion() : AnyP::ProtocolVersion(AnyP::PROTO_HTTP,0,0) {}
+
+    ProtocolVersion(unsigned int aMajor, unsigned int aMinor) : AnyP::ProtocolVersion(AnyP::PROTO_HTTP,aMajor,aMinor) {}
+};
+
+}; // namespace Http
+
+#endif /* SQUID_HTTP_PROTOCOLVERSION_H */
index c34bac1cab9eed88c120bdd5a1494acb80b2a0c8..1361437fb06ecf5896b2fbf29ecfa987b62f3dbf 100644 (file)
@@ -1333,7 +1333,7 @@ netdbExchangeStart(void *data)
 
     HTTPMSGLOCK(ex->r);
     assert(NULL != ex->r);
-    ex->r->http_ver = HttpVersion(1,1);
+    ex->r->http_ver = Http::ProtocolVersion(1,1);
     ex->connstate = STATE_HEADER;
     ex->e = storeCreateEntry(uri, uri, RequestFlags(), Http::METHOD_GET);
     ex->buf_sz = NETDB_REQBUF_SZ;