From: Amos Jeffries Date: Fri, 7 Feb 2014 13:45:20 +0000 (-0700) Subject: SourceLayout: shuffle URLScheme to AnyP::UriScheme X-Git-Tag: SQUID_3_5_0_1~385 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1ca54a54f6b63bb389dc7a5a0270f771cf9b82d6;p=thirdparty%2Fsquid.git SourceLayout: shuffle URLScheme to AnyP::UriScheme This class holds a generic protocol agnostic Scheme representation. * rename const_str() member to c_str() since it produces a const C-string (char*) representation. * Remove some unecessary dependencies. * Cleanup the coding style to match guidelines. --- diff --git a/src/Makefile.am b/src/Makefile.am index 396e47c57a..400f3153d5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -555,8 +555,6 @@ squid_SOURCES = \ $(UNLINKDSOURCE) \ url.cc \ URL.h \ - URLScheme.cc \ - URLScheme.h \ urn.h \ urn.cc \ wccp.h \ @@ -1193,7 +1191,6 @@ tests_testHttpReply_SOURCES=\ tests/testMain.cc \ tests/stub_time.cc \ url.cc \ - URLScheme.cc \ wordlist.h \ wordlist.cc nodist_tests_testHttpReply_SOURCES=\ @@ -1327,8 +1324,6 @@ tests_testACLMaxUserIP_SOURCES= \ tests/stub_time.cc \ url.cc \ URL.h \ - URLScheme.cc \ - URLScheme.h \ Mem.h \ tests/stub_mem.cc \ MemBuf.cc \ @@ -1574,7 +1569,6 @@ tests_testCacheManager_SOURCES = \ MemStore.cc \ $(UNLINKDSOURCE) \ url.cc \ - URLScheme.cc \ urn.h \ urn.cc \ wccp2.h \ @@ -1762,7 +1756,6 @@ tests_testDiskIO_SOURCES = \ tests/stub_time.cc \ $(UNLINKDSOURCE) \ url.cc \ - URLScheme.cc \ $(WIN32_SOURCE) \ wordlist.h \ wordlist.cc \ @@ -2007,7 +2000,6 @@ tests_testEvent_SOURCES = \ MemStore.cc \ $(UNLINKDSOURCE) \ url.cc \ - URLScheme.cc \ urn.h \ urn.cc \ wccp2.h \ @@ -2255,7 +2247,6 @@ tests_testEventLoop_SOURCES = \ MemStore.cc \ $(UNLINKDSOURCE) \ url.cc \ - URLScheme.cc \ urn.h \ urn.cc \ wccp2.h \ @@ -2496,7 +2487,6 @@ tests_test_http_range_SOURCES = \ tests/stub_tunnel.cc \ $(UNLINKDSOURCE) \ url.cc \ - URLScheme.cc \ urn.h \ urn.cc \ wccp2.h \ @@ -2786,7 +2776,6 @@ tests_testHttpRequest_SOURCES = \ tests/stub_SwapDir.cc \ MemStore.cc \ url.cc \ - URLScheme.cc \ urn.h \ urn.cc \ wccp2.h \ @@ -2973,7 +2962,6 @@ tests_testStore_SOURCES= \ tests/TestSwapDir.h \ tests/stub_time.cc \ url.cc \ - URLScheme.cc \ wordlist.h \ wordlist.cc @@ -3202,7 +3190,6 @@ tests_testUfs_SOURCES = \ tests/testStoreSupport.cc \ tests/testStoreSupport.h \ time.cc \ - URLScheme.cc \ wordlist.h \ wordlist.cc \ $(DISKIO_SOURCE) @@ -3385,7 +3372,6 @@ tests_testRock_SOURCES = \ tests/stub_tools.cc \ time.cc \ url.cc \ - URLScheme.cc \ wordlist.h \ wordlist.cc \ $(DELAY_POOL_SOURCE) \ @@ -3614,8 +3600,8 @@ tests_testURL_SOURCES = \ tests/stub_store_stats.cc \ tests/testURL.cc \ tests/testURL.h \ - tests/testURLScheme.cc \ - tests/testURLScheme.h \ + tests/testUriScheme.cc \ + tests/testUriScheme.h \ tests/testMain.cc \ tests/stub_time.cc \ tests/stub_EventLoop.cc \ @@ -3623,7 +3609,6 @@ tests_testURL_SOURCES = \ tools.cc \ tests/stub_tunnel.cc \ url.cc \ - URLScheme.cc \ urn.h \ urn.cc \ wccp2.h \ diff --git a/src/URL.h b/src/URL.h index de33fab249..5aff09d66c 100644 --- a/src/URL.h +++ b/src/URL.h @@ -31,9 +31,8 @@ #ifndef SQUID_SRC_URL_H #define SQUID_SRC_URL_H -#include "anyp/ProtocolType.h" +#include "anyp/UriScheme.h" #include "MemPool.h" -#include "URLScheme.h" /** \ingroup POD @@ -42,13 +41,11 @@ */ class URL { - public: - MEMPROXY_CLASS(URL); - URL(); - URL(URLScheme const &); - URLScheme const & getScheme() const {return scheme; } + URL() : scheme_() {} + URL(AnyP::UriScheme const &aScheme) : scheme_(aScheme) {} + AnyP::UriScheme const & getScheme() const {return scheme_;} private: /** @@ -62,7 +59,7 @@ private: * is to have one prototype URL with no host etc for each scheme, * another is to have an explicit scheme class, and then each URL class * could be a subclass of the scheme. Another way is one instance of - * a URLScheme class instance for each URLScheme we support, and one URL + * a AnyP::UriScheme class instance for each URL scheme we support, and one URL * class for each manner of treating the scheme : a Hierarchical URL, a * non-hierarchical URL etc. \par @@ -71,7 +68,7 @@ private: * In order to make taking any of these routes easy, scheme is private * and immutable, only settable at construction time, */ - URLScheme const scheme; + AnyP::UriScheme const scheme_; }; MEMPROXY_CLASS_INLINE(URL); diff --git a/src/URLScheme.cc b/src/URLScheme.cc deleted file mode 100644 index 6ccba69ba1..0000000000 --- a/src/URLScheme.cc +++ /dev/null @@ -1,54 +0,0 @@ - -/* - * DEBUG: section 23 URL Scheme parsing - * AUTHOR: Robert Collins - * - * SQUID Web Proxy Cache http://www.squid-cache.org/ - * ---------------------------------------------------------- - * - * Squid is the result of efforts by numerous individuals from - * the Internet community; see the CONTRIBUTORS file for full - * details. Many organizations have provided support for Squid's - * development; see the SPONSORS file for full details. Squid is - * Copyrighted (C) 2001 by the Regents of the University of - * California; see the COPYRIGHT file for full details. Squid - * incorporates software developed and/or copyrighted by other - * sources; see the CREDITS file for full details. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. - * - */ - -#include "squid.h" -#include "URLScheme.h" -#include "wordlist.h" - -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 deleted file mode 100644 index cb4fc5edb0..0000000000 --- a/src/URLScheme.h +++ /dev/null @@ -1,74 +0,0 @@ - -/* - * - * SQUID Web Proxy Cache http://www.squid-cache.org/ - * ---------------------------------------------------------- - * - * Squid is the result of efforts by numerous individuals from - * the Internet community; see the CONTRIBUTORS file for full - * details. Many organizations have provided support for Squid's - * development; see the SPONSORS file for full details. Squid is - * Copyrighted (C) 2001 by the Regents of the University of - * California; see the COPYRIGHT file for full details. Squid - * incorporates software developed and/or copyrighted by other - * sources; see the CREDITS file for full details. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. - * - */ - -#ifndef SQUID_URLSCHEME_H -#define SQUID_URLSCHEME_H - -#include "anyp/ProtocolType.h" -#if HAVE_IOSFWD -#include -#endif - -/** 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_(AnyP::PROTO_NONE) {} - URLScheme(AnyP::ProtocolType const aScheme) : theScheme_(aScheme) {} - ~URLScheme() {} - - operator AnyP::ProtocolType() const { return theScheme_; } - - bool operator != (AnyP::ProtocolType const & aProtocol) const { return theScheme_ != aProtocol; } - - /** 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 pointer into the enum/registry of protocols handled. - AnyP::ProtocolType theScheme_; -}; - -inline std::ostream & -operator << (std::ostream &os, URLScheme const &scheme) -{ - os << scheme.const_str(); - return os; -} - -#endif /* SQUID_URLSCHEME_H */ diff --git a/src/acl/ProtocolData.cc b/src/acl/ProtocolData.cc index f0b6899a9c..dcfe1bcf4a 100644 --- a/src/acl/ProtocolData.cc +++ b/src/acl/ProtocolData.cc @@ -37,7 +37,6 @@ #include "acl/ProtocolData.h" #include "cache_cf.h" #include "Debug.h" -#include "URLScheme.h" #include "wordlist.h" ACLProtocolData::ACLProtocolData() : values (NULL) diff --git a/src/anyp/Makefile.am b/src/anyp/Makefile.am index 2724a482ce..39a428fe80 100644 --- a/src/anyp/Makefile.am +++ b/src/anyp/Makefile.am @@ -10,7 +10,9 @@ libanyp_la_SOURCES = \ ProtocolType.cc \ ProtocolType.h \ ProtocolVersion.h \ - TrafficMode.h + TrafficMode.h \ + UriScheme.cc \ + UriScheme.h ProtocolType.cc: ProtocolType.h $(top_srcdir)/src/mk-string-arrays.awk ($(AWK) -f $(top_srcdir)/src/mk-string-arrays.awk <$(srcdir)/ProtocolType.h | sed -e 's%PROTO_%%' >$@) || ($(RM) -f $@ && exit 1) diff --git a/src/anyp/UriScheme.cc b/src/anyp/UriScheme.cc new file mode 100644 index 0000000000..36a873fedc --- /dev/null +++ b/src/anyp/UriScheme.cc @@ -0,0 +1,24 @@ +/* + * DEBUG: section 23 URL Scheme parsing + * AUTHOR: Robert Collins, Amos Jeffries + */ +#include "squid.h" +#include "anyp/UriScheme.h" + +char const * +AnyP::UriScheme::c_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/anyp/UriScheme.h b/src/anyp/UriScheme.h new file mode 100644 index 0000000000..98de13c69f --- /dev/null +++ b/src/anyp/UriScheme.h @@ -0,0 +1,49 @@ +#ifndef SQUID_ANYP_URISCHEME_H +#define SQUID_ANYP_URISCHEME_H + +#include "anyp/ProtocolType.h" +#if HAVE_IOSFWD +#include +#endif + +namespace AnyP +{ + +/** This class represents a URI Scheme such as http:// https://, wais://, urn: etc. + * It does not represent the PROTOCOL that such schemes refer to. + */ +class UriScheme +{ +public: + UriScheme() : theScheme_(AnyP::PROTO_NONE) {} + UriScheme(AnyP::ProtocolType const aScheme) : theScheme_(aScheme) {} + ~UriScheme() {} + + operator AnyP::ProtocolType() const { return theScheme_; } + + bool operator != (AnyP::ProtocolType const & aProtocol) const { return theScheme_ != aProtocol; } + + /** Get a char string representation of the scheme. + * Does not include the ':' or '://" terminators. + * + * 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 *c_str() const; + +private: + /// This is a typecode pointer into the enum/registry of protocols handled. + AnyP::ProtocolType theScheme_; +}; + +} // namespace AnyP + +inline std::ostream & +operator << (std::ostream &os, AnyP::UriScheme const &scheme) +{ + os << scheme.c_str(); + return os; +} + +#endif /* SQUID_ANYP_URISCHEME_H */ diff --git a/src/anyp/forward.h b/src/anyp/forward.h index b01b4c0077..bc9a52ef36 100644 --- a/src/anyp/forward.h +++ b/src/anyp/forward.h @@ -9,6 +9,8 @@ namespace AnyP class PortCfg; typedef CbcPointer PortCfgPointer; +class UriScheme; + } // namespace AnyP #endif /* _SQUID_SRC_ANYP_FORWARD_H */ diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 7b1f453a45..95fcd154d7 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -40,6 +40,7 @@ #include "acl/MethodData.h" #include "acl/Tree.h" #include "anyp/PortCfg.h" +#include "anyp/UriScheme.h" #include "AuthReg.h" #include "base/RunnersRegistry.h" #include "cache_cf.h" @@ -78,7 +79,6 @@ #include "StoreFileSystem.h" #include "SwapDir.h" #include "tools.h" -#include "URLScheme.h" #include "wordlist.h" /* wccp2 has its own conditional definitions */ #include "wccp2.h" @@ -3513,7 +3513,7 @@ parsePortSpecification(AnyP::PortCfg * s, char *token) s->name = xstrdup(token); s->connection_auth_disabled = false; - const char *portType = URLScheme(s->transport.protocol).const_str(); + const char *portType = AnyP::UriScheme(s->transport.protocol).c_str(); if (*token == '[') { /* [ipv6]:port */ @@ -3832,7 +3832,7 @@ parsePortCfg(AnyP::PortCfg ** head, const char *optionName) // clone the port options from *s to *(s->next) s->next = cbdataReference(s->clone()); s->next->s.setIPv4(); - debugs(3, 3, URLScheme(s->transport.protocol) << "_port: clone wildcard address for split-stack: " << s->s << " and " << s->next->s); + debugs(3, 3, AnyP::UriScheme(s->transport.protocol).c_str() << "_port: clone wildcard address for split-stack: " << s->s << " and " << s->next->s); } while (*head) @@ -3873,7 +3873,7 @@ dump_generic_port(StoreEntry * e, const char *n, const AnyP::PortCfg * s) // TODO: compare against prefix of 'n' instead of assuming http_port if (s->transport.protocol != AnyP::PROTO_HTTP) - storeAppendPrintf(e, " protocol=%s", URLScheme(s->transport.protocol).const_str()); + storeAppendPrintf(e, " protocol=%s", AnyP::UriScheme(s->transport.protocol).c_str()); if (s->allow_direct) storeAppendPrintf(e, " allow-direct"); diff --git a/src/carp.cc b/src/carp.cc index 37e916c1b5..a52527e682 100644 --- a/src/carp.cc +++ b/src/carp.cc @@ -40,7 +40,6 @@ #include "SquidConfig.h" #include "Store.h" #include "URL.h" -#include "URLScheme.h" #if HAVE_MATH_H #include @@ -195,8 +194,8 @@ carpSelectParent(HttpRequest * request) // corner cases should use the canonical URL if (tp->options.carp_key.scheme) { // temporary, until bug 1961 URL handling is fixed. - const URLScheme sch = request->protocol; - key.append(sch.const_str()); + const AnyP::UriScheme sch(request->protocol); + key.append(sch.c_str()); if (key.size()) //if the scheme is not empty key.append("://"); } diff --git a/src/client_side.cc b/src/client_side.cc index 0781d7d890..9fbf9e52a2 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -2120,7 +2120,7 @@ prepareAcceleratedURL(ConnStateData * conn, ClientHttpRequest *http, char *url, strlen(host); http->uri = (char *)xcalloc(url_sz, 1); const char *protocol = switchedToHttps ? - "https" : URLScheme(conn->port->transport.protocol).const_str(); + "https" : AnyP::UriScheme(conn->port->transport.protocol).c_str(); snprintf(http->uri, url_sz, "%s://%s%s", protocol, host, url); debugs(33, 5, "ACCEL VHOST REWRITE: '" << http->uri << "'"); } else if (conn->port->defaultsite /* && !vhost */) { @@ -2134,7 +2134,7 @@ prepareAcceleratedURL(ConnStateData * conn, ClientHttpRequest *http, char *url, snprintf(vportStr, sizeof(vportStr),":%d",vport); } snprintf(http->uri, url_sz, "%s://%s%s%s", - URLScheme(conn->port->transport.protocol).const_str(), conn->port->defaultsite, vportStr, url); + AnyP::UriScheme(conn->port->transport.protocol).c_str(), conn->port->defaultsite, vportStr, url); debugs(33, 5, "ACCEL DEFAULTSITE REWRITE: '" << http->uri <<"'"); } else if (vport > 0 /* && (!vhost || no Host:) */) { debugs(33, 5, "ACCEL VPORT REWRITE: http_port IP + vport=" << vport); @@ -2143,7 +2143,7 @@ prepareAcceleratedURL(ConnStateData * conn, ClientHttpRequest *http, char *url, http->uri = (char *)xcalloc(url_sz, 1); http->getConn()->clientConnection->local.toHostStr(ipbuf,MAX_IPSTRLEN); snprintf(http->uri, url_sz, "%s://%s:%d%s", - URLScheme(conn->port->transport.protocol).const_str(), + AnyP::UriScheme(conn->port->transport.protocol).c_str(), ipbuf, vport, url); debugs(33, 5, "ACCEL VPORT REWRITE: '" << http->uri << "'"); } @@ -2164,7 +2164,7 @@ prepareTransparentURL(ConnStateData * conn, ClientHttpRequest *http, char *url, int url_sz = strlen(url) + 32 + Config.appendDomainLen + strlen(host); http->uri = (char *)xcalloc(url_sz, 1); - snprintf(http->uri, url_sz, "%s://%s%s", URLScheme(conn->port->transport.protocol).const_str(), host, url); + snprintf(http->uri, url_sz, "%s://%s%s", AnyP::UriScheme(conn->port->transport.protocol).c_str(), host, url); debugs(33, 5, "TRANSPARENT HOST REWRITE: '" << http->uri <<"'"); } else { /* Put the local socket IP address as the hostname. */ @@ -2172,7 +2172,7 @@ prepareTransparentURL(ConnStateData * conn, ClientHttpRequest *http, char *url, http->uri = (char *)xcalloc(url_sz, 1); http->getConn()->clientConnection->local.toHostStr(ipbuf,MAX_IPSTRLEN); snprintf(http->uri, url_sz, "%s://%s:%d%s", - URLScheme(http->getConn()->port->transport.protocol).const_str(), + AnyP::UriScheme(http->getConn()->port->transport.protocol).c_str(), ipbuf, http->getConn()->clientConnection->local.port(), url); debugs(33, 5, "TRANSPARENT REWRITE: '" << http->uri << "'"); } @@ -4071,7 +4071,7 @@ clientHttpConnectionsOpen(void) #if USE_SSL if (s->flags.tunnelSslBumping && !Config.accessList.ssl_bump) { - debugs(33, DBG_IMPORTANT, "WARNING: No ssl_bump configured. Disabling ssl-bump on " << URLScheme(s->transport.protocol) << "_port " << s->s); + debugs(33, DBG_IMPORTANT, "WARNING: No ssl_bump configured. Disabling ssl-bump on " << AnyP::UriScheme(s->transport.protocol) << "_port " << s->s); s->flags.tunnelSslBumping = false; } @@ -4128,7 +4128,7 @@ clientHttpsConnectionsOpen(void) // TODO: merge with similar code in clientHttpConnectionsOpen() if (s->flags.tunnelSslBumping && !Config.accessList.ssl_bump) { - debugs(33, DBG_IMPORTANT, "WARNING: No ssl_bump configured. Disabling ssl-bump on " << URLScheme(s->transport.protocol) << "_port " << s->s); + debugs(33, DBG_IMPORTANT, "WARNING: No ssl_bump configured. Disabling ssl-bump on " << AnyP::UriScheme(s->transport.protocol) << "_port " << s->s); s->flags.tunnelSslBumping = false; } diff --git a/src/errorpage.cc b/src/errorpage.cc index 6c25de0ae2..4d98ba2e18 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -49,8 +49,6 @@ #include "Store.h" #include "tools.h" #include "URL.h" -#include "URL.h" -#include "URLScheme.h" #include "wordlist.h" #if USE_AUTH #include "auth/UserRequest.h" diff --git a/src/external_acl.cc b/src/external_acl.cc index c5063c7321..8e858aaedd 100644 --- a/src/external_acl.cc +++ b/src/external_acl.cc @@ -62,7 +62,6 @@ #include "Store.h" #include "tools.h" #include "URL.h" -#include "URLScheme.h" #include "wordlist.h" #if USE_SSL #include "ssl/support.h" diff --git a/src/ftp.cc b/src/ftp.cc index 05275efaa8..9901ffc248 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -60,7 +60,6 @@ #include "Store.h" #include "tools.h" #include "URL.h" -#include "URLScheme.h" #include "wordlist.h" #if USE_DELAY_POOLS diff --git a/src/tests/testURL.cc b/src/tests/testURL.cc index 379d431e9d..cb6649a359 100644 --- a/src/tests/testURL.cc +++ b/src/tests/testURL.cc @@ -22,17 +22,17 @@ testURL::setUp() } /* - * we can construct a URL with a URLScheme. + * we can construct a URL with a AnyP::UriScheme. * This creates a URL for that scheme. */ void testURL::testConstructScheme() { - URLScheme empty_scheme; + AnyP::UriScheme empty_scheme; URL protoless_url(AnyP::PROTO_NONE); CPPUNIT_ASSERT_EQUAL(empty_scheme, protoless_url.getScheme()); - URLScheme ftp_scheme(AnyP::PROTO_FTP); + AnyP::UriScheme ftp_scheme(AnyP::PROTO_FTP); URL ftp_url(AnyP::PROTO_FTP); CPPUNIT_ASSERT_EQUAL(ftp_scheme, ftp_url.getScheme()); } @@ -45,7 +45,7 @@ testURL::testConstructScheme() void testURL::testDefaultConstructor() { - URLScheme aScheme; + AnyP::UriScheme aScheme; URL aUrl; CPPUNIT_ASSERT_EQUAL(aScheme, aUrl.getScheme()); diff --git a/src/tests/testURLScheme.cc b/src/tests/testUriScheme.cc similarity index 52% rename from src/tests/testURLScheme.cc rename to src/tests/testUriScheme.cc index b4709f90e8..680f0accc2 100644 --- a/src/tests/testURLScheme.cc +++ b/src/tests/testUriScheme.cc @@ -4,16 +4,16 @@ #include +#include "anyp/UriScheme.h" #include "Mem.h" #include "SquidString.h" -#include "testURLScheme.h" -#include "URLScheme.h" +#include "tests/testUriScheme.h" #if HAVE_SSTREAM #include #endif -CPPUNIT_TEST_SUITE_REGISTRATION( testURLScheme ); +CPPUNIT_TEST_SUITE_REGISTRATION( testUriScheme ); #if 0 /* @@ -47,58 +47,58 @@ testHttpRequestMethod::testConstructCharStartEnd() #endif /* - * we should be able to assign a protocol_t to a URLScheme for ease + * we should be able to assign a protocol_t to a AnyP::UriScheme for ease * of code conversion */ void -testURLScheme::testAssignFromprotocol_t() +testUriScheme::testAssignFromprotocol_t() { - URLScheme empty_scheme; - URLScheme scheme; + AnyP::UriScheme empty_scheme; + AnyP::UriScheme scheme; scheme = AnyP::PROTO_NONE; CPPUNIT_ASSERT_EQUAL(empty_scheme, scheme); - URLScheme https_scheme(AnyP::PROTO_HTTPS); + AnyP::UriScheme https_scheme(AnyP::PROTO_HTTPS); scheme = AnyP::PROTO_HTTPS; CPPUNIT_ASSERT_EQUAL(https_scheme, scheme); } /* - * We should be able to get a protocol_t from a URLScheme for ease + * We should be able to get a protocol_t from a AnyP::UriScheme for ease * of migration */ void -testURLScheme::testCastToprotocol_t() +testUriScheme::testCastToprotocol_t() { /* explicit cast */ - AnyP::ProtocolType protocol = static_cast(URLScheme()); + AnyP::ProtocolType protocol = static_cast(AnyP::UriScheme()); CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE, protocol); /* and implicit */ - protocol = URLScheme(AnyP::PROTO_HTTP); + protocol = AnyP::UriScheme(AnyP::PROTO_HTTP); CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, protocol); } /* - * a default constructed URLScheme is == AnyP::PROTO_NONE + * a default constructed AnyP::UriScheme is == AnyP::PROTO_NONE */ void -testURLScheme::testDefaultConstructor() +testUriScheme::testDefaultConstructor() { - URLScheme lhs; - URLScheme rhs(AnyP::PROTO_NONE); + AnyP::UriScheme lhs; + AnyP::UriScheme rhs(AnyP::PROTO_NONE); CPPUNIT_ASSERT_EQUAL(lhs, rhs); } /* - * we should be able to construct a URLScheme from the old 'protocol_t' enum. + * we should be able to construct a AnyP::UriScheme from the old 'protocol_t' enum. */ void -testURLScheme::testConstructprotocol_t() +testUriScheme::testConstructprotocol_t() { - URLScheme lhs_none(AnyP::PROTO_NONE), rhs_none(AnyP::PROTO_NONE); + AnyP::UriScheme lhs_none(AnyP::PROTO_NONE), rhs_none(AnyP::PROTO_NONE); CPPUNIT_ASSERT_EQUAL(lhs_none, rhs_none); - URLScheme lhs_cacheobj(AnyP::PROTO_CACHE_OBJECT), rhs_cacheobj(AnyP::PROTO_CACHE_OBJECT); + AnyP::UriScheme lhs_cacheobj(AnyP::PROTO_CACHE_OBJECT), rhs_cacheobj(AnyP::PROTO_CACHE_OBJECT); CPPUNIT_ASSERT_EQUAL(lhs_cacheobj, rhs_cacheobj); CPPUNIT_ASSERT(lhs_none != rhs_cacheobj); } @@ -107,47 +107,47 @@ testURLScheme::testConstructprotocol_t() * we should be able to get a char const * version of the method. */ void -testURLScheme::testConst_str() +testUriScheme::testC_str() { String lhs("wais"); - URLScheme wais(AnyP::PROTO_WAIS); - String rhs(wais.const_str()); + AnyP::UriScheme wais(AnyP::PROTO_WAIS); + String rhs(wais.c_str()); CPPUNIT_ASSERT_EQUAL(lhs, rhs); } /* - * a URLScheme replaces protocol_t, so we should be able to test for equality on + * a AnyP::UriScheme replaces protocol_t, so we should be able to test for equality on * either the left or right hand side seamlessly. */ void -testURLScheme::testEqualprotocol_t() +testUriScheme::testEqualprotocol_t() { - 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_CACHE_OBJECT == URLScheme(AnyP::PROTO_HTTP))); + CPPUNIT_ASSERT(AnyP::UriScheme() == AnyP::PROTO_NONE); + CPPUNIT_ASSERT(not (AnyP::UriScheme(AnyP::PROTO_WAIS) == AnyP::PROTO_HTTP)); + CPPUNIT_ASSERT(AnyP::PROTO_HTTP == AnyP::UriScheme(AnyP::PROTO_HTTP)); + CPPUNIT_ASSERT(not (AnyP::PROTO_CACHE_OBJECT == AnyP::UriScheme(AnyP::PROTO_HTTP))); } /* - * a URLScheme should testable for inequality with a protocol_t. + * a AnyP::UriScheme should testable for inequality with a protocol_t. */ void -testURLScheme::testNotEqualprotocol_t() +testUriScheme::testNotEqualprotocol_t() { - 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))); + CPPUNIT_ASSERT(AnyP::UriScheme(AnyP::PROTO_NONE) != AnyP::PROTO_HTTP); + CPPUNIT_ASSERT(not (AnyP::UriScheme(AnyP::PROTO_HTTP) != AnyP::PROTO_HTTP)); + CPPUNIT_ASSERT(AnyP::PROTO_NONE != AnyP::UriScheme(AnyP::PROTO_HTTP)); + CPPUNIT_ASSERT(not (AnyP::PROTO_WAIS != AnyP::UriScheme(AnyP::PROTO_WAIS))); } /* * we should be able to send it to a stream and get the normalised version */ void -testURLScheme::testStream() +testUriScheme::testStream() { std::ostringstream buffer; - buffer << URLScheme(AnyP::PROTO_HTTP); + buffer << AnyP::UriScheme(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/tests/testURLScheme.h b/src/tests/testUriScheme.h similarity index 77% rename from src/tests/testURLScheme.h rename to src/tests/testUriScheme.h index fe8ba2b7de..d996ee12b2 100644 --- a/src/tests/testURLScheme.h +++ b/src/tests/testUriScheme.h @@ -1,16 +1,16 @@ -#ifndef SQUID_SRC_TEST_URL_SCHEME_H -#define SQUID_SRC_TEST_URL_SCHEME_H +#ifndef SQUID_SRC_TESTS_TESTURISCHEME_H +#define SQUID_SRC_TESTS_TESTURISCHEME_H #include /* - * test URLScheme + * test UriScheme */ -class testURLScheme : public CPPUNIT_NS::TestFixture +class testUriScheme : public CPPUNIT_NS::TestFixture { - CPPUNIT_TEST_SUITE( testURLScheme ); + CPPUNIT_TEST_SUITE( testUriScheme ); CPPUNIT_TEST( testAssignFromprotocol_t ); CPPUNIT_TEST( testCastToprotocol_t ); CPPUNIT_TEST( testConstructprotocol_t ); @@ -23,7 +23,7 @@ class testURLScheme : public CPPUNIT_NS::TestFixture CPPUNIT_TEST( testDefaultConstructor ); CPPUNIT_TEST( testEqualprotocol_t ); CPPUNIT_TEST( testNotEqualprotocol_t ); - CPPUNIT_TEST( testConst_str ); + CPPUNIT_TEST( testC_str ); CPPUNIT_TEST( testStream ); CPPUNIT_TEST_SUITE_END(); @@ -39,7 +39,7 @@ protected: void testConstructCharStartEnd(); #endif - void testConst_str(); + void testC_str(); void testDefaultConstructor(); void testEqualprotocol_t(); void testNotEqualprotocol_t(); diff --git a/src/url.cc b/src/url.cc index e740ec5dc0..0268467f8e 100644 --- a/src/url.cc +++ b/src/url.cc @@ -38,7 +38,6 @@ #include "SquidConfig.h" #include "SquidString.h" #include "URL.h" -#include "URLScheme.h" static HttpRequest *urlParseFinish(const HttpRequestMethod& method, const AnyP::ProtocolType protocol, @@ -515,9 +514,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. + const AnyP::UriScheme sch = request->protocol; // temporary, until bug 1961 URL handling is fixed. snprintf(urlbuf, MAX_URL, "%s://%s%s%s%s" SQUIDSTRINGPH, - sch.const_str(), + sch.c_str(), request->login, *request->login ? "@" : null_string, request->GetHost(), @@ -562,9 +561,9 @@ urlCanonicalClean(const HttpRequest * request) strcat(loginbuf, "@"); } - const URLScheme sch = request->protocol; // temporary, until bug 1961 URL handling is fixed. + const AnyP::UriScheme sch = request->protocol; // temporary, until bug 1961 URL handling is fixed. snprintf(buf, MAX_URL, "%s://%s%s%s" SQUIDSTRINGPH, - sch.const_str(), + sch.c_str(), loginbuf, request->GetHost(), portbuf, @@ -662,10 +661,10 @@ urlMakeAbsolute(const HttpRequest * req, const char *relUrl) size_t urllen; - const URLScheme sch = req->protocol; // temporary, until bug 1961 URL handling is fixed. + const AnyP::UriScheme 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", - sch.const_str(), + sch.c_str(), req->login, *req->login ? "@" : null_string, req->GetHost(), @@ -673,7 +672,7 @@ urlMakeAbsolute(const HttpRequest * req, const char *relUrl) ); } else { urllen = snprintf(urlbuf, MAX_URL, "%s://%s%s%s", - sch.const_str(), + sch.c_str(), req->login, *req->login ? "@" : null_string, req->GetHost() @@ -980,9 +979,3 @@ URLHostName::extract(char const *aUrl) return Host; } - -URL::URL() : scheme() -{} - -URL::URL(URLScheme const &aScheme): scheme(aScheme) -{}