|
Squid Web Cache master
|
#include <Uri.h>
Public Member Functions | |
| Uri () | |
| Uri (AnyP::UriScheme const &aScheme) | |
| Uri (const Uri &)=default | |
| Uri (Uri &&)=default | |
| Uri & | operator= (const Uri &)=default |
| Uri & | operator= (Uri &&)=default |
| void | clear () |
| void | touch () |
| clear the cached URI display forms | |
| bool | parse (const HttpRequestMethod &, const SBuf &url) |
| AnyP::UriScheme const & | getScheme () const |
| void | setScheme (const AnyP::ProtocolType &p, const char *str) |
| convert the URL scheme to that given | |
| void | setScheme (const AnyP::UriScheme &s) |
| void | userInfo (const SBuf &s) |
| const SBuf & | userInfo () const |
| void | host (const char *src) |
| const char * | host (void) const |
| int | hostIsNumeric (void) const |
| Ip::Address const & | hostIP (void) const |
| std::optional< Host > | parsedHost () const |
| SBuf | hostOrIp () const |
| void | port (const Port p) |
| reset authority port subcomponent | |
| Port | port () const |
| authority port subcomponent | |
| void | defaultPort () |
| reset the port to the default port number for the current scheme | |
| void | path (const char *p) |
| void | path (const SBuf &p) |
| const SBuf & | path () const |
| void | addRelativePath (const char *relUrl) |
| SBuf & | authority (bool requirePort=false) const |
| SBuf & | absolute () const |
| SBuf & | absolutePath () const |
| RFC 3986 section 4.2 relative reference called 'absolute-path'. | |
| SBuf & | originForm () const |
| The RFC 7230 origin-form URI for currently stored values. | |
Static Public Member Functions | |
| static char * | cleanup (const char *uri) |
| static const SBuf & | SlashPath () |
| the static '/' default URL-path | |
| static const SBuf & | Asterisk () |
| the static '*' pseudo-URI | |
| static SBuf | Encode (const SBuf &, const CharacterSet &expected) |
| static std::optional< SBuf > | Decode (const SBuf &) |
| static SBuf | DecodeOrDupe (const SBuf &input) |
Private Member Functions | |
| MEMPROXY_CLASS (Uri) | |
| void | parseUrn (Parser::Tokenizer &) |
| SBuf | parseHost (Parser::Tokenizer &) const |
| int | parsePort (Parser::Tokenizer &) const |
Private Attributes | |
| AnyP::UriScheme | scheme_ |
| SBuf | userInfo_ |
| char | host_ [SQUIDHOSTNAMELEN] |
| string representation of the URI authority name or IP | |
| bool | hostIsNumeric_ |
| whether the authority 'host' is a raw-IP | |
| Ip::Address | hostAddr_ |
| binary representation of the URI authority if it is a raw-IP | |
| Port | port_ |
| authority port subcomponent | |
| SBuf | path_ |
| URI path segment. | |
| SBuf | authorityHttp_ |
| RFC 7230 section 5.3.3 authority, maybe without default-port. | |
| SBuf | authorityWithPort_ |
| RFC 7230 section 5.3.3 authority with explicit port. | |
| SBuf | absolute_ |
| RFC 7230 section 5.3.2 absolute-URI. | |
| SBuf | absolutePath_ |
| RFC 3986 section 4.2 absolute-path. | |
Represents a Uniform Resource Identifier. Can store both URL or URN representations.
Governed by RFC 3986
| AnyP::Uri::Uri | ( | AnyP::UriScheme const & | aScheme | ) |
|
default |
|
default |
| SBuf & AnyP::Uri::absolute | ( | ) | const |
The absolute-form URI for currently stored values.
As defined by RFC 7230 section 5.3.3 this form omits the userinfo@ field from RFC 3986 defined authority segments when the protocol scheme is http: or https:.
Definition at line 743 of file Uri.cc.
References MAX_URL, AnyP::PROTO_FTP, AnyP::PROTO_UNKNOWN, AnyP::PROTO_URN, CharacterSet::remove(), CharacterSet::rename(), SBuf::reserveCapacity(), and UserInfoChars().
Referenced by HttpRequest::effectiveRequestUri(), CacheManager::ParseUrl(), purgeEntriesByHeader(), UrnState::setUriResFromRequest(), and urnParseReply().
| SBuf & AnyP::Uri::absolutePath | ( | ) | const |
Definition at line 775 of file Uri.cc.
References PathChars().
Referenced by Format::Format::assemble(), carpSelectParent(), ErrorState::compileLegacyCode(), internalStart(), AnyP::operator<<(), originForm(), Adaptation::Service::wants(), and whoisStart().
| void AnyP::Uri::addRelativePath | ( | const char * | relUrl | ) |
Merge a relative-path URL into the existing URI details. Implements RFC 3986 section 5.2.3
The caller must ensure relUrl is a valid relative-path.
Definition at line 879 of file Uri.cc.
References SBuf::npos, and AnyP::PROTO_URN.
Referenced by purgeEntriesByHeader().
|
static |
Definition at line 140 of file Uri.cc.
Referenced by urlCheckRequest().
| SBuf & AnyP::Uri::authority | ( | bool | requirePort = false | ) | const |
The authority-form URI for currently stored values.
As defined by RFC 7230 section 5.3.3 this form omits the userinfo@ field from RFC 3986 defined authority segment.
| requirePort | when true the port will be included, otherwise port will be elided when it is the default for the current scheme. |
Definition at line 721 of file Uri.cc.
References SBuf::append(), SBuf::appendf(), and port.
Referenced by Ssl::ServerBump::ServerBump(), Http::Tunneler::Tunneler(), Http::One::Server::buildHttpRequest(), ClientHttpRequest::checkForInternalAccess(), copyOneHeaderFromClientsideRequestToUpstreamRequest(), HttpRequest::effectiveRequestUri(), HttpStateData::httpBuildRequestHeader(), internalRemoteUri(), AnyP::operator<<(), and peerAllowedToUse().
|
static |
Definition at line 1076 of file Uri.cc.
References assert, Config, MAX_URL, rfc1738_do_escape(), RFC1738_ESCAPE_NOSPACE, RFC1738_ESCAPE_UNESCAPED, rfc1738_escape_unescaped, SquidConfig::uri_whitespace, URI_WHITESPACE_ALLOW, URI_WHITESPACE_CHOP, URI_WHITESPACE_DENY, URI_WHITESPACE_ENCODE, URI_WHITESPACE_STRIP, w_space, xfree, xisspace, xmalloc, and xstrndup().
Referenced by ClientHttpRequest::setLogUriToRawUri().
|
inline |
Definition at line 43 of file Uri.h.
References host_, hostAddr_, hostIsNumeric_, port_, AnyP::PROTO_NONE, scheme_, Ip::Address::setEmpty(), and touch().
Referenced by HttpRequest::clean(), and HttpRequest::init().
%-decode the given buffer
| std::nullopt | on decoding failures |
Definition at line 105 of file Uri.cc.
References SBuf::append(), CharacterSet::complement(), and debugs.
Referenced by Ftp::Gateway::decodedRequestUriPath(), and TestUri::testEncoding().
%-decode the given buffer
| decoded | input if input obeys RFC 3986 Percent-Encoding rules |
| an | input copy if input violates RFC 3986 Percent-Encoding rules |
Definition at line 132 of file Uri.cc.
Referenced by Acl::UrlCheck::match(), Acl::UrlLoginCheck::match(), and TestUri::testEncoding().
|
inline |
Definition at line 94 of file Uri.h.
References defaultPort(), getScheme(), and port().
Referenced by defaultPort().
|
static |
%-encode characters in a buffer which do not conform to the provided set of expected characters.
Governed by RFC 3986 section 2.1
Definition at line 76 of file Uri.cc.
References SBuf::append(), SBuf::appendf(), Parser::Tokenizer::atEnd(), SBuf::isEmpty(), SBuf::length(), Parser::Tokenizer::prefix(), Parser::Tokenizer::remaining(), SBuf::reserveSpace(), and Parser::Tokenizer::skip().
Referenced by ErrorState::Dump(), and TestUri::testEncoding().
|
inline |
Definition at line 58 of file Uri.h.
References scheme_.
Referenced by Format::Format::assemble(), clientReplyContext::cacheHit(), HttpRequest::canonicalCleanUrl(), carpSelectParent(), ClientHttpRequest::checkForInternalAccess(), clientHierarchical(), ErrorState::compileLegacyCode(), defaultPort(), FwdState::dispatch(), HttpRequest::effectiveRequestUri(), ClientRequestContext::hostHeaderVerify(), HttpStateData::httpBuildRequestHeader(), HttpRequest::maybeCacheable(), AnyP::operator<<(), HttpStateData::processReplyHeader(), purgeEntriesByHeader(), FwdState::secureConnectionToPeerIfNeeded(), PeerSelector::selectSomeDirect(), FwdState::Start(), TestUri::testConstructScheme(), TestHttpRequest::testCreateFromUrl(), TestUri::testDefaultConstructor(), TestHttpRequest::testIPv6HostColonBug(), urlCheckRequest(), and Ftp::UrlWith2f().
| void AnyP::Uri::host | ( | const char * | src | ) |
Definition at line 154 of file Uri.cc.
References debugs, and xstrncpy().
Referenced by PeerPoolMgr::PeerPoolMgr(), Format::Format::assemble(), ConnStateData::borrowPinnedConnection(), ConnStateData::buildFakeRequest(), carpSelectParent(), HttpStateData::checkDateSkew(), ClientHttpRequest::checkForInternalAccess(), PeerSelector::checkNetdbDirect(), ErrorState::compileLegacyCode(), TunnelStateData::connectDone(), FwdState::connectStart(), FwdState::dispatch(), doV2Query(), ftpSendUser(), TunnelStateData::getHost(), ClientRequestContext::hostHeaderVerify(), htcpTstReply(), clientReplyContext::identifyFoundObject(), internalRemoteUri(), ACLDestinationIP::match(), neighborType(), netdbClosestParent(), netdbUpdatePeer(), FwdState::noteConnection(), TunnelStateData::noteConnection(), PeerSelector::noteIps(), operator<<(), CacheManager::ParseUrl(), ConnStateData::pinConnection(), ConnStateData::postHttpsAccept(), HttpStateData::processReplyBody(), clientReplyContext::purgeRequest(), PeerSelector::resolveSelected(), PeerSelector::selectMore(), PeerSelector::selectSomeParent(), UrnState::setUriResFromRequest(), TunnelStateData::startConnecting(), ACLDestinationIP::StartLookup(), FwdState::successfullyConnectedToPeer(), TestHttpRequest::testCreateFromUrl(), TestHttpRequest::testIPv6HostColonBug(), TestCacheManager::testParseUrl(), urlCanonicalFakeHttps(), urnParseReply(), FwdState::usePinned(), and TunnelStateData::usePinned().
|
inline |
|
inline |
|
inline |
Definition at line 77 of file Uri.h.
References hostIsNumeric_.
Referenced by ACLDestinationIP::match().
| SBuf AnyP::Uri::hostOrIp | ( | ) | const |
Definition at line 170 of file Uri.cc.
References MAX_IPSTRLEN.
Referenced by ConnStateData::initiateTunneledRequest().
|
private |
|
inline |
Definition at line 154 of file Uri.h.
References absolutePath().
Referenced by HttpStateData::buildRequestPrefix(), HttpRequest::packFirstLineInto(), and HttpRequest::prefixLen().
| bool AnyP::Uri::parse | ( | const HttpRequestMethod & | method, |
| const SBuf & | url | ||
| ) |
Definition at line 326 of file Uri.cc.
References SquidConfig::allow_underscore, SquidConfig::appendDomainLen, Assure, SquidConfig::check_hostnames, Config, CurrentException(), DBG_IMPORTANT, debugs, AnyP::UriScheme::defaultPort(), Here, AnyP::UriScheme::image(), SBuf::length(), LOCAL_ARRAY, MAX_URL, Http::METHOD_CONNECT, Http::METHOD_OPTIONS, Http::METHOD_TRACE, MYNAME, SquidConfig::onoff, port, AnyP::PROTO_HTTP, AnyP::PROTO_NONE, AnyP::PROTO_URN, SBuf::rawContent(), rfc1738_escape_unescaped, rfc1738_unescape(), SBufToCstring(), stringHasWhitespace(), SquidConfig::uri_whitespace, URI_WHITESPACE_ALLOW, URI_WHITESPACE_CHOP, URI_WHITESPACE_DENY, URI_WHITESPACE_ENCODE, URI_WHITESPACE_STRIP, uriParseScheme(), urlAppendDomain(), valid_hostname_chars, valid_hostname_chars_u, w_space, xisspace, xstrncpy(), and xtolower.
Referenced by ClientRequestContext::clientRedirectDone(), HttpRequest::parseFirstLine(), and urnParseReply().
| std::optional< AnyP::Host > AnyP::Uri::parsedHost | ( | ) | const |
Successfully interpreted non-empty host subcomponent of the authority component (if any). XXX: Remove hostOrIp() and print Host instead.
Definition at line 181 of file Uri.cc.
References debugs, SBuf::find(), SBuf::npos, AnyP::Host::ParseIp(), and AnyP::Host::ParseSimpleDomainName().
Referenced by ConnStateData::serveDelayedError().
|
private |
Extracts and returns a (suspected but only partially validated) uri-host IPv6address, IPv4address, or reg-name component. This function uses (and quotes) RFC 3986, Section 3.2.2 syntax rules.
Definition at line 632 of file Uri.cc.
References SBuf::c_str(), SBuf::find(), Ip::Address::fromHost(), Here, CharacterSet::HEXDIG, SBuf::npos, and CharacterSet::TCHAR.
|
private |
Extracts and returns an RFC 3986 URI authority port value (with additional restrictions). The RFC defines port as a possibly empty sequence of decimal digits. We reject certain ports (that are syntactically valid from the RFC point of view) because we are worried that Squid and other traffic handlers may dangerously mishandle unusual (and virtually always bogus) port numbers. Rejected ports cannot be successfully used by Squid itself.
|
private |
Governed by RFC 8141 section 2:
assigned-name = "urn" ":" NID ":" NSS NID = (alphanum) 0*30(ldh) (alphanum) ldh = alphanum / "-" NSS = pchar *(pchar / "/")
RFC 3986 Appendix D.2 defines (as deprecated):
alphanum = ALPHA / DIGIT
Notice that NID is exactly 2-32 characters in length.
Definition at line 601 of file Uri.cc.
References CharacterSet::ALPHA, SBuf::begin(), SBuf::c_str(), debugs, CharacterSet::DIGIT, Here, SBuf::length(), AnyP::PROTO_URN, and SBuf::rbegin().
| const SBuf & AnyP::Uri::path | ( | ) | const |
Definition at line 200 of file Uri.cc.
References AnyP::PROTO_HTTP, and AnyP::PROTO_HTTPS.
|
inline |
Definition at line 96 of file Uri.h.
References path_, and touch().
Referenced by ClientHttpRequest::checkForInternalAccess(), ftpFail(), ftpReadType(), ftpSendType(), HttpRequest::initHTTP(), CacheManager::ParseUrl(), purgeEntriesByHeader(), TestHttpRequest::testCreateFromUrl(), TestHttpRequest::testIPv6HostColonBug(), TestCacheManager::testParseUrl(), urlCheckRequest(), and Ftp::UrlWith2f().
|
inline |
|
inline |
|
inline |
Definition at line 90 of file Uri.h.
References port_, and touch().
Referenced by Format::Format::assemble(), ConnStateData::borrowPinnedConnection(), ConnStateData::buildFakeRequest(), carpSelectParent(), ClientHttpRequest::checkForInternalAccess(), ErrorState::compileLegacyCode(), ClientRequestContext::hostHeaderVerify(), ConnStateData::initiateTunneledRequest(), internalRemoteUri(), PeerSelector::noteIp(), peerAllowedToUse(), ConnStateData::pinConnection(), ConnStateData::postHttpsAccept(), TestHttpRequest::testCreateFromUrl(), TestHttpRequest::testIPv6HostColonBug(), TestCacheManager::testParseUrl(), and urlCanonicalFakeHttps().
|
inline |
Definition at line 61 of file Uri.h.
References scheme_, and touch().
Referenced by ConnStateData::buildFakeRequest(), ClientHttpRequest::checkForInternalAccess(), HttpRequest::initHTTP(), and TestCacheManager::testParseUrl().
|
inline |
|
static |
Definition at line 147 of file Uri.cc.
Referenced by Ftp::UrlWith2f().
| void AnyP::Uri::touch | ( | ) |
Definition at line 712 of file Uri.cc.
Referenced by clear(), path(), path(), port(), setScheme(), setScheme(), and userInfo().
|
inline |
|
inline |
Definition at line 70 of file Uri.h.
References touch(), and userInfo_.
Referenced by clientInterpretRequestHeaders(), HttpStateData::httpBuildRequestHeader(), netdbExchangeStart(), and peerDigestRequest().
|
private |
|
private |
|
private |
Definition at line 189 of file Uri.h.
Referenced by clear(), and hostIsNumeric().
|
private |
|
private |
|
private |
Definition at line 182 of file Uri.h.
Referenced by clear(), getScheme(), setScheme(), and setScheme().
|
private |
Definition at line 184 of file Uri.h.
Referenced by userInfo(), and userInfo().