diff options
author | coryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-01-30 22:06:41 +0000 |
---|---|---|
committer | coryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-01-30 22:06:41 +0000 |
commit | 5ab941dcae73ae9a4aa49ea51bf8918b1727e6f0 (patch) | |
tree | 337918c7241c7acb5b8c21a9e679562a20a3e4db /websvcs/lib | |
parent | 9040375d5e4cb83f6bfa6741814eb8646ce40bf8 (diff) | |
download | ATCD-5ab941dcae73ae9a4aa49ea51bf8918b1727e6f0.tar.gz |
ChangeLogTag:Sat Jan 30 16:03:23 1999 Carlos O'Ryan <coryan@cs.wustl.edu>
Diffstat (limited to 'websvcs/lib')
-rw-r--r-- | websvcs/lib/URL_Addr.cpp | 103 | ||||
-rw-r--r-- | websvcs/lib/URL_Addr.h | 14 |
2 files changed, 117 insertions, 0 deletions
diff --git a/websvcs/lib/URL_Addr.cpp b/websvcs/lib/URL_Addr.cpp index 51fce7b1b70..1b66c1b98a2 100644 --- a/websvcs/lib/URL_Addr.cpp +++ b/websvcs/lib/URL_Addr.cpp @@ -15,6 +15,33 @@ static size_t ftp_size = sizeof(ftp)/sizeof(ftp[0]) - 1; static ASYS_TCHAR mailto[] = ASYS_TEXT ("mailto:"); static size_t mailto_size = sizeof(mailto)/sizeof(mailto[0]) - 1; + +static ASYS_TCHAR file[] = ASYS_TEXT ("file:"); +static size_t file_size = sizeof(file)/sizeof(file[0]) - 1; +static ASYS_TCHAR afs[] = ASYS_TEXT ("afs:"); +static size_t afs_size = sizeof(afs)/sizeof(afs[0]) - 1; +static ASYS_TCHAR news[] = ASYS_TEXT ("news:"); +static size_t news_size = sizeof(news)/sizeof(news[0]) - 1; +static ASYS_TCHAR nntp[] = ASYS_TEXT ("nntp:"); +static size_t nntp_size = sizeof(nntp)/sizeof(nntp[0]) - 1; +static ASYS_TCHAR cid[] = ASYS_TEXT ("cid:"); +static size_t cid_size = sizeof(cid)/sizeof(cid[0]) - 1; +static ASYS_TCHAR mid[] = ASYS_TEXT ("mid:"); +static size_t mid_size = sizeof(mid)/sizeof(mid[0]) - 1; +static ASYS_TCHAR wais[] = ASYS_TEXT ("wais:"); +static size_t wais_size = sizeof(wais)/sizeof(wais[0]) - 1; +static ASYS_TCHAR prospero[] = ASYS_TEXT ("prospero:"); +static size_t prospero_size = sizeof(prospero)/sizeof(prospero[0]) - 1; +static ASYS_TCHAR telnet[] = ASYS_TEXT ("telnet:"); +static size_t telnet_size = sizeof(telnet)/sizeof(telnet[0]) - 1; +static ASYS_TCHAR rlogin[] = ASYS_TEXT ("rlogin:"); +static size_t rlogin_size = sizeof(rlogin)/sizeof(rlogin[0]) - 1; +static ASYS_TCHAR tn3270[] = ASYS_TEXT ("tn3270:"); +static size_t tn3270_size = sizeof(tn3270)/sizeof(tn3270[0]) - 1; +static ASYS_TCHAR gopher[] = ASYS_TEXT ("gopher:"); +static size_t gopher_size = sizeof(gopher)/sizeof(gopher[0]) - 1; + + ACE_URL_Addr::ACE_URL_Addr (void) : url_ (0) { @@ -82,6 +109,43 @@ ACE_URL_Addr::create_address (LPCTSTR url) return addr; } +int +ACE_URL_Addr::known_scheme (LPCTSTR url) +{ + if (ACE_OS::strncmp (http, url, http_size) == 0) + return 1; + else if (ACE_OS::strncmp (ftp, url, ftp_size) == 0) + return 1; + else if (ACE_OS::strncmp (mailto, url, mailto_size) == 0) + return 1; + else if (ACE_OS::strncmp (file, url, file_size) == 0) + return 1; + else if (ACE_OS::strncmp (afs, url, afs_size) == 0) + return 1; + else if (ACE_OS::strncmp (news, url, news_size) == 0) + return 1; + else if (ACE_OS::strncmp (nntp, url, nntp_size) == 0) + return 1; + else if (ACE_OS::strncmp (cid, url, cid_size) == 0) + return 1; + else if (ACE_OS::strncmp (mid, url, mid_size) == 0) + return 1; + else if (ACE_OS::strncmp (wais, url, wais_size) == 0) + return 1; + else if (ACE_OS::strncmp (prospero, url, prospero_size) == 0) + return 1; + else if (ACE_OS::strncmp (telnet, url, telnet_size) == 0) + return 1; + else if (ACE_OS::strncmp (rlogin, url, rlogin_size) == 0) + return 1; + else if (ACE_OS::strncmp (tn3270, url, tn3270_size) == 0) + return 1; + else if (ACE_OS::strncmp (gopher, url, gopher_size) == 0) + return 1; + + return 0; +} + // **************************************************************** ACE_URL_Addr_Visitor::~ACE_URL_Addr_Visitor (void) @@ -242,6 +306,45 @@ ACE_HTTP_Addr::url_size (int flags) const return size; } +ACE_URL_Addr* +ACE_HTTP_Addr::create_relative_address (LPCTSTR url) const +{ + if (ACE_URL_Addr::known_scheme (url)) + return ACE_URL_Addr::create_address (url); + + ACE_HTTP_Addr* addr = 0; + if (url[0] == '/') + { + ACE_NEW_RETURN (addr, ACE_HTTP_Addr (this->get_hostname (), + url, + 0, + this->get_port_number ()), + 0); + } + else + { + LPTSTR buf; + ACE_NEW_RETURN (buf, + ASYS_TCHAR [ACE_OS::strlen (url) + + ACE_OS::strlen (this->get_path ()) + + 2], + 0); + LPCTSTR path = this->get_path (); + int l = ACE_OS::strlen (path); + if (path[l-1] == '/') + ACE_OS::sprintf (buf, "%s%s", path, url); + else + ACE_OS::sprintf (buf, "%s/%s", path, url); + ACE_NEW_RETURN (addr, ACE_HTTP_Addr (this->get_hostname (), + buf, + 0, + this->get_port_number ()), + 0); + delete[] buf; + } + return addr; +} + int ACE_HTTP_Addr::string_to_addr (LPCTSTR address) { diff --git a/websvcs/lib/URL_Addr.h b/websvcs/lib/URL_Addr.h index b51cad24bfb..1c37713c4b3 100644 --- a/websvcs/lib/URL_Addr.h +++ b/websvcs/lib/URL_Addr.h @@ -69,6 +69,9 @@ public: static ACE_URL_Addr* create_address (LPCTSTR url); // Create an address from a complete URL, such as "http://www/foo" // or "ftp://ftp.here/get_this". + + static int known_scheme (LPCTSTR url); + // Returns 1 if the URL scheme is recognized, 0 otherwise. protected: void set_url (LPTSTR url); @@ -185,6 +188,17 @@ public: LPCTSTR get_query (void) const; // Get the query component in the URL + ACE_URL_Addr* create_relative_address (LPCTSTR url) const; + // Create an address from a (possibly) relative URL, such as + // "../foo.html", or "/icons/bar.gif" + // If the URL is absolute (like "http://www/foo" or "ftp:host/bar") + // it simply returns the correct ACE_URL_Addr object; but if the URL + // is not absolute then it is interpreted as relative from the + // current address. In that case url is just a path, if it is a + // relative path the new address simply concatenates the path and + // uses the same host:port; if it is an absolute path only the host + // and port are used. + // = The ACE_URL methods, see the documentation above. virtual int string_to_addr (LPCTSTR address); virtual int addr_to_string (LPTSTR s, |