]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/uri.h
say that use of _T() is discouraged in new code, just like wxT() is
[wxWidgets.git] / interface / wx / uri.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: uri.h
e54c96f1 3// Purpose: interface of wxURI
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
fbec75d0
BP
9/**
10 Host type of URI returned from wxURI::GetHostType().
11*/
12enum wxURIHostType
13{
14 wxURI_REGNAME, ///< Host is a normal register name (@c "www.mysite.com").
15 wxURI_IPV4ADDRESS, ///< Host is a version 4 ip address (@c "192.168.1.100").
16 wxURI_IPV6ADDRESS, ///< Host is a version 6 ip address (@c "[aa:aa:aa:aa::aa:aa]:5050").
17 wxURI_IPVFUTURE ///< Host is a future ip address, wxURI is unsure what kind.
18};
19
23324ae1
FM
20/**
21 @class wxURI
7c913512 22
fbec75d0
BP
23 wxURI is used to extract information from a URI (Uniform Resource
24 Identifier).
7c913512 25
fbec75d0
BP
26 For information about URIs, see RFC 3986
27 <http://www.ietf.org/rfc/rfc3986.txt>.
7c913512 28
fbec75d0 29 In short, a URL is a URI. In other words, URL is a subset of a URI - all
23324ae1 30 acceptable URLs are also acceptable URIs.
7c913512 31
fbec75d0
BP
32 wxURI automatically escapes invalid characters in a string, so there is no
33 chance of wxURI "failing" on construction/creation.
34
35 wxURI supports copy construction and standard assignment operators. wxURI
36 can also be inherited from to provide furthur functionality.
37
38 To obtain individual components you can use one of the GetXXX() methods.
39 However, you should check HasXXX() before calling a get method, which
40 determines whether or not the component referred to by the method is
41 defined according to RFC 2396. Consider an undefined component equivalent
42 to a @NULL C string.
43
44 Example:
45
46 @code
47 //protocol will hold the http protocol (i.e. "http")
48 wxString protocol;
49 wxURI myuri("http://mysite.com");
50 if( myuri.HasScheme() )
51 protocol = myuri.GetScheme();
52 @endcode
7c913512 53
fbec75d0
BP
54 @note On URIs with a "file" scheme wxURI does not parse the userinfo,
55 server, or port portion. This is to keep compatability with
56 wxFileSystem, the old wxURL, and older url specifications.
7c913512 57
23324ae1 58 @library{wxbase}
ea2a647d 59 @category{net}
7c913512 60
e54c96f1 61 @see wxURL
23324ae1
FM
62*/
63class wxURI : public wxObject
64{
65public:
23324ae1 66 /**
fbec75d0
BP
67 Creates an empty URI.
68 */
69 wxURI();
cfbe5614 70
fbec75d0
BP
71 /**
72 Constructor for quick creation.
3c4f71cc 73
7c913512 74 @param uri
fbec75d0 75 URI (Uniform Resource Identifier) to initialize with.
23324ae1 76 */
cfbe5614
FM
77 wxURI(const wxString& uri);
78
fbec75d0
BP
79 /**
80 Copies this URI from another URI.
81
82 @param uri
83 URI (Uniform Resource Identifier) to initialize with.
84 */
7c913512 85 wxURI(const wxURI& uri);
23324ae1
FM
86
87 /**
fbec75d0
BP
88 Builds the URI from its individual components and adds proper
89 separators.
90
91 If the URI is not a reference or is not resolved, the URI that is
92 returned is the same one passed to the constructor or Create().
23324ae1 93 */
328f5751 94 wxString BuildURI() const;
23324ae1
FM
95
96 /**
fbec75d0
BP
97 Builds the URI from its individual components, adds proper separators,
98 and returns escape sequences to normal characters.
99
100 @note It is preferred to call this over Unescape(BuildURI()) since
101 BuildUnescapedURI() performs some optimizations over the plain
102 method.
23324ae1 103 */
328f5751 104 wxString BuildUnescapedURI() const;
23324ae1
FM
105
106 /**
fbec75d0 107 Creates this URI from the @a uri string.
3c4f71cc 108
cfbe5614 109 Returns @true if this instance was correctly initialized.
3c4f71cc 110
fbec75d0
BP
111 @param uri
112 String to initialize from.
23324ae1 113 */
cfbe5614 114 bool Create(const wxString& uri);
23324ae1
FM
115
116 /**
fbec75d0 117 Obtains the fragment of this URI.
23324ae1 118
fbec75d0
BP
119 The fragment of a URI is the last value of the URI, and is the value
120 after a "#" character after the path of the URI.
23324ae1 121
fbec75d0 122 @c "http://mysite.com/mypath#<fragment>"
23324ae1 123 */
fbec75d0 124 const wxString& GetFragment() const;
23324ae1
FM
125
126 /**
fbec75d0 127 Obtains the host type of this URI, which is one of wxURIHostType.
23324ae1 128 */
cfbe5614 129 wxURIHostType GetHostType() const;
23324ae1
FM
130
131 /**
fbec75d0
BP
132 Returns the password part of the userinfo component of this URI. Note
133 that this is explicitly depreciated by RFC 1396 and should generally be
134 avoided if possible.
135
136 @c "http://<user>:<password>@mysite.com/mypath"
23324ae1 137 */
cfbe5614 138 wxString GetPassword() const;
23324ae1
FM
139
140 /**
141 Returns the (normalized) path of the URI.
fbec75d0
BP
142
143 The path component of a URI comes directly after the scheme component
144 if followed by zero or one slashes ('/'), or after the server/port
145 component.
146
147 Absolute paths include the leading '/' character.
148
149 @c "http://mysite.com<path>"
23324ae1 150 */
fbec75d0 151 const wxString& GetPath() const;
23324ae1
FM
152
153 /**
154 Returns a string representation of the URI's port.
fbec75d0
BP
155
156 The Port of a URI is a value after the server, and must come after a
157 colon (:).
158
159 @c "http://mysite.com:<port>"
160
161 @note You can easily get the numeric value of the port by using
162 wxAtoi() or wxString::Format().
23324ae1 163 */
fbec75d0 164 const wxString& GetPort() const;
23324ae1
FM
165
166 /**
167 Returns the Query component of the URI.
fbec75d0
BP
168
169 The query component is what is commonly passed to a cgi application,
170 and must come after the path component, and after a '?' character.
171
172 @c "http://mysite.com/mypath?<query>"
23324ae1 173 */
fbec75d0 174 const wxString& GetQuery() const;
23324ae1
FM
175
176 /**
177 Returns the Scheme component of the URI.
fbec75d0
BP
178
179 The first part of the URI.
180
181 @c "<scheme>://mysite.com"
23324ae1 182 */
fbec75d0 183 const wxString& GetScheme() const;
23324ae1
FM
184
185 /**
186 Returns the Server component of the URI.
fbec75d0
BP
187
188 The server of the URI can be a server name or a type of IP address. See
189 GetHostType() for the possible values for the host type of the server
190 component.
191
192 @c "http://<server>/mypath"
23324ae1 193 */
fbec75d0 194 const wxString& GetServer() const;
23324ae1
FM
195
196 /**
fbec75d0
BP
197 Returns the username part of the userinfo component of this URI. Note
198 that this is explicitly depreciated by RFC 1396 and should generally be
199 avoided if possible.
200
201 @c "http://<user>:<password>@mysite.com/mypath"
23324ae1 202 */
cfbe5614 203 wxString GetUser() const;
23324ae1
FM
204
205 /**
206 Returns the UserInfo component of the URI.
fbec75d0
BP
207
208 The component of a URI before the server component that is postfixed by
209 a '@' character.
210
211 @c "http://<userinfo>@mysite.com/mypath"
23324ae1 212 */
fbec75d0 213 const wxString& GetUserInfo() const;
23324ae1
FM
214
215 /**
216 Returns @true if the Fragment component of the URI exists.
217 */
328f5751 218 bool HasFragment() const;
23324ae1
FM
219
220 /**
221 Returns @true if the Path component of the URI exists.
222 */
328f5751 223 bool HasPath() const;
23324ae1
FM
224
225 /**
226 Returns @true if the Port component of the URI exists.
227 */
328f5751 228 bool HasPort() const;
23324ae1
FM
229
230 /**
231 Returns @true if the Query component of the URI exists.
232 */
328f5751 233 bool HasQuery() const;
23324ae1
FM
234
235 /**
236 Returns @true if the Scheme component of the URI exists.
237 */
328f5751 238 bool HasScheme() const;
23324ae1
FM
239
240 /**
241 Returns @true if the Server component of the URI exists.
242 */
328f5751 243 bool HasServer() const;
23324ae1
FM
244
245 /**
246 Returns @true if the User component of the URI exists.
247 */
328f5751 248 bool HasUser() const;
23324ae1
FM
249
250 /**
fbec75d0
BP
251 Returns @true if a valid [absolute] URI, otherwise this URI is a URI
252 reference and not a full URI, and this function returns @false.
23324ae1 253 */
328f5751 254 bool IsReference() const;
23324ae1
FM
255
256 /**
fbec75d0
BP
257 Inherits this URI from a base URI - components that do not exist in
258 this URI are copied from the base, and if this URI's path is not an
259 absolute path (prefixed by a '/'), then this URI's path is merged with
260 the base's path.
3c4f71cc 261
7c913512 262 For instance, resolving "../mydir" from "http://mysite.com/john/doe"
fbec75d0
BP
263 results in the scheme (http) and server ("mysite.com") being copied
264 into this URI, since they do not exist. In addition, since the path of
265 this URI is not absolute (does not begin with '/'), the path of the
266 base's is merged with this URI's path, resulting in the URI
23324ae1 267 "http://mysite.com/john/mydir".
3c4f71cc 268
7c913512 269 @param base
fbec75d0 270 Base URI to inherit from. Must be a full URI and not a reference.
7c913512 271 @param flags
fbec75d0
BP
272 Currently either wxURI_STRICT or 0, in non-strict mode some
273 compatibility layers are enabled to allow loopholes from RFCs prior
274 to 2396.
23324ae1
FM
275 */
276 void Resolve(const wxURI& base, int flags = wxURI_STRICT);
277
278 /**
fbec75d0
BP
279 Translates all escape sequences (normal characters and returns the
280 result.
281
282 If you want to unescape an entire wxURI, use BuildUnescapedURI()
283 instead, as it performs some optimizations over this method.
3c4f71cc 284
7c913512 285 @param uri
fbec75d0 286 String with escaped characters to convert.
23324ae1 287 */
adaaa686 288 static wxString Unescape(const wxString& uri);
23324ae1
FM
289
290 /**
fbec75d0
BP
291 Compares this URI to another URI, and returns @true if this URI equals
292 @a uricomp, otherwise it returns @false.
3c4f71cc 293
fbec75d0
BP
294 @param uricomp
295 URI to compare to.
23324ae1 296 */
cfbe5614 297 bool operator==(const wxURI& uricomp) const;
23324ae1 298};
e54c96f1 299