xbmc
Public Member Functions | Protected Attributes | List of all members
NPT_Url Class Reference
Inheritance diagram for NPT_Url:
Inheritance graph
[legend]
Collaboration diagram for NPT_Url:
Collaboration graph
[legend]

Public Member Functions

 NPT_Url ()
 Default constructor. More...
 
 NPT_Url (const char *url, NPT_UInt16 default_port=0)
 Construct a URL by parsing an input string in its fully encoded form. More...
 
 NPT_Url (const char *scheme, const char *host, NPT_UInt16 port, const char *path, const char *query=NULL, const char *fragment=NULL)
 Construct a URL from its components. More...
 
NPT_Result Parse (const char *url, NPT_UInt16 default_port=0)
 Parse a URL from its fully encoded form. More...
 
NPT_Result ParsePathPlus (const char *path_plus)
 Parse just the path plus optional query and fragment from a fully encoded form. More...
 
const NPT_StringGetHost () const
 Returns the host part of the URL, in its encoded form.
 
NPT_UInt16 GetPort () const
 Returns the port number of the URL.
 
const NPT_StringGetPath () const
 Returns the path part of the URL, in its encoded form.
 
NPT_String GetPath (bool decoded) const
 Returns the path part of the URL, in its encoded or decoded form.
 
const NPT_StringGetQuery () const
 Returns the query part of the URL, in its encoded form.
 
const NPT_StringGetFragment () const
 Returns the fragment part of the URL, in its encoded form.
 
virtual bool IsValid () const
 Returns whether the URL is valid or not. More...
 
void Reset ()
 Resets a URL to an uninitialized state.
 
bool HasQuery () const
 Returns whether the URL has a query part or not. More...
 
bool HasFragment () const
 Returns whether the URL has a fragment part or not. More...
 
NPT_Result SetHost (const char *host)
 Sets the host part of the URL. More...
 
NPT_Result SetPort (NPT_UInt16 port)
 Sets the port number of the URL. More...
 
NPT_Result SetPath (const char *path, bool encoded=false)
 Sets the path part of the URL. More...
 
NPT_Result SetQuery (const char *query, bool encoded=false)
 Sets the query part of the URL. More...
 
NPT_Result SetFragment (const char *fragment, bool encoded=false)
 Sets the fragment part of the URL. More...
 
virtual NPT_String ToRequestString (bool with_fragment=false) const
 Return the string representation of the URL in a way that can be used in an HTTP request (i.e just the portion of the URL starting with the path) More...
 
virtual NPT_String ToStringWithDefaultPort (NPT_UInt16 default_port, bool with_fragment=true) const
 Return the string representation of the URL. More...
 
virtual NPT_String ToString (bool with_fragment=true) const
 Return the string representation of the URL. More...
 
- Public Member Functions inherited from NPT_Uri
const NPT_StringGetScheme () const
 
void SetScheme (const char *scheme)
 
NPT_Result SetSchemeFromUri (const char *uri)
 
SchemeId GetSchemeId () const
 

Protected Attributes

NPT_String m_Host
 
bool m_HostIsIpv6Address
 
NPT_UInt16 m_Port
 
NPT_String m_Path
 
bool m_HasQuery
 
NPT_String m_Query
 
bool m_HasFragment
 
NPT_String m_Fragment
 
- Protected Attributes inherited from NPT_Uri
NPT_String m_Scheme
 
SchemeId m_SchemeId
 

Additional Inherited Members

- Public Types inherited from NPT_Uri
enum  SchemeId { SCHEME_ID_UNKNOWN, SCHEME_ID_HTTP, SCHEME_ID_HTTPS }
 
- Static Public Member Functions inherited from NPT_Uri
static NPT_String PercentEncode (const char *str, const char *chars, bool encode_percents=true)
 
static NPT_String PercentDecode (const char *str)
 
static SchemeId ParseScheme (const NPT_String &scheme)
 
- Static Public Attributes inherited from NPT_Uri
static const char *const PathCharsToEncode = NPT_URI_ALWAYS_ENCODE "?#[]"
 
static const char *const QueryCharsToEncode = NPT_URI_ALWAYS_ENCODE "#[]"
 
static const char *const FragmentCharsToEncode = NPT_URI_ALWAYS_ENCODE "[]"
 
static const char *const UnsafeCharsToEncode = NPT_URI_ALWAYS_ENCODE
 

Constructor & Destructor Documentation

◆ NPT_Url() [1/3]

NPT_Url::NPT_Url ( )

Default constructor.

This does not construct a valid URL, but an uninitialized one that can later be initialized to a valid URL by parsing or setting some of its fields.

◆ NPT_Url() [2/3]

NPT_Url::NPT_Url ( const char *  url,
NPT_UInt16  default_port = 0 
)

Construct a URL by parsing an input string in its fully encoded form.

If an error occurs during parsing (such as an invalid syntax), the URL will be in an invalid state (a call to IsValid() will return false).

Parameters
urlThe URL string in its encoded form
default_portThe default port number, or 0 if not specified

◆ NPT_Url() [3/3]

NPT_Url::NPT_Url ( const char *  scheme,
const char *  host,
NPT_UInt16  port,
const char *  path,
const char *  query = NULL,
const char *  fragment = NULL 
)

Construct a URL from its components.

When constructing a URL from components, the components are assumed to be passed in their non-encoded form, and will thus be encoded automatically.

Parameters
schemeThe URL scheme
hostThe host name (enclose with [ and ] for IPv6 addresses)
portThe port number
pathThe path
queryThe query, if any, or NULL
fragmentThe fragment, if any, or NULL

Member Function Documentation

◆ HasFragment()

bool NPT_Url::HasFragment ( ) const
inline

Returns whether the URL has a fragment part or not.

Returns
true if the URL has a fragment part, false if it does not.

◆ HasQuery()

bool NPT_Url::HasQuery ( ) const
inline

Returns whether the URL has a query part or not.

Returns
true if the URL has a query part, false if it does not.

◆ IsValid()

bool NPT_Url::IsValid ( ) const
virtual

Returns whether the URL is valid or not.

Invalid URLs are uninitialized or not fully initialized URLs.

Returns
true if the URL is valid, false if it is not.

◆ Parse()

NPT_Result NPT_Url::Parse ( const char *  url,
NPT_UInt16  default_port = 0 
)

Parse a URL from its fully encoded form.

Parameters
urlThe URL string in its encoded form
defaultport The defautl port number, or 0 if not specified

◆ ParsePathPlus()

NPT_Result NPT_Url::ParsePathPlus ( const char *  path_plus)

Parse just the path plus optional query and fragment from a fully encoded form.

Parameters
path_plusThe URL path plus optional query and fragment

◆ SetFragment()

NPT_Result NPT_Url::SetFragment ( const char *  fragment,
bool  encoded = false 
)

Sets the fragment part of the URL.

Parameters
queryThe fragment part of the URL
encodedBoolean flag indicating whether the fragment parameter is already encoded or not. If it is not already encoded, it will be automatically encoded.

◆ SetHost()

NPT_Result NPT_Url::SetHost ( const char *  host)

Sets the host part of the URL.

Parameters
hostThe host part of the URL (enclose with [ and ] for IPv6 addresses)

◆ SetPath()

NPT_Result NPT_Url::SetPath ( const char *  path,
bool  encoded = false 
)

Sets the path part of the URL.

Parameters
pathThe path part of the URL
encodedBoolean flag indicating whether the path parameter is already encoded or not. If it is not already encoded, it will be automatically encoded.

◆ SetPort()

NPT_Result NPT_Url::SetPort ( NPT_UInt16  port)

Sets the port number of the URL.

Parameters
portThe port number of the URL

◆ SetQuery()

NPT_Result NPT_Url::SetQuery ( const char *  query,
bool  encoded = false 
)

Sets the query part of the URL.

Parameters
queryThe query part of the URL
encodedBoolean flag indicating whether the query parameter is already encoded or not. If it is not already encoded, it will be automatically encoded.

◆ ToRequestString()

NPT_String NPT_Url::ToRequestString ( bool  with_fragment = false) const
virtual

Return the string representation of the URL in a way that can be used in an HTTP request (i.e just the portion of the URL starting with the path)

Parameters
with_fragmentBoolean flag specifiying whether the fragment part of the URL should be included in the returned string or not.

◆ ToString()

NPT_String NPT_Url::ToString ( bool  with_fragment = true) const
virtual

Return the string representation of the URL.

Parameters
with_fragmentBoolean flag specifiying whether the fragment part of the URL should be included in the returned string or not.

Reimplemented in NPT_HttpUrl.

◆ ToStringWithDefaultPort()

NPT_String NPT_Url::ToStringWithDefaultPort ( NPT_UInt16  default_port,
bool  with_fragment = true 
) const
virtual

Return the string representation of the URL.

Parameters
default_portdefault port number for the scheme. If the port number of the URL is not equal to the default port, then port number is explicitely included in the string representation of the URL.
with_fragmentBoolean flag specifiying whether the fragment part of the URL should be included in the returned string or not.

The documentation for this class was generated from the following files: