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

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

#include "urlSpec.h"

Public Member Functions

 URLSpec (const std::string &url, bool server_name_expected=false)
 
 URLSpec (const URLSpec &url, const Filename &path)
 Creates a URLSpec by appending a path to the end of the old URLSpec, inserting an intervening forward slash if necessary. More...
 
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
 Returns false if the URLSpec is valid (not empty), or true if it is an empty string. More...
 
std::string get_authority () const
 
size_t get_hash () const
 
std::string get_path () const
 
std::string get_path_and_query () const
 Returns the path (or "/" if no path is specified), followed by the query if it is specified. More...
 
uint16_t get_port () const
 
std::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...
 
std::string get_query () const
 
std::string get_scheme () const
 
std::string get_server () const
 
std::string get_server_and_port () const
 
const std::string & get_url () const
 Returns the complete URL specification. More...
 
std::string get_username () const
 
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 (std::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
 
size_t length () const
 
bool operator != (const URLSpec &other) const
 
char operator [] (size_t n) const
 
 operator bool () const
 Returns true if the URLSpec is valid (not empty), or false if it is an empty string. More...
 
 operator const std::string & () const
 
bool operator< (const URLSpec &other) const
 
void operator= (const std::string &url)
 
bool operator== (const URLSpec &other) const
 
void output (std::ostream &out) const
 
void set_authority (const std::string &authority)
 
void set_path (const std::string &path)
 
void set_port (const std::string &port)
 
void set_port (uint16_t port)
 
void set_query (const std::string &query)
 
void set_scheme (const std::string &scheme)
 
void set_server (const std::string &server)
 
void set_server_and_port (const std::string &server_and_port)
 
void set_url (const std::string &url, bool server_name_expected=false)
 Completely replaces the URL with the indicated string. More...
 
void set_username (const std::string &username)
 
size_t size () const
 

Static Public Member Functions

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

Public Attributes

 get_authority
 Returns the authority specified by the URL (this includes username, server, and/or port), or empty string if no authority is specified. More...
 
 get_path
 Returns the path specified by the URL, or "/" if no path is specified. More...
 
 get_port
 Returns the port number specified by the URL, or the default port if not specified. More...
 
 get_query
 Returns the query specified by the URL, or empty string if no query is specified. More...
 
 get_scheme
 Returns the scheme specified by the URL, or empty string if no scheme is specified. More...
 
 get_server
 Returns the server name specified by the URL, if any. More...
 
 get_server_and_port
 Returns a string consisting of the server name, followed by a colon, followed by the port number. More...
 
 get_username
 Returns the username specified by the URL, if any. More...
 
 is_ssl
 Returns true if the URL's scheme specifies an SSL-secured protocol such as https, or false otherwise. More...
 
 set_authority
 Replaces the authority part of the URL specification. More...
 
 set_path
 Replaces the path part of the URL specification. More...
 
 set_port
 Replaces the port part of the URL specification. More...
 
 set_query
 Replaces the query part of the URL specification. More...
 
 set_scheme
 Replaces the scheme part of the URL specification. More...
 
 set_server
 Replaces the server part of the URL specification. More...
 
 set_server_and_port
 Replaces the server and port parts of the URL specification simultaneously. More...
 
 set_username
 Replaces the username part of the URL specification. 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 28 of file urlSpec.h.

Constructor & Destructor Documentation

◆ URLSpec()

URLSpec::URLSpec ( const URLSpec url,
const Filename path 
)

Creates a URLSpec by appending a path to the end of the old URLSpec, inserting an intervening forward slash if necessary.

Definition at line 51 of file urlSpec.cxx.

References Filename::get_fullpath(), get_path, and set_path.

Member Function Documentation

◆ compare_to()

int URLSpec::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.

Definition at line 77 of file urlSpec.cxx.

References has_scheme().

◆ empty()

bool URLSpec::empty ( ) const
inline

Returns false if the URLSpec is valid (not empty), or true if it is an empty string.

Definition at line 209 of file urlSpec.I.

◆ get_default_port_for_scheme()

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

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

Definition at line 172 of file urlSpec.cxx.

Referenced by is_default_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 228 of file urlSpec.cxx.

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

◆ get_port_str()

std::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 148 of file urlSpec.I.

◆ get_url()

const std::string & URLSpec::get_url ( ) const
inline

Returns the complete URL specification.

Definition at line 184 of file urlSpec.I.

◆ 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 68 of file urlSpec.I.

Referenced by set_url().

◆ 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 102 of file urlSpec.I.

Referenced by get_path_and_query().

◆ has_port()

bool URLSpec::has_port ( ) const
inline

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

Definition at line 93 of file urlSpec.I.

Referenced by is_default_port().

◆ has_query()

bool URLSpec::has_query ( ) const
inline

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

Definition at line 110 of file urlSpec.I.

Referenced by get_path_and_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 59 of file urlSpec.I.

Referenced by compare_to(), 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 85 of file urlSpec.I.

◆ has_username()

bool URLSpec::has_username ( ) const
inline

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

Definition at line 77 of file urlSpec.I.

◆ 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 160 of file urlSpec.cxx.

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

◆ operator bool()

URLSpec::operator bool ( ) const
inline

Returns true if the URLSpec is valid (not empty), or false if it is an empty string.

Definition at line 218 of file urlSpec.I.

◆ quote()

string URLSpec::quote ( const std::string &  source,
const std::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 719 of file urlSpec.cxx.

◆ quote_plus()

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

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

Definition at line 758 of file urlSpec.cxx.

◆ set_url()

void URLSpec::set_url ( const std::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 554 of file urlSpec.cxx.

References has_authority(), and has_scheme().

◆ unquote()

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

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

Definition at line 801 of file urlSpec.cxx.

◆ unquote_plus()

string URLSpec::unquote_plus ( const std::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 837 of file urlSpec.cxx.

Member Data Documentation

◆ get_authority

std::string URLSpec::get_authority
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 94 of file urlSpec.h.

◆ get_path

string URLSpec::get_path

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

Definition at line 99 of file urlSpec.h.

Referenced by URLSpec().

◆ get_port

uint16_t URLSpec::get_port

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

Definition at line 97 of file urlSpec.h.

◆ get_query

std::string URLSpec::get_query
inline

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

Definition at line 100 of file urlSpec.h.

Referenced by get_path_and_query().

◆ get_scheme

string URLSpec::get_scheme

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

Definition at line 93 of file urlSpec.h.

Referenced by is_default_port().

◆ get_server

std::string URLSpec::get_server
inline

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

In case of an IPv6 address, does not include the enclosing brackets.

Definition at line 96 of file urlSpec.h.

◆ get_server_and_port

string URLSpec::get_server_and_port

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. If the server is an IPv6 address, it will be enclosed in square brackets.

Definition at line 98 of file urlSpec.h.

◆ get_username

std::string URLSpec::get_username
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 95 of file urlSpec.h.

◆ is_ssl

bool URLSpec::is_ssl
inline

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

Definition at line 101 of file urlSpec.h.

◆ set_authority

void URLSpec::set_authority

Replaces the authority part of the URL specification.

This includes the username, server, and port.

Definition at line 94 of file urlSpec.h.

◆ set_path

void URLSpec::set_path

Replaces the path part of the URL specification.

Definition at line 99 of file urlSpec.h.

Referenced by URLSpec().

◆ set_port

void URLSpec::set_port

Replaces the port part of the URL specification.

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

Definition at line 97 of file urlSpec.h.

◆ set_query

void URLSpec::set_query

Replaces the query part of the URL specification.

Definition at line 100 of file urlSpec.h.

◆ set_scheme

void URLSpec::set_scheme

Replaces the scheme part of the URL specification.

Definition at line 93 of file urlSpec.h.

◆ set_server

void URLSpec::set_server

Replaces the server part of the URL specification.

Unlike set_server_and_port, this method does not require IPv6 addresses to be enclosed in square brackets.

Definition at line 96 of file urlSpec.h.

◆ set_server_and_port

void URLSpec::set_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. Any IPv6 address must be enclosed in square brackets.

Definition at line 98 of file urlSpec.h.

◆ set_username

void URLSpec::set_username

Replaces the username part of the URL specification.

Definition at line 95 of file urlSpec.h.


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