1 #include "ace/OS_NS_string.h"
2 #include "ace/OS_NS_stdlib.h"
3 #include "ace/Log_Msg.h"
4 #include "HTTPU/parse_url.h"
6 HTTP_Parse_URL::HTTP_Parse_URL (const char *url
)
14 error_ (URL_ERROR_NONE
),
20 HTTP_Parse_URL::~HTTP_Parse_URL ()
23 ACE_OS::free (this->url_
);
35 HTTP_Parse_URL::init( const char *url
)
37 // Should really reset completely and cleanly here before
38 // doing anything else!
45 url_
= ACE_OS::strdup( url
);
48 error_
= URL_ERROR_STRDUP
;
52 if (ACE_OS::strlen (this->url_
) > 3 && ACE_OS::strstr ("://", this->url_
))
54 // Parse it out completely. Figure out what it is later.
59 this->url_path_
= this->url_
;
60 this->is_cgi (this->url_path_
);
66 HTTP_Parse_URL::parse_url ()
71 if ((q
= ACE_OS::strchr (this->url_
, '\r'))
72 || (q
= ACE_OS::strchr (this->url_
, '\n')))
75 this->parse_scheme (p
);
78 this->error_
= URL_ERROR_SCHEME
;
83 if (*p
!= '/' || *(p
+1) != '/')
85 this->error_
= URL_ERROR_SLASHSLASH
;
99 this->is_cgi (this->url_path_
);
103 HTTP_Parse_URL::parse_scheme (char *&p
)
105 // Parse the scheme. The scheme is delimited by a ':'.
128 HTTP_Parse_URL::parse_host (char *&p
)
130 // Parse user, password, host, port
131 if (*p
== '/' || *p
== '\0')
133 this->set_port_from_scheme ();
153 if (at
!= 0 && colon2
== 0)
160 if (at
!= 0 && colon2
== 0)
173 if (at
== 0 && colon1
== 0)
175 if (*p
!= '\0' && *p
!= '/')
180 else if (at
== 0 && colon1
!= 0)
185 this->port_
= ACE_OS::atoi (colon1
);
188 // user, no passwd, no port
189 else if (at
!= 0 && colon1
== 0 && colon2
== 0)
193 if (*at
!= '\0' && *at
!= '/')
197 // user, no passwd, port
198 else if (at
!= 0 && colon1
== 0 && colon2
!= 0)
205 this->port_
= ACE_OS::atoi (colon2
);
208 // user, passwd, no port
209 else if (at
!= 0 && colon1
!= 0 && colon2
== 0)
213 this->passwd_
= colon1
;
219 // user, passwd, and port
220 else if (at
!= 0 && colon1
!= 0 && colon2
!= 0)
224 this->passwd_
= colon1
;
229 this->port_
= ACE_OS::atoi (colon2
);
235 ACE_ERROR ((LM_ERROR
, "uh oh!\n"));
240 this->set_port_from_scheme ();
245 HTTP_Parse_URL::set_port_from_scheme ()
247 if (ACE_OS::strcmp (this->scheme_
, "ftp") == 0)
249 if (this->port_
== -1)
251 if (this->user_
== 0)
253 this->user_
= "anonymous";
255 // *** need something better here
256 this->passwd_
= "a@b.c";
259 else if (ACE_OS::strcmp (this->scheme_
, "http") == 0)
261 if (this->port_
== -1)
267 HTTP_Parse_URL::scheme () const
269 return this->scheme_
;
273 HTTP_Parse_URL::user () const
279 HTTP_Parse_URL::passwd () const
281 return this->passwd_
;
285 HTTP_Parse_URL::host () const
291 HTTP_Parse_URL::port () const
297 HTTP_Parse_URL::url_path () const
299 return this->url_path_
? this->url_path_
: "";
303 HTTP_Parse_URL::is_cgi (const char *path
)
307 yes
= (ACE_OS::strchr (path
, '?') != 0);
308 if (!yes
&& (ACE_OS::strlen (path
) >= 3))
309 yes
= (ACE_OS::strstr (path
, "cgi") != 0);
311 yes
= (ACE_OS::strstr (path
, "asp") != 0);
317 HTTP_Parse_URL::is_cgi () const
319 return this->is_cgi_
;