Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

URLSpec Class Reference

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

#include <urlSpec.h>

List of all members.

Public Member Functions

 URLSpec ()
 URLSpec (const string &url, bool server_name_expected=false)
 URLSpec (const URLSpec &copy)
void operator= (const string &url)
void operator= (const URLSpec &copy)
bool operator== (const URLSpec &other) const
bool operator!= (const URLSpec &other) const
bool operator< (const URLSpec &other) 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.

bool has_scheme () const
 Returns true if the URL specifies a scheme (e.g.

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

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

bool has_server () const
 Returns true if the URL specifies a server name, false otherwise.

bool has_port () const
 Returns true if the URL specifies a port number, false otherwise.

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.

bool has_query () const
 Returns true if the URL includes a query specification, false otherwise.

string get_scheme () const
 Returns the scheme specified by the URL, or empty string if no scheme is specified.

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.

string get_username () const
 Returns the username specified by the URL, if any.

string get_server () const
 Returns the server name specified by the URL, if any.

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

int get_port () const
 Returns the port number specified by the URL, or the default port if not specified.

string get_server_and_port () const
 Returns a string consisting of the server name, followed by a colon, followed by the port number.

string get_path () const
 Returns the path specified by the URL, or "/" if no path is specified.

string get_query () const
 Returns the query specified by the URL, or empty string if no query is specified.

const string & get_url () const
 Returns the complete URL specification.

void set_scheme (const string &scheme)
 Replaces the scheme part of the URL specification.

void set_authority (const string &authority)
 Replaces the authority part of the URL specification.

void set_username (const string &username)
 Replaces the username part of the URL specification.

void set_server (const string &server)
 Replaces the server part of the URL specification.

void set_port (const string &port)
 Replaces the port part of the URL specification.

void set_port (int port)
 Replaces the port part of the URL specification, given a numeric port number.

void set_server_and_port (const string &server_and_port)
 Replaces the server and port parts of the URL specification simultaneously.

void set_path (const string &path)
 Replaces the path part of the URL specification.

void set_query (const string &query)
 Replaces the query part of the URL specification.

void set_url (const string &url, bool server_name_expected=false)
 Completely replaces the URL with the indicated string.

 operator const string & () const
const char * c_str () const
bool empty () const
size_t length () const
char operator[] (int n) const
bool input (istream &in)
void output (ostream &out) const

Static Public Member Functions

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.

string quote_plus (const string &source, const string &safe="/")
 Behaves like quote() with the additional behavior of replacing spaces with plus signs.

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

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.


Private Types

enum  Flags {
  F_has_scheme = 0x0001, F_has_authority = 0x0002, F_has_username = 0x0004, F_has_server = 0x0008,
  F_has_port = 0x0010, F_has_path = 0x0020, F_has_query = 0x0040
}

Private Member Functions

void parse_authority ()
 Assumes _url[_username_start ..


Private Attributes

string _url
int _port
int _flags
size_t _scheme_end
size_t _username_start
size_t _username_end
size_t _server_start
size_t _server_end
size_t _port_start
size_t _port_end
size_t _path_start
size_t _path_end
size_t _query_start


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 43 of file urlSpec.h.


Member Enumeration Documentation

enum URLSpec::Flags [private]
 

Enumeration values:
F_has_scheme 
F_has_authority 
F_has_username 
F_has_server 
F_has_port 
F_has_path 
F_has_query 

Definition at line 105 of file urlSpec.h.


Constructor & Destructor Documentation

URLSpec::URLSpec  ) 
 

Definition at line 35 of file urlSpec.cxx.

URLSpec::URLSpec const string &  url,
bool  server_name_expected = false
[inline]
 

Definition at line 31 of file urlSpec.I.

References INLINE.

URLSpec::URLSpec const URLSpec &  copy  )  [inline]
 

Definition at line 43 of file urlSpec.I.

References INLINE, set_url(), and url.


Member Function Documentation

const char * URLSpec::c_str  )  const [inline]
 

Definition at line 337 of file urlSpec.I.

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

References _flags, F_has_authority, and INLINE.

bool URLSpec::empty  )  const [inline]
 

Definition at line 349 of file urlSpec.I.

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

References _url, and INLINE.

string URLSpec::get_path  )  const
 

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

Definition at line 151 of file urlSpec.cxx.

int URLSpec::get_port  )  const
 

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

Definition at line 103 of file urlSpec.cxx.

References _port_end, _server_start, _url, get_server(), has_port(), and ostringstream::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 285 of file urlSpec.I.

References _url, INLINE, and nassertr.

string URLSpec::get_query  )  const [inline]
 

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

Definition at line 300 of file urlSpec.I.

References url.

string URLSpec::get_scheme  )  const
 

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

Definition at line 85 of file urlSpec.cxx.

References _port, and has_port().

string URLSpec::get_server  )  const [inline]
 

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

Definition at line 266 of file urlSpec.I.

References _url.

Referenced by get_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 131 of file urlSpec.cxx.

const string & URLSpec::get_url  )  const [inline]
 

Returns the complete URL specification.

Definition at line 313 of file urlSpec.I.

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

References _url, and INLINE.

Referenced by set_port().

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

References _flags, F_has_port, and INLINE.

Referenced by set_port().

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

References _server_end, _server_start, and _url.

bool URLSpec::has_port  )  const [inline]
 

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

Definition at line 185 of file urlSpec.I.

References _url, _username_end, _username_start, and INLINE.

Referenced by get_port(), and get_scheme().

bool URLSpec::has_query  )  const [inline]
 

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

Definition at line 217 of file urlSpec.I.

bool URLSpec::has_scheme  )  const [inline]
 

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

"http:"), false otherwise.

Definition at line 123 of file urlSpec.I.

References _flags, and F_has_username.

bool URLSpec::has_server  )  const [inline]
 

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

Definition at line 170 of file urlSpec.I.

References _port_end, _url, _username_start, and INLINE.

bool URLSpec::has_username  )  const [inline]
 

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

Definition at line 155 of file urlSpec.I.

References _flags, F_has_path, and INLINE.

Referenced by set_port().

bool URLSpec::input istream &  in  ) 
 

Definition at line 633 of file urlSpec.cxx.

size_t URLSpec::length  )  const [inline]
 

Definition at line 361 of file urlSpec.I.

URLSpec::operator const string &  )  const [inline]
 

Definition at line 325 of file urlSpec.I.

bool URLSpec::operator!= const URLSpec &  other  )  const [inline]
 

Definition at line 79 of file urlSpec.I.

References _url, and INLINE.

bool URLSpec::operator< const URLSpec &  other  )  const [inline]
 

Definition at line 91 of file urlSpec.I.

References _flags, F_has_scheme, and INLINE.

void URLSpec::operator= const URLSpec &  copy  ) 
 

Definition at line 58 of file urlSpec.cxx.

References _path_end, _path_start, _port_end, _port_start, _query_start, _server_end, and _server_start.

void URLSpec::operator= const string &  url  )  [inline]
 

Definition at line 55 of file urlSpec.I.

References _url, and INLINE.

bool URLSpec::operator== const URLSpec &  other  )  const [inline]
 

Definition at line 67 of file urlSpec.I.

char URLSpec::operator[] int  n  )  const [inline]
 

Definition at line 373 of file urlSpec.I.

void URLSpec::output ostream &  out  )  const
 

Definition at line 652 of file urlSpec.cxx.

void URLSpec::parse_authority  )  [private]
 

Assumes _url[_username_start ..

_port_end - 1] is the authority component if the URL, consisting of [username@]server[:port]. Parses out the three pieces and updates the various _start and _end parameters accordingly.

Definition at line 867 of file urlSpec.cxx.

Referenced by set_url().

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

References size_t.

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

References size_t.

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

Referenced by set_port().

void URLSpec::set_path const string &  path  ) 
 

Replaces the path part of the URL specification.

Definition at line 426 of file urlSpec.cxx.

References _flags, and F_has_query.

void URLSpec::set_port int  port  ) 
 

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

Definition at line 383 of file urlSpec.cxx.

void URLSpec::set_port const string &  port  ) 
 

Replaces the port part of the URL specification.

Definition at line 353 of file urlSpec.cxx.

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

void URLSpec::set_query const string &  query  ) 
 

Replaces the query part of the URL specification.

Definition at line 475 of file urlSpec.cxx.

References _flags, _scheme_end, _url, F_has_scheme, and size_t.

void URLSpec::set_scheme const string &  scheme  ) 
 

Replaces the scheme part of the URL specification.

Definition at line 167 of file urlSpec.cxx.

void URLSpec::set_server const string &  server  ) 
 

Replaces the server part of the URL specification.

Definition at line 326 of file urlSpec.cxx.

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

References _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 512 of file urlSpec.cxx.

References _flags, _port_end, _url, _username_start, F_has_authority, and parse_authority().

Referenced by URLSpec().

void URLSpec::set_username const string &  username  ) 
 

Replaces the username part of the URL specification.

Definition at line 299 of file urlSpec.cxx.

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

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

References _path_end, _path_start, _port_start, _query_start, and _server_end.


Member Data Documentation

int URLSpec::_flags [private]
 

Definition at line 117 of file urlSpec.h.

Referenced by compare_to(), has_authority(), has_scheme(), has_username(), operator<(), set_path(), set_query(), and set_url().

size_t URLSpec::_path_end [private]
 

Definition at line 127 of file urlSpec.h.

Referenced by operator=(), and unquote_plus().

size_t URLSpec::_path_start [private]
 

Definition at line 126 of file urlSpec.h.

Referenced by operator=(), and unquote_plus().

int URLSpec::_port [private]
 

Definition at line 116 of file urlSpec.h.

Referenced by get_scheme().

size_t URLSpec::_port_end [private]
 

Definition at line 125 of file urlSpec.h.

Referenced by get_port(), has_server(), operator=(), and set_url().

size_t URLSpec::_port_start [private]
 

Definition at line 124 of file urlSpec.h.

Referenced by operator=(), and unquote_plus().

size_t URLSpec::_query_start [private]
 

Definition at line 128 of file urlSpec.h.

Referenced by operator=(), and unquote_plus().

size_t URLSpec::_scheme_end [private]
 

Definition at line 119 of file urlSpec.h.

Referenced by set_query().

size_t URLSpec::_server_end [private]
 

Definition at line 123 of file urlSpec.h.

Referenced by has_path(), operator=(), and unquote_plus().

size_t URLSpec::_server_start [private]
 

Definition at line 122 of file urlSpec.h.

Referenced by get_port(), has_path(), and operator=().

string URLSpec::_url [private]
 

Definition at line 115 of file urlSpec.h.

Referenced by get_authority(), get_port(), get_port_str(), get_server(), get_username(), has_path(), has_port(), has_server(), operator!=(), operator=(), set_query(), set_server_and_port(), and set_url().

size_t URLSpec::_username_end [private]
 

Definition at line 121 of file urlSpec.h.

Referenced by has_port().

size_t URLSpec::_username_start [private]
 

Definition at line 120 of file urlSpec.h.

Referenced by has_port(), has_server(), and set_url().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:56:03 2003 for Panda by doxygen1.3