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...

Public Member Functions

 __init__ ()
 
 __init__ (const URLSpec)
 
 __init__ (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...
 
 __init__ (str url, bool server_name_expected)
 
int compareTo (const URLSpec other)
 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...
 
str cStr ()
 
bool empty ()
 Returns false if the URLSpec is valid (not empty), or true if it is an empty string. More...
 
str getAuthority ()
 Returns the authority specified by the URL (this includes username, server, and/or port), or empty string if no authority is specified. More...
 
int getHash ()
 
str getPath ()
 Returns the path specified by the URL, or "/" if no path is specified. More...
 
str getPathAndQuery ()
 Returns the path (or "/" if no path is specified), followed by the query if it is specified. More...
 
uint16_t getPort ()
 Returns the port number specified by the URL, or the default port if not specified. More...
 
str getPortStr ()
 Returns the port specified by the URL as a string, or the empty string if no port is specified. More...
 
str getQuery ()
 Returns the query specified by the URL, or empty string if no query is specified. More...
 
str getScheme ()
 Returns the scheme specified by the URL, or empty string if no scheme is specified. More...
 
str getServer ()
 Returns the server name specified by the URL, if any. More...
 
str getServerAndPort ()
 Returns a string consisting of the server name, followed by a colon, followed by the port number. More...
 
str getUrl ()
 Returns the complete URL specification. More...
 
str getUsername ()
 Returns the username specified by the URL, if any. More...
 
bool hasAuthority ()
 Returns true if the URL specifies an authority (this includes username, server, and/or port), false otherwise. More...
 
bool hasPath ()
 Returns true if the URL includes a path specification (that is, the particular filename on the server to retrieve), false otherwise. More...
 
bool hasPort ()
 Returns true if the URL specifies a port number, false otherwise. More...
 
bool hasQuery ()
 Returns true if the URL includes a query specification, false otherwise. More...
 
bool hasScheme ()
 Returns true if the URL specifies a scheme (e.g. More...
 
bool hasServer ()
 Returns true if the URL specifies a server name, false otherwise. More...
 
bool hasUsername ()
 Returns true if the URL specifies a username (and/or password), false otherwise. More...
 
bool input (Istream in)
 
bool isDefaultPort ()
 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 isSsl ()
 Returns true if the URL's scheme specifies an SSL-secured protocol such as https, or false otherwise. More...
 
int length ()
 
bool operator != (const URLSpec other)
 
char operator [] (int n)
 
bool operator< (const URLSpec other)
 
URLSpec operator= (str url)
 
bool operator== (const URLSpec other)
 
 output (Ostream out)
 
 setAuthority (str authority)
 Replaces the authority part of the URL specification. More...
 
 setPath (str path)
 Replaces the path part of the URL specification. More...
 
 setPort (str port)
 Replaces the port part of the URL specification. More...
 
 setPort (uint16_t port)
 Replaces the port part of the URL specification, given a numeric port number. More...
 
 setQuery (str query)
 Replaces the query part of the URL specification. More...
 
 setScheme (str scheme)
 Replaces the scheme part of the URL specification. More...
 
 setServer (str server)
 Replaces the server part of the URL specification. More...
 
 setServerAndPort (str server_and_port)
 Replaces the server and port parts of the URL specification simultaneously. More...
 
 setUrl (str url, bool server_name_expected)
 Completely replaces the URL with the indicated string. More...
 
 setUsername (str username)
 Replaces the username part of the URL specification. More...
 
int size ()
 

Static Public Member Functions

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

String authority
 Returns the authority specified by the URL (this includes username, server, and/or port), or empty string if no authority is specified. More...
 
String path
 Returns the path specified by the URL, or "/" if no path is specified. More...
 
uint16_t port
 Returns the port number specified by the URL, or the default port if not specified. More...
 
String query
 Returns the query specified by the URL, or empty string if no query is specified. More...
 
String scheme
 Returns the scheme specified by the URL, or empty string if no scheme is specified. More...
 
String server
 Returns the server name specified by the URL, if any. More...
 
String server_and_port
 Returns a string consisting of the server name, followed by a colon, followed by the port number. More...
 
bool ssl
 Returns true if the URL's scheme specifies an SSL-secured protocol such as https, or false otherwise. More...
 
String username
 Returns the username specified by the URL, if any. 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.

Member Function Documentation

◆ __init__() [1/4]

__init__ ( )

◆ __init__() [2/4]

__init__ ( const  URLSpec)

◆ __init__() [3/4]

__init__ ( 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.

◆ __init__() [4/4]

__init__ ( str  url,
bool  server_name_expected 
)

◆ compareTo()

int compareTo ( const URLSpec  other)

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.

◆ cStr()

str cStr ( )

◆ empty()

bool empty ( )

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

◆ getAuthority()

str getAuthority ( )

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

◆ getDefaultPortForScheme()

static int getDefaultPortForScheme ( str  scheme)
static

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

◆ getHash()

int getHash ( )

◆ getPath()

str getPath ( )

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

◆ getPathAndQuery()

str getPathAndQuery ( )

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

◆ getPort()

uint16_t getPort ( )

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

◆ getPortStr()

str getPortStr ( )

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.

◆ getQuery()

str getQuery ( )

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

◆ getScheme()

str getScheme ( )

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

◆ getServer()

str getServer ( )

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

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

◆ getServerAndPort()

str getServerAndPort ( )

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.

◆ getUrl()

str getUrl ( )

Returns the complete URL specification.

◆ getUsername()

str getUsername ( )

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.

◆ hasAuthority()

bool hasAuthority ( )

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

◆ hasPath()

bool hasPath ( )

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

◆ hasPort()

bool hasPort ( )

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

◆ hasQuery()

bool hasQuery ( )

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

◆ hasScheme()

bool hasScheme ( )

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

"http:"), false otherwise.

◆ hasServer()

bool hasServer ( )

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

◆ hasUsername()

bool hasUsername ( )

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

◆ input()

bool input ( Istream  in)

◆ isDefaultPort()

bool isDefaultPort ( )

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.

◆ isSsl()

bool isSsl ( )

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

◆ length()

int length ( )

◆ operator !=()

bool operator != ( const URLSpec  other)

◆ operator []()

char operator [] ( int  n)

◆ operator<()

bool operator< ( const URLSpec  other)

◆ operator=()

URLSpec operator= ( str  url)

◆ operator==()

bool operator== ( const URLSpec  other)

◆ output()

output ( Ostream  out)

◆ quote()

static str quote ( str  source,
str  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.

◆ quotePlus()

static str quotePlus ( str  source,
str  safe 
)
static

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

◆ setAuthority()

setAuthority ( str  authority)

Replaces the authority part of the URL specification.

This includes the username, server, and port.

◆ setPath()

setPath ( str  path)

Replaces the path part of the URL specification.

◆ setPort() [1/2]

setPort ( str  port)

Replaces the port part of the URL specification.

◆ setPort() [2/2]

setPort ( uint16_t  port)

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

◆ setQuery()

setQuery ( str  query)

Replaces the query part of the URL specification.

◆ setScheme()

setScheme ( str  scheme)

Replaces the scheme part of the URL specification.

◆ setServer()

setServer ( str  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.

◆ setServerAndPort()

setServerAndPort ( str  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.

◆ setUrl()

setUrl ( str  url,
bool  server_name_expected 
)

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.

◆ setUsername()

setUsername ( str  username)

Replaces the username part of the URL specification.

◆ size()

int size ( )

◆ unquote()

static str unquote ( str  source)
static

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

◆ unquotePlus()

static str unquotePlus ( str  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.

Member Data Documentation

◆ authority

String authority

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

◆ path

String path

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

◆ port

uint16_t port

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

◆ query

String query

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

◆ scheme

String scheme

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

◆ server

String server

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

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

◆ server_and_port

String 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.

◆ ssl

bool ssl

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

◆ username

String username

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.