#include <Uri.h>

Collaboration diagram for AnyP::Uri:

Public Member Functions

 Uri ()
 
 Uri (AnyP::UriScheme const &aScheme)
 
 Uri (const Uri &other)
 
Urioperator= (const Uri &o)
 
void clear ()
 
void touch ()
 clear the cached URI display forms More...
 
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 More...
 
void setScheme (const AnyP::UriScheme &s)
 
void userInfo (const SBuf &s)
 
const SBufuserInfo () const
 
void host (const char *src)
 
const char * host (void) const
 
int hostIsNumeric (void) const
 
Ip::Address const & hostIP (void) const
 
SBuf hostOrIp () const
 
void port (const Port p)
 reset authority port subcomponent More...
 
Port port () const
 authority port subcomponent More...
 
void defaultPort ()
 reset the port to the default port number for the current scheme More...
 
void path (const char *p)
 
void path (const SBuf &p)
 
const SBufpath () const
 
void addRelativePath (const char *relUrl)
 
SBufauthority (bool requirePort=false) const
 
SBufabsolute () const
 

Static Public Member Functions

static char * cleanup (const char *uri)
 
static const SBufSlashPath ()
 the static '/' default URL-path More...
 
static const SBufAsterisk ()
 the static '*' pseudo-URI More...
 
static SBuf Encode (const SBuf &, const CharacterSet &expected)
 

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 More...
 
bool hostIsNumeric_
 whether the authority 'host' is a raw-IP More...
 
Ip::Address hostAddr_
 binary representation of the URI authority if it is a raw-IP More...
 
Port port_
 authority port subcomponent More...
 
SBuf path_
 URI path segment. More...
 
SBuf authorityHttp_
 RFC 7230 section 5.3.3 authority, maybe without default-port. More...
 
SBuf authorityWithPort_
 RFC 7230 section 5.3.3 authority with explicit port. More...
 
SBuf absolute_
 RFC 7230 section 5.3.2 absolute-URI. More...
 

Detailed Description

Represents a Uniform Resource Identifier. Can store both URL or URN representations.

Governed by RFC 3986

Definition at line 30 of file Uri.h.

Constructor & Destructor Documentation

◆ Uri() [1/3]

AnyP::Uri::Uri ( )
inline

Definition at line 35 of file Uri.h.

References host_.

◆ Uri() [2/3]

AnyP::Uri::Uri ( AnyP::UriScheme const &  aScheme)

Definition at line 984 of file Uri.cc.

References host_.

◆ Uri() [3/3]

AnyP::Uri::Uri ( const Uri other)
inline

Definition at line 37 of file Uri.h.

References operator=().

Member Function Documentation

◆ absolute()

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 668 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 asnCacheStart(), HttpRequest::effectiveRequestUri(), CacheManager::ParseUrl(), purgeEntriesByHeader(), UrnState::setUriResFromRequest(), and urnParseReply().

◆ addRelativePath()

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.

NP: absolute-path are also accepted, but path() method should be used instead when possible.

Definition at line 796 of file Uri.cc.

References SBuf::npos, and AnyP::PROTO_URN.

Referenced by purgeEntriesByHeader().

◆ Asterisk()

const SBuf & AnyP::Uri::Asterisk ( )
static

Definition at line 86 of file Uri.cc.

Referenced by urlCheckRequest().

◆ authority()

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.

Parameters
requirePortwhen true the port will be included, otherwise port will be elided when it is the default for the current scheme.

Definition at line 646 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().

◆ cleanup()

◆ clear()

void AnyP::Uri::clear ( )
inline

◆ defaultPort()

void AnyP::Uri::defaultPort ( )
inline

Definition at line 99 of file Uri.h.

References defaultPort(), getScheme(), and port().

Referenced by asnCacheStart(), and defaultPort().

◆ Encode()

SBuf AnyP::Uri::Encode ( const SBuf buf,
const CharacterSet ignore 
)
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 57 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().

◆ getScheme()

◆ host() [1/2]

void AnyP::Uri::host ( const char *  src)

◆ host() [2/2]

const char * AnyP::Uri::host ( void  ) const
inline

Definition at line 85 of file Uri.h.

References host_.

◆ hostIP()

Ip::Address const & AnyP::Uri::hostIP ( void  ) const
inline

Definition at line 87 of file Uri.h.

References hostAddr_.

Referenced by ACLDestinationIP::match().

◆ hostIsNumeric()

int AnyP::Uri::hostIsNumeric ( void  ) const
inline

Definition at line 86 of file Uri.h.

References hostIsNumeric_.

Referenced by ACLDestinationIP::match().

◆ hostOrIp()

SBuf AnyP::Uri::hostOrIp ( ) const
Returns
the host subcomponent of the authority component If the host is an IPv6 address, returns that IP address with [brackets]. See RFC 3986 Section 3.2.2.

Definition at line 115 of file Uri.cc.

References MAX_IPSTRLEN.

Referenced by ConnStateData::initiateTunneledRequest().

◆ MEMPROXY_CLASS()

AnyP::Uri::MEMPROXY_CLASS ( Uri  )
private

◆ operator=()

Uri & AnyP::Uri::operator= ( const Uri o)
inline

Definition at line 40 of file Uri.h.

References host_, hostAddr_, hostIsNumeric_, path_, port_, scheme_, touch(), and userInfo_.

Referenced by Uri().

◆ parse()

◆ parseHost()

SBuf AnyP::Uri::parseHost ( Parser::Tokenizer tok) const
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 558 of file Uri.cc.

References SBuf::c_str(), SBuf::find(), Ip::Address::fromHost(), Here, CharacterSet::HEXDIG, SBuf::npos, and CharacterSet::TCHAR.

◆ parsePort()

int AnyP::Uri::parsePort ( Parser::Tokenizer tok) const
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.

Definition at line 616 of file Uri.cc.

References Assure, Here, Less(), and max().

◆ parseUrn()

void AnyP::Uri::parseUrn ( Parser::Tokenizer tok)
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 527 of file Uri.cc.

References CharacterSet::ALPHA, SBuf::begin(), SBuf::c_str(), debugs, CharacterSet::DIGIT, Here, SBuf::length(), AnyP::PROTO_URN, and SBuf::rbegin().

◆ path() [1/3]

const SBuf & AnyP::Uri::path ( ) const

Definition at line 126 of file Uri.cc.

References AnyP::PROTO_HTTP, and AnyP::PROTO_HTTPS.

◆ path() [2/3]

◆ path() [3/3]

void AnyP::Uri::path ( const SBuf p)
inline

Definition at line 102 of file Uri.h.

References path_, and touch().

◆ port() [1/2]

Port AnyP::Uri::port ( ) const
inline

Definition at line 97 of file Uri.h.

References port_.

Referenced by defaultPort().

◆ port() [2/2]

◆ setScheme() [1/2]

void AnyP::Uri::setScheme ( const AnyP::ProtocolType p,
const char *  str 
)
inline

◆ setScheme() [2/2]

void AnyP::Uri::setScheme ( const AnyP::UriScheme s)
inline

Definition at line 74 of file Uri.h.

References scheme_, and touch().

◆ SlashPath()

const SBuf & AnyP::Uri::SlashPath ( )
static

Definition at line 93 of file Uri.cc.

◆ touch()

void AnyP::Uri::touch ( )

Definition at line 638 of file Uri.cc.

Referenced by clear(), operator=(), path(), port(), setScheme(), and userInfo().

◆ userInfo() [1/2]

const SBuf & AnyP::Uri::userInfo ( ) const
inline
Returns
raw userinfo subcomponent (or an empty string) the caller is responsible for caller-specific encoding

Definition at line 82 of file Uri.h.

References userInfo_.

◆ userInfo() [2/2]

void AnyP::Uri::userInfo ( const SBuf s)
inline

Member Data Documentation

◆ absolute_

SBuf AnyP::Uri::absolute_
mutableprivate

Definition at line 191 of file Uri.h.

◆ authorityHttp_

SBuf AnyP::Uri::authorityHttp_
mutableprivate

Definition at line 189 of file Uri.h.

◆ authorityWithPort_

SBuf AnyP::Uri::authorityWithPort_
mutableprivate

Definition at line 190 of file Uri.h.

◆ host_

char AnyP::Uri::host_[SQUIDHOSTNAMELEN]
private

Definition at line 179 of file Uri.h.

Referenced by Uri(), clear(), host(), and operator=().

◆ hostAddr_

Ip::Address AnyP::Uri::hostAddr_
private

Definition at line 181 of file Uri.h.

Referenced by clear(), hostIP(), and operator=().

◆ hostIsNumeric_

bool AnyP::Uri::hostIsNumeric_
private

Definition at line 180 of file Uri.h.

Referenced by clear(), hostIsNumeric(), and operator=().

◆ path_

SBuf AnyP::Uri::path_
private

Definition at line 186 of file Uri.h.

Referenced by operator=(), and path().

◆ port_

Port AnyP::Uri::port_
private

Definition at line 183 of file Uri.h.

Referenced by clear(), operator=(), and port().

◆ scheme_

AnyP::UriScheme AnyP::Uri::scheme_
private
The scheme of this URL. This has the 'type code' smell about it. In future we may want to make the methods that dispatch based on the scheme virtual and have a class per protocol.
On the other hand, having Protocol as an explicit concept is useful, see for instance the ACLProtocol acl type. One way to represent this 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 AnyP::UriScheme class instance for each URL scheme we support, and one class for each manner of treating the scheme : a Hierarchical URL, a non-hierarchical URL etc.
Deferring the decision, its a type code for now. RBC 20060507.
In order to make taking any of these routes easy, scheme is private, only settable at construction time, or with explicit setter

Definition at line 173 of file Uri.h.

Referenced by clear(), getScheme(), operator=(), and setScheme().

◆ userInfo_

SBuf AnyP::Uri::userInfo_
private

Definition at line 175 of file Uri.h.

Referenced by operator=(), and userInfo().


The documentation for this class was generated from the following files:

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors