Public Member Functions | Private Member Functions | Private Attributes

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 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_Charaddr_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_Charget_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_Charpath_name_
 Our path name.
ACEXML_Charaddr_string_
size_t addr_string_len_
 Current length of the <addr_string_>

Detailed Description

Defines a URL address family address format.

Definition at line 32 of file URL_Addr.h.


Constructor & Destructor Documentation

ACEXML_URL_Addr::ACEXML_URL_Addr ( void   ) 

Initialization and termination methods.

Definition at line 18 of file URL_Addr.cpp.

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 163 of file URL_Addr.cpp.

  : ACE_INET_Addr (port, host_name),
    path_name_ (ACE_OS::strdup (path_name)),
    addr_string_ (0),
    addr_string_len_ (0)
{
}

ACEXML_URL_Addr::ACEXML_URL_Addr ( const ACEXML_URL_Addr addr  ) 

Copy constructor.

Definition at line 129 of file URL_Addr.cpp.

  : ACE_INET_Addr (),
    path_name_ (0),
    addr_string_ (0),
    addr_string_len_ (0)
{
  if (this->set (addr) == -1)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("%p\n"),
                ACE_TEXT ("ACEXML_URL_Addr::ACEXML_URL_Addr")));
}

ACEXML_URL_Addr::~ACEXML_URL_Addr ( void   ) 

Destructor.

Definition at line 173 of file URL_Addr.cpp.

{
  ACE_OS::free (this->path_name_);
  ACE_OS::free (this->addr_string_);
  this->path_name_ = 0;
}


Member Function Documentation

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 26 of file URL_Addr.cpp.

{
  size_t total_len = this->calculate_length (ipaddr_format);
  if (size < total_len)
    return -1;
  else
    {
      ACE_OS::sprintf (s, ACE_TEXT ("%s:%d/%s"),
                       ACE_TEXT_CHAR_TO_TCHAR (ipaddr_format == 0
                                               ? this->get_host_name ()
                                               : this->get_host_addr ()),
                       this->get_port_number (),
                       this->get_path_name ());
      return 0;
    }
}

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 46 of file URL_Addr.cpp.

{
  size_t size = this->calculate_length (ipaddr_format);
  if (size > this->addr_string_len_)
    {
      ACE_ALLOCATOR_RETURN (this->addr_string_,
                            (ACEXML_Char *) ACE_OS::realloc(this->addr_string_,
                                                            size), 0);
      this->addr_string_len_ = size;
    }
  ACE_OS::sprintf (this->addr_string_,
                   ACE_TEXT ("%s:%d/%s"),
                   ACE_TEXT_CHAR_TO_TCHAR (ipaddr_format == 0
                                           ? this->get_host_name ()
                                          : this->get_host_addr ()),
                   this->get_port_number (),
                   this->get_path_name ());
  return this->addr_string_;
}

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

{
  return ACE_OS::strlen (ipaddr_format == 0 ?
                         this->get_host_name () : this->get_host_addr ())
                     + ACE_OS::strlen ("65536") // Assume the max port number.
                     + ACE_OS::strlen (this->get_path_name ())
                     + sizeof (':')
                     + sizeof ('/')
                     + sizeof ('\0'); // For trailing '\0'.
}

ACE_INLINE int ACEXML_URL_Addr::destroy ( void   ) 

Commit suicide.

Definition at line 60 of file URL_Addr.inl.

{
  // Commit suicide.
  delete this;
  return 0;
}

ACE_INLINE const ACEXML_Char * ACEXML_URL_Addr::get_path_name ( void   )  const

Return the path name.

Definition at line 54 of file URL_Addr.inl.

{
  return this->path_name_;
}

ACE_INLINE u_long ACEXML_URL_Addr::hash ( void   )  const [virtual]

Computes and returns hash value.

Reimplemented from ACE_INET_Addr.

Definition at line 32 of file URL_Addr.inl.

{
  u_long result = this->ACE_INET_Addr::hash ()
                  + ACE::hash_pjw (this->get_path_name ());
  return result;
}

ACE_INLINE bool ACEXML_URL_Addr::operator!= ( const ACEXML_URL_Addr SAP  )  const

Compare two addresses for inequality.

Definition at line 48 of file URL_Addr.inl.

{
  return !(*this == addr);
}

ACE_INLINE void ACEXML_URL_Addr::operator= ( const ACEXML_URL_Addr addr  ) 

Assignment operator.

Definition at line 23 of file URL_Addr.inl.

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

ACE_INLINE bool 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 40 of file URL_Addr.inl.

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

int ACEXML_URL_Addr::set ( const ACEXML_URL_Addr addr  ) 

Essentially the copy constructor.

Definition at line 142 of file URL_Addr.cpp.

{
  ACE_OS::free (this->path_name_);
  ACE_OS::free (this->addr_string_);
  if (this->ACE_INET_Addr::set (addr) == -1)
    return -1;
  else
    {
      if (addr.path_name_)
        ACE_ALLOCATOR_RETURN (this->path_name_,
                              ACE_OS::strdup (addr.path_name_),
                              -1);
      if (addr.addr_string_)
        ACE_ALLOCATOR_RETURN (this->addr_string_,
                              ACE_OS::strdup (addr.addr_string_),
                              -1);
      this->addr_string_len_ = addr.addr_string_len_;
      return 0;
    }
}

int ACEXML_URL_Addr::string_to_addr ( const ACEXML_Char address,
int  address_family = AF_UNSPEC 
) [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 76 of file URL_Addr.cpp.

{
  if (s == 0)
    return -1;

  const ACEXML_Char* http = ACE_TEXT ("http://");
  size_t http_len = ACE_OS::strlen (http);

  // Check validity of URL
  if (ACE_OS::strncmp (http, s, http_len) != 0)
    ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Invalid URL %s\n"), s), -1);

  const ACEXML_Char* url = 0;
  // Get the host name
  for (url = s + http_len; *url != '\0' && *url != ':' && *url != '/'; ++url)
    ;

  size_t host_len = url - s;
  host_len -= http_len;

  ACEXML_Char* host_name = 0;
  ACE_NEW_RETURN (host_name, ACEXML_Char[host_len + 1], -1);
  ACE_OS::strncpy (host_name, s + http_len, host_len);
  host_name[host_len] = '\0';
  ACE_Auto_Basic_Array_Ptr<ACEXML_Char> cleanup_host_name (host_name);

  // Get the port number (if any)
  unsigned short port = ACE_DEFAULT_HTTP_PORT;
  if (*url == ':')
    {
      port = (unsigned short) ACE_OS::strtol (++url, 0, 10); // Skip over ':'
      while ( *url != '\0' && *url != '/' )
        ++url;
    }

  // Set the addr
  int result = this->ACE_INET_Addr::set (port, host_name);

  if (result == -1)
    return -1;

  // Get the path name
  const ACEXML_Char* path_name = 0;
  if (*url == '\0')
    path_name = ACE_TEXT ("/");
  else
    path_name = url;

  ACE_ALLOCATOR_RETURN (this->path_name_, ACE_OS::strdup (path_name), -1);
  return result;
}


Member Data Documentation

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

Definition at line 125 of file URL_Addr.h.

Current length of the <addr_string_>

Definition at line 128 of file URL_Addr.h.

Our path name.

Definition at line 121 of file URL_Addr.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines