#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) |
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 161 of file URL_Addr.cpp. References ACEXML_Char.
00164 : ACE_INET_Addr (port, host_name), 00165 path_name_ (ACE_OS::strdup (path_name)), 00166 addr_string_ (0), 00167 addr_string_len_ (0) 00168 { 00169 } |
|
Copy constructor.
Definition at line 127 of file URL_Addr.cpp. References ACE_ERROR, ACE_TEXT, LM_ERROR, and set().
00128 : ACE_INET_Addr (), 00129 path_name_ (0), 00130 addr_string_ (0), 00131 addr_string_len_ (0) 00132 { 00133 if (this->set (addr) == -1) 00134 ACE_ERROR ((LM_ERROR, 00135 ACE_TEXT ("%p\n"), 00136 ACE_TEXT ("ACEXML_URL_Addr::ACEXML_URL_Addr"))); 00137 } |
|
Destructor.
Definition at line 171 of file URL_Addr.cpp. References ACE_OS::free(), and path_name_.
00172 { 00173 ACE_OS::free (this->path_name_); 00174 ACE_OS::free (this->addr_string_); 00175 this->path_name_ = 0; 00176 } |
|
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 140 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=().
00141 { 00142 ACE_OS::free (this->path_name_); 00143 ACE_OS::free (this->addr_string_); 00144 if (this->ACE_INET_Addr::set (addr) == -1) 00145 return -1; 00146 else 00147 { 00148 if (addr.path_name_) 00149 ACE_ALLOCATOR_RETURN (this->path_name_, 00150 ACE_OS::strdup (addr.path_name_), 00151 -1); 00152 if (addr.addr_string_) 00153 ACE_ALLOCATOR_RETURN (this->addr_string_, 00154 ACE_OS::strdup (addr.addr_string_), 00155 -1); 00156 this->addr_string_len_ = addr.addr_string_len_; 00157 return 0; 00158 } 00159 } |
|
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 75 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().
00076 { 00077 if (s == 0) 00078 return -1; 00079 00080 const ACEXML_Char* http = ACE_TEXT ("http://"); 00081 size_t http_len = ACE_OS::strlen (http); 00082 00083 // Check validity of URL 00084 if (ACE_OS::strncmp (http, s, http_len) != 0) 00085 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Invalid URL %s\n"), s), -1); 00086 00087 const ACEXML_Char* url = 0; 00088 // Get the host name 00089 for (url = s + http_len; *url != '\0' && *url != ':' && *url != '/'; ++url) 00090 ; 00091 00092 size_t host_len = url - s; 00093 host_len -= http_len; 00094 00095 ACEXML_Char* host_name = 0; 00096 ACE_NEW_RETURN (host_name, ACEXML_Char[host_len + 1], -1); 00097 ACE_OS::strncpy (host_name, s + http_len, host_len); 00098 host_name[host_len] = '\0'; 00099 ACE_Auto_Basic_Array_Ptr<ACEXML_Char> cleanup_host_name (host_name); 00100 00101 // Get the port number (if any) 00102 unsigned short port = ACE_DEFAULT_HTTP_PORT; 00103 if (*url == ':') 00104 { 00105 port = (unsigned short) ACE_OS::strtol (++url, 0, 10); // Skip over ':' 00106 while ( *url != '\0' && *url != '/' ) 00107 ++url; 00108 } 00109 00110 // Set the addr 00111 int result = this->ACE_INET_Addr::set (port, host_name); 00112 00113 if (result == -1) 00114 return -1; 00115 00116 // Get the path name 00117 const ACEXML_Char* path_name = 0; 00118 if (*url == '\0') 00119 path_name = ACE_TEXT ("/"); 00120 else 00121 path_name = url; 00122 00123 ACE_ALLOCATOR_RETURN (this->path_name_, ACE_OS::strdup (path_name), -1); 00124 return result; 00125 } |
|
The dynamically created address string that's used for the method. Definition at line 123 of file URL_Addr.h. Referenced by addr_to_string(), and set(). |
|
Current length of the .
Definition at line 126 of file URL_Addr.h. Referenced by addr_to_string(), and set(). |
|
Our path name.
Definition at line 119 of file URL_Addr.h. Referenced by get_path_name(), set(), and ~ACEXML_URL_Addr(). |