Panda3D
Public Member Functions | Static Public Member Functions | List of all members
URLSpec Class Reference

A container for a URL, e.g. More...

#include "urlSpec.h"

Public Member Functions

 URLSpec (const string &url, bool server_name_expected=false)
 
 URLSpec (const URLSpec &copy)
 
const char * c_str () const
 
int compare_to (const URLSpec &other) const
 Returns a number less than zero if this URLSpec sorts before the other one, greater than zero if it sorts after, or zero if they are equivalent. More...
 
bool empty () const
 
string get_authority () const
 Returns the authority specified by the URL (this includes username, server, and/or port), or empty string if no authority is specified. More...
 
string get_path () const
 Returns the path specified by the URL, or "/" if no path is specified. More...
 
string get_path_and_query () const
 Returns the path (or "/" if no path is specified), followed by the query if it is specified. More...
 
int get_port () const
 Returns the port number specified by the URL, or the default port if not specified. More...
 
string get_port_str () const
 Returns the port specified by the URL as a string, or the empty string if no port is specified. More...
 
string get_query () const
 Returns the query specified by the URL, or empty string if no query is specified. More...
 
string get_scheme () const
 Returns the scheme specified by the URL, or empty string if no scheme is specified. More...
 
string get_server () const
 Returns the server name specified by the URL, if any. More...
 
string get_server_and_port () const
 Returns a string consisting of the server name, followed by a colon, followed by the port number. More...
 
const string & get_url () const
 Returns the complete URL specification. More...
 
string get_username () const
 Returns the username specified by the URL, if any. More...
 
bool has_authority () const
 Returns true if the URL specifies an authority (this includes username, server, and/or port), false otherwise. More...
 
bool has_path () const
 Returns true if the URL includes a path specification (that is, the particular filename on the server to retrieve), false otherwise. More...
 
bool has_port () const
 Returns true if the URL specifies a port number, false otherwise. More...
 
bool has_query () const
 Returns true if the URL includes a query specification, false otherwise. More...
 
bool has_scheme () const
 Returns true if the URL specifies a scheme (e.g. More...
 
bool has_server () const
 Returns true if the URL specifies a server name, false otherwise. More...
 
bool has_username () const
 Returns true if the URL specifies a username (and/or password), false otherwise. More...
 
bool input (istream &in)
 
bool is_default_port () const
 Returns true if the port number encoded in this URL is the default port number for the scheme (or if there is no port number), or false if it is a nonstandard port. More...
 
bool is_ssl () const
 Returns true if the URL's scheme specifies an SSL-secured protocol such as https, or false otherwise. More...
 
size_t length () const
 
 operator const string & () const
 
bool operator!= (const URLSpec &other) const
 
bool operator< (const URLSpec &other) const
 
void operator= (const string &url)
 
void operator= (const URLSpec &copy)
 
bool operator== (const URLSpec &other) const
 
char operator[] (int n) const
 
void output (ostream &out) const
 
void set_authority (const string &authority)
 Replaces the authority part of the URL specification. More...
 
void set_path (const string &path)
 Replaces the path part of the URL specification. More...
 
void set_port (const string &port)
 Replaces the port part of the URL specification. More...
 
void set_port (int port)
 Replaces the port part of the URL specification, given a numeric port number. More...
 
void set_query (const string &query)
 Replaces the query part of the URL specification. More...
 
void set_scheme (const string &scheme)
 Replaces the scheme part of the URL specification. More...
 
void set_server (const string &server)
 Replaces the server part of the URL specification. More...
 
void set_server_and_port (const string &server_and_port)
 Replaces the server and port parts of the URL specification simultaneously. More...
 
void set_url (const string &url, bool server_name_expected=false)
 Completely replaces the URL with the indicated string. More...
 
void set_username (const string &username)
 Replaces the username part of the URL specification. More...
 

Static Public Member Functions

static int get_default_port_for_scheme (const string &scheme)
 Returns the default port number for the indicated scheme, or 0 if there is no known default. More...
 
static string quote (const string &source, const string &safe="/")
 Returns the source string with all "unsafe" characters quoted, making a string suitable for placing in a URL. More...
 
static string quote_plus (const string &source, const string &safe="/")
 Behaves like quote() with the additional behavior of replacing spaces with plus signs. More...
 
static string unquote (const string &source)
 Reverses the operation of quote(): converts escaped characters of the form "%xx" to their ascii equivalent. More...
 
static string unquote_plus (const string &source)
 Reverses the operation of quote_plus(): converts escaped characters of the form "%xx" to their ascii equivalent, and also converts plus signs to spaces. More...
 

Detailed Description

A container for a URL, e.g.

"http://server:port/path".

The URLSpec object is similar to a Filename in that it contains logic to identify the various parts of a URL and return (or modify) them separately.

Definition at line 29 of file urlSpec.h.

Member Function Documentation

◆ compare_to()

int URLSpec::compare_to ( const URLSpec other) const
inline

Returns a number less than zero if this URLSpec sorts before the other one, greater than zero if it sorts after, or zero if they are equivalent.

Definition at line 84 of file urlSpec.I.

References has_scheme().

◆ get_authority()

string URLSpec::get_authority ( ) const
inline

Returns the authority specified by the URL (this includes username, server, and/or port), or empty string if no authority is specified.

Definition at line 175 of file urlSpec.I.

References get_username().

Referenced by has_query().

◆ get_default_port_for_scheme()

int URLSpec::get_default_port_for_scheme ( const string &  scheme)
static

Returns the default port number for the indicated scheme, or 0 if there is no known default.

Definition at line 114 of file urlSpec.cxx.

References get_server_and_port().

Referenced by get_port(), and is_default_port().

◆ get_path()

string URLSpec::get_path ( ) const

Returns the path specified by the URL, or "/" if no path is specified.

Definition at line 153 of file urlSpec.cxx.

References get_path_and_query(), and has_path().

Referenced by get_server_and_port().

◆ get_path_and_query()

string URLSpec::get_path_and_query ( ) const

Returns the path (or "/" if no path is specified), followed by the query if it is specified.

Definition at line 167 of file urlSpec.cxx.

References get_query(), has_path(), has_query(), and set_scheme().

Referenced by get_path().

◆ get_port()

int URLSpec::get_port ( ) const

Returns the port number specified by the URL, or the default port if not specified.

Definition at line 84 of file urlSpec.cxx.

References get_default_port_for_scheme(), get_scheme(), has_port(), and is_default_port().

Referenced by get_scheme(), get_server_and_port(), and CConnectionRepository::set_tcp_header_size().

◆ get_port_str()

string URLSpec::get_port_str ( ) const
inline

Returns the port specified by the URL as a string, or the empty string if no port is specified.

Compare this with get_port(), which returns a default port number if no port is specified.

Definition at line 211 of file urlSpec.I.

References get_query().

Referenced by get_server(), set_server(), and set_username().

◆ get_query()

string URLSpec::get_query ( ) const
inline

Returns the query specified by the URL, or empty string if no query is specified.

Definition at line 222 of file urlSpec.I.

References is_ssl().

Referenced by get_path_and_query(), and get_port_str().

◆ get_scheme()

string URLSpec::get_scheme ( ) const

Returns the scheme specified by the URL, or empty string if no scheme is specified.

Definition at line 70 of file urlSpec.cxx.

References get_port(), and has_scheme().

Referenced by get_port(), and is_default_port().

◆ get_server()

string URLSpec::get_server ( ) const
inline

Returns the server name specified by the URL, if any.

Definition at line 198 of file urlSpec.I.

References get_port_str().

Referenced by get_server_and_port(), get_username(), set_port(), CConnectionRepository::set_tcp_header_size(), and set_username().

◆ get_server_and_port()

string URLSpec::get_server_and_port ( ) const

Returns a string consisting of the server name, followed by a colon, followed by the port number.

If the port number is not explicitly given in the URL, this string will include the implicit port number.

Definition at line 137 of file urlSpec.cxx.

References get_path(), get_port(), get_server(), and has_port().

Referenced by get_default_port_for_scheme().

◆ get_url()

const string & URLSpec::get_url ( ) const
inline

Returns the complete URL specification.

Definition at line 254 of file urlSpec.I.

Referenced by is_ssl(), and set_url().

◆ get_username()

string URLSpec::get_username ( ) const
inline

Returns the username specified by the URL, if any.

This might also include a password, e.g. "username:password", although putting a password on the URL is probably a bad idea.

Definition at line 188 of file urlSpec.I.

References get_server().

Referenced by get_authority(), set_port(), set_server(), and set_server_and_port().

◆ has_authority()

bool URLSpec::has_authority ( ) const
inline

Returns true if the URL specifies an authority (this includes username, server, and/or port), false otherwise.

Definition at line 107 of file urlSpec.I.

References has_username().

Referenced by has_scheme(), set_authority(), set_port(), set_server(), set_server_and_port(), set_url(), set_username(), and unquote_plus().

◆ has_path()

bool URLSpec::has_path ( ) const
inline

Returns true if the URL includes a path specification (that is, the particular filename on the server to retrieve), false otherwise.

Definition at line 152 of file urlSpec.I.

References has_query().

Referenced by get_path(), get_path_and_query(), has_port(), set_authority(), and set_path().

◆ has_port()

bool URLSpec::has_port ( ) const
inline

Returns true if the URL specifies a port number, false otherwise.

Definition at line 140 of file urlSpec.I.

References has_path().

Referenced by get_port(), get_server_and_port(), has_server(), is_default_port(), set_server(), and set_username().

◆ has_query()

bool URLSpec::has_query ( ) const
inline

Returns true if the URL includes a query specification, false otherwise.

Definition at line 163 of file urlSpec.I.

References get_authority().

Referenced by get_path_and_query(), has_path(), and set_query().

◆ has_scheme()

bool URLSpec::has_scheme ( ) const
inline

Returns true if the URL specifies a scheme (e.g.

"http:"), false otherwise.

Definition at line 95 of file urlSpec.I.

References has_authority().

Referenced by compare_to(), get_scheme(), is_ssl(), set_scheme(), and set_url().

◆ has_server()

bool URLSpec::has_server ( ) const
inline

Returns true if the URL specifies a server name, false otherwise.

Definition at line 129 of file urlSpec.I.

References has_port().

Referenced by has_username().

◆ has_username()

bool URLSpec::has_username ( ) const
inline

Returns true if the URL specifies a username (and/or password), false otherwise.

Definition at line 118 of file urlSpec.I.

References has_server().

Referenced by has_authority(), set_port(), set_server(), and set_server_and_port().

◆ is_default_port()

bool URLSpec::is_default_port ( ) const

Returns true if the port number encoded in this URL is the default port number for the scheme (or if there is no port number), or false if it is a nonstandard port.

Definition at line 100 of file urlSpec.cxx.

References get_default_port_for_scheme(), get_scheme(), and has_port().

Referenced by get_port().

◆ is_ssl()

bool URLSpec::is_ssl ( ) const
inline

Returns true if the URL's scheme specifies an SSL-secured protocol such as https, or false otherwise.

Definition at line 234 of file urlSpec.I.

References get_url(), and has_scheme().

Referenced by get_query().

◆ quote()

string URLSpec::quote ( const string &  source,
const string &  safe = "/" 
)
static

Returns the source string with all "unsafe" characters quoted, making a string suitable for placing in a URL.

Letters, digits, and the underscore, comma, period, and hyphen characters, as well as any included in the safe string, are left alone; all others are converted to hex representation.

Definition at line 656 of file urlSpec.cxx.

References quote_plus().

Referenced by set_url().

◆ quote_plus()

string URLSpec::quote_plus ( const string &  source,
const string &  safe = "/" 
)
static

Behaves like quote() with the additional behavior of replacing spaces with plus signs.

Definition at line 697 of file urlSpec.cxx.

References unquote().

Referenced by quote().

◆ set_authority()

void URLSpec::set_authority ( const string &  authority)

Replaces the authority part of the URL specification.

This includes the username, server, and port.

Definition at line 254 of file urlSpec.cxx.

References has_authority(), has_path(), and set_username().

Referenced by set_port(), set_scheme(), set_server(), set_server_and_port(), and set_username().

◆ set_path()

void URLSpec::set_path ( const string &  path)

Replaces the path part of the URL specification.

Definition at line 416 of file urlSpec.cxx.

References has_path(), and set_query().

Referenced by set_server_and_port().

◆ set_port() [1/2]

void URLSpec::set_port ( const string &  port)

Replaces the port part of the URL specification.

Definition at line 356 of file urlSpec.cxx.

References get_server(), get_username(), has_authority(), has_username(), and set_authority().

Referenced by set_port(), and set_server().

◆ set_port() [2/2]

void URLSpec::set_port ( int  port)

Replaces the port part of the URL specification, given a numeric port number.

Definition at line 382 of file urlSpec.cxx.

References set_port(), and set_server_and_port().

◆ set_query()

void URLSpec::set_query ( const string &  query)

Replaces the query part of the URL specification.

Definition at line 462 of file urlSpec.cxx.

References has_query(), and set_url().

Referenced by set_path().

◆ set_scheme()

void URLSpec::set_scheme ( const string &  scheme)

Replaces the scheme part of the URL specification.

Definition at line 183 of file urlSpec.cxx.

References has_scheme(), and set_authority().

Referenced by get_path_and_query().

◆ set_server()

void URLSpec::set_server ( const string &  server)

Replaces the server part of the URL specification.

Definition at line 332 of file urlSpec.cxx.

References get_port_str(), get_username(), has_authority(), has_port(), has_username(), set_authority(), and set_port().

Referenced by set_username().

◆ set_server_and_port()

void URLSpec::set_server_and_port ( const string &  server_and_port)

Replaces the server and port parts of the URL specification simultaneously.

The input string should be of the form "server:port", or just "server" to make the port number implicit.

Definition at line 397 of file urlSpec.cxx.

References get_username(), has_authority(), has_username(), set_authority(), and set_path().

Referenced by set_port().

◆ set_url()

void URLSpec::set_url ( const string &  url,
bool  server_name_expected = false 
)

Completely replaces the URL with the indicated string.

If server_name_expected is true, it is a hint that an undecorated URL is probably a server name, not a local filename.

Definition at line 493 of file urlSpec.cxx.

References get_url(), has_authority(), has_scheme(), and quote().

Referenced by set_query().

◆ set_username()

void URLSpec::set_username ( const string &  username)

Replaces the username part of the URL specification.

Definition at line 308 of file urlSpec.cxx.

References get_port_str(), get_server(), has_authority(), has_port(), set_authority(), and set_server().

Referenced by set_authority().

◆ unquote()

string URLSpec::unquote ( const string &  source)
static

Reverses the operation of quote(): converts escaped characters of the form "%xx" to their ascii equivalent.

Definition at line 743 of file urlSpec.cxx.

References unquote_plus().

Referenced by quote_plus().

◆ unquote_plus()

string URLSpec::unquote_plus ( const string &  source)
static

Reverses the operation of quote_plus(): converts escaped characters of the form "%xx" to their ascii equivalent, and also converts plus signs to spaces.

Definition at line 781 of file urlSpec.cxx.

References has_authority().

Referenced by unquote().


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