2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: uri.h
|
2008-03-10 15:24:38 +00:00
|
|
|
// Purpose: interface of wxURI
|
2008-03-08 13:52:38 +00:00
|
|
|
// Author: wxWidgets team
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-04-22 06:01:48 +00:00
|
|
|
/**
|
|
|
|
Host type of URI returned from wxURI::GetHostType().
|
|
|
|
*/
|
|
|
|
enum wxURIHostType
|
|
|
|
{
|
|
|
|
wxURI_REGNAME, ///< Host is a normal register name (@c "www.mysite.com").
|
|
|
|
wxURI_IPV4ADDRESS, ///< Host is a version 4 ip address (@c "192.168.1.100").
|
|
|
|
wxURI_IPV6ADDRESS, ///< Host is a version 6 ip address (@c "[aa:aa:aa:aa::aa:aa]:5050").
|
|
|
|
wxURI_IPVFUTURE ///< Host is a future ip address, wxURI is unsure what kind.
|
|
|
|
};
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxURI
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2009-04-21 11:21:36 +00:00
|
|
|
wxURI is used to extract information from a URI (Uniform Resource Identifier).
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2009-04-21 11:21:36 +00:00
|
|
|
For information about URIs, see RFC 3986 (http://www.ietf.org/rfc/rfc3986.txt).
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-04-22 06:01:48 +00:00
|
|
|
In short, a URL is a URI. In other words, URL is a subset of a URI - all
|
2008-03-08 13:52:38 +00:00
|
|
|
acceptable URLs are also acceptable URIs.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-04-22 06:01:48 +00:00
|
|
|
wxURI automatically escapes invalid characters in a string, so there is no
|
|
|
|
chance of wxURI "failing" on construction/creation.
|
|
|
|
|
|
|
|
wxURI supports copy construction and standard assignment operators. wxURI
|
2011-04-03 20:52:18 +00:00
|
|
|
can also be inherited from to provide further functionality.
|
2008-04-22 06:01:48 +00:00
|
|
|
|
|
|
|
To obtain individual components you can use one of the GetXXX() methods.
|
|
|
|
However, you should check HasXXX() before calling a get method, which
|
|
|
|
determines whether or not the component referred to by the method is
|
|
|
|
defined according to RFC 2396. Consider an undefined component equivalent
|
|
|
|
to a @NULL C string.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
@code
|
2009-04-21 11:21:36 +00:00
|
|
|
// protocol will hold the http protocol (i.e. "http")
|
|
|
|
wxString protocol;
|
|
|
|
wxURI myuri("http://mysite.com");
|
|
|
|
if( myuri.HasScheme() )
|
|
|
|
protocol = myuri.GetScheme();
|
2008-04-22 06:01:48 +00:00
|
|
|
@endcode
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-04-22 06:01:48 +00:00
|
|
|
@note On URIs with a "file" scheme wxURI does not parse the userinfo,
|
2012-02-22 13:41:07 +00:00
|
|
|
server, or port portion. This is to keep compatibility with
|
2008-04-22 06:01:48 +00:00
|
|
|
wxFileSystem, the old wxURL, and older url specifications.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
2008-12-01 17:44:27 +00:00
|
|
|
@category{net}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxURL
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxURI : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-04-22 06:01:48 +00:00
|
|
|
Creates an empty URI.
|
|
|
|
*/
|
|
|
|
wxURI();
|
2008-10-28 14:29:36 +00:00
|
|
|
|
2008-04-22 06:01:48 +00:00
|
|
|
/**
|
|
|
|
Constructor for quick creation.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param uri
|
2008-04-22 06:01:48 +00:00
|
|
|
URI (Uniform Resource Identifier) to initialize with.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-28 14:29:36 +00:00
|
|
|
wxURI(const wxString& uri);
|
|
|
|
|
2008-04-22 06:01:48 +00:00
|
|
|
/**
|
|
|
|
Copies this URI from another URI.
|
|
|
|
|
|
|
|
@param uri
|
|
|
|
URI (Uniform Resource Identifier) to initialize with.
|
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
wxURI(const wxURI& uri);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-22 06:01:48 +00:00
|
|
|
Builds the URI from its individual components and adds proper
|
|
|
|
separators.
|
|
|
|
|
|
|
|
If the URI is not a reference or is not resolved, the URI that is
|
|
|
|
returned is the same one passed to the constructor or Create().
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxString BuildURI() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-22 06:01:48 +00:00
|
|
|
Builds the URI from its individual components, adds proper separators,
|
|
|
|
and returns escape sequences to normal characters.
|
|
|
|
|
|
|
|
@note It is preferred to call this over Unescape(BuildURI()) since
|
|
|
|
BuildUnescapedURI() performs some optimizations over the plain
|
|
|
|
method.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxString BuildUnescapedURI() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-22 06:01:48 +00:00
|
|
|
Creates this URI from the @a uri string.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-10-28 14:29:36 +00:00
|
|
|
Returns @true if this instance was correctly initialized.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-04-22 06:01:48 +00:00
|
|
|
@param uri
|
|
|
|
String to initialize from.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-28 14:29:36 +00:00
|
|
|
bool Create(const wxString& uri);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-22 06:01:48 +00:00
|
|
|
Obtains the fragment of this URI.
|
2008-03-08 13:52:38 +00:00
|
|
|
|
2008-04-22 06:01:48 +00:00
|
|
|
The fragment of a URI is the last value of the URI, and is the value
|
|
|
|
after a "#" character after the path of the URI.
|
2008-03-08 13:52:38 +00:00
|
|
|
|
2008-04-22 06:01:48 +00:00
|
|
|
@c "http://mysite.com/mypath#<fragment>"
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-04-22 06:01:48 +00:00
|
|
|
const wxString& GetFragment() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-22 06:01:48 +00:00
|
|
|
Obtains the host type of this URI, which is one of wxURIHostType.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-28 14:29:36 +00:00
|
|
|
wxURIHostType GetHostType() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-22 06:01:48 +00:00
|
|
|
Returns the password part of the userinfo component of this URI. Note
|
|
|
|
that this is explicitly depreciated by RFC 1396 and should generally be
|
|
|
|
avoided if possible.
|
|
|
|
|
|
|
|
@c "http://<user>:<password>@mysite.com/mypath"
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-28 14:29:36 +00:00
|
|
|
wxString GetPassword() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the (normalized) path of the URI.
|
2008-04-22 06:01:48 +00:00
|
|
|
|
|
|
|
The path component of a URI comes directly after the scheme component
|
|
|
|
if followed by zero or one slashes ('/'), or after the server/port
|
|
|
|
component.
|
|
|
|
|
|
|
|
Absolute paths include the leading '/' character.
|
|
|
|
|
|
|
|
@c "http://mysite.com<path>"
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-04-22 06:01:48 +00:00
|
|
|
const wxString& GetPath() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a string representation of the URI's port.
|
2008-04-22 06:01:48 +00:00
|
|
|
|
|
|
|
The Port of a URI is a value after the server, and must come after a
|
|
|
|
colon (:).
|
|
|
|
|
|
|
|
@c "http://mysite.com:<port>"
|
|
|
|
|
|
|
|
@note You can easily get the numeric value of the port by using
|
|
|
|
wxAtoi() or wxString::Format().
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-04-22 06:01:48 +00:00
|
|
|
const wxString& GetPort() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the Query component of the URI.
|
2008-04-22 06:01:48 +00:00
|
|
|
|
|
|
|
The query component is what is commonly passed to a cgi application,
|
|
|
|
and must come after the path component, and after a '?' character.
|
|
|
|
|
|
|
|
@c "http://mysite.com/mypath?<query>"
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-04-22 06:01:48 +00:00
|
|
|
const wxString& GetQuery() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the Scheme component of the URI.
|
2008-04-22 06:01:48 +00:00
|
|
|
|
|
|
|
The first part of the URI.
|
|
|
|
|
|
|
|
@c "<scheme>://mysite.com"
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-04-22 06:01:48 +00:00
|
|
|
const wxString& GetScheme() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the Server component of the URI.
|
2008-04-22 06:01:48 +00:00
|
|
|
|
|
|
|
The server of the URI can be a server name or a type of IP address. See
|
|
|
|
GetHostType() for the possible values for the host type of the server
|
|
|
|
component.
|
|
|
|
|
|
|
|
@c "http://<server>/mypath"
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-04-22 06:01:48 +00:00
|
|
|
const wxString& GetServer() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-22 06:01:48 +00:00
|
|
|
Returns the username part of the userinfo component of this URI. Note
|
|
|
|
that this is explicitly depreciated by RFC 1396 and should generally be
|
|
|
|
avoided if possible.
|
|
|
|
|
|
|
|
@c "http://<user>:<password>@mysite.com/mypath"
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-28 14:29:36 +00:00
|
|
|
wxString GetUser() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the UserInfo component of the URI.
|
2008-04-22 06:01:48 +00:00
|
|
|
|
|
|
|
The component of a URI before the server component that is postfixed by
|
|
|
|
a '@' character.
|
|
|
|
|
|
|
|
@c "http://<userinfo>@mysite.com/mypath"
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-04-22 06:01:48 +00:00
|
|
|
const wxString& GetUserInfo() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the Fragment component of the URI exists.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool HasFragment() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the Path component of the URI exists.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool HasPath() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the Port component of the URI exists.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool HasPort() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the Query component of the URI exists.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool HasQuery() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the Scheme component of the URI exists.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool HasScheme() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the Server component of the URI exists.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool HasServer() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the User component of the URI exists.
|
|
|
|
*/
|
2012-04-02 16:07:38 +00:00
|
|
|
bool HasUserInfo() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-22 06:01:48 +00:00
|
|
|
Returns @true if a valid [absolute] URI, otherwise this URI is a URI
|
|
|
|
reference and not a full URI, and this function returns @false.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool IsReference() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-22 06:01:48 +00:00
|
|
|
Inherits this URI from a base URI - components that do not exist in
|
|
|
|
this URI are copied from the base, and if this URI's path is not an
|
|
|
|
absolute path (prefixed by a '/'), then this URI's path is merged with
|
|
|
|
the base's path.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
For instance, resolving "../mydir" from "http://mysite.com/john/doe"
|
2008-04-22 06:01:48 +00:00
|
|
|
results in the scheme (http) and server ("mysite.com") being copied
|
|
|
|
into this URI, since they do not exist. In addition, since the path of
|
|
|
|
this URI is not absolute (does not begin with '/'), the path of the
|
|
|
|
base's is merged with this URI's path, resulting in the URI
|
2008-03-08 13:52:38 +00:00
|
|
|
"http://mysite.com/john/mydir".
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param base
|
2008-04-22 06:01:48 +00:00
|
|
|
Base URI to inherit from. Must be a full URI and not a reference.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param flags
|
2008-04-22 06:01:48 +00:00
|
|
|
Currently either wxURI_STRICT or 0, in non-strict mode some
|
|
|
|
compatibility layers are enabled to allow loopholes from RFCs prior
|
|
|
|
to 2396.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void Resolve(const wxURI& base, int flags = wxURI_STRICT);
|
|
|
|
|
|
|
|
/**
|
2009-04-21 11:21:36 +00:00
|
|
|
Translates all escape sequences (normal characters and returns the result.
|
2008-04-22 06:01:48 +00:00
|
|
|
|
|
|
|
If you want to unescape an entire wxURI, use BuildUnescapedURI()
|
|
|
|
instead, as it performs some optimizations over this method.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param uri
|
2008-04-22 06:01:48 +00:00
|
|
|
String with escaped characters to convert.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
static wxString Unescape(const wxString& uri);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-22 06:01:48 +00:00
|
|
|
Compares this URI to another URI, and returns @true if this URI equals
|
|
|
|
@a uricomp, otherwise it returns @false.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-04-22 06:01:48 +00:00
|
|
|
@param uricomp
|
|
|
|
URI to compare to.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-28 14:29:36 +00:00
|
|
|
bool operator==(const wxURI& uricomp) const;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
2008-03-10 15:24:38 +00:00
|
|
|
|