quickfix_ruby 1.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/ext/quickfix/Acceptor.cpp +248 -0
  3. data/ext/quickfix/Acceptor.h +127 -0
  4. data/ext/quickfix/Allocator.h +9 -0
  5. data/ext/quickfix/Application.h +127 -0
  6. data/ext/quickfix/AtomicCount.h +109 -0
  7. data/ext/quickfix/DOMDocument.h +74 -0
  8. data/ext/quickfix/DataDictionary.cpp +618 -0
  9. data/ext/quickfix/DataDictionary.h +539 -0
  10. data/ext/quickfix/DataDictionaryProvider.cpp +71 -0
  11. data/ext/quickfix/DataDictionaryProvider.h +70 -0
  12. data/ext/quickfix/DatabaseConnectionID.h +105 -0
  13. data/ext/quickfix/DatabaseConnectionPool.h +91 -0
  14. data/ext/quickfix/Dictionary.cpp +162 -0
  15. data/ext/quickfix/Dictionary.h +94 -0
  16. data/ext/quickfix/Event.h +95 -0
  17. data/ext/quickfix/Exceptions.h +299 -0
  18. data/ext/quickfix/Field.h +672 -0
  19. data/ext/quickfix/FieldConvertors.h +863 -0
  20. data/ext/quickfix/FieldMap.cpp +238 -0
  21. data/ext/quickfix/FieldMap.h +244 -0
  22. data/ext/quickfix/FieldNumbers.h +46 -0
  23. data/ext/quickfix/FieldTypes.cpp +64 -0
  24. data/ext/quickfix/FieldTypes.h +698 -0
  25. data/ext/quickfix/Fields.h +31 -0
  26. data/ext/quickfix/FileLog.cpp +200 -0
  27. data/ext/quickfix/FileLog.h +112 -0
  28. data/ext/quickfix/FileStore.cpp +332 -0
  29. data/ext/quickfix/FileStore.h +129 -0
  30. data/ext/quickfix/FixFieldNumbers.h +1537 -0
  31. data/ext/quickfix/FixFields.h +1538 -0
  32. data/ext/quickfix/FixValues.h +3281 -0
  33. data/ext/quickfix/FlexLexer.h +188 -0
  34. data/ext/quickfix/Group.cpp +64 -0
  35. data/ext/quickfix/Group.h +73 -0
  36. data/ext/quickfix/HtmlBuilder.h +186 -0
  37. data/ext/quickfix/HttpConnection.cpp +739 -0
  38. data/ext/quickfix/HttpConnection.h +78 -0
  39. data/ext/quickfix/HttpMessage.cpp +149 -0
  40. data/ext/quickfix/HttpMessage.h +133 -0
  41. data/ext/quickfix/HttpParser.cpp +49 -0
  42. data/ext/quickfix/HttpParser.h +54 -0
  43. data/ext/quickfix/HttpServer.cpp +169 -0
  44. data/ext/quickfix/HttpServer.h +78 -0
  45. data/ext/quickfix/Initiator.cpp +289 -0
  46. data/ext/quickfix/Initiator.h +149 -0
  47. data/ext/quickfix/Log.cpp +77 -0
  48. data/ext/quickfix/Log.h +179 -0
  49. data/ext/quickfix/Message.cpp +580 -0
  50. data/ext/quickfix/Message.h +370 -0
  51. data/ext/quickfix/MessageCracker.h +188 -0
  52. data/ext/quickfix/MessageSorters.cpp +105 -0
  53. data/ext/quickfix/MessageSorters.h +156 -0
  54. data/ext/quickfix/MessageStore.cpp +146 -0
  55. data/ext/quickfix/MessageStore.h +174 -0
  56. data/ext/quickfix/Mutex.h +131 -0
  57. data/ext/quickfix/MySQLConnection.h +194 -0
  58. data/ext/quickfix/MySQLLog.cpp +275 -0
  59. data/ext/quickfix/MySQLLog.h +145 -0
  60. data/ext/quickfix/MySQLStore.cpp +331 -0
  61. data/ext/quickfix/MySQLStore.h +142 -0
  62. data/ext/quickfix/NullStore.cpp +54 -0
  63. data/ext/quickfix/NullStore.h +99 -0
  64. data/ext/quickfix/OdbcConnection.h +266 -0
  65. data/ext/quickfix/OdbcLog.cpp +252 -0
  66. data/ext/quickfix/OdbcLog.h +117 -0
  67. data/ext/quickfix/OdbcStore.cpp +338 -0
  68. data/ext/quickfix/OdbcStore.h +113 -0
  69. data/ext/quickfix/PUGIXML_DOMDocument.cpp +112 -0
  70. data/ext/quickfix/PUGIXML_DOMDocument.h +81 -0
  71. data/ext/quickfix/Parser.cpp +103 -0
  72. data/ext/quickfix/Parser.h +57 -0
  73. data/ext/quickfix/PostgreSQLConnection.h +176 -0
  74. data/ext/quickfix/PostgreSQLLog.cpp +276 -0
  75. data/ext/quickfix/PostgreSQLLog.h +144 -0
  76. data/ext/quickfix/PostgreSQLStore.cpp +334 -0
  77. data/ext/quickfix/PostgreSQLStore.h +141 -0
  78. data/ext/quickfix/Queue.h +75 -0
  79. data/ext/quickfix/QuickfixRuby.cpp +252066 -0
  80. data/ext/quickfix/QuickfixRuby.h +34 -0
  81. data/ext/quickfix/Responder.h +43 -0
  82. data/ext/quickfix/Session.cpp +1487 -0
  83. data/ext/quickfix/Session.h +335 -0
  84. data/ext/quickfix/SessionFactory.cpp +274 -0
  85. data/ext/quickfix/SessionFactory.h +86 -0
  86. data/ext/quickfix/SessionID.h +170 -0
  87. data/ext/quickfix/SessionSettings.cpp +189 -0
  88. data/ext/quickfix/SessionSettings.h +171 -0
  89. data/ext/quickfix/SessionState.h +231 -0
  90. data/ext/quickfix/Settings.cpp +100 -0
  91. data/ext/quickfix/Settings.h +53 -0
  92. data/ext/quickfix/SharedArray.h +150 -0
  93. data/ext/quickfix/SocketAcceptor.cpp +222 -0
  94. data/ext/quickfix/SocketAcceptor.h +75 -0
  95. data/ext/quickfix/SocketConnection.cpp +238 -0
  96. data/ext/quickfix/SocketConnection.h +103 -0
  97. data/ext/quickfix/SocketConnector.cpp +116 -0
  98. data/ext/quickfix/SocketConnector.h +67 -0
  99. data/ext/quickfix/SocketInitiator.cpp +260 -0
  100. data/ext/quickfix/SocketInitiator.h +81 -0
  101. data/ext/quickfix/SocketMonitor.cpp +335 -0
  102. data/ext/quickfix/SocketMonitor.h +111 -0
  103. data/ext/quickfix/SocketServer.cpp +177 -0
  104. data/ext/quickfix/SocketServer.h +100 -0
  105. data/ext/quickfix/ThreadedSocketAcceptor.cpp +258 -0
  106. data/ext/quickfix/ThreadedSocketAcceptor.h +98 -0
  107. data/ext/quickfix/ThreadedSocketConnection.cpp +209 -0
  108. data/ext/quickfix/ThreadedSocketConnection.h +82 -0
  109. data/ext/quickfix/ThreadedSocketInitiator.cpp +268 -0
  110. data/ext/quickfix/ThreadedSocketInitiator.h +84 -0
  111. data/ext/quickfix/TimeRange.cpp +173 -0
  112. data/ext/quickfix/TimeRange.h +258 -0
  113. data/ext/quickfix/Utility.cpp +537 -0
  114. data/ext/quickfix/Utility.h +219 -0
  115. data/ext/quickfix/Values.h +62 -0
  116. data/ext/quickfix/config.h +0 -0
  117. data/ext/quickfix/config_windows.h +0 -0
  118. data/ext/quickfix/extconf.rb +12 -0
  119. data/ext/quickfix/index.h +37 -0
  120. data/ext/quickfix/pugiconfig.hpp +72 -0
  121. data/ext/quickfix/pugixml.cpp +10765 -0
  122. data/ext/quickfix/pugixml.hpp +1341 -0
  123. data/ext/quickfix/strptime.h +7 -0
  124. data/lib/quickfix40.rb +274 -0
  125. data/lib/quickfix41.rb +351 -0
  126. data/lib/quickfix42.rb +1184 -0
  127. data/lib/quickfix43.rb +3504 -0
  128. data/lib/quickfix44.rb +10721 -0
  129. data/lib/quickfix50.rb +13426 -0
  130. data/lib/quickfix50sp1.rb +15629 -0
  131. data/lib/quickfix50sp2.rb +17068 -0
  132. data/lib/quickfix_fields.rb +19853 -0
  133. data/lib/quickfix_ruby.rb +82 -0
  134. data/lib/quickfixt11.rb +70 -0
  135. data/spec/FIX40.xml +862 -0
  136. data/spec/FIX41.xml +1285 -0
  137. data/spec/FIX42.xml +2746 -0
  138. data/spec/FIX43.xml +4229 -0
  139. data/spec/FIX44.xml +6596 -0
  140. data/spec/FIX50.xml +8137 -0
  141. data/spec/FIX50SP1.xml +9496 -0
  142. data/spec/FIX50SP2.xml +10011 -0
  143. data/spec/FIXT11.xml +313 -0
  144. data/test/test_DataDictionaryTestCase.rb +268 -0
  145. data/test/test_DictionaryTestCase.rb +112 -0
  146. data/test/test_FieldBaseTestCase.rb +24 -0
  147. data/test/test_MessageTestCase.rb +368 -0
  148. data/test/test_SessionSettingsTestCase.rb +41 -0
  149. metadata +193 -0
@@ -0,0 +1,739 @@
1
+ /****************************************************************************
2
+ ** Copyright (c) 2001-2014
3
+ **
4
+ ** This file is part of the QuickFIX FIX Engine
5
+ **
6
+ ** This file may be distributed under the terms of the quickfixengine.org
7
+ ** license as defined by quickfixengine.org and appearing in the file
8
+ ** LICENSE included in the packaging of this file.
9
+ **
10
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12
+ **
13
+ ** See http://www.quickfixengine.org/LICENSE for licensing information.
14
+ **
15
+ ** Contact ask@quickfixengine.org if any conditions of this licensing are
16
+ ** not clear to you.
17
+ **
18
+ ****************************************************************************/
19
+
20
+ #ifdef _MSC_VER
21
+ #include "stdafx.h"
22
+ #else
23
+ #include "config.h"
24
+ #endif
25
+
26
+ #include "HttpConnection.h"
27
+ #include "HttpMessage.h"
28
+ #include "HtmlBuilder.h"
29
+ #include "Session.h"
30
+ #include "Utility.h"
31
+
32
+ using namespace HTML;
33
+
34
+ namespace FIX
35
+ {
36
+ HttpConnection::HttpConnection( int s )
37
+ : m_socket( s )
38
+ {
39
+ FD_ZERO( &m_fds );
40
+ FD_SET( m_socket, &m_fds );
41
+ }
42
+
43
+ bool HttpConnection::send( const std::string& msg )
44
+ {
45
+ return socket_send( m_socket, msg.c_str(), msg.length() ) >= 0;
46
+ }
47
+
48
+ void HttpConnection::disconnect( int error )
49
+ {
50
+ if( error > 0 )
51
+ send( HttpMessage::createResponse(error) );
52
+
53
+ socket_close( m_socket );
54
+ }
55
+
56
+ bool HttpConnection::read()
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 = recv( m_socket, m_buffer, sizeof(m_buffer), 0 );
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
+ }
92
+
93
+ bool HttpConnection::readMessage( std::string& msg )
94
+ throw( SocketRecvFailed )
95
+ {
96
+ try
97
+ {
98
+ return m_parser.readHttpMessage( msg );
99
+ }
100
+ catch ( MessageParseError& )
101
+ {
102
+ disconnect( 400 );
103
+ }
104
+ return true;
105
+ }
106
+
107
+ void HttpConnection::processStream()
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
+ }
125
+
126
+ void HttpConnection::processRequest( const HttpMessage& request )
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
+ }
180
+
181
+ void HttpConnection::processRoot
182
+ ( const HttpMessage& request, std::stringstream& h, std::stringstream& b )
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
+ }
232
+
233
+ void HttpConnection::processResetSessions
234
+ ( const HttpMessage& request, std::stringstream& h, std::stringstream& b )
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
+ }
279
+
280
+ void HttpConnection::processRefreshSessions
281
+ ( const HttpMessage& request, std::stringstream& h, std::stringstream& b )
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
+ }
326
+
327
+ void HttpConnection::processEnableSessions
328
+ ( const HttpMessage& request, std::stringstream& h, std::stringstream& b )
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
+ }
373
+
374
+ void HttpConnection::processDisableSessions
375
+ ( const HttpMessage& request, std::stringstream& h, std::stringstream& b )
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
+ }
420
+
421
+ void HttpConnection::processSession
422
+ ( const HttpMessage& request, std::stringstream& h, std::stringstream& b )
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
+ }
557
+
558
+ void HttpConnection::processResetSession
559
+ ( const HttpMessage& request, std::stringstream& h, std::stringstream& b )
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
+ }
615
+
616
+ void HttpConnection::processRefreshSession
617
+ ( const HttpMessage& request, std::stringstream& h, std::stringstream& b )
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
+ }
673
+
674
+ void HttpConnection::showRow
675
+ ( std::stringstream& s, const std::string& name, bool value, const std::string& url )
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
+ }
691
+
692
+ void HttpConnection::showRow
693
+ ( std::stringstream& s, const std::string& name, const std::string& value, const std::string& url )
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
+ }
703
+
704
+ void HttpConnection::showRow
705
+ ( std::stringstream& s, const std::string& name, int value, const std::string& url )
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
+ }
738
+
739
+ } // namespace FIX