From: Amos Jeffries Date: Sun, 17 Mar 2013 12:19:16 +0000 (-0600) Subject: SourceLayout: Shuffle HttpVersion.h to http/ProtocolVersion.h X-Git-Tag: SQUID_3_4_0_1~235 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=526ed14e46378b5106175b44f3718d9179b38015;p=thirdparty%2Fsquid.git SourceLayout: Shuffle HttpVersion.h to http/ProtocolVersion.h * 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) --- diff --git a/src/AccessLogEntry.h b/src/AccessLogEntry.h index bea75087d0..14c1d1b53e 100644 --- a/src/AccessLogEntry.h +++ b/src/AccessLogEntry.h @@ -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) diff --git a/src/HttpMsg.cc b/src/HttpMsg.cc index 33aae9461b..3b8ca169b9 100644 --- a/src/HttpMsg.cc +++ b/src/HttpMsg.cc @@ -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. diff --git a/src/HttpMsg.h b/src/HttpMsg.h index 02231eada6..6de4cfbd0d 100644 --- a/src/HttpMsg.h +++ b/src/HttpMsg.h @@ -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; diff --git a/src/HttpReply.cc b/src/HttpReply.cc index ae9333a79f..7965ce5728 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -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); diff --git a/src/HttpReply.h b/src/HttpReply.h index c1fc688a47..3718a0eaf8 100644 --- a/src/HttpReply.h +++ b/src/HttpReply.h @@ -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 */ diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index 09a0f6c4b8..4739572fc0 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -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 diff --git a/src/HttpStatusLine.cc b/src/HttpStatusLine.cc index f888634d0a..f3835fba8e 100644 --- a/src/HttpStatusLine.cc +++ b/src/HttpStatusLine.cc @@ -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; diff --git a/src/HttpStatusLine.h b/src/HttpStatusLine.h index 5e95c20957..f98586c771 100644 --- a/src/HttpStatusLine.h +++ b/src/HttpStatusLine.h @@ -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 index cbc7d1fe04..0000000000 --- a/src/HttpVersion.h +++ /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 - */ - -#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 */ diff --git a/src/Makefile.am b/src/Makefile.am index 60c477dc79..050176fdba 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -408,7 +408,6 @@ squid_SOURCES = \ HttpRequest.h \ HttpRequestMethod.cc \ HttpRequestMethod.h \ - HttpVersion.h \ ICP.h \ icp_opcode.h \ icp_v2.cc \ diff --git a/src/anyp/ProtocolVersion.h b/src/anyp/ProtocolVersion.h index ecede00573..3ba01cd147 100644 --- a/src/anyp/ProtocolVersion.h +++ b/src/anyp/ProtocolVersion.h @@ -10,6 +10,10 @@ 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) diff --git a/src/client_side.cc b/src/client_side.cc index 7124461d97..b2422fd574 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -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); diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 90459a4171..e78b2132bc 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -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 */ diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 62f7418ade..88d535660a 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -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); diff --git a/src/errorpage.cc b/src/errorpage.cc index 90c9560308..ee12000f3f 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -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; } diff --git a/src/http.cc b/src/http.cc index 11739ff9d2..7dc88aa28e 100644 --- a/src/http.cc +++ b/src/http.cc @@ -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(); diff --git a/src/http/Makefile.am b/src/http/Makefile.am index 73dfc89f72..a887316ff6 100644 --- a/src/http/Makefile.am +++ b/src/http/Makefile.am @@ -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 index 0000000000..9df8c24fed --- /dev/null +++ b/src/http/ProtocolVersion.h @@ -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 */ diff --git a/src/icmp/net_db.cc b/src/icmp/net_db.cc index c34bac1cab..1361437fb0 100644 --- a/src/icmp/net_db.cc +++ b/src/icmp/net_db.cc @@ -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;