TAO_HTTP_Parser Class Reference

Implements the <http:> IOR format. More...

#include <HTTP_Parser.h>

Inheritance diagram for TAO_HTTP_Parser:

Inheritance graph
[legend]
Collaboration diagram for TAO_HTTP_Parser:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual ~TAO_HTTP_Parser (void)
 The destructor.
virtual bool match_prefix (const char *ior_string) const
virtual CORBA::Object_ptr parse_string (const char *ior, CORBA::ORB_ptr orb)

Detailed Description

Implements the <http:> IOR format.

This class implements the <http:> IOR format. It is dynamically loaded by the ORB and used to get an IOR from a http server and then interprete the data as an IOR (that can be in any valid format).

Definition at line 41 of file HTTP_Parser.h.


Constructor & Destructor Documentation

TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_HTTP_Parser::~TAO_HTTP_Parser ( void   )  [virtual]

The destructor.

Definition at line 27 of file HTTP_Parser.cpp.

00028 {
00029 }


Member Function Documentation

bool TAO_HTTP_Parser::match_prefix ( const char *  ior_string  )  const [virtual]

Return true if ior_string starts with a prefix known to this IOR parser

Implements TAO_IOR_Parser.

Definition at line 33 of file HTTP_Parser.cpp.

References ACE_TEXT_CHAR_TO_TCHAR, file_prefix, and ACE_OS::strncmp().

00034 {
00035   const ACE_TCHAR *ior_string = ACE_TEXT_CHAR_TO_TCHAR (nior_string);
00036   return (ACE_OS::strncmp (ior_string,
00037                            ::file_prefix,
00038                            sizeof (::file_prefix) - 1) == 0);
00039 }

CORBA::Object_ptr TAO_HTTP_Parser::parse_string ( const char *  ior,
CORBA::ORB_ptr  orb 
) [virtual]

Parse the ior argument and return an object reference. The call may raise the standard system exceptions (NO_MEMORY, INV_OBJREF, etc.)

Implements TAO_IOR_Parser.

Definition at line 42 of file HTTP_Parser.cpp.

References ACE_DEBUG, ACE_NEW_RETURN, ACE_NEW_THROW_EX, ACE_TEXT, ACE_TEXT_CHAR_TO_TCHAR, ACE_OS::atoi(), ACE_String_Base< CHAR >::c_str(), TAO_HTTP_Client::close(), ACE_Message_Block::cont(), file_prefix, ACE_OS::free(), hostname(), LM_DEBUG, TAO_HTTP_Client::open(), TAO_HTTP_Client::read(), ACE_OS::strdup(), CORBA::ORB::string_to_object(), ACE_OS::strncpy(), ACE_OS::strstr(), and TAO_debug_level.

00044 {
00045   // Skip the prefix, we know it is there because this method in only
00046   // called if <match_prefix> returns 1.
00047   const ACE_TCHAR *ior = ACE_TEXT_CHAR_TO_TCHAR (nior);
00048   const ACE_TCHAR *http_url =
00049     ior + sizeof (::file_prefix) + 1;
00050 
00051   ACE_TCHAR *hostname = 0;
00052   ACE_TCHAR *filename = 0;
00053   const ACE_TCHAR *ptr = 0;
00054   u_short port = 80;
00055 
00056   if (http_url[0] == '/')
00057     {
00058       filename = ACE_OS::strdup (http_url);
00059     }
00060   else
00061     {
00062       ptr = ACE_OS::strstr (http_url, ACE_TEXT (":"));
00063       if (ptr)
00064         port = ACE_OS::atoi (ptr + 1);
00065       else
00066         ptr = ACE_OS::strstr (http_url, ACE_TEXT ("/"));
00067 
00068     if(!ptr)
00069       return 0;
00070     else
00071     {
00072       size_t const host_len = ptr - http_url;
00073       ACE_NEW_RETURN (hostname, ACE_TCHAR [host_len + 1], 0 );
00074       ACE_OS::strncpy (hostname, http_url, host_len);
00075       hostname [host_len] = '\0';
00076       ptr = ACE_OS::strstr (ptr, ACE_TEXT ("/"));
00077       if (ptr)
00078       {
00079         filename = ACE_OS::strdup(ptr);
00080       }
00081       else
00082         return 0;
00083     }
00084   }
00085 
00086   ACE_Message_Block* mb = 0;
00087   ACE_NEW_THROW_EX (mb,
00088                     ACE_Message_Block (),
00089                     CORBA::INTERNAL ());
00090 
00091   // Create a client
00092   TAO_HTTP_Client client;
00093 
00094   if (TAO_debug_level > 4)
00095     {
00096       ACE_DEBUG ((LM_DEBUG,
00097                   ACE_TEXT ("TAO (%P|%t) - HTTP_Parser::parse_string, getting IOR from <%s> <%s> <%d>\n"),
00098                   hostname, filename, port));
00099     }
00100 
00101   // Open the client
00102   if (client.open (filename,
00103                    hostname,
00104                    port) == -1)
00105   {
00106       client.close ();
00107       return 0;
00108   }
00109 
00110   delete [] hostname;
00111   ACE_OS::free (filename);
00112 
00113   // Read from it
00114   if (client.read (mb) <= 0)
00115   {
00116       client.close ();
00117       return 0;
00118   }
00119 
00120   // We get multiple message blocks back, concatenate them to
00121   // one large string
00122   ACE_CString string;
00123   for (ACE_Message_Block * curr = mb; curr != 0; curr = curr->cont ())
00124     string += curr->rd_ptr();
00125 
00126   return orb->string_to_object (string.c_str());
00127 }


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:39:31 2010 for TAO by  doxygen 1.4.7