#include <ACEXML/common/URL_Addr.h>
Inheritance diagram for ACEXML_URL_Addr:
Public Member Functions | |
ACEXML_URL_Addr (void) | |
Initialization and termination methods. | |
ACEXML_URL_Addr (const ACEXML_Char *host_name, const ACEXML_Char *path_name, unsigned short port=ACE_DEFAULT_HTTP_PORT) | |
Constructor. | |
ACEXML_URL_Addr (const ACEXML_URL_Addr &addr) | |
Copy constructor. | |
int | set (const ACEXML_URL_Addr &addr) |
Essentially the copy constructor. | |
virtual int | string_to_addr (const ACEXML_Char *address, int address_family=AF_UNSPEC) |
virtual int | addr_to_string (ACEXML_Char *s, size_t size, int ipaddr_format=1) const |
virtual const ACEXML_Char * | addr_to_string (int ipaddr_format=1) |
void | operator= (const ACEXML_URL_Addr &addr) |
Assignment operator. | |
~ACEXML_URL_Addr (void) | |
Destructor. | |
bool | operator== (const ACEXML_URL_Addr &SAP) const |
bool | operator!= (const ACEXML_URL_Addr &SAP) const |
Compare two addresses for inequality. | |
virtual u_long | hash (void) const |
Computes and returns hash value. | |
const ACEXML_Char * | get_path_name (void) const |
Return the path name. | |
int | destroy (void) |
Commit suicide. | |
Private Member Functions | |
size_t | calculate_length (int ipaddr_format) const |
Calculate the maximum length of the address string. | |
Private Attributes | |
ACEXML_Char * | path_name_ |
Our path name. | |
ACEXML_Char * | addr_string_ |
size_t | addr_string_len_ |
Current length of the . |
Definition at line 32 of file URL_Addr.h.
|
Initialization and termination methods.
Definition at line 18 of file URL_Addr.cpp.
00019 : path_name_ (0), 00020 addr_string_ (0), 00021 addr_string_len_ (0) 00022 { 00023 } |
|
Constructor.
Definition at line 163 of file URL_Addr.cpp. References ACEXML_Char.
00166 : ACE_INET_Addr (port, host_name), 00167 path_name_ (ACE_OS::strdup (path_name)), 00168 addr_string_ (0), 00169 addr_string_len_ (0) 00170 { 00171 } |
|
Copy constructor.
Definition at line 129 of file URL_Addr.cpp. References ACE_ERROR, ACE_TEXT, LM_ERROR, and set().
00130 : ACE_INET_Addr (), 00131 path_name_ (0), 00132 addr_string_ (0), 00133 addr_string_len_ (0) 00134 { 00135 if (this->set (addr) == -1) 00136 ACE_ERROR ((LM_ERROR, 00137 ACE_TEXT ("%p\n"), 00138 ACE_TEXT ("ACEXML_URL_Addr::ACEXML_URL_Addr"))); 00139 } |
|
Destructor.
Definition at line 173 of file URL_Addr.cpp. References ACE_OS::free(), and path_name_.
00174 { 00175 ACE_OS::free (this->path_name_); 00176 ACE_OS::free (this->addr_string_); 00177 this->path_name_ = 0; 00178 } |
|
Transform the current address into string format. If is non-0 this produces "ip-number:port-number/path-name" (e.g., "128.252.166.57:80/~schmidt/"), whereas if is 0 this produces "ip-name:port-number" (e.g., "www.cs.wustl.edu:80/~schmidt/"). Uses dynamic memory, which is allocated on demand and deallocated when the object is destroyed. Returns -1 if dynamic memory fails, else 0. Definition at line 46 of file URL_Addr.cpp. References ACE_ALLOCATOR_RETURN, ACE_TEXT, ACE_TEXT_CHAR_TO_TCHAR, ACEXML_Char, addr_string_, addr_string_len_, calculate_length(), ACE_INET_Addr::get_host_addr(), get_path_name(), ACE_INET_Addr::get_port_number(), and ACE_OS::sprintf().
00047 { 00048 size_t size = this->calculate_length (ipaddr_format); 00049 if (size > this->addr_string_len_) 00050 { 00051 ACE_ALLOCATOR_RETURN (this->addr_string_, 00052 (ACEXML_Char *) ACE_OS::realloc(this->addr_string_, 00053 size), 0); 00054 this->addr_string_len_ = size; 00055 } 00056 ACE_OS::sprintf (this->addr_string_, 00057 ACE_TEXT ("%s:%d/%s"), 00058 ACE_TEXT_CHAR_TO_TCHAR (ipaddr_format == 0 00059 ? this->get_host_name () 00060 : this->get_host_addr ()), 00061 this->get_port_number (), 00062 this->get_path_name ()); 00063 return this->addr_string_; 00064 } |
|
Transform the current address into string format. If is non-0 this produces "ip-number:port-number/path-name" (e.g., "128.252.166.57:80/~schmidt/"), whereas if is 0 this produces "ip-name:port-number" (e.g., "www.cs.wustl.edu:80/~schmidt/"). Returns -1 if the of the is too small, else 0. Definition at line 26 of file URL_Addr.cpp. References ACE_TEXT, ACE_TEXT_CHAR_TO_TCHAR, ACEXML_Char, calculate_length(), ACE_INET_Addr::get_host_addr(), get_path_name(), ACE_INET_Addr::get_port_number(), and ACE_OS::sprintf().
00029 { 00030 size_t total_len = this->calculate_length (ipaddr_format); 00031 if (size < total_len) 00032 return -1; 00033 else 00034 { 00035 ACE_OS::sprintf (s, ACE_TEXT ("%s:%d/%s"), 00036 ACE_TEXT_CHAR_TO_TCHAR (ipaddr_format == 0 00037 ? this->get_host_name () 00038 : this->get_host_addr ()), 00039 this->get_port_number (), 00040 this->get_path_name ()); 00041 return 0; 00042 } 00043 } |
|
Calculate the maximum length of the address string.
Definition at line 11 of file URL_Addr.inl. References ACE_INET_Addr::get_host_addr(), and ACE_OS::strlen(). Referenced by addr_to_string().
00012 { 00013 return ACE_OS::strlen (ipaddr_format == 0 ? 00014 this->get_host_name () : this->get_host_addr ()) 00015 + ACE_OS::strlen ("65536") // Assume the max port number. 00016 + ACE_OS::strlen (this->get_path_name ()) 00017 + sizeof (':') 00018 + sizeof ('/') 00019 + sizeof ('\0'); // For trailing '\0'. 00020 } |
|
Commit suicide.
Definition at line 60 of file URL_Addr.inl.
00061 { 00062 // Commit suicide. 00063 delete this; 00064 return 0; 00065 } |
|
Return the path name.
Definition at line 54 of file URL_Addr.inl. References path_name_. Referenced by addr_to_string(), and operator==().
00055 { 00056 return this->path_name_; 00057 } |
|
Computes and returns hash value.
Reimplemented from ACE_INET_Addr. Definition at line 32 of file URL_Addr.inl. References ACE_INET_Addr::hash(), and ACE::hash_pjw().
00033 { 00034 u_long result = this->ACE_INET_Addr::hash () 00035 + ACE::hash_pjw (this->get_path_name ()); 00036 return result; 00037 } |
|
Compare two addresses for inequality.
Definition at line 48 of file URL_Addr.inl.
00049 { 00050 return !(*this == addr); 00051 } |
|
Assignment operator.
Definition at line 23 of file URL_Addr.inl. References ACE_ERROR, ACE_TEXT, LM_ERROR, and set().
|
|
Compare two addresses for equality. The addresses are considered equal if they contain the same IP address, port number, and path name. Definition at line 40 of file URL_Addr.inl. References ACE_INET_Addr::get_ip_address(), get_path_name(), ACE_INET_Addr::get_port_number(), and ACE_OS::strcmp().
00041 { 00042 return ACE_OS::strcmp (addr.get_path_name (), this->get_path_name ()) == 0 00043 && addr.get_port_number () == this->get_port_number () 00044 && addr.get_ip_address () == this->get_ip_address (); 00045 } |
|
Essentially the copy constructor.
Definition at line 142 of file URL_Addr.cpp. References ACE_ALLOCATOR_RETURN, addr_string_, addr_string_len_, ACE_OS::free(), path_name_, and ACE_INET_Addr::set(). Referenced by ACEXML_URL_Addr(), and operator=().
00143 { 00144 ACE_OS::free (this->path_name_); 00145 ACE_OS::free (this->addr_string_); 00146 if (this->ACE_INET_Addr::set (addr) == -1) 00147 return -1; 00148 else 00149 { 00150 if (addr.path_name_) 00151 ACE_ALLOCATOR_RETURN (this->path_name_, 00152 ACE_OS::strdup (addr.path_name_), 00153 -1); 00154 if (addr.addr_string_) 00155 ACE_ALLOCATOR_RETURN (this->addr_string_, 00156 ACE_OS::strdup (addr.addr_string_), 00157 -1); 00158 this->addr_string_len_ = addr.addr_string_len_; 00159 return 0; 00160 } 00161 } |
|
Initializes an from the , which can be "ip-number:port-number/path-name" (e.g., "www.cs.wustl.edu:1234/~schmidt/" "ip-number:port-number/path-name" (e.g., "128.252.166.57:1234/~schmidt"). If there is no ':' in the it is assumed to be an ip-number or ip-address number, with the port number . Definition at line 76 of file URL_Addr.cpp. References ACE_ALLOCATOR_RETURN, ACE_DEFAULT_HTTP_PORT, ACE_ERROR_RETURN, ACE_NEW_RETURN, ACE_TEXT, ACEXML_Char, LM_ERROR, ACE_INET_Addr::set(), ACE_OS::strlen(), ACE_OS::strncmp(), ACE_OS::strncpy(), and ACE_OS::strtol(). Referenced by ACEXML_HttpCharStream::open().
00078 { 00079 if (s == 0) 00080 return -1; 00081 00082 const ACEXML_Char* http = ACE_TEXT ("http://"); 00083 size_t http_len = ACE_OS::strlen (http); 00084 00085 // Check validity of URL 00086 if (ACE_OS::strncmp (http, s, http_len) != 0) 00087 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Invalid URL %s\n"), s), -1); 00088 00089 const ACEXML_Char* url = 0; 00090 // Get the host name 00091 for (url = s + http_len; *url != '\0' && *url != ':' && *url != '/'; ++url) 00092 ; 00093 00094 size_t host_len = url - s; 00095 host_len -= http_len; 00096 00097 ACEXML_Char* host_name = 0; 00098 ACE_NEW_RETURN (host_name, ACEXML_Char[host_len + 1], -1); 00099 ACE_OS::strncpy (host_name, s + http_len, host_len); 00100 host_name[host_len] = '\0'; 00101 ACE_Auto_Basic_Array_Ptr<ACEXML_Char> cleanup_host_name (host_name); 00102 00103 // Get the port number (if any) 00104 unsigned short port = ACE_DEFAULT_HTTP_PORT; 00105 if (*url == ':') 00106 { 00107 port = (unsigned short) ACE_OS::strtol (++url, 0, 10); // Skip over ':' 00108 while ( *url != '\0' && *url != '/' ) 00109 ++url; 00110 } 00111 00112 // Set the addr 00113 int result = this->ACE_INET_Addr::set (port, host_name); 00114 00115 if (result == -1) 00116 return -1; 00117 00118 // Get the path name 00119 const ACEXML_Char* path_name = 0; 00120 if (*url == '\0') 00121 path_name = ACE_TEXT ("/"); 00122 else 00123 path_name = url; 00124 00125 ACE_ALLOCATOR_RETURN (this->path_name_, ACE_OS::strdup (path_name), -1); 00126 return result; 00127 } |
|
The dynamically created address string that's used for the method. Definition at line 125 of file URL_Addr.h. Referenced by addr_to_string(), and set(). |
|
Current length of the .
Definition at line 128 of file URL_Addr.h. Referenced by addr_to_string(), and set(). |
|
Our path name.
Definition at line 121 of file URL_Addr.h. Referenced by get_path_name(), set(), and ~ACEXML_URL_Addr(). |