ARC SDK
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends

Class to represent general URLs. More...

#include <arc/URL.h>

Inheritance diagram for Arc::URL:
Arc::SourceType Arc::TargetType Arc::URLLocation

Public Types

enum  Scope
 Scope for LDAP URLs.
 

Public Member Functions

 URL ()
 Empty constructor. URL object is invalid.
 
 URL (const std::string &url, bool encoded=false)
 Constructs a new URL from a string representation.
 
virtual ~URL ()
 Empty destructor.
 
void URIDecode (void)
 Perform decoding of stored URL parts according to RFC 3986. More...
 
const std::string & Protocol () const
 Returns the protocol of the URL.
 
void ChangeProtocol (const std::string &newprot)
 Changes the protocol of the URL.
 
const std::string & Username () const
 Returns the username of the URL.
 
const std::string & Passwd () const
 Returns the password of the URL.
 
const std::string & Host () const
 Returns the hostname of the URL.
 
void ChangeHost (const std::string &newhost)
 Changes the hostname of the URL.
 
int Port () const
 Returns the port of the URL.
 
void ChangePort (int newport)
 Changes the port of the URL.
 
const std::string & Path () const
 Returns the path of the URL.
 
std::string FullPath () const
 Returns the path of the URL with all options attached.
 
std::string FullPathURIEncoded () const
 Returns the path and all options, URI-encoded according to RFC 3986. More...
 
void ChangePath (const std::string &newpath)
 Changes the path of the URL.
 
void ChangeFullPath (const std::string &newpath, bool encoded=false)
 Changes the path of the URL and all options attached.
 
const std::map< std::string,
std::string > & 
HTTPOptions () const
 Returns HTTP options if any.
 
const std::string & HTTPOption (const std::string &option, const std::string &undefined="") const
 Returns the value of an HTTP option. More...
 
bool AddHTTPOption (const std::string &option, const std::string &value, bool overwrite=true)
 Adds a HTP option with the given value. More...
 
void RemoveHTTPOption (const std::string &option)
 Removes a HTTP option if exists. More...
 
const std::list< std::string > & LDAPAttributes () const
 Returns the LDAP attributes if any.
 
void AddLDAPAttribute (const std::string &attribute)
 Adds an LDAP attribute.
 
Scope LDAPScope () const
 Returns the LDAP scope.
 
void ChangeLDAPScope (const Scope newscope)
 Changes the LDAP scope.
 
const std::string & LDAPFilter () const
 Returns the LDAP filter.
 
void ChangeLDAPFilter (const std::string &newfilter)
 Changes the LDAP filter.
 
const std::map< std::string,
std::string > & 
Options () const
 Returns URL options if any.
 
const std::string & Option (const std::string &option, const std::string &undefined="") const
 Returns the value of a URL option. More...
 
const std::map< std::string,
std::string > & 
MetaDataOptions () const
 Returns metadata options if any.
 
const std::string & MetaDataOption (const std::string &option, const std::string &undefined="") const
 Returns the value of a metadata option. More...
 
bool AddOption (const std::string &option, const std::string &value, bool overwrite=true)
 Adds a URL option with the given value. More...
 
bool AddOption (const std::string &option, bool overwrite=true)
 Adds a URL option where option has the format "name=value". More...
 
void AddMetaDataOption (const std::string &option, const std::string &value, bool overwrite=true)
 Adds a metadata option.
 
void AddLocation (const URLLocation &location)
 Adds a Location.
 
const std::list< URLLocation > & Locations () const
 Returns the locations if any.
 
const std::map< std::string,
std::string > & 
CommonLocOptions () const
 Returns the common location options if any.
 
const std::string & CommonLocOption (const std::string &option, const std::string &undefined="") const
 Returns the value of a common location option. More...
 
void RemoveOption (const std::string &option)
 Removes a URL option if exists. More...
 
void RemoveMetaDataOption (const std::string &option)
 Remove a metadata option if exits. More...
 
virtual std::string str (bool encode=false) const
 Returns a string representation of the URL including meta-options.
 
virtual std::string plainstr (bool encode=false) const
 Returns a string representation of the URL without any options.
 
virtual std::string fullstr (bool encode=false) const
 Returns a string representation including options and locations.
 
virtual std::string ConnectionURL () const
 Returns a string representation with protocol, host and port only.
 
bool operator< (const URL &url) const
 Compares one URL to another.
 
bool operator== (const URL &url) const
 Is one URL equal to another?
 
 operator bool () const
 Check if instance holds valid URL.
 
bool operator! () const
 Check if instance does not hold valid URL.
 
bool StringMatches (const std::string &str) const
 Returns true if string matches url.
 
std::map< std::string,
std::string > 
ParseOptions (const std::string &optstring, char separator, bool encoded=false)
 Parse a string of options separated by separator into an attribute->value map.
 

Static Public Member Functions

static std::string OptionString (const std::map< std::string, std::string > &options, char separator, bool encode=false)
 Returns a string representation of the options given in the options map. More...
 
static std::string URIEncode (const std::string &str)
 Perform encoding according to RFC 3986. More...
 
static std::string URIDecode (const std::string &str)
 Perform decoding according to RFC 3986. More...
 

Protected Member Functions

void ParsePath (bool encoded=false)
 Convenience method for splitting schema specific part into path and options.
 

Static Protected Member Functions

static std::string BaseDN2Path (const std::string &)
 a private method that converts an ldap basedn to a path.
 
static std::string Path2BaseDN (const std::string &)
 a private method that converts an ldap path to a basedn.
 

Protected Attributes

std::string protocol
 the url protocol.
 
std::string username
 username of the url.
 
std::string passwd
 password of the url.
 
std::string host
 hostname of the url.
 
bool ip6addr
 if host is IPv6 numerical address notation.
 
int port
 portnumber of the url.
 
std::string path
 the url path.
 
std::map< std::string,
std::string > 
httpoptions
 HTTP options of the url.
 
std::map< std::string,
std::string > 
metadataoptions
 Meta data options.
 
std::list< std::string > ldapattributes
 LDAP attributes of the url.
 
Scope ldapscope
 LDAP scope of the url.
 
std::string ldapfilter
 LDAP filter of the url.
 
std::map< std::string,
std::string > 
urloptions
 options of the url.
 
std::list< URLLocationlocations
 locations for index server URLs.
 
std::map< std::string,
std::string > 
commonlocoptions
 common location options for index server URLs.
 
bool valid
 flag to describe validity of URL
 

Friends

std::ostream & operator<< (std::ostream &out, const URL &u)
 Overloaded operator << to print a URL.
 

Detailed Description

Class to represent general URLs.

  The URL is split into protocol, hostname, port and path. This class tries
  to follow RFC 3986 for splitting URLs, at least for protocol + host part.
  It also accepts local file paths which are converted to file:path.
  The usual system dependent file paths are supported. Relative paths are
  converted to absolute paths by prepending them with current working
  directory path. A file path can't start from # symbol. If the string
  representation of URL starts from '@' then it is treated as path to a
  file containing a list of URLs.

  A URL is parsed in the following way:
 [protocol:][//[username:passwd@][host][:port]][;urloptions[;...]][/path[?httpoption[&...]][:metadataoption[:...]]]

The 'protocol' and 'host' parts are treated as case-insensitive and to avoid confusion are converted to lowercase in constructor. Note that 'path' is always converted to absolute path in the constructor. The meaning of 'absolute' may depend upon URL type. For generic URL and local POSIX file paths that means the path starts from / like

 /path/to/file

For Windows paths the absolute path may look like

 C:\path\to\file

It is important to note that path still can be empty. For referencing a local file using an absolute path on a POSIX filesystem one may use either

 file:///path/to/file or file:/path/to/file

The relative path will look like

 file:to/file

For local Windows files possible URLs are

 %file:C:\path\to\file or %file:to\file

URLs representing LDAP resources have a different structure of options following the 'path' part:

 ldap://host[:port][;urloptions[;...]][/path[?attributes[?scope[?filter]]]]

For LDAP URLs paths are converted from /key1=value1/.../keyN=valueN notation to keyN=valueN,...,key1=value1 and hence path does not contain a leading /. If an LDAP URL initially had its path in the second notation, the leading / is treated as a separator only and is stripped.

URLs of indexing services optionally may have locations specified before the 'host' part

 protocol://[location[;location[;...]]@][host][:port]...

The structure of the 'location' element is protocol specific.

Member Function Documentation

bool Arc::URL::AddHTTPOption ( const std::string &  option,
const std::string &  value,
bool  overwrite = true 
)

Adds a HTP option with the given value.

Returns
false if overwrite is false and option already exists, true otherwise.
bool Arc::URL::AddOption ( const std::string &  option,
const std::string &  value,
bool  overwrite = true 
)

Adds a URL option with the given value.

Note that some compilers may interpret AddOption("name", "value") as a call to AddOption(const std::string&, bool) so it is recommended to use explicit string types when calling this method.

Returns
false if overwrite is false and option already exists, true otherwise.
bool Arc::URL::AddOption ( const std::string &  option,
bool  overwrite = true 
)

Adds a URL option where option has the format "name=value".

Returns
false if overwrite is true and option already exists or if option does not have the correct format. Returns true otherwise.
const std::string& Arc::URL::CommonLocOption ( const std::string &  option,
const std::string &  undefined = "" 
) const

Returns the value of a common location option.

Parameters
optionThe option whose value is returned.
undefinedThis value is returned if the common location option is not defined.
std::string Arc::URL::FullPathURIEncoded ( ) const

Returns the path and all options, URI-encoded according to RFC 3986.

Forward slashes ('/') in the path are not encoded but are encoded in the options.

const std::string& Arc::URL::HTTPOption ( const std::string &  option,
const std::string &  undefined = "" 
) const

Returns the value of an HTTP option.

Parameters
optionThe option whose value is returned.
undefinedThis value is returned if the HTTP option is not defined.
const std::string& Arc::URL::MetaDataOption ( const std::string &  option,
const std::string &  undefined = "" 
) const

Returns the value of a metadata option.

Parameters
optionThe option whose value is returned.
undefinedThis value is returned if the metadata option is not defined.
const std::string& Arc::URL::Option ( const std::string &  option,
const std::string &  undefined = "" 
) const

Returns the value of a URL option.

Parameters
optionThe option whose value is returned.
undefinedThis value is returned if the URL option is not defined.
static std::string Arc::URL::OptionString ( const std::map< std::string, std::string > &  options,
char  separator,
bool  encode = false 
)
static

Returns a string representation of the options given in the options map.

Parameters
optionsKey-value map of options
separatorThe character that separates options
encodeif set to true then options are encoded according to RFC 3986
void Arc::URL::RemoveHTTPOption ( const std::string &  option)

Removes a HTTP option if exists.

Parameters
optionThe option to remove.
void Arc::URL::RemoveMetaDataOption ( const std::string &  option)

Remove a metadata option if exits.

Parameters
optionThe option to remove.
void Arc::URL::RemoveOption ( const std::string &  option)

Removes a URL option if exists.

Parameters
optionThe option to remove.
void Arc::URL::URIDecode ( void  )

Perform decoding of stored URL parts according to RFC 3986.

This method is supposed to be used only if for some reason URL constructor was called with encoded=false for URL which was encoded. Use it only once.

static std::string Arc::URL::URIDecode ( const std::string &  str)
static

Perform decoding according to RFC 3986.

This simply calls Arc::uri_unencode().

static std::string Arc::URL::URIEncode ( const std::string &  str)
static

Perform encoding according to RFC 3986.

This simply calls Arc::uri_encode().


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