]> git.ipfire.org Git - thirdparty/squid.git/blame - src/URL.h
Revert r14137 due to compile errors
[thirdparty/squid.git] / src / URL.h
CommitLineData
985c86bc 1/*
bde978a6 2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
985c86bc 3 *
bbc27441
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
985c86bc 7 */
8
9#ifndef SQUID_SRC_URL_H
10#define SQUID_SRC_URL_H
11
1ca54a54 12#include "anyp/UriScheme.h"
5c51bffb
AJ
13#include "ip/Address.h"
14#include "rfc2181.h"
92d6986d 15#include "SBuf.h"
985c86bc 16
63be0a78 17/**
63be0a78 18 * The URL class represents a Uniform Resource Location
5c51bffb
AJ
19 *
20 * Governed by RFC 3986
63be0a78 21 */
985c86bc 22class URL
23{
985c86bc 24 MEMPROXY_CLASS(URL);
741c2986
AJ
25
26public:
5c51bffb
AJ
27 URL() : scheme_(), hostIsNumeric_(false), port_(0) {*host_=0;}
28 URL(AnyP::UriScheme const &aScheme) : scheme_(aScheme), hostIsNumeric_(false), port_(0) {*host_=0;}
4e3f4dc7
AJ
29
30 void clear() {
31 scheme_=AnyP::PROTO_NONE;
5c51bffb
AJ
32 hostIsNumeric_ = false;
33 *host_ = 0;
34 hostAddr_.setEmpty();
35 port_ = 0;
36 touch();
4e3f4dc7 37 }
5c51bffb 38 void touch(); ///< clear the cached URI display forms
4e3f4dc7 39
1ca54a54 40 AnyP::UriScheme const & getScheme() const {return scheme_;}
985c86bc 41
4e3f4dc7 42 /// convert the URL scheme to that given
5c51bffb 43 void setScheme(const AnyP::ProtocolType &p) {scheme_=p; touch();}
4e3f4dc7 44
5c51bffb 45 void userInfo(const SBuf &s) {userInfo_=s; touch();}
92d6986d
AJ
46 const SBuf &userInfo() const {return userInfo_;}
47
5c51bffb
AJ
48 void host(const char *src);
49 const char *host(void) const {return host_;}
50 int hostIsNumeric(void) const {return hostIsNumeric_;}
51 Ip::Address const & hostIP(void) const {return hostAddr_;}
52
53 void port(unsigned short p) {port_=p; touch();}
54 unsigned short port() const {return port_;}
55
2e260208
AJ
56 /// the static '*' pseudo-URL
57 static const SBuf &Asterisk();
58
5c51bffb
AJ
59 /**
60 * The authority-form URI for currently stored values.
61 *
62 * As defined by RFC 7230 section 5.3.3 this form omits the
63 * userinfo@ field from RFC 3986 defined authority segment.
64 *
65 * \param requirePort when true the port will be included, otherwise
66 * port will be elided when it is the default for
67 * the current scheme.
68 */
69 SBuf &authority(bool requirePort = false) const;
70
985c86bc 71private:
63be0a78 72 /**
73 \par
74 * The scheme of this URL. This has the 'type code' smell about it.
26ac0430
AJ
75 * In future we may want to make the methods that dispatch based on
76 * the scheme virtual and have a class per protocol.
63be0a78 77 \par
78 * On the other hand, having Protocol as an explicit concept is useful,
985c86bc 79 * see for instance the ACLProtocol acl type. One way to represent this
26ac0430 80 * is to have one prototype URL with no host etc for each scheme,
985c86bc 81 * another is to have an explicit scheme class, and then each URL class
26ac0430 82 * could be a subclass of the scheme. Another way is one instance of
1ca54a54 83 * a AnyP::UriScheme class instance for each URL scheme we support, and one URL
985c86bc 84 * class for each manner of treating the scheme : a Hierarchical URL, a
63be0a78 85 * non-hierarchical URL etc.
86 \par
985c86bc 87 * Deferring the decision, its a type code for now. RBC 20060507.
63be0a78 88 \par
26ac0430 89 * In order to make taking any of these routes easy, scheme is private
985c86bc 90 * and immutable, only settable at construction time,
91 */
4e3f4dc7 92 AnyP::UriScheme scheme_;
92d6986d
AJ
93
94 SBuf userInfo_; // aka 'URL-login'
5c51bffb
AJ
95
96 // XXX: uses char[] instead of SBUf to reduce performance regressions
97 // from c_str() since most code using this is not yet using SBuf
98 char host_[SQUIDHOSTNAMELEN]; ///< string representation of the URI authority name or IP
99 bool hostIsNumeric_; ///< whether the authority 'host' is a raw-IP
100 Ip::Address hostAddr_; ///< binary representation of the URI authority if it is a raw-IP
101
102 unsigned short port_; ///< URL port
103
104 // pre-assembled URL forms
105 mutable SBuf authorityHttp_; ///< RFC 7230 section 5.3.3 authority, maybe without default-port
106 mutable SBuf authorityWithPort_; ///< RFC 7230 section 5.3.3 authority with explicit port
985c86bc 107};
108
fc54b8d2
FC
109class HttpRequest;
110class HttpRequestMethod;
111
8a648e8d
FC
112AnyP::ProtocolType urlParseProtocol(const char *, const char *e = NULL);
113void urlInitialize(void);
114HttpRequest *urlParse(const HttpRequestMethod&, char *, HttpRequest *request = NULL);
115const char *urlCanonical(HttpRequest *);
116char *urlCanonicalClean(const HttpRequest *);
117const char *urlCanonicalFakeHttps(const HttpRequest * request);
118bool urlIsRelative(const char *);
119char *urlMakeAbsolute(const HttpRequest *, const char *);
120char *urlRInternal(const char *host, unsigned short port, const char *dir, const char *name);
121char *urlInternal(const char *dir, const char *name);
69f69080
CT
122
123/**
124 * matchDomainName() compares a hostname (usually extracted from traffic)
125 * with a domainname (usually from an ACL) according to the following rules:
126 *
127 * HOST | DOMAIN | MATCH?
128 * -------------|-------------|------
129 * foo.com | foo.com | YES
130 * .foo.com | foo.com | YES
131 * x.foo.com | foo.com | NO
132 * foo.com | .foo.com | YES
133 * .foo.com | .foo.com | YES
134 * x.foo.com | .foo.com | YES
135 *
136 * We strip leading dots on hosts (but not domains!) so that
137 * ".foo.com" is always the same as "foo.com".
138 *
139 * if honorWildcards is true then the matchDomainName() also accepts
140 * optional wildcards on hostname:
141 *
142 * HOST | DOMAIN | MATCH?
143 * -------------|--------------|-------
144 * *.foo.com | x.foo.com | YES
145 * *.foo.com | .x.foo.com | YES
146 * *.foo.com | .foo.com | YES
147 * *.foo.com | foo.com | NO
148 *
149 * \retval 0 means the host matches the domain
150 * \retval 1 means the host is greater than the domain
151 * \retval -1 means the host is less than the domain
152 */
153int matchDomainName(const char *host, const char *domain, bool honorWildcards = false);
8a648e8d 154int urlCheckRequest(const HttpRequest *);
8a648e8d
FC
155char *urlHostname(const char *url);
156void urlExtMethodConfigure(void);
fc54b8d2 157
985c86bc 158#endif /* SQUID_SRC_URL_H_H */
f53969cc 159