]>
Commit | Line | Data |
---|---|---|
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" |
92d6986d | 13 | #include "SBuf.h" |
985c86bc | 14 | |
63be0a78 | 15 | /** |
63be0a78 | 16 | * The URL class represents a Uniform Resource Location |
17 | */ | |
985c86bc | 18 | class URL |
19 | { | |
985c86bc | 20 | MEMPROXY_CLASS(URL); |
741c2986 AJ |
21 | |
22 | public: | |
1ca54a54 AJ |
23 | URL() : scheme_() {} |
24 | URL(AnyP::UriScheme const &aScheme) : scheme_(aScheme) {} | |
4e3f4dc7 AJ |
25 | |
26 | void clear() { | |
27 | scheme_=AnyP::PROTO_NONE; | |
28 | } | |
29 | ||
1ca54a54 | 30 | AnyP::UriScheme const & getScheme() const {return scheme_;} |
985c86bc | 31 | |
4e3f4dc7 AJ |
32 | /// convert the URL scheme to that given |
33 | void setScheme(const AnyP::ProtocolType &p) {scheme_=p;} | |
34 | ||
92d6986d AJ |
35 | void userInfo(const SBuf &s) {userInfo_=s;} |
36 | const SBuf &userInfo() const {return userInfo_;} | |
37 | ||
2e260208 AJ |
38 | /// the static '*' pseudo-URL |
39 | static const SBuf &Asterisk(); | |
40 | ||
985c86bc | 41 | private: |
63be0a78 | 42 | /** |
43 | \par | |
44 | * The scheme of this URL. This has the 'type code' smell about it. | |
26ac0430 AJ |
45 | * In future we may want to make the methods that dispatch based on |
46 | * the scheme virtual and have a class per protocol. | |
63be0a78 | 47 | \par |
48 | * On the other hand, having Protocol as an explicit concept is useful, | |
985c86bc | 49 | * see for instance the ACLProtocol acl type. One way to represent this |
26ac0430 | 50 | * is to have one prototype URL with no host etc for each scheme, |
985c86bc | 51 | * another is to have an explicit scheme class, and then each URL class |
26ac0430 | 52 | * could be a subclass of the scheme. Another way is one instance of |
1ca54a54 | 53 | * a AnyP::UriScheme class instance for each URL scheme we support, and one URL |
985c86bc | 54 | * class for each manner of treating the scheme : a Hierarchical URL, a |
63be0a78 | 55 | * non-hierarchical URL etc. |
56 | \par | |
985c86bc | 57 | * Deferring the decision, its a type code for now. RBC 20060507. |
63be0a78 | 58 | \par |
26ac0430 | 59 | * In order to make taking any of these routes easy, scheme is private |
985c86bc | 60 | * and immutable, only settable at construction time, |
61 | */ | |
4e3f4dc7 | 62 | AnyP::UriScheme scheme_; |
92d6986d AJ |
63 | |
64 | SBuf userInfo_; // aka 'URL-login' | |
985c86bc | 65 | }; |
66 | ||
fc54b8d2 FC |
67 | class HttpRequest; |
68 | class HttpRequestMethod; | |
69 | ||
8a648e8d FC |
70 | AnyP::ProtocolType urlParseProtocol(const char *, const char *e = NULL); |
71 | void urlInitialize(void); | |
72 | HttpRequest *urlParse(const HttpRequestMethod&, char *, HttpRequest *request = NULL); | |
73 | const char *urlCanonical(HttpRequest *); | |
74 | char *urlCanonicalClean(const HttpRequest *); | |
75 | const char *urlCanonicalFakeHttps(const HttpRequest * request); | |
76 | bool urlIsRelative(const char *); | |
77 | char *urlMakeAbsolute(const HttpRequest *, const char *); | |
78 | char *urlRInternal(const char *host, unsigned short port, const char *dir, const char *name); | |
79 | char *urlInternal(const char *dir, const char *name); | |
69f69080 CT |
80 | |
81 | /** | |
82 | * matchDomainName() compares a hostname (usually extracted from traffic) | |
83 | * with a domainname (usually from an ACL) according to the following rules: | |
84 | * | |
85 | * HOST | DOMAIN | MATCH? | |
86 | * -------------|-------------|------ | |
87 | * foo.com | foo.com | YES | |
88 | * .foo.com | foo.com | YES | |
89 | * x.foo.com | foo.com | NO | |
90 | * foo.com | .foo.com | YES | |
91 | * .foo.com | .foo.com | YES | |
92 | * x.foo.com | .foo.com | YES | |
93 | * | |
94 | * We strip leading dots on hosts (but not domains!) so that | |
95 | * ".foo.com" is always the same as "foo.com". | |
96 | * | |
97 | * if honorWildcards is true then the matchDomainName() also accepts | |
98 | * optional wildcards on hostname: | |
99 | * | |
100 | * HOST | DOMAIN | MATCH? | |
101 | * -------------|--------------|------- | |
102 | * *.foo.com | x.foo.com | YES | |
103 | * *.foo.com | .x.foo.com | YES | |
104 | * *.foo.com | .foo.com | YES | |
105 | * *.foo.com | foo.com | NO | |
106 | * | |
107 | * \retval 0 means the host matches the domain | |
108 | * \retval 1 means the host is greater than the domain | |
109 | * \retval -1 means the host is less than the domain | |
110 | */ | |
111 | int matchDomainName(const char *host, const char *domain, bool honorWildcards = false); | |
8a648e8d FC |
112 | int urlCheckRequest(const HttpRequest *); |
113 | int urlDefaultPort(AnyP::ProtocolType p); | |
114 | char *urlHostname(const char *url); | |
115 | void urlExtMethodConfigure(void); | |
fc54b8d2 | 116 | |
985c86bc | 117 | #endif /* SQUID_SRC_URL_H_H */ |
f53969cc | 118 |