![]() |
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 ©) | |
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 Parameters & | getParameters () 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 |
HTTP Message that implemented GET functionality.
Definition at line 37 of file HttpMessage.h.
typedef std::map<std::string, std::string> FIX::HttpMessage::Parameters |
Definition at line 40 of file HttpMessage.h.
FIX::HttpMessage::HttpMessage | ( | ) |
Definition at line 35 of file HttpMessage.cpp.
FIX::HttpMessage::HttpMessage | ( | const std::string & | string | ) | throw ( InvalidMessage ) |
Construct a message from a string.
Definition at line 37 of file HttpMessage.cpp.
00039 { 00040 setString( string ); 00041 }
FIX::HttpMessage::HttpMessage | ( | const HttpMessage & | copy | ) | [inline] |
Definition at line 48 of file HttpMessage.h.
References m_parameters, and m_root.
00049 { 00050 m_root = copy.m_root; 00051 m_parameters = copy.m_parameters; 00052 }
void FIX::HttpMessage::addParameter | ( | const std::string & | key, | |
const std::string & | value | |||
) | [inline] |
Definition at line 106 of file HttpMessage.h.
References m_parameters.
00107 { 00108 m_parameters[key] = value; 00109 }
void FIX::HttpMessage::clear | ( | ) | [inline] |
Definition at line 63 of file HttpMessage.h.
References m_parameters, and m_root.
00064 { 00065 #if defined(_MSC_VER) && _MSC_VER < 1300 00066 m_root = ""; 00067 #else 00068 m_root.clear(); 00069 #endif 00070 m_parameters.clear(); 00071 }
std::string FIX::HttpMessage::createResponse | ( | int | error = 0 , |
|
const std::string & | text = "" | |||
) | [static] |
Definition at line 96 of file HttpMessage.cpp.
References QF_STACK_POP, and QF_STACK_PUSH.
Referenced by FIX::HttpConnection::disconnect(), and FIX::HttpConnection::processRequest().
00097 { QF_STACK_PUSH(HttpMessage::createResponse) 00098 00099 std::string errorString; 00100 switch( error ) 00101 { 00102 case 100: errorString = "Continue"; break; 00103 case 101: errorString = "Switching Protocols"; break; 00104 case 200: errorString = "OK"; break; 00105 case 201: errorString = "Created"; break; 00106 case 202: errorString = "Accepted"; break; 00107 case 203: errorString = "Non-Authoritative Information"; break; 00108 case 204: errorString = "No Content"; break; 00109 case 205: errorString = "Reset Content"; break; 00110 case 206: errorString = "Partial Content"; break; 00111 case 300: errorString = "Multiple Choices"; break; 00112 case 301: errorString = "Moved Permanently"; break; 00113 case 302: errorString = "Found"; break; 00114 case 303: errorString = "See Other"; break; 00115 case 304: errorString = "Not Modified"; break; 00116 case 305: errorString = "Use Proxy"; break; 00117 case 307: errorString = "Temporary Redirect"; break; 00118 case 400: errorString = "Bad Request"; break; 00119 case 401: errorString = "Unauthorized"; break; 00120 case 402: errorString = "Payment Required"; break; 00121 case 403: errorString = "Forbidden"; break; 00122 case 404: errorString = "Not Found"; break; 00123 case 405: errorString = "Method Not Allowed"; break; 00124 case 406: errorString = "Not Acceptable"; break; 00125 case 407: errorString = "Proxy Authentication Required"; break; 00126 case 408: errorString = "Request Timeout"; break; 00127 case 409: errorString = "Conflict"; break; 00128 case 410: errorString = "Gone"; break; 00129 case 411: errorString = "Length Required"; break; 00130 case 412: errorString = "Precondition Failed"; break; 00131 case 413: errorString = "Request Entity Too Large"; break; 00132 case 414: errorString = "Request-URI Too Large"; break; 00133 case 415: errorString = "Unsupported Media Type"; break; 00134 case 416: errorString = "Requested Range Not Satisfiable"; break; 00135 case 417: errorString = "Expectation Failed"; break; 00136 case 500: errorString = "Internal Server Error"; break; 00137 case 501: errorString = "Not Implemented"; break; 00138 case 502: errorString = "Bad Gateway"; break; 00139 case 503: errorString = "Service Unavailable"; break; 00140 case 504: errorString = "Gateway Timeout"; break; 00141 case 505: errorString = "HTTP Version not supported"; break; 00142 default: errorString = "Unknown"; 00143 } 00144 00145 std::stringstream response; 00146 response << "HTTP/1.1 " << error << " " << errorString << "\r\n" 00147 << "Server: QuickFIX" << "\r\n" 00148 << "Content-Type: text/html; charset=iso-8859-1" << "\r\n\r\n" 00149 << "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">"; 00150 00151 if( error < 200 || error >= 300 ) 00152 response << "<HTML><HEAD><TITLE>" << error << " " << errorString << "</TITLE></HEAD><BODY>" 00153 << "<H1>" << error << " " << errorString << "</H1>" << text << "</BODY></HTML>"; 00154 else 00155 response << text; 00156 00157 return response.str(); 00158 00159 QF_STACK_POP 00160 }
const std::string& FIX::HttpMessage::getParameter | ( | const std::string & | key | ) | const throw ( std::logic_error ) [inline] |
Definition at line 97 of file HttpMessage.h.
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().
00099 { 00100 Parameters::const_iterator find = m_parameters.find( key ); 00101 if( find == m_parameters.end() ) 00102 throw std::logic_error( "Parameter " + key + " not found" ); 00103 return find->second; 00104 }
const Parameters& FIX::HttpMessage::getParameters | ( | ) | const [inline] |
Definition at line 88 of file HttpMessage.h.
References m_parameters.
00089 { 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().
00077 { 00078 std::string result; 00079 Parameters::const_iterator i; 00080 for( i = m_parameters.begin(); i != m_parameters.end(); ++i ) 00081 { 00082 result += (i == m_parameters.begin()) ? "?" : "&"; 00083 result += i->first + "=" + i->second; 00084 } 00085 return result; 00086 }
const std::string& FIX::HttpMessage::getRootString | ( | ) | const [inline] |
Definition at line 73 of file HttpMessage.h.
References m_root.
Referenced by FIX::HttpConnection::processRequest().
00074 { return m_root; }
bool FIX::HttpMessage::hasParameter | ( | const std::string & | key | ) | const [inline] |
Definition at line 91 of file HttpMessage.h.
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().
00092 { 00093 Parameters::const_iterator find = m_parameters.find( key ); 00094 return find != m_parameters.end(); 00095 }
void FIX::HttpMessage::removeParameter | ( | const std::string & | key | ) | [inline] |
Definition at line 111 of file HttpMessage.h.
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().
00112 { 00113 m_parameters.erase( key ); 00114 }
void FIX::HttpMessage::setString | ( | const std::string & | string | ) | throw ( InvalidMessage ) |
Definition at line 61 of file HttpMessage.cpp.
References QF_STACK_POP, and QF_STACK_PUSH.
00063 { QF_STACK_PUSH(HttpMessage::setString) 00064 00065 clear(); 00066 00067 std::string::size_type eolPos = string.find( "\r\n" ); 00068 if( eolPos == std::string::npos ) throw InvalidMessage(); 00069 std::string line = string.substr( 0, eolPos ); 00070 std::string::size_type getPos = line.find( "GET " ); 00071 if( getPos != 0 ) throw InvalidMessage(); 00072 std::string::size_type httpPos = line.rfind( "HTTP", std::string::npos ); 00073 if( httpPos == std::string::npos ) throw InvalidMessage(); 00074 00075 m_root = line.substr( getPos + 4, httpPos - 5 ); 00076 std::string::size_type paramPos = m_root.find_first_of( '?' ); 00077 if( paramPos == std::string::npos ) return; 00078 std::string parameters = m_root.substr( paramPos, m_root.size() - paramPos ); 00079 m_root = m_root.substr( 0, paramPos ); 00080 paramPos = 0; 00081 00082 while( paramPos != std::string::npos ) 00083 { 00084 std::string::size_type sepPos = parameters.find_first_of( "=", paramPos ); 00085 if( sepPos == std::string::npos ) break; 00086 std::string::size_type tempPos = paramPos; 00087 paramPos = parameters.find_first_of( "&", paramPos + 1 ); 00088 std::string key = parameters.substr(tempPos + 1, sepPos - tempPos - 1); 00089 std::string value = parameters.substr(sepPos + 1, paramPos - sepPos - 1); 00090 m_parameters[key] = value; 00091 } 00092 00093 QF_STACK_POP 00094 }
std::string & FIX::HttpMessage::toString | ( | std::string & | str | ) | const |
Get a string representation without making a copy.
Definition at line 52 of file HttpMessage.cpp.
References getParameterString(), m_root, QF_STACK_POP, QF_STACK_PUSH, and toString().
00053 { QF_STACK_PUSH(HttpMessage::toString) 00054 00055 str = m_root + getParameterString(); 00056 return str; 00057 00058 QF_STACK_POP 00059 }
std::string FIX::HttpMessage::toString | ( | ) | const |
Get a string representation of the message.
Definition at line 43 of file HttpMessage.cpp.
References QF_STACK_POP, and QF_STACK_PUSH.
Referenced by FIX::HttpConnection::processDisableSessions(), FIX::HttpConnection::processEnableSessions(), FIX::HttpConnection::processRefreshSession(), FIX::HttpConnection::processRefreshSessions(), FIX::HttpConnection::processRequest(), FIX::HttpConnection::processResetSession(), FIX::HttpConnection::processResetSessions(), FIX::HttpConnection::processSession(), and toString().
00044 { QF_STACK_PUSH(HttpMessage::toString) 00045 00046 std::string str; 00047 return toString( str ); 00048 00049 QF_STACK_POP 00050 }
Parameters FIX::HttpMessage::m_parameters [private] |
Definition at line 120 of file HttpMessage.h.
Referenced by addParameter(), clear(), getParameter(), getParameters(), getParameterString(), hasParameter(), HttpMessage(), and removeParameter().
std::string FIX::HttpMessage::m_root [private] |
Definition at line 119 of file HttpMessage.h.
Referenced by clear(), getRootString(), HttpMessage(), and toString().