]>
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 | ||
fbec75d0 BP |
9 | /** |
10 | Host type of URI returned from wxURI::GetHostType(). | |
11 | */ | |
12 | enum 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 FM |
58 | @library{wxbase} |
59 | @category{data} | |
7c913512 | 60 | |
e54c96f1 | 61 | @see wxURL |
23324ae1 FM |
62 | */ |
63 | class wxURI : public wxObject | |
64 | { | |
65 | public: | |
23324ae1 | 66 | /** |
fbec75d0 BP |
67 | Creates an empty URI. |
68 | */ | |
69 | wxURI(); | |
70 | /** | |
71 | Constructor for quick creation. | |
3c4f71cc | 72 | |
7c913512 | 73 | @param uri |
fbec75d0 | 74 | URI (Uniform Resource Identifier) to initialize with. |
23324ae1 | 75 | */ |
7c913512 | 76 | wxURI(const wxChar* uri); |
fbec75d0 BP |
77 | /** |
78 | Copies this URI from another URI. | |
79 | ||
80 | @param uri | |
81 | URI (Uniform Resource Identifier) to initialize with. | |
82 | */ | |
7c913512 | 83 | wxURI(const wxURI& uri); |
23324ae1 FM |
84 | |
85 | /** | |
fbec75d0 BP |
86 | Builds the URI from its individual components and adds proper |
87 | separators. | |
88 | ||
89 | If the URI is not a reference or is not resolved, the URI that is | |
90 | returned is the same one passed to the constructor or Create(). | |
23324ae1 | 91 | */ |
328f5751 | 92 | wxString BuildURI() const; |
23324ae1 FM |
93 | |
94 | /** | |
fbec75d0 BP |
95 | Builds the URI from its individual components, adds proper separators, |
96 | and returns escape sequences to normal characters. | |
97 | ||
98 | @note It is preferred to call this over Unescape(BuildURI()) since | |
99 | BuildUnescapedURI() performs some optimizations over the plain | |
100 | method. | |
23324ae1 | 101 | */ |
328f5751 | 102 | wxString BuildUnescapedURI() const; |
23324ae1 FM |
103 | |
104 | /** | |
fbec75d0 | 105 | Creates this URI from the @a uri string. |
3c4f71cc | 106 | |
fbec75d0 BP |
107 | Returns the position at which parsing stopped (there is no such thing |
108 | as an "invalid" wxURI). | |
3c4f71cc | 109 | |
fbec75d0 BP |
110 | @param uri |
111 | String to initialize from. | |
23324ae1 FM |
112 | */ |
113 | const wxChar* Create(const wxString uri); | |
114 | ||
115 | /** | |
fbec75d0 | 116 | Obtains the fragment of this URI. |
23324ae1 | 117 | |
fbec75d0 BP |
118 | The fragment of a URI is the last value of the URI, and is the value |
119 | after a "#" character after the path of the URI. | |
23324ae1 | 120 | |
fbec75d0 | 121 | @c "http://mysite.com/mypath#<fragment>" |
23324ae1 | 122 | */ |
fbec75d0 | 123 | const wxString& GetFragment() const; |
23324ae1 FM |
124 | |
125 | /** | |
fbec75d0 | 126 | Obtains the host type of this URI, which is one of wxURIHostType. |
23324ae1 | 127 | */ |
fbec75d0 | 128 | const wxURIHostType& GetHostType() const; |
23324ae1 FM |
129 | |
130 | /** | |
fbec75d0 BP |
131 | Returns the password part of the userinfo component of this URI. Note |
132 | that this is explicitly depreciated by RFC 1396 and should generally be | |
133 | avoided if possible. | |
134 | ||
135 | @c "http://<user>:<password>@mysite.com/mypath" | |
23324ae1 | 136 | */ |
fbec75d0 | 137 | const wxString& GetPassword() const; |
23324ae1 FM |
138 | |
139 | /** | |
140 | Returns the (normalized) path of the URI. | |
fbec75d0 BP |
141 | |
142 | The path component of a URI comes directly after the scheme component | |
143 | if followed by zero or one slashes ('/'), or after the server/port | |
144 | component. | |
145 | ||
146 | Absolute paths include the leading '/' character. | |
147 | ||
148 | @c "http://mysite.com<path>" | |
23324ae1 | 149 | */ |
fbec75d0 | 150 | const wxString& GetPath() const; |
23324ae1 FM |
151 | |
152 | /** | |
153 | Returns a string representation of the URI's port. | |
fbec75d0 BP |
154 | |
155 | The Port of a URI is a value after the server, and must come after a | |
156 | colon (:). | |
157 | ||
158 | @c "http://mysite.com:<port>" | |
159 | ||
160 | @note You can easily get the numeric value of the port by using | |
161 | wxAtoi() or wxString::Format(). | |
23324ae1 | 162 | */ |
fbec75d0 | 163 | const wxString& GetPort() const; |
23324ae1 FM |
164 | |
165 | /** | |
166 | Returns the Query component of the URI. | |
fbec75d0 BP |
167 | |
168 | The query component is what is commonly passed to a cgi application, | |
169 | and must come after the path component, and after a '?' character. | |
170 | ||
171 | @c "http://mysite.com/mypath?<query>" | |
23324ae1 | 172 | */ |
fbec75d0 | 173 | const wxString& GetQuery() const; |
23324ae1 FM |
174 | |
175 | /** | |
176 | Returns the Scheme component of the URI. | |
fbec75d0 BP |
177 | |
178 | The first part of the URI. | |
179 | ||
180 | @c "<scheme>://mysite.com" | |
23324ae1 | 181 | */ |
fbec75d0 | 182 | const wxString& GetScheme() const; |
23324ae1 FM |
183 | |
184 | /** | |
185 | Returns the Server component of the URI. | |
fbec75d0 BP |
186 | |
187 | The server of the URI can be a server name or a type of IP address. See | |
188 | GetHostType() for the possible values for the host type of the server | |
189 | component. | |
190 | ||
191 | @c "http://<server>/mypath" | |
23324ae1 | 192 | */ |
fbec75d0 | 193 | const wxString& GetServer() const; |
23324ae1 FM |
194 | |
195 | /** | |
fbec75d0 BP |
196 | Returns the username part of the userinfo component of this URI. Note |
197 | that this is explicitly depreciated by RFC 1396 and should generally be | |
198 | avoided if possible. | |
199 | ||
200 | @c "http://<user>:<password>@mysite.com/mypath" | |
23324ae1 | 201 | */ |
fbec75d0 | 202 | const wxString& GetUser() const; |
23324ae1 FM |
203 | |
204 | /** | |
205 | Returns the UserInfo component of the URI. | |
fbec75d0 BP |
206 | |
207 | The component of a URI before the server component that is postfixed by | |
208 | a '@' character. | |
209 | ||
210 | @c "http://<userinfo>@mysite.com/mypath" | |
23324ae1 | 211 | */ |
fbec75d0 | 212 | const wxString& GetUserInfo() const; |
23324ae1 FM |
213 | |
214 | /** | |
215 | Returns @true if the Fragment component of the URI exists. | |
216 | */ | |
328f5751 | 217 | bool HasFragment() const; |
23324ae1 FM |
218 | |
219 | /** | |
220 | Returns @true if the Path component of the URI exists. | |
221 | */ | |
328f5751 | 222 | bool HasPath() const; |
23324ae1 FM |
223 | |
224 | /** | |
225 | Returns @true if the Port component of the URI exists. | |
226 | */ | |
328f5751 | 227 | bool HasPort() const; |
23324ae1 FM |
228 | |
229 | /** | |
230 | Returns @true if the Query component of the URI exists. | |
231 | */ | |
328f5751 | 232 | bool HasQuery() const; |
23324ae1 FM |
233 | |
234 | /** | |
235 | Returns @true if the Scheme component of the URI exists. | |
236 | */ | |
328f5751 | 237 | bool HasScheme() const; |
23324ae1 FM |
238 | |
239 | /** | |
240 | Returns @true if the Server component of the URI exists. | |
241 | */ | |
328f5751 | 242 | bool HasServer() const; |
23324ae1 FM |
243 | |
244 | /** | |
245 | Returns @true if the User component of the URI exists. | |
246 | */ | |
328f5751 | 247 | bool HasUser() const; |
23324ae1 FM |
248 | |
249 | /** | |
fbec75d0 BP |
250 | Returns @true if a valid [absolute] URI, otherwise this URI is a URI |
251 | reference and not a full URI, and this function returns @false. | |
23324ae1 | 252 | */ |
328f5751 | 253 | bool IsReference() const; |
23324ae1 FM |
254 | |
255 | /** | |
fbec75d0 BP |
256 | Inherits this URI from a base URI - components that do not exist in |
257 | this URI are copied from the base, and if this URI's path is not an | |
258 | absolute path (prefixed by a '/'), then this URI's path is merged with | |
259 | the base's path. | |
3c4f71cc | 260 | |
7c913512 | 261 | For instance, resolving "../mydir" from "http://mysite.com/john/doe" |
fbec75d0 BP |
262 | results in the scheme (http) and server ("mysite.com") being copied |
263 | into this URI, since they do not exist. In addition, since the path of | |
264 | this URI is not absolute (does not begin with '/'), the path of the | |
265 | base's is merged with this URI's path, resulting in the URI | |
23324ae1 | 266 | "http://mysite.com/john/mydir". |
3c4f71cc | 267 | |
7c913512 | 268 | @param base |
fbec75d0 | 269 | Base URI to inherit from. Must be a full URI and not a reference. |
7c913512 | 270 | @param flags |
fbec75d0 BP |
271 | Currently either wxURI_STRICT or 0, in non-strict mode some |
272 | compatibility layers are enabled to allow loopholes from RFCs prior | |
273 | to 2396. | |
23324ae1 FM |
274 | */ |
275 | void Resolve(const wxURI& base, int flags = wxURI_STRICT); | |
276 | ||
277 | /** | |
fbec75d0 BP |
278 | Translates all escape sequences (normal characters and returns the |
279 | result. | |
280 | ||
281 | If you want to unescape an entire wxURI, use BuildUnescapedURI() | |
282 | instead, as it performs some optimizations over this method. | |
3c4f71cc | 283 | |
7c913512 | 284 | @param uri |
fbec75d0 | 285 | String with escaped characters to convert. |
23324ae1 FM |
286 | */ |
287 | wxString Unescape(const wxString& uri); | |
288 | ||
289 | /** | |
fbec75d0 BP |
290 | Compares this URI to another URI, and returns @true if this URI equals |
291 | @a uricomp, otherwise it returns @false. | |
3c4f71cc | 292 | |
fbec75d0 BP |
293 | @param uricomp |
294 | URI to compare to. | |
23324ae1 FM |
295 | */ |
296 | void operator ==(const wxURI& uricomp); | |
297 | }; | |
e54c96f1 | 298 |