2 #include "ace/Log_Msg.h"
3 #include "ace/OS_NS_string.h"
4 #include "ace/OS_NS_stdio.h"
5 #include "ace/OS_NS_stdlib.h"
6 #include "ace/OS_Memory.h"
8 ACE_URL_Addr::ACE_URL_Addr ()
16 ACE_URL_Addr::addr_to_string (ACE_TCHAR
*s
,
18 int ipaddr_format
) const
20 const size_t total_len
=
21 ACE_OS::strlen (ipaddr_format
== 0 ?
22 this->get_host_name () :
23 this->get_host_addr ())
24 + ACE_OS::strlen ("65536") // Assume the max port number.
25 + ACE_OS::strlen (this->get_path_name ())
28 + sizeof ('\0'); // For trailing '\0'.
34 ACE_OS::sprintf (s
, ACE_TEXT ("%s:%d/%s"),
35 ACE_TEXT_CHAR_TO_TCHAR (ipaddr_format
== 0
36 ? this->get_host_name ()
37 : this->get_host_addr ()),
38 this->get_port_number (),
39 this->get_path_name ());
45 ACE_URL_Addr::addr_to_string (int ipaddr_format
) const
47 ACE_URL_Addr
*this_ptr
= const_cast<ACE_URL_Addr
*> (this);
50 ACE_OS::strlen (ipaddr_format
== 0 ?
51 this->get_host_name () :
52 this->get_host_addr ())
53 + ACE_OS::strlen ("65536") // Assume the max port number.
54 + ACE_OS::strlen (this->get_path_name ())
57 + sizeof ('\0'); // For trailing '\0'.
59 if (size
> this->addr_string_len_
)
61 ACE_ALLOCATOR_RETURN (this_ptr
->addr_string_
,
62 (ACE_TCHAR
*) ACE_OS::realloc ((void *) this->addr_string_
,
65 this_ptr
->addr_string_len_
= size
;
67 ACE_OS::sprintf (this->addr_string_
,
68 ACE_TEXT ("%s:%d/%s"),
69 ACE_TEXT_CHAR_TO_TCHAR (ipaddr_format
== 0
70 ? this->get_host_name ()
71 : this->get_host_addr ()),
72 this->get_port_number (),
73 this->get_path_name ());
74 return this->addr_string_
;
78 ACE_URL_Addr::string_to_addr (const ACE_TCHAR
*s
,
79 int /* address_family */)
84 // Need to make a duplicate since we'll be overwriting the string.
85 ACE_ALLOCATOR_RETURN (t
,
90 // First split off the path_name.
92 ACE_TCHAR
*path_name
= ACE_OS::strchr (t
, ACE_TEXT ('/'));
93 const ACE_TCHAR
*name
= ACE_TEXT ("index.html");
96 if (ACE_OS::strlen (path_name
+ 1) > 0)
102 ACE_ALLOCATOR_RETURN (this->path_name_
,
104 ACE_OS::strdup (name
),
107 // Now handle the host address and port number.
108 ACE_TCHAR
*port_number
= ACE_OS::strchr (t
, ':');
110 if (port_number
== 0)
112 // Assume it's an ip-address or ip-number.
113 result
= this->ACE_INET_Addr::set (ACE_DEFAULT_HTTP_PORT
,
119 u_short port
= (u_short
) ACE_OS::atoi (port_number
+ 1); // Skip over ':'
120 result
= this->ACE_INET_Addr::set (port
, t
);
123 ACE_OS::free (ACE_MALLOC_T (t
));
127 ACE_URL_Addr::ACE_URL_Addr (const ACE_URL_Addr
&addr
)
133 if (this->set (addr
) == -1)
134 ACE_ERROR ((LM_ERROR
,
136 ACE_TEXT ("ACE_URL_Addr::ACE_URL_Addr")));
140 ACE_URL_Addr::set (const ACE_URL_Addr
&addr
)
142 ACE_OS::free (reinterpret_cast<void *> (const_cast<ACE_TCHAR
*>
143 (this->path_name_
)));
144 ACE_OS::free (reinterpret_cast<void *> (const_cast<ACE_TCHAR
*>
145 (this->addr_string_
)));
146 if (this->ACE_INET_Addr::set (addr
) == -1)
151 ACE_ALLOCATOR_RETURN (this->path_name_
,
152 ACE_OS::strdup (addr
.path_name_
),
154 if (addr
.addr_string_
)
155 ACE_ALLOCATOR_RETURN (this->addr_string_
,
156 ACE_OS::strdup (addr
.addr_string_
),
158 this->addr_string_len_
=
159 addr
.addr_string_len_
;
165 ACE_URL_Addr::operator= (const ACE_URL_Addr
&addr
)
167 if (this->set (addr
) == -1)
168 ACE_ERROR ((LM_ERROR
,
170 ACE_TEXT ("ACE_URL_Addr::ACE_URL_Addr")));
174 ACE_URL_Addr::hash () const
176 u_long result
= this->ACE_INET_Addr::hash ()
177 + ACE::hash_pjw (this->get_path_name ());
183 ACE_URL_Addr::operator== (const ACE_URL_Addr
&addr
) const
185 return ACE_OS::strcmp (addr
.get_path_name (),
186 this->get_path_name ()) == 0
187 && addr
.get_port_number () == this->get_port_number ()
188 && addr
.get_ip_address () == this->get_ip_address ();
192 ACE_URL_Addr::operator!= (const ACE_URL_Addr
&addr
) const
194 return !(*this == addr
);
197 ACE_URL_Addr::ACE_URL_Addr (const ACE_TCHAR
*host_name
,
198 const ACE_TCHAR
*path_name
,
200 : ACE_INET_Addr (port
, host_name
),
201 path_name_ (ACE_OS::strdup (path_name
)),
208 ACE_URL_Addr::get_path_name () const
210 return this->path_name_
;
213 ACE_URL_Addr::~ACE_URL_Addr ()
215 ACE_OS::free (reinterpret_cast<void *> (const_cast<ACE_TCHAR
*>
216 (this->path_name_
)));
217 ACE_OS::free (reinterpret_cast<void *> (const_cast<ACE_TCHAR
*>
218 (this->addr_string_
)));
219 this->path_name_
= 0;
223 ACE_URL_Addr::destroy ()