libzypp
13.10.6
|
Url manipulation class. More...
#include <Url.h>
Public Types | |
typedef zypp::url::EEncoding | EEncoding |
Encoding flags. More... | |
typedef zypp::url::ViewOptions | ViewOptions |
View options. More... | |
Public Member Functions | |
~Url () | |
Url () | |
Url (const Url &url) | |
Create a new Url object as shared copy of the given one. More... | |
Url (const zypp::url::UrlRef &url) | |
Create a new Url object as shared copy of the given reference. More... | |
Url (const std::string &encodedUrl) | |
Construct a Url object from percent-encoded URL string. More... | |
Url & | operator= (const std::string &encodedUrl) |
Assigns parsed percent-encoded URL string to the object. More... | |
Url & | operator= (const Url &url) |
Assign shared copy of url to the current object. More... | |
zypp::url::UrlSchemes | getKnownSchemes () const |
Returns scheme names known to this object. More... | |
bool | isValidScheme (const std::string &scheme) const |
Verifies specified scheme name. More... | |
bool | schemeIsLocal () const |
bool | schemeIsRemote () const |
bool | schemeIsVolatile () const |
bool | schemeIsDownloading () const |
bool | isValid () const |
Verifies the Url. More... | |
std::string | asString () const |
Returns a default string representation of the Url object. More... | |
std::string | asString (const ViewOptions &opts) const |
Returns a string representation of the Url object. More... | |
std::string | asCompleteString () const |
Returns a complete string representation of the Url object. More... | |
std::string | getScheme () const |
Returns the scheme name of the URL. More... | |
std::string | getAuthority () const |
Returns the encoded authority component of the URL. More... | |
std::string | getUsername (EEncoding eflag=zypp::url::E_DECODED) const |
Returns the username from the URL authority. More... | |
std::string | getPassword (EEncoding eflag=zypp::url::E_DECODED) const |
Returns the password from the URL authority. More... | |
bool | hasCredentialsInAuthority () const |
Returns true if username and password are encoded in the authority component. More... | |
std::string | getHost (EEncoding eflag=zypp::url::E_DECODED) const |
Returns the hostname or IP from the URL authority. More... | |
std::string | getPort () const |
Returns the port from the URL authority. More... | |
std::string | getPathData () const |
Returns the encoded path component of the URL. More... | |
std::string | getPathName (EEncoding eflag=zypp::url::E_DECODED) const |
Returns the path name from the URL. More... | |
std::string | getPathParams () const |
Returns the path parameters from the URL. More... | |
zypp::url::ParamVec | getPathParamsVec () const |
Returns a vector with path parameter substrings. More... | |
zypp::url::ParamMap | getPathParamsMap (EEncoding eflag=zypp::url::E_DECODED) const |
Returns a string map with path parameter keys and values. More... | |
std::string | getPathParam (const std::string ¶m, EEncoding eflag=zypp::url::E_DECODED) const |
Return the value for the specified path parameter. More... | |
std::string | getQueryString () const |
Returns the encoded query string component of the URL. More... | |
zypp::url::ParamVec | getQueryStringVec () const |
Returns a vector with query string parameter substrings. More... | |
zypp::url::ParamMap | getQueryStringMap (EEncoding eflag=zypp::url::E_DECODED) const |
Returns a string map with query parameter and their values. More... | |
std::string | getQueryParam (const std::string ¶m, EEncoding eflag=zypp::url::E_DECODED) const |
Return the value for the specified query parameter. More... | |
std::string | getFragment (EEncoding eflag=zypp::url::E_DECODED) const |
Returns the encoded fragment component of the URL. More... | |
void | setScheme (const std::string &scheme) |
Set the scheme name in the URL. More... | |
void | setAuthority (const std::string &authority) |
Set the authority component in the URL. More... | |
void | setUsername (const std::string &user, EEncoding eflag=zypp::url::E_DECODED) |
Set the username in the URL authority. More... | |
void | setPassword (const std::string &pass, EEncoding eflag=zypp::url::E_DECODED) |
Set the password in the URL authority. More... | |
void | setHost (const std::string &host) |
Set the hostname or IP in the URL authority. More... | |
void | setPort (const std::string &port) |
Set the port number in the URL authority. More... | |
void | setPathData (const std::string &pathdata) |
Set the path data component in the URL. More... | |
void | setPathName (const std::string &path, EEncoding eflag=zypp::url::E_DECODED) |
Set the path name. More... | |
void | setPathName (const Pathname &path, EEncoding eflag=zypp::url::E_DECODED) |
void | setPathName (const char *path, EEncoding eflag=zypp::url::E_DECODED) |
void | setPathParams (const std::string ¶ms) |
Set the path parameters. More... | |
void | setPathParamsVec (const zypp::url::ParamVec &pvec) |
Set the path parameters. More... | |
void | setPathParamsMap (const zypp::url::ParamMap &pmap) |
Set the path parameters. More... | |
void | setPathParam (const std::string ¶m, const std::string &value) |
Set or add value for the specified path parameter. More... | |
void | setQueryString (const std::string &querystr) |
Set the query string in the URL. More... | |
void | setQueryStringVec (const zypp::url::ParamVec &qvec) |
Set the query parameters. More... | |
void | setQueryStringMap (const zypp::url::ParamMap &qmap) |
Set the query parameters. More... | |
void | setQueryParam (const std::string ¶m, const std::string &value) |
Set or add value for the specified query parameter. More... | |
void | delQueryParam (const std::string ¶m) |
remove the specified query parameter. More... | |
void | setFragment (const std::string &fragment, EEncoding eflag=zypp::url::E_DECODED) |
Set the fragment string in the URL. More... | |
ViewOptions | getViewOptions () const |
Return the view options of the current object. More... | |
void | setViewOptions (const ViewOptions &vopts) |
Change the view options of the current object. More... | |
Static Public Member Functions | |
static url::UrlRef | parseUrl (const std::string &encodedUrl) |
Parse a percent-encoded URL string. More... | |
static bool | registerScheme (const std::string &scheme, url::UrlRef urlImpl) |
Register a scheme-specific implementation. More... | |
static zypp::url::UrlSchemes | getRegisteredSchemes () |
Returns all registered scheme names. More... | |
static bool | isRegisteredScheme (const std::string &scheme) |
Returns if scheme name is registered. More... | |
static bool | schemeIsLocal (const std::string &scheme_r) |
hd cd dvd dir file iso More... | |
static bool | schemeIsRemote (const std::string &scheme_r) |
nfs nfs4 smb cifs http https ftp sftp tftp More... | |
static bool | schemeIsVolatile (const std::string &scheme_r) |
cd dvd More... | |
static bool | schemeIsDownloading (const std::string &scheme_r) |
http https ftp sftp tftp More... | |
Private Attributes | |
url::UrlRef | m_impl |
Url manipulation class.
The generic URL (URI) syntax and its main components are defined in RFC3986 (http://rfc.net/rfc3986.html) Section 3, "Syntax Components". The scheme specific URL syntax and semantics is defined in the specification of the particular scheme. See also RFC1738 (http://rfc.net/rfc1738.html), that defines specific syntax for several URL schemes.
This class provides methods to access and manipulate generic and common scheme-specific URL components (or using the more general term, URI components). To consider the scheme-specifics of a URL, the Url class contains a reference object pointing to a UrlBase or derived object, that implements the scheme specifics.
Using the Url::registerScheme() method, it is possible to register a preconfigured or derived UrlBase object for a specific scheme name. The registered object will be cloned to handle all URL's containing the specified scheme name.
The generic URI syntax consists of a hierarchical sequence of components referred to as the scheme, authority, path, query, and fragment.
The scheme and path components are required, though the path may be empty (no characters). When authority is present, the path must either be empty or begin with a slash ("/") character. When authority is not present, the path cannot begin with two slash characters ("//"). These restrictions result in five different ABNF rules for a path (Section 3.3), only one of which will match any given URI reference.
The following are two example URIs and their component parts:
zypp::Url::Url | ( | const Url & | url | ) |
Create a new Url object as shared copy of the given one.
Upon return, both objects will point to the same underlying object. This state will remain until one of the object is modified.
url | The Url object to make a copy of. |
url::UrlException | if copy fails (should not happen). |
zypp::Url::Url | ( | const zypp::url::UrlRef & | url | ) |
Create a new Url object as shared copy of the given reference.
Upon return, both objects will point to the same underlying object. This state will remain until one of the object is modified.
url | The URL implementation reference to make a copy of. |
url::UrlException | if reference is empty. |
zypp::Url::Url | ( | const std::string & | encodedUrl | ) |
Construct a Url object from percent-encoded URL string.
Parses the encodedUrl
string using the parseUrl() method and assings the result to the new created object.
encodedUrl | A percent-encoded URL string. |
url::UrlParsingException | if parsing of the url fails. |
url::UrlNotAllowedException | if one of the components is not allowed for the scheme. |
url::UrlBadComponentException | if one of the components contains an invalid character. |
|
static |
Parse a percent-encoded URL string.
Trys to parses the given string into generic URL components and created a clone of a scheme-specialized object or a new UrlBase object.
encodedUrl | A percent-encoded URL string. |
encodedUrl
string does not match the generic URL syntax. url::UrlNotAllowedException | if one of the components is not allowed for the scheme. |
url::UrlBadComponentException | if one of the components contains an invalid character. |
Url & zypp::Url::operator= | ( | const std::string & | encodedUrl | ) |
Assigns parsed percent-encoded URL string to the object.
Parses encodedUrl
string using the parseUrl() method and assigns the result to the current object.
encodedUrl | A percent-encoded URL string. |
url::UrlParsingException | if parsing of the url fails. |
url::UrlNotAllowedException | if one of the components is not allowed for the scheme. |
url::UrlBadComponentException | if one of the components contains an invalid character. |
|
static |
|
static |
|
static |
zypp::url::UrlSchemes zypp::Url::getKnownSchemes | ( | ) | const |
bool zypp::Url::isValidScheme | ( | const std::string & | scheme | ) | const |
Verifies specified scheme name.
Verifies the generic syntax of the specified scheme
name and if it is contained in the current object's list of known schemes (see getKnownSchemes()) if the list is not empty.
The default implementation in the UrlBase class returns an emtpy list of known schemes, causing a check of the generic syntax only.
|
static |
|
inline |
|
static |
|
inline |
|
static |
|
inline |
|
static |
|
inline |
bool zypp::Url::isValid | ( | ) | const |
std::string zypp::Url::asString | ( | ) | const |
std::string zypp::Url::asString | ( | const ViewOptions & | opts | ) | const |
std::string zypp::Url::asCompleteString | ( | ) | const |
std::string zypp::Url::getScheme | ( | ) | const |
std::string zypp::Url::getAuthority | ( | ) | const |
std::string zypp::Url::getUsername | ( | EEncoding | eflag = zypp::url::E_DECODED | ) | const |
Returns the username from the URL authority.
eflag | Flag if the usename should be percent-decoded or not. |
url::UrlDecodingException | if the decoded result string would contain a '\0' character. |
std::string zypp::Url::getPassword | ( | EEncoding | eflag = zypp::url::E_DECODED | ) | const |
Returns the password from the URL authority.
eflag | Flag if the password should be percent-decoded or not. |
url::UrlDecodingException | if the decoded result string would contain a '\0' character. |
|
inline |
std::string zypp::Url::getHost | ( | EEncoding | eflag = zypp::url::E_DECODED | ) | const |
Returns the hostname or IP from the URL authority.
In case the Url contains an IP number, it may be surrounded by "[" and "]" characters, for example "[::1]" for an IPv6 localhost address.
eflag | Flag if the host should be percent-decoded or not. |
url::UrlDecodingException | if the decoded result string would contain a '\0' character. |
std::string zypp::Url::getPort | ( | ) | const |
std::string zypp::Url::getPathData | ( | ) | const |
std::string zypp::Url::getPathName | ( | EEncoding | eflag = zypp::url::E_DECODED | ) | const |
Returns the path name from the URL.
eflag | Flag if the path should be decoded or not. |
url::UrlDecodingException | if the decoded result string would contain a '\0' character. |
std::string zypp::Url::getPathParams | ( | ) | const |
zypp::url::ParamVec zypp::Url::getPathParamsVec | ( | ) | const |
Returns a vector with path parameter substrings.
The default path parameter separator is the '
,' character. A schema specific object may overide the default separators.
For example, the path parameters string "foo=1,bar=2" is splited by default into a vector containing the substrings "foo=1" and "bar=2".
zypp::url::ParamMap zypp::Url::getPathParamsMap | ( | EEncoding | eflag = zypp::url::E_DECODED | ) | const |
Returns a string map with path parameter keys and values.
The default path parameter separator is the '
,' character, the default key/value separator for the path parameters is the '='
character. A schema specific object may overide the default separators.
For example, the path parameters string "foo=1,bar=2" is splited into a map containing "foo" = "1" and "bar" = "2" by default.
eflag | Flag if the path parameter keys and values should be decoded or not. |
url::UrlNotSupportedException | if parameter parsing is not supported for a URL (scheme). |
url::UrlDecodingException | if the decoded result string would contain a '\0' character. |
std::string zypp::Url::getPathParam | ( | const std::string & | param, |
EEncoding | eflag = zypp::url::E_DECODED |
||
) | const |
Return the value for the specified path parameter.
For example, if the path parameters string is "foo=1,bar=2" the method will return the substring "1" for the param key "foo" and "2" for the param key "bar".
param | The path parameter key. |
eflag | Flag if the path parameter keys and values should be decoded or not. |
url::UrlNotSupportedException | if parameter parsing is not supported for a URL (scheme). |
url::UrlDecodingException | if the decoded result string would contain a '\0' character. |
std::string zypp::Url::getQueryString | ( | ) | const |
zypp::url::ParamVec zypp::Url::getQueryStringVec | ( | ) | const |
Returns a vector with query string parameter substrings.
The default query string parameter separator is the '&'
character. A schema specific object may overide the default separators.
For example, the query string "foo=1&bar=2" is splited by default into a vector containing the substrings "foo=1" and "bar=2".
zypp::url::ParamMap zypp::Url::getQueryStringMap | ( | EEncoding | eflag = zypp::url::E_DECODED | ) | const |
Returns a string map with query parameter and their values.
The default query string parameter separator is the '
,' character, the default key/value separator the '='
character. A schema specific object may overide the default separators.
For example, the query string "foo=1&bar=2" is splited by default into a map containing "foo" = "1" and "bar" = "2".
eflag | Flag if the query string keys and values should be decoded or not. |
url::UrlNotSupportedException | if parameter parsing is not supported for a URL (scheme). |
url::UrlDecodingException | if the decoded result string would contain a '\0' character. |
std::string zypp::Url::getQueryParam | ( | const std::string & | param, |
EEncoding | eflag = zypp::url::E_DECODED |
||
) | const |
Return the value for the specified query parameter.
For example, if the query string is "foo=1,bar=2" the method will return the substring "1" for the param key "foo" and "2" for the param key "bar".
param | The query parameter key. |
eflag | Flag if the query parameter keys and values should be decoded or not. |
url::UrlNotSupportedException | if parameter parsing is not supported for a URL (scheme). |
url::UrlDecodingException | if the decoded result string would contain a '\0' character. |
std::string zypp::Url::getFragment | ( | EEncoding | eflag = zypp::url::E_DECODED | ) | const |
Returns the encoded fragment component of the URL.
eflag | Flag if the fragment should be percent-decoded or not. |
url::UrlDecodingException | if the decoded result string would contain a '\0' character. |
void zypp::Url::setScheme | ( | const std::string & | scheme | ) |
Set the scheme name in the URL.
scheme | The new scheme name. |
url::UrlBadComponentException | if the scheme contains an invalid character or is empty. |
void zypp::Url::setAuthority | ( | const std::string & | authority | ) |
Set the authority component in the URL.
The authority
string shoud contain the "user:pass@host:port" sub-components without any leading "//" separator characters.
authority | The encoded authority component string. |
url::UrlNotAllowedException | if the authority has to be empty in for the current scheme. |
url::UrlBadComponentException | if the authority contains an invalid character. |
url::UrlParsingException | if authority parsing fails. |
void zypp::Url::setUsername | ( | const std::string & | user, |
EEncoding | eflag = zypp::url::E_DECODED |
||
) |
Set the username in the URL authority.
user | The new username. |
eflag | If the username is encoded or not. |
url::UrlNotAllowedException | if the user has to be empty in for the current scheme |
url::UrlBadComponentException | if the user contains an invalid character. |
void zypp::Url::setPassword | ( | const std::string & | pass, |
EEncoding | eflag = zypp::url::E_DECODED |
||
) |
Set the password in the URL authority.
pass | The new password. |
eflag | If the password is encoded or not. |
url::UrlNotAllowedException | if the pass has to be empty in for the current scheme. |
url::UrlBadComponentException | if the pass contains an invalid character. |
void zypp::Url::setHost | ( | const std::string & | host | ) |
Set the hostname or IP in the URL authority.
The host
parameter may contain a hostname, an IPv4 address in dotted-decimal form or an IPv6 address literal encapsulated within square brackets (RFC3513, Sect. 2.2).
A hostname may contain national alphanumeric UTF8 characters (letters other than ASCII a-z0-9), that will be encoded. This function allows to specify both, a encoded or decoded hostname.
Other IP literals in "[v ... ]" square bracket format are not supported by the implementation in UrlBase class.
host | The new hostname or IP address. |
url::UrlNotAllowedException | if the host (authority) has to be empty in for the current scheme. |
url::UrlBadComponentException | if the host is invalid. |
void zypp::Url::setPort | ( | const std::string & | port | ) |
Set the port number in the URL authority.
port | The new port number. |
url::UrlNotAllowedException | if the port (authority) has to be empty in for the current scheme. |
url::UrlBadComponentException | if the port is invalid. |
void zypp::Url::setPathData | ( | const std::string & | pathdata | ) |
Set the path data component in the URL.
By default, the pathdata
string may include path parameters separated by the ";" separator character.
pathdata | The encoded path data component string. |
url::UrlBadComponentException | if the pathdata contains an invalid character. |
void zypp::Url::setPathName | ( | const std::string & | path, |
EEncoding | eflag = zypp::url::E_DECODED |
||
) |
Set the path name.
path | The new path name. |
eflag | If the path name is encoded or not. |
url::UrlBadComponentException | if the path name contains an invalid character. |
void zypp::Url::setPathName | ( | const Pathname & | path, |
EEncoding | eflag = zypp::url::E_DECODED |
||
) |
void zypp::Url::setPathName | ( | const char * | path, |
EEncoding | eflag = zypp::url::E_DECODED |
||
) |
void zypp::Url::setPathParams | ( | const std::string & | params | ) |
Set the path parameters.
params | The new encoded path parameter string. |
url::UrlBadComponentException | if the path params contains an invalid character. |
void zypp::Url::setPathParamsVec | ( | const zypp::url::ParamVec & | pvec | ) |
Set the path parameters.
pvec | The vector with encoded path parameters. |
url::UrlBadComponentException | if the pvec contains an invalid character. |
void zypp::Url::setPathParamsMap | ( | const zypp::url::ParamMap & | pmap | ) |
Set the path parameters.
pmap | The map with decoded path parameters. |
url::UrlNotSupportedException | if parameter parsing is not supported for a URL (scheme). |
void zypp::Url::setPathParam | ( | const std::string & | param, |
const std::string & | value | ||
) |
Set or add value for the specified path parameter.
param | The decoded path parameter name. |
value | The decoded path parameter value. |
url::UrlNotSupportedException | if parameter parsing is not supported for a URL (scheme). |
url::UrlDecodingException | if the decoded result string would contain a '\0' character. |
void zypp::Url::setQueryString | ( | const std::string & | querystr | ) |
Set the query string in the URL.
querystr | The new encoded query string. |
url::UrlBadComponentException | if the querystr contains an invalid character. |
void zypp::Url::setQueryStringVec | ( | const zypp::url::ParamVec & | qvec | ) |
Set the query parameters.
qvec | The vector with encoded query parameters. |
url::UrlBadComponentException | if the qvec contains an invalid character. |
void zypp::Url::setQueryStringMap | ( | const zypp::url::ParamMap & | qmap | ) |
Set the query parameters.
qmap | The map with decoded query parameters. |
url::UrlNotSupportedException | if parameter parsing is not supported for a URL (scheme). |
void zypp::Url::setQueryParam | ( | const std::string & | param, |
const std::string & | value | ||
) |
Set or add value for the specified query parameter.
param | The decoded query parameter name. |
value | The decoded query parameter value. |
url::UrlNotSupportedException | if parameter parsing is not supported for a URL (scheme). |
url::UrlDecodingException | if the decoded result string would contain a '\0' character. |
void zypp::Url::delQueryParam | ( | const std::string & | param | ) |
remove the specified query parameter.
param | The decoded query parameter name. |
url::UrlNotSupportedException | if parameter parsing is not supported for a URL (scheme). |
url::UrlDecodingException | if the decoded result string would contain a '\0' character. |
void zypp::Url::setFragment | ( | const std::string & | fragment, |
EEncoding | eflag = zypp::url::E_DECODED |
||
) |
Set the fragment string in the URL.
fragment | The new fragment string. |
eflag | If the fragment is encoded or not. |
url::UrlBadComponentException | if the fragment contains an invalid character. |
ViewOptions zypp::Url::getViewOptions | ( | ) | const |
Return the view options of the current object.
This method is used to query the view options used by the asString() method.
void zypp::Url::setViewOptions | ( | const ViewOptions & | vopts | ) |
Change the view options of the current object.
This method is used to change the view options used by the asString() method.
vopts | New view options combination. |
|
private |