|
PTLib
Version 2.18.8
|
This class describes a Universal Resource Locator. More...
#include <url.h>


Classes | |
| struct | LoadParams |
Public Member Functions | |
| PURL () | |
| Construct a new URL object from the URL string. More... | |
| PURL (const char *cstr, const char *defaultScheme="http") | |
| Construct a new URL object from the URL string. More... | |
| PURL (const PString &str, const char *defaultScheme="http") | |
| Construct a new URL object from the URL string. More... | |
| PURL (const PFilePath &path) | |
| Construct a new URL object from the file path. More... | |
| PURL (const PURL &other) | |
| PURL & | operator= (const PURL &other) |
| bool | LegacyParse (const char *str, const PURLLegacyScheme *schemeInfo) |
| PString | LegacyAsString (PURL::UrlFormat fmt, const PURLLegacyScheme *schemeInfo) const |
Overrides from class PObject | |
| virtual Comparison | Compare (const PObject &obj) const |
| Compare the two URLs and return their relative rank. More... | |
| virtual PINDEX | HashFunction () const |
This function yields a hash value required by the PDictionary class. More... | |
| virtual void | PrintOn (ostream &strm) const |
| Output the contents of the URL to the stream as a string. More... | |
| virtual void | ReadFrom (istream &strm) |
| Input the contents of the URL from the stream. More... | |
Public Member Functions inherited from PObject | |
| __inline unsigned | GetTraceContextIdentifier () const |
| Get PTRACE context identifier. More... | |
| __inline void | SetTraceContextIdentifier (unsigned id) |
| __inline void | SetTraceContextIdentifier (const PObject &obj) |
| __inline void | SetTraceContextIdentifier (const PObject *obj) |
| __inline void | CopyTraceContextIdentifier (PObject &obj) const |
| __inline void | CopyTraceContextIdentifier (PObject *obj) const |
| virtual | ~PObject () |
| __inline const char * | GetClass () const |
| __inline bool | IsClass (const char *name) const |
| __inline const PObject * | PTraceObjectInstance () const |
| virtual PObject * | Clone () const |
| Create a copy of the class on the heap. More... | |
| template<class CLS > | |
| CLS * | CloneAs () const |
| As for Clone() but converts to specified type. More... | |
| virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const |
| Determine the byte wise comparison of two objects. More... | |
| bool | operator== (const PObject &obj) const |
| Compare the two objects. More... | |
| bool | operator!= (const PObject &obj) const |
| Compare the two objects. More... | |
| bool | operator< (const PObject &obj) const |
| Compare the two objects. More... | |
| bool | operator> (const PObject &obj) const |
| Compare the two objects. More... | |
| bool | operator<= (const PObject &obj) const |
| Compare the two objects. More... | |
| bool | operator>= (const PObject &obj) const |
| Compare the two objects. More... | |
| virtual void | PrintOn (ostream &strm) const |
| Output the contents of the object to the stream. More... | |
| virtual void | ReadFrom (istream &strm) |
| Input the contents of the object from the stream. More... | |
Protected Member Functions | |
| void | CopyContents (const PURL &other) |
| virtual PBoolean | InternalParse (const char *cstr, const char *defaultScheme) |
| void | Recalculate () |
Protected Member Functions inherited from PObject | |
| PObject () | |
| Constructor for PObject, made protected so cannot ever create one on its own. More... | |
Protected Attributes | |
| const PURLScheme * | m_schemeInfo |
| PString | m_urlString |
| PCaselessString | m_scheme |
| PString | m_username |
| PString | m_password |
| PCaselessString | m_hostname |
| WORD | m_port |
| bool | m_portSupplied |
| bool | m_relativePath |
| port was supplied in string input More... | |
| PStringArray | m_path |
| PStringOptions | m_paramVars |
| PString | m_fragment |
| PStringOptions | m_queryVars |
| PString | m_contents |
Protected Attributes inherited from PObject | |
| unsigned | m_traceContextIdentifier |
New functions for class. | |
| enum | UrlFormat { FullURL, PathOnly, LocationOnly, RelativeOnly, HostPortOnly = LocationOnly, URIOnly = RelativeOnly } |
| Print/String output representation formats. More... | |
| enum | TranslationType { LoginTranslation, PathTranslation, QueryTranslation, ParameterTranslation, QuotedParameterTranslation } |
| Type for translation of strings to URL format,. More... | |
| PBoolean | Parse (const char *cstr, const char *defaultScheme=NULL) |
| Parse the URL string into the fields in the object instance. More... | |
| PBoolean | Parse (const PString &str, const char *defaultScheme=NULL) |
| Parse the URL string into the fields in the object instance. More... | |
| PString | AsString (UrlFormat fmt=FullURL) const |
| Convert the URL object into its string representation. More... | |
| operator PString () const | |
| PFilePath | AsFilePath () const |
| Get the "file:" URL as a file path. More... | |
| const PCaselessString & | GetScheme () const |
| Get the scheme field of the URL. More... | |
| bool | SetScheme (const PString &scheme) |
| Set the scheme field of the URL. More... | |
| const PString & | GetUserName () const |
| Get the username field of the URL. More... | |
| void | SetUserName (const PString &username) |
| Set the username field of the URL. More... | |
| const PString & | GetPassword () const |
| Get the password field of the URL. More... | |
| void | SetPassword (const PString &password) |
| Set the password field of the URL. More... | |
| const PCaselessString & | GetHostName () const |
| Get the hostname field of the URL. More... | |
| void | SetHostName (const PString &hostname) |
| Set the hostname field of the URL. More... | |
| WORD | GetPort () const |
| Get the port field of the URL. More... | |
| void | SetPort (WORD newPort) |
| Set the port field in the URL. Zero resets to default. More... | |
| PBoolean | GetPortSupplied () const |
| Get if explicit port is specified. More... | |
| PString | GetHostPort () const |
| Get the hostname and optional port fields of the URL. More... | |
| PBoolean | GetRelativePath () const |
| Get if path is relative or absolute. More... | |
| PString | GetPathStr () const |
| Get the path field of the URL as a string. More... | |
| void | SetPathStr (const PString &pathStr) |
| Set the path field of the URL as a string. More... | |
| const PStringArray & | GetPath () const |
| Get the path field of the URL as a string array. More... | |
| void | SetPath (const PStringArray &path) |
| Set the path field of the URL as a string array. More... | |
| void | AppendPath (const PString &segment) |
| Append segment to the path field of the URL. More... | |
| void | ChangePath (const PString &segment, PINDEX idx=P_MAX_INDEX) |
| Change segment in the path field of the URL. More... | |
| PString | GetParameters () const |
| Get the parameter (;) field of the URL. More... | |
| void | SetParameters (const PString ¶meters) |
| Set the parameter (;) field of the URL. More... | |
| const PStringOptions & | GetParamVars () const |
| Get the parameter (;) field(s) of the URL as a string dictionary. More... | |
| void | SetParamVars (const PStringToString ¶mVars, bool merge=false) |
| Set the parameter (;) field(s) of the URL as a string dictionary. More... | |
| void | SetParamVar (const PString &key, const PString &data, bool emptyDataDeletes=true) |
| Set the parameter (;) field of the URL as a string dictionary. More... | |
| const PString & | GetFragment () const |
| Get the fragment (#) field of the URL. More... | |
| PString | GetQuery () const |
| Get the Query (?) field of the URL as a string. More... | |
| void | SetQuery (const PString &query) |
| Set the Query (?) field of the URL as a string. More... | |
| const PStringOptions & | GetQueryVars () const |
| Get the Query (?) field of the URL as a string dictionary. More... | |
| void | SetQueryVars (const PStringToString &queryVars) |
| Set the Query (?) field(s) of the URL as a string dictionary. More... | |
| void | SetQueryVar (const PString &key, const PString &data) |
| Set the Query (?) field of the URL as a string dictionary. More... | |
| const PString & | GetContents () const |
| Get the contents of URL, data left after all elemetns are parsed out. More... | |
| void | SetContents (const PString &str) |
| Set the contents of URL, data left after all elemetns are parsed out. More... | |
| PBoolean | IsEmpty () const |
| Return true if the URL is an empty string. More... | |
| bool | LoadResource (PString &data, const LoadParams ¶ms=LoadParams()) const |
| Get the resource the URL is pointing at. More... | |
| bool | LoadResource (PBYTEArray &data, const LoadParams ¶ms=LoadParams()) const |
| template<class T > | |
| bool | LoadResource (T &data, const PString &requiredContentType=PString::Empty(), const PTimeInterval &timeout=PMaxTimeInterval) const |
| bool | OpenBrowser () const |
| Open the URL in a browser. More... | |
| static PString | TranslateString (const PString &str, TranslationType type) |
| Translate a string from general form to one that can be included into a URL. More... | |
| static PString | UntranslateString (const PString &str, TranslationType type) |
| Untranslate a string from a form that was included into a URL into a normal string. More... | |
| static void | SplitVars (const PString &str, PStringToString &vars, char sep1= ';', char sep2= '=', TranslationType type=ParameterTranslation) |
| Split a string to a dictionary of names and values. More... | |
| static void | SplitQueryVars (const PString &queryStr, PStringToString &queryVars) |
| Split a string in &= form to a dictionary of names and values. More... | |
| static void | OutputVars (ostream &strm, const PStringToString &vars, char sep0= ';', char sep1= ';', char sep2= '=', TranslationType type=ParameterTranslation) |
| Construct string from a dictionary using separators. More... | |
| static PCaselessString | ExtractScheme (const char *str) |
| Extract scheme as per RFC2396. More... | |
| static bool | OpenBrowser (const PString &url) |
Additional Inherited Members | |
Public Types inherited from PObject | |
| enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 } |
Result of the comparison operation performed by the Compare() function. More... | |
Static Public Member Functions inherited from PObject | |
| static __inline void | CopyTraceContextIdentifier (PObject &to, const PObject &from) |
| static __inline void | CopyTraceContextIdentifier (PObject &to, const PObject *from) |
| static __inline void | CopyTraceContextIdentifier (PObject *to, const PObject &from) |
| static __inline void | CopyTraceContextIdentifier (PObject *to, const PObject *from) |
| static __inline const char * | Class () |
| static __inline const PObject * | PTraceObjectInstance (const char *) |
| static __inline const PObject * | PTraceObjectInstance (const PObject *obj) |
| template<typename T > | |
| static Comparison | Compare2 (T v1, T v2) |
| Compare two types, returning Comparison type. More... | |
| static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size) |
| Internal function caled from CompareObjectMemoryDirect() More... | |
This class describes a Universal Resource Locator.
This is the desciption of a resource location as used by the World Wide Web and the PHTTPSocket class.
Note, this has been extended to be for URI's (Universal Resource Identifier) which is a superset of URL's. But for backward compatinility reasons the name is still PURL.
Type for translation of strings to URL format,.
| enum PURL::UrlFormat |
Print/String output representation formats.
| PURL::PURL | ( | ) |
Construct a new URL object from the URL string.
| PURL::PURL | ( | const char * | cstr, |
| const char * | defaultScheme = "http" |
||
| ) |
Construct a new URL object from the URL string.
| cstr | C string representation of the URL. |
| defaultScheme | Default scheme for URL |
| PURL::PURL | ( | const PString & | str, |
| const char * | defaultScheme = "http" |
||
| ) |
Construct a new URL object from the URL string.
| str | String representation of the URL. |
| defaultScheme | Default scheme for URL |
| PURL::PURL | ( | const PFilePath & | path | ) |
Construct a new URL object from the file path.
| path | File path to turn into a "file:" URL. |
| PURL::PURL | ( | const PURL & | other | ) |
| void PURL::AppendPath | ( | const PString & | segment | ) |
Append segment to the path field of the URL.
| PFilePath PURL::AsFilePath | ( | ) | const |
Get the "file:" URL as a file path.
If the URL is not a "file:" URL then returns an empty string.
Convert the URL object into its string representation.
The parameter indicates whether a full or partial representation os to be produced.
| fmt | The type of string to be returned. |
Referenced by PHTTPResource::GetHotLink(), OpenBrowser(), and operator PString().
| void PURL::ChangePath | ( | const PString & | segment, |
| PINDEX | idx = P_MAX_INDEX |
||
| ) |
Change segment in the path field of the URL.
| segment | New value for segment, empty means remove |
| idx | Segment index, P_MAX_INDEX means last segment |
|
virtual |
Compare the two URLs and return their relative rank.
LessThan, EqualTo or GreaterThan according to the relative rank of the objects. | obj | Object to compare against. |
Reimplemented from PObject.
|
protected |
|
static |
Extract scheme as per RFC2396.
|
inline |
Get the contents of URL, data left after all elemetns are parsed out.
References m_contents.
|
inline |
Get the fragment (#) field of the URL.
References m_fragment.
|
inline |
Get the hostname field of the URL.
References m_hostname.
| PString PURL::GetHostPort | ( | ) | const |
Get the hostname and optional port fields of the URL.
| PString PURL::GetParameters | ( | ) | const |
Get the parameter (;) field of the URL.
|
inline |
Get the parameter (;) field(s) of the URL as a string dictionary.
Note the values have already been translated using UntranslateString
References m_paramVars.
|
inline |
Get the password field of the URL.
References m_password.
|
inline |
Get the path field of the URL as a string array.
References m_path.
| PString PURL::GetPathStr | ( | ) | const |
Get the path field of the URL as a string.
|
inline |
Get the port field of the URL.
References m_port.
|
inline |
Get if explicit port is specified.
References m_portSupplied.
| PString PURL::GetQuery | ( | ) | const |
Get the Query (?) field of the URL as a string.
|
inline |
Get the Query (?) field of the URL as a string dictionary.
Note the values have already been translated using UntranslateString
References m_queryVars.
|
inline |
Get if path is relative or absolute.
References m_relativePath.
|
inline |
Get the scheme field of the URL.
References m_scheme.
|
inline |
Get the username field of the URL.
References m_username.
|
virtual |
This function yields a hash value required by the PDictionary class.
A descendent class that is required to be the key of a dictionary should override this function. The precise values returned is dependent on the semantics of the class. For example, the PString class overrides it to provide a hash function for distinguishing text strings.
The default behaviour is to return the value zero.
Reimplemented from PObject.
|
protectedvirtual |
| cstr | URL as a string to parse. |
| defaultScheme | Default scheme for URL |
Referenced by Parse().
|
inline |
Return true if the URL is an empty string.
References PString::IsEmpty(), and m_urlString.
| PString PURL::LegacyAsString | ( | PURL::UrlFormat | fmt, |
| const PURLLegacyScheme * | schemeInfo | ||
| ) | const |
Referenced by PURLLegacyScheme::AsString().
| bool PURL::LegacyParse | ( | const char * | str, |
| const PURLLegacyScheme * | schemeInfo | ||
| ) |
Referenced by PURLLegacyScheme::Parse().
| bool PURL::LoadResource | ( | PString & | data, |
| const LoadParams & | params = LoadParams() |
||
| ) | const |
Get the resource the URL is pointing at.
The data returned is obtained according to the scheme and the factory PURLLoaderFactory.
| data | Resource data as a string |
| params | Parameters for load |
Referenced by LoadResource().
| bool PURL::LoadResource | ( | PBYTEArray & | data, |
| const LoadParams & | params = LoadParams() |
||
| ) | const |
| data | Resource data as a binary blob |
| params | Parameters for load |
|
inline |
| data | Resource data as a string |
| requiredContentType | Expected content type where applicable |
| timeout | Timeout to wait for resource |
References LoadResource().
|
inline |
Open the URL in a browser.
References AsString(), and OpenBrowser().
Referenced by OpenBrowser().
|
static |
| url | URL to open |
|
inline |
References AsString().
|
static |
Construct string from a dictionary using separators.
| strm | Stream to output dictionary to |
| vars | Dictionary of variable names and values. |
| sep0 | First separater before all ('\0' means none) |
| sep1 | Separater between pairs |
| sep2 | Separater between key and value |
| type | Type of translation. |
|
inline |
Parse the URL string into the fields in the object instance.
| cstr | URL as a string to parse. |
| defaultScheme | Default scheme for URL |
References InternalParse().
Parse the URL string into the fields in the object instance.
| str | URL as a string to parse. |
| defaultScheme | Default scheme for URL |
References InternalParse().
|
virtual |
Output the contents of the URL to the stream as a string.
| strm | Stream to print the object into. |
|
virtual |
Input the contents of the URL from the stream.
The input is a URL in string form.
| strm | Stream to read the objects contents from. |
|
protected |
| void PURL::SetContents | ( | const PString & | str | ) |
Set the contents of URL, data left after all elemetns are parsed out.
| void PURL::SetHostName | ( | const PString & | hostname | ) |
Set the hostname field of the URL.
| void PURL::SetParameters | ( | const PString & | parameters | ) |
Set the parameter (;) field of the URL.
Set the parameter (;) field of the URL as a string dictionary.
Note the values will be translated using TranslateString
| key | Key to add/delete |
| data | Vlaue to add at key, if empty string may be removed |
| emptyDataDeletes | If true, and data empty string, key is removed |
| void PURL::SetParamVars | ( | const PStringToString & | paramVars, |
| bool | merge = false |
||
| ) |
Set the parameter (;) field(s) of the URL as a string dictionary.
Note the values will be translated using TranslateString
| void PURL::SetPassword | ( | const PString & | password | ) |
Set the password field of the URL.
| void PURL::SetPath | ( | const PStringArray & | path | ) |
Set the path field of the URL as a string array.
| void PURL::SetPathStr | ( | const PString & | pathStr | ) |
Set the path field of the URL as a string.
| void PURL::SetPort | ( | WORD | newPort | ) |
Set the port field in the URL. Zero resets to default.
| void PURL::SetQuery | ( | const PString & | query | ) |
Set the Query (?) field of the URL as a string.
Note the values will be translated using UntranslateString
Set the Query (?) field of the URL as a string dictionary.
Note the values will be translated using TranslateString
| void PURL::SetQueryVars | ( | const PStringToString & | queryVars | ) |
Set the Query (?) field(s) of the URL as a string dictionary.
Note the values will be translated using TranslateString
| bool PURL::SetScheme | ( | const PString & | scheme | ) |
Set the scheme field of the URL.
| void PURL::SetUserName | ( | const PString & | username | ) |
Set the username field of the URL.
|
inlinestatic |
Split a string in &= form to a dictionary of names and values.
| queryStr | String to split into variables. |
| queryVars | Dictionary of variable names and values. |
References QueryTranslation, and SplitVars().
|
static |
Split a string to a dictionary of names and values.
| str | String to split into variables. |
| vars | Dictionary of variable names and values. |
| sep1 | Separater between pairs |
| sep2 | Separater between key and value |
| type | Type of translation. |
Referenced by SplitQueryVars().
|
static |
Translate a string from general form to one that can be included into a URL.
All reserved characters for the particular field type are escaped.
| str | String to be translated. |
| type | Type of translation. |
|
static |
Untranslate a string from a form that was included into a URL into a normal string.
All reserved characters for the particular field type are unescaped.
| str | String to be translated. |
| type | Type of translation. |
|
protected |
Referenced by GetContents().
|
protected |
Referenced by GetFragment().
|
protected |
Referenced by GetHostName().
|
protected |
Referenced by GetParamVars().
|
protected |
Referenced by GetPassword().
|
protected |
Referenced by GetPath().
|
protected |
Referenced by GetPort().
|
protected |
Referenced by GetPortSupplied().
|
protected |
Referenced by GetQueryVars().
|
protected |
port was supplied in string input
Referenced by GetRelativePath().
|
protected |
Referenced by GetScheme().
|
protected |
|
protected |
Referenced by GetUserName().