Public Member Functions | Private Member Functions | Private Attributes | List of all members
FIX::HttpConnection Class Reference

Encapsulates a HTTP socket file descriptor. More...

#include <HttpConnection.h>

Collaboration diagram for FIX::HttpConnection:
Collaboration graph
[legend]

Public Member Functions

 HttpConnection (int s)
 
int getSocket () const
 
bool read ()
 

Private Member Functions

bool readMessage (std::string &msg) throw ( SocketRecvFailed )
 
void processStream ()
 
void processRequest (const HttpMessage &)
 
void processRoot (const HttpMessage &, std::stringstream &h, std::stringstream &b)
 
void processResetSessions (const HttpMessage &, std::stringstream &h, std::stringstream &b)
 
void processRefreshSessions (const HttpMessage &, std::stringstream &h, std::stringstream &b)
 
void processEnableSessions (const HttpMessage &, std::stringstream &h, std::stringstream &b)
 
void processDisableSessions (const HttpMessage &, std::stringstream &h, std::stringstream &b)
 
void processSession (const HttpMessage &, std::stringstream &h, std::stringstream &b)
 
void processResetSession (const HttpMessage &, std::stringstream &h, std::stringstream &b)
 
void processRefreshSession (const HttpMessage &, std::stringstream &h, std::stringstream &b)
 
void showToggle (std::stringstream &s, const std::string &name, bool value, const std::string &url)
 
void showRow (std::stringstream &s, const std::string &name, bool value, const std::string &url="")
 
void showRow (std::stringstream &s, const std::string &name, const std::string &value, const std::string &url="")
 
void showRow (std::stringstream &s, const std::string &name, int value, const std::string &url="")
 
bool send (const std::string &)
 
void disconnect (int error=0)
 

Private Attributes

int m_socket
 
char m_buffer [BUFSIZ]
 
HttpParser m_parser
 
fd_set m_fds
 

Detailed Description

Encapsulates a HTTP socket file descriptor.

Definition at line 54 of file HttpConnection.h.

Constructor & Destructor Documentation

◆ HttpConnection()

FIX::HttpConnection::HttpConnection ( int  s)

Definition at line 36 of file HttpConnection.cpp.

37 : m_socket( s )
38 {
39  FD_ZERO( &m_fds );
40  FD_SET( m_socket, &m_fds );
41 }

References m_fds, and m_socket.

Member Function Documentation

◆ disconnect()

void FIX::HttpConnection::disconnect ( int  error = 0)
private

Definition at line 48 of file HttpConnection.cpp.

49 {
50  if( error > 0 )
52 
54 }

References FIX::HttpMessage::createResponse(), m_socket, send(), and FIX::socket_close().

Referenced by processRequest(), processStream(), and read().

◆ getSocket()

int FIX::HttpConnection::getSocket ( ) const
inline

Definition at line 59 of file HttpConnection.h.

◆ processDisableSessions()

void FIX::HttpConnection::processDisableSessions ( const HttpMessage request,
std::stringstream &  h,
std::stringstream &  b 
)
private

Definition at line 375 of file HttpConnection.cpp.

376 {
377  try
378  {
379  HttpMessage copy = request;
380 
381  bool confirm = false;
382  if( copy.hasParameter("confirm") && copy.getParameter("confirm") != "0" )
383  {
384  confirm = true;
385  std::set<SessionID> sessions = Session::getSessions();
386  std::set<SessionID>::iterator session;
387  for( session = sessions.begin(); session != sessions.end(); ++session )
388  Session::lookupSession( *session )->logout();
389  copy.removeParameter("confirm");
390  }
391 
392  if( confirm )
393  {
394  h << "<META http-equiv='refresh' content=2;URL='" << "/'>";
395  CENTER center(b); center.text();
396  H2 h2(b); h2.text();
397  { A a(b); a.href("/").text("Sessions"); }
398  b << " have been disabled";
399  }
400  else
401  {
402  { CENTER center(b); center.text();
403  H2 h2(b); h2.text();
404  b << "Are you sure you want to disable all sessions ?";
405  }
406  { CENTER center(b); center.text();
407  b << "[";
408  { A a(b); a.href(request.toString() + "?confirm=1").text("YES, disable sessions"); }
409  b << "]" << NBSP << "[";
410  { A a(b); a.href("/").text("NO, do not disable sessions"); }
411  b << "]";
412  }
413  }
414  }
415  catch( std::exception& e )
416  {
417  b << e.what();
418  }
419 }

References FIX::HttpMessage::getParameter(), FIX::Session::getSessions(), FIX::HttpMessage::hasParameter(), HTML::A::href(), FIX::Session::logout(), FIX::Session::lookupSession(), HTML::NBSP, FIX::HttpMessage::removeParameter(), HTML::TAG::text(), and FIX::HttpMessage::toString().

Referenced by processRequest().

◆ processEnableSessions()

void FIX::HttpConnection::processEnableSessions ( const HttpMessage request,
std::stringstream &  h,
std::stringstream &  b 
)
private

Definition at line 328 of file HttpConnection.cpp.

329 {
330  try
331  {
332  HttpMessage copy = request;
333 
334  bool confirm = false;
335  if( copy.hasParameter("confirm") && copy.getParameter("confirm") != "0" )
336  {
337  confirm = true;
338  std::set<SessionID> sessions = Session::getSessions();
339  std::set<SessionID>::iterator session;
340  for( session = sessions.begin(); session != sessions.end(); ++session )
341  Session::lookupSession( *session )->logon();
342  copy.removeParameter("confirm");
343  }
344 
345  if( confirm )
346  {
347  h << "<META http-equiv='refresh' content=2;URL='" << "/'>";
348  CENTER center(b); center.text();
349  H2 h2(b); h2.text();
350  { A a(b); a.href("/").text("Sessions"); }
351  b << " have been enabled";
352  }
353  else
354  {
355  { CENTER center(b); center.text();
356  H2 h2(b); h2.text();
357  b << "Are you sure you want to enable all sessions ?";
358  }
359  { CENTER center(b); center.text();
360  b << "[";
361  { A a(b); a.href(request.toString() + "?confirm=1").text("YES, enable sessions"); }
362  b << "]" << NBSP << "[";
363  { A a(b); a.href("/").text("NO, do not enable sessions"); }
364  b << "]";
365  }
366  }
367  }
368  catch( std::exception& e )
369  {
370  b << e.what();
371  }
372 }

References FIX::HttpMessage::getParameter(), FIX::Session::getSessions(), FIX::HttpMessage::hasParameter(), HTML::A::href(), FIX::Session::logon(), FIX::Session::lookupSession(), HTML::NBSP, FIX::HttpMessage::removeParameter(), HTML::TAG::text(), and FIX::HttpMessage::toString().

Referenced by processRequest().

◆ processRefreshSession()

void FIX::HttpConnection::processRefreshSession ( const HttpMessage request,
std::stringstream &  h,
std::stringstream &  b 
)
private

Definition at line 617 of file HttpConnection.cpp.

618 {
619  try
620  {
621  HttpMessage copy = request;
622  std::string beginString = request.getParameter( "BeginString" );
623  std::string senderCompID = request.getParameter( "SenderCompID" );
624  std::string targetCompID = request.getParameter( "TargetCompID" );
625  std::string sessionQualifier;
626  if( copy.hasParameter("SessionQualifier") )
627  sessionQualifier = copy.getParameter( "SessionQualifier" );
628 
629  SessionID sessionID( beginString, senderCompID, targetCompID, sessionQualifier );
630  Session* pSession = Session::lookupSession( sessionID );
631  if( pSession == 0 ) throw SessionNotFound();
632 
633  std::string sessionUrl = "/session" + request.getParameterString();
634 
635  bool confirm = false;
636  if( copy.hasParameter("confirm") && copy.getParameter("confirm") != "0" )
637  {
638  confirm = true;
639  pSession->refresh();
640  copy.removeParameter("confirm");
641  }
642 
643  if( confirm )
644  {
645  h << "<META http-equiv='refresh' content=2;URL='" << "/session" << copy.getParameterString() << "'>";
646  CENTER center(b); center.text();
647  H2 h2(b); h2.text();
648  { A a(b); a.href("/session" + copy.getParameterString()).text(sessionID.toString()); }
649  b << " has been refreshed";
650  }
651  else
652  {
653  { CENTER center(b); center.text();
654  H2 h2(b); h2.text();
655  b << "Are you sure you want to refresh session ";
656  { A a(b); a.href(sessionUrl + request.getParameterString()).text(sessionID.toString()); }
657  b << "?";
658  }
659  { CENTER center(b); center.text();
660  b << "[";
661  { A a(b); a.href(request.toString() + "&confirm=1").text("YES, refresh session"); }
662  b << "]" << NBSP << "[";
663  { A a(b); a.href(sessionUrl).text("NO, do not refresh session"); }
664  b << "]";
665  }
666  }
667  }
668  catch( std::exception& e )
669  {
670  b << e.what();
671  }
672 }

References FIX::HttpMessage::getParameter(), FIX::HttpMessage::getParameterString(), FIX::HttpMessage::hasParameter(), HTML::A::href(), FIX::Session::lookupSession(), HTML::NBSP, FIX::Session::refresh(), FIX::HttpMessage::removeParameter(), HTML::TAG::text(), FIX::HttpMessage::toString(), and FIX::SessionID::toString().

Referenced by processRequest().

◆ processRefreshSessions()

void FIX::HttpConnection::processRefreshSessions ( const HttpMessage request,
std::stringstream &  h,
std::stringstream &  b 
)
private

Definition at line 281 of file HttpConnection.cpp.

282 {
283  try
284  {
285  HttpMessage copy = request;
286 
287  bool confirm = false;
288  if( copy.hasParameter("confirm") && copy.getParameter("confirm") != "0" )
289  {
290  confirm = true;
291  std::set<SessionID> sessions = Session::getSessions();
292  std::set<SessionID>::iterator session;
293  for( session = sessions.begin(); session != sessions.end(); ++session )
294  Session::lookupSession( *session )->refresh();
295  copy.removeParameter("confirm");
296  }
297 
298  if( confirm )
299  {
300  h << "<META http-equiv='refresh' content=2;URL='" << "/'>";
301  CENTER center(b); center.text();
302  H2 h2(b); h2.text();
303  { A a(b); a.href("/").text("Sessions"); }
304  b << " have been refreshed";
305  }
306  else
307  {
308  { CENTER center(b); center.text();
309  H2 h2(b); h2.text();
310  b << "Are you sure you want to refresh all sessions ?";
311  }
312  { CENTER center(b); center.text();
313  b << "[";
314  { A a(b); a.href(request.toString() + "?confirm=1").text("YES, refresh sessions"); }
315  b << "]" << NBSP << "[";
316  { A a(b); a.href("/").text("NO, do not refresh sessions"); }
317  b << "]";
318  }
319  }
320  }
321  catch( std::exception& e )
322  {
323  b << e.what();
324  }
325 }

References FIX::HttpMessage::getParameter(), FIX::Session::getSessions(), FIX::HttpMessage::hasParameter(), HTML::A::href(), FIX::Session::lookupSession(), HTML::NBSP, FIX::Session::refresh(), FIX::HttpMessage::removeParameter(), HTML::TAG::text(), and FIX::HttpMessage::toString().

Referenced by processRequest().

◆ processRequest()

void FIX::HttpConnection::processRequest ( const HttpMessage request)
private

Definition at line 126 of file HttpConnection.cpp.

127 {
128  int error = 200;
129  std::stringstream h;
130  std::stringstream b;
131  std::string titleString = "QuickFIX Engine Web Interface";
132 
133  { HEAD head(h); head.text();
134  { CENTER center(h); center.text();
135  { TITLE title(h); title.text(titleString); }
136  { H1 h1(h); h1.text(titleString); }
137  }
138  { CENTER center(h); center.text();
139  { A a(h); a.href("/").text("HOME"); }
140  h << NBSP;
141  { A a(h); a.href(request.toString()).text("RELOAD"); }
142  }
143  HR hr(h); hr.text();
144  }
145 
146  BODY body(b); body.text();
147 
148  try
149  {
150  if( request.getRootString() == "/" )
151  processRoot( request, h, b );
152  else if( request.getRootString() == "/resetSessions" )
153  processResetSessions( request, h, b );
154  else if( request.getRootString() == "/refreshSessions" )
155  processRefreshSessions( request, h, b );
156  else if( request.getRootString() == "/enableSessions" )
157  processEnableSessions( request, h, b );
158  else if( request.getRootString() == "/disableSessions" )
159  processDisableSessions( request, h, b );
160  else if( request.getRootString() == "/session" )
161  processSession( request, h, b );
162  else if( request.getRootString() == "/resetSession" )
163  processResetSession( request, h, b );
164  else if( request.getRootString() == "/refreshSession" )
165  processRefreshSession( request, h, b );
166  else
167  error = 404;
168  }
169  catch( std::exception& e )
170  {
171  error = 400;
172  b << e.what();
173  }
174 
175  std::string response = "<HTML>" + h.str() + b.str() + "</HTML>";
176  send( HttpMessage::createResponse(error, error == 200 ? response : "") );
177 
178  disconnect();
179 }

References FIX::HttpMessage::createResponse(), disconnect(), FIX::HttpMessage::getRootString(), HTML::A::href(), HTML::NBSP, processDisableSessions(), processEnableSessions(), processRefreshSession(), processRefreshSessions(), processResetSession(), processResetSessions(), processRoot(), processSession(), send(), HTML::TAG::text(), and FIX::HttpMessage::toString().

Referenced by processStream().

◆ processResetSession()

void FIX::HttpConnection::processResetSession ( const HttpMessage request,
std::stringstream &  h,
std::stringstream &  b 
)
private

Definition at line 559 of file HttpConnection.cpp.

560 {
561  try
562  {
563  HttpMessage copy = request;
564  std::string beginString = request.getParameter( "BeginString" );
565  std::string senderCompID = request.getParameter( "SenderCompID" );
566  std::string targetCompID = request.getParameter( "TargetCompID" );
567  std::string sessionQualifier;
568  if( copy.hasParameter("SessionQualifier") )
569  sessionQualifier = copy.getParameter( "SessionQualifier" );
570 
571  SessionID sessionID( beginString, senderCompID, targetCompID, sessionQualifier );
572  Session* pSession = Session::lookupSession( sessionID );
573  if( pSession == 0 ) throw SessionNotFound();
574 
575  std::string sessionUrl = "/session" + request.getParameterString();
576 
577  bool confirm = false;
578  if( copy.hasParameter("confirm") && copy.getParameter("confirm") != "0" )
579  {
580  confirm = true;
581  pSession->reset();
582  copy.removeParameter("confirm");
583  }
584 
585  if( confirm )
586  {
587  h << "<META http-equiv='refresh' content=2;URL='" << "/session" << copy.getParameterString() << "'>";
588  CENTER center(b); center.text();
589  H2 h2(b); h2.text();
590  { A a(b); a.href("/session" + copy.getParameterString()).text(sessionID.toString()); }
591  b << " has been reset";
592  }
593  else
594  {
595  { CENTER center(b); center.text();
596  H2 h2(b); h2.text();
597  b << "Are you sure you want to reset session ";
598  { A a(b); a.href(sessionUrl + request.getParameterString()).text(sessionID.toString()); }
599  b << "?";
600  }
601  { CENTER center(b); center.text();
602  b << "[";
603  { A a(b); a.href(request.toString() + "&confirm=1").text("YES, reset session"); }
604  b << "]" << NBSP << "[";
605  { A a(b); a.href(sessionUrl).text("NO, do not reset session"); }
606  b << "]";
607  }
608  }
609  }
610  catch( std::exception& e )
611  {
612  b << e.what();
613  }
614 }

References FIX::HttpMessage::getParameter(), FIX::HttpMessage::getParameterString(), FIX::HttpMessage::hasParameter(), HTML::A::href(), FIX::Session::lookupSession(), HTML::NBSP, FIX::HttpMessage::removeParameter(), FIX::Session::reset(), HTML::TAG::text(), FIX::HttpMessage::toString(), and FIX::SessionID::toString().

Referenced by processRequest().

◆ processResetSessions()

void FIX::HttpConnection::processResetSessions ( const HttpMessage request,
std::stringstream &  h,
std::stringstream &  b 
)
private

Definition at line 234 of file HttpConnection.cpp.

235 {
236  try
237  {
238  HttpMessage copy = request;
239 
240  bool confirm = false;
241  if( copy.hasParameter("confirm") && copy.getParameter("confirm") != "0" )
242  {
243  confirm = true;
244  std::set<SessionID> sessions = Session::getSessions();
245  std::set<SessionID>::iterator session;
246  for( session = sessions.begin(); session != sessions.end(); ++session )
247  Session::lookupSession( *session )->reset();
248  copy.removeParameter("confirm");
249  }
250 
251  if( confirm )
252  {
253  h << "<META http-equiv='refresh' content=2;URL='" << "/'>";
254  CENTER center(b); center.text();
255  H2 h2(b); h2.text();
256  { A a(b); a.href("/").text("Sessions"); }
257  b << " have been reset";
258  }
259  else
260  {
261  { CENTER center(b); center.text();
262  H2 h2(b); h2.text();
263  b << "Are you sure you want to reset all sessions ?";
264  }
265  { CENTER center(b); center.text();
266  b << "[";
267  { A a(b); a.href(request.toString() + "?confirm=1").text("YES, reset sessions"); }
268  b << "]" << NBSP << "[";
269  { A a(b); a.href("/").text("NO, do not reset sessions"); }
270  b << "]";
271  }
272  }
273  }
274  catch( std::exception& e )
275  {
276  b << e.what();
277  }
278 }

References FIX::HttpMessage::getParameter(), FIX::Session::getSessions(), FIX::HttpMessage::hasParameter(), HTML::A::href(), FIX::Session::lookupSession(), HTML::NBSP, FIX::HttpMessage::removeParameter(), FIX::Session::reset(), HTML::TAG::text(), and FIX::HttpMessage::toString().

Referenced by processRequest().

◆ processRoot()

void FIX::HttpConnection::processRoot ( const HttpMessage request,
std::stringstream &  h,
std::stringstream &  b 
)
private

Definition at line 182 of file HttpConnection.cpp.

183 {
184  TABLE table(b); table.border(1).cellspacing(2).width(100).text();
185 
186  { CAPTION caption(b); caption.text();
187  EM em(b); em.text();
188  b << Session::numSessions() << " Sessions managed by QuickFIX";
189  { HR hr(b); hr.text(); }
190  { b << NBSP; A a(b); a.href("/resetSessions" + request.getParameterString()).text("RESET"); }
191  { b << NBSP; A a(b); a.href("/refreshSessions" + request.getParameterString()).text("REFRESH"); }
192  { b << NBSP; A a(b); a.href("/enableSessions" + request.getParameterString()).text("ENABLE"); }
193  { b << NBSP; A a(b); a.href("/disableSessions" + request.getParameterString()).text("DISABLE"); }
194  }
195 
196  { TR tr(b); tr.text();
197  { TD td(b); td.align("center").text("Session"); }
198  { TD td(b); td.align("center").text("ConnectionType"); }
199  { TD td(b); td.align("center").text("Enabled"); }
200  { TD td(b); td.align("center").text("Session Time"); }
201  { TD td(b); td.align("center").text("Logged On"); }
202  { TD td(b); td.align("center").text("Next Incoming"); }
203  { TD td(b); td.align("center").text("Next Outgoing"); }
204  }
205 
206  std::set<SessionID> sessions = Session::getSessions();
207  std::set<SessionID>::iterator i;
208  for( i = sessions.begin(); i != sessions.end(); ++i )
209  {
210  Session* pSession = Session::lookupSession( *i );
211  if( !pSession ) continue;
212 
213  { TR tr(b); tr.text();
214  { TD td(b); td.text();
215  std::string href = "/session?BeginString=" + i->getBeginString().getValue() +
216  "&SenderCompID=" + i->getSenderCompID().getValue() +
217  "&TargetCompID=" + i->getTargetCompID().getValue();
218  if( i->getSessionQualifier().size() )
219  href += "&SessionQualifier=" + i->getSessionQualifier();
220 
221  A a(b); a.href(href).text(i->toString());
222  }
223  { TD td(b); td.text(pSession->isInitiator() ? "initiator" : "acceptor"); }
224  { TD td(b); td.text(pSession->isEnabled() ? "yes" : "no"); }
225  { TD td(b); td.text(pSession->isSessionTime(UtcTimeStamp()) ? "yes" : "no"); }
226  { TD td(b); td.text(pSession->isLoggedOn() ? "yes" : "no"); }
227  { TD td(b); td.text(pSession->getExpectedTargetNum()); }
228  { TD td(b); td.text(pSession->getExpectedSenderNum()); }
229  }
230  }
231 }

References HTML::TD::align(), HTML::TABLE::border(), HTML::TABLE::cellspacing(), FIX::Session::getExpectedSenderNum(), FIX::Session::getExpectedTargetNum(), FIX::HttpMessage::getParameterString(), FIX::Session::getSessions(), HTML::A::href(), FIX::Session::isEnabled(), FIX::Session::isInitiator(), FIX::Session::isLoggedOn(), FIX::Session::isSessionTime(), FIX::Session::lookupSession(), HTML::NBSP, FIX::Session::numSessions(), HTML::TAG::text(), and HTML::TABLE::width().

Referenced by processRequest().

◆ processSession()

void FIX::HttpConnection::processSession ( const HttpMessage request,
std::stringstream &  h,
std::stringstream &  b 
)
private

Definition at line 422 of file HttpConnection.cpp.

423 {
424  try
425  {
426  HttpMessage copy = request;
427  std::string url = request.toString();
428  std::string beginString = copy.getParameter( "BeginString" );
429  std::string senderCompID = copy.getParameter( "SenderCompID" );
430  std::string targetCompID = copy.getParameter( "TargetCompID" );
431  std::string sessionQualifier;
432  if( copy.hasParameter("SessionQualifier") )
433  sessionQualifier = copy.getParameter( "SessionQualifier" );
434 
435  SessionID sessionID( beginString, senderCompID, targetCompID, sessionQualifier );
436  Session* pSession = Session::lookupSession( sessionID );
437  if( pSession == 0 ) throw SessionNotFound();
438 
439  if( copy.hasParameter("Enabled") )
440  {
441  copy.getParameter("Enabled") == "0" ? pSession->logout() : pSession->logon();
442  copy.removeParameter("Enabled");
443  }
444  if( copy.hasParameter("Next%20Incoming") )
445  {
446  int value = IntConvertor::convert( copy.getParameter("Next%20Incoming") );
447  pSession->setNextTargetMsgSeqNum( value <= 0 ? 1 : value );
448  copy.removeParameter("Next%20Incoming");
449  }
450  if( copy.hasParameter("Next%20Outgoing") )
451  {
452  int value = IntConvertor::convert( copy.getParameter("Next%20Outgoing") );
453  pSession->setNextSenderMsgSeqNum( value <= 0 ? 1 : value );
454  copy.removeParameter("Next%20Outgoing");
455  }
456  if( copy.hasParameter(SEND_REDUNDANT_RESENDREQUESTS) )
457  {
458  pSession->setSendRedundantResendRequests( copy.getParameter(SEND_REDUNDANT_RESENDREQUESTS) != "0" );
459  copy.removeParameter(SEND_REDUNDANT_RESENDREQUESTS);
460  }
461  if( copy.hasParameter(CHECK_COMPID) )
462  {
463  pSession->setCheckCompId( copy.getParameter(CHECK_COMPID) != "0" );
464  copy.removeParameter(CHECK_COMPID);
465  }
466  if( copy.hasParameter(CHECK_LATENCY) )
467  {
468  pSession->setCheckLatency( copy.getParameter(CHECK_LATENCY) != "0" );
469  copy.removeParameter(CHECK_LATENCY);
470  }
471  if( copy.hasParameter(MAX_LATENCY) )
472  {
473  int value = IntConvertor::convert( copy.getParameter(MAX_LATENCY) );
474  pSession->setMaxLatency( value <= 0 ? 1 : value );
475  copy.removeParameter(MAX_LATENCY);
476  }
477  if( copy.hasParameter(LOGON_TIMEOUT) )
478  {
479  int value = IntConvertor::convert( copy.getParameter(LOGON_TIMEOUT) );
480  pSession->setLogonTimeout( value <= 0 ? 1 : value );
481  copy.removeParameter(LOGON_TIMEOUT);
482  }
483  if( copy.hasParameter(LOGOUT_TIMEOUT) )
484  {
485  int value = IntConvertor::convert( copy.getParameter(LOGOUT_TIMEOUT) );
486  pSession->setLogoutTimeout( value <= 0 ? 1 : value );
487  copy.removeParameter(LOGOUT_TIMEOUT);
488  }
489  if( copy.hasParameter(RESET_ON_LOGON) )
490  {
491  pSession->setResetOnLogon( copy.getParameter(RESET_ON_LOGON) != "0" );
492  copy.removeParameter(RESET_ON_LOGON);
493  }
494  if( copy.hasParameter(RESET_ON_LOGOUT) )
495  {
496  pSession->setResetOnLogout( copy.getParameter(RESET_ON_LOGOUT) != "0" );
497  copy.removeParameter(RESET_ON_LOGOUT);
498  }
499  if( copy.hasParameter(RESET_ON_DISCONNECT) )
500  {
501  pSession->setResetOnDisconnect( copy.getParameter(RESET_ON_DISCONNECT) != "0" );
502  copy.removeParameter(RESET_ON_DISCONNECT);
503  }
504  if( copy.hasParameter(REFRESH_ON_LOGON) )
505  {
506  pSession->setRefreshOnLogon( copy.getParameter(REFRESH_ON_LOGON) != "0" );
507  copy.removeParameter(REFRESH_ON_LOGON);
508  }
509  if( copy.hasParameter(MILLISECONDS_IN_TIMESTAMP) )
510  {
511  pSession->setMillisecondsInTimeStamp( copy.getParameter(MILLISECONDS_IN_TIMESTAMP) != "0" );
512  copy.removeParameter(MILLISECONDS_IN_TIMESTAMP);
513  }
514  if( copy.hasParameter(PERSIST_MESSAGES) )
515  {
516  pSession->setPersistMessages( copy.getParameter(PERSIST_MESSAGES) != "0" );
517  copy.removeParameter(PERSIST_MESSAGES);
518  }
519 
520  if( url != copy.toString() )
521  h << "<META http-equiv='refresh' content=0;URL='" << copy.toString() << "'>";
522 
523  TABLE table(b); table.border(1).cellspacing(2).width(100).text();
524 
525  { CAPTION caption(b); caption.text();
526  EM em(b); em.text();
527  b << sessionID;
528  { HR hr(b); hr.text(); }
529  { b << NBSP; A a(b); a.href("/resetSession" + copy.getParameterString()).text("RESET"); }
530  { b << NBSP; A a(b); a.href("/refreshSession" + copy.getParameterString()).text("REFRESH"); }
531  }
532 
533  showRow( b, "Enabled", pSession->isEnabled(), url );
534  showRow( b, "ConnectionType", std::string(pSession->isInitiator() ?"initiator" : "acceptor") );
535  showRow( b, "SessionTime", pSession->isSessionTime(UtcTimeStamp()) );
536  showRow( b, "Logged On", pSession->isLoggedOn() );
537  showRow( b, "Next Incoming", (int)pSession->getExpectedTargetNum(), url );
538  showRow( b, "Next Outgoing", (int)pSession->getExpectedSenderNum(), url );
539  showRow( b, SEND_REDUNDANT_RESENDREQUESTS, pSession->getSendRedundantResendRequests(), url );
540  showRow( b, CHECK_COMPID, pSession->getCheckCompId(), url );
541  showRow( b, CHECK_LATENCY, pSession->getCheckLatency(), url );
542  showRow( b, MAX_LATENCY, pSession->getMaxLatency(), url );
543  showRow( b, LOGON_TIMEOUT, pSession->getLogonTimeout(), url );
544  showRow( b, LOGOUT_TIMEOUT, pSession->getLogoutTimeout(), url );
545  showRow( b, RESET_ON_LOGON, pSession->getResetOnLogon(), url );
546  showRow( b, RESET_ON_LOGOUT, pSession->getResetOnLogout(), url );
547  showRow( b, RESET_ON_DISCONNECT, pSession->getResetOnDisconnect(), url );
548  showRow( b, REFRESH_ON_LOGON, pSession->getRefreshOnLogon(), url );
549  showRow( b, MILLISECONDS_IN_TIMESTAMP, pSession->getMillisecondsInTimeStamp(), url );
550  showRow( b, PERSIST_MESSAGES, pSession->getPersistMessages(), url );
551  }
552  catch( std::exception& e )
553  {
554  b << e.what();
555  }
556 }

References HTML::TABLE::border(), HTML::TABLE::cellspacing(), FIX::CHECK_COMPID, FIX::CHECK_LATENCY, FIX::IntConvertor::convert(), FIX::Session::getCheckCompId(), FIX::Session::getCheckLatency(), FIX::Session::getExpectedSenderNum(), FIX::Session::getExpectedTargetNum(), FIX::Session::getLogonTimeout(), FIX::Session::getLogoutTimeout(), FIX::Session::getMaxLatency(), FIX::Session::getMillisecondsInTimeStamp(), FIX::HttpMessage::getParameter(), FIX::HttpMessage::getParameterString(), FIX::Session::getPersistMessages(), FIX::Session::getRefreshOnLogon(), FIX::Session::getResetOnDisconnect(), FIX::Session::getResetOnLogon(), FIX::Session::getResetOnLogout(), FIX::Session::getSendRedundantResendRequests(), FIX::HttpMessage::hasParameter(), HTML::A::href(), FIX::Session::isEnabled(), FIX::Session::isInitiator(), FIX::Session::isLoggedOn(), FIX::Session::isSessionTime(), FIX::Session::logon(), FIX::LOGON_TIMEOUT, FIX::Session::logout(), FIX::LOGOUT_TIMEOUT, FIX::Session::lookupSession(), FIX::MAX_LATENCY, FIX::MILLISECONDS_IN_TIMESTAMP, HTML::NBSP, FIX::PERSIST_MESSAGES, FIX::REFRESH_ON_LOGON, FIX::HttpMessage::removeParameter(), FIX::RESET_ON_DISCONNECT, FIX::RESET_ON_LOGON, FIX::RESET_ON_LOGOUT, FIX::SEND_REDUNDANT_RESENDREQUESTS, FIX::Session::setCheckCompId(), FIX::Session::setCheckLatency(), FIX::Session::setLogonTimeout(), FIX::Session::setLogoutTimeout(), FIX::Session::setMaxLatency(), FIX::Session::setMillisecondsInTimeStamp(), FIX::Session::setNextSenderMsgSeqNum(), FIX::Session::setNextTargetMsgSeqNum(), FIX::Session::setPersistMessages(), FIX::Session::setRefreshOnLogon(), FIX::Session::setResetOnDisconnect(), FIX::Session::setResetOnLogon(), FIX::Session::setResetOnLogout(), FIX::Session::setSendRedundantResendRequests(), HTML::TAG::text(), FIX::HttpMessage::toString(), and HTML::TABLE::width().

Referenced by processRequest().

◆ processStream()

void FIX::HttpConnection::processStream ( )
private

Definition at line 107 of file HttpConnection.cpp.

108 {
109  std::string msg;
110  try
111  {
112  if( !readMessage(msg) )
113  return;
114  HttpMessage request( msg );
115  processRequest( request );
116  }
117  catch( InvalidMessage& )
118  {
119  disconnect( 400 );
120  return;
121  }
122 
123  return;
124 }

References disconnect(), processRequest(), and readMessage().

Referenced by read().

◆ read()

bool FIX::HttpConnection::read ( )

Definition at line 56 of file HttpConnection.cpp.

57 {
58  struct timeval timeout = { 2, 0 };
59  fd_set readset = m_fds;
60 
61  try
62  {
63  // Wait for input (1 second timeout)
64  int result = select( 1 + m_socket, &readset, 0, 0, &timeout );
65 
66  if( result > 0 ) // Something to read
67  {
68  // We can read without blocking
69  ssize_t size = socket_recv( m_socket, m_buffer, sizeof(m_buffer) );
70  if ( size <= 0 ) { throw SocketRecvFailed( size ); }
71  m_parser.addToStream( m_buffer, size );
72  }
73  else if( result == 0 ) // Timeout
74  {
75  disconnect( 408 );
76  return false;
77  }
78  else if( result < 0 ) // Error
79  {
80  throw SocketRecvFailed( result );
81  }
82 
83  processStream();
84  return true;
85  }
86  catch ( SocketRecvFailed& )
87  {
88  disconnect();
89  return false;
90  }
91 }

References FIX::HttpParser::addToStream(), disconnect(), m_buffer, m_fds, m_parser, m_socket, processStream(), and FIX::socket_recv().

◆ readMessage()

bool FIX::HttpConnection::readMessage ( std::string &  msg)
throw (SocketRecvFailed
)
private

Definition at line 93 of file HttpConnection.cpp.

95 {
96  try
97  {
98  return m_parser.readHttpMessage( msg );
99  }
100  catch ( MessageParseError& )
101  {
102  disconnect( 400 );
103  }
104  return true;
105 }

Referenced by processStream().

◆ send()

bool FIX::HttpConnection::send ( const std::string &  msg)
private

Definition at line 43 of file HttpConnection.cpp.

44 {
45  return socket_send( m_socket, msg.c_str(), msg.length() ) >= 0;
46 }

References m_socket, and FIX::socket_send().

Referenced by disconnect(), and processRequest().

◆ showRow() [1/3]

void FIX::HttpConnection::showRow ( std::stringstream &  s,
const std::string &  name,
bool  value,
const std::string &  url = "" 
)
private

Definition at line 675 of file HttpConnection.cpp.

676 {
677  { TR tr(s); tr.text();
678  { TD td(s); td.text(name); }
679  { TD td(s); td.text(value ? "yes" : "no"); }
680  { TD td(s); td.text();
681  CENTER center(s); center.text();
682  if( url.size() )
683  {
684  std::stringstream href;
685  href << url << "&" << name << "=" << !value;
686  A a(s); a.href(href.str()).text("toggle");
687  }
688  }
689  }
690 }

References HTML::A::href(), and HTML::TAG::text().

◆ showRow() [2/3]

void FIX::HttpConnection::showRow ( std::stringstream &  s,
const std::string &  name,
const std::string &  value,
const std::string &  url = "" 
)
private

Definition at line 693 of file HttpConnection.cpp.

694 {
695  { TR tr(s); tr.text();
696  { TD td(s); td.text(name); }
697  { TD td(s); td.text(value); }
698  { TD td(s); td.text();
699  CENTER center(s); center.text();
700  }
701  }
702 }

References HTML::TAG::text().

◆ showRow() [3/3]

void FIX::HttpConnection::showRow ( std::stringstream &  s,
const std::string &  name,
int  value,
const std::string &  url = "" 
)
private

Definition at line 705 of file HttpConnection.cpp.

706 {
707  { TR tr(s); tr.text();
708  { TD td(s); td.text(name); }
709  { TD td(s); td.text(value); }
710  { TD td(s); td.text();
711  CENTER center(s); center.text();
712  {
713  std::stringstream href;
714  href << url << "&" << name << "=" << value - 10;
715  A a(s); a.href(href.str()).text("<<");
716  }
717  s << NBSP;
718  {
719  std::stringstream href;
720  href << url << "&" << name << "=" << value - 1;
721  A a(s); a.href(href.str()).text("<");
722  }
723  s << NBSP << "|" << NBSP;
724  {
725  std::stringstream href;
726  href << url << "&" << name << "=" << value + 1;
727  A a(s); a.href(href.str()).text(">");
728  }
729  s << NBSP;
730  {
731  std::stringstream href;
732  href << url << "&" << name << "=" << value + 10;
733  A a(s); a.href(href.str()).text(">>");
734  }
735  }
736  }
737 }

References HTML::A::href(), HTML::NBSP, and HTML::TAG::text().

◆ showToggle()

void FIX::HttpConnection::showToggle ( std::stringstream &  s,
const std::string &  name,
bool  value,
const std::string &  url 
)
private

Member Data Documentation

◆ m_buffer

char FIX::HttpConnection::m_buffer[BUFSIZ]
private

Definition at line 88 of file HttpConnection.h.

Referenced by read().

◆ m_fds

fd_set FIX::HttpConnection::m_fds
private

Definition at line 91 of file HttpConnection.h.

Referenced by HttpConnection(), and read().

◆ m_parser

HttpParser FIX::HttpConnection::m_parser
private

Definition at line 90 of file HttpConnection.h.

Referenced by read().

◆ m_socket

int FIX::HttpConnection::m_socket
private

Definition at line 87 of file HttpConnection.h.

Referenced by disconnect(), HttpConnection(), read(), and send().


The documentation for this class was generated from the following files:
HTML::TR
Definition: HtmlBuilder.h:195
FIX::RESET_ON_LOGOUT
const char RESET_ON_LOGOUT[]
Definition: SessionSettings.h:143
FIX::RESET_ON_LOGON
const char RESET_ON_LOGON[]
Definition: SessionSettings.h:142
FIX::LOGOUT_TIMEOUT
const char LOGOUT_TIMEOUT[]
Definition: SessionSettings.h:96
FIX::LOGON_TIMEOUT
const char LOGON_TIMEOUT[]
Definition: SessionSettings.h:95
FIX::HttpConnection::processRefreshSessions
void processRefreshSessions(const HttpMessage &, std::stringstream &h, std::stringstream &b)
Definition: HttpConnection.cpp:281
FIX::Session::lookupSession
static Session * lookupSession(const SessionID &)
Definition: Session.cpp:1513
HTML::HR
Definition: HtmlBuilder.h:155
FIX::HttpParser::readHttpMessage
bool readHttpMessage(std::string &str)
Definition: HttpParser.cpp:49
FIX::HttpConnection::send
bool send(const std::string &)
Definition: HttpConnection.cpp:43
FIX::HttpMessage::createResponse
static std::string createResponse(int error=0, const std::string &text="")
Definition: HttpMessage.cpp:103
HTML::NBSP
const char * NBSP
Definition: HtmlBuilder.h:162
FIX::PERSIST_MESSAGES
const char PERSIST_MESSAGES[]
Definition: SessionSettings.h:149
HTML::HEAD
Definition: HtmlBuilder.h:148
FIX::HttpConnection::processResetSession
void processResetSession(const HttpMessage &, std::stringstream &h, std::stringstream &b)
Definition: HttpConnection.cpp:559
FIX::Session::reset
void reset()
Definition: Session.h:100
FIX::Session::refresh
void refresh()
Definition: Session.h:102
HTML::H2
Definition: HtmlBuilder.h:141
FIX::Session::getSessions
static std::set< SessionID > getSessions()
Definition: Session.cpp:1502
FIX::Session::numSessions
static size_t numSessions()
Definition: Session.cpp:1570
FIX::CHECK_LATENCY
const char CHECK_LATENCY[]
Definition: SessionSettings.h:76
FIX::socket_recv
ssize_t socket_recv(int s, char *buf, size_t length)
Definition: Utility.cpp:187
FIX::HttpConnection::processSession
void processSession(const HttpMessage &, std::stringstream &h, std::stringstream &b)
Definition: HttpConnection.cpp:422
FIX::TYPE::UtcTimeStamp
@ UtcTimeStamp
Definition: FieldTypes.h:940
FIX::SEND_REDUNDANT_RESENDREQUESTS
const char SEND_REDUNDANT_RESENDREQUESTS[]
Definition: SessionSettings.h:62
FIX::IntConvertor::convert
static std::string convert(signed_int value)
Definition: FieldConvertors.h:170
FIX::HttpConnection::m_parser
HttpParser m_parser
Definition: HttpConnection.h:90
HTML::H1
Definition: HtmlBuilder.h:134
FIX::HttpConnection::showRow
void showRow(std::stringstream &s, const std::string &name, bool value, const std::string &url="")
Definition: HttpConnection.cpp:675
FIX::MAX_LATENCY
const char MAX_LATENCY[]
Definition: SessionSettings.h:77
FIX::HttpConnection::processEnableSessions
void processEnableSessions(const HttpMessage &, std::stringstream &h, std::stringstream &b)
Definition: HttpConnection.cpp:328
FIX::MILLISECONDS_IN_TIMESTAMP
const char MILLISECONDS_IN_TIMESTAMP[]
Definition: SessionSettings.h:146
FIX::HttpConnection::processStream
void processStream()
Definition: HttpConnection.cpp:107
FIX::socket_send
ssize_t socket_send(int s, const char *msg, size_t length)
Definition: Utility.cpp:192
FIX::HttpConnection::processRefreshSession
void processRefreshSession(const HttpMessage &, std::stringstream &h, std::stringstream &b)
Definition: HttpConnection.cpp:617
HTML::CENTER
Definition: HtmlBuilder.h:120
FIX::HttpConnection::processDisableSessions
void processDisableSessions(const HttpMessage &, std::stringstream &h, std::stringstream &b)
Definition: HttpConnection.cpp:375
FIX::HttpConnection::processResetSessions
void processResetSessions(const HttpMessage &, std::stringstream &h, std::stringstream &b)
Definition: HttpConnection.cpp:234
FIX::HttpConnection::m_buffer
char m_buffer[BUFSIZ]
Definition: HttpConnection.h:88
HTML::EM
Definition: HtmlBuilder.h:127
HTML::TD
Definition: HtmlBuilder.h:178
HTML::BODY
Definition: HtmlBuilder.h:99
FIX::HttpConnection::m_socket
int m_socket
Definition: HttpConnection.h:87
FIX::CHECK_COMPID
const char CHECK_COMPID[]
Definition: SessionSettings.h:75
FIX::HttpConnection::readMessage
bool readMessage(std::string &msg)
Definition: HttpConnection.cpp:93
FIX::REFRESH_ON_LOGON
const char REFRESH_ON_LOGON[]
Definition: SessionSettings.h:145
FIX::socket_close
void socket_close(int s)
Definition: Utility.cpp:197
FIX::RESET_ON_DISCONNECT
const char RESET_ON_DISCONNECT[]
Definition: SessionSettings.h:144
FIX::Session::logon
void logon()
Definition: Session.h:89
HTML::CAPTION
Definition: HtmlBuilder.h:113
FIX::HttpConnection::processRoot
void processRoot(const HttpMessage &, std::stringstream &h, std::stringstream &b)
Definition: HttpConnection.cpp:182
FIX::HttpConnection::processRequest
void processRequest(const HttpMessage &)
Definition: HttpConnection.cpp:126
FIX::Session::logout
void logout(const std::string &reason="")
Definition: Session.h:91
FIX::HttpConnection::disconnect
void disconnect(int error=0)
Definition: HttpConnection.cpp:48
HTML::TITLE
Definition: HtmlBuilder.h:188
HTML::A
Definition: HtmlBuilder.h:89
FIX::HttpConnection::m_fds
fd_set m_fds
Definition: HttpConnection.h:91
FIX::HttpParser::addToStream
void addToStream(const char *str, size_t len)
Definition: HttpParser.h:79
HTML::TABLE
Definition: HtmlBuilder.h:164

Generated on Wed Apr 29 2020 19:41:30 for QuickFIX by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2001