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