Uri.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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 char *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 
75  void userInfo(const SBuf &s) {userInfo_=s; touch();}
76  const SBuf &userInfo() const {return userInfo_;}
77 
78  void host(const char *src);
79  const char *host(void) const {return host_;}
80  int hostIsNumeric(void) const {return hostIsNumeric_;}
81  Ip::Address const & hostIP(void) const {return hostAddr_;}
82 
86  SBuf hostOrIp() const;
87 
88  void port(unsigned short p) {port_=p; touch();}
89  unsigned short port() const {return port_;}
92 
93  void path(const char *p) {path_=p; touch();}
94  void path(const SBuf &p) {path_=p; touch();}
95  const SBuf &path() const;
96 
98  static const SBuf &SlashPath();
99 
101  static const SBuf &Asterisk();
102 
113  SBuf &authority(bool requirePort = false) const;
114 
122  SBuf &absolute() const;
123 
124 private:
125  void parseFinish(const AnyP::ProtocolType, const char *const, const char *const, const char *const, const SBuf &, const int);
126 
148 
149  SBuf userInfo_; // aka 'URL-login'
150 
151  // XXX: uses char[] instead of SBUf to reduce performance regressions
152  // from c_str() since most code using this is not yet using SBuf
156 
157  unsigned short port_;
158 
159  // XXX: for now includes query-string.
161 
162  // pre-assembled URI forms
165  mutable SBuf absolute_;
166 };
167 
168 } // namespace AnyP
169 
170 inline std::ostream &
171 operator <<(std::ostream &os, const AnyP::Uri &url)
172 {
173  // none means explicit empty string for scheme.
174  if (url.getScheme() != AnyP::PROTO_NONE)
175  os << url.getScheme().image();
176  os << ":";
177 
178  // no authority section on URN
179  if (url.getScheme() != AnyP::PROTO_URN)
180  os << "//" << url.authority();
181 
182  // path is what it is - including absent
183  os << url.path();
184  return os;
185 }
186 
187 /* Deprecated functions for Legacy code handling URLs */
188 
189 class HttpRequest;
190 
191 void urlInitialize(void);
195 char *urlCanonicalCleanWithoutRequest(const SBuf &url, const HttpRequestMethod &, const AnyP::UriScheme &);
196 const char *urlCanonicalFakeHttps(const HttpRequest * request);
197 bool urlIsRelative(const char *);
198 char *urlMakeAbsolute(const HttpRequest *, const char *);
199 char *urlRInternal(const char *host, unsigned short port, const char *dir, const char *name);
200 char *urlInternal(const char *dir, const char *name);
201 bool urlAppendDomain(char *host);
202 
204  mdnNone = 0,
207 };
208 
242 int matchDomainName(const char *host, const char *domain, uint8_t flags = mdnNone);
243 int urlCheckRequest(const HttpRequest *);
244 char *urlHostname(const char *url);
245 void urlExtMethodConfigure(void);
246 
247 #endif /* SQUID_SRC_ANYP_URI_H */
248 
void path(const SBuf &p)
Definition: Uri.h:94
SBuf & authority(bool requirePort=false) const
Definition: Uri.cc:503
SBuf image() const
Definition: UriScheme.h:50
void path(const char *p)
Definition: Uri.h:93
Definition: SBuf.h:86
SBuf userInfo_
Definition: Uri.h:149
unsigned short port() const
Definition: Uri.h:89
char * urlMakeAbsolute(const HttpRequest *, const char *)
Definition: Uri.cc:634
MatchDomainNameFlags
Definition: Uri.h:203
SBuf path_
URI path segment.
Definition: Uri.h:160
static const SBuf & SlashPath()
the static &#39;/&#39; default URL-path
Definition: Uri.cc:40
SBuf authorityHttp_
RFC 7230 section 5.3.3 authority, maybe without default-port.
Definition: Uri.h:163
char * p
Definition: membanger.c:43
char * urlHostname(const char *url)
Definition: Uri.cc:891
MEMPROXY_CLASS(Uri)
static const SBuf & Asterisk()
the static &#39;*&#39; pseudo-URI
Definition: Uri.cc:33
SBuf & absolute() const
Definition: Uri.cc:521
const char * host(void) const
Definition: Uri.h:79
void urlInitialize(void)
Definition: Uri.cc:85
void port(unsigned short p)
Definition: Uri.h:88
int matchDomainName(const char *host, const char *domain, uint8_t flags=mdnNone)
Definition: Uri.cc:693
Uri()
Definition: Uri.h:35
Uri & operator=(const Uri &o)
Definition: Uri.h:40
bool parse(const HttpRequestMethod &, const char *url)
Definition: Uri.cc:225
void setScheme(const AnyP::ProtocolType &p, const char *str)
convert the URL scheme to that given
Definition: Uri.h:70
void touch()
clear the cached URI display forms
Definition: Uri.cc:495
Definition: forward.h:14
char * urlInternal(const char *dir, const char *name)
int hostIsNumeric(void) const
Definition: Uri.h:80
void userInfo(const SBuf &s)
Definition: Uri.h:75
const SBuf & path() const
Definition: Uri.cc:73
bool urlIsRelative(const char *)
Definition: Uri.cc:601
const char * urlCanonicalFakeHttps(const HttpRequest *request)
Definition: Uri.cc:580
unsigned short port_
URL port.
Definition: Uri.h:157
Ip::Address hostAddr_
binary representation of the URI authority if it is a raw-IP
Definition: Uri.h:155
void setEmpty()
Fast reset of the stored content to what would be after default constructor.
Definition: Address.cc:184
bool urlAppendDomain(char *host)
apply append_domain config to the given hostname
Definition: Uri.cc:188
Uri(const Uri &other)
Definition: Uri.h:37
void parseFinish(const AnyP::ProtocolType, const char *const, const char *const, const char *const, const SBuf &, const int)
Update the URL object with parsed URI data.
Definition: Uri.cc:480
static char * cleanup(const char *uri)
Definition: Uri.cc:974
bool hostIsNumeric_
whether the authority &#39;host&#39; is a raw-IP
Definition: Uri.h:154
Definition: Uri.h:204
RequestFlags flags
Definition: HttpRequest.h:141
SBuf authorityWithPort_
RFC 7230 section 5.3.3 authority with explicit port.
Definition: Uri.h:164
Definition: Uri.h:30
char * urlRInternal(const char *host, unsigned short port, const char *dir, const char *name)
#define SQUIDHOSTNAMELEN
Definition: rfc2181.h:30
char host_[SQUIDHOSTNAMELEN]
string representation of the URI authority name or IP
Definition: Uri.h:153
ProtocolType
Definition: ProtocolType.h:22
void urlExtMethodConfigure(void)
SBuf hostOrIp() const
Definition: Uri.cc:63
const SBuf & userInfo() const
Definition: Uri.h:76
std::ostream & operator<<(std::ostream &os, ProtocolType const &p)
Definition: ProtocolType.h:53
AnyP::UriScheme scheme_
Definition: Uri.h:147
void defaultPort()
reset the port to the default port number for the current scheme
Definition: Uri.h:91
Ip::Address const & hostIP(void) const
Definition: Uri.h:81
AnyP::UriScheme const & getScheme() const
Definition: Uri.h:67
void clear()
Definition: Uri.h:52
int urlCheckRequest(const HttpRequest *)
Definition: Uri.cc:790
char * urlCanonicalCleanWithoutRequest(const SBuf &url, const HttpRequestMethod &, const AnyP::UriScheme &)
Definition: Uri.cc:551
SBuf absolute_
RFC 7230 section 5.3.2 absolute-URI.
Definition: Uri.h:165
#define false
Definition: GnuRegex.c:233

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors