Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
FIX::HttpMessage Class Reference

HTTP Message that implemented GET functionality. More...

#include <HttpMessage.h>

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

◆ Parameters

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

Definition at line 40 of file HttpMessage.h.

Constructor & Destructor Documentation

◆ HttpMessage() [1/3]

FIX::HttpMessage::HttpMessage ( )

Definition at line 34 of file HttpMessage.cpp.

34{}

◆ HttpMessage() [2/3]

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

Construct a message from a string.

Definition at line 36 of file HttpMessage.cpp.

38{
39 setString( string );
40}
void setString(const std::string &string)

◆ HttpMessage() [3/3]

FIX::HttpMessage::HttpMessage ( const HttpMessage copy)
inline

Definition at line 48 of file HttpMessage.h.

49 {
50 m_root = copy.m_root;
51 m_parameters = copy.m_parameters;
52 }
Parameters m_parameters
std::string m_root

References m_parameters, and m_root.

Member Function Documentation

◆ addParameter()

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

Definition at line 106 of file HttpMessage.h.

107 {
108 m_parameters[key] = value;
109 }

References m_parameters.

◆ clear()

void FIX::HttpMessage::clear ( )
inline

Definition at line 63 of file HttpMessage.h.

64 {
65#if defined(_MSC_VER) && _MSC_VER < 1300
66 m_root = "";
67#else
68 m_root.clear();
69#endif
70 m_parameters.clear();
71 }

References m_parameters, and m_root.

◆ createResponse()

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

Definition at line 86 of file HttpMessage.cpp.

87{
88 std::string errorString;
89 switch( error )
90 {
91 case 100: errorString = "Continue"; break;
92 case 101: errorString = "Switching Protocols"; break;
93 case 200: errorString = "OK"; break;
94 case 201: errorString = "Created"; break;
95 case 202: errorString = "Accepted"; break;
96 case 203: errorString = "Non-Authoritative Information"; break;
97 case 204: errorString = "No Content"; break;
98 case 205: errorString = "Reset Content"; break;
99 case 206: errorString = "Partial Content"; break;
100 case 300: errorString = "Multiple Choices"; break;
101 case 301: errorString = "Moved Permanently"; break;
102 case 302: errorString = "Found"; break;
103 case 303: errorString = "See Other"; break;
104 case 304: errorString = "Not Modified"; break;
105 case 305: errorString = "Use Proxy"; break;
106 case 307: errorString = "Temporary Redirect"; break;
107 case 400: errorString = "Bad Request"; break;
108 case 401: errorString = "Unauthorized"; break;
109 case 402: errorString = "Payment Required"; break;
110 case 403: errorString = "Forbidden"; break;
111 case 404: errorString = "Not Found"; break;
112 case 405: errorString = "Method Not Allowed"; break;
113 case 406: errorString = "Not Acceptable"; break;
114 case 407: errorString = "Proxy Authentication Required"; break;
115 case 408: errorString = "Request Timeout"; break;
116 case 409: errorString = "Conflict"; break;
117 case 410: errorString = "Gone"; break;
118 case 411: errorString = "Length Required"; break;
119 case 412: errorString = "Precondition Failed"; break;
120 case 413: errorString = "Request Entity Too Large"; break;
121 case 414: errorString = "Request-URI Too Large"; break;
122 case 415: errorString = "Unsupported Media Type"; break;
123 case 416: errorString = "Requested Range Not Satisfiable"; break;
124 case 417: errorString = "Expectation Failed"; break;
125 case 500: errorString = "Internal Server Error"; break;
126 case 501: errorString = "Not Implemented"; break;
127 case 502: errorString = "Bad Gateway"; break;
128 case 503: errorString = "Service Unavailable"; break;
129 case 504: errorString = "Gateway Timeout"; break;
130 case 505: errorString = "HTTP Version not supported"; break;
131 default: errorString = "Unknown";
132 }
133
134 std::stringstream response;
135 response << "HTTP/1.1 " << error << " " << errorString << "\r\n"
136 << "Server: QuickFIX" << "\r\n"
137 << "Content-Type: text/html; charset=iso-8859-1" << "\r\n\r\n"
138 << "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">";
139
140 if( error < 200 || error >= 300 )
141 response << "<HTML><HEAD><TITLE>" << error << " " << errorString << "</TITLE></HEAD><BODY>"
142 << "<H1>" << error << " " << errorString << "</H1>" << text << "</BODY></HTML>";
143 else
144 response << text;
145
146 return response.str();
147}

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

◆ getParameter()

const std::string & FIX::HttpMessage::getParameter ( const std::string &  key) const
throw (std::logic_error
)
inline

Definition at line 97 of file HttpMessage.h.

99 {
100 Parameters::const_iterator find = m_parameters.find( key );
101 if( find == m_parameters.end() )
102 throw std::logic_error( "Parameter " + key + " not found" );
103 return find->second;
104 }

References m_parameters.

Referenced by FIX::HttpConnection::processDisableSessions(), FIX::HttpConnection::processEnableSessions(), FIX::HttpConnection::processRefreshSession(), FIX::HttpConnection::processRefreshSessions(), FIX::HttpConnection::processResetSession(), FIX::HttpConnection::processResetSessions(), and FIX::HttpConnection::processSession().

◆ getParameters()

const Parameters & FIX::HttpMessage::getParameters ( ) const
inline

Definition at line 88 of file HttpMessage.h.

89 { return m_parameters; }

References m_parameters.

◆ getParameterString()

const std::string FIX::HttpMessage::getParameterString ( ) const
inline

Definition at line 76 of file HttpMessage.h.

77 {
78 std::string result;
79 Parameters::const_iterator i;
80 for( i = m_parameters.begin(); i != m_parameters.end(); ++i )
81 {
82 result += (i == m_parameters.begin()) ? "?" : "&";
83 result += i->first + "=" + i->second;
84 }
85 return result;
86 }

References m_parameters.

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

◆ getRootString()

const std::string & FIX::HttpMessage::getRootString ( ) const
inline

Definition at line 73 of file HttpMessage.h.

74 { return m_root; }

References m_root.

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

◆ hasParameter()

bool FIX::HttpMessage::hasParameter ( const std::string &  key) const
inline

◆ removeParameter()

void FIX::HttpMessage::removeParameter ( const std::string &  key)
inline

◆ setString()

void FIX::HttpMessage::setString ( const std::string &  string)
throw (InvalidMessage
)

Definition at line 54 of file HttpMessage.cpp.

56{
57 clear();
58
59 std::string::size_type eolPos = string.find( "\r\n" );
60 if( eolPos == std::string::npos ) throw InvalidMessage();
61 std::string line = string.substr( 0, eolPos );
62 std::string::size_type getPos = line.find( "GET " );
63 if( getPos != 0 ) throw InvalidMessage();
64 std::string::size_type httpPos = line.rfind( "HTTP", std::string::npos );
65 if( httpPos == std::string::npos ) throw InvalidMessage();
66
67 m_root = line.substr( getPos + 4, httpPos - 5 );
68 std::string::size_type paramPos = m_root.find_first_of( '?' );
69 if( paramPos == std::string::npos ) return;
70 std::string parameters = m_root.substr( paramPos, m_root.size() - paramPos );
71 m_root = m_root.substr( 0, paramPos );
72 paramPos = 0;
73
74 while( paramPos != std::string::npos )
75 {
76 std::string::size_type sepPos = parameters.find_first_of( "=", paramPos );
77 if( sepPos == std::string::npos ) break;
78 std::string::size_type tempPos = paramPos;
79 paramPos = parameters.find_first_of( "&", paramPos + 1 );
80 std::string key = parameters.substr(tempPos + 1, sepPos - tempPos - 1);
81 std::string value = parameters.substr(sepPos + 1, paramPos - sepPos - 1);
82 m_parameters[key] = value;
83 }
84}

◆ toString() [1/2]

std::string FIX::HttpMessage::toString ( ) const

◆ toString() [2/2]

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.

49{
50 str = m_root + getParameterString();
51 return str;
52}
const std::string getParameterString() const
Definition HttpMessage.h:76

References getParameterString(), and m_root.

Member Data Documentation

◆ m_parameters

Parameters FIX::HttpMessage::m_parameters
private

◆ m_root

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 Thu May 22 2025 08:23:50 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001