summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcoryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-01-24 08:10:02 +0000
committercoryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-01-24 08:10:02 +0000
commit3e9141dbad3c85ed51f78a019941ff501c38996f (patch)
tree90c7308887b342bbf7df25c8a39e366ec5fee5c2
parent7e35610dc2f669145a8d7b6f5f8672080f7f858e (diff)
downloadATCD-3e9141dbad3c85ed51f78a019941ff501c38996f.tar.gz
ChangeLogTag:Sun Jan 24 02:08:57 1999 Carlos O'Ryan <coryan@cs.wustl.edu>
-rw-r--r--ChangeLog-99b8
-rw-r--r--websvcs/lib/URL_Addr.cpp168
-rw-r--r--websvcs/lib/URL_Addr.h19
-rw-r--r--websvcs/lib/URL_Addr.i19
-rw-r--r--websvcs/tests/Test_URL_Addr.cpp130
5 files changed, 316 insertions, 28 deletions
diff --git a/ChangeLog-99b b/ChangeLog-99b
index aec1f1545ba..2528ac5fa7a 100644
--- a/ChangeLog-99b
+++ b/ChangeLog-99b
@@ -1,3 +1,11 @@
+Sun Jan 24 02:08:57 1999 Carlos O'Ryan <coryan@cs.wustl.edu>
+
+ * websvcs/lib/URL_Addr.cpp:
+ * websvcs/lib/URL_Addr.h:
+ * websvcs/lib/URL_Addr.i:
+ * websvcs/tests/Test_URL_Addr.cpp:
+ Added support for mailto: URLs
+
Sat Jan 23 23:53:29 1999 Carlos O'Ryan <coryan@cs.wustl.edu>
* websvcs/Makefile:
diff --git a/websvcs/lib/URL_Addr.cpp b/websvcs/lib/URL_Addr.cpp
index 2e4b9b6be33..47a33237307 100644
--- a/websvcs/lib/URL_Addr.cpp
+++ b/websvcs/lib/URL_Addr.cpp
@@ -50,6 +50,7 @@ ACE_URL_Addr::addr_to_string (LPTSTR s,
if (size < ACE_OS::strlen (this->url_))
return -1;
ACE_OS::strcpy (s, this->url_);
+ return 0;
}
int
@@ -62,7 +63,6 @@ ACE_URL_Addr::accept (ACE_URL_Addr_Visitor* visitor)
ACE_URL_Addr*
ACE_URL_Addr::create_address (LPCTSTR url)
{
-
ACE_URL_Addr* addr = 0;
if (ACE_OS::strncmp (http, url, http_size) == 0)
ACE_NEW_RETURN (addr, ACE_HTTP_Addr (), 0);
@@ -73,7 +73,7 @@ ACE_URL_Addr::create_address (LPCTSTR url)
else
ACE_NEW_RETURN (addr, ACE_URL_Addr (), 0);
- if (addr->string_to_addr (url) == -1)
+ if (addr->string_to_addr (url) != 0)
{
delete addr;
addr = 0;
@@ -203,18 +203,21 @@ ACE_HTTP_Addr::url_size (int flags) const
// Notice that we cannot hard-code the value because the size in
// wchar's may be different.
size_t size =
- + (this->path_?ACE_OS::strlen (this->path_):0)
- + (this->query_?ACE_OS::strlen (this->query_):0)
+ sizeof (ASYS_TEXT ("http://"))
+ sizeof (ASYS_TEXT ("/:?")); // separators
+ size_t chars =
+ + (this->path_?ACE_OS::strlen (this->path_):0)
+ + (this->query_?ACE_OS::strlen (this->query_):0);
+
+
if (flags == 0)
{
size += sizeof (ASYS_TEXT("255.255.255.255"));
}
else
{
- size += ACE_OS::strlen (this->hostname_) * sizeof(ASYS_TCHAR);
+ chars += ACE_OS::strlen (this->hostname_);
}
if (this->port_number_ != ACE_DEFAULT_HTTP_PORT)
@@ -222,6 +225,8 @@ ACE_HTTP_Addr::url_size (int flags) const
size += sizeof (ASYS_TEXT(":65335"));
}
+ size += chars * sizeof(ASYS_TCHAR);
+
return size;
}
@@ -237,7 +242,8 @@ ACE_HTTP_Addr::string_to_addr (LPCTSTR address)
this->query_ = 0;
// Save the original URL....
- this->ACE_URL_Addr::string_to_addr (address);
+ if (this->ACE_URL_Addr::string_to_addr (address) != 0)
+ return -1;
LPCTSTR string = address;
string += http_size;
@@ -419,21 +425,24 @@ ACE_FTP_Addr::url_size (int flags) const
// Notice that we cannot hard-code the value because the size in
// wchar's may be different.
size_t size =
- + (this->user_?ACE_OS::strlen (this->path_):0)
- + (this->passwd_?ACE_OS::strlen (this->passwd_):0)
- + (this->path_?ACE_OS::strlen (this->path_):0)
+ sizeof (ASYS_TEXT ("ftp://"))
+ sizeof (ASYS_TEXT ("@:/")); // separators
+ size_t chars =
+ + (this->user_?ACE_OS::strlen (this->path_):0)
+ + (this->passwd_?ACE_OS::strlen (this->passwd_):0)
+ + (this->path_?ACE_OS::strlen (this->path_):0);
+
if (flags == 0)
{
size += sizeof (ASYS_TEXT("255.255.255.255"));
}
else
{
- size += ACE_OS::strlen (this->hostname_) * sizeof(ASYS_TCHAR);
+ chars += ACE_OS::strlen (this->hostname_);
}
+ size += chars * sizeof(ASYS_TCHAR);
return size;
}
@@ -547,25 +556,162 @@ ACE_FTP_Addr::accept (ACE_URL_Addr_Visitor* visitor)
// ****************************************************************
ACE_Mailto_Addr::ACE_Mailto_Addr (void)
+ : user_ (0),
+ hostname_ (0),
+ headers_ (0)
{
}
+ACE_Mailto_Addr::ACE_Mailto_Addr (LPCTSTR user,
+ LPCTSTR hostname,
+ LPCTSTR headers)
+ : user_ (0),
+ hostname_ (0),
+ headers_ (0)
+{
+ this->set (user, hostname, headers);
+}
+
+ACE_Mailto_Addr::ACE_Mailto_Addr (const ACE_Mailto_Addr &addr)
+ : ACE_URL_Addr (addr),
+ user_ (0),
+ hostname_ (0),
+ headers_ (0)
+{
+ this->set (addr);
+}
+
ACE_Mailto_Addr::~ACE_Mailto_Addr (void)
{
}
int
+ACE_Mailto_Addr::set (LPCTSTR user,
+ LPCTSTR hostname,
+ LPCTSTR headers)
+{
+ this->clear ();
+ ACE_ALLOCATOR_RETURN (this->user_, ACE_OS::strdup (user), -1);
+ ACE_ALLOCATOR_RETURN (this->hostname_, ACE_OS::strdup (hostname), -1);
+ ACE_ALLOCATOR_RETURN (this->headers_, ACE_OS::strdup (headers), -1);
+ size_t size = this->url_size (1);
+ LPTSTR buffer;
+ ACE_ALLOCATOR_RETURN (buffer,
+ ACE_reinterpret_cast(LPTSTR,
+ ACE_OS::malloc (size)),
+ -1);
+ if (this->addr_to_string (buffer, size, 1) == -1)
+ return -1;
+ this->set_url (buffer);
+ return 0;
+}
+
+int
+ACE_Mailto_Addr::set (const ACE_Mailto_Addr &addr)
+{
+ if (this->ACE_URL_Addr::set (addr) != 0)
+ return -1;
+ this->clear ();
+ ACE_ALLOCATOR_RETURN (this->user_, ACE_OS::strdup (addr.user_), -1);
+ ACE_ALLOCATOR_RETURN (this->hostname_, ACE_OS::strdup (addr.hostname_), -1);
+ ACE_ALLOCATOR_RETURN (this->headers_, ACE_OS::strdup (addr.headers_), -1);
+ return 0;
+}
+
+void
+ACE_Mailto_Addr::clear (void)
+{
+ if (this->user_ != 0)
+ ACE_OS::free (this->user_);
+ if (this->hostname_ != 0)
+ ACE_OS::free (this->hostname_);
+ if (this->headers_ != 0)
+ ACE_OS::free (this->headers_);
+}
+
+size_t
+ACE_Mailto_Addr::url_size (int flags) const
+{
+ // Notice that we cannot hard-code the value because the size in
+ // wchar's may be different.
+ size_t size = sizeof (ASYS_TEXT ("mailto:"))
+ + sizeof (ASYS_TEXT ("@?")); // separators
+
+ size_t chars =
+ + (this->user_?ACE_OS::strlen (this->user_):0)
+ + (this->hostname_?ACE_OS::strlen (this->hostname_):0)
+ + (this->headers_?ACE_OS::strlen (this->headers_):0);
+ size += chars * sizeof (ASYS_TCHAR);
+
+ return size;
+}
+
+int
ACE_Mailto_Addr::addr_to_string (LPTSTR buffer,
size_t size,
int flags) const
{
+ if (size < this->url_size (flags))
+ return -1;
+ if (this->user_ == 0 || this->hostname_ == 0)
+ return -1;
+
+ size_t n = ACE_OS::sprintf (buffer, ASYS_TEXT ("mailto:%s@%s"),
+ this->user_, this->hostname_);
+ if (this->headers_ != 0)
+ {
+ n += ACE_OS::sprintf (buffer + n, ASYS_TEXT ("?%s"),
+ this->headers_);
+ }
+
return 0;
}
int
ACE_Mailto_Addr::string_to_addr (LPCTSTR address)
{
- // @@
+ if (ACE_OS::strncmp (mailto, address, mailto_size) != 0)
+ return -1;
+
+ this->clear ();
+ this->user_ = 0;
+ this->hostname_ = 0;
+ this->headers_ = 0;
+
+ // Save the original URL....
+ if (this->ACE_URL_Addr::string_to_addr (address) != 0)
+ return -1;
+
+ LPCTSTR string = address;
+ string += mailto_size;
+
+ // Make a copy of the string to manipulate it.
+ ASYS_TCHAR *t;
+ ACE_ALLOCATOR_RETURN (t, ACE_OS::strdup (string), -1);
+
+ ASYS_TCHAR *host_start = ACE_OS::strchr (t, '@');
+ if (host_start != 0)
+ {
+ // terminate the host:port substring
+ host_start[0] = '\0';
+ host_start++;
+ ASYS_TCHAR *headers_start = ACE_OS::strchr (host_start, '?');
+ if (headers_start != 0)
+ {
+ headers_start[0] = '\0';
+ headers_start++;
+ ACE_ALLOCATOR_RETURN (this->headers_,
+ ACE_OS::strdup (headers_start),
+ -1);
+ }
+ ACE_ALLOCATOR_RETURN (this->hostname_, ACE_OS::strdup (host_start), -1);
+ }
+ else
+ {
+ return -1;
+ }
+ this->user_ = t;
+
return 0;
}
diff --git a/websvcs/lib/URL_Addr.h b/websvcs/lib/URL_Addr.h
index c04a1fd7b3c..7a486b870c1 100644
--- a/websvcs/lib/URL_Addr.h
+++ b/websvcs/lib/URL_Addr.h
@@ -313,12 +313,12 @@ public:
ACE_Mailto_Addr (void);
// Constructor
- ACE_Mailto_Addr (LPCTSTR name,
+ ACE_Mailto_Addr (LPCTSTR user,
LPCTSTR hostname,
LPCTSTR headers = 0);
// Construct an FTP URL from the host, path and headers.
- int set (LPCTSTR name,
+ int set (LPCTSTR user,
LPCTSTR hostname,
LPCTSTR headers = 0);
// Essentially the constructor above.
@@ -332,8 +332,11 @@ public:
virtual ~ACE_Mailto_Addr (void);
// Destructor
+ LPCTSTR get_user (void) const;
+ // Get the username component in the URL
+
LPCTSTR get_hostname (void) const;
- // Get the path component in the URL
+ // Get the hostname component in the URL
LPCTSTR get_headers (void) const;
// Get the headers as a single string
@@ -350,7 +353,15 @@ public:
virtual int accept (ACE_URL_Addr_Visitor* visitor);
private:
- LPTSTR name_;
+ size_t url_size (int flags = 0) const;
+ // Compute the size required to store the URL in a string
+ // representation.
+
+ void clear (void);
+ // Helper method to cleanup resources
+
+private:
+ LPTSTR user_;
LPTSTR hostname_;
LPTSTR headers_;
};
diff --git a/websvcs/lib/URL_Addr.i b/websvcs/lib/URL_Addr.i
index aaeddb6266c..482abda66ab 100644
--- a/websvcs/lib/URL_Addr.i
+++ b/websvcs/lib/URL_Addr.i
@@ -84,3 +84,22 @@ ACE_FTP_Addr::get_inet_address (void) const
return ACE_INET_Addr (ASYS_TEXT ("ftp"), this->hostname_);
}
+// ****************************************************************
+
+ACE_INLINE LPCTSTR
+ACE_Mailto_Addr::get_user (void) const
+{
+ return this->user_;
+}
+
+ACE_INLINE LPCTSTR
+ACE_Mailto_Addr::get_hostname (void) const
+{
+ return this->hostname_;
+}
+
+ACE_INLINE LPCTSTR
+ACE_Mailto_Addr::get_headers (void) const
+{
+ return this->headers_;
+}
diff --git a/websvcs/tests/Test_URL_Addr.cpp b/websvcs/tests/Test_URL_Addr.cpp
index 27fecd854b2..644f0ebd467 100644
--- a/websvcs/tests/Test_URL_Addr.cpp
+++ b/websvcs/tests/Test_URL_Addr.cpp
@@ -6,25 +6,48 @@ ACE_RCSID(WEBSVCS_Test, Test_URL_Addr, "$Id$")
void test_http_addr (void);
void test_ftp_addr (void);
+void test_mailto_addr (void);
void test_url_addr (void);
int main (int, char*[])
{
test_http_addr ();
test_ftp_addr ();
+ test_mailto_addr ();
+ test_url_addr ();
return 0;
}
+#define HTTP_TEST_ARRAY \
+ ASYS_TEXT("http://www.cs.wustl.edu/"), \
+ ASYS_TEXT("http://www.cs.wustl.edu/index.html"), \
+ ASYS_TEXT("http://www.cs.wustl.edu/form?var=foo"), \
+ ASYS_TEXT("http://www.notexist.com:8080/index.html"), \
+ ASYS_TEXT("http://www.notexist.com:80/index.html"), \
+ ASYS_TEXT("ftp://foo"), \
+ ASYS_TEXT("http://www/?kkk//")
+
+#define FTP_TEST_ARRAY \
+ ASYS_TEXT("ftp://www.cs.wustl.edu/"), \
+ ASYS_TEXT("ftp://user@www.cs.wustl.edu/"), \
+ ASYS_TEXT("ftp://user:pass@www.cs.wustl.edu/"), \
+ ASYS_TEXT("ftp://user:pass@www.cs.wustl.edu/path"), \
+ ASYS_TEXT("ftp://www.cs.wustl.edu"), \
+ ASYS_TEXT("http://www.cs.wustl.edu/index.html")
+
+#define MAILTO_TEST_ARRAY \
+ ASYS_TEXT("mailto:ace-users@cs.wustl.edu"), \
+ ASYS_TEXT("mailto:majordomo@cs.wustl.edu?Subject: subscribe ace-users"), \
+ ASYS_TEXT("mailto:nobody"), \
+ ASYS_TEXT("http://www.cs.wustl.edu")
+
+#define URL_TEST_ARRAY \
+ ASYS_TEXT("file:/etc/passwd")
+
void test_http_addr (void)
{
static LPCTSTR addresses[] = {
- ASYS_TEXT("http://www.cs.wustl.edu/"),
- ASYS_TEXT("http://www.cs.wustl.edu/index.html"),
- ASYS_TEXT("http://www.cs.wustl.edu/form?var=foo"),
- ASYS_TEXT("http://www.notexist.com:8080/index.html"),
- ASYS_TEXT("http://www.notexist.com:80/index.html"),
- ASYS_TEXT("ftp://foo"),
- ASYS_TEXT("http://www/?kkk//")
+ HTTP_TEST_ARRAY
};
static int naddresses = sizeof(addresses)/sizeof(addresses[0]);
for (int i = 0; i < naddresses; ++i)
@@ -64,12 +87,7 @@ void test_http_addr (void)
void test_ftp_addr (void)
{
static LPCTSTR addresses[] = {
- ASYS_TEXT("ftp://www.cs.wustl.edu/"),
- ASYS_TEXT("ftp://user@www.cs.wustl.edu/"),
- ASYS_TEXT("ftp://user:pass@www.cs.wustl.edu/"),
- ASYS_TEXT("ftp://user:pass@www.cs.wustl.edu/path"),
- ASYS_TEXT("ftp://www.cs.wustl.edu"),
- ASYS_TEXT("http://www.cs.wustl.edu/index.html"),
+ FTP_TEST_ARRAY
};
static int naddresses = sizeof(addresses)/sizeof(addresses[0]);
for (int i = 0; i < naddresses; ++i)
@@ -107,6 +125,92 @@ void test_ftp_addr (void)
}
}
+void test_mailto_addr (void)
+{
+ static LPCTSTR addresses[] = {
+ MAILTO_TEST_ARRAY
+ };
+ static int naddresses = sizeof(addresses)/sizeof(addresses[0]);
+ for (int i = 0; i < naddresses; ++i)
+ {
+ ACE_Mailto_Addr addr;
+ if (addr.string_to_addr (addresses[i]) != 0)
+ {
+ ACE_ERROR ((LM_ERROR,
+ "Mailto[%d]\n"
+ " \"%s\" ERROR\n",
+ i, addresses[i]));
+ continue;
+ }
+
+ ASYS_TCHAR buffer[BUFSIZ];
+ if (addr.addr_to_string (buffer, BUFSIZ, i%2) == 0)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "Mailto[%d]\n"
+ " \"%s\"\n"
+ " <%s>\n"
+ " <%s>\n",
+ i, addresses[i],
+ addr.get_url (),
+ buffer));
+ }
+ else
+ {
+ ACE_ERROR ((LM_ERROR,
+ "Mailto[%d]\n"
+ " \"%s\" ERROR\n",
+ i, addresses[i]));
+
+ }
+ }
+}
+
+void test_url_addr (void)
+{
+ static LPCTSTR addresses[] = {
+ HTTP_TEST_ARRAY,
+ FTP_TEST_ARRAY,
+ MAILTO_TEST_ARRAY,
+ URL_TEST_ARRAY
+ };
+ static int naddresses = sizeof(addresses)/sizeof(addresses[0]);
+ for (int i = 0; i < naddresses; ++i)
+ {
+ ACE_URL_Addr* addr =
+ ACE_URL_Addr::create_address (addresses[i]);
+ if (addr == 0)
+ {
+ ACE_ERROR ((LM_ERROR,
+ "URL[%d]\n"
+ " \"%s\" ERROR\n",
+ i, addresses[i]));
+ continue;
+ }
+
+ ASYS_TCHAR buffer[BUFSIZ];
+ if (addr->addr_to_string (buffer, BUFSIZ, i%2) == 0)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "URL[%d]\n"
+ " \"%s\"\n"
+ " <%s>\n"
+ " <%s>\n",
+ i, addresses[i],
+ addr->get_url (),
+ buffer));
+ }
+ else
+ {
+ ACE_ERROR ((LM_ERROR,
+ "URL[%d]\n"
+ " \"%s\" ERROR\n",
+ i, addresses[i]));
+
+ }
+ }
+}
+
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */