Uri.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 #ifndef SQUID_SRC_ANYP_URI_H
10 #define SQUID_SRC_ANYP_URI_H
11 
12 #include "anyp/UriScheme.h"
13 #include "ip/Address.h"
14 #include "rfc2181.h"
15 #include "sbuf/SBuf.h"
16 
17 #include <iosfwd>
18 
19 class HttpRequestMethod;
20 
21 namespace AnyP
22 {
23 
30 class Uri
31 {
33 
34 public:
36  Uri(AnyP::UriScheme const &aScheme);
37  Uri(const Uri &other) {
38  this->operator =(other);
39  }
40  Uri &operator =(const Uri &o) {
41  scheme_ = o.scheme_;
42  userInfo_ = o.userInfo_;
43  memcpy(host_, o.host_, sizeof(host_));
45  hostAddr_ = o.hostAddr_;
46  port_ = o.port_;
47  path_ = o.path_;
48  touch();
49  return *this;
50  }
51 
52  void clear() {
54  hostIsNumeric_ = false;
55  *host_ = 0;
57  port_ = 0;
58  touch();
59  }
60  void touch();
61 
62  bool parse(const HttpRequestMethod &, const SBuf &url);
63 
65  static char *cleanup(const char *uri);
66 
67  AnyP::UriScheme const & getScheme() const {return scheme_;}
68 
70  void setScheme(const AnyP::ProtocolType &p, const char *str) {
71  scheme_ = AnyP::UriScheme(p, str);
72  touch();
73  }
74  void setScheme(const AnyP::UriScheme &s) {
75  scheme_ = s;
76  touch();
77  }
78 
79  void userInfo(const SBuf &s) {userInfo_=s; touch();}
82  const SBuf &userInfo() const {return userInfo_;}
83 
84  void host(const char *src);
85  const char *host(void) const {return host_;}
86  int hostIsNumeric(void) const {return hostIsNumeric_;}
87  Ip::Address const & hostIP(void) const {return hostAddr_;}
88 
92  SBuf hostOrIp() const;
93 
94  void port(unsigned short p) {port_=p; touch();}
95  unsigned short port() const {return port_;}
98 
99  void path(const char *p) {path_=p; touch();}
100  void path(const SBuf &p) {path_=p; touch();}
101  const SBuf &path() const;
102 
112  void addRelativePath(const char *relUrl);
113 
115  static const SBuf &SlashPath();
116 
118  static const SBuf &Asterisk();
119 
122  static SBuf Encode(const SBuf &, const CharacterSet &expected);
123 
134  SBuf &authority(bool requirePort = false) const;
135 
143  SBuf &absolute() const;
144 
145 private:
147 
169 
170  SBuf userInfo_; // aka 'URL-login'
171 
172  // XXX: uses char[] instead of SBUf to reduce performance regressions
173  // from c_str() since most code using this is not yet using SBuf
177 
178  unsigned short port_;
179 
180  // XXX: for now includes query-string.
182 
183  // pre-assembled URI forms
186  mutable SBuf absolute_;
187 };
188 
189 } // namespace AnyP
190 
191 inline std::ostream &
192 operator <<(std::ostream &os, const AnyP::Uri &url)
193 {
194  // none means explicit empty string for scheme.
195  if (url.getScheme() != AnyP::PROTO_NONE)
196  os << url.getScheme().image();
197  os << ":";
198 
199  // no authority section on URN
200  if (url.getScheme() != AnyP::PROTO_URN)
201  os << "//" << url.authority();
202 
203  // path is what it is - including absent
204  os << url.path();
205  return os;
206 }
207 
208 /* Deprecated functions for Legacy code handling URLs */
209 
210 class HttpRequest;
211 
212 void urlInitialize(void);
217 const char *urlCanonicalFakeHttps(const HttpRequest * request);
218 bool urlIsRelative(const char *);
219 char *urlRInternal(const char *host, unsigned short port, const char *dir, const char *name);
220 char *urlInternal(const char *dir, const char *name);
221 bool urlAppendDomain(char *host);
222 
224  mdnNone = 0,
227 };
228 
262 int matchDomainName(const char *host, const char *domain, MatchDomainNameFlags flags = mdnNone);
263 int urlCheckRequest(const HttpRequest *);
264 void urlExtMethodConfigure(void);
265 
266 #endif /* SQUID_SRC_ANYP_URI_H */
267 
static char * cleanup(const char *uri)
Definition: Uri.cc:930
bool hostIsNumeric_
whether the authority 'host' is a raw-IP
Definition: Uri.h:175
@ mdnNone
Definition: Uri.h:224
Uri(const Uri &other)
Definition: Uri.h:37
bool urlAppendDomain(char *host)
apply append_domain config to the given hostname
Definition: Uri.cc:224
void userInfo(const SBuf &s)
Definition: Uri.h:79
void port(unsigned short p)
Definition: Uri.h:94
AnyP::Uri url
the request URI
Definition: HttpRequest.h:115
unsigned short port_
URL port.
Definition: Uri.h:178
Definition: Uri.h:30
char host_[SQUIDHOSTNAMELEN]
string representation of the URI authority name or IP
Definition: Uri.h:174
@ mdnHonorWildcards
Definition: Uri.h:225
RequestFlags flags
Definition: HttpRequest.h:141
@ PROTO_NONE
Definition: ProtocolType.h:24
int urlCheckRequest(const HttpRequest *)
Definition: Uri.cc:845
SBuf hostOrIp() const
Definition: Uri.cc:114
bool parse(const HttpRequestMethod &, const SBuf &url)
Definition: Uri.cc:253
Definition: SBuf.h:86
void defaultPort()
reset the port to the default port number for the current scheme
Definition: Uri.h:97
SBuf authorityWithPort_
RFC 7230 section 5.3.3 authority with explicit port.
Definition: Uri.h:185
const char * urlCanonicalFakeHttps(const HttpRequest *request)
Definition: Uri.cc:661
static int port
Definition: ldap_backend.cc:69
void urlInitialize(void)
Definition: Uri.cc:136
void urlExtMethodConfigure(void)
char * urlCanonicalCleanWithoutRequest(const SBuf &url, const HttpRequestMethod &, const AnyP::UriScheme &)
Definition: Uri.cc:632
void setScheme(const AnyP::UriScheme &s)
Definition: Uri.h:74
@ PROTO_URN
Definition: ProtocolType.h:37
ProtocolType
Definition: ProtocolType.h:23
AnyP::UriScheme scheme_
Definition: Uri.h:168
void path(const SBuf &p)
Definition: Uri.h:100
void clear()
Definition: Uri.h:52
bool urlIsRelative(const char *)
Definition: Uri.cc:688
Definition: forward.h:14
const SBuf & userInfo() const
Definition: Uri.h:82
MatchDomainNameFlags
Definition: Uri.h:223
void parseUrn(Parser::Tokenizer &)
Definition: Uri.cc:542
char * urlInternal(const char *dir, const char *name)
SBuf image() const
Definition: UriScheme.h:50
SBuf path_
URI path segment.
Definition: Uri.h:181
SBuf absolute_
RFC 7230 section 5.3.2 absolute-URI.
Definition: Uri.h:186
const AnyP::UriScheme & getScheme() const
Definition: Uri.h:67
SBuf & authority(bool requirePort=false) const
Definition: Uri.cc:578
char * urlRInternal(const char *host, unsigned short port, const char *dir, const char *name)
int matchDomainName(const char *host, const char *domain, MatchDomainNameFlags flags=mdnNone)
Definition: Uri.cc:748
void setEmpty()
Fast reset of the stored content to what would be after default constructor.
Definition: Address.cc:184
void addRelativePath(const char *relUrl)
Definition: Uri.cc:724
MEMPROXY_CLASS(Uri)
SBuf authorityHttp_
RFC 7230 section 5.3.3 authority, maybe without default-port.
Definition: Uri.h:184
static const SBuf & SlashPath()
the static '/' default URL-path
Definition: Uri.cc:91
SBuf & absolute() const
Definition: Uri.cc:596
unsigned short port() const
Definition: Uri.h:95
void path(const char *p)
Definition: Uri.h:99
@ mdnRejectSubsubDomains
Definition: Uri.h:226
const Ip::Address & hostIP(void) const
Definition: Uri.h:87
SBuf userInfo_
Definition: Uri.h:170
Uri()
Definition: Uri.h:35
std::ostream & operator<<(std::ostream &os, const AnyP::Uri &url)
Definition: Uri.h:192
int hostIsNumeric(void) const
Definition: Uri.h:86
optimized set of C chars, with quick membership test and merge support
Definition: CharacterSet.h:17
const SBuf & path() const
Definition: Uri.cc:124
Uri & operator=(const Uri &o)
Definition: Uri.h:40
void setScheme(const AnyP::ProtocolType &p, const char *str)
convert the URL scheme to that given
Definition: Uri.h:70
const char * host(void) const
Definition: Uri.h:85
#define false
Definition: GnuRegex.c:233
Ip::Address hostAddr_
binary representation of the URI authority if it is a raw-IP
Definition: Uri.h:176
static const SBuf & Asterisk()
the static '*' pseudo-URI
Definition: Uri.cc:84
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
static SBuf Encode(const SBuf &, const CharacterSet &expected)
Definition: Uri.cc:55
#define SQUIDHOSTNAMELEN
Definition: rfc2181.h:30
void touch()
clear the cached URI display forms
Definition: Uri.cc:570

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors