Panda3D
Loading...
Searching...
No Matches
urlSpec.I
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file urlSpec.I
10 * @author drose
11 * @date 2002-09-24
12 */
13
14/**
15 *
16 */
17INLINE URLSpec::
18URLSpec(const std::string &url, bool server_name_expected) {
19 set_url(url, server_name_expected);
20}
21
22/**
23 *
24 */
25INLINE void URLSpec::
26operator = (const std::string &url) {
27 set_url(url);
28}
29
30/**
31 *
32 */
33INLINE bool URLSpec::
34operator == (const URLSpec &other) const {
35 return compare_to(other) == 0;
36}
37
38/**
39 *
40 */
41INLINE bool URLSpec::
42operator != (const URLSpec &other) const {
43 return compare_to(other) != 0;
44}
45
46/**
47 *
48 */
49INLINE bool URLSpec::
50operator < (const URLSpec &other) const {
51 return compare_to(other) < 0;
52}
53
54/**
55 * Returns true if the URL specifies a scheme (e.g. "http:"), false
56 * otherwise.
57 */
58INLINE bool URLSpec::
59has_scheme() const {
60 return (_flags & F_has_scheme) != 0;
61}
62
63/**
64 * Returns true if the URL specifies an authority (this includes username,
65 * server, and/or port), false otherwise.
66 */
67INLINE bool URLSpec::
68has_authority() const {
69 return (_flags & F_has_authority) != 0;
70}
71
72/**
73 * Returns true if the URL specifies a username (and/or password), false
74 * otherwise.
75 */
76INLINE bool URLSpec::
77has_username() const {
78 return (_flags & F_has_username) != 0;
79}
80
81/**
82 * Returns true if the URL specifies a server name, false otherwise.
83 */
84INLINE bool URLSpec::
85has_server() const {
86 return (_flags & F_has_server) != 0;
87}
88
89/**
90 * Returns true if the URL specifies a port number, false otherwise.
91 */
92INLINE bool URLSpec::
93has_port() const {
94 return (_flags & F_has_port) != 0;
95}
96
97/**
98 * Returns true if the URL includes a path specification (that is, the
99 * particular filename on the server to retrieve), false otherwise.
100 */
101INLINE bool URLSpec::
102has_path() const {
103 return (_flags & F_has_path) != 0;
104}
105
106/**
107 * Returns true if the URL includes a query specification, false otherwise.
108 */
109INLINE bool URLSpec::
110has_query() const {
111 return (_flags & F_has_query) != 0;
112}
113
114/**
115 * Returns the authority specified by the URL (this includes username, server,
116 * and/or port), or empty string if no authority is specified.
117 */
118INLINE std::string URLSpec::
119get_authority() const {
120 return _url.substr(_username_start, _port_end - _username_start);
121}
122
123/**
124 * Returns the username specified by the URL, if any. This might also include
125 * a password, e.g. "username:password", although putting a password on the
126 * URL is probably a bad idea.
127 */
128INLINE std::string URLSpec::
129get_username() const {
130 return _url.substr(_username_start, _username_end - _username_start);
131}
132
133/**
134 * Returns the server name specified by the URL, if any. In case of an IPv6
135 * address, does not include the enclosing brackets.
136 */
137INLINE std::string URLSpec::
138get_server() const {
139 return _url.substr(_server_start, _server_end - _server_start);
140}
141
142/**
143 * Returns the port specified by the URL as a string, or the empty string if
144 * no port is specified. Compare this with get_port(), which returns a
145 * default port number if no port is specified.
146 */
147INLINE std::string URLSpec::
148get_port_str() const {
149 return _url.substr(_port_start, _port_end - _port_start);
150}
151
152/**
153 * Returns the query specified by the URL, or empty string if no query is
154 * specified.
155 */
156INLINE std::string URLSpec::
157get_query() const {
158 return _url.substr(_query_start);
159}
160
161/**
162 * Returns true if the URL's scheme specifies an SSL-secured protocol such as
163 * https, or false otherwise.
164 */
165INLINE bool URLSpec::
166is_ssl() const {
167 if (has_scheme() && _scheme_end > 0) {
168 // If we have a scheme specification, assume it is SSL-secured if it ends
169 // in "s", except for the special case of "socks".
170 if (_url.substr(0, _scheme_end) == "socks") {
171 return false;
172 }
173 return (_url[_scheme_end - 1] == 's');
174 }
175
176 // If we have no scheme specification, it's not SSL-secured.
177 return false;
178}
179
180/**
181 * Returns the complete URL specification.
182 */
183INLINE const std::string &URLSpec::
184get_url() const {
185 return _url;
186}
187
188/**
189 *
190 */
191INLINE URLSpec::
192operator const std::string & () const {
193 return _url;
194}
195
196/**
197 *
198 */
199INLINE const char *URLSpec::
200c_str() const {
201 return _url.c_str();
202}
203
204/**
205 * Returns false if the URLSpec is valid (not empty), or true if it is an
206 * empty string.
207 */
208INLINE bool URLSpec::
209empty() const {
210 return _url.empty();
211}
212
213/**
214 * Returns true if the URLSpec is valid (not empty), or false if it is an
215 * empty string.
216 */
217INLINE URLSpec::
218operator bool() const {
219 return !_url.empty();
220}
221
222/**
223 *
224 */
225INLINE size_t URLSpec::
226length() const {
227 return _url.length();
228}
229
230/**
231 *
232 */
233INLINE size_t URLSpec::
234size() const {
235 return _url.size();
236}
237
238/**
239 *
240 */
241INLINE char URLSpec::
242operator [] (size_t n) const {
243 nassertr(n < _url.length(), '\0');
244 return _url[n];
245}
246
247INLINE std::istream &
248operator >> (std::istream &in, URLSpec &url) {
249 if (!url.input(in)) {
250 in.clear(std::ios::failbit | in.rdstate());
251 }
252 return in;
253}
254
255INLINE std::ostream &
256operator << (std::ostream &out, const URLSpec &url) {
257 url.output(out);
258 return out;
259}
A container for a URL, e.g.
Definition urlSpec.h:28
bool has_username() const
Returns true if the URL specifies a username (and/or password), false otherwise.
Definition urlSpec.I:77
bool empty() const
Returns false if the URLSpec is valid (not empty), or true if it is an empty string.
Definition urlSpec.I:209
bool has_path() const
Returns true if the URL includes a path specification (that is, the particular filename on the server...
Definition urlSpec.I:102
get_username
Returns the username specified by the URL, if any.
Definition urlSpec.h:95
bool has_authority() const
Returns true if the URL specifies an authority (this includes username, server, and/or port),...
Definition urlSpec.I:68
bool has_query() const
Returns true if the URL includes a query specification, false otherwise.
Definition urlSpec.I:110
const std::string & get_url() const
Returns the complete URL specification.
Definition urlSpec.I:184
get_server
Returns the server name specified by the URL, if any.
Definition urlSpec.h:96
get_query
Returns the query specified by the URL, or empty string if no query is specified.
Definition urlSpec.h:100
std::string get_port_str() const
Returns the port specified by the URL as a string, or the empty string if no port is specified.
Definition urlSpec.I:148
bool has_port() const
Returns true if the URL specifies a port number, false otherwise.
Definition urlSpec.I:93
bool has_scheme() const
Returns true if the URL specifies a scheme (e.g.
Definition urlSpec.I:59
is_ssl
Returns true if the URL's scheme specifies an SSL-secured protocol such as https, or false otherwise.
Definition urlSpec.h:101
void set_url(const std::string &url, bool server_name_expected=false)
Completely replaces the URL with the indicated string.
Definition urlSpec.cxx:554
bool has_server() const
Returns true if the URL specifies a server name, false otherwise.
Definition urlSpec.I:85
get_authority
Returns the authority specified by the URL (this includes username, server, and/or port),...
Definition urlSpec.h:94
int compare_to(const URLSpec &other) const
Returns a number less than zero if this URLSpec sorts before the other one, greater than zero if it s...
Definition urlSpec.cxx:77