]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
SourceLayout: protocol_t upgrade
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 2 Mar 2011 07:27:24 +0000 (00:27 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 2 Mar 2011 07:27:24 +0000 (00:27 -0700)
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.

38 files changed:
configure.ac
src/AclRegs.cc
src/HttpMsg.cc
src/HttpMsg.h
src/HttpRequest.cc
src/HttpRequest.h
src/HttpStatusLine.cc
src/HttpStatusLine.h
src/Makefile.am
src/URLScheme.cc
src/URLScheme.h
src/acl/Protocol.cc
src/acl/Protocol.h
src/acl/ProtocolData.cc
src/acl/ProtocolData.h
src/anyp/Makefile.am [new file with mode: 0644]
src/anyp/ProtocolType.h [new file with mode: 0644]
src/client_db.cc
src/client_side.cc
src/client_side_reply.cc
src/client_side_request.cc
src/enums.h
src/errorpage.cc
src/external_acl.cc
src/forward.cc
src/ftp.cc
src/http.cc
src/icp_v2.cc
src/internal.cc
src/neighbors.cc
src/peer_select.cc
src/protos.h
src/tests/stub_HttpRequest.cc
src/tests/testHttpRequest.cc
src/tests/testURL.cc
src/tests/testURLScheme.cc
src/typedefs.h
src/url.cc

index 8a36faa871336b4d7ac16b8ac2f6cd0bdc70ee51..1fcc3b6d84c2c45a2b8f806526c6d44054e75230 100644 (file)
@@ -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 \
index 5c3ef645b9356b5b48cd520dc4c98e39117171c3..3f4a00789ba911a85c1c9968e2d4f3a07f93da6d 100644 (file)
@@ -110,7 +110,7 @@ ACLStrategised<const char *> ACLMyPortName::RegistryEntry_(new ACLStringData, AC
 ACL::Prototype ACLPeerName::RegistryProtoype(&ACLPeerName::RegistryEntry_, "peername");
 ACLStrategised<const char *> ACLPeerName::RegistryEntry_(new ACLStringData, ACLPeerNameStrategy::Instance(), "peername");
 ACL::Prototype ACLProtocol::RegistryProtoype(&ACLProtocol::RegistryEntry_, "proto");
-ACLStrategised<protocol_t> ACLProtocol::RegistryEntry_(new ACLProtocolData, ACLProtocolStrategy::Instance(), "proto");
+ACLStrategised<AnyP::ProtocolType> 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");
index 276ca59acffb66b9067c253ece0483a0276c459d..9c9f5c6a908085ce54432290348cd53330eba24d 100644 (file)
@@ -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)
 {}
 
index 12b8c7484e8e4b1c654801b48d5216301a99c12c..736ec4fb3d5c7b87c2f3b11055fb4b76bb576192 100644 (file)
@@ -89,7 +89,7 @@ public:
 
     int64_t content_length;
 
-    protocol_t protocol;
+    AnyP::ProtocolType protocol;
 
     HttpMsgParseState pstate;   /* the current parsing state */
 
index ad3a74cf6945dab6d5fc1a84c8f05bc4c23bcdcf..3d5400c4b95c891e2dc263065ee993ad757e524c 100644 (file)
@@ -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;
index 1baa1488b1c4e3ada45bfd4da7996050f238fe53..6fed46a1a09fc7b53d11d1b6ea6f03db0bb9d400 100644 (file)
@@ -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<HttpRequest*>(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;
 
index 63e5402064b0c0239e3dbc0d34549b5bcda2a4e0..eda2844c812f6204b8794b7223f1beafdf88b02d 100644 (file)
@@ -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) {
 
index d5dcb7814875e31b80a75238c0545d1af06191ce..d9022eab126212282bcc7fdb6b6629785f01f58c 100644 (file)
 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
index 10cc2871853204117c1097155bb3ebd2fe9effc0..cccc2b1ac56dd1c82b85c2a442a5368599f03cde 100644 (file)
@@ -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 \
index 5c3aba354f85f16ce7543b3ec15b9965868774a2..66aef0225e02056b3e8ae2580e1f2735136d50a7 100644 (file)
  *
  */
 
-#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;
+}
index 38b4e43cd3f0611d5897c23892d1fc9c3d79fa00..77c68158159270562cbfa2c2c08ff4da1f925a8b 100644 (file)
 #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 <iosfwd>
+#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 &
index 3ed48a51266e282b74629673d1beaf227c54a804..6d0a4e0a6e671c721693827fc52b61d3049fc0b8 100644 (file)
@@ -41,7 +41,7 @@
 
 /* explicit template instantiation required for some systems */
 
-template class ACLStrategised<protocol_t>;
+template class ACLStrategised<AnyP::ProtocolType>;
 
 
 
index e6a935db1b6c95933c4d8fa31ca8188c489947b5..3b54f339859e8a8a4e2decf834583bdf06134aa7 100644 (file)
 
 #ifndef SQUID_ACLPROTOCOL_H
 #define SQUID_ACLPROTOCOL_H
+
 #include "acl/Strategy.h"
 #include "acl/Strategised.h"
+#include "anyp/ProtocolType.h"
 
-class ACLProtocolStrategy : public ACLStrategy<protocol_t>
+class ACLProtocolStrategy : public ACLStrategy<AnyP::ProtocolType>
 {
 
 public:
@@ -63,7 +65,7 @@ class ACLProtocol
 
 private:
     static ACL::Prototype RegistryProtoype;
-    static ACLStrategised<protocol_t> RegistryEntry_;
+    static ACLStrategised<AnyP::ProtocolType> RegistryEntry_;
 };
 
 #endif /* SQUID_ACLPROTOCOL_H */
index 6fef08809226b664cdb6ff342843fa0b141b61e1..b73a4d9b56ab76b57b80a8f71fa9f1024ced4f1f 100644 (file)
@@ -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<protocol_t>::CBDATA_CbDataList;
+template cbdata_type CbDataList<AnyP::ProtocolType>::CBDATA_CbDataList;
 /// \endcond
 
 wordlist *
 ACLProtocolData::dump()
 {
     wordlist *W = NULL;
-    CbDataList<protocol_t> *data = values;
+    CbDataList<AnyP::ProtocolType> *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<protocol_t> **Tail;
+    CbDataList<AnyP::ProtocolType> **Tail;
     char *t = NULL;
 
     for (Tail = &values; *Tail; Tail = &((*Tail)->next));
     while ((t = strtokFile())) {
-        CbDataList<protocol_t> *q = new CbDataList<protocol_t> (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<AnyP::ProtocolType> *q = new CbDataList<AnyP::ProtocolType>(static_cast<AnyP::ProtocolType>(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<protocol_t> *
+ACLData<AnyP::ProtocolType> *
 ACLProtocolData::clone() const
 {
     /* Splay trees don't clone yet. */
index af987469140663bcc657c5036e35804f783f88ea..dbec63d1ae936b5679e882ad8a93cafbf6a53393 100644 (file)
 
 #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<protocol_t>
+class ACLProtocolData : public ACLData<AnyP::ProtocolType>
 {
 
 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<protocol_t> *clone() const;
+    virtual ACLData<AnyP::ProtocolType> *clone() const;
 
-    CbDataList<protocol_t> *values;
+    CbDataList<AnyP::ProtocolType> *values;
 };
 
 MEMPROXY_CLASS_INLINE(ACLProtocolData);
diff --git a/src/anyp/Makefile.am b/src/anyp/Makefile.am
new file mode 100644 (file)
index 0000000..c8cd4a8
--- /dev/null
@@ -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 (file)
index 0000000..031f47c
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef _SQUID_SRC_ANYP_PROTOCOLTYPE_H
+#define _SQUID_SRC_ANYP_PROTOCOLTYPE_H
+
+#if HAVE_OSTREAM
+#include <ostream>
+#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<int>(p);
+    return os;
+}
+
+} // namespace AnyP
+
+#endif /* _SQUID_SRC_ANYP_PROTOCOLTYPE_H */
index 90e5d513556f1f14cd6cd0e8ca6c92c43e68ca0d..6d64c8410a324f258f1ad4e47bf937b689ddf260 100644 (file)
@@ -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);
index 0fcd5bd20e5f6291a2cf4863d03d3817947e1d9c..30efedc5ad2ed4f4bfa9d5c88712d4522cf166ac 100644 (file)
@@ -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';
     }
 
index 7425d7378437cd6bb9fbfeda20045fd4edc46d76..6b0fa67ace9bb874449ef1dea472909715175f7b 100644 (file)
@@ -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);
 
index 28eef99dcba305a774fbe1aff525bcd111194650..bc68a93ebbc913ec41d9c38d369c91032f2ad50a 100644 (file)
@@ -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)
 {
index 0e9a41113d9dcc1b295da40e4caff899581244b6..3422976307ca7c19cf83cd4187385a0eedbf2041 100644 (file)
@@ -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
  *
index 7284041a770c4b831620068ac17eebcf5d107bdb..c2479a4d9738957bf540344bfab3da8f9ba728b1 100644 (file)
@@ -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]";
         }
index 24fefaaef60817fcf21872553ade32888f07063d..dff0ea91d5076647d52559b92617c0b3774723ae 100644 (file)
@@ -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:
index 930a11062937c5e3b7ab64221d1bdde68d76e9e9..baf01c63830d5a8d3c1545e48f8a47a5d9a5449f 100644 (file)
@@ -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() << "'" );
index 752c2ebf60068f3886d7193cb38e9cb2ecc29de0..8490922705c2d23d11acb4b113666fdfde41fdab 100644 (file)
@@ -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]=='/' ) {
index d33e4b1d39cf727eae2570c5a0f372e02350238b..87718c7f616f7eda89b2b31c02f12fa6afea9053 100644 (file)
@@ -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");
     }
 
index 2f1d326517a0d1c700e387477b62ac048591c44f..fe4b956c5abe8a9013fc0b5e333bea1f014a83bd 100644 (file)
@@ -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);
     }
index f7e7757904e16885e5c967123551e9a749853456..765d67f3ce4bdaae89810840830004d5fd08b509 100644 (file)
@@ -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)
index caacb55d127c62ebdf7c45084f39c4dc8845d7c5..b1ac1f97c219b596d9d22eae46ee1c1b7c3167a7 100644 (file)
@@ -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);
 }
 
 /*
index 84117d86c5d7239314971304cf4873129c13ca5c..8715991aad259e96b187a4c45e4d94d5cb355dcf 100644 (file)
@@ -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
index e1b99ed7020dd18cf5a22bc498f9d68cd4789582..acd7411f3b9464c64d0927ba520b7c9eea3ea8e3 100644 (file)
@@ -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);
 
index 94c014298293a557a0b339e09153308b71af7fa9..51b97f7805b77598d508f6381b63009f1957e0bd 100644 (file)
@@ -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");
 }
index 0ca95d83346f64a99e517bf7b4e9865407f22ac6..04ea216913818e8dfe899dc3f46b1bcfb298d1ac 100644 (file)
@@ -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);
 }
index aba0f174c4897deb13ef1b2499929f15c2d1d6e2..a9adf6aca19b6993ca28f35e16062711b906712d 100644 (file)
@@ -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());
 }
 
index eebcbcd27d6b734ee2e34367534d419c615c5fd3..dce1c4df50ff70dc46c9dd0968e1244458385d7b 100644 (file)
@@ -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<AnyP::ProtocolType>(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);
index dcd614a9b0d0be4e091e7f9f65d418c4b0cb95d7..44d14837e032ae150287a8a99de1d32ffcad41a0 100644 (file)
@@ -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 *);
index 24d635412d39930b546440ca9a9c19d3118c891e..0da3b619845a4e53090f263cde0b909cd4bc8025 100644 (file)
@@ -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;