Public Member Functions

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_HTTP_Parser::~TAO_HTTP_Parser ( void   )  [virtual]

The destructor.

Definition at line 27 of file HTTP_Parser.cpp.

{
}


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.

{
  ACE_TString ior_string = ACE_TEXT_CHAR_TO_TCHAR (nior_string);
  return (ACE_OS::strncmp (ior_string.c_str (),
                           ::file_prefix,
                           sizeof (::file_prefix) - 1) == 0);
}

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.

{
  // Skip the prefix, we know it is there because this method in only
  // called if <match_prefix> returns 1.
  ACE_TString ior = ACE_TEXT_CHAR_TO_TCHAR (nior);
  const ACE_TCHAR *http_url =
    ior.c_str () + sizeof (::file_prefix) + 1;

  ACE_TCHAR *hostname = 0;
  ACE_TCHAR *filename = 0;
  const ACE_TCHAR *ptr = 0;
  u_short port = 80;

  if (http_url[0] == '/')
    {
      filename = ACE_OS::strdup (http_url);
    }
  else
    {
      ptr = ACE_OS::strstr (http_url, ACE_TEXT (":"));
      if (ptr)
        port = ACE_OS::atoi (ptr + 1);
      else
        ptr = ACE_OS::strstr (http_url, ACE_TEXT ("/"));

    if(!ptr)
      return 0;
    else
    {
      size_t const host_len = ptr - http_url;
      ACE_NEW_RETURN (hostname, ACE_TCHAR [host_len + 1], 0 );
      ACE_OS::strncpy (hostname, http_url, host_len);
      hostname [host_len] = '\0';
      ptr = ACE_OS::strstr (ptr, ACE_TEXT ("/"));
      if (ptr)
      {
        filename = ACE_OS::strdup(ptr);
      }
      else
        return 0;
    }
  }

  ACE_Message_Block* mb = 0;
  ACE_NEW_THROW_EX (mb,
                    ACE_Message_Block (),
                    CORBA::INTERNAL ());

  // Create a client
  TAO_HTTP_Client client;

  if (TAO_debug_level > 4)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO (%P|%t) - HTTP_Parser::parse_string, getting IOR from <%s> <%s> <%d>\n"),
                  hostname, filename, port));
    }

  // Open the client
  if (client.open (filename,
                   hostname,
                   port) == -1)
  {
      client.close ();
      return 0;
  }

  delete [] hostname;
  ACE_OS::free (filename);

  // Read from it
  if (client.read (mb) <= 0)
  {
      client.close ();
      return 0;
  }

  // We get multiple message blocks back, concatenate them to
  // one large string
  ACE_CString string;
  for (ACE_Message_Block * curr = mb; curr != 0; curr = curr->cont ())
    string += curr->rd_ptr();

  return orb->string_to_object (string.c_str());
}


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines