Public Types | Public Member Functions | Static Public Member Functions | Private Attributes
FIX::HttpMessage Class Reference

HTTP Message that implemented GET functionality. More...

#include <HttpMessage.h>

List of all members.

Public Types

typedef std::map< std::string,
std::string > 
Parameters

Public Member Functions

 HttpMessage ()
 HttpMessage (const std::string &string) throw ( InvalidMessage )
 Construct a message from a string.
 HttpMessage (const HttpMessage &copy)
std::string toString () const
 Get a string representation of the message.
std::string & toString (std::string &) const
 Get a string representation without making a copy.
void setString (const std::string &string) throw ( InvalidMessage )
void clear ()
const std::string & getRootString () const
const std::string getParameterString () const
const ParametersgetParameters () const
bool hasParameter (const std::string &key) const
const std::string & getParameter (const std::string &key) const throw ( std::logic_error )
void addParameter (const std::string &key, const std::string &value)
void removeParameter (const std::string &key)

Static Public Member Functions

static std::string createResponse (int error=0, const std::string &text="")

Private Attributes

std::string m_root
Parameters m_parameters

Detailed Description

HTTP Message that implemented GET functionality.

Definition at line 37 of file HttpMessage.h.


Member Typedef Documentation

typedef std::map<std::string, std::string> FIX::HttpMessage::Parameters

Definition at line 40 of file HttpMessage.h.


Constructor & Destructor Documentation

Definition at line 34 of file HttpMessage.cpp.

{}
FIX::HttpMessage::HttpMessage ( const std::string &  string) throw ( InvalidMessage )

Construct a message from a string.

Definition at line 36 of file HttpMessage.cpp.

{
  setString( string );
}
FIX::HttpMessage::HttpMessage ( const HttpMessage copy) [inline]

Definition at line 48 of file HttpMessage.h.

References m_parameters, and m_root.

  {
    m_root = copy.m_root;
    m_parameters = copy.m_parameters;
  }

Member Function Documentation

void FIX::HttpMessage::addParameter ( const std::string &  key,
const std::string &  value 
) [inline]

Definition at line 106 of file HttpMessage.h.

References m_parameters.

  {
    m_parameters[key] = value;
  }
void FIX::HttpMessage::clear ( ) [inline]

Definition at line 63 of file HttpMessage.h.

References m_parameters, and m_root.

  {
#if defined(_MSC_VER) && _MSC_VER < 1300
    m_root = "";
#else
    m_root.clear();
#endif
    m_parameters.clear();
  }
std::string FIX::HttpMessage::createResponse ( int  error = 0,
const std::string &  text = "" 
) [static]

Definition at line 86 of file HttpMessage.cpp.

Referenced by FIX::HttpConnection::disconnect(), and FIX::HttpConnection::processRequest().

{
  std::string errorString;
  switch( error )
  {
  case 100: errorString = "Continue"; break;
  case 101: errorString = "Switching Protocols"; break;
  case 200: errorString = "OK"; break;
  case 201: errorString = "Created"; break;
  case 202: errorString = "Accepted"; break;
  case 203: errorString = "Non-Authoritative Information"; break;
  case 204: errorString = "No Content"; break;
  case 205: errorString = "Reset Content"; break;
  case 206: errorString = "Partial Content"; break;
  case 300: errorString = "Multiple Choices"; break;
  case 301: errorString = "Moved Permanently"; break;
  case 302: errorString = "Found"; break;
  case 303: errorString = "See Other"; break;
  case 304: errorString = "Not Modified"; break;
  case 305: errorString = "Use Proxy"; break;
  case 307: errorString = "Temporary Redirect"; break;
  case 400: errorString = "Bad Request"; break;
  case 401: errorString = "Unauthorized"; break;
  case 402: errorString = "Payment Required"; break;
  case 403: errorString = "Forbidden"; break;
  case 404: errorString = "Not Found"; break;
  case 405: errorString = "Method Not Allowed"; break;
  case 406: errorString = "Not Acceptable"; break;
  case 407: errorString = "Proxy Authentication Required"; break;
  case 408: errorString = "Request Timeout"; break;
  case 409: errorString = "Conflict"; break;
  case 410: errorString = "Gone"; break;
  case 411: errorString = "Length Required"; break;
  case 412: errorString = "Precondition Failed"; break;
  case 413: errorString = "Request Entity Too Large"; break;
  case 414: errorString = "Request-URI Too Large"; break;
  case 415: errorString = "Unsupported Media Type"; break;
  case 416: errorString = "Requested Range Not Satisfiable"; break;
  case 417: errorString = "Expectation Failed"; break;
  case 500: errorString = "Internal Server Error"; break;
  case 501: errorString = "Not Implemented"; break;
  case 502: errorString = "Bad Gateway"; break;
  case 503: errorString = "Service Unavailable"; break;
  case 504: errorString = "Gateway Timeout"; break;
  case 505: errorString = "HTTP Version not supported"; break;
  default: errorString = "Unknown";
  }

  std::stringstream response;
  response << "HTTP/1.1 " << error << " " << errorString << "\r\n"
           << "Server: QuickFIX" << "\r\n"
           << "Content-Type: text/html; charset=iso-8859-1" << "\r\n\r\n"
           << "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">";

  if( error < 200 || error >= 300 )
    response << "<HTML><HEAD><TITLE>" << error << " " << errorString << "</TITLE></HEAD><BODY>"
             << "<H1>" << error << " " << errorString << "</H1>" << text << "</BODY></HTML>";
  else
    response << text;

  return response.str();
}
const std::string& FIX::HttpMessage::getParameter ( const std::string &  key) const throw ( std::logic_error ) [inline]
const Parameters& FIX::HttpMessage::getParameters ( ) const [inline]

Definition at line 88 of file HttpMessage.h.

References m_parameters.

  { return m_parameters; }
const std::string FIX::HttpMessage::getParameterString ( ) const [inline]

Definition at line 76 of file HttpMessage.h.

References m_parameters.

Referenced by FIX::HttpConnection::processRefreshSession(), FIX::HttpConnection::processResetSession(), FIX::HttpConnection::processRoot(), FIX::HttpConnection::processSession(), and toString().

  {
    std::string result;
    Parameters::const_iterator i;
    for( i = m_parameters.begin(); i != m_parameters.end(); ++i )
    {
      result += (i == m_parameters.begin()) ? "?" : "&";
      result += i->first + "=" + i->second;
    }
    return result;
  }
const std::string& FIX::HttpMessage::getRootString ( ) const [inline]

Definition at line 73 of file HttpMessage.h.

References m_root.

Referenced by FIX::HttpConnection::processRequest().

  { return m_root; }
bool FIX::HttpMessage::hasParameter ( const std::string &  key) const [inline]
void FIX::HttpMessage::removeParameter ( const std::string &  key) [inline]
void FIX::HttpMessage::setString ( const std::string &  string) throw ( InvalidMessage )

Definition at line 54 of file HttpMessage.cpp.

{
  clear();

  std::string::size_type eolPos = string.find( "\r\n" );
  if( eolPos == std::string::npos ) throw InvalidMessage();
  std::string line = string.substr( 0, eolPos );
  std::string::size_type getPos = line.find( "GET " );
  if( getPos != 0 ) throw InvalidMessage();
  std::string::size_type httpPos = line.rfind( "HTTP", std::string::npos );
  if( httpPos == std::string::npos ) throw InvalidMessage();

  m_root = line.substr( getPos + 4, httpPos - 5 );
  std::string::size_type paramPos = m_root.find_first_of( '?' );
  if( paramPos == std::string::npos ) return;
  std::string parameters = m_root.substr( paramPos, m_root.size() - paramPos );
  m_root = m_root.substr( 0, paramPos );
  paramPos = 0;

  while( paramPos != std::string::npos )
  {
    std::string::size_type sepPos = parameters.find_first_of( "=", paramPos );
    if( sepPos == std::string::npos ) break;
    std::string::size_type tempPos = paramPos;
    paramPos = parameters.find_first_of( "&", paramPos + 1 );
    std::string key = parameters.substr(tempPos + 1, sepPos - tempPos - 1);
    std::string value = parameters.substr(sepPos + 1, paramPos - sepPos - 1);
    m_parameters[key] = value;
  }
}
std::string FIX::HttpMessage::toString ( ) const
std::string & FIX::HttpMessage::toString ( std::string &  str) const

Get a string representation without making a copy.

Definition at line 48 of file HttpMessage.cpp.

References getParameterString(), and m_root.

{
  str = m_root + getParameterString();
  return str;
}

Member Data Documentation

std::string FIX::HttpMessage::m_root [private]

Definition at line 119 of file HttpMessage.h.

Referenced by clear(), getRootString(), HttpMessage(), and toString().


The documentation for this class was generated from the following files:

Generated on Mon Jun 23 2014 23:49:39 for QuickFIX by doxygen 1.7.6.1 written by Dimitri van Heesch, © 1997-2001