URL.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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_URL_H
10 #define SQUID_SRC_URL_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 
24 class URL
25 {
27 
28 public:
30  URL(AnyP::UriScheme const &aScheme);
31  URL(const URL &other) {
32  this->operator =(other);
33  }
34  URL &operator =(const URL &o) {
35  scheme_ = o.scheme_;
36  userInfo_ = o.userInfo_;
37  memcpy(host_, o.host_, sizeof(host_));
39  hostAddr_ = o.hostAddr_;
40  port_ = o.port_;
41  path_ = o.path_;
42  touch();
43  return *this;
44  }
45 
46  void clear() {
48  hostIsNumeric_ = false;
49  *host_ = 0;
51  port_ = 0;
52  touch();
53  }
54  void touch();
55 
56  bool parse(const HttpRequestMethod &, const char *url);
57 
58  AnyP::UriScheme const & getScheme() const {return scheme_;}
59 
61  void setScheme(const AnyP::ProtocolType &p, const char *str) {
62  scheme_ = AnyP::UriScheme(p, str);
63  touch();
64  }
65 
66  void userInfo(const SBuf &s) {userInfo_=s; touch();}
67  const SBuf &userInfo() const {return userInfo_;}
68 
69  void host(const char *src);
70  const char *host(void) const {return host_;}
71  int hostIsNumeric(void) const {return hostIsNumeric_;}
72  Ip::Address const & hostIP(void) const {return hostAddr_;}
73 
74  void port(unsigned short p) {port_=p; touch();}
75  unsigned short port() const {return port_;}
76 
77  void path(const char *p) {path_=p; touch();}
78  void path(const SBuf &p) {path_=p; touch();}
79  const SBuf &path() const;
80 
82  static const SBuf &SlashPath();
83 
85  static const SBuf &Asterisk();
86 
97  SBuf &authority(bool requirePort = false) const;
98 
106  SBuf &absolute() const;
107 
108 private:
109  void parseFinish(const AnyP::ProtocolType, const char *const, const char *const, const char *const, const SBuf &, const int);
110 
132 
133  SBuf userInfo_; // aka 'URL-login'
134 
135  // XXX: uses char[] instead of SBUf to reduce performance regressions
136  // from c_str() since most code using this is not yet using SBuf
140 
141  unsigned short port_;
142 
143  // XXX: for now includes query-string.
145 
146  // pre-assembled URL forms
149  mutable SBuf absolute_;
150 };
151 
152 inline std::ostream &
153 operator <<(std::ostream &os, const URL &url)
154 {
155  // none means explicit empty string for scheme.
156  if (url.getScheme() != AnyP::PROTO_NONE)
157  os << url.getScheme().image();
158  os << ":";
159 
160  // no authority section on URN
161  if (url.getScheme() != AnyP::PROTO_URN)
162  os << "//" << url.authority();
163 
164  // path is what it is - including absent
165  os << url.path();
166  return os;
167 }
168 
169 class HttpRequest;
170 class HttpRequestMethod;
171 
172 void urlInitialize(void);
173 char *urlCanonicalClean(const HttpRequest *);
174 const char *urlCanonicalFakeHttps(const HttpRequest * request);
175 bool urlIsRelative(const char *);
176 char *urlMakeAbsolute(const HttpRequest *, const char *);
177 char *urlRInternal(const char *host, unsigned short port, const char *dir, const char *name);
178 char *urlInternal(const char *dir, const char *name);
179 
181  mdnNone = 0,
184 };
185 
219 int matchDomainName(const char *host, const char *domain, uint flags = mdnNone);
220 int urlCheckRequest(const HttpRequest *);
221 char *urlHostname(const char *url);
222 void urlExtMethodConfigure(void);
223 
224 #endif /* SQUID_SRC_URL_H_H */
225 
bool hostIsNumeric_
whether the authority 'host' is a raw-IP
Definition: URL.h:138
static const SBuf & SlashPath()
the static '/' default URL-path
Definition: url.cc:40
int hostIsNumeric(void) const
Definition: URL.h:71
const char * host(void) const
Definition: URL.h:70
AnyP::UriScheme scheme_
Definition: URL.h:131
MEMPROXY_CLASS(URL)
char * urlHostname(const char *url)
Definition: url.cc:858
void urlInitialize(void)
Definition: url.cc:75
Definition: SBuf.h:87
SBuf image() const
Definition: UriScheme.h:50
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
bool parse(const HttpRequestMethod &, const char *url)
Definition: url.cc:191
std::ostream & operator<<(std::ostream &os, const URL &url)
Definition: URL.h:153
void port(unsigned short p)
Definition: URL.h:74
char * p
Definition: membanger.c:43
URL()
Definition: URL.h:29
const char * urlCanonicalFakeHttps(const HttpRequest *request)
Definition: url.cc:547
const SBuf & path() const
Definition: url.cc:63
MatchDomainNameFlags
Definition: URL.h:180
static const SBuf & Asterisk()
the static '*' pseudo-URL
Definition: stub_url.cc:26
Definition: URL.h:24
void userInfo(const SBuf &s)
Definition: URL.h:66
Ip::Address const & hostIP(void) const
Definition: URL.h:72
void clear()
Definition: URL.h:46
SBuf userInfo_
Definition: URL.h:133
const SBuf & userInfo() const
Definition: URL.h:67
URL(const URL &other)
Definition: URL.h:31
Definition: URL.h:181
SBuf & authority(bool requirePort=false) const
Definition: url.cc:470
AnyP::UriScheme const & getScheme() const
Definition: URL.h:58
char * urlCanonicalClean(const HttpRequest *)
Definition: url.cc:518
void touch()
clear the cached URI display forms
Definition: stub_url.cc:20
SBuf path_
URL path segment.
Definition: URL.h:144
char * urlInternal(const char *dir, const char *name)
void setEmpty()
Fast reset of the stored content to what would be after default constructor.
Definition: Address.cc:177
void urlExtMethodConfigure(void)
static int port
Definition: ldap_backend.cc:69
int urlCheckRequest(const HttpRequest *)
Definition: url.cc:757
void path(const char *p)
Definition: URL.h:77
void setScheme(const AnyP::ProtocolType &p, const char *str)
convert the URL scheme to that given
Definition: URL.h:61
unsigned short port() const
Definition: URL.h:75
#define SQUIDHOSTNAMELEN
Definition: rfc2181.h:30
ProtocolType
Definition: ProtocolType.h:22
char host_[SQUIDHOSTNAMELEN]
string representation of the URI authority name or IP
Definition: URL.h:137
SBuf authorityWithPort_
RFC 7230 section 5.3.3 authority with explicit port.
Definition: URL.h:148
bool urlIsRelative(const char *)
Definition: url.cc:568
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: url.cc:447
SBuf authorityHttp_
RFC 7230 section 5.3.3 authority, maybe without default-port.
Definition: URL.h:147
void path(const SBuf &p)
Definition: URL.h:78
int matchDomainName(const char *host, const char *domain, uint flags=mdnNone)
Definition: url.cc:660
URL & operator=(const URL &o)
Definition: URL.h:34
char * urlRInternal(const char *host, unsigned short port, const char *dir, const char *name)
Ip::Address hostAddr_
binary representation of the URI authority if it is a raw-IP
Definition: URL.h:139
SBuf & absolute() const
Definition: url.cc:488
unsigned short port_
URL port.
Definition: URL.h:141
#define false
Definition: GnuRegex.c:233
SBuf absolute_
RFC 7230 section 5.3.2 absolute-URI.
Definition: URL.h:149
char * urlMakeAbsolute(const HttpRequest *, const char *)
Definition: url.cc:601

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors