quickfix_ruby_ud 2.0.7-aarch64-linux

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 (205) hide show
  1. checksums.yaml +7 -0
  2. data/ext/quickfix/Acceptor.cpp +257 -0
  3. data/ext/quickfix/Acceptor.h +127 -0
  4. data/ext/quickfix/Allocator.h +9 -0
  5. data/ext/quickfix/Application.h +137 -0
  6. data/ext/quickfix/DOMDocument.h +70 -0
  7. data/ext/quickfix/DataDictionary.cpp +679 -0
  8. data/ext/quickfix/DataDictionary.h +607 -0
  9. data/ext/quickfix/DataDictionaryProvider.cpp +66 -0
  10. data/ext/quickfix/DataDictionaryProvider.h +67 -0
  11. data/ext/quickfix/DatabaseConnectionID.h +98 -0
  12. data/ext/quickfix/DatabaseConnectionPool.h +84 -0
  13. data/ext/quickfix/Dictionary.cpp +157 -0
  14. data/ext/quickfix/Dictionary.h +89 -0
  15. data/ext/quickfix/Event.h +89 -0
  16. data/ext/quickfix/Except.h +39 -0
  17. data/ext/quickfix/Exceptions.h +257 -0
  18. data/ext/quickfix/Field.h +654 -0
  19. data/ext/quickfix/FieldConvertors.cpp +86 -0
  20. data/ext/quickfix/FieldConvertors.h +800 -0
  21. data/ext/quickfix/FieldMap.cpp +254 -0
  22. data/ext/quickfix/FieldMap.h +327 -0
  23. data/ext/quickfix/FieldNumbers.h +44 -0
  24. data/ext/quickfix/FieldTypes.cpp +62 -0
  25. data/ext/quickfix/FieldTypes.h +817 -0
  26. data/ext/quickfix/Fields.h +30 -0
  27. data/ext/quickfix/FileLog.cpp +176 -0
  28. data/ext/quickfix/FileLog.h +110 -0
  29. data/ext/quickfix/FileStore.cpp +369 -0
  30. data/ext/quickfix/FileStore.h +131 -0
  31. data/ext/quickfix/FixCommonFields.h +13 -0
  32. data/ext/quickfix/FixFieldNumbers.h +6132 -0
  33. data/ext/quickfix/FixFields.h +6133 -0
  34. data/ext/quickfix/FixValues.h +5790 -0
  35. data/ext/quickfix/Group.cpp +44 -0
  36. data/ext/quickfix/Group.h +78 -0
  37. data/ext/quickfix/HostDetailsProvider.cpp +79 -0
  38. data/ext/quickfix/HostDetailsProvider.h +44 -0
  39. data/ext/quickfix/HtmlBuilder.h +178 -0
  40. data/ext/quickfix/HttpConnection.cpp +914 -0
  41. data/ext/quickfix/HttpConnection.h +74 -0
  42. data/ext/quickfix/HttpMessage.cpp +229 -0
  43. data/ext/quickfix/HttpMessage.h +112 -0
  44. data/ext/quickfix/HttpParser.cpp +49 -0
  45. data/ext/quickfix/HttpParser.h +49 -0
  46. data/ext/quickfix/HttpServer.cpp +152 -0
  47. data/ext/quickfix/HttpServer.h +76 -0
  48. data/ext/quickfix/Initiator.cpp +310 -0
  49. data/ext/quickfix/Initiator.h +151 -0
  50. data/ext/quickfix/Log.cpp +71 -0
  51. data/ext/quickfix/Log.h +254 -0
  52. data/ext/quickfix/Message.cpp +617 -0
  53. data/ext/quickfix/Message.h +419 -0
  54. data/ext/quickfix/MessageCracker.h +171 -0
  55. data/ext/quickfix/MessageSorters.cpp +101 -0
  56. data/ext/quickfix/MessageSorters.h +185 -0
  57. data/ext/quickfix/MessageStore.cpp +182 -0
  58. data/ext/quickfix/MessageStore.h +164 -0
  59. data/ext/quickfix/Mutex.h +120 -0
  60. data/ext/quickfix/MySQLConnection.h +187 -0
  61. data/ext/quickfix/MySQLLog.cpp +262 -0
  62. data/ext/quickfix/MySQLLog.h +158 -0
  63. data/ext/quickfix/MySQLStore.cpp +323 -0
  64. data/ext/quickfix/MySQLStore.h +161 -0
  65. data/ext/quickfix/MySQLStubs.h +203 -0
  66. data/ext/quickfix/NullStore.cpp +40 -0
  67. data/ext/quickfix/NullStore.h +89 -0
  68. data/ext/quickfix/OdbcConnection.h +241 -0
  69. data/ext/quickfix/OdbcLog.cpp +230 -0
  70. data/ext/quickfix/OdbcLog.h +109 -0
  71. data/ext/quickfix/OdbcStore.cpp +313 -0
  72. data/ext/quickfix/OdbcStore.h +124 -0
  73. data/ext/quickfix/PUGIXML_DOMDocument.cpp +112 -0
  74. data/ext/quickfix/PUGIXML_DOMDocument.h +81 -0
  75. data/ext/quickfix/Parser.cpp +111 -0
  76. data/ext/quickfix/Parser.h +50 -0
  77. data/ext/quickfix/PostgreSQLConnection.h +163 -0
  78. data/ext/quickfix/PostgreSQLLog.cpp +263 -0
  79. data/ext/quickfix/PostgreSQLLog.h +157 -0
  80. data/ext/quickfix/PostgreSQLStore.cpp +327 -0
  81. data/ext/quickfix/PostgreSQLStore.h +160 -0
  82. data/ext/quickfix/PostgreSQLStubs.h +203 -0
  83. data/ext/quickfix/Queue.h +66 -0
  84. data/ext/quickfix/QuickfixRuby.cpp +131900 -0
  85. data/ext/quickfix/QuickfixRuby.h +56 -0
  86. data/ext/quickfix/Responder.h +41 -0
  87. data/ext/quickfix/SSLSocketAcceptor.cpp +409 -0
  88. data/ext/quickfix/SSLSocketAcceptor.h +186 -0
  89. data/ext/quickfix/SSLSocketConnection.cpp +434 -0
  90. data/ext/quickfix/SSLSocketConnection.h +221 -0
  91. data/ext/quickfix/SSLSocketInitiator.cpp +558 -0
  92. data/ext/quickfix/SSLSocketInitiator.h +203 -0
  93. data/ext/quickfix/SSLStubs.h +129 -0
  94. data/ext/quickfix/Session.cpp +1437 -0
  95. data/ext/quickfix/Session.h +343 -0
  96. data/ext/quickfix/SessionFactory.cpp +314 -0
  97. data/ext/quickfix/SessionFactory.h +84 -0
  98. data/ext/quickfix/SessionID.h +136 -0
  99. data/ext/quickfix/SessionSettings.cpp +165 -0
  100. data/ext/quickfix/SessionSettings.h +283 -0
  101. data/ext/quickfix/SessionState.h +260 -0
  102. data/ext/quickfix/Settings.cpp +160 -0
  103. data/ext/quickfix/Settings.h +56 -0
  104. data/ext/quickfix/SharedArray.h +274 -0
  105. data/ext/quickfix/SocketAcceptor.cpp +216 -0
  106. data/ext/quickfix/SocketAcceptor.h +77 -0
  107. data/ext/quickfix/SocketConnection.cpp +256 -0
  108. data/ext/quickfix/SocketConnection.h +102 -0
  109. data/ext/quickfix/SocketConnector.cpp +112 -0
  110. data/ext/quickfix/SocketConnector.h +76 -0
  111. data/ext/quickfix/SocketInitiator.cpp +241 -0
  112. data/ext/quickfix/SocketInitiator.h +76 -0
  113. data/ext/quickfix/SocketMonitor.h +26 -0
  114. data/ext/quickfix/SocketMonitor_UNIX.cpp +238 -0
  115. data/ext/quickfix/SocketMonitor_UNIX.h +101 -0
  116. data/ext/quickfix/SocketMonitor_WIN32.cpp +248 -0
  117. data/ext/quickfix/SocketMonitor_WIN32.h +99 -0
  118. data/ext/quickfix/SocketServer.cpp +163 -0
  119. data/ext/quickfix/SocketServer.h +100 -0
  120. data/ext/quickfix/ThreadedSSLSocketAcceptor.cpp +436 -0
  121. data/ext/quickfix/ThreadedSSLSocketAcceptor.h +209 -0
  122. data/ext/quickfix/ThreadedSSLSocketConnection.cpp +364 -0
  123. data/ext/quickfix/ThreadedSSLSocketConnection.h +191 -0
  124. data/ext/quickfix/ThreadedSSLSocketInitiator.cpp +434 -0
  125. data/ext/quickfix/ThreadedSSLSocketInitiator.h +193 -0
  126. data/ext/quickfix/ThreadedSocketAcceptor.cpp +242 -0
  127. data/ext/quickfix/ThreadedSocketAcceptor.h +95 -0
  128. data/ext/quickfix/ThreadedSocketConnection.cpp +227 -0
  129. data/ext/quickfix/ThreadedSocketConnection.h +89 -0
  130. data/ext/quickfix/ThreadedSocketInitiator.cpp +238 -0
  131. data/ext/quickfix/ThreadedSocketInitiator.h +78 -0
  132. data/ext/quickfix/TimeRange.cpp +227 -0
  133. data/ext/quickfix/TimeRange.h +215 -0
  134. data/ext/quickfix/Utility.cpp +639 -0
  135. data/ext/quickfix/Utility.h +255 -0
  136. data/ext/quickfix/UtilitySSL.cpp +1612 -0
  137. data/ext/quickfix/UtilitySSL.h +274 -0
  138. data/ext/quickfix/Values.h +63 -0
  139. data/ext/quickfix/config-all.h +10 -0
  140. data/ext/quickfix/config.h +10 -0
  141. data/ext/quickfix/config_unix.h +178 -0
  142. data/ext/quickfix/config_windows.h +0 -0
  143. data/ext/quickfix/dirent_windows.h +838 -0
  144. data/ext/quickfix/double-conversion/bignum-dtoa.cc +641 -0
  145. data/ext/quickfix/double-conversion/bignum-dtoa.h +84 -0
  146. data/ext/quickfix/double-conversion/bignum.cc +766 -0
  147. data/ext/quickfix/double-conversion/bignum.h +144 -0
  148. data/ext/quickfix/double-conversion/cached-powers.cc +176 -0
  149. data/ext/quickfix/double-conversion/cached-powers.h +64 -0
  150. data/ext/quickfix/double-conversion/diy-fp.cc +57 -0
  151. data/ext/quickfix/double-conversion/diy-fp.h +118 -0
  152. data/ext/quickfix/double-conversion/double-conversion.cc +994 -0
  153. data/ext/quickfix/double-conversion/double-conversion.h +543 -0
  154. data/ext/quickfix/double-conversion/fast-dtoa.cc +665 -0
  155. data/ext/quickfix/double-conversion/fast-dtoa.h +88 -0
  156. data/ext/quickfix/double-conversion/fixed-dtoa.cc +404 -0
  157. data/ext/quickfix/double-conversion/fixed-dtoa.h +56 -0
  158. data/ext/quickfix/double-conversion/ieee.h +402 -0
  159. data/ext/quickfix/double-conversion/strtod.cc +557 -0
  160. data/ext/quickfix/double-conversion/strtod.h +45 -0
  161. data/ext/quickfix/double-conversion/utils.h +374 -0
  162. data/ext/quickfix/extconf.rb +76 -0
  163. data/ext/quickfix/index.h +37 -0
  164. data/ext/quickfix/pugiconfig.hpp +77 -0
  165. data/ext/quickfix/pugixml.cpp +13237 -0
  166. data/ext/quickfix/pugixml.hpp +1516 -0
  167. data/ext/quickfix/scope_guard.hpp +215 -0
  168. data/ext/quickfix/stdint_msvc.h +254 -0
  169. data/ext/quickfix/strptime.h +7 -0
  170. data/lib/2.4/quickfix.so +0 -0
  171. data/lib/2.5/quickfix.so +0 -0
  172. data/lib/2.6/quickfix.so +0 -0
  173. data/lib/2.7/quickfix.so +0 -0
  174. data/lib/3.0/quickfix.so +0 -0
  175. data/lib/3.1/quickfix.so +0 -0
  176. data/lib/3.2/quickfix.so +0 -0
  177. data/lib/3.3/quickfix.so +0 -0
  178. data/lib/3.4/quickfix.so +0 -0
  179. data/lib/quickfix40.rb +274 -0
  180. data/lib/quickfix41.rb +351 -0
  181. data/lib/quickfix42.rb +1184 -0
  182. data/lib/quickfix43.rb +3504 -0
  183. data/lib/quickfix44.rb +14040 -0
  184. data/lib/quickfix50.rb +20051 -0
  185. data/lib/quickfix50sp1.rb +23596 -0
  186. data/lib/quickfix50sp2.rb +412444 -0
  187. data/lib/quickfix_fields.rb +79393 -0
  188. data/lib/quickfix_ruby.rb +82 -0
  189. data/lib/quickfixt11.rb +65 -0
  190. data/spec/FIX40.xml +862 -0
  191. data/spec/FIX41.xml +1282 -0
  192. data/spec/FIX42.xml +2743 -0
  193. data/spec/FIX43.xml +4230 -0
  194. data/spec/FIX44.xml +6600 -0
  195. data/spec/FIX50.xml +8142 -0
  196. data/spec/FIX50SP1.xml +9506 -0
  197. data/spec/FIX50SP2.xml +26069 -0
  198. data/spec/FIXT11.xml +252 -0
  199. data/test/DataDictionaryTestCase.rb +268 -0
  200. data/test/DictionaryTestCase.rb +112 -0
  201. data/test/FieldBaseTestCase.rb +24 -0
  202. data/test/MessageStoreTestCase.rb +19 -0
  203. data/test/MessageTestCase.rb +368 -0
  204. data/test/SessionSettingsTestCase.rb +41 -0
  205. metadata +247 -0
@@ -0,0 +1,558 @@
1
+ /* ====================================================================
2
+ * Copyright (c) 1998-2006 Ralf S. Engelschall. All rights reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions
6
+ * are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following
13
+ * disclaimer in the documentation and/or other materials
14
+ * provided with the distribution.
15
+ *
16
+ * 3. All advertising materials mentioning features or use of this
17
+ * software must display the following acknowledgment:
18
+ * "This product includes software developed by
19
+ * Ralf S. Engelschall <rse@engelschall.com> for use in the
20
+ * mod_ssl project (http://www.modssl.org/)."
21
+ *
22
+ * 4. The names "mod_ssl" must not be used to endorse or promote
23
+ * products derived from this software without prior written
24
+ * permission. For written permission, please contact
25
+ * rse@engelschall.com.
26
+ *
27
+ * 5. Products derived from this software may not be called "mod_ssl"
28
+ * nor may "mod_ssl" appear in their names without prior
29
+ * written permission of Ralf S. Engelschall.
30
+ *
31
+ * 6. Redistributions of any form whatsoever must retain the following
32
+ * acknowledgment:
33
+ * "This product includes software developed by
34
+ * Ralf S. Engelschall <rse@engelschall.com> for use in the
35
+ * mod_ssl project (http://www.modssl.org/)."
36
+ *
37
+ * THIS SOFTWARE IS PROVIDED BY RALF S. ENGELSCHALL ``AS IS'' AND ANY
38
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RALF S. ENGELSCHALL OR
41
+ * HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
46
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
49
+ * ====================================================================
50
+ */
51
+
52
+ /* ====================================================================
53
+ * Copyright (c) 1995-1999 Ben Laurie. All rights reserved.
54
+ *
55
+ * Redistribution and use in source and binary forms, with or without
56
+ * modification, are permitted provided that the following conditions
57
+ * are met:
58
+ *
59
+ * 1. Redistributions of source code must retain the above copyright
60
+ * notice, this list of conditions and the following disclaimer.
61
+ *
62
+ * 2. Redistributions in binary form must reproduce the above copyright
63
+ * notice, this list of conditions and the following disclaimer in
64
+ * the documentation and/or other materials provided with the
65
+ * distribution.
66
+ *
67
+ * 3. All advertising materials mentioning features or use of this
68
+ * software must display the following acknowledgment:
69
+ * "This product includes software developed by Ben Laurie
70
+ * for use in the Apache-SSL HTTP server project."
71
+ *
72
+ * 4. The name "Apache-SSL Server" must not be used to
73
+ * endorse or promote products derived from this software without
74
+ * prior written permission.
75
+ *
76
+ * 5. Redistributions of any form whatsoever must retain the following
77
+ * acknowledgment:
78
+ * "This product includes software developed by Ben Laurie
79
+ * for use in the Apache-SSL HTTP server project."
80
+ *
81
+ * THIS SOFTWARE IS PROVIDED BY BEN LAURIE ``AS IS'' AND ANY
82
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
83
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
84
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BEN LAURIE OR
85
+ * HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
86
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
87
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
88
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
89
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
90
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
91
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
92
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
93
+ * ====================================================================
94
+ */
95
+
96
+ /****************************************************************************
97
+ ** Copyright (c) 2001-2014
98
+ **
99
+ ** This file is part of the QuickFIX FIX Engine
100
+ **
101
+ ** This file may be distributed under the terms of the quickfixengine.org
102
+ ** license as defined by quickfixengine.org and appearing in the file
103
+ ** LICENSE included in the packaging of this file.
104
+ **
105
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
106
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
107
+ **
108
+ ** See http://www.quickfixengine.org/LICENSE for licensing information.
109
+ **
110
+ ** Contact ask@quickfixengine.org if any conditions of this licensing are
111
+ ** not clear to you.
112
+ **
113
+ ****************************************************************************/
114
+
115
+ #ifdef _MSC_VER
116
+ #include "stdafx.h"
117
+ #else
118
+ #include "config.h"
119
+ #endif
120
+
121
+ #if (HAVE_SSL > 0)
122
+
123
+ #include "SSLSocketInitiator.h"
124
+ #include "Session.h"
125
+ #include "Settings.h"
126
+
127
+ namespace FIX {
128
+
129
+ int SSLSocketInitiator::passwordHandleCB(char *buf, int bufsize, int verify, void *instance) {
130
+ return reinterpret_cast<SSLSocketInitiator *>(instance)->passwordHandleCallback(buf, bufsize, verify);
131
+ }
132
+
133
+ SSLSocketInitiator::SSLSocketInitiator(
134
+ Application &application,
135
+ MessageStoreFactory &factory,
136
+ const SessionSettings &settings) EXCEPT(ConfigError)
137
+ : Initiator(application, factory, settings),
138
+ m_connector(1),
139
+ m_lastConnect(0),
140
+ m_reconnectInterval(30),
141
+ m_noDelay(false),
142
+ m_sendBufSize(0),
143
+ m_rcvBufSize(0),
144
+ m_sslInit(false),
145
+ m_ctx(0),
146
+ m_cert(0),
147
+ m_key(0) {}
148
+
149
+ SSLSocketInitiator::SSLSocketInitiator(
150
+ Application &application,
151
+ MessageStoreFactory &factory,
152
+ const SessionSettings &settings,
153
+ LogFactory &logFactory) EXCEPT(ConfigError)
154
+ : Initiator(application, factory, settings, logFactory),
155
+ m_connector(1),
156
+ m_lastConnect(0),
157
+ m_reconnectInterval(30),
158
+ m_noDelay(false),
159
+ m_sendBufSize(0),
160
+ m_rcvBufSize(0),
161
+ m_sslInit(false),
162
+ m_ctx(0),
163
+ m_cert(0),
164
+ m_key(0) {}
165
+
166
+ SSLSocketInitiator::~SSLSocketInitiator() {
167
+ for (const SocketConnections::value_type &connection : m_connections) {
168
+ delete connection.second;
169
+ }
170
+
171
+ for (const SocketConnections::value_type &connection : m_pendingConnections) {
172
+ delete connection.second;
173
+ }
174
+
175
+ for (const SocketConnections::value_type &connection : m_pendingSSLHandshakes) {
176
+ delete connection.second;
177
+ }
178
+
179
+ if (m_sslInit) {
180
+ SSL_CTX_free(m_ctx);
181
+ m_ctx = 0;
182
+ ssl_term();
183
+ }
184
+ }
185
+
186
+ void SSLSocketInitiator::onConfigure(const SessionSettings &s) EXCEPT(ConfigError) {
187
+ const Dictionary &dict = s.get();
188
+
189
+ if (dict.has(RECONNECT_INTERVAL)) // ReconnectInterval in [DEFAULT]
190
+ {
191
+ m_reconnectInterval = dict.getInt(RECONNECT_INTERVAL);
192
+ }
193
+ if (dict.has(SOCKET_NODELAY)) {
194
+ m_noDelay = dict.getBool(SOCKET_NODELAY);
195
+ }
196
+ if (dict.has(SOCKET_SEND_BUFFER_SIZE)) {
197
+ m_sendBufSize = dict.getInt(SOCKET_SEND_BUFFER_SIZE);
198
+ }
199
+ if (dict.has(SOCKET_RECEIVE_BUFFER_SIZE)) {
200
+ m_rcvBufSize = dict.getInt(SOCKET_RECEIVE_BUFFER_SIZE);
201
+ }
202
+ }
203
+
204
+ void SSLSocketInitiator::onInitialize(const SessionSettings &s) EXCEPT(RuntimeError) {
205
+ if (m_sslInit) {
206
+ return;
207
+ }
208
+
209
+ ssl_init();
210
+
211
+ std::string errStr;
212
+
213
+ /* set up the application context */
214
+ if ((m_ctx = createSSLContext(false, s, errStr)) == 0) {
215
+ throw RuntimeError(errStr);
216
+ }
217
+
218
+ if (m_cert && m_key) {
219
+ if (SSL_CTX_use_certificate(m_ctx, m_cert) < 1) {
220
+ ssl_term();
221
+ throw RuntimeError("Failed to set certificate");
222
+ }
223
+
224
+ if (SSL_CTX_use_RSAPrivateKey(m_ctx, m_key) <= 0) {
225
+ ssl_term();
226
+ throw RuntimeError("Failed to set key");
227
+ }
228
+ } else if (!loadSSLCert(m_ctx, false, s, getLog(), SSLSocketInitiator::passwordHandleCB, this, errStr)) {
229
+ ssl_term();
230
+ throw RuntimeError(errStr);
231
+ }
232
+
233
+ int verifyLevel;
234
+ if (!loadCAInfo(m_ctx, false, s, getLog(), errStr, verifyLevel)) {
235
+ ssl_term();
236
+ throw RuntimeError(errStr);
237
+ }
238
+
239
+ m_sslInit = true;
240
+ }
241
+
242
+ void SSLSocketInitiator::onStart() {
243
+ connect();
244
+
245
+ while (!isStopped()) {
246
+ m_connector.block(*this, false, 1.0);
247
+ onTimeout(m_connector);
248
+ }
249
+
250
+ time_t start = 0;
251
+ time_t now = 0;
252
+
253
+ ::time(&start);
254
+ while (isLoggedOn()) {
255
+ m_connector.block(*this);
256
+ if (::time(&now) - 5 >= start) {
257
+ break;
258
+ }
259
+ }
260
+ }
261
+
262
+ bool SSLSocketInitiator::onPoll() {
263
+ time_t start = 0;
264
+ time_t now = 0;
265
+
266
+ if (isStopped()) {
267
+ if (start == 0) {
268
+ ::time(&start);
269
+ }
270
+ if (!isLoggedOn()) {
271
+ return false;
272
+ }
273
+ if (::time(&now) - 5 >= start) {
274
+ return false;
275
+ }
276
+ }
277
+
278
+ m_connector.block(*this, true);
279
+ return true;
280
+ }
281
+
282
+ void SSLSocketInitiator::onStop() {}
283
+
284
+ void SSLSocketInitiator::doConnect(const SessionID &sessionID, const Dictionary &dictionary) {
285
+ try {
286
+
287
+ Session *session = Session::lookupSession(sessionID);
288
+ if (!session->isSessionTime(UtcTimeStamp::now())) {
289
+ return;
290
+ }
291
+
292
+ Log *log = session->getLog();
293
+
294
+ HostDetails host = m_hostDetailsProvider.getHost(sessionID, dictionary);
295
+ if (dictionary.has(RECONNECT_INTERVAL)) // ReconnectInterval in [SESSION]
296
+ {
297
+ m_reconnectInterval = dictionary.getInt(RECONNECT_INTERVAL);
298
+ }
299
+
300
+ log->onEvent(
301
+ "Connecting to " + host.address + " on port " + IntConvertor::convert((unsigned short)host.port) + " (Source "
302
+ + host.sourceAddress + ":" + IntConvertor::convert((unsigned short)host.sourcePort)
303
+ + ") ReconnectInterval=" + IntConvertor::convert((int)m_reconnectInterval));
304
+ socket_handle result = m_connector.connect(
305
+ host.address,
306
+ host.port,
307
+ m_noDelay,
308
+ m_sendBufSize,
309
+ m_rcvBufSize,
310
+ host.sourceAddress,
311
+ host.sourcePort);
312
+
313
+ log->onEvent("Socket created with handle:" + std::to_string(result));
314
+
315
+ SSL *ssl = SSL_new(m_ctx);
316
+ if (ssl == 0) {
317
+ log->onEvent("Failed to create ssl object");
318
+ return;
319
+ }
320
+ SSL_clear(ssl);
321
+ BIO *sbio = BIO_new_socket(result, BIO_NOCLOSE); // unfortunately OpenSSL assumes socket is int
322
+
323
+ if (sbio == 0) {
324
+ log->onEvent("BIO_new_socket failed");
325
+ return;
326
+ }
327
+ SSL_set_bio(ssl, sbio, sbio);
328
+
329
+ setPending(sessionID);
330
+ m_pendingConnections[result] = new SSLSocketConnection(*this, sessionID, result, ssl, &m_connector.getMonitor());
331
+ } catch (std::exception &ex) {
332
+ getLog()->onEvent(ex.what());
333
+ }
334
+ }
335
+
336
+ SSLHandshakeStatus SSLSocketInitiator::handshakeSSL(SSLSocketConnection *connection) {
337
+ SSL *ssl = connection->sslObject();
338
+ ERR_clear_error();
339
+ // Do the SSL handshake.
340
+ int rc = SSL_connect(ssl);
341
+ if (rc <= 0) {
342
+ int err = SSL_get_error(ssl, rc);
343
+ if ((err == SSL_ERROR_WANT_READ) || (err == SSL_ERROR_WANT_WRITE)) {
344
+ errno = EINTR;
345
+
346
+ if (err == SSL_ERROR_WANT_WRITE) {
347
+ connection->subscribeToSocketWriteAvailableEvents();
348
+ }
349
+ return SSL_HANDSHAKE_IN_PROGRESS;
350
+ } else if (err == SSL_ERROR_SYSCALL) {
351
+ getLog()->onEvent("SSL_connect failed with SSL error " + IntConvertor::convert(err) + ". Error stack:");
352
+
353
+ char errorBuffer[512];
354
+ unsigned long systemError;
355
+
356
+ while ((systemError = ERR_get_error()) != 0) {
357
+ ERR_error_string_n(systemError, errorBuffer, sizeof(errorBuffer));
358
+ getLog()->onEvent(errorBuffer);
359
+ }
360
+ getLog()->onEvent("End of error stack");
361
+
362
+ getLog()->onEvent(socket_get_last_error());
363
+
364
+ return SSL_HANDSHAKE_FAILED;
365
+ } else {
366
+ getLog()->onEvent("SSL_connect failed with SSL error " + IntConvertor::convert(err));
367
+ return SSL_HANDSHAKE_FAILED;
368
+ }
369
+ }
370
+
371
+ return SSL_HANDSHAKE_SUCCEDED;
372
+ }
373
+
374
+ void SSLSocketInitiator::onConnect(SocketConnector &connector, socket_handle socket) {
375
+ getLog()->onEvent("Socket connected handle: " + std::to_string(socket));
376
+
377
+ time_t now;
378
+ ::time(&now);
379
+
380
+ SocketConnections::iterator i = m_pendingConnections.find(socket);
381
+ if (i == m_pendingConnections.end()) {
382
+ return;
383
+ }
384
+ SSLSocketConnection *pSocketConnection = i->second;
385
+
386
+ m_pendingConnections.erase(i);
387
+ m_pendingSSLHandshakes[socket] = pSocketConnection;
388
+ pSocketConnection->setHandshakeStartTime(now);
389
+
390
+ handshakeSSLAndHandleConnection(connector, socket);
391
+ }
392
+
393
+ void SSLSocketInitiator::handshakeSSLAndHandleConnection(SocketConnector &connector, socket_handle socket) {
394
+ SocketConnections::iterator i = m_pendingSSLHandshakes.find(socket);
395
+ if (i == m_pendingSSLHandshakes.end()) {
396
+ return;
397
+ }
398
+ SSLSocketConnection *pSocketConnection = i->second;
399
+
400
+ SSLHandshakeStatus sslHandshakeStatus = handshakeSSL(pSocketConnection);
401
+
402
+ if (sslHandshakeStatus == SSL_HANDSHAKE_SUCCEDED) {
403
+ m_connections[socket] = pSocketConnection;
404
+ m_pendingSSLHandshakes.erase(i);
405
+ setConnected(pSocketConnection->getSession()->getSessionID());
406
+ pSocketConnection->onTimeout();
407
+ } else if (sslHandshakeStatus == SSL_HANDSHAKE_FAILED) {
408
+ setDisconnected(pSocketConnection->getSession()->getSessionID());
409
+
410
+ Session *pSession = pSocketConnection->getSession();
411
+ if (pSession) {
412
+ pSession->disconnect();
413
+ setDisconnected(pSession->getSessionID());
414
+ }
415
+
416
+ delete pSocketConnection;
417
+ m_pendingSSLHandshakes.erase(i);
418
+
419
+ getLog()->onEvent("Socket deleted due to ssl handshake error");
420
+ }
421
+ }
422
+
423
+ void SSLSocketInitiator::onWrite(SocketConnector &connector, socket_handle socket) {
424
+ SocketConnections::iterator iPendingSSL = m_pendingSSLHandshakes.find(socket);
425
+ if (iPendingSSL != m_pendingSSLHandshakes.end()) {
426
+ SSLSocketConnection *pSocketConnection = iPendingSSL->second;
427
+ pSocketConnection->unsignal();
428
+ handshakeSSLAndHandleConnection(connector, socket);
429
+ return;
430
+ }
431
+
432
+ SocketConnections::iterator i = m_connections.find(socket);
433
+ if (i == m_connections.end()) {
434
+ return;
435
+ }
436
+ SSLSocketConnection *pSocketConnection = i->second;
437
+
438
+ if (pSocketConnection->didReadFromSocketRequestToWrite()) {
439
+ pSocketConnection->read(connector);
440
+ }
441
+
442
+ if (pSocketConnection->processQueue()) {
443
+ pSocketConnection->unsignal();
444
+ }
445
+ }
446
+
447
+ bool SSLSocketInitiator::onData(SocketConnector &connector, socket_handle socket) {
448
+ SocketConnections::iterator iPending = m_pendingSSLHandshakes.find(socket);
449
+ if (iPending != m_pendingSSLHandshakes.end()) {
450
+ handshakeSSLAndHandleConnection(connector, socket);
451
+ return true;
452
+ }
453
+
454
+ SocketConnections::iterator i = m_connections.find(socket);
455
+ if (i == m_connections.end()) {
456
+ return false;
457
+ }
458
+ SSLSocketConnection *pSocketConnection = i->second;
459
+
460
+ if (pSocketConnection->didProcessQueueRequestToRead()) {
461
+ pSocketConnection->processQueue();
462
+ pSocketConnection->signal();
463
+ }
464
+
465
+ return pSocketConnection->read(connector);
466
+ }
467
+
468
+ void SSLSocketInitiator::onDisconnect(SocketConnector &, socket_handle socket) {
469
+ getLog()->onEvent("Socket disconnect " + std::to_string(socket));
470
+ SocketConnections::iterator i = m_connections.find(socket);
471
+ SocketConnections::iterator j = m_pendingConnections.find(socket);
472
+ SocketConnections::iterator k = m_pendingSSLHandshakes.find(socket);
473
+
474
+ SSLSocketConnection *pSocketConnection = 0;
475
+ if (i != m_connections.end()) {
476
+ pSocketConnection = i->second;
477
+ }
478
+ if (j != m_pendingConnections.end()) {
479
+ pSocketConnection = j->second;
480
+ }
481
+ if (k != m_pendingSSLHandshakes.end()) {
482
+ pSocketConnection = k->second;
483
+ }
484
+
485
+ if (!pSocketConnection) {
486
+ return;
487
+ }
488
+
489
+ Session *pSession = pSocketConnection->getSession();
490
+ if (pSession) {
491
+ pSession->disconnect();
492
+ setDisconnected(pSession->getSessionID());
493
+ }
494
+
495
+ delete pSocketConnection;
496
+ m_connections.erase(socket);
497
+ m_pendingConnections.erase(socket);
498
+ m_pendingSSLHandshakes.erase(socket);
499
+ }
500
+
501
+ void SSLSocketInitiator::onError(SocketConnector &connector) {
502
+ getLog()->onEvent("Socket error " + socket_get_last_error());
503
+ onTimeout(connector);
504
+ }
505
+
506
+ void SSLSocketInitiator::onTimeout(SocketConnector &) {
507
+ time_t now;
508
+ ::time(&now);
509
+
510
+ disconnectPendingSSLHandshakesThatTakeTooLong(now);
511
+
512
+ if ((now - m_lastConnect) >= m_reconnectInterval) {
513
+ connect();
514
+ m_lastConnect = now;
515
+ }
516
+
517
+ SocketConnections::iterator i;
518
+ for (i = m_connections.begin(); i != m_connections.end(); ++i) {
519
+ i->second->onTimeout();
520
+ }
521
+ }
522
+
523
+ void SSLSocketInitiator::disconnectPendingSSLHandshakesThatTakeTooLong(time_t now) {
524
+ SocketConnections::iterator iPendingSSL;
525
+ for (iPendingSSL = m_pendingSSLHandshakes.begin(); iPendingSSL != m_pendingSSLHandshakes.end();) {
526
+ FIX::SSLSocketConnection *pSocketConnection = iPendingSSL->second;
527
+
528
+ if (pSocketConnection->getSecondsFromHandshakeStart(now) > 10) {
529
+ getLog()->onEvent("SSL Handshake took too long to complete");
530
+
531
+ setDisconnected(pSocketConnection->getSession()->getSessionID());
532
+
533
+ Session *pSession = pSocketConnection->getSession();
534
+ if (pSession) {
535
+ pSession->disconnect();
536
+ setDisconnected(pSession->getSessionID());
537
+ }
538
+
539
+ delete pSocketConnection;
540
+
541
+ iPendingSSL = m_pendingSSLHandshakes.erase(iPendingSSL);
542
+ } else {
543
+ ++iPendingSSL;
544
+ }
545
+ }
546
+ }
547
+
548
+ int SSLSocketInitiator::passwordHandleCallback(char *buf, size_t bufsize, int verify) {
549
+ if (m_password.length() > bufsize) {
550
+ return -1;
551
+ }
552
+
553
+ std::strcpy(buf, m_password.c_str());
554
+ return m_password.length();
555
+ }
556
+ } // namespace FIX
557
+
558
+ #endif