PUri Class Reference

Detailed Description

The PUri class represents an Unified Resource Identifier (URI), this class can also be used to handle URL; NOT thread-safe.

A Uniform Resource Identifier (URI) is a string of characters used to identify a resource. With this class, you can also handle URLs which are a special kind of URI.

Syntax of an URI is:

scheme://username:password\@domain:port/path?query_string#fragment

Examples of URI:

- http://user:password\@host:port/path/page.html?key1=value1&key2=value2#fragment
- file:video.mp4
- tvi://user:password\@host?encodername=myEncoder
- rtsp://example.com/media.mp4

Definition at line 43 of file PUri.h.

#include <PUri.h>

Constructor & Destructor Documentation

◆ PUri() [1/3]

PUri::PUri ( const char *  uri = "")
explicit

Constructs an URI from the specified string (empty by default).

See also
IsValid()

◆ PUri() [2/3]

PUri::PUri ( const PString uri)
explicit

Constructs an URI from the specified PString.

See also
IsValid()

◆ PUri() [3/3]

PUri::PUri ( const PUri other)

Constructs a shared copy of other.

◆ ~PUri()

virtual PUri::~PUri ( )
virtual

Destroys this object.

Member Function Documentation

◆ CheckScheme()

PResult PUri::CheckScheme ( const PStringList validSchemeList) const

Returns PResult::C_OK if this URI has a scheme is in the specified list, another result otherwise.

Comparison is case insensitive.

WARNING: in SDK <= 4.5, this function was also tested for URL validity; it's no more the case.

◆ Decode()

PResult PUri::Decode ( )

Returns the percent-decoded version of the internal URI.

See also
Encode()
IsEncoded()

◆ Encode()

PResult PUri::Encode ( )

Returns the percent-encoded version of the internal URI, excluding the characters ":/@".

Example: A URI "http://user:*+,-.:;<=>@host.com/" will be percent-encoded as "http://user:%2A%2B%2C-.:%3B%3C%3D%3E@host.com/".

See also
Decode()
IsEncoded()

◆ GetAuthority()

PString PUri::GetAuthority ( ) const

Returns the authority of this URI or an empty string if it is undefined.

Example: http://user:password@host:port/path/page.html?key1=value1&key2=value2#fragment Authority is "user:password\@host:port"

◆ GetFragment()

PString PUri::GetFragment ( ) const

Returns the first query string value whose key is equal to the specified key from this URI or an empty string if it is undefined.

Example: http://user:password@host:port/path/page.html?key1=value1&key2=value2::fragment GetFragment() is "fragment".

◆ GetHost()

PString PUri::GetHost ( ) const

Returns the host part of this URI or an empty string if it is undefined.

Example: http://user:password@host:port/path/page.html?key1=value1&key2=value2::fragment Host is "host".

◆ GetPassword()

PString PUri::GetPassword ( ) const

Returns the fully decoded password of this URI or an empty string if it is undefined.

Percent-encoded sequences are decoded.

Example: http://user:password@host:port/path/page.html?key1=value1&key2=value2::fragment Password is "password".

◆ GetPath()

PString PUri::GetPath ( ) const

Returns the fully decoded path of this URI or an empty string if it is undefined.

Percent-encoded sequences are decoded.

Examples:

◆ GetPort()

int32 PUri::GetPort ( ) const

Returns the port of this URI or -1 if it is undefined.

Example: http://user:password@host:port/path/page.html?key1=value1&key2=value2::fragment Port is "port".

◆ GetQueryString()

PString PUri::GetQueryString ( ) const

Returns the first query string value whose key is equal to the specified key from this URI or an empty string if it is undefined.

Example: http://user:password@host:port/path/page.html?key1=value1&key2=value2::fragment GetQueryString() is "key1=value1&key2=value2".

◆ GetQueryValue() [1/3]

bool PUri::GetQueryValue ( const PString key,
PString value 
) const

Searches for the specified key in the query string.

Returns true and set value to the value of the specified key in case of success, false otherwise. In case of failure, value is set to an empty string.

Example: http://user:password@host:port/path/page.html?key1=value1&key2=value2::fragment GetQueryValue("key2",s) => s = "value2".

◆ GetQueryValue() [2/3]

bool PUri::GetQueryValue ( const PString key,
papillon::int32 &  value 
) const

Searches for the specified key in the query string.

Returns true and set value to the value of the specified key in case of success, false otherwise. If there is a key with the specified name, but the key is not an integer, then return false. In case of failure, value is set to -1.

Example: http://user:password@host:port/path/page.html?key1=value1&key2=2#fragment GetQueryValue("key2", i) => i = 2.

◆ GetQueryValue() [3/3]

bool PUri::GetQueryValue ( const PString key,
double &  value 
) const

Searches for the specified key in the query string.

Returns true and set value to the value of the specified key in case of success, false otherwise. If there is a key with the specified name, but the key is not a floating point number, \ then return false. In case of failure, value is set to NaN.

Example: http://user:password@host:port/path/page.html?key1=value1&key2=2.3#fragment GetQueryValue("key2", x) => x = 2.3.

◆ GetScheme()

PString PUri::GetScheme ( ) const

Returns the scheme part of this URI (in lowercase form).

The scheme can only contain US-ASCII letters or digits, which means it cannot contain any character that would otherwise require encoding. Additionally, schemes are always returned in lowercase form.

Example: http://user:password@host:port/path/page.html?key1=value1&key2=value2::fragment Scheme is "http".

◆ GetUsername()

PString PUri::GetUsername ( ) const

Returns the fully decoded username of this URI or an empty string if it is undefined.

Percent-encoded sequences are decoded.

Example: http://user:password@host:port/path/page.html?key1=value1&key2=value2::fragment Username is "user".

◆ HasQuery()

bool PUri::HasQuery ( ) const

Returns true if this URI contains a query, false otherwise.

◆ HasQueryItem()

bool PUri::HasQueryItem ( const PString key) const

Returns true if the specified key is in the query string, false otherwise.

◆ IsEmpty()

bool PUri::IsEmpty ( ) const

Returns true if this URI is empty; otherwise returns false.

◆ IsEncoded()

bool PUri::IsEncoded ( ) const

Returns true if this URI is percent-encoded, false otherwise.

◆ IsFile()

bool PUri::IsFile ( ) const

Returns true if this URI represents a file (i.e.

if its scheme is empty or "file"), false otherwise.

◆ IsNetwork()

bool PUri::IsNetwork ( ) const

Returns true if this URI represents a network stream (i.e.

if its scheme is "rtsp", "rtp", "udp", etc.), false otherwise.

◆ IsValid()

bool PUri::IsValid ( ) const

Returns true if this URI is non-empty and valid; otherwise returns false.

◆ operator!=()

bool PUri::operator!= ( const PUri other) const

Returns true if this URI is equal to other; otherwise returns false.

◆ operator=()

PUri& PUri::operator= ( const PUri other)

Performs a shared copy of other to this object.

◆ operator==()

bool PUri::operator== ( const PUri other) const

Returns true if this URI is equal to other; otherwise returns false.

◆ RemoveQueryItem()

bool PUri::RemoveQueryItem ( const PString key)

Removes the query item with given key value.

Returns true if the item is removed successfully, false otherwise.

Example: When RemoveQueryItem("key1") is called on the URI below, http://user:password@host:port/path/page.html?key1=value1&key2=2.3#fragment result will be, http://user:password@host:port/path/page.html?key2=2.3#fragment

◆ ToStringRemovedUserInfo()

PString PUri::ToStringRemovedUserInfo ( ) const

Returns a string representation of this URI without any user/password information.