summaryrefslogtreecommitdiff
path: root/websvcs
diff options
context:
space:
mode:
authorcoryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-01-24 05:55:27 +0000
committercoryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-01-24 05:55:27 +0000
commit74b88e2098f5852803b4522c573c54a5949960a8 (patch)
tree1c0d05831555e434f6909308ce5210afb900f212 /websvcs
parentc99bcf7bab5149f3ad603cf801a7698de5327901 (diff)
downloadATCD-74b88e2098f5852803b4522c573c54a5949960a8.tar.gz
ChangeLogTag:Sat Jan 23 23:53:29 1999 Carlos O'Ryan <coryan@cs.wustl.edu>
Diffstat (limited to 'websvcs')
-rw-r--r--websvcs/Makefile24
-rw-r--r--websvcs/lib/Makefile71
-rw-r--r--websvcs/lib/URL_Addr.cpp577
-rw-r--r--websvcs/lib/URL_Addr.h362
-rw-r--r--websvcs/lib/URL_Addr.i86
-rw-r--r--websvcs/lib/websvcs_export.h35
-rw-r--r--websvcs/tests/Makefile76
-rw-r--r--websvcs/tests/Test_URL_Addr.cpp112
8 files changed, 1343 insertions, 0 deletions
diff --git a/websvcs/Makefile b/websvcs/Makefile
new file mode 100644
index 00000000000..b98929bad75
--- /dev/null
+++ b/websvcs/Makefile
@@ -0,0 +1,24 @@
+#----------------------------------------------------------------------------
+# $Id$
+#
+# Makefile for the ACE websvcs services
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# Local macros
+#----------------------------------------------------------------------------
+
+# lib must come first!
+DIRS = lib \
+ tests \
+
+#----------------------------------------------------------------------------
+# Include macros and targets
+#----------------------------------------------------------------------------
+
+include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU
+include $(ACE_ROOT)/include/makeinclude/macros.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.common.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.nested.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.nolocal.GNU
+
diff --git a/websvcs/lib/Makefile b/websvcs/lib/Makefile
new file mode 100644
index 00000000000..5b1ac0069ea
--- /dev/null
+++ b/websvcs/lib/Makefile
@@ -0,0 +1,71 @@
+#----------------------------------------------------------------------------
+# $Id$
+#
+# Makefile for the server-side ACE WEB services
+#----------------------------------------------------------------------------
+
+LIB = libwebsvcs.a
+SHLIB = libwebsvcs.$(SOEXT)
+
+FILES = URL_Addr
+DEFS = $(addsuffix .h,$(FILES))
+LSRC = $(addsuffix .cpp,$(FILES))
+
+LIBS += $(ACELIB)
+
+BUILD = $(VLIB) $(VSHLIB)
+
+#----------------------------------------------------------------------------
+# Include macros and targets
+#----------------------------------------------------------------------------
+
+include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU
+include $(ACE_ROOT)/include/makeinclude/macros.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.common.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.lib.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.local.GNU
+
+#----------------------------------------------------------------------------
+# Local targets
+#----------------------------------------------------------------------------
+
+ifeq ($(SUPPRESS_DASH_G),1)
+#### Build this target without -g on some platforms.
+$(VDIR)Server_Logging_Handler.o $(VSHDIR)Server_Logging_Handler.$(SOEXT):
+ $(COMPILE-NO_DASH_G.cc) -o $@ $<
+endif # SUPPRESS_DASH_G
+
+#----------------------------------------------------------------------------
+# Dependencies
+#----------------------------------------------------------------------------
+# DO NOT DELETE THIS LINE -- g++dep uses it.
+# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
+
+.obj/URL_Addr.o .obj/URL_Addr.so .shobj/URL_Addr.o .shobj/URL_Addr.so: URL_Addr.cpp URL_Addr.h \
+ $(ACE_ROOT)/ace/INET_Addr.h \
+ $(ACE_ROOT)/ace/ACE.h \
+ $(ACE_ROOT)/ace/OS.h \
+ $(ACE_ROOT)/ace/inc_user_config.h \
+ $(ACE_ROOT)/ace/config.h \
+ $(ACE_ROOT)/ace/config-sunos5.5.h \
+ $(ACE_ROOT)/ace/config-g++-common.h \
+ $(ACE_ROOT)/ace/streams.h \
+ $(ACE_ROOT)/ace/Basic_Types.h \
+ $(ACE_ROOT)/ace/Basic_Types.i \
+ $(ACE_ROOT)/ace/OS.i \
+ $(ACE_ROOT)/ace/Trace.h \
+ $(ACE_ROOT)/ace/Log_Msg.h \
+ $(ACE_ROOT)/ace/Log_Record.h \
+ $(ACE_ROOT)/ace/ACE.i \
+ $(ACE_ROOT)/ace/Log_Priority.h \
+ $(ACE_ROOT)/ace/SString.h \
+ $(ACE_ROOT)/ace/SString.i \
+ $(ACE_ROOT)/ace/Malloc_Base.h \
+ $(ACE_ROOT)/ace/Log_Record.i \
+ $(ACE_ROOT)/ace/Addr.h \
+ $(ACE_ROOT)/ace/Addr.i \
+ $(ACE_ROOT)/ace/INET_Addr.i \
+ websvcs_export.h URL_Addr.i
+
+# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
diff --git a/websvcs/lib/URL_Addr.cpp b/websvcs/lib/URL_Addr.cpp
new file mode 100644
index 00000000000..2e4b9b6be33
--- /dev/null
+++ b/websvcs/lib/URL_Addr.cpp
@@ -0,0 +1,577 @@
+// $Id$
+
+#define ACE_WEBSVCS_BUILD_DLL
+#include "URL_Addr.h"
+
+#if !defined (__ACE_INLINE__)
+#include "ace/URL_Addr.i"
+#endif /* __ACE_INLINE__ */
+
+ACE_RCSID(ace, URL_Addr, "$Id$")
+
+static ASYS_TCHAR http[] = ASYS_TEXT ("http:");
+static size_t http_size = sizeof(http)/sizeof(http[0]) - 1;
+static ASYS_TCHAR ftp[] = ASYS_TEXT ("ftp:");
+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;
+
+ACE_URL_Addr::ACE_URL_Addr (void)
+ : url_ (0)
+{
+}
+
+ACE_URL_Addr::~ACE_URL_Addr ()
+{
+ ACE_OS::free (this->url_);
+ this->url_ = 0;
+}
+
+int
+ACE_URL_Addr::set (const ACE_URL_Addr& address)
+{
+ return this->ACE_URL_Addr::string_to_addr (address.url_);
+}
+
+int
+ACE_URL_Addr::string_to_addr (LPCTSTR address)
+{
+ if (this->url_ != 0)
+ ACE_OS::free (this->url_);
+ ACE_ALLOCATOR_RETURN (this->url_, ACE_OS::strdup (address), -1);
+ return 0;
+}
+
+int
+ACE_URL_Addr::addr_to_string (LPTSTR s,
+ size_t size,
+ int ipaddr_format) const
+{
+ if (size < ACE_OS::strlen (this->url_))
+ return -1;
+ ACE_OS::strcpy (s, this->url_);
+}
+
+int
+ACE_URL_Addr::accept (ACE_URL_Addr_Visitor* visitor)
+{
+ return visitor->visit (this);
+}
+
+// The factory method to create URL addresses.
+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);
+ else if (ACE_OS::strncmp (ftp, url, ftp_size) == 0)
+ ACE_NEW_RETURN (addr, ACE_FTP_Addr (), 0);
+ else if (ACE_OS::strncmp (mailto, url, mailto_size) == 0)
+ ACE_NEW_RETURN (addr, ACE_Mailto_Addr (), 0);
+ else
+ ACE_NEW_RETURN (addr, ACE_URL_Addr (), 0);
+
+ if (addr->string_to_addr (url) == -1)
+ {
+ delete addr;
+ addr = 0;
+ }
+ return addr;
+}
+
+// ****************************************************************
+
+ACE_URL_Addr_Visitor::~ACE_URL_Addr_Visitor (void)
+{
+}
+
+int
+ACE_URL_Addr_Visitor::visit (ACE_URL_Addr*)
+{
+ return 0;
+}
+
+int
+ACE_URL_Addr_Visitor::visit (ACE_HTTP_Addr*)
+{
+ return 0;
+}
+
+int
+ACE_URL_Addr_Visitor::visit (ACE_FTP_Addr*)
+{
+ return 0;
+}
+
+int
+ACE_URL_Addr_Visitor::visit (ACE_Mailto_Addr*)
+{
+ return 0;
+}
+
+// ****************************************************************
+
+ACE_HTTP_Addr::ACE_HTTP_Addr (void)
+ : hostname_ (0),
+ port_number_ (0),
+ path_ (0),
+ query_ (0)
+{
+}
+
+ACE_HTTP_Addr::ACE_HTTP_Addr (LPCTSTR host_name,
+ LPCTSTR path,
+ LPCTSTR query,
+ u_short port)
+ : hostname_ (0),
+ port_number_ (0),
+ path_ (0),
+ query_ (0)
+{
+ this->set (host_name, path, query, port);
+}
+
+ACE_HTTP_Addr::ACE_HTTP_Addr (const ACE_HTTP_Addr &addr)
+ : hostname_ (0),
+ port_number_ (0),
+ path_ (0),
+ query_ (0)
+{
+ this->set (addr);
+}
+
+ACE_HTTP_Addr::~ACE_HTTP_Addr (void)
+{
+ this->clear ();
+ this->hostname_ = 0;
+ this->path_ = 0;
+ this->query_ = 0;
+}
+
+int
+ACE_HTTP_Addr::set (LPCTSTR host_name,
+ LPCTSTR path,
+ LPCTSTR query,
+ u_short port)
+{
+ this->clear ();
+ ACE_ALLOCATOR_RETURN (this->hostname_, ACE_OS::strdup (host_name), -1);
+ ACE_ALLOCATOR_RETURN (this->path_, ACE_OS::strdup (path), -1);
+ ACE_ALLOCATOR_RETURN (this->query_, ACE_OS::strdup (query), -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_HTTP_Addr::set (const ACE_HTTP_Addr &addr)
+{
+ if (this->ACE_URL_Addr::set (addr) != 0)
+ return -1;
+ this->clear ();
+ ACE_ALLOCATOR_RETURN (this->hostname_, ACE_OS::strdup (addr.hostname_), -1);
+ ACE_ALLOCATOR_RETURN (this->path_, ACE_OS::strdup (addr.path_), -1);
+ ACE_ALLOCATOR_RETURN (this->query_, ACE_OS::strdup (addr.query_), -1);
+ return 0;
+}
+
+void
+ACE_HTTP_Addr::clear (void)
+{
+ if (this->hostname_ != 0)
+ ACE_OS::free (this->hostname_);
+ if (this->path_ != 0)
+ ACE_OS::free (this->path_);
+ if (this->query_ != 0)
+ ACE_OS::free (this->query_);
+}
+
+size_t
+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
+
+ if (flags == 0)
+ {
+ size += sizeof (ASYS_TEXT("255.255.255.255"));
+ }
+ else
+ {
+ size += ACE_OS::strlen (this->hostname_) * sizeof(ASYS_TCHAR);
+ }
+
+ if (this->port_number_ != ACE_DEFAULT_HTTP_PORT)
+ {
+ size += sizeof (ASYS_TEXT(":65335"));
+ }
+
+ return size;
+}
+
+int
+ACE_HTTP_Addr::string_to_addr (LPCTSTR address)
+{
+ if (ACE_OS::strncmp (http, address, http_size) != 0)
+ return -1;
+
+ this->clear ();
+ this->hostname_ = 0;
+ this->path_ = 0;
+ this->query_ = 0;
+
+ // Save the original URL....
+ this->ACE_URL_Addr::string_to_addr (address);
+
+ LPCTSTR string = address;
+ string += http_size;
+ ASYS_TCHAR separator[] = ASYS_TEXT("//");
+ string += sizeof(separator)/sizeof(separator[0]) - 1;
+
+ // Make a copy of the string to manipulate it.
+ ASYS_TCHAR *t;
+ ACE_ALLOCATOR_RETURN (t, ACE_OS::strdup (string), -1);
+
+ ASYS_TCHAR *path_start = ACE_OS::strchr (t, '/');
+ if (path_start != 0)
+ {
+ // terminate the host:port substring
+ path_start[0] = '\0';
+ path_start++;
+ ASYS_TCHAR *query_start = ACE_OS::strchr (path_start, '?');
+ if (query_start != 0)
+ {
+ query_start[0] = '\0';
+ query_start++;
+ ACE_ALLOCATOR_RETURN (this->query_,
+ ACE_OS::strdup (query_start),
+ -1);
+ }
+ ACE_ALLOCATOR_RETURN (this->path_, ACE_OS::strdup (path_start), -1);
+ }
+
+ // By now t is null terminated at the start of the path, find the
+ // port (if present).
+ ASYS_TCHAR *port_start = ACE_OS::strchr(t, ':');
+ this->port_number_ = ACE_DEFAULT_HTTP_PORT;
+ if (port_start != 0)
+ {
+ // terminate the ipaddr.
+ port_start[0] = '\0';
+ port_start++;
+ this->port_number_ = ACE_OS::atoi (port_start);
+ }
+ this->hostname_ = t;
+
+ return 0;
+}
+
+int
+ACE_HTTP_Addr::addr_to_string (LPTSTR buffer,
+ size_t size,
+ int flags) const
+{
+ if (size < this->url_size (flags))
+ return -1;
+
+ if (this->hostname_ == 0)
+ return -1;
+
+ size_t n = ACE_OS::sprintf (buffer,
+ ASYS_TEXT ("http://"));
+ if (flags == 0)
+ {
+ ACE_INET_Addr inet = this->get_inet_address ();
+ n += ACE_OS::sprintf (buffer + n, "%s", inet.get_host_addr ());
+ }
+ else
+ {
+ n += ACE_OS::sprintf (buffer + n, "%s", this->hostname_);
+ }
+
+ if (this->port_number_ != ACE_DEFAULT_HTTP_PORT)
+ {
+ n += ACE_OS::sprintf (buffer + n, ":%d", this->port_number_);
+ }
+ if (this->path_ != 0)
+ {
+ n += ACE_OS::sprintf (buffer + n, "/%s", this->path_);
+ }
+ if (this->query_ != 0)
+ {
+ n += ACE_OS::sprintf (buffer + n, "?%s", this->query_);
+ }
+ return 0;
+}
+
+int
+ACE_HTTP_Addr::accept (ACE_URL_Addr_Visitor *visitor)
+{
+ return visitor->visit (this);
+}
+
+// ****************************************************************
+
+ACE_FTP_Addr::ACE_FTP_Addr (void)
+ : user_ (0),
+ passwd_ (0),
+ hostname_ (0),
+ path_ (0)
+{
+}
+
+ACE_FTP_Addr::ACE_FTP_Addr (LPCTSTR host_name,
+ LPCTSTR path,
+ LPCTSTR user,
+ LPCTSTR passwd)
+ : user_ (0),
+ passwd_ (0),
+ hostname_ (0),
+ path_ (0)
+{
+ this->set (host_name, path, user, passwd);
+}
+
+ACE_FTP_Addr::ACE_FTP_Addr (const ACE_FTP_Addr& addr)
+ : user_ (0),
+ passwd_ (0),
+ hostname_ (0),
+ path_ (0)
+{
+ this->set (addr);
+}
+
+ACE_FTP_Addr::~ACE_FTP_Addr (void)
+{
+ this->clear ();
+}
+
+int
+ACE_FTP_Addr::set (LPCTSTR host_name,
+ LPCTSTR path,
+ LPCTSTR user,
+ LPCTSTR passwd)
+{
+ this->clear ();
+ ACE_ALLOCATOR_RETURN (this->hostname_, ACE_OS::strdup (host_name), -1);
+ ACE_ALLOCATOR_RETURN (this->path_, ACE_OS::strdup (path), -1);
+ ACE_ALLOCATOR_RETURN (this->user_, ACE_OS::strdup (user), -1);
+ ACE_ALLOCATOR_RETURN (this->passwd_, ACE_OS::strdup (passwd), -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_FTP_Addr::set (const ACE_FTP_Addr& addr)
+{
+ if (this->ACE_URL_Addr::set (addr) != 0)
+ return -1;
+ this->clear ();
+ ACE_ALLOCATOR_RETURN (this->hostname_, ACE_OS::strdup (addr.hostname_), -1);
+ ACE_ALLOCATOR_RETURN (this->path_, ACE_OS::strdup (addr.path_), -1);
+ ACE_ALLOCATOR_RETURN (this->user_, ACE_OS::strdup (addr.user_), -1);
+ ACE_ALLOCATOR_RETURN (this->passwd_, ACE_OS::strdup (addr.passwd_), -1);
+ return 0;
+}
+
+void
+ACE_FTP_Addr::clear (void)
+{
+ if (this->hostname_ != 0)
+ ACE_OS::free (this->hostname_);
+ if (this->path_ != 0)
+ ACE_OS::free (this->path_);
+ if (this->user_ != 0)
+ ACE_OS::free (this->user_);
+ if (this->passwd_ != 0)
+ ACE_OS::free (this->passwd_);
+}
+
+size_t
+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
+
+ if (flags == 0)
+ {
+ size += sizeof (ASYS_TEXT("255.255.255.255"));
+ }
+ else
+ {
+ size += ACE_OS::strlen (this->hostname_) * sizeof(ASYS_TCHAR);
+ }
+
+ return size;
+}
+
+int
+ACE_FTP_Addr::addr_to_string (LPTSTR buffer,
+ size_t size,
+ int flags) const
+{
+ if (size < this->url_size (flags))
+ return -1;
+
+ size_t n = ACE_OS::sprintf (buffer,
+ ASYS_TEXT ("ftp://"));
+
+ if (this->user_ != 0)
+ {
+ n += ACE_OS::sprintf (buffer + n, "%s", this->user_);
+ }
+ if (this->passwd_ != 0)
+ {
+ n += ACE_OS::sprintf (buffer + n, ":%s", this->passwd_);
+ }
+
+ if (this->user_ != 0)
+ {
+ n += ACE_OS::sprintf (buffer + n, "@");
+ }
+
+ if (flags == 0)
+ {
+ ACE_INET_Addr inet = this->get_inet_address ();
+ n += ACE_OS::sprintf (buffer + n, "%s", inet.get_host_addr ());
+ }
+ else
+ {
+ n += ACE_OS::sprintf (buffer + n, "%s", this->hostname_);
+ }
+ if (this->path_ != 0)
+ {
+ n += ACE_OS::sprintf (buffer + n, "/%s", this->path_);
+ }
+ return 0;
+}
+
+int
+ACE_FTP_Addr::string_to_addr (LPCTSTR address)
+{
+ if (ACE_OS::strncmp (ftp, address, ftp_size) != 0)
+ return -1;
+
+ this->clear ();
+ this->hostname_ = 0;
+ this->user_ = 0;
+ this->passwd_ = 0;
+ this->path_ = 0;
+
+ // Save the original URL....
+ this->ACE_URL_Addr::string_to_addr (address);
+
+ LPCTSTR string = address;
+ string += ftp_size;
+ ASYS_TCHAR separator[] = ASYS_TEXT("//");
+ string += sizeof(separator)/sizeof(separator[0]) - 1;
+
+ // Make a copy of the string to manipulate it.
+ ASYS_TCHAR *t;
+ ACE_ALLOCATOR_RETURN (t, ACE_OS::strdup (string), -1);
+
+ ASYS_TCHAR *path_start = ACE_OS::strchr (t, '/');
+ if (path_start != 0)
+ {
+ // terminate the host:port substring
+ path_start[0] = '\0';
+ path_start++;
+ ACE_ALLOCATOR_RETURN (this->path_, ACE_OS::strdup (path_start), -1);
+ }
+
+ ASYS_TCHAR *host_start = ACE_OS::strchr (t, '@');
+ if (host_start != 0)
+ {
+ host_start[0] = '\0';
+ host_start++;
+ ACE_ALLOCATOR_RETURN (this->hostname_,
+ ACE_OS::strdup (host_start),
+ -1);
+ ASYS_TCHAR *pass_start = ACE_OS::strchr (t, ':');
+ if (pass_start != 0)
+ {
+ pass_start[0] = '\0';
+ pass_start++;
+ ACE_ALLOCATOR_RETURN (this->passwd_,
+ ACE_OS::strdup (pass_start),
+ -1);
+ }
+ this->user_ = t;
+ }
+ else
+ {
+ this->hostname_ = t;
+ }
+
+ return 0;
+}
+
+int
+ACE_FTP_Addr::accept (ACE_URL_Addr_Visitor* visitor)
+{
+ return visitor->visit (this);
+}
+
+// ****************************************************************
+
+ACE_Mailto_Addr::ACE_Mailto_Addr (void)
+{
+}
+
+ACE_Mailto_Addr::~ACE_Mailto_Addr (void)
+{
+}
+
+int
+ACE_Mailto_Addr::addr_to_string (LPTSTR buffer,
+ size_t size,
+ int flags) const
+{
+ return 0;
+}
+
+int
+ACE_Mailto_Addr::string_to_addr (LPCTSTR address)
+{
+ // @@
+ return 0;
+}
+
+int
+ACE_Mailto_Addr::accept (ACE_URL_Addr_Visitor* visitor)
+{
+ return visitor->visit (this);
+}
+
diff --git a/websvcs/lib/URL_Addr.h b/websvcs/lib/URL_Addr.h
new file mode 100644
index 00000000000..c04a1fd7b3c
--- /dev/null
+++ b/websvcs/lib/URL_Addr.h
@@ -0,0 +1,362 @@
+/* -*- C++ -*- */
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// ace
+//
+// = FILENAME
+// URL_Addr.h
+//
+// = AUTHOR
+// Douglas C. Schmidt <schmidt@cs.wustl.edu>
+//
+// ============================================================================
+
+#ifndef ACE_URL_ADDR_H
+#define ACE_URL_ADDR_H
+
+#include "ace/INET_Addr.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+#include "websvcs_export.h"
+
+class ACE_URL_Addr_Visitor;
+
+class ACE_WEBSVCS_Export ACE_URL_Addr : public ACE_Addr
+{
+ // = TITLE
+ // Defines the interface for an URL
+ //
+ // = DESCRIPTION
+ // All URLs derive from this class
+ //
+public:
+ ACE_URL_Addr (void);
+ // Constructor.
+
+ ACE_URL_Addr (const ACE_URL_Addr& address);
+ // The copy constructor.
+
+ LPCTSTR get_url (void) const;
+ // Get the original URL
+
+ int set (const ACE_URL_Addr& address);
+ // Essentially the copy contructor.
+
+ virtual ~ACE_URL_Addr (void);
+
+ virtual int string_to_addr (LPCTSTR address);
+ // Initializes from the scheme specific address, for instance: if
+ // the address is an http URL it will initialize the address from
+ // an string such as "www.cs.wustl.edu/~schmidt"
+
+ virtual int addr_to_string (LPTSTR s,
+ size_t size,
+ int flags = 0) const;
+ // Write the address in the scheme specific representation.
+ // <flags> provides control over scheme specific features (such as
+ // using numeric vs. fully qualified host names).
+
+ virtual int accept (ACE_URL_Addr_Visitor* visitor);
+ // The accept method in the Visitor Pattern. Should return 0 on
+ // success and not 0 on failure.
+
+ 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".
+
+protected:
+ void set_url (LPTSTR url);
+ // Allows the derived classes to store the compact representation of
+ // the URL
+
+private:
+ LPTSTR url_;
+};
+
+class ACE_HTTP_Addr;
+class ACE_FTP_Addr;
+class ACE_Mailto_Addr;
+// @@ TODO add more URP schemes as needed.
+// class ACE_File_Addr;
+// class ACE_AFS_Addr;
+// class ACE_News_Addr;
+// class ACE_NNTP_Addr;
+// class ACE_CID_Addr;
+// class ACE_MID_Addr;
+// class ACE_WAIS_Addr;
+// class ACE_Prospero_Addr;
+// class ACE_Telnet_Addr;
+// class ACE_Rlogin_Addr;
+// class ACE_TN3270_Addr;
+// class ACE_Gopher_Addr;
+
+class ACE_WEBSVCS_Export ACE_URL_Addr_Visitor
+{
+ // = TITLE
+ // Implements a Visitor object for the ACE_URL hierarchy.
+ //
+ // = DESCRIPTION
+ // The manipulation of URL objects is much simpler if we use the
+ // Visitor pattern to solve the double dispatch problem between
+ // the "what to do on a URL" vs. "what to do on each kind of
+ // URL".
+ //
+public:
+ virtual ~ACE_URL_Addr_Visitor (void);
+ // Destructor
+
+ virtual int visit (ACE_URL_Addr*);
+ virtual int visit (ACE_HTTP_Addr*);
+ virtual int visit (ACE_FTP_Addr*);
+ virtual int visit (ACE_Mailto_Addr*);
+ // The visit methods for all the hierarchy.
+ // The default implementation is a nop (instead of a pure virtual
+ // function) to facilitate the addition of new members in the
+ // hierarchy.
+ // virtual int visit (ACE_AFS_Addr*);
+ // virtual int visit (ACE_News_Addr*);
+ // virtual int visit (ACE_NNTP_Addr*);
+};
+
+// ****************************************************************
+
+class ACE_WEBSVCS_Export ACE_HTTP_Addr : public ACE_URL_Addr
+{
+ // = TITLE
+ // Defines the HTTP scheme addresses
+ //
+ // = DESCRIPTION
+ // Encapsulates an HTTP URL; the most general form is:
+ //
+ // http://host:port/path?query
+ //
+ // but these are also accepted:
+ //
+ // http://host/path?query
+ // http://host:port/path
+ // http://host/path
+ //
+public:
+ ACE_HTTP_Addr (void);
+ // Constructor
+
+ ACE_HTTP_Addr (LPCTSTR host_name,
+ LPCTSTR path,
+ LPCTSTR query = 0,
+ u_short port = ACE_DEFAULT_HTTP_PORT);
+ // Construct an HTTP URL from the host, path, query and port.
+
+ int set (LPCTSTR host_name,
+ LPCTSTR path,
+ LPCTSTR query = 0,
+ u_short port = ACE_DEFAULT_HTTP_PORT);
+ // Essentially the constructor above.
+
+ ACE_HTTP_Addr (const ACE_HTTP_Addr &addr);
+ // Copy constructor.
+
+ int set (const ACE_HTTP_Addr &addr);
+ // Essentially the copy constructor.
+
+ virtual ~ACE_HTTP_Addr (void);
+ // Destructor
+
+ ACE_INET_Addr get_inet_address (void) const;
+ // Build the INET_Address implicit in the URL, notice that we
+ // maintain the hostname in its string representation, because the
+ // URL can be can be refering to an hostname that cannot be
+ // validated at this point.
+
+ LPCTSTR get_hostname (void) const;
+ // Get the name of the host.
+
+ u_short get_port_number (void) const;
+ // Get the port number.
+
+ LPCTSTR get_path (void) const;
+ // Get the path component in the URL
+
+ LPCTSTR get_query (void) const;
+ // Get the query component in the URL
+
+ // = The ACE_URL methods, see the documentation above.
+ virtual int string_to_addr (LPCTSTR address);
+ virtual int addr_to_string (LPTSTR s,
+ size_t size,
+ int flags = 0) const;
+ virtual int accept (ACE_URL_Addr_Visitor* visitor);
+
+private:
+ 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 hostname_;
+ u_short port_number_;
+ // The host:port component in the URL
+
+ LPTSTR path_;
+ // The path component in the URL
+
+ LPTSTR query_;
+ // The query component in the URL
+};
+
+// ****************************************************************
+
+class ACE_WEBSVCS_Export ACE_FTP_Addr : public ACE_URL_Addr
+{
+ // = TITLE
+ // Defines the FTP scheme addresses
+ //
+ // = DESCRIPTION
+ // Encapsulates an FTP URL; usually an FTP URL is of the form:
+ //
+ // ftp://hostname/path
+ //
+ // but the most general form is:
+ //
+ // ftp://user:passwd@hostname/path
+ //
+ // the [:passwd] part can be omitted too.
+ //
+public:
+ ACE_FTP_Addr (void);
+ // Constructor
+
+ ACE_FTP_Addr (LPCTSTR host_name,
+ LPCTSTR path,
+ LPCTSTR user = 0,
+ LPCTSTR passwd = 0);
+ // Construct an FTP URL from the host_name, the path, the username
+ // and the passwd.
+
+ int set (LPCTSTR host_name,
+ LPCTSTR path,
+ LPCTSTR user = 0,
+ LPCTSTR passwd = 0);
+ // Essentially the constructor above.
+
+ ACE_FTP_Addr (const ACE_FTP_Addr &addr);
+ // Copy constructor.
+
+ int set (const ACE_FTP_Addr &addr);
+ // Essentially the copy constructor.
+
+ virtual ~ACE_FTP_Addr (void);
+ // Destructor
+
+ LPCTSTR get_hostname (void) const;
+ // Get the host name component in the URL
+
+ LPCTSTR get_user (void) const;
+ // Get the username component in the URL
+
+ LPCTSTR get_passwd (void) const;
+ // Get the passwd component in the URL
+
+ LPCTSTR get_path (void) const;
+ // Get the path component in the URL
+
+ ACE_INET_Addr get_inet_address (void) const;
+ // Obtain the INET_Address implicit in the URL, can be used to
+ // obtain the host and the port.
+
+ // = The ACE_Addr methods, see the documentation above.
+ virtual int string_to_addr (LPCTSTR address);
+ virtual int addr_to_string (LPTSTR s,
+ size_t size,
+ int flags = 0) const;
+ virtual int accept (ACE_URL_Addr_Visitor* visitor);
+
+private:
+ 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 release the internal resources
+
+private:
+ LPTSTR user_;
+ LPTSTR passwd_;
+ // The login name
+
+ LPTSTR hostname_;
+ // The hostname part.
+
+ LPTSTR path_;
+ // The other components.
+};
+
+// ****************************************************************
+
+class ACE_WEBSVCS_Export ACE_Mailto_Addr : public ACE_URL_Addr
+{
+ // = TITLE
+ // Defines the mailto scheme addresses
+ //
+ // = DESCRIPTION
+ // Encapsulates an URL that refers to an email address.
+ //
+public:
+ ACE_Mailto_Addr (void);
+ // Constructor
+
+ ACE_Mailto_Addr (LPCTSTR name,
+ LPCTSTR hostname,
+ LPCTSTR headers = 0);
+ // Construct an FTP URL from the host, path and headers.
+
+ int set (LPCTSTR name,
+ LPCTSTR hostname,
+ LPCTSTR headers = 0);
+ // Essentially the constructor above.
+
+ ACE_Mailto_Addr (const ACE_Mailto_Addr &addr);
+ // Copy constructor.
+
+ int set (const ACE_Mailto_Addr &addr);
+ // Essentially the copy constructor.
+
+ virtual ~ACE_Mailto_Addr (void);
+ // Destructor
+
+ LPCTSTR get_hostname (void) const;
+ // Get the path component in the URL
+
+ LPCTSTR get_headers (void) const;
+ // Get the headers as a single string
+
+ // @@ TODO A mailto: URL can contain multiple headers, an iterator
+ // over them would be a good idea. Similarly a method to *add*
+ // headers would be nice also.
+
+ // = The ACE_URL methods, see the documentation above.
+ virtual int string_to_addr (LPCTSTR address);
+ virtual int addr_to_string (LPTSTR s,
+ size_t size,
+ int flags = 0) const;
+ virtual int accept (ACE_URL_Addr_Visitor* visitor);
+
+private:
+ LPTSTR name_;
+ LPTSTR hostname_;
+ LPTSTR headers_;
+};
+
+#if defined (__ACE_INLINE__)
+#include "URL_Addr.i"
+#endif /* __ACE_INLINE__ */
+
+#endif /* ACE_URL_ADDR_H */
diff --git a/websvcs/lib/URL_Addr.i b/websvcs/lib/URL_Addr.i
new file mode 100644
index 00000000000..aaeddb6266c
--- /dev/null
+++ b/websvcs/lib/URL_Addr.i
@@ -0,0 +1,86 @@
+// $Id$
+
+// ****************************************************************
+
+ACE_INLINE
+ACE_URL_Addr::ACE_URL_Addr (const ACE_URL_Addr& address)
+ : url_ (ACE_OS::strdup (address.url_))
+{
+}
+
+ACE_INLINE LPCTSTR
+ACE_URL_Addr::get_url (void) const
+{
+ return this->url_;
+}
+
+ACE_INLINE void
+ACE_URL_Addr::set_url (LPTSTR url)
+{
+ this->url_ = url;
+}
+
+// ****************************************************************
+
+ACE_INLINE ACE_INET_Addr
+ACE_HTTP_Addr::get_inet_address (void) const
+{
+ return ACE_INET_Addr (this->port_number_, this->hostname_);
+}
+
+ACE_INLINE LPCTSTR
+ACE_HTTP_Addr::get_hostname (void) const
+{
+ return this->hostname_;
+}
+
+ACE_INLINE u_short
+ACE_HTTP_Addr::get_port_number (void) const
+{
+ return this->port_number_;
+}
+
+ACE_INLINE LPCTSTR
+ACE_HTTP_Addr::get_path (void) const
+{
+ return this->path_;
+}
+
+ACE_INLINE LPCTSTR
+ACE_HTTP_Addr::get_query (void) const
+{
+ return this->query_;
+}
+
+// ****************************************************************
+
+ACE_INLINE LPCTSTR
+ACE_FTP_Addr::get_user (void) const
+{
+ return this->user_;
+}
+
+ACE_INLINE LPCTSTR
+ACE_FTP_Addr::get_hostname (void) const
+{
+ return this->hostname_;
+}
+
+ACE_INLINE LPCTSTR
+ACE_FTP_Addr::get_passwd (void) const
+{
+ return this->passwd_;
+}
+
+ACE_INLINE LPCTSTR
+ACE_FTP_Addr::get_path (void) const
+{
+ return this->path_;
+}
+
+ACE_INLINE ACE_INET_Addr
+ACE_FTP_Addr::get_inet_address (void) const
+{
+ return ACE_INET_Addr (ASYS_TEXT ("ftp"), this->hostname_);
+}
+
diff --git a/websvcs/lib/websvcs_export.h b/websvcs/lib/websvcs_export.h
new file mode 100644
index 00000000000..92ce0ccbc4f
--- /dev/null
+++ b/websvcs/lib/websvcs_export.h
@@ -0,0 +1,35 @@
+// $Id$
+
+// Definition for Win32 Export directives.
+// This file is generated automatically by
+// ${TAO_ROOT}/TAO_IDL/GenExportH.BAT
+// ------------------------------
+#ifndef ACE_WEBSVCS_EXPORT_H
+#define ACE_WEBSVCS_EXPORT_H
+
+#include "ace/OS.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+#if defined (ACE_WEBSVCS_HAS_DLL)
+# if (ACE_WEBSVCS_HAS_DLL == 1)
+# if defined (ACE_WEBSVCS_BUILD_DLL)
+# define ACE_WEBSVCS_Export ACE_Proper_Export_Flag
+# define ACE_WEBSVCS_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T)
+# else
+# define ACE_WEBSVCS_Export ACE_Proper_Import_Flag
+# define ACE_WEBSVCS_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T)
+# endif /* ACE_WEBSVCS_BUILD_DLL */
+# else
+# define ACE_WEBSVCS_Export
+# define ACE_WEBSVCS_SINGLETON_DECLARATION(T)
+# endif /* ! ACE_WEBSVCS_HAS_DLL == 1 */
+#else
+# define ACE_WEBSVCS_Export
+# define ACE_WEBSVCS_SINGLETON_DECLARATION(T)
+#endif /* ACE_WEBSVCS_HAS_DLL */
+
+#endif /* ACE_WEBSVCS_EXPORT_H */
+ // End of auto generated file.
diff --git a/websvcs/tests/Makefile b/websvcs/tests/Makefile
new file mode 100644
index 00000000000..cdd9a16c3fc
--- /dev/null
+++ b/websvcs/tests/Makefile
@@ -0,0 +1,76 @@
+#----------------------------------------------------------------------------
+#
+# $Id$
+#
+# Makefile for all the ACE/websvcs ``one-button' tests
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# Local macros
+#----------------------------------------------------------------------------
+
+BIN = Test_URL_Addr
+
+LSRC = $(addsuffix .cpp,$(BIN))
+
+BUILD = $(VBIN)
+
+#----------------------------------------------------------------------------
+# Include macros and targets
+#----------------------------------------------------------------------------
+
+include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU
+include $(ACE_ROOT)/include/makeinclude/macros.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.common.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.bin.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.local.GNU
+
+VLDLIBS := -lwebsvcs $(VLDLIBS)
+
+# To build multiple executables in the same directory on AIX, it works
+# best to wipe out any previously-created tempinc directory.
+# The compiler/linker isn't too smart about instantiating templates...
+ifdef TEMPINCDIR
+COMPILE.cc := $(RM) -rf tempinc; $(COMPILE.cc)
+endif
+
+#----------------------------------------------------------------------------
+# Local targets
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# Dependencies
+#----------------------------------------------------------------------------
+# DO NOT DELETE THIS LINE -- g++dep uses it.
+# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
+
+.obj/Test_URL_Addr.o .obj/Test_URL_Addr.so .shobj/Test_URL_Addr.o .shobj/Test_URL_Addr.so: Test_URL_Addr.cpp \
+ $(ACE_ROOT)/websvcs/lib/URL_Addr.h \
+ $(ACE_ROOT)/ace/INET_Addr.h \
+ $(ACE_ROOT)/ace/ACE.h \
+ $(ACE_ROOT)/ace/OS.h \
+ $(ACE_ROOT)/ace/inc_user_config.h \
+ $(ACE_ROOT)/ace/config.h \
+ $(ACE_ROOT)/ace/config-sunos5.5.h \
+ $(ACE_ROOT)/ace/config-g++-common.h \
+ $(ACE_ROOT)/ace/streams.h \
+ $(ACE_ROOT)/ace/Basic_Types.h \
+ $(ACE_ROOT)/ace/Basic_Types.i \
+ $(ACE_ROOT)/ace/OS.i \
+ $(ACE_ROOT)/ace/Trace.h \
+ $(ACE_ROOT)/ace/Log_Msg.h \
+ $(ACE_ROOT)/ace/Log_Record.h \
+ $(ACE_ROOT)/ace/ACE.i \
+ $(ACE_ROOT)/ace/Log_Priority.h \
+ $(ACE_ROOT)/ace/SString.h \
+ $(ACE_ROOT)/ace/SString.i \
+ $(ACE_ROOT)/ace/Malloc_Base.h \
+ $(ACE_ROOT)/ace/Log_Record.i \
+ $(ACE_ROOT)/ace/Addr.h \
+ $(ACE_ROOT)/ace/Addr.i \
+ $(ACE_ROOT)/ace/INET_Addr.i \
+ $(ACE_ROOT)/websvcs/lib/websvcs_export.h \
+ $(ACE_ROOT)/websvcs/lib/URL_Addr.i
+
+# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
diff --git a/websvcs/tests/Test_URL_Addr.cpp b/websvcs/tests/Test_URL_Addr.cpp
new file mode 100644
index 00000000000..27fecd854b2
--- /dev/null
+++ b/websvcs/tests/Test_URL_Addr.cpp
@@ -0,0 +1,112 @@
+// $Id$
+
+#include "websvcs/lib/URL_Addr.h"
+
+ACE_RCSID(WEBSVCS_Test, Test_URL_Addr, "$Id$")
+
+void test_http_addr (void);
+void test_ftp_addr (void);
+void test_url_addr (void);
+
+int main (int, char*[])
+{
+ test_http_addr ();
+ test_ftp_addr ();
+ return 0;
+}
+
+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//")
+ };
+ static int naddresses = sizeof(addresses)/sizeof(addresses[0]);
+ for (int i = 0; i < naddresses; ++i)
+ {
+ ACE_HTTP_Addr addr;
+ if (addr.string_to_addr (addresses[i]) != 0)
+ {
+ ACE_ERROR ((LM_ERROR,
+ "HTTP[%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,
+ "HTTP[%d]\n"
+ " \"%s\"\n"
+ " <%s>\n"
+ " <%s>\n",
+ i, addresses[i],
+ addr.get_url (),
+ buffer));
+ }
+ else
+ {
+ ACE_ERROR ((LM_ERROR,
+ "HTTP[%d]\n"
+ " \"%s\" ERROR\n",
+ i, addresses[i]));
+ }
+ }
+}
+
+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"),
+ };
+ static int naddresses = sizeof(addresses)/sizeof(addresses[0]);
+ for (int i = 0; i < naddresses; ++i)
+ {
+ ACE_FTP_Addr addr;
+ if (addr.string_to_addr (addresses[i]) != 0)
+ {
+ ACE_ERROR ((LM_ERROR,
+ "FTP[%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,
+ "FTP[%d]\n"
+ " \"%s\"\n"
+ " <%s>\n"
+ " <%s>\n",
+ i, addresses[i],
+ addr.get_url (),
+ buffer));
+ }
+ else
+ {
+ ACE_ERROR ((LM_ERROR,
+ "FTP[%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 */