From: Amos Jeffries Date: Wed, 2 Mar 2011 07:27:24 +0000 (-0700) Subject: SourceLayout: protocol_t upgrade X-Git-Tag: take06~27^2~128 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c3d3f65531d4c9f8267118441fbd2bad9c85147;p=thirdparty%2Fsquid.git SourceLayout: protocol_t upgrade This begins the libanyp.la SourceLayout changes by moving the protocol_t type code to stand-alone files inside its namespace. On the most part there are no behaviour changes. The boundaries between the two semi-related types of protocol and protocol scheme are now clear: * URLScheme is to be used where the protocol name is related to a URI scheme description. * AnyP::ProtocolType is to be used for other non-URI places requiring the protocol to be named or manipulated as a concept. Textual representations of these two concepts differ and the output of these two types likewise differs to accomodate. Abusing them will result in visibly unusual output. --- diff --git a/configure.ac b/configure.ac index 8a36faa871..1fcc3b6d84 100644 --- a/configure.ac +++ b/configure.ac @@ -3366,6 +3366,7 @@ AC_CONFIG_FILES([\ lib/smblib/Makefile \ scripts/Makefile \ src/Makefile \ + src/anyp/Makefile \ src/base/Makefile \ src/acl/Makefile \ src/fs/Makefile \ diff --git a/src/AclRegs.cc b/src/AclRegs.cc index 5c3ef645b9..3f4a00789b 100644 --- a/src/AclRegs.cc +++ b/src/AclRegs.cc @@ -110,7 +110,7 @@ ACLStrategised ACLMyPortName::RegistryEntry_(new ACLStringData, AC ACL::Prototype ACLPeerName::RegistryProtoype(&ACLPeerName::RegistryEntry_, "peername"); ACLStrategised ACLPeerName::RegistryEntry_(new ACLStringData, ACLPeerNameStrategy::Instance(), "peername"); ACL::Prototype ACLProtocol::RegistryProtoype(&ACLProtocol::RegistryEntry_, "proto"); -ACLStrategised ACLProtocol::RegistryEntry_(new ACLProtocolData, ACLProtocolStrategy::Instance(), "proto"); +ACLStrategised ACLProtocol::RegistryEntry_(new ACLProtocolData, ACLProtocolStrategy::Instance(), "proto"); ACL::Prototype ACLRandom::RegistryProtoype(&ACLRandom::RegistryEntry_, "random"); ACLRandom ACLRandom::RegistryEntry_("random"); ACL::Prototype ACLReferer::RegistryProtoype(&ACLReferer::RegistryEntry_, "referer_regex"); diff --git a/src/HttpMsg.cc b/src/HttpMsg.cc index 276ca59acf..9c9f5c6a90 100644 --- a/src/HttpMsg.cc +++ b/src/HttpMsg.cc @@ -38,7 +38,7 @@ #include "MemBuf.h" HttpMsg::HttpMsg(http_hdr_owner_type owner): header(owner), - cache_control(NULL), hdr_sz(0), content_length(0), protocol(PROTO_NONE), + cache_control(NULL), hdr_sz(0), content_length(0), protocol(AnyP::PROTO_NONE), pstate(psReadyToParseStartLine), lock_count(0) {} diff --git a/src/HttpMsg.h b/src/HttpMsg.h index 12b8c7484e..736ec4fb3d 100644 --- a/src/HttpMsg.h +++ b/src/HttpMsg.h @@ -89,7 +89,7 @@ public: int64_t content_length; - protocol_t protocol; + AnyP::ProtocolType protocol; HttpMsgParseState pstate; /* the current parsing state */ diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index ad3a74cf69..3d5400c4b9 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -53,7 +53,7 @@ HttpRequest::HttpRequest() : HttpMsg(hoRequest) init(); } -HttpRequest::HttpRequest(const HttpRequestMethod& aMethod, protocol_t aProtocol, const char *aUrlpath) : HttpMsg(hoRequest) +HttpRequest::HttpRequest(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *aUrlpath) : HttpMsg(hoRequest) { static unsigned int id = 1; debugs(93,7, HERE << "constructed, this=" << this << " id=" << ++id); @@ -68,7 +68,7 @@ HttpRequest::~HttpRequest() } void -HttpRequest::initHTTP(const HttpRequestMethod& aMethod, protocol_t aProtocol, const char *aUrlpath) +HttpRequest::initHTTP(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *aUrlpath) { method = aMethod; protocol = aProtocol; @@ -79,7 +79,7 @@ void HttpRequest::init() { method = METHOD_NONE; - protocol = PROTO_NONE; + protocol = AnyP::PROTO_NONE; urlpath = NULL; login[0] = '\0'; host[0] = '\0'; @@ -565,7 +565,7 @@ HttpRequest::CreateFromUrl(char * url) bool HttpRequest::cacheable() const { - if (protocol == PROTO_HTTP) + if (protocol == AnyP::PROTO_HTTP) return httpCachable(method); /* @@ -580,10 +580,10 @@ HttpRequest::cacheable() const * XXX POST may be cached sometimes.. ignored * for now */ - if (protocol == PROTO_GOPHER) + if (protocol == AnyP::PROTO_GOPHER) return gopherCachable(this); - if (protocol == PROTO_CACHEOBJ) + if (protocol == AnyP::PROTO_CACHEOBJ) return false; return true; diff --git a/src/HttpRequest.h b/src/HttpRequest.h index 1baa1488b1..6fed46a1a0 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -73,7 +73,7 @@ public: MEMPROXY_CLASS(HttpRequest); HttpRequest(); - HttpRequest(const HttpRequestMethod& aMethod, protocol_t aProtocol, const char *aUrlpath); + HttpRequest(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *aUrlpath); ~HttpRequest(); virtual void reset(); @@ -82,7 +82,7 @@ public: return static_cast(HttpMsg::_lock()); }; - void initHTTP(const HttpRequestMethod& aMethod, protocol_t aProtocol, const char *aUrlpath); + void initHTTP(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *aUrlpath); virtual HttpRequest *clone() const; diff --git a/src/HttpStatusLine.cc b/src/HttpStatusLine.cc index 63e5402064..eda2844c81 100644 --- a/src/HttpStatusLine.cc +++ b/src/HttpStatusLine.cc @@ -60,7 +60,7 @@ void httpStatusLineSet(HttpStatusLine * sline, HttpVersion version, http_status status, const char *reason) { assert(sline); - sline->protocol = PROTO_HTTP; + sline->protocol = AnyP::PROTO_HTTP; sline->version = version; sline->status = status; /* Note: no xstrdup for 'reason', assumes constant 'reasons' */ @@ -77,7 +77,7 @@ httpStatusLinePackInto(const HttpStatusLine * sline, Packer * p) assert(sline && p); /* handle ICY protocol status line specially. Pass on the bad format. */ - if (sline->protocol == PROTO_ICY) { + if (sline->protocol == AnyP::PROTO_ICY) { debugs(57, 9, "packing sline " << sline << " using " << p << ":"); debugs(57, 9, "FORMAT=" << IcyStatusLineFormat ); debugs(57, 9, "ICY " << sline->status << " " << (sline->reason ? sline->reason : httpStatusString(sline->status)) ); @@ -108,7 +108,7 @@ httpStatusLineParse(HttpStatusLine * sline, const String &protoPrefix, const cha if (protoPrefix.cmp("ICY", 3) == 0) { debugs(57, 3, "httpStatusLineParse: Invalid HTTP identifier. Detected ICY protocol istead."); - sline->protocol = PROTO_ICY; + sline->protocol = AnyP::PROTO_ICY; start += protoPrefix.size(); } else if (protoPrefix.caseCmp(start, protoPrefix.size()) == 0) { diff --git a/src/HttpStatusLine.h b/src/HttpStatusLine.h index d5dcb78148..d9022eab12 100644 --- a/src/HttpStatusLine.h +++ b/src/HttpStatusLine.h @@ -36,10 +36,9 @@ class Packer; class String; -/* for http_status and protocol_t */ -#include "enums.h" - +#include "HttpStatusCode.h" #include "HttpVersion.h" +#include "anyp/ProtocolType.h" #include "SquidString.h" /** @@ -54,10 +53,10 @@ public: /** * By rights protocol name should be a constant "HTTP", with no need for this field to exist. - * However there are protocols which violate HTTP by sending their wn custom formats - * back with other protocol names (ICY streaming format being the current major problem) + * However there are protocols which violate HTTP by sending their own custom formats + * back with other protocol names (ICY streaming format being the current major problem). */ - protocol_t protocol; + AnyP::ProtocolType protocol; HttpVersion version; ///< breakdown of protocol version labels: 0.9 1.0 1.1 http_status status; ///< status code. ie 200 404 diff --git a/src/Makefile.am b/src/Makefile.am index 10cc287185..cccc2b1ac5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,8 +30,8 @@ LOADABLE_MODULES_SOURCES = \ LoadableModules.h \ LoadableModules.cc -SUBDIRS = base comm eui acl fs repl -DIST_SUBDIRS = base comm eui acl fs repl +SUBDIRS = base anyp comm eui acl fs repl +DIST_SUBDIRS = base anyp comm eui acl fs repl if ENABLE_AUTH SUBDIRS += auth @@ -554,6 +554,7 @@ nodist_squid_SOURCES = \ squid_LDADD = \ $(COMMON_LIBS) \ + anyp/libanyp.la \ comm/libcomm.la \ eui/libeui.la \ icmp/libicmp.la icmp/libicmp-core.la \ @@ -1044,6 +1045,7 @@ nodist_tests_testAuth_SOURCES = \ tests_testAuth_LDADD= \ $(COMMON_LIBS) \ + anyp/libanyp.la \ $(top_builddir)/lib/libmisccontainers.la \ $(top_builddir)/lib/libmiscencoding.la \ $(top_builddir)/lib/libmiscutil.la \ @@ -1310,6 +1312,7 @@ tests_testCacheManager_LDADD = \ $(ADAPTATION_LIBS) \ $(ESI_LIBS) \ $(SSL_LIBS) \ + anyp/libanyp.la \ $(top_builddir)/lib/libmisccontainers.la \ $(top_builddir)/lib/libmiscencoding.la \ $(top_builddir)/lib/libmiscutil.la \ @@ -1341,6 +1344,7 @@ nodist_tests_testDiskIO_SOURCES= \ SquidMath.h \ swap_log_op.cc tests_testDiskIO_LDADD = \ + anyp/libanyp.la \ SquidConfig.o \ CommCalls.o \ DnsLookupDetails.o \ @@ -1513,6 +1517,7 @@ nodist_tests_testEvent_SOURCES = \ $(BUILT_SOURCES) tests_testEvent_LDADD = \ $(COMMON_LIBS) \ + anyp/libanyp.la \ $(SNMP_LIBS) \ icmp/libicmp.la icmp/libicmp-core.la \ comm/libcomm.la \ @@ -1674,6 +1679,7 @@ nodist_tests_testEventLoop_SOURCES = \ $(BUILT_SOURCES) tests_testEventLoop_LDADD = \ $(COMMON_LIBS) \ + anyp/libanyp.la \ $(SNMP_LIBS) \ icmp/libicmp.la icmp/libicmp-core.la \ comm/libcomm.la \ @@ -1830,6 +1836,7 @@ nodist_tests_test_http_range_SOURCES = \ $(BUILT_SOURCES) tests_test_http_range_LDADD = \ $(COMMON_LIBS) \ + anyp/libanyp.la \ $(SNMP_LIBS) \ icmp/libicmp.la icmp/libicmp-core.la \ comm/libcomm.la \ @@ -1991,6 +1998,7 @@ nodist_tests_testHttpRequest_SOURCES = \ $(BUILT_SOURCES) tests_testHttpRequest_LDADD = \ $(COMMON_LIBS) \ + anyp/libanyp.la \ $(SNMP_LIBS) \ icmp/libicmp.la icmp/libicmp-core.la \ comm/libcomm.la \ @@ -2089,6 +2097,7 @@ nodist_tests_testStore_SOURCES= \ tests_testStore_LDADD= \ $(COMMON_LIBS) \ + anyp/libanyp.la \ $(top_builddir)/lib/libmisccontainers.la \ $(top_builddir)/lib/libmiscencoding.la \ $(top_builddir)/lib/libmiscutil.la \ @@ -2191,6 +2200,7 @@ nodist_tests_testUfs_SOURCES = \ SquidMath.h \ swap_log_op.cc tests_testUfs_LDADD = \ + anyp/libanyp.la \ CommCalls.o \ DnsLookupDetails.o \ $(COMMON_LIBS) \ @@ -2405,6 +2415,7 @@ tests_testURL_SOURCES = \ nodist_tests_testURL_SOURCES = \ $(BUILT_SOURCES) tests_testURL_LDADD = \ + anyp/libanyp.la \ $(COMMON_LIBS) \ $(SNMP_LIBS) \ icmp/libicmp.la icmp/libicmp-core.la \ diff --git a/src/URLScheme.cc b/src/URLScheme.cc index 5c3aba354f..66aef0225e 100644 --- a/src/URLScheme.cc +++ b/src/URLScheme.cc @@ -33,25 +33,24 @@ * */ -#include "squid.h" +#include "config.h" #include "URLScheme.h" #include "wordlist.h" -const char *ProtocolStr[] = { - "NONE", - "http", - "ftp", - "gopher", - "wais", - "cache_object", - "icp", -#if USE_HTCP - "htcp", -#endif - "urn", - "whois", - "internal", - "https", - "icy", - "TOTAL" -}; +char const * +URLScheme::const_str() const +{ + if (theScheme_ == AnyP::PROTO_UNKNOWN) + return "(unknown)"; + + static char out[BUFSIZ]; + int p = 0; + + if (theScheme_ > AnyP::PROTO_NONE && theScheme_ < AnyP::PROTO_MAX) { + const char *in = AnyP::ProtocolType_str[theScheme_]; + for (; p < (BUFSIZ-1) && in[p] != '\0'; ++p) + out[p] = xtolower(in[p]); + } + out[p] = '\0'; + return out; +} diff --git a/src/URLScheme.h b/src/URLScheme.h index 38b4e43cd3..77c6815815 100644 --- a/src/URLScheme.h +++ b/src/URLScheme.h @@ -34,40 +34,36 @@ #ifndef SQUID_URLSCHEME_H #define SQUID_URLSCHEME_H -/* For the definition of NULL and protocol_t */ -#include "squid.h" - +#include "anyp/ProtocolType.h" +#if HAVE_IOSFWD #include +#endif -extern const char *ProtocolStr[]; - -/* This class represents a URL Scheme such as HTTPS, HTTP, WAIS etc. +/** This class represents a URL Scheme such as HTTPS, HTTP, WAIS etc. * It does not represent the PROTOCOL that such schemes refer to. */ - class URLScheme { public: - URLScheme() : theScheme(PROTO_NONE) {} + URLScheme() : theScheme_(AnyP::PROTO_NONE) {} + URLScheme(AnyP::ProtocolType const aScheme) : theScheme_(aScheme) {} + ~URLScheme() {} - URLScheme(protocol_t const aScheme) : theScheme(aScheme) {} + operator AnyP::ProtocolType() const { return theScheme_; } - operator protocol_t() const { return theScheme; } + bool operator != (AnyP::ProtocolType const & aProtocol) const { return theScheme_ != aProtocol; } - bool operator != (protocol_t const & aProtocol) const { return theScheme != aProtocol;} - - /* Get a char string representation of the scheme. */ - char const *const_str() const { return ProtocolStr[theScheme]; } + /** Get a char string representation of the scheme. + * An upper bound length of BUFSIZ bytes converted. Remainder will be truncated. + * The result of this call will remain usable only until any subsequest call + * and must be copied if persistence is needed. + */ + char const *const_str() const; private: - /* This is a typecode for now - TODO make the varying methods virtual - * Doing that without doubling the storage size will require having - * something like a flyweight. perhaps the strategy pattern is appropiate: - * one strategy per scheme, and an object that is nothing but a pointer - * into the registry of schemes. - */ - protocol_t theScheme; + /// This is a typecode pointer into the enum/registry of protocols handled. + AnyP::ProtocolType theScheme_; }; inline std::ostream & diff --git a/src/acl/Protocol.cc b/src/acl/Protocol.cc index 3ed48a5126..6d0a4e0a6e 100644 --- a/src/acl/Protocol.cc +++ b/src/acl/Protocol.cc @@ -41,7 +41,7 @@ /* explicit template instantiation required for some systems */ -template class ACLStrategised; +template class ACLStrategised; diff --git a/src/acl/Protocol.h b/src/acl/Protocol.h index e6a935db1b..3b54f33985 100644 --- a/src/acl/Protocol.h +++ b/src/acl/Protocol.h @@ -35,10 +35,12 @@ #ifndef SQUID_ACLPROTOCOL_H #define SQUID_ACLPROTOCOL_H + #include "acl/Strategy.h" #include "acl/Strategised.h" +#include "anyp/ProtocolType.h" -class ACLProtocolStrategy : public ACLStrategy +class ACLProtocolStrategy : public ACLStrategy { public: @@ -63,7 +65,7 @@ class ACLProtocol private: static ACL::Prototype RegistryProtoype; - static ACLStrategised RegistryEntry_; + static ACLStrategised RegistryEntry_; }; #endif /* SQUID_ACLPROTOCOL_H */ diff --git a/src/acl/ProtocolData.cc b/src/acl/ProtocolData.cc index 6fef088092..b73a4d9b56 100644 --- a/src/acl/ProtocolData.cc +++ b/src/acl/ProtocolData.cc @@ -55,7 +55,7 @@ ACLProtocolData::~ACLProtocolData() } bool -ACLProtocolData::match(protocol_t toFind) +ACLProtocolData::match(AnyP::ProtocolType toFind) { return values->findAndTune (toFind); } @@ -63,17 +63,17 @@ ACLProtocolData::match(protocol_t toFind) /* explicit instantiation required for some systems */ /// \cond AUTODOCS-IGNORE -template cbdata_type CbDataList::CBDATA_CbDataList; +template cbdata_type CbDataList::CBDATA_CbDataList; /// \endcond wordlist * ACLProtocolData::dump() { wordlist *W = NULL; - CbDataList *data = values; + CbDataList *data = values; while (data != NULL) { - wordlistAdd(&W, ProtocolStr[data->element]); + wordlistAdd(&W, AnyP::ProtocolType_str[data->element]); data = data->next; } @@ -83,14 +83,21 @@ ACLProtocolData::dump() void ACLProtocolData::parse() { - CbDataList **Tail; + CbDataList **Tail; char *t = NULL; for (Tail = &values; *Tail; Tail = &((*Tail)->next)); while ((t = strtokFile())) { - CbDataList *q = new CbDataList (urlParseProtocol(t)); - *(Tail) = q; - Tail = &q->next; + for (int p = AnyP::PROTO_NONE; p < AnyP::PROTO_UNKNOWN; ++p) { + if (strcasecmp(t, AnyP::ProtocolType_str[p]) != 0) { + CbDataList *q = new CbDataList(static_cast(p)); + *(Tail) = q; + Tail = &q->next; + break; + } else { + debugs(28, DBG_IMPORTANT, "WARNING: Ignoring unknown protocol '" << t << "' in the ACL named '" << AclMatchedName << "'"); + } + } } } @@ -100,7 +107,7 @@ ACLProtocolData::empty() const return values == NULL; } -ACLData * +ACLData * ACLProtocolData::clone() const { /* Splay trees don't clone yet. */ diff --git a/src/acl/ProtocolData.h b/src/acl/ProtocolData.h index af98746914..dbec63d1ae 100644 --- a/src/acl/ProtocolData.h +++ b/src/acl/ProtocolData.h @@ -35,11 +35,13 @@ #ifndef SQUID_ACLPROTOCOLDATA_H #define SQUID_ACLPROTOCOLDATA_H + #include "acl/Acl.h" #include "acl/Data.h" +#include "anyp/ProtocolType.h" #include "CbDataList.h" -class ACLProtocolData : public ACLData +class ACLProtocolData : public ACLData { public: @@ -49,13 +51,13 @@ public: ACLProtocolData(ACLProtocolData const &); ACLProtocolData &operator= (ACLProtocolData const &); virtual ~ACLProtocolData(); - bool match(protocol_t); + bool match(AnyP::ProtocolType); wordlist *dump(); void parse(); bool empty() const; - virtual ACLData *clone() const; + virtual ACLData *clone() const; - CbDataList *values; + CbDataList *values; }; MEMPROXY_CLASS_INLINE(ACLProtocolData); diff --git a/src/anyp/Makefile.am b/src/anyp/Makefile.am new file mode 100644 index 0000000000..c8cd4a8567 --- /dev/null +++ b/src/anyp/Makefile.am @@ -0,0 +1,13 @@ +include $(top_srcdir)/src/Common.am +include $(top_srcdir)/src/TestHeaders.am + +noinst_LTLIBRARIES = libanyp.la + +libanyp_la_SOURCES = \ + ProtocolType.cc \ + ProtocolType.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) + +CLEANFILES += ProtocolType.cc diff --git a/src/anyp/ProtocolType.h b/src/anyp/ProtocolType.h new file mode 100644 index 0000000000..031f47c596 --- /dev/null +++ b/src/anyp/ProtocolType.h @@ -0,0 +1,53 @@ +#ifndef _SQUID_SRC_ANYP_PROTOCOLTYPE_H +#define _SQUID_SRC_ANYP_PROTOCOLTYPE_H + +#if HAVE_OSTREAM +#include +#endif + +namespace AnyP { + +/** + * List of all protocols known and supported. + * This is a combined list. It is used as type-codes where needed and + * the AnyP::ProtocolType_Str array of strings may be used for display + */ +typedef enum { + PROTO_NONE = 0, + PROTO_HTTP, + PROTO_FTP, + PROTO_HTTPS, + PROTO_GOPHER, + PROTO_WAIS, + PROTO_CACHEOBJ, + PROTO_ICP, +#if USE_HTCP + PROTO_HTCP, +#endif + PROTO_URN, + PROTO_WHOIS, + PROTO_INTERNAL, + PROTO_ICY, + PROTO_UNKNOWN, + PROTO_MAX +} ProtocolType; + +extern const char *ProtocolType_str[]; + +/** Display the registered Protocol Type (in upper case). + * If the protocol is not a registered AnyP::ProtocolType nothing will be displayed. + * The caller is responsible for any alternative text. + */ +inline std::ostream & +operator <<(std::ostream &os, ProtocolType const &p) +{ + if (PROTO_NONE <= p && p < PROTO_MAX) + os << ProtocolType_str[p]; + else + os << static_cast(p); + return os; +} + +} // namespace AnyP + +#endif /* _SQUID_SRC_ANYP_PROTOCOLTYPE_H */ diff --git a/src/client_db.cc b/src/client_db.cc index 90e5d51355..6d64c8410a 100644 --- a/src/client_db.cc +++ b/src/client_db.cc @@ -143,7 +143,7 @@ ClientInfo * clientdbGetInfo(const Ip::Address &addr) } #endif void -clientdbUpdate(const Ip::Address &addr, log_type ltype, protocol_t p, size_t size) +clientdbUpdate(const Ip::Address &addr, log_type ltype, AnyP::ProtocolType p, size_t size) { char key[MAX_IPSTRLEN]; ClientInfo *c; @@ -161,14 +161,14 @@ clientdbUpdate(const Ip::Address &addr, log_type ltype, protocol_t p, size_t siz if (c == NULL) debug_trap("clientdbUpdate: Failed to add entry"); - if (p == PROTO_HTTP) { + if (p == AnyP::PROTO_HTTP) { c->Http.n_requests++; c->Http.result_hist[ltype]++; kb_incr(&c->Http.kbytes_out, size); if (logTypeIsATcpHit(ltype)) kb_incr(&c->Http.hit_kbytes_out, size); - } else if (p == PROTO_ICP) { + } else if (p == AnyP::PROTO_ICP) { c->Icp.n_requests++; c->Icp.result_hist[ltype]++; kb_incr(&c->Icp.kbytes_out, size); diff --git a/src/client_side.cc b/src/client_side.cc index 0fcd5bd20e..30efedc5ad 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -679,7 +679,7 @@ ClientHttpRequest::logRequest() updateCounters(); if (getConn() != NULL) - clientdbUpdate(getConn()->peer, logType, PROTO_HTTP, out.size); + clientdbUpdate(getConn()->peer, logType, AnyP::PROTO_HTTP, out.size); } delete checklist; @@ -2485,7 +2485,7 @@ clientProcessRequest(ConnStateData *conn, HttpParser *hp, ClientSocketContext *c } if (http->flags.internal) { - request->protocol = PROTO_HTTP; + request->protocol = AnyP::PROTO_HTTP; request->login[0] = '\0'; } diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 7425d73784..6b0fa67ace 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -551,7 +551,7 @@ clientReplyContext::cacheHit(StoreIOBuffer result) */ http->logType = LOG_TCP_CLIENT_REFRESH_MISS; processMiss(); - } else if (r->protocol == PROTO_HTTP) { + } else if (r->protocol == AnyP::PROTO_HTTP) { /* * Object needs to be revalidated * XXX This could apply to FTP as well, if Last-Modified is known. @@ -658,7 +658,7 @@ clientReplyContext::processMiss() /** Check for internal requests. Update Protocol info if so. */ if (http->flags.internal) - r->protocol = PROTO_INTERNAL; + r->protocol = AnyP::PROTO_INTERNAL; r->clientConnection = http->getConn(); @@ -1504,7 +1504,7 @@ clientReplyContext::cloneReply() reply = HTTPMSGLOCK(rep); - if (reply->sline.protocol == PROTO_HTTP) { + 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); } @@ -2148,7 +2148,7 @@ clientReplyContext::createStoreEntry(const HttpRequestMethod& m, request_flags r */ if (http->request == NULL) - http->request = HTTPMSGLOCK(new HttpRequest(m, PROTO_NONE, null_string)); + http->request = HTTPMSGLOCK(new HttpRequest(m, AnyP::PROTO_NONE, null_string)); StoreEntry *e = storeCreateEntry(http->uri, http->log_uri, reqFlags, m); diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 28eef99dcb..bc68a93ebb 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -763,19 +763,18 @@ clientHierarchical(ClientHttpRequest * http) if (request->flags.loopdetect) return 0; - if (request->protocol == PROTO_HTTP) + if (request->protocol == AnyP::PROTO_HTTP) return httpCachable(method); - if (request->protocol == PROTO_GOPHER) + if (request->protocol == AnyP::PROTO_GOPHER) return gopherCachable(request); - if (request->protocol == PROTO_CACHEOBJ) + if (request->protocol == AnyP::PROTO_CACHEOBJ) return 0; return 1; } - static void clientCheckPinning(ClientHttpRequest * http) { diff --git a/src/enums.h b/src/enums.h index 0e9a41113d..3422976307 100644 --- a/src/enums.h +++ b/src/enums.h @@ -143,25 +143,6 @@ typedef enum { STORE_DISK_CLIENT } store_client_t; -typedef enum { - PROTO_NONE, - PROTO_HTTP, - PROTO_FTP, - PROTO_GOPHER, - PROTO_WAIS, - PROTO_CACHEOBJ, - PROTO_ICP, -#if USE_HTCP - PROTO_HTCP, -#endif - PROTO_URN, - PROTO_WHOIS, - PROTO_INTERNAL, - PROTO_HTTPS, - PROTO_ICY, - PROTO_MAX -} protocol_t; - /* * These are for StoreEntry->flag, which is defined as a SHORT * diff --git a/src/errorpage.cc b/src/errorpage.cc index 7284041a77..c2479a4d97 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -808,7 +808,7 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion case 'P': if (request) { - p = ProtocolStr[request->protocol]; + p = AnyP::ProtocolType_str[request->protocol]; } else if (!building_deny_info_url) { p = "[unknown protocol]"; } diff --git a/src/external_acl.cc b/src/external_acl.cc index 24fefaaef6..dff0ea91d5 100644 --- a/src/external_acl.cc +++ b/src/external_acl.cc @@ -954,7 +954,7 @@ makeExternalAclKey(ACLFilledChecklist * ch, external_acl_data * acl_data) break; case _external_acl_format::EXT_ACL_PROTO: - str = ProtocolStr[request->protocol]; + str = AnyP::ProtocolType_str[request->protocol]; break; case _external_acl_format::EXT_ACL_PORT: diff --git a/src/forward.cc b/src/forward.cc index 930a110629..baf01c6383 100644 --- a/src/forward.cc +++ b/src/forward.cc @@ -203,7 +203,7 @@ FwdState::fwdStart(int client_fd, StoreEntry *entry, HttpRequest *request) */ if ( Config.accessList.miss && !request->client_addr.IsNoAddr() && - request->protocol != PROTO_INTERNAL && request->protocol != PROTO_CACHEOBJ) { + request->protocol != AnyP::PROTO_INTERNAL && request->protocol != AnyP::PROTO_CACHEOBJ) { /** * Check if this host is allowed to fetch MISSES from us (miss_access) */ @@ -247,15 +247,15 @@ FwdState::fwdStart(int client_fd, StoreEntry *entry, HttpRequest *request) switch (request->protocol) { - case PROTO_INTERNAL: + case AnyP::PROTO_INTERNAL: internalStart(request, entry); return; - case PROTO_CACHEOBJ: + case AnyP::PROTO_CACHEOBJ: CacheManager::GetInstance()->Start(client_fd, request, entry); return; - case PROTO_URN: + case AnyP::PROTO_URN: urnStart(request, entry); return; @@ -752,7 +752,7 @@ FwdState::connectDone(int aServerFD, const DnsLookupDetails &dns, comm_err_t sta #if USE_SSL if ((fs->_peer && fs->_peer->use_ssl) || - (!fs->_peer && request->protocol == PROTO_HTTPS)) { + (!fs->_peer && request->protocol == AnyP::PROTO_HTTPS)) { initiateSSL(); return; } @@ -1069,36 +1069,36 @@ FwdState::dispatch() switch (request->protocol) { #if USE_SSL - case PROTO_HTTPS: + case AnyP::PROTO_HTTPS: httpStart(this); break; #endif - case PROTO_HTTP: + case AnyP::PROTO_HTTP: httpStart(this); break; - case PROTO_GOPHER: + case AnyP::PROTO_GOPHER: gopherStart(this); break; - case PROTO_FTP: + case AnyP::PROTO_FTP: ftpStart(this); break; - case PROTO_CACHEOBJ: + case AnyP::PROTO_CACHEOBJ: - case PROTO_INTERNAL: + case AnyP::PROTO_INTERNAL: - case PROTO_URN: + case AnyP::PROTO_URN: fatal_dump("Should never get here"); break; - case PROTO_WHOIS: + case AnyP::PROTO_WHOIS: whoisStart(this); break; - case PROTO_WAIS: /* Not implemented */ + case AnyP::PROTO_WAIS: /* Not implemented */ default: debugs(17, 1, "fwdDispatch: Cannot retrieve '" << entry->url() << "'" ); diff --git a/src/ftp.cc b/src/ftp.cc index 752c2ebf60..8490922705 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1471,7 +1471,7 @@ FtpStateData::buildTitleUrl() title_url.append(request->GetHost()); - if (request->port != urlDefaultPort(PROTO_FTP)) { + if (request->port != urlDefaultPort(AnyP::PROTO_FTP)) { title_url.append(":"); title_url.append(xitoa(request->port)); } @@ -1493,7 +1493,7 @@ FtpStateData::buildTitleUrl() base_href.append(request->GetHost()); - if (request->port != urlDefaultPort(PROTO_FTP)) { + if (request->port != urlDefaultPort(AnyP::PROTO_FTP)) { base_href.append(":"); base_href.append(xitoa(request->port)); } @@ -3773,7 +3773,7 @@ ftpUrlWith2f(HttpRequest * request) { String newbuf = "%2f"; - if (request->protocol != PROTO_FTP) + if (request->protocol != AnyP::PROTO_FTP) return NULL; if ( request->urlpath[0]=='/' ) { diff --git a/src/http.cc b/src/http.cc index d33e4b1d39..87718c7f61 100644 --- a/src/http.cc +++ b/src/http.cc @@ -717,14 +717,14 @@ HttpStateData::processReplyHeader() newrep->removeStaleWarnings(); - if (newrep->sline.protocol == PROTO_HTTP && newrep->sline.status >= 100 && newrep->sline.status < 200) { + if (newrep->sline.protocol == AnyP::PROTO_HTTP && newrep->sline.status >= 100 && newrep->sline.status < 200) { handle1xx(newrep); ctx_exit(ctx); return; } flags.chunked = 0; - if (newrep->sline.protocol == PROTO_HTTP && newrep->header.chunked()) { + if (newrep->sline.protocol == AnyP::PROTO_HTTP && newrep->header.chunked()) { flags.chunked = 1; httpChunkDecoder = new ChunkedCodingParser; } @@ -1816,7 +1816,7 @@ HttpStateData::httpBuildRequestHeader(HttpRequest * request, /* append Front-End-Https */ if (flags.front_end_https) { - if (flags.front_end_https == 1 || request->protocol == PROTO_HTTPS) + if (flags.front_end_https == 1 || request->protocol == AnyP::PROTO_HTTPS) hdr_out->putStr(HDR_FRONT_END_HTTPS, "On"); } diff --git a/src/icp_v2.cc b/src/icp_v2.cc index 2f1d326517..fe4b956c5a 100644 --- a/src/icp_v2.cc +++ b/src/icp_v2.cc @@ -214,7 +214,7 @@ icpLogIcp(const Ip::Address &caddr, log_type logcode, int len, const char *url, if (LOG_ICP_QUERY == logcode) return; - clientdbUpdate(caddr, logcode, PROTO_ICP, len); + clientdbUpdate(caddr, logcode, AnyP::PROTO_ICP, len); if (!Config.onoff.log_udp) return; @@ -425,7 +425,7 @@ icpDenyAccess(Ip::Address &from, char *url, int reqnum, int fd) * count this DENIED query in the clientdb, even though * we're not sending an ICP reply... */ - clientdbUpdate(from, LOG_UDP_DENIED, PROTO_ICP, 0); + clientdbUpdate(from, LOG_UDP_DENIED, AnyP::PROTO_ICP, 0); } else { icpCreateAndSend(ICP_DENIED, 0, url, reqnum, 0, fd, from); } diff --git a/src/internal.cc b/src/internal.cc index f7e7757904..765d67f3ce 100644 --- a/src/internal.cc +++ b/src/internal.cc @@ -125,7 +125,7 @@ internalRemoteUri(const char *host, u_short port, const char *dir, const char *n mb.Printf("http://%s", lc_host); /* append port if not default */ - if (port && port != urlDefaultPort(PROTO_HTTP)) + if (port && port != urlDefaultPort(AnyP::PROTO_HTTP)) mb.Printf(":%d", port); if (dir) diff --git a/src/neighbors.cc b/src/neighbors.cc index caacb55d12..b1ac1f97c2 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -1093,14 +1093,14 @@ neighborsUdpAck(const cache_key * key, icp_common_t * header, const Ip::Address if (p == NULL) { neighborIgnoreNonPeer(from, opcode); } else { - mem->ping_reply_callback(p, ntype, PROTO_ICP, header, mem->ircb_data); + mem->ping_reply_callback(p, ntype, AnyP::PROTO_ICP, header, mem->ircb_data); } } else if (opcode == ICP_HIT) { if (p == NULL) { neighborIgnoreNonPeer(from, opcode); } else { header->opcode = ICP_HIT; - mem->ping_reply_callback(p, ntype, PROTO_ICP, header, mem->ircb_data); + mem->ping_reply_callback(p, ntype, AnyP::PROTO_ICP, header, mem->ircb_data); } } else if (opcode == ICP_DECHO) { if (p == NULL) { @@ -1109,7 +1109,7 @@ neighborsUdpAck(const cache_key * key, icp_common_t * header, const Ip::Address debug_trap("neighborsUdpAck: Found non-ICP cache as SIBLING\n"); debug_trap("neighborsUdpAck: non-ICP neighbors must be a PARENT\n"); } else { - mem->ping_reply_callback(p, ntype, PROTO_ICP, header, mem->ircb_data); + mem->ping_reply_callback(p, ntype, AnyP::PROTO_ICP, header, mem->ircb_data); } } else if (opcode == ICP_SECHO) { if (p) { @@ -1132,7 +1132,7 @@ neighborsUdpAck(const cache_key * key, icp_common_t * header, const Ip::Address } } } else if (opcode == ICP_MISS_NOFETCH) { - mem->ping_reply_callback(p, ntype, PROTO_ICP, header, mem->ircb_data); + mem->ping_reply_callback(p, ntype, AnyP::PROTO_ICP, header, mem->ircb_data); } else { debugs(15, 0, "neighborsUdpAck: Unexpected ICP reply: " << opcode_d); } @@ -1523,7 +1523,7 @@ peerCountMcastPeersDone(void *data) } static void -peerCountHandleIcpReply(peer * p, peer_t type, protocol_t proto, void *hdrnotused, void *data) +peerCountHandleIcpReply(peer * p, peer_t type, AnyP::ProtocolType proto, void *hdrnotused, void *data) { int rtt_av_factor; @@ -1531,7 +1531,7 @@ peerCountHandleIcpReply(peer * p, peer_t type, protocol_t proto, void *hdrnotuse StoreEntry *fake = psstate->entry; MemObject *mem = fake->mem_obj; int rtt = tvSubMsec(mem->start_ping, current_time); - assert(proto == PROTO_ICP); + assert(proto == AnyP::PROTO_ICP); assert(fake); assert(mem); psstate->ping.n_recv++; @@ -1838,7 +1838,7 @@ neighborsHtcpReply(const cache_key * key, htcpReplyData * htcp, const Ip::Addres } debugs(15, 3, "neighborsHtcpReply: e = " << e); - mem->ping_reply_callback(p, ntype, PROTO_HTCP, htcp, mem->ircb_data); + mem->ping_reply_callback(p, ntype, AnyP::PROTO_HTCP, htcp, mem->ircb_data); } /* diff --git a/src/peer_select.cc b/src/peer_select.cc index 84117d86c5..8715991aad 100644 --- a/src/peer_select.cc +++ b/src/peer_select.cc @@ -497,7 +497,7 @@ peerGetSomeDirect(ps_state * ps) return; /* WAIS is not implemented natively */ - if (ps->request->protocol == PROTO_WAIS) + if (ps->request->protocol == AnyP::PROTO_WAIS) return; peerAddFwdServer(&ps->servers, NULL, HIER_DIRECT); @@ -745,20 +745,20 @@ peerHtcpParentMiss(peer * p, htcpReplyData * htcp, ps_state * ps) #endif static void -peerHandlePingReply(peer * p, peer_t type, protocol_t proto, void *pingdata, void *data) +peerHandlePingReply(peer * p, peer_t type, AnyP::ProtocolType proto, void *pingdata, void *data) { - if (proto == PROTO_ICP) + if (proto == AnyP::PROTO_ICP) peerHandleIcpReply(p, type, (icp_common_t *)pingdata, data); #if USE_HTCP - else if (proto == PROTO_HTCP) + else if (proto == AnyP::PROTO_HTCP) peerHandleHtcpReply(p, type, (htcpReplyData *)pingdata, data); #endif else - debugs(44, 1, "peerHandlePingReply: unknown protocol_t " << proto); + debugs(44, 1, "peerHandlePingReply: unknown protocol " << proto); } static void diff --git a/src/protos.h b/src/protos.h index e1b99ed702..acd7411f3b 100644 --- a/src/protos.h +++ b/src/protos.h @@ -84,7 +84,8 @@ SQUIDCEXTERN void parse_time_t(time_t * var); SQUIDCEXTERN void clientdbInit(void); -SQUIDCEXTERN void clientdbUpdate(const Ip::Address &, log_type, protocol_t, size_t); +#include "anyp/ProtocolType.h" +SQUIDCEXTERN void clientdbUpdate(const Ip::Address &, log_type, AnyP::ProtocolType, size_t); SQUIDCEXTERN int clientdbCutoffDenied(const Ip::Address &); void clientdbDump(StoreEntry *); @@ -614,7 +615,7 @@ SQUIDCEXTERN void unlinkdClose(void); SQUIDCEXTERN void unlinkdUnlink(const char *); #endif -SQUIDCEXTERN protocol_t urlParseProtocol(const char *, const char *e = NULL); +SQUIDCEXTERN AnyP::ProtocolType urlParseProtocol(const char *, const char *e = NULL); SQUIDCEXTERN void urlInitialize(void); SQUIDCEXTERN HttpRequest *urlParse(const HttpRequestMethod&, char *, HttpRequest *request = NULL); SQUIDCEXTERN const char *urlCanonical(HttpRequest *); @@ -626,7 +627,7 @@ SQUIDCEXTERN char *urlRInternal(const char *host, u_short port, const char *dir, SQUIDCEXTERN char *urlInternal(const char *dir, const char *name); SQUIDCEXTERN int matchDomainName(const char *host, const char *domain); SQUIDCEXTERN int urlCheckRequest(const HttpRequest *); -SQUIDCEXTERN int urlDefaultPort(protocol_t p); +SQUIDCEXTERN int urlDefaultPort(AnyP::ProtocolType p); SQUIDCEXTERN char *urlHostname(const char *url); SQUIDCEXTERN void urlExtMethodConfigure(void); diff --git a/src/tests/stub_HttpRequest.cc b/src/tests/stub_HttpRequest.cc index 94c0142982..51b97f7805 100644 --- a/src/tests/stub_HttpRequest.cc +++ b/src/tests/stub_HttpRequest.cc @@ -41,7 +41,7 @@ HttpRequest::HttpRequest() : HttpMsg(hoRequest) fatal("Not implemented"); } -HttpRequest::HttpRequest(const HttpRequestMethod& method, protocol_t protocol, const char *aUrlpath) : HttpMsg(hoRequest) +HttpRequest::HttpRequest(const HttpRequestMethod& method, AnyP::ProtocolType protocol, const char *aUrlpath) : HttpMsg(hoRequest) { fatal("Not implemented"); } @@ -82,7 +82,7 @@ HttpRequest::expectingBody(const HttpRequestMethod& unused, int64_t&) const } void -HttpRequest::initHTTP(const HttpRequestMethod& aMethod, protocol_t aProtocol, const char *aUrlpath) +HttpRequest::initHTTP(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *aUrlpath) { fatal("Not implemented"); } diff --git a/src/tests/testHttpRequest.cc b/src/tests/testHttpRequest.cc index 0ca95d8334..04ea216913 100644 --- a/src/tests/testHttpRequest.cc +++ b/src/tests/testHttpRequest.cc @@ -42,7 +42,7 @@ testHttpRequest::testCreateFromUrlAndMethod() CPPUNIT_ASSERT(aRequest->method == METHOD_GET); CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest->GetHost())); CPPUNIT_ASSERT_EQUAL(String("/bar"), aRequest->urlpath); - CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, aRequest->protocol); CPPUNIT_ASSERT_EQUAL(String("http://foo:90/bar"), String(url)); xfree(url); @@ -54,7 +54,7 @@ testHttpRequest::testCreateFromUrlAndMethod() CPPUNIT_ASSERT(aRequest->method == METHOD_PUT); CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest->GetHost())); CPPUNIT_ASSERT_EQUAL(String("/bar"), aRequest->urlpath); - CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, aRequest->protocol); CPPUNIT_ASSERT_EQUAL(String("http://foo/bar"), String(url)); /* a connect url with non-CONNECT data */ @@ -71,7 +71,7 @@ testHttpRequest::testCreateFromUrlAndMethod() CPPUNIT_ASSERT(aRequest->method == METHOD_CONNECT); CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest->GetHost())); CPPUNIT_ASSERT_EQUAL(String(""), aRequest->urlpath); - CPPUNIT_ASSERT_EQUAL(PROTO_NONE, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE, aRequest->protocol); CPPUNIT_ASSERT_EQUAL(String("foo:45"), String(url)); xfree(url); } @@ -91,7 +91,7 @@ testHttpRequest::testCreateFromUrl() CPPUNIT_ASSERT(aRequest->method == METHOD_GET); CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest->GetHost())); CPPUNIT_ASSERT_EQUAL(String("/bar"), aRequest->urlpath); - CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, aRequest->protocol); CPPUNIT_ASSERT_EQUAL(String("http://foo:90/bar"), String(url)); xfree(url); } @@ -114,7 +114,7 @@ testHttpRequest::testIPv6HostColonBug() CPPUNIT_ASSERT(aRequest->method == METHOD_GET); CPPUNIT_ASSERT_EQUAL(String("[2000:800::45]"), String(aRequest->GetHost())); CPPUNIT_ASSERT_EQUAL(String("/foo"), aRequest->urlpath); - CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, aRequest->protocol); CPPUNIT_ASSERT_EQUAL(String("http://[2000:800::45]/foo"), String(url)); xfree(url); @@ -126,7 +126,7 @@ testHttpRequest::testIPv6HostColonBug() CPPUNIT_ASSERT(aRequest->method == METHOD_GET); CPPUNIT_ASSERT_EQUAL(String("[2000:800::45]"), String(aRequest->GetHost())); CPPUNIT_ASSERT_EQUAL(String("/foo"), aRequest->urlpath); - CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, aRequest->protocol); CPPUNIT_ASSERT_EQUAL(String("http://[2000:800::45]:90/foo"), String(url)); xfree(url); @@ -138,7 +138,7 @@ testHttpRequest::testIPv6HostColonBug() CPPUNIT_ASSERT(aRequest->method == METHOD_GET); CPPUNIT_ASSERT_EQUAL(String("[2000:800::45]"), String(aRequest->GetHost())); CPPUNIT_ASSERT_EQUAL(String("/foo"), aRequest->urlpath); - CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, aRequest->protocol); CPPUNIT_ASSERT_EQUAL(String("http://2000:800::45/foo"), String(url)); xfree(url); } diff --git a/src/tests/testURL.cc b/src/tests/testURL.cc index aba0f174c4..a9adf6aca1 100644 --- a/src/tests/testURL.cc +++ b/src/tests/testURL.cc @@ -29,11 +29,11 @@ void testURL::testConstructScheme() { URLScheme empty_scheme; - URL protoless_url(PROTO_NONE); + URL protoless_url(AnyP::PROTO_NONE); CPPUNIT_ASSERT_EQUAL(empty_scheme, protoless_url.getScheme()); - URLScheme ftp_scheme(PROTO_FTP); - URL ftp_url(PROTO_FTP); + URLScheme ftp_scheme(AnyP::PROTO_FTP); + URL ftp_url(AnyP::PROTO_FTP); CPPUNIT_ASSERT_EQUAL(ftp_scheme, ftp_url.getScheme()); } diff --git a/src/tests/testURLScheme.cc b/src/tests/testURLScheme.cc index eebcbcd27d..dce1c4df50 100644 --- a/src/tests/testURLScheme.cc +++ b/src/tests/testURLScheme.cc @@ -55,11 +55,11 @@ testURLScheme::testAssignFromprotocol_t() { URLScheme empty_scheme; URLScheme scheme; - scheme = PROTO_NONE; + scheme = AnyP::PROTO_NONE; CPPUNIT_ASSERT_EQUAL(empty_scheme, scheme); - URLScheme https_scheme(PROTO_HTTPS); - scheme = PROTO_HTTPS; + URLScheme https_scheme(AnyP::PROTO_HTTPS); + scheme = AnyP::PROTO_HTTPS; CPPUNIT_ASSERT_EQUAL(https_scheme, scheme); } @@ -71,21 +71,21 @@ void testURLScheme::testCastToprotocol_t() { /* explicit cast */ - protocol_t protocol = (protocol_t) URLScheme(); - CPPUNIT_ASSERT_EQUAL(PROTO_NONE, protocol); + AnyP::ProtocolType protocol = static_cast(URLScheme()); + CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE, protocol); /* and implicit */ - protocol = URLScheme(PROTO_HTTP); - CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, protocol); + protocol = URLScheme(AnyP::PROTO_HTTP); + CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, protocol); } /* - * a default constructed URLScheme is == PROTO_NONE + * a default constructed URLScheme is == AnyP::PROTO_NONE */ void testURLScheme::testDefaultConstructor() { URLScheme lhs; - URLScheme rhs(PROTO_NONE); + URLScheme rhs(AnyP::PROTO_NONE); CPPUNIT_ASSERT_EQUAL(lhs, rhs); } @@ -95,10 +95,10 @@ testURLScheme::testDefaultConstructor() void testURLScheme::testConstructprotocol_t() { - URLScheme lhs_none(PROTO_NONE), rhs_none(PROTO_NONE); + URLScheme lhs_none(AnyP::PROTO_NONE), rhs_none(AnyP::PROTO_NONE); CPPUNIT_ASSERT_EQUAL(lhs_none, rhs_none); - URLScheme lhs_cacheobj(PROTO_CACHEOBJ), rhs_cacheobj(PROTO_CACHEOBJ); + URLScheme lhs_cacheobj(AnyP::PROTO_CACHEOBJ), rhs_cacheobj(AnyP::PROTO_CACHEOBJ); CPPUNIT_ASSERT_EQUAL(lhs_cacheobj, rhs_cacheobj); CPPUNIT_ASSERT(lhs_none != rhs_cacheobj); } @@ -110,7 +110,7 @@ void testURLScheme::testConst_str() { String lhs("wais"); - URLScheme wais(PROTO_WAIS); + URLScheme wais(AnyP::PROTO_WAIS); String rhs(wais.const_str()); CPPUNIT_ASSERT_EQUAL(lhs, rhs); } @@ -122,10 +122,10 @@ testURLScheme::testConst_str() void testURLScheme::testEqualprotocol_t() { - CPPUNIT_ASSERT(URLScheme() == PROTO_NONE); - CPPUNIT_ASSERT(not (URLScheme(PROTO_WAIS) == PROTO_HTTP)); - CPPUNIT_ASSERT(PROTO_HTTP == URLScheme(PROTO_HTTP)); - CPPUNIT_ASSERT(not (PROTO_CACHEOBJ == URLScheme(PROTO_HTTP))); + CPPUNIT_ASSERT(URLScheme() == AnyP::PROTO_NONE); + CPPUNIT_ASSERT(not (URLScheme(AnyP::PROTO_WAIS) == AnyP::PROTO_HTTP)); + CPPUNIT_ASSERT(AnyP::PROTO_HTTP == URLScheme(AnyP::PROTO_HTTP)); + CPPUNIT_ASSERT(not (AnyP::PROTO_CACHEOBJ == URLScheme(AnyP::PROTO_HTTP))); } /* @@ -134,10 +134,10 @@ testURLScheme::testEqualprotocol_t() void testURLScheme::testNotEqualprotocol_t() { - CPPUNIT_ASSERT(URLScheme(PROTO_NONE) != PROTO_HTTP); - CPPUNIT_ASSERT(not (URLScheme(PROTO_HTTP) != PROTO_HTTP)); - CPPUNIT_ASSERT(PROTO_NONE != URLScheme(PROTO_HTTP)); - CPPUNIT_ASSERT(not (PROTO_WAIS != URLScheme(PROTO_WAIS))); + CPPUNIT_ASSERT(URLScheme(AnyP::PROTO_NONE) != AnyP::PROTO_HTTP); + CPPUNIT_ASSERT(not (URLScheme(AnyP::PROTO_HTTP) != AnyP::PROTO_HTTP)); + CPPUNIT_ASSERT(AnyP::PROTO_NONE != URLScheme(AnyP::PROTO_HTTP)); + CPPUNIT_ASSERT(not (AnyP::PROTO_WAIS != URLScheme(AnyP::PROTO_WAIS))); } /* @@ -147,7 +147,7 @@ void testURLScheme::testStream() { std::ostringstream buffer; - buffer << URLScheme(PROTO_HTTP); + buffer << URLScheme(AnyP::PROTO_HTTP); String http_str("http"); String from_buf(buffer.str().c_str()); CPPUNIT_ASSERT_EQUAL(http_str, from_buf); diff --git a/src/typedefs.h b/src/typedefs.h index dcd614a9b0..44d14837e0 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -154,7 +154,9 @@ class DnsLookupDetails; typedef void FQDNH(const char *, const DnsLookupDetails &details, void *); typedef void IDCB(const char *ident, void *data); typedef void IPH(const ipcache_addrs *, const DnsLookupDetails &details, void *); -typedef void IRCB(struct peer *, peer_t, protocol_t, void *, void *data); + +#include "anyp/ProtocolType.h" +typedef void IRCB(struct peer *, peer_t, AnyP::ProtocolType, void *, void *data); class FwdServer; typedef void PSC(FwdServer *, void *); diff --git a/src/url.cc b/src/url.cc index 24d635412d..0da3b61984 100644 --- a/src/url.cc +++ b/src/url.cc @@ -40,7 +40,7 @@ #include "rfc1738.h" static HttpRequest *urlParseFinish(const HttpRequestMethod& method, - const protocol_t protocol, + const AnyP::ProtocolType protocol, const char *const urlpath, const char *const host, const char *const login, @@ -65,9 +65,9 @@ urlInitialize(void) { debugs(23, 5, "urlInitialize: Initializing..."); /* this ensures that the number of protocol strings is the same as - * the enum slots allocated because the last enum is always 'TOTAL'. + * the enum slots allocated because the last enum is always 'MAX'. */ - assert(strcmp(ProtocolStr[PROTO_MAX], "TOTAL") == 0); + assert(strcmp(AnyP::ProtocolType_str[AnyP::PROTO_MAX], "MAX") == 0); /* * These test that our matchDomainName() function works the * way we expect it to. @@ -97,7 +97,7 @@ urlInitialize(void) * backwards compatibility, e defaults to NULL, in which case we * assume b is NULL-terminated. */ -protocol_t +AnyP::ProtocolType urlParseProtocol(const char *b, const char *e) { /* @@ -114,64 +114,64 @@ urlParseProtocol(const char *b, const char *e) /* test common stuff first */ if (strncasecmp(b, "http", len) == 0) - return PROTO_HTTP; + return AnyP::PROTO_HTTP; if (strncasecmp(b, "ftp", len) == 0) - return PROTO_FTP; + return AnyP::PROTO_FTP; if (strncasecmp(b, "https", len) == 0) - return PROTO_HTTPS; + return AnyP::PROTO_HTTPS; if (strncasecmp(b, "file", len) == 0) - return PROTO_FTP; + return AnyP::PROTO_FTP; if (strncasecmp(b, "gopher", len) == 0) - return PROTO_GOPHER; + return AnyP::PROTO_GOPHER; if (strncasecmp(b, "wais", len) == 0) - return PROTO_WAIS; + return AnyP::PROTO_WAIS; if (strncasecmp(b, "cache_object", len) == 0) - return PROTO_CACHEOBJ; + return AnyP::PROTO_CACHEOBJ; if (strncasecmp(b, "urn", len) == 0) - return PROTO_URN; + return AnyP::PROTO_URN; if (strncasecmp(b, "whois", len) == 0) - return PROTO_WHOIS; + return AnyP::PROTO_WHOIS; if (strncasecmp(b, "internal", len) == 0) - return PROTO_INTERNAL; + return AnyP::PROTO_INTERNAL; - return PROTO_NONE; + return AnyP::PROTO_NONE; } int -urlDefaultPort(protocol_t p) +urlDefaultPort(AnyP::ProtocolType p) { switch (p) { - case PROTO_HTTP: + case AnyP::PROTO_HTTP: return 80; - case PROTO_HTTPS: + case AnyP::PROTO_HTTPS: return 443; - case PROTO_FTP: + case AnyP::PROTO_FTP: return 21; - case PROTO_GOPHER: + case AnyP::PROTO_GOPHER: return 70; - case PROTO_WAIS: + case AnyP::PROTO_WAIS: return 210; - case PROTO_CACHEOBJ: + case AnyP::PROTO_CACHEOBJ: - case PROTO_INTERNAL: + case AnyP::PROTO_INTERNAL: return CACHE_HTTP_PORT; - case PROTO_WHOIS: + case AnyP::PROTO_WHOIS: return 43; default: @@ -210,7 +210,7 @@ urlParse(const HttpRequestMethod& method, char *url, HttpRequest *request) char *t = NULL; char *q = NULL; int port; - protocol_t protocol = PROTO_NONE; + AnyP::ProtocolType protocol = AnyP::PROTO_NONE; int l; int i; const char *src; @@ -232,7 +232,7 @@ urlParse(const HttpRequestMethod& method, char *url, HttpRequest *request) } else if ((method == METHOD_OPTIONS || method == METHOD_TRACE) && strcmp(url, "*") == 0) { - protocol = PROTO_HTTP; + protocol = AnyP::PROTO_HTTP; port = urlDefaultPort(protocol); return urlParseFinish(method, protocol, url, host, login, port, request); } else if (!strncmp(url, "urn:", 4)) { @@ -425,7 +425,7 @@ urlParse(const HttpRequestMethod& method, char *url, HttpRequest *request) */ static HttpRequest * urlParseFinish(const HttpRequestMethod& method, - const protocol_t protocol, + const AnyP::ProtocolType protocol, const char *const urlpath, const char *const host, const char *const login, @@ -448,7 +448,7 @@ static HttpRequest * urnParse(const HttpRequestMethod& method, char *urn) { debugs(50, 5, "urnParse: " << urn); - return new HttpRequest(method, PROTO_URN, urn + 4); + return new HttpRequest(method, AnyP::PROTO_URN, urn + 4); } const char * @@ -461,7 +461,7 @@ urlCanonical(HttpRequest * request) if (request->canonical) return request->canonical; - if (request->protocol == PROTO_URN) { + if (request->protocol == AnyP::PROTO_URN) { snprintf(urlbuf, MAX_URL, "urn:" SQUIDSTRINGPH, SQUIDSTRINGPRINT(request->urlpath)); } else { @@ -478,8 +478,9 @@ urlCanonical(HttpRequest * request) if (request->port != urlDefaultPort(request->protocol)) snprintf(portbuf, 32, ":%d", request->port); + const URLScheme sch = request->protocol; // temporary, until bug 1961 URL handling is fixed. snprintf(urlbuf, MAX_URL, "%s://%s%s%s%s" SQUIDSTRINGPH, - ProtocolStr[request->protocol], + sch.const_str(), request->login, *request->login ? "@" : null_string, request->GetHost(), @@ -505,7 +506,7 @@ urlCanonicalClean(const HttpRequest * request) LOCAL_ARRAY(char, loginbuf, MAX_LOGIN_SZ + 1); char *t; - if (request->protocol == PROTO_URN) { + if (request->protocol == AnyP::PROTO_URN) { snprintf(buf, MAX_URL, "urn:" SQUIDSTRINGPH, SQUIDSTRINGPRINT(request->urlpath)); } else { @@ -535,8 +536,9 @@ urlCanonicalClean(const HttpRequest * request) strcat(loginbuf, "@"); } + const URLScheme sch = request->protocol; // temporary, until bug 1961 URL handling is fixed. snprintf(buf, MAX_URL, "%s://%s%s%s" SQUIDSTRINGPH, - ProtocolStr[request->protocol], + sch.const_str(), loginbuf, request->GetHost(), portbuf, @@ -630,7 +632,7 @@ urlMakeAbsolute(const HttpRequest * req, const char *relUrl) char *urlbuf = (char *)xmalloc(MAX_URL * sizeof(char)); - if (req->protocol == PROTO_URN) { + if (req->protocol == AnyP::PROTO_URN) { snprintf(urlbuf, MAX_URL, "urn:" SQUIDSTRINGPH, SQUIDSTRINGPRINT(req->urlpath)); return (urlbuf); @@ -638,9 +640,10 @@ urlMakeAbsolute(const HttpRequest * req, const char *relUrl) size_t urllen; + const URLScheme sch = req->protocol; // temporary, until bug 1961 URL handling is fixed. if (req->port != urlDefaultPort(req->protocol)) { urllen = snprintf(urlbuf, MAX_URL, "%s://%s%s%s:%d", - ProtocolStr[req->protocol], + sch.const_str(), req->login, *req->login ? "@" : null_string, req->GetHost(), @@ -648,7 +651,7 @@ urlMakeAbsolute(const HttpRequest * req, const char *relUrl) ); } else { urllen = snprintf(urlbuf, MAX_URL, "%s://%s%s%s", - ProtocolStr[req->protocol], + sch.const_str(), req->login, *req->login ? "@" : null_string, req->GetHost() @@ -808,24 +811,24 @@ urlCheckRequest(const HttpRequest * r) /* does method match the protocol? */ switch (r->protocol) { - case PROTO_URN: + case AnyP::PROTO_URN: - case PROTO_HTTP: + case AnyP::PROTO_HTTP: - case PROTO_CACHEOBJ: + case AnyP::PROTO_CACHEOBJ: rc = 1; break; - case PROTO_FTP: + case AnyP::PROTO_FTP: if (r->method == METHOD_PUT) rc = 1; - case PROTO_GOPHER: + case AnyP::PROTO_GOPHER: - case PROTO_WAIS: + case AnyP::PROTO_WAIS: - case PROTO_WHOIS: + case AnyP::PROTO_WHOIS: if (r->method == METHOD_GET) rc = 1; else if (r->method == METHOD_HEAD) @@ -833,7 +836,7 @@ urlCheckRequest(const HttpRequest * r) break; - case PROTO_HTTPS: + case AnyP::PROTO_HTTPS: #if USE_SSL rc = 1;