Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACEXML_URL_Addr Class Reference

#include "ACEXML/common/URL_Addr.h"

Inheritance diagram for ACEXML_URL_Addr:

Inheritance graph
[legend]
Collaboration diagram for ACEXML_URL_Addr:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACEXML_URL_Addr (void)
 Initialization and termination methods. More...

 ACEXML_URL_Addr (const ACEXML_Char *host_name, const ACEXML_Char *path_name, unsigned short port=ACE_DEFAULT_HTTP_PORT)
 Constructor. More...

 ACEXML_URL_Addr (const ACEXML_URL_Addr &addr)
 Copy constructor. More...

int set (const ACEXML_URL_Addr &addr)
 Essentially the copy constructor. More...

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_Charaddr_to_string (int ipaddr_format=1)
void operator= (const ACEXML_URL_Addr &addr)
 Assignment operator. More...

 ~ACEXML_URL_Addr (void)
 Destructor. More...

int operator== (const ACEXML_URL_Addr &SAP) const
int operator!= (const ACEXML_URL_Addr &SAP) const
 Compare two addresses for inequality. More...

virtual u_long hash (void) const
 Computes and returns hash value. More...

const ACEXML_Charget_path_name (void) const
 Return the path name. More...

int destroy (void)
 Commit suicide. More...


Private Methods

size_t calculate_length (int ipaddr_format) const
 Calculate the maximum length of the address string. More...


Private Attributes

ACEXML_Charpath_name_
 Our path name. More...

ACEXML_Charaddr_string_
 The dynamically created address string that's used for the <addr_to_string> method. More...

size_t addr_string_len_
 Current length of the <addr_string_>. More...


Detailed Description

Defines a URL address family address format.

Definition at line 31 of file URL_Addr.h.


Constructor & Destructor Documentation

ACEXML_URL_Addr::ACEXML_URL_Addr void   
 

Initialization and termination methods.

Definition at line 14 of file URL_Addr.cpp.

00015   : path_name_ (0),
00016     addr_string_ (0),
00017     addr_string_len_ (0)
00018 {
00019 }

ACEXML_URL_Addr::ACEXML_URL_Addr const ACEXML_Char   host_name,
const ACEXML_Char   path_name,
unsigned short    port = ACE_DEFAULT_HTTP_PORT
 

Constructor.

Definition at line 157 of file URL_Addr.cpp.

References ACEXML_Char.

00160   : ACE_INET_Addr (port, host_name),
00161     path_name_ (ACE_OS::strdup (path_name)),
00162     addr_string_ (0),
00163     addr_string_len_ (0)
00164 {
00165 }

ACEXML_URL_Addr::ACEXML_URL_Addr const ACEXML_URL_Addr &    addr
 

Copy constructor.

Definition at line 123 of file URL_Addr.cpp.

References ACE_ERROR, ACE_TEXT, LM_ERROR, and set.

00124   : ACE_INET_Addr (),
00125     path_name_ (0),
00126     addr_string_ (0),
00127     addr_string_len_ (0)
00128 {
00129   if (this->set (addr) == -1)
00130     ACE_ERROR ((LM_ERROR,
00131                 ACE_TEXT ("%p\n"),
00132                 ACE_TEXT ("ACEXML_URL_Addr::ACEXML_URL_Addr")));
00133 }

ACEXML_URL_Addr::~ACEXML_URL_Addr void   
 

Destructor.

Definition at line 167 of file URL_Addr.cpp.

References ACE_OS_Memory::free, and path_name_.

00168 {
00169   ACE_OS::free (this->path_name_);
00170   ACE_OS::free (this->addr_string_);
00171   this->path_name_ = 0;
00172 }


Member Function Documentation

const ACEXML_Char * ACEXML_URL_Addr::addr_to_string int    ipaddr_format = 1 [virtual]
 

Transform the current <ACE_INET_Addr> address into string format. If <ipaddr_format> is non-0 this produces "ip-number:port-number/path-name" (e.g., "128.252.166.57:80/~schmidt/"), whereas if <ipaddr_format> 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 42 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.

00043 {
00044   size_t size = this->calculate_length (ipaddr_format);
00045   if (size > this->addr_string_len_)
00046     {
00047       ACE_ALLOCATOR_RETURN (this->addr_string_,
00048                             (ACEXML_Char *) ACE_OS::realloc(this->addr_string_,
00049                                                             size), 0);
00050       this->addr_string_len_ = size;
00051     }
00052   ACE_OS::sprintf (this->addr_string_,
00053                    ACE_TEXT ("%s:%d/%s"),
00054                    ACE_TEXT_CHAR_TO_TCHAR (ipaddr_format == 0
00055                                            ? this->get_host_name ()
00056                                           : this->get_host_addr ()),
00057                    this->get_port_number (),
00058                    this->get_path_name ());
00059   return this->addr_string_;
00060 }

int ACEXML_URL_Addr::addr_to_string ACEXML_Char   s,
size_t    size,
int    ipaddr_format = 1
const [virtual]
 

Transform the current <ACE_INET_Addr> address into string format. If <ipaddr_format> is non-0 this produces "ip-number:port-number/path-name" (e.g., "128.252.166.57:80/~schmidt/"), whereas if <ipaddr_format> is 0 this produces "ip-name:port-number" (e.g., "www.cs.wustl.edu:80/~schmidt/"). Returns -1 if the <size> of the <buffer> is too small, else 0.

Definition at line 22 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.

00025 {
00026   size_t total_len = this->calculate_length (ipaddr_format);
00027   if (size < total_len)
00028     return -1;
00029   else
00030     {
00031       ACE_OS::sprintf (s, ACE_TEXT ("%s:%d/%s"),
00032                        ACE_TEXT_CHAR_TO_TCHAR (ipaddr_format == 0
00033                                                ? this->get_host_name ()
00034                                                : this->get_host_addr ()),
00035                        this->get_port_number (),
00036                        this->get_path_name ());
00037       return 0;
00038     }
00039 }

ACE_INLINE size_t ACEXML_URL_Addr::calculate_length int    ipaddr_format const [private]
 

Calculate the maximum length of the address string.

Definition at line 13 of file URL_Addr.inl.

References ACE_INET_Addr::get_host_addr, and ACE_OS_String::strlen.

Referenced by addr_to_string.

00014 {
00015   return ACE_OS::strlen (ipaddr_format == 0 ?
00016                          this->get_host_name () : this->get_host_addr ())
00017                      + ACE_OS::strlen ("65536") // Assume the max port number.
00018                      + ACE_OS::strlen (this->get_path_name ())
00019                      + sizeof (':')
00020                      + sizeof ('/')
00021                      + sizeof ('\0'); // For trailing '\0'.
00022 }

ACE_INLINE int ACEXML_URL_Addr::destroy void   
 

Commit suicide.

Definition at line 56 of file URL_Addr.inl.

00057 {
00058   // Commit suicide.
00059   delete this;
00060   return 0;
00061 }

ACE_INLINE const ACEXML_Char * ACEXML_URL_Addr::get_path_name void    const
 

Return the path name.

Definition at line 7 of file URL_Addr.inl.

References path_name_.

Referenced by addr_to_string, and operator==.

00008 {
00009   return this->path_name_;
00010 }

ACE_INLINE u_long ACEXML_URL_Addr::hash void    const [virtual]
 

Computes and returns hash value.

Reimplemented from ACE_INET_Addr.

Definition at line 34 of file URL_Addr.inl.

References ACE_INET_Addr::hash, and ACE::hash_pjw.

00035 {
00036   u_long result = this->ACE_INET_Addr::hash ()
00037                   + ACE::hash_pjw (this->get_path_name ());
00038   return result;
00039 }

ACE_INLINE int ACEXML_URL_Addr::operator!= const ACEXML_URL_Addr &    SAP const
 

Compare two addresses for inequality.

Definition at line 50 of file URL_Addr.inl.

00051 {
00052   return !(*this == addr);
00053 }

ACE_INLINE void ACEXML_URL_Addr::operator= const ACEXML_URL_Addr &    addr
 

Assignment operator.

Definition at line 25 of file URL_Addr.inl.

References ACE_ERROR, ACE_TEXT, LM_ERROR, and set.

00026 {
00027   if (this->set (addr) == -1)
00028     ACE_ERROR ((LM_ERROR,
00029                 ACE_TEXT ("%p\n"),
00030                 ACE_TEXT ("ACEXML_URL_Addr::ACEXML_URL_Addr")));
00031 }

ACE_INLINE int ACEXML_URL_Addr::operator== const ACEXML_URL_Addr &    SAP const
 

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 42 of file URL_Addr.inl.

References ACE_INET_Addr::get_ip_address, get_path_name, ACE_INET_Addr::get_port_number, and ACE_OS_String::strcmp.

00043 {
00044   return ACE_OS::strcmp (addr.get_path_name (), this->get_path_name ()) == 0
00045     && addr.get_port_number () == this->get_port_number ()
00046     && addr.get_ip_address () == this->get_ip_address ();
00047 }

int ACEXML_URL_Addr::set const ACEXML_URL_Addr &    addr
 

Essentially the copy constructor.

Definition at line 136 of file URL_Addr.cpp.

References ACE_ALLOCATOR_RETURN, addr_string_, addr_string_len_, ACE_OS_Memory::free, path_name_, and ACE_INET_Addr::set.

Referenced by ACEXML_URL_Addr, and operator=.

00137 {
00138   ACE_OS::free (this->path_name_);
00139   ACE_OS::free (this->addr_string_);
00140   if (this->ACE_INET_Addr::set (addr) == -1)
00141     return -1;
00142   else
00143     {
00144       if (addr.path_name_)
00145         ACE_ALLOCATOR_RETURN (this->path_name_,
00146                               ACE_OS::strdup (addr.path_name_),
00147                               -1);
00148       if (addr.addr_string_)
00149         ACE_ALLOCATOR_RETURN (this->addr_string_,
00150                               ACE_OS::strdup (addr.addr_string_),
00151                               -1);
00152       this->addr_string_len_ = addr.addr_string_len_;
00153       return 0;
00154     }
00155 }

int ACEXML_URL_Addr::string_to_addr const ACEXML_Char   address [virtual]
 

Initializes an <ACEXML_URL_Addr> from the <address>, 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 <address> it is assumed to be an ip-number or ip-address number, with the port number <ACE_DEFAULT_HTTP_PORT>.

Definition at line 71 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_String::strlen, ACE_OS_String::strncmp, ACE_OS_String::strncpy, and ACE_OS_String::strtol.

Referenced by ACEXML_HttpCharStream::open.

00072 {
00073   if (s == 0)
00074     return -1;
00075 
00076   const ACEXML_Char* http = ACE_TEXT ("http://");
00077   size_t http_len = ACE_OS::strlen (http);
00078 
00079   // Check validity of URL
00080   if (ACE_OS::strncmp (http, s, http_len) != 0)
00081     ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Invalid URL %s\n"), s), -1);
00082 
00083   const ACEXML_Char* url = 0;
00084   // Get the host name
00085   for (url = s + http_len; *url != '\0' && *url != ':' && *url != '/'; ++url)
00086     ;
00087 
00088   size_t host_len = url - s;
00089   host_len -= http_len;
00090 
00091   ACEXML_Char* host_name = 0;
00092   ACE_NEW_RETURN (host_name, ACEXML_Char[host_len + 1], -1);
00093   ACE_OS::strncpy (host_name, s + http_len, host_len);
00094   host_name[host_len] = '\0';
00095   ACE_Auto_Basic_Array_Ptr<ACEXML_Char> cleanup_host_name (host_name);
00096 
00097   // Get the port number (if any)
00098   unsigned short port = ACE_DEFAULT_HTTP_PORT;
00099   if (*url == ':')
00100     {
00101       port = (unsigned short) ACE_OS::strtol (++url, 0, 10); // Skip over ':'
00102       while ( *url != '\0' && *url != '/' )
00103         ++url;
00104     }
00105 
00106   // Set the addr
00107   int result = this->ACE_INET_Addr::set (port, host_name);
00108 
00109   if (result == -1)
00110     return -1;
00111 
00112   // Get the path name
00113   const ACEXML_Char* path_name = 0;
00114   if (*url == '\0')
00115     path_name = ACE_TEXT ("/");
00116   else
00117     path_name = url;
00118 
00119   ACE_ALLOCATOR_RETURN (this->path_name_, ACE_OS::strdup (path_name), -1);
00120   return result;
00121 }


Member Data Documentation

ACEXML_Char* ACEXML_URL_Addr::addr_string_ [private]
 

The dynamically created address string that's used for the <addr_to_string> method.

Definition at line 122 of file URL_Addr.h.

Referenced by addr_to_string, and set.

size_t ACEXML_URL_Addr::addr_string_len_ [private]
 

Current length of the <addr_string_>.

Definition at line 125 of file URL_Addr.h.

Referenced by addr_to_string, and set.

ACEXML_Char* ACEXML_URL_Addr::path_name_ [private]
 

Our path name.

Definition at line 118 of file URL_Addr.h.

Referenced by get_path_name, set, and ~ACEXML_URL_Addr.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 13:27:32 2003 for ACEXML by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002