HttpConnection.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (c) 2001-2014
00003 **
00004 ** This file is part of the QuickFIX FIX Engine
00005 **
00006 ** This file may be distributed under the terms of the quickfixengine.org
00007 ** license as defined by quickfixengine.org and appearing in the file
00008 ** LICENSE included in the packaging of this file.
00009 **
00010 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00011 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00012 **
00013 ** See http://www.quickfixengine.org/LICENSE for licensing information.
00014 **
00015 ** Contact ask@quickfixengine.org if any conditions of this licensing are
00016 ** not clear to you.
00017 **
00018 ****************************************************************************/
00019 
00020 #ifdef _MSC_VER
00021 #include "stdafx.h"
00022 #else
00023 #include "config.h"
00024 #endif
00025 
00026 #include "HttpConnection.h"
00027 #include "HttpMessage.h"
00028 #include "HtmlBuilder.h"
00029 #include "Session.h"
00030 #include "Utility.h"
00031 
00032 using namespace HTML;
00033 
00034 namespace FIX
00035 {
00036 HttpConnection::HttpConnection( int s )
00037 : m_socket( s )
00038 {
00039   FD_ZERO( &m_fds );
00040   FD_SET( m_socket, &m_fds );
00041 }
00042 
00043 bool HttpConnection::send( const std::string& msg )
00044 {
00045   return socket_send( m_socket, msg.c_str(), msg.length() ) >= 0;
00046 }
00047 
00048 void HttpConnection::disconnect( int error )
00049 { 
00050   if( error > 0 )
00051     send( HttpMessage::createResponse(error) );
00052 
00053   socket_close( m_socket );
00054 }
00055 
00056 bool HttpConnection::read()
00057 {
00058   struct timeval timeout = { 2, 0 };
00059   fd_set readset = m_fds;
00060 
00061   try
00062   {
00063     // Wait for input (1 second timeout)
00064     int result = select( 1 + m_socket, &readset, 0, 0, &timeout );
00065 
00066     if( result > 0 ) // Something to read
00067     {
00068       // We can read without blocking
00069       int size = recv( m_socket, m_buffer, sizeof(m_buffer), 0 );
00070       if ( size <= 0 ) { throw SocketRecvFailed( size ); }
00071       m_parser.addToStream( m_buffer, size );
00072     }
00073     else if( result == 0 ) // Timeout
00074     {
00075       disconnect( 408 );
00076       return false;
00077     }
00078     else if( result < 0 ) // Error
00079     {
00080       throw SocketRecvFailed( result );
00081     }
00082 
00083     processStream();
00084     return true;
00085   }
00086   catch ( SocketRecvFailed& )
00087   {
00088     disconnect();
00089     return false;
00090   }
00091 }
00092 
00093 bool HttpConnection::readMessage( std::string& msg )
00094 throw( SocketRecvFailed )
00095 {
00096   try
00097   {
00098     return m_parser.readHttpMessage( msg );
00099   }
00100   catch ( MessageParseError& ) 
00101   { 
00102     disconnect( 400 );
00103   }
00104   return true;
00105 }
00106 
00107 void HttpConnection::processStream()
00108 {
00109   std::string msg;
00110   try
00111   {
00112     if( !readMessage(msg) )
00113       return;
00114     HttpMessage request( msg );
00115     processRequest( request );
00116   }
00117   catch( InvalidMessage& ) 
00118   {
00119     disconnect( 400 );
00120     return;
00121   }
00122 
00123   return;
00124 }
00125 
00126 void HttpConnection::processRequest( const HttpMessage& request )
00127 {
00128   int error = 200;
00129   std::stringstream h;
00130   std::stringstream b;
00131   std::string titleString = "QuickFIX Engine Web Interface";
00132 
00133   { HEAD head(h); head.text();
00134     { CENTER center(h); center.text();
00135       { TITLE title(h); title.text(titleString); }
00136       { H1 h1(h); h1.text(titleString); }
00137     }
00138     { CENTER center(h); center.text();
00139       { A a(h); a.href("/").text("HOME"); }
00140       h << NBSP;
00141       { A a(h); a.href(request.toString()).text("RELOAD"); }
00142     }
00143     HR hr(h); hr.text();
00144   }
00145 
00146   BODY body(b); body.text();
00147 
00148   try
00149   {
00150     if( request.getRootString() == "/" )
00151       processRoot( request, h, b );
00152     else if( request.getRootString() == "/resetSessions" )
00153       processResetSessions( request, h, b );
00154     else if( request.getRootString() == "/refreshSessions" )
00155       processRefreshSessions( request, h, b );
00156     else if( request.getRootString() == "/enableSessions" )
00157       processEnableSessions( request, h, b );
00158     else if( request.getRootString() == "/disableSessions" )
00159       processDisableSessions( request, h, b );
00160     else if( request.getRootString() == "/session" )
00161       processSession( request, h, b );
00162     else if( request.getRootString() == "/resetSession" )
00163       processResetSession( request, h, b );
00164     else if( request.getRootString() == "/refreshSession" )
00165       processRefreshSession( request, h, b );
00166     else
00167       error = 404;
00168   }
00169   catch( std::exception& e )
00170   {
00171     error = 400;
00172     b << e.what();
00173   }
00174 
00175   std::string response = "<HTML>" + h.str() + b.str() + "</HTML>";
00176   send( HttpMessage::createResponse(error, error == 200 ? response : "") );
00177 
00178   disconnect();
00179 }
00180 
00181 void HttpConnection::processRoot
00182 ( const HttpMessage& request, std::stringstream& h, std::stringstream& b )
00183 {
00184   TABLE table(b); table.border(1).cellspacing(2).width(100).text();
00185 
00186   { CAPTION caption(b); caption.text();
00187     EM em(b); em.text();
00188     b << Session::numSessions() << " Sessions managed by QuickFIX";
00189     { HR hr(b); hr.text(); }
00190     { b << NBSP; A a(b); a.href("/resetSessions" + request.getParameterString()).text("RESET"); }
00191     { b << NBSP; A a(b); a.href("/refreshSessions" + request.getParameterString()).text("REFRESH"); }
00192     { b << NBSP; A a(b); a.href("/enableSessions" + request.getParameterString()).text("ENABLE"); }
00193     { b << NBSP; A a(b); a.href("/disableSessions" + request.getParameterString()).text("DISABLE"); }
00194   }
00195 
00196   { TR tr(b); tr.text();
00197     { TD td(b); td.align("center").text("Session"); }
00198     { TD td(b); td.align("center").text("ConnectionType"); }
00199     { TD td(b); td.align("center").text("Enabled"); }
00200     { TD td(b); td.align("center").text("Session Time"); }
00201     { TD td(b); td.align("center").text("Logged On"); }
00202     { TD td(b); td.align("center").text("Next Incoming"); }
00203     { TD td(b); td.align("center").text("Next Outgoing"); }
00204   }
00205 
00206   std::set<SessionID> sessions = Session::getSessions();
00207   std::set<SessionID>::iterator i;
00208   for( i = sessions.begin(); i != sessions.end(); ++i )
00209   {
00210     Session* pSession = Session::lookupSession( *i );
00211     if( !pSession ) continue;
00212 
00213     { TR tr(b); tr.text();
00214       { TD td(b); td.text();
00215         std::string href = "/session?BeginString=" + i->getBeginString().getValue() +
00216                             "&SenderCompID=" + i->getSenderCompID().getValue() +
00217                             "&TargetCompID=" + i->getTargetCompID().getValue();
00218         if( i->getSessionQualifier().size() )
00219           href += "&SessionQualifier=" + i->getSessionQualifier();
00220 
00221         A a(b); a.href(href).text(i->toString());
00222       }
00223       { TD td(b); td.text(pSession->isInitiator() ? "initiator" : "acceptor"); }
00224       { TD td(b); td.text(pSession->isEnabled() ? "yes" : "no"); }
00225       { TD td(b); td.text(pSession->isSessionTime(UtcTimeStamp()) ? "yes" : "no"); }
00226       { TD td(b); td.text(pSession->isLoggedOn() ? "yes" : "no"); }
00227       { TD td(b); td.text(pSession->getExpectedTargetNum()); }
00228       { TD td(b); td.text(pSession->getExpectedSenderNum()); }
00229     }
00230   }
00231 }
00232 
00233 void HttpConnection::processResetSessions
00234 ( const HttpMessage& request, std::stringstream& h, std::stringstream& b )
00235 {
00236   try
00237   {
00238     HttpMessage copy = request;
00239 
00240     bool confirm = false;
00241     if( copy.hasParameter("confirm") && copy.getParameter("confirm") != "0" )
00242     {
00243       confirm = true;
00244       std::set<SessionID> sessions = Session::getSessions();
00245       std::set<SessionID>::iterator session;
00246       for( session = sessions.begin(); session != sessions.end(); ++session )
00247       Session::lookupSession( *session )->reset();
00248       copy.removeParameter("confirm");
00249     }
00250 
00251     if( confirm )
00252     {
00253       h << "<META http-equiv='refresh' content=2;URL='" << "/'>";
00254       CENTER center(b); center.text();
00255       H2 h2(b); h2.text();
00256       { A a(b); a.href("/").text("Sessions"); }
00257       b << " have been reset";
00258     }
00259     else
00260     {
00261       { CENTER center(b); center.text();
00262         H2 h2(b); h2.text();
00263         b << "Are you sure you want to reset all sessions ?";
00264       }
00265       { CENTER center(b); center.text();
00266         b << "[";
00267         { A a(b); a.href(request.toString() + "?confirm=1").text("YES, reset sessions"); }
00268         b << "]" << NBSP << "[";
00269         { A a(b); a.href("/").text("NO, do not reset sessions"); }
00270         b << "]";
00271       }
00272     }
00273   }
00274   catch( std::exception& e )
00275   {
00276     b << e.what();
00277   }
00278 }
00279 
00280 void HttpConnection::processRefreshSessions
00281 ( const HttpMessage& request, std::stringstream& h, std::stringstream& b )
00282 {
00283   try
00284   {
00285     HttpMessage copy = request;
00286 
00287     bool confirm = false;
00288     if( copy.hasParameter("confirm") && copy.getParameter("confirm") != "0" )
00289     {
00290       confirm = true;
00291       std::set<SessionID> sessions = Session::getSessions();
00292       std::set<SessionID>::iterator session;
00293       for( session = sessions.begin(); session != sessions.end(); ++session )
00294       Session::lookupSession( *session )->refresh();
00295       copy.removeParameter("confirm");
00296     }
00297 
00298     if( confirm )
00299     {
00300       h << "<META http-equiv='refresh' content=2;URL='" << "/'>";
00301       CENTER center(b); center.text();
00302       H2 h2(b); h2.text();
00303       { A a(b); a.href("/").text("Sessions"); }
00304       b << " have been refreshed";
00305     }
00306     else
00307     {
00308       { CENTER center(b); center.text();
00309         H2 h2(b); h2.text();
00310         b << "Are you sure you want to refresh all sessions ?";
00311       }
00312       { CENTER center(b); center.text();
00313         b << "[";
00314         { A a(b); a.href(request.toString() + "?confirm=1").text("YES, refresh sessions"); }
00315         b << "]" << NBSP << "[";
00316         { A a(b); a.href("/").text("NO, do not refresh sessions"); }
00317         b << "]";
00318       }
00319     }
00320   }
00321   catch( std::exception& e )
00322   {
00323     b << e.what();
00324   }
00325 }
00326 
00327 void HttpConnection::processEnableSessions
00328 ( const HttpMessage& request, std::stringstream& h, std::stringstream& b )
00329 {
00330   try
00331   {
00332     HttpMessage copy = request;
00333 
00334     bool confirm = false;
00335     if( copy.hasParameter("confirm") && copy.getParameter("confirm") != "0" )
00336     {
00337       confirm = true;
00338       std::set<SessionID> sessions = Session::getSessions();
00339       std::set<SessionID>::iterator session;
00340       for( session = sessions.begin(); session != sessions.end(); ++session )
00341       Session::lookupSession( *session )->logon();
00342       copy.removeParameter("confirm");
00343     }
00344 
00345     if( confirm )
00346     {
00347       h << "<META http-equiv='refresh' content=2;URL='" << "/'>";
00348       CENTER center(b); center.text();
00349       H2 h2(b); h2.text();
00350       { A a(b); a.href("/").text("Sessions"); }
00351       b << " have been enabled";
00352     }
00353     else
00354     {
00355       { CENTER center(b); center.text();
00356         H2 h2(b); h2.text();
00357         b << "Are you sure you want to enable all sessions ?";
00358       }
00359       { CENTER center(b); center.text();
00360         b << "[";
00361         { A a(b); a.href(request.toString() + "?confirm=1").text("YES, enable sessions"); }
00362         b << "]" << NBSP << "[";
00363         { A a(b); a.href("/").text("NO, do not enable sessions"); }
00364         b << "]";
00365       }
00366     }
00367   }
00368   catch( std::exception& e )
00369   {
00370     b << e.what();
00371   }
00372 }
00373 
00374 void HttpConnection::processDisableSessions
00375 ( const HttpMessage& request, std::stringstream& h, std::stringstream& b )
00376 {
00377   try
00378   {
00379     HttpMessage copy = request;
00380 
00381     bool confirm = false;
00382     if( copy.hasParameter("confirm") && copy.getParameter("confirm") != "0" )
00383     {
00384       confirm = true;
00385       std::set<SessionID> sessions = Session::getSessions();
00386       std::set<SessionID>::iterator session;
00387       for( session = sessions.begin(); session != sessions.end(); ++session )
00388       Session::lookupSession( *session )->logout();
00389       copy.removeParameter("confirm");
00390     }
00391 
00392     if( confirm )
00393     {
00394       h << "<META http-equiv='refresh' content=2;URL='" << "/'>";
00395       CENTER center(b); center.text();
00396       H2 h2(b); h2.text();
00397       { A a(b); a.href("/").text("Sessions"); }
00398       b << " have been disabled";
00399     }
00400     else
00401     {
00402       { CENTER center(b); center.text();
00403         H2 h2(b); h2.text();
00404         b << "Are you sure you want to disable all sessions ?";
00405       }
00406       { CENTER center(b); center.text();
00407         b << "[";
00408         { A a(b); a.href(request.toString() + "?confirm=1").text("YES, disable sessions"); }
00409         b << "]" << NBSP << "[";
00410         { A a(b); a.href("/").text("NO, do not disable sessions"); }
00411         b << "]";
00412       }
00413     }
00414   }
00415   catch( std::exception& e )
00416   {
00417     b << e.what();
00418   }
00419 }
00420 
00421 void HttpConnection::processSession
00422 ( const HttpMessage& request, std::stringstream& h, std::stringstream& b )
00423 {
00424   try
00425   {
00426     HttpMessage copy = request;
00427     std::string url = request.toString();
00428     std::string beginString = copy.getParameter( "BeginString" );
00429     std::string senderCompID = copy.getParameter( "SenderCompID" );
00430     std::string targetCompID = copy.getParameter( "TargetCompID" );
00431     std::string sessionQualifier;
00432     if( copy.hasParameter("SessionQualifier") )
00433       sessionQualifier = copy.getParameter( "SessionQualifier" );
00434 
00435     SessionID sessionID( beginString, senderCompID, targetCompID, sessionQualifier );
00436     Session* pSession = Session::lookupSession( sessionID );
00437     if( pSession == 0 ) throw SessionNotFound();
00438 
00439     if( copy.hasParameter("Enabled") )
00440     {
00441       copy.getParameter("Enabled") == "0" ? pSession->logout() : pSession->logon();
00442       copy.removeParameter("Enabled");
00443     }
00444     if( copy.hasParameter("Next%20Incoming") )
00445     {
00446       int value = IntConvertor::convert( copy.getParameter("Next%20Incoming") );
00447       pSession->setNextTargetMsgSeqNum( value <= 0 ? 1 : value );
00448       copy.removeParameter("Next%20Incoming");
00449     }
00450     if( copy.hasParameter("Next%20Outgoing") )
00451     {
00452       int value = IntConvertor::convert( copy.getParameter("Next%20Outgoing") );
00453       pSession->setNextSenderMsgSeqNum( value <= 0 ? 1 : value );
00454       copy.removeParameter("Next%20Outgoing");
00455     }
00456     if( copy.hasParameter(SEND_REDUNDANT_RESENDREQUESTS) )
00457     {
00458       pSession->setSendRedundantResendRequests( copy.getParameter(SEND_REDUNDANT_RESENDREQUESTS) != "0" );
00459       copy.removeParameter(SEND_REDUNDANT_RESENDREQUESTS);
00460     }
00461     if( copy.hasParameter(CHECK_COMPID) )
00462     {
00463       pSession->setCheckCompId( copy.getParameter(CHECK_COMPID) != "0" );
00464       copy.removeParameter(CHECK_COMPID);
00465     }
00466     if( copy.hasParameter(CHECK_LATENCY) )
00467     {
00468       pSession->setCheckLatency( copy.getParameter(CHECK_LATENCY) != "0" );
00469       copy.removeParameter(CHECK_LATENCY);
00470     }
00471     if( copy.hasParameter(MAX_LATENCY) )
00472     {
00473       int value = IntConvertor::convert( copy.getParameter(MAX_LATENCY) );
00474       pSession->setMaxLatency( value <= 0 ? 1 : value );
00475       copy.removeParameter(MAX_LATENCY);
00476     }
00477     if( copy.hasParameter(LOGON_TIMEOUT) )
00478     {
00479       int value = IntConvertor::convert( copy.getParameter(LOGON_TIMEOUT) );
00480       pSession->setLogonTimeout( value <= 0 ? 1 : value );
00481       copy.removeParameter(LOGON_TIMEOUT);
00482     }
00483     if( copy.hasParameter(LOGOUT_TIMEOUT) )
00484     {
00485       int value = IntConvertor::convert( copy.getParameter(LOGOUT_TIMEOUT) );
00486       pSession->setLogoutTimeout( value <= 0 ? 1 : value );
00487       copy.removeParameter(LOGOUT_TIMEOUT);
00488     }
00489     if( copy.hasParameter(RESET_ON_LOGON) )
00490     {
00491       pSession->setResetOnLogon( copy.getParameter(RESET_ON_LOGON) != "0" );
00492       copy.removeParameter(RESET_ON_LOGON);
00493     }
00494     if( copy.hasParameter(RESET_ON_LOGOUT) )
00495     {
00496       pSession->setResetOnLogout( copy.getParameter(RESET_ON_LOGOUT) != "0" );
00497       copy.removeParameter(RESET_ON_LOGOUT);
00498     }
00499     if( copy.hasParameter(RESET_ON_DISCONNECT) )
00500     {
00501       pSession->setResetOnDisconnect( copy.getParameter(RESET_ON_DISCONNECT) != "0" );
00502       copy.removeParameter(RESET_ON_DISCONNECT);
00503     }
00504     if( copy.hasParameter(REFRESH_ON_LOGON) )
00505     {
00506       pSession->setRefreshOnLogon( copy.getParameter(REFRESH_ON_LOGON) != "0" );
00507       copy.removeParameter(REFRESH_ON_LOGON);
00508     }
00509     if( copy.hasParameter(MILLISECONDS_IN_TIMESTAMP) )
00510     {
00511       pSession->setMillisecondsInTimeStamp( copy.getParameter(MILLISECONDS_IN_TIMESTAMP) != "0" );
00512       copy.removeParameter(MILLISECONDS_IN_TIMESTAMP);
00513     }
00514     if( copy.hasParameter(PERSIST_MESSAGES) )
00515     {
00516       pSession->setPersistMessages( copy.getParameter(PERSIST_MESSAGES) != "0" );
00517       copy.removeParameter(PERSIST_MESSAGES);
00518     }
00519 
00520     if( url != copy.toString() )
00521       h << "<META http-equiv='refresh' content=0;URL='" << copy.toString() << "'>";
00522 
00523     TABLE table(b); table.border(1).cellspacing(2).width(100).text();
00524 
00525     { CAPTION caption(b); caption.text();
00526       EM em(b); em.text();
00527       b << sessionID;
00528       { HR hr(b); hr.text(); }
00529       { b << NBSP; A a(b); a.href("/resetSession" + copy.getParameterString()).text("RESET"); }
00530       { b << NBSP; A a(b); a.href("/refreshSession" + copy.getParameterString()).text("REFRESH"); }
00531     }
00532 
00533     showRow( b, "Enabled", pSession->isEnabled(), url );
00534     showRow( b, "ConnectionType", std::string(pSession->isInitiator() ?"initiator" : "acceptor") );
00535     showRow( b, "SessionTime", pSession->isSessionTime(UtcTimeStamp()) );
00536     showRow( b, "Logged On", pSession->isLoggedOn() );
00537     showRow( b, "Next Incoming", (int)pSession->getExpectedTargetNum(), url );
00538     showRow( b, "Next Outgoing", (int)pSession->getExpectedSenderNum(), url );
00539     showRow( b, SEND_REDUNDANT_RESENDREQUESTS, pSession->getSendRedundantResendRequests(), url );
00540     showRow( b, CHECK_COMPID, pSession->getCheckCompId(), url );
00541     showRow( b, CHECK_LATENCY, pSession->getCheckLatency(), url );
00542     showRow( b, MAX_LATENCY, pSession->getMaxLatency(), url );
00543     showRow( b, LOGON_TIMEOUT, pSession->getLogonTimeout(), url );
00544     showRow( b, LOGOUT_TIMEOUT, pSession->getLogoutTimeout(), url );
00545     showRow( b, RESET_ON_LOGON, pSession->getResetOnLogon(), url );
00546     showRow( b, RESET_ON_LOGOUT, pSession->getResetOnLogout(), url );
00547     showRow( b, RESET_ON_DISCONNECT, pSession->getResetOnDisconnect(), url );
00548     showRow( b, REFRESH_ON_LOGON, pSession->getRefreshOnLogon(), url );
00549     showRow( b, MILLISECONDS_IN_TIMESTAMP, pSession->getMillisecondsInTimeStamp(), url );
00550     showRow( b, PERSIST_MESSAGES, pSession->getPersistMessages(), url );
00551   }
00552   catch( std::exception& e )
00553   {
00554     b << e.what();
00555   }
00556 }
00557 
00558 void HttpConnection::processResetSession
00559 ( const HttpMessage& request, std::stringstream& h, std::stringstream& b )
00560 {
00561   try
00562   {
00563     HttpMessage copy = request;
00564     std::string beginString = request.getParameter( "BeginString" );
00565     std::string senderCompID = request.getParameter( "SenderCompID" );
00566     std::string targetCompID = request.getParameter( "TargetCompID" );
00567     std::string sessionQualifier;
00568     if( copy.hasParameter("SessionQualifier") )
00569       sessionQualifier = copy.getParameter( "SessionQualifier" );
00570 
00571     SessionID sessionID( beginString, senderCompID, targetCompID, sessionQualifier );
00572     Session* pSession = Session::lookupSession( sessionID );
00573     if( pSession == 0 ) throw SessionNotFound();
00574 
00575     std::string sessionUrl = "/session" + request.getParameterString();
00576 
00577     bool confirm = false;
00578     if( copy.hasParameter("confirm") && copy.getParameter("confirm") != "0" )
00579     {
00580       confirm = true;
00581       pSession->reset();
00582       copy.removeParameter("confirm");
00583     }
00584 
00585     if( confirm )
00586     {
00587       h << "<META http-equiv='refresh' content=2;URL='" << "/session" << copy.getParameterString() << "'>";
00588       CENTER center(b); center.text();
00589       H2 h2(b); h2.text();
00590       { A a(b); a.href("/session" + copy.getParameterString()).text(sessionID.toString()); }
00591       b << " has been reset";
00592     }
00593     else
00594     {
00595       { CENTER center(b); center.text();
00596         H2 h2(b); h2.text();
00597         b << "Are you sure you want to reset session ";
00598         { A a(b); a.href(sessionUrl + request.getParameterString()).text(sessionID.toString()); }
00599         b << "?";
00600       }
00601       { CENTER center(b); center.text();
00602         b << "[";
00603         { A a(b); a.href(request.toString() + "&confirm=1").text("YES, reset session"); }
00604         b << "]" << NBSP << "[";
00605         { A a(b); a.href(sessionUrl).text("NO, do not reset session"); }
00606         b << "]";
00607       }
00608     }
00609   }
00610   catch( std::exception& e )
00611   {
00612     b << e.what();
00613   }
00614 }
00615 
00616 void HttpConnection::processRefreshSession
00617 ( const HttpMessage& request, std::stringstream& h, std::stringstream& b )
00618 {
00619   try
00620   {
00621     HttpMessage copy = request;
00622     std::string beginString = request.getParameter( "BeginString" );
00623     std::string senderCompID = request.getParameter( "SenderCompID" );
00624     std::string targetCompID = request.getParameter( "TargetCompID" );
00625     std::string sessionQualifier;
00626     if( copy.hasParameter("SessionQualifier") )
00627     sessionQualifier = copy.getParameter( "SessionQualifier" );
00628 
00629     SessionID sessionID( beginString, senderCompID, targetCompID, sessionQualifier );
00630     Session* pSession = Session::lookupSession( sessionID );
00631     if( pSession == 0 ) throw SessionNotFound();
00632 
00633     std::string sessionUrl = "/session" + request.getParameterString();
00634 
00635     bool confirm = false;
00636     if( copy.hasParameter("confirm") && copy.getParameter("confirm") != "0" )
00637     {
00638       confirm = true;
00639       pSession->refresh();
00640       copy.removeParameter("confirm");
00641     }
00642 
00643     if( confirm )
00644     {
00645       h << "<META http-equiv='refresh' content=2;URL='" << "/session" << copy.getParameterString() << "'>";
00646       CENTER center(b); center.text();
00647       H2 h2(b); h2.text();
00648       { A a(b); a.href("/session" + copy.getParameterString()).text(sessionID.toString()); }
00649       b << " has been refreshed";
00650     }
00651     else
00652     {
00653       { CENTER center(b); center.text();
00654         H2 h2(b); h2.text();
00655         b << "Are you sure you want to refresh session ";
00656         { A a(b); a.href(sessionUrl + request.getParameterString()).text(sessionID.toString()); }
00657         b << "?";
00658       }
00659       { CENTER center(b); center.text();
00660         b << "[";
00661         { A a(b); a.href(request.toString() + "&confirm=1").text("YES, refresh session"); }
00662         b << "]" << NBSP << "[";
00663         { A a(b); a.href(sessionUrl).text("NO, do not refresh session"); }
00664         b << "]";
00665       }
00666     }
00667   }
00668   catch( std::exception& e )
00669   {
00670     b << e.what();
00671   }
00672 }
00673 
00674 void HttpConnection::showRow
00675 ( std::stringstream& s, const std::string& name, bool value, const std::string& url )
00676 {
00677     { TR tr(s); tr.text();
00678       { TD td(s); td.text(name); }
00679       { TD td(s); td.text(value ? "yes" : "no"); }
00680       { TD td(s); td.text();
00681         CENTER center(s); center.text();
00682         if( url.size() )
00683         {
00684           std::stringstream href;
00685           href << url << "&" << name << "=" << !value;
00686           A a(s); a.href(href.str()).text("toggle");
00687         }
00688       }
00689     }
00690 }
00691 
00692 void HttpConnection::showRow
00693 ( std::stringstream& s, const std::string& name, const std::string& value, const std::string& url )
00694 {
00695     { TR tr(s); tr.text();
00696       { TD td(s); td.text(name); }
00697       { TD td(s); td.text(value); }
00698       { TD td(s); td.text();
00699         CENTER center(s); center.text();
00700       }
00701     }
00702 }
00703 
00704 void HttpConnection::showRow
00705 ( std::stringstream& s, const std::string& name, int value, const std::string& url )
00706 {
00707     { TR tr(s); tr.text();
00708       { TD td(s); td.text(name); }
00709       { TD td(s); td.text(value); }
00710       { TD td(s); td.text();
00711         CENTER center(s); center.text();
00712         {
00713           std::stringstream href;
00714           href << url << "&" << name << "=" << value - 10;
00715           A a(s); a.href(href.str()).text("<<");
00716         }
00717         s << NBSP;
00718         {
00719           std::stringstream href;
00720           href << url << "&" << name << "=" << value - 1;
00721           A a(s); a.href(href.str()).text("<");
00722         }
00723         s << NBSP << "|" << NBSP;
00724         {
00725           std::stringstream href;
00726           href << url << "&" << name << "=" << value + 1;
00727           A a(s); a.href(href.str()).text(">");
00728         }
00729         s << NBSP;
00730         {
00731           std::stringstream href;
00732           href << url << "&" << name << "=" << value + 10;
00733           A a(s); a.href(href.str()).text(">>");
00734         }
00735       }
00736     }
00737 }
00738 
00739 } // namespace FIX

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