Represents and manipulates an URL (Uniform Resource Locator). More...
Inherits BArchivable.
Public Member Functions | |
virtual status_t | Archive (BMessage *into, bool deep=true) const |
Archive the object into a BMessage. | |
bool | HasPreferredApplication () const |
Undocumented public method. | |
status_t | IDNAToAscii () |
Undocumented public method. | |
status_t | IDNAToUnicode () |
Undocumented public method. | |
status_t | OpenWithPreferredApplication (bool onProblemAskUser=true) const |
Undocumented public method. | |
operator const char * () const | |
Undocumented public method. | |
bool | operator!= (BUrl &other) const |
Undocumented public method. | |
const BUrl & | operator= (const BString &string) |
Undocumented public method. | |
const BUrl & | operator= (const BUrl &other) |
Undocumented public method. | |
const BUrl & | operator= (const char *string) |
Undocumented public method. | |
bool | operator== (BUrl &other) const |
Undocumented public method. | |
BString | PreferredApplication () const |
Undocumented public method. | |
void | UrlDecode (bool strict=false) |
Undocumented public method. | |
void | UrlEncode (bool strict=false) |
Undocumented public method. | |
BUrl (const char *url) | |
Constructs a BUrl and fills it. | |
BUrl (BMessage *archive) | |
Restore an URL from archived data. | |
BUrl (const BUrl &other) | |
Copy constructor. | |
BUrl (const BUrl &base, const BString &relative) | |
Construct a BUrl using a known base and a string representing a relative URL. | |
BUrl (const BPath &path) | |
Constructs a BUrl identifying a local file. | |
BUrl () | |
Constructs an empty BUrl. | |
virtual | ~BUrl () |
Destructor for BUrl. | |
BUrl & | SetUrlString (const BString &url) |
Parse a string and set the URL accordingly. | |
BUrl & | SetProtocol (const BString &scheme) |
Set the protocol. | |
BUrl & | SetUserName (const BString &user) |
Set the username in the authority component. | |
BUrl & | SetPassword (const BString &password) |
Set the password in the authority component. | |
void | SetAuthority (const BString &authority) |
Replace the complete authority component. | |
BUrl & | SetHost (const BString &host) |
Sets the host part of the authority component. | |
BUrl & | SetPort (int port) |
Set the port of the authority component. | |
BUrl & | SetPath (const BString &path) |
Set the path of the URL. | |
BUrl & | SetRequest (const BString &request) |
Set the request part of the URL. | |
BUrl & | SetFragment (const BString &fragment) |
Set the fragment part of the URL. | |
const BString & | UrlString () const |
Returns the string representation of the URL. | |
const BString & | Protocol () const |
Returns the protocol used in the url. | |
const BString & | UserName () const |
Returns the username. | |
const BString & | Password () const |
Returns the password. | |
const BString & | UserInfo () const |
Returns the user information (username:password) | |
const BString & | Host () const |
Returns the URL host component. | |
int | Port () const |
Returns the URL port number. | |
const BString & | Authority () const |
Returns the authority url as a string. | |
const BString & | Path () const |
Returns the url path. | |
const BString & | Request () const |
Returns the url-request. | |
const BString & | Fragment () const |
Returns the fragment of the url. | |
bool | IsValid () const |
Check if the URL is valid. | |
bool | HasProtocol () const |
Check wether the URL has a protocol. | |
bool | HasUserName () const |
Check wether the URL has an username. | |
bool | HasPassword () const |
Check wether the URL has a password. | |
bool | HasUserInfo () const |
Check wether the URL has user information. | |
bool | HasHost () const |
Check wether the URL has an host. | |
bool | HasPort () const |
Check wether the URL has a port. | |
bool | HasAuthority () const |
Check if the URL has an host or port. | |
bool | HasPath () const |
Check wether the URL has a path. | |
bool | HasRequest () const |
Check wether the URL has a request. | |
bool | HasFragment () const |
Check wether the URL has a fragment. | |
Public Member Functions inherited from BArchivable | |
BArchivable () | |
Constructor. Does nothing. | |
BArchivable (BMessage *from) | |
Constructor. Does important behind-the-scenes work in the unarchiving process. | |
virtual | ~BArchivable () |
Destructor. Does nothing. | |
virtual status_t | AllArchived (BMessage *archive) const |
Method relating to the use of BArchiver . | |
virtual status_t | AllUnarchived (const BMessage *archive) |
Method relating to the use of BUnarchiver . | |
virtual status_t | Archive (BMessage *into, bool deep=true) const |
Archive the object into a BMessage. | |
virtual status_t | Perform (perform_code d, void *arg) |
Perform some action (Internal method defined for binary compatibility purposes). | |
Static Public Member Functions | |
static BArchivable * | Instantiate (BMessage *archive) |
Undocumented public method. | |
static BString | UrlDecode (const BString &url, bool strict=false) |
Undocumented public method. | |
static BString | UrlEncode (const BString &url, bool strict=false, bool directory=false) |
Undocumented public method. | |
Static Public Member Functions inherited from BArchivable | |
static BArchivable * | Instantiate (BMessage *archive) |
Static member to restore objects from messages. | |
Represents and manipulates an URL (Uniform Resource Locator).
An "Uniform Resource Locator" identifies a place where a resource can be found. It specifies both a location and a mechanism to retrieve the data. For example, http://www.example.com/index.html indicates a protocol (http), a hostname (www.example.com), and a file name (index.html).
Every URL consists of a sequence of up to five components: protocol, authority (consisting of login and password, hostname and port) path, request and fragment.
The format is provided in RFC3986 (URI generic syntax), Appendix B as a regular expression: ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
This regular expression makes it possible to parse any string as an URL (if there are no special characters to spearate the fields, everything will end up in the path compopent). However, some characters are not allowed: space, newlines, tabs, <, > and ". If any of these is present in the URL string, the parsing results in an empty URL.
The protocols (http, https, ftp, irc, etc) identifies which way the resource can be accessed.
Authority consists of userinfo such as username and password, a host subcomponent consisting of IP address or hostname and a port subcomponent.
The path component locates the resource inside the authority's hierarchy, and can have different formats (for example, directory names separated by slashes) depending on the protocol in use.
The request component (preceeded by a question mark) contains a query string of non-hierarchial data.
The fragment contains a fragment identifier providing direction to a secondary resource, usually an identifier for a specific element into the resource such as a paragraph in a text.
BUrl::BUrl | ( | const char * | url | ) |
Constructs a BUrl and fills it.
url | A string to parse and populate the URL fields from. |
Call InitCheck() to verify that the string was succesfully parsed and resulted in a valid URL.
BUrl::BUrl | ( | BMessage * | archive | ) |
Restore an URL from archived data.
archive | An archived BUrl (using BArchive()). |
Usually, archived messages are restored using BArchivable::Unarchive() which will automatically instanciate the correct class.
Construct a BUrl using a known base and a string representing a relative URL.
base | A BUrl object that holds base URL. |
relative | A path relative to the base URL. |
URLs can sometimes be represented in relative form. For example, links in a webpage may refer to only a path, assuming the same protocol and authority are the same as the current page. This constructor applies the required resolution process to construct a complete, standalone URL from such a string.
For example, the following:
BUrl base("http://example.org/path/page.html"); BUrl relative(base, "sudirectory/otherpage.html");
results in:
"http://example.org/path/subdirectory/otherpage.hhtml"
The relative URL can override any of the fields from the original one. The algorithm for resolution is documented in RFC3986 section 5.
BUrl::BUrl | ( | const BPath & | path | ) |
Constructs a BUrl identifying a local file.
path | The path to convert into an URL |
The generated URL uses the file protocol, and its path component is the path given as a parameter.
Archive the object into a BMessage.
You should call this method from your derived implementation as it adds the data needed to instantiate your object to the message.
into | The message you store your object in. |
deep | If true , all children of this object should be archived as well. |
B_OK | The archive operation was successful. |
B_BAD_VALUE | NULL archive message. |
B_ERROR | The archive operation failed. |
Reimplemented from BArchivable.
const BString & BUrl::Authority | ( | ) | const |
Returns the authority url as a string.
The authority is of the form username:password@host:port.
const BString & BUrl::Fragment | ( | ) | const |
Returns the fragment of the url.
bool BUrl::HasAuthority | ( | ) | const |
Check if the URL has an host or port.
bool BUrl::HasFragment | ( | ) | const |
Check wether the URL has a fragment.
bool BUrl::HasHost | ( | ) | const |
Check wether the URL has an host.
bool BUrl::HasPassword | ( | ) | const |
Check wether the URL has a password.
bool BUrl::HasPath | ( | ) | const |
Check wether the URL has a path.
bool BUrl::HasPort | ( | ) | const |
Check wether the URL has a port.
bool BUrl::HasPreferredApplication | ( | ) | const |
Undocumented public method.
<value> | Undocumented |
bool BUrl::HasProtocol | ( | ) | const |
Check wether the URL has a protocol.
bool BUrl::HasRequest | ( | ) | const |
Check wether the URL has a request.
bool BUrl::HasUserInfo | ( | ) | const |
Check wether the URL has user information.
bool BUrl::HasUserName | ( | ) | const |
Check wether the URL has an username.
const BString & BUrl::Host | ( | ) | const |
Returns the URL host component.
status_t BUrl::IDNAToAscii | ( | ) |
Undocumented public method.
<value> | Undocumented |
status_t BUrl::IDNAToUnicode | ( | ) |
Undocumented public method.
<value> | Undocumented |
|
static |
Undocumented public method.
archive | Undocumented |
<value> | Undocumented |
bool BUrl::IsValid | ( | ) | const |
Check if the URL is valid.
This function verifies that the mandatory fields are present and perform some other sanity checks on the URL.
An URL is valid if:
An invalid URL can still be modified using the various setters to turn it into a valid one.
status_t BUrl::OpenWithPreferredApplication | ( | bool | onProblemAskUser = true | ) | const |
Undocumented public method.
onProblemAskUser | Undocumented |
<value> | Undocumented |
BUrl::operator const char * | ( | ) | const |
Undocumented public method.
<value> | Undocumented |
bool BUrl::operator!= | ( | BUrl & | other | ) | const |
Undocumented public method.
other | Undocumented |
<value> | Undocumented |
Undocumented public method.
string | Undocumented |
<value> | Undocumented |
Undocumented public method.
other | Undocumented |
<value> | Undocumented |
const BUrl & BUrl::operator= | ( | const char * | string | ) |
Undocumented public method.
string | Undocumented |
<value> | Undocumented |
bool BUrl::operator== | ( | BUrl & | other | ) | const |
Undocumented public method.
other | Undocumented |
<value> | Undocumented |
const BString & BUrl::Password | ( | ) | const |
Returns the password.
const BString & BUrl::Path | ( | ) | const |
Returns the url path.
int BUrl::Port | ( | ) | const |
Returns the URL port number.
-1 is returned if no port is set.
BString BUrl::PreferredApplication | ( | ) | const |
Undocumented public method.
<value> | Undocumented |
const BString & BUrl::Protocol | ( | ) | const |
Returns the protocol used in the url.
const BString & BUrl::Request | ( | ) | const |
Returns the url-request.
void BUrl::SetAuthority | ( | const BString & | authority | ) |
Replace the complete authority component.
authority | The authority component. |
The username, password, host and port fields are replaced. The authority can be of the form username:password@host:port
Set the fragment part of the URL.
fragment | The fragment to use. |
Sets the host part of the authority component.
host | The hostname or address to use. |
Set the password in the authority component.
password | The password. |
Set the path of the URL.
path | Set the path to use. |
BUrl & BUrl::SetPort | ( | int | port | ) |
Set the port of the authority component.
port | The port number to use (usually a TCP or UDP port). |
Set the protocol.
scheme | The protocol to use. |
Set the request part of the URL.
request | The request string. |
Parse a string and set the URL accordingly.
url | A string to parse as an absolute URL. |
Set the username in the authority component.
user | The username. |
void BUrl::UrlDecode | ( | bool | strict = false | ) |
Undocumented public method.
strict | Undocumented |
Undocumented public method.
url | Undocumented |
strict | Undocumented |
<value> | Undocumented |
void BUrl::UrlEncode | ( | bool | strict = false | ) |
Undocumented public method.
strict | Undocumented |
|
static |
Undocumented public method.
url | Undocumented |
strict | Undocumented |
directory | Undocumented |
<value> | Undocumented |
const BString & BUrl::UrlString | ( | ) | const |
Returns the string representation of the URL.
A complete URL string is of the form protocol://username:passord@host:port/path?request::fragment . All the fields are optional, for example a file URL will have only a protocol and a path.
const BString & BUrl::UserInfo | ( | ) | const |
Returns the user information (username:password)
If there is no password, the username alone is returned. If there is no username, a string of the form ":password" is returned.
const BString & BUrl::UserName | ( | ) | const |
Returns the username.