diff options
author | kirthika <kirthika@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-05-03 20:10:01 +0000 |
---|---|---|
committer | kirthika <kirthika@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-05-03 20:10:01 +0000 |
commit | 5f0e54917fcfd2c48810eb97219cb5177d91f1f9 (patch) | |
tree | 02f61f1caf84d9b9474989bec5427421686fd185 /examples | |
parent | c28e263fdf7db735972b528b44fd51b3f2727843 (diff) | |
download | ATCD-5f0e54917fcfd2c48810eb97219cb5177d91f1f9.tar.gz |
part of HTTP_Client example
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Web_Crawler/HTTP_URL.cpp | 101 | ||||
-rw-r--r-- | examples/Web_Crawler/HTTP_URL.h | 64 |
2 files changed, 165 insertions, 0 deletions
diff --git a/examples/Web_Crawler/HTTP_URL.cpp b/examples/Web_Crawler/HTTP_URL.cpp new file mode 100644 index 00000000000..c57a4aa0445 --- /dev/null +++ b/examples/Web_Crawler/HTTP_URL.cpp @@ -0,0 +1,101 @@ +// $Id$ + +#include "ace/Auto_Ptr.h" +#include "URL_Visitor.h" +#include "Options.h" +#include "HTTP_URL.h" + +ACE_RCSID(HTTP_1.1_Client, HTTP_URL, "$Id$") + +const ACE_URL_Addr & +HTTP_URL::url_addr (void) const +{ + return this->url_addr_; +} + +HTTP_URL::HTTP_URL (const ACE_URL_Addr &url_addr, + HTTP_URL *cp) + : url_addr_ (url_addr), + containing_page_ (cp == 0 ? this : cp) +{ + ACE_DEBUG ((LM_DEBUG, "HTTP_URL %s\n", url_addr.addr_to_string ())); +} + +int +HTTP_URL::send_request (void) +{ + /* + // Since this is HTTP 1.1 we'll need to establish a connection + // only once. Trying for relative paths. + // if (this->url_addr ().get_hostname () != url_hostname) + // { + if (this->stream ().open (this->url_addr ()) == -1) + return -1; + // }*/ + int commandsize = + ACE_OS::strlen (this->url_addr ().get_path_name ()) + + ACE_OS::strlen (this->url_addr ().get_host_name ()) + + 20 // Extra + + 1 // NUL byte + + 16; // Protocol filler... + + + char *command; + ACE_NEW_RETURN (command, + char[commandsize], + -1); + + // Ensure that the <command> memory is deallocated. + ACE_Auto_Basic_Array_Ptr<char> cmd_ptr (command); + + ACE_OS::sprintf (cmd_ptr.get (), + "GET /%s HTTP/1.1\r\n", + this->url_addr ().get_path_name ()); + + ACE_DEBUG ((LM_DEBUG, "Command:%s length %d", + cmd_ptr.get (), + ACE_OS::strlen (cmd_ptr.get ()))); + + // Send the GET command to the connected server. + if (this->stream ().send_n (cmd_ptr.get (), + ACE_OS::strlen (cmd_ptr.get ()), + ACE_const_cast (ACE_Time_Value *, + OPTIONS::instance ()->timeout ())) > 0) + { + ACE_OS::sprintf (cmd_ptr.get (), + "Host: %s\r\n\r\n", + this->url_addr ().get_host_name ()); + + ACE_DEBUG ((LM_DEBUG, "Command:%s length %d", + cmd_ptr.get (), + ACE_OS::strlen (cmd_ptr.get ()))); + + // IMP: The length of teh command has to be sent! + int retval = this->stream ().send_n (cmd_ptr.get (), + ACE_OS::strlen (cmd_ptr.get ()), + ACE_const_cast (ACE_Time_Value *, + OPTIONS::instance ()->timeout ())); + this->stream ().svc_handler ()->idle (0); //KIRTHIKA + if (retval <= 0) + return -1; + else + return retval; + } + else + return -1; +} + +int +HTTP_URL::accept (URL_Visitor *visitor) +{ + // This is part of the visitor pattern. + return visitor->visit (*this); +} + +int +HTTP_URL::destroy (void) +{ + delete this; + return 0; + // Commit suicide! +} diff --git a/examples/Web_Crawler/HTTP_URL.h b/examples/Web_Crawler/HTTP_URL.h new file mode 100644 index 00000000000..b571b1043f8 --- /dev/null +++ b/examples/Web_Crawler/HTTP_URL.h @@ -0,0 +1,64 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// apps/Web +// +// = FILENAME +// HTTP_URL.h +// +// = AUTHOR +// Douglas C. Schmidt <schmidt@cs.wustl.edu> +// +// ============================================================================ + +#ifndef _HTTP_URL_H +#define _HTTP_URL_H + +#include "URL_Status.h" +#include "URL.h" +#include "Options.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +#define ACE_LACKS_PRAGMA_ONCE +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +class HTTP_URL : public URL +{ + // = TITLE + // An ADT for an HTTP URL. + // + // = DESCRIPTION + // This class plays the "element" role in the Visitor pattern. +public: + HTTP_URL (const ACE_URL_Addr &url_addr, + HTTP_URL *containing_page = 0); + // The <url_addr> is the URL that we're going to be visiting. We + // also keep track of the containing page, if any, which is used to + // print out more meaningful messages. + + virtual int accept (URL_Visitor *visitor); + // Accept the visitor, which will then perform a particular + // visitation strategy on the URL. This method is part of the + // Visitor pattern. + + virtual int send_request (void); + // Send a <GET> command to fetch the contents in the URI from the + // server. + + virtual const ACE_URL_Addr &url_addr (void) const; + // Returns the URL that we represent. + + int destroy (void); + // Commit suicide +private: + ACE_URL_Addr url_addr_; + // Address of the URL we're connected to. + + HTTP_URL *containing_page_; + // Page that contained us. +}; + +#endif /* _HTTP_URL_H */ |