quickfix_ruby 1.14.3.1 → 1.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/quickfix/Acceptor.h +2 -0
- data/ext/quickfix/AtomicCount.h +82 -12
- data/ext/quickfix/DOMDocument.h +9 -7
- data/ext/quickfix/DataDictionary.cpp +77 -14
- data/ext/quickfix/DataDictionary.h +90 -16
- data/ext/quickfix/Dictionary.cpp +1 -2
- data/ext/quickfix/Exceptions.h +3 -5
- data/ext/quickfix/Field.h +83 -32
- data/ext/quickfix/FieldConvertors.cpp +93 -0
- data/ext/quickfix/FieldConvertors.h +129 -275
- data/ext/quickfix/FieldMap.cpp +53 -13
- data/ext/quickfix/FieldMap.h +200 -62
- data/ext/quickfix/FieldTypes.cpp +10 -10
- data/ext/quickfix/FieldTypes.h +293 -44
- data/ext/quickfix/FileLog.cpp +6 -10
- data/ext/quickfix/FileLog.h +4 -10
- data/ext/quickfix/FileStore.cpp +19 -6
- data/ext/quickfix/FileStore.h +4 -0
- data/ext/quickfix/FixFieldNumbers.h +1462 -1461
- data/ext/quickfix/FixFields.h +1462 -1461
- data/ext/quickfix/FixValues.h +3230 -3227
- data/ext/quickfix/HttpConnection.cpp +1 -1
- data/ext/quickfix/Initiator.cpp +7 -1
- data/ext/quickfix/Initiator.h +2 -0
- data/ext/quickfix/Log.h +6 -12
- data/ext/quickfix/Message.cpp +186 -57
- data/ext/quickfix/Message.h +109 -47
- data/ext/quickfix/MySQLConnection.h +1 -1
- data/ext/quickfix/PostgreSQLConnection.h +1 -1
- data/ext/quickfix/QuickfixRuby.cpp +79141 -77959
- data/ext/quickfix/QuickfixRuby.h +1 -1
- data/ext/quickfix/SSLSocketAcceptor.cpp +410 -0
- data/ext/quickfix/SSLSocketAcceptor.h +185 -0
- data/ext/quickfix/SSLSocketConnection.cpp +427 -0
- data/ext/quickfix/SSLSocketConnection.h +206 -0
- data/ext/quickfix/SSLSocketInitiator.cpp +485 -0
- data/ext/quickfix/SSLSocketInitiator.h +196 -0
- data/ext/quickfix/Session.cpp +113 -20
- data/ext/quickfix/Session.h +18 -4
- data/ext/quickfix/SessionFactory.cpp +10 -3
- data/ext/quickfix/SessionSettings.cpp +5 -3
- data/ext/quickfix/SessionSettings.h +97 -5
- data/ext/quickfix/Settings.cpp +72 -2
- data/ext/quickfix/Settings.h +3 -0
- data/ext/quickfix/SharedArray.h +140 -6
- data/ext/quickfix/SocketConnection.cpp +2 -2
- data/ext/quickfix/SocketConnector.cpp +5 -2
- data/ext/quickfix/SocketConnector.h +3 -2
- data/ext/quickfix/SocketInitiator.cpp +28 -4
- data/ext/quickfix/SocketInitiator.h +1 -1
- data/ext/quickfix/SocketMonitor.cpp +5 -5
- data/ext/quickfix/ThreadedSSLSocketAcceptor.cpp +455 -0
- data/ext/quickfix/ThreadedSSLSocketAcceptor.h +217 -0
- data/ext/quickfix/ThreadedSSLSocketConnection.cpp +404 -0
- data/ext/quickfix/ThreadedSSLSocketConnection.h +189 -0
- data/ext/quickfix/ThreadedSSLSocketInitiator.cpp +469 -0
- data/ext/quickfix/ThreadedSSLSocketInitiator.h +201 -0
- data/ext/quickfix/ThreadedSocketAcceptor.cpp +5 -1
- data/ext/quickfix/ThreadedSocketConnection.cpp +8 -2
- data/ext/quickfix/ThreadedSocketConnection.h +4 -1
- data/ext/quickfix/ThreadedSocketInitiator.cpp +24 -4
- data/ext/quickfix/ThreadedSocketInitiator.h +1 -1
- data/ext/quickfix/Utility.cpp +23 -1
- data/ext/quickfix/Utility.h +28 -2
- data/ext/quickfix/UtilitySSL.cpp +1733 -0
- data/ext/quickfix/UtilitySSL.h +277 -0
- data/ext/quickfix/config-all.h +10 -0
- data/ext/quickfix/dirent_windows.h +838 -0
- data/ext/quickfix/double-conversion/bignum-dtoa.cc +641 -0
- data/ext/quickfix/double-conversion/bignum-dtoa.h +84 -0
- data/ext/quickfix/double-conversion/bignum.cc +766 -0
- data/ext/quickfix/double-conversion/bignum.h +144 -0
- data/ext/quickfix/double-conversion/cached-powers.cc +176 -0
- data/ext/quickfix/double-conversion/cached-powers.h +64 -0
- data/ext/quickfix/double-conversion/diy-fp.cc +57 -0
- data/ext/quickfix/double-conversion/diy-fp.h +118 -0
- data/ext/quickfix/double-conversion/double-conversion.cc +994 -0
- data/ext/quickfix/double-conversion/double-conversion.h +543 -0
- data/ext/quickfix/double-conversion/fast-dtoa.cc +665 -0
- data/ext/quickfix/double-conversion/fast-dtoa.h +88 -0
- data/ext/quickfix/double-conversion/fixed-dtoa.cc +404 -0
- data/ext/quickfix/double-conversion/fixed-dtoa.h +56 -0
- data/ext/quickfix/double-conversion/ieee.h +402 -0
- data/ext/quickfix/double-conversion/strtod.cc +557 -0
- data/ext/quickfix/double-conversion/strtod.h +45 -0
- data/ext/quickfix/double-conversion/utils.h +372 -0
- data/ext/quickfix/stdint_msvc.h +254 -0
- data/lib/quickfix44.rb +3329 -10
- data/lib/quickfix50.rb +6649 -81
- data/lib/quickfix50sp1.rb +8054 -142
- data/lib/quickfix50sp2.rb +10900 -234
- data/lib/quickfix_fields.rb +7662 -7649
- data/spec/FIX40.xml +28 -28
- data/spec/FIX41.xml +29 -29
- data/spec/FIX42.xml +47 -47
- data/spec/FIX43.xml +148 -148
- data/spec/FIX44.xml +1078 -1081
- data/spec/FIX50.xml +1292 -1289
- data/spec/FIX50SP1.xml +1811 -1802
- data/spec/FIX50SP2.xml +1948 -1939
- data/spec/FIXT11.xml +5 -8
- data/test/test_FieldBaseTestCase.rb +1 -1
- data/test/test_MessageTestCase.rb +2 -2
- metadata +42 -6
@@ -0,0 +1,189 @@
|
|
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
|
+
/* -*- C++ -*- */
|
97
|
+
|
98
|
+
/****************************************************************************
|
99
|
+
** Copyright (c) 2001-2014
|
100
|
+
**
|
101
|
+
** This file is part of the QuickFIX FIX Engine
|
102
|
+
**
|
103
|
+
** This file may be distributed under the terms of the quickfixengine.org
|
104
|
+
** license as defined by quickfixengine.org and appearing in the file
|
105
|
+
** LICENSE included in the packaging of this file.
|
106
|
+
**
|
107
|
+
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
108
|
+
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
109
|
+
**
|
110
|
+
** See http://www.quickfixengine.org/LICENSE for licensing information.
|
111
|
+
**
|
112
|
+
** Contact ask@quickfixengine.org if any conditions of this licensing are
|
113
|
+
** not clear to you.
|
114
|
+
**
|
115
|
+
****************************************************************************/
|
116
|
+
|
117
|
+
#ifndef FIX_THREADEDSSLSOCKETCONNECTION_H
|
118
|
+
#define FIX_THREADEDSSLSOCKETCONNECTION_H
|
119
|
+
|
120
|
+
#if (HAVE_SSL > 0)
|
121
|
+
|
122
|
+
#ifdef _MSC_VER
|
123
|
+
#pragma warning(disable : 4503 4355 4786 4290)
|
124
|
+
#endif
|
125
|
+
|
126
|
+
#include "Parser.h"
|
127
|
+
#include "Responder.h"
|
128
|
+
#include "SessionID.h"
|
129
|
+
#include "Mutex.h"
|
130
|
+
#include "UtilitySSL.h"
|
131
|
+
#include <set>
|
132
|
+
#include <map>
|
133
|
+
|
134
|
+
namespace FIX
|
135
|
+
{
|
136
|
+
class ThreadedSSLSocketAcceptor;
|
137
|
+
class ThreadedSSLSocketInitiator;
|
138
|
+
class Session;
|
139
|
+
class Application;
|
140
|
+
class Log;
|
141
|
+
|
142
|
+
/// Encapsulates a socket file descriptor (multi-threaded).
|
143
|
+
class ThreadedSSLSocketConnection : Responder
|
144
|
+
{
|
145
|
+
public:
|
146
|
+
typedef std::set< SessionID > Sessions;
|
147
|
+
|
148
|
+
ThreadedSSLSocketConnection(int s, SSL *ssl, Sessions sessions, Log *pLog);
|
149
|
+
ThreadedSSLSocketConnection(const SessionID &, int s, SSL *ssl,
|
150
|
+
const std::string &address, short port,
|
151
|
+
Log *pLog);
|
152
|
+
virtual ~ThreadedSSLSocketConnection();
|
153
|
+
|
154
|
+
Session *getSession() const { return m_pSession; }
|
155
|
+
int getSocket() const { return m_socket; }
|
156
|
+
bool connect();
|
157
|
+
void disconnect();
|
158
|
+
bool read();
|
159
|
+
SSL *sslObject() { return m_ssl; }
|
160
|
+
|
161
|
+
private:
|
162
|
+
typedef std::pair< int, SSL * > SocketKey;
|
163
|
+
|
164
|
+
bool readMessage(std::string &msg) throw(SocketRecvFailed);
|
165
|
+
void processStream();
|
166
|
+
bool send(const std::string &);
|
167
|
+
bool setSession(const std::string &msg);
|
168
|
+
|
169
|
+
int m_socket;
|
170
|
+
SSL *m_ssl;
|
171
|
+
char m_buffer[BUFSIZ];
|
172
|
+
|
173
|
+
std::string m_address;
|
174
|
+
int m_port;
|
175
|
+
|
176
|
+
Log *m_pLog;
|
177
|
+
Parser m_parser;
|
178
|
+
Sessions m_sessions;
|
179
|
+
Session *m_pSession;
|
180
|
+
bool m_disconnect;
|
181
|
+
fd_set m_fds;
|
182
|
+
|
183
|
+
Mutex m_mutex;
|
184
|
+
};
|
185
|
+
}
|
186
|
+
|
187
|
+
#endif // FIX_THREADEDSOCKETCONNECTION_H
|
188
|
+
|
189
|
+
#endif
|
@@ -0,0 +1,469 @@
|
|
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
|
+
** Copyright (c) 2001-2014
|
97
|
+
**
|
98
|
+
** This file is part of the QuickFIX FIX Engine
|
99
|
+
**
|
100
|
+
** This file may be distributed under the terms of the quickfixengine.org
|
101
|
+
** license as defined by quickfixengine.org and appearing in the file
|
102
|
+
** LICENSE included in the packaging of this file.
|
103
|
+
**
|
104
|
+
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
105
|
+
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
106
|
+
**
|
107
|
+
** See http://www.quickfixengine.org/LICENSE for licensing information.
|
108
|
+
**
|
109
|
+
** Contact ask@quickfixengine.org if any conditions of this licensing are
|
110
|
+
** not clear to you.
|
111
|
+
**
|
112
|
+
****************************************************************************/
|
113
|
+
|
114
|
+
#ifdef _MSC_VER
|
115
|
+
#include "stdafx.h"
|
116
|
+
#else
|
117
|
+
#include "config.h"
|
118
|
+
#endif
|
119
|
+
|
120
|
+
#if (HAVE_SSL > 0)
|
121
|
+
|
122
|
+
#include "UtilitySSL.h"
|
123
|
+
#include "ThreadedSSLSocketInitiator.h"
|
124
|
+
#include "Session.h"
|
125
|
+
#include "Settings.h"
|
126
|
+
|
127
|
+
namespace FIX
|
128
|
+
{
|
129
|
+
FIX::ThreadedSSLSocketInitiator *initObjT = 0;
|
130
|
+
|
131
|
+
int ThreadedSSLSocketInitiator::passwordHandleCB(char *buf, int bufsize, int verify, void *job)
|
132
|
+
{
|
133
|
+
return initObjT->passwordHandleCallback(buf, bufsize, verify, job);
|
134
|
+
}
|
135
|
+
|
136
|
+
ThreadedSSLSocketInitiator::ThreadedSSLSocketInitiator(
|
137
|
+
Application &application, MessageStoreFactory &factory,
|
138
|
+
const SessionSettings &settings) throw(ConfigError)
|
139
|
+
: Initiator(application, factory, settings), m_lastConnect(0),
|
140
|
+
m_reconnectInterval(30), m_noDelay(false), m_sendBufSize(0),
|
141
|
+
m_rcvBufSize(0), m_sslInit(false), m_ctx(0), m_cert(0), m_key(0)
|
142
|
+
{
|
143
|
+
socket_init();
|
144
|
+
initObjT = this;
|
145
|
+
}
|
146
|
+
|
147
|
+
ThreadedSSLSocketInitiator::ThreadedSSLSocketInitiator(
|
148
|
+
Application &application, MessageStoreFactory &factory,
|
149
|
+
const SessionSettings &settings, LogFactory &logFactory) throw(ConfigError)
|
150
|
+
: Initiator(application, factory, settings, logFactory), m_lastConnect(0),
|
151
|
+
m_reconnectInterval(30), m_noDelay(false), m_sendBufSize(0),
|
152
|
+
m_rcvBufSize(0), m_sslInit(false), m_ctx(0), m_cert(0), m_key(0)
|
153
|
+
{
|
154
|
+
socket_init();
|
155
|
+
initObjT = this;
|
156
|
+
}
|
157
|
+
|
158
|
+
ThreadedSSLSocketInitiator::~ThreadedSSLSocketInitiator()
|
159
|
+
{
|
160
|
+
if (m_sslInit)
|
161
|
+
{
|
162
|
+
SSL_CTX_free(m_ctx);
|
163
|
+
m_ctx = 0;
|
164
|
+
ssl_term();
|
165
|
+
}
|
166
|
+
|
167
|
+
socket_term();
|
168
|
+
}
|
169
|
+
|
170
|
+
void ThreadedSSLSocketInitiator::onConfigure(const SessionSettings &s) throw(
|
171
|
+
ConfigError)
|
172
|
+
{
|
173
|
+
const Dictionary &dict = s.get();
|
174
|
+
|
175
|
+
if (dict.has(RECONNECT_INTERVAL))
|
176
|
+
m_reconnectInterval = dict.getInt(RECONNECT_INTERVAL);
|
177
|
+
if (dict.has(SOCKET_NODELAY))
|
178
|
+
m_noDelay = dict.getBool(SOCKET_NODELAY);
|
179
|
+
if (dict.has(SOCKET_SEND_BUFFER_SIZE))
|
180
|
+
m_sendBufSize = dict.getInt(SOCKET_SEND_BUFFER_SIZE);
|
181
|
+
if (dict.has(SOCKET_RECEIVE_BUFFER_SIZE))
|
182
|
+
m_rcvBufSize = dict.getInt(SOCKET_RECEIVE_BUFFER_SIZE);
|
183
|
+
}
|
184
|
+
|
185
|
+
void ThreadedSSLSocketInitiator::onInitialize(const SessionSettings &s) throw(
|
186
|
+
RuntimeError)
|
187
|
+
{
|
188
|
+
if (m_sslInit)
|
189
|
+
return;
|
190
|
+
|
191
|
+
ssl_init();
|
192
|
+
|
193
|
+
std::string errStr;
|
194
|
+
|
195
|
+
/* set up the application context */
|
196
|
+
if ((m_ctx = createSSLContext(false, m_settings, errStr)) == 0)
|
197
|
+
{
|
198
|
+
throw RuntimeError(errStr);
|
199
|
+
}
|
200
|
+
|
201
|
+
if (m_cert && m_key)
|
202
|
+
{
|
203
|
+
if (SSL_CTX_use_certificate(m_ctx, m_cert) < 1)
|
204
|
+
{
|
205
|
+
ssl_term();
|
206
|
+
throw RuntimeError("Failed to set certificate");
|
207
|
+
}
|
208
|
+
|
209
|
+
if (SSL_CTX_use_RSAPrivateKey(m_ctx, m_key) <= 0)
|
210
|
+
{
|
211
|
+
ssl_term();
|
212
|
+
throw RuntimeError("Failed to set key");
|
213
|
+
}
|
214
|
+
}
|
215
|
+
else if (!loadSSLCert(m_ctx, false, m_settings, getLog(), ThreadedSSLSocketInitiator::passwordHandleCB, errStr))
|
216
|
+
{
|
217
|
+
ssl_term();
|
218
|
+
throw RuntimeError(errStr);
|
219
|
+
}
|
220
|
+
|
221
|
+
int verifyLevel;
|
222
|
+
if (!loadCAInfo(m_ctx, false, m_settings, getLog(), errStr, verifyLevel))
|
223
|
+
{
|
224
|
+
ssl_term();
|
225
|
+
throw RuntimeError(errStr);
|
226
|
+
}
|
227
|
+
|
228
|
+
m_sslInit = true;
|
229
|
+
}
|
230
|
+
|
231
|
+
void ThreadedSSLSocketInitiator::onStart()
|
232
|
+
{
|
233
|
+
while (!isStopped())
|
234
|
+
{
|
235
|
+
time_t now;
|
236
|
+
::time(&now);
|
237
|
+
|
238
|
+
if ((now - m_lastConnect) >= m_reconnectInterval)
|
239
|
+
{
|
240
|
+
Locker l(m_mutex);
|
241
|
+
connect();
|
242
|
+
m_lastConnect = now;
|
243
|
+
}
|
244
|
+
|
245
|
+
process_sleep(1);
|
246
|
+
}
|
247
|
+
}
|
248
|
+
|
249
|
+
bool ThreadedSSLSocketInitiator::onPoll(double timeout) { return false; }
|
250
|
+
|
251
|
+
void ThreadedSSLSocketInitiator::onStop()
|
252
|
+
{
|
253
|
+
SocketToThread threads;
|
254
|
+
SocketToThread::iterator i;
|
255
|
+
|
256
|
+
{
|
257
|
+
Locker l(m_mutex);
|
258
|
+
|
259
|
+
time_t start = 0;
|
260
|
+
time_t now = 0;
|
261
|
+
|
262
|
+
::time(&start);
|
263
|
+
while (isLoggedOn())
|
264
|
+
{
|
265
|
+
if (::time(&now) - 5 >= start)
|
266
|
+
break;
|
267
|
+
}
|
268
|
+
|
269
|
+
threads = m_threads;
|
270
|
+
m_threads.clear();
|
271
|
+
}
|
272
|
+
|
273
|
+
for (i = threads.begin(); i != threads.end(); ++i)
|
274
|
+
ssl_socket_close(i->first.first, i->first.second);
|
275
|
+
|
276
|
+
for (i = threads.begin(); i != threads.end(); ++i)
|
277
|
+
{
|
278
|
+
thread_join(i->second);
|
279
|
+
if (i->first.second != 0)
|
280
|
+
SSL_free(i->first.second);
|
281
|
+
}
|
282
|
+
threads.clear();
|
283
|
+
}
|
284
|
+
|
285
|
+
void ThreadedSSLSocketInitiator::doConnect(const SessionID &s,
|
286
|
+
const Dictionary &d)
|
287
|
+
{
|
288
|
+
try
|
289
|
+
{
|
290
|
+
Session *session = Session::lookupSession(s);
|
291
|
+
if (!session->isSessionTime(UtcTimeStamp()))
|
292
|
+
return;
|
293
|
+
|
294
|
+
Log *log = session->getLog();
|
295
|
+
|
296
|
+
std::string address;
|
297
|
+
short port = 0;
|
298
|
+
getHost(s, d, address, port);
|
299
|
+
|
300
|
+
int socket = socket_createConnector();
|
301
|
+
if (m_noDelay)
|
302
|
+
socket_setsockopt(socket, TCP_NODELAY);
|
303
|
+
if (m_sendBufSize)
|
304
|
+
socket_setsockopt(socket, SO_SNDBUF, m_sendBufSize);
|
305
|
+
if (m_rcvBufSize)
|
306
|
+
socket_setsockopt(socket, SO_RCVBUF, m_rcvBufSize);
|
307
|
+
|
308
|
+
setPending(s);
|
309
|
+
log->onEvent("Connecting to " + address + " on port " +
|
310
|
+
IntConvertor::convert((unsigned short)port));
|
311
|
+
|
312
|
+
SSL *ssl = SSL_new(m_ctx);
|
313
|
+
if (ssl == 0)
|
314
|
+
{
|
315
|
+
log->onEvent("Failed to create ssl object");
|
316
|
+
return;
|
317
|
+
}
|
318
|
+
SSL_clear(ssl);
|
319
|
+
BIO *sbio = BIO_new_socket(socket, BIO_CLOSE);
|
320
|
+
SSL_set_bio(ssl, sbio, sbio);
|
321
|
+
|
322
|
+
ThreadedSSLSocketConnection *pConnection = new ThreadedSSLSocketConnection(
|
323
|
+
s, socket, ssl, address, port, getLog());
|
324
|
+
|
325
|
+
ThreadPair *pair = new ThreadPair(this, pConnection);
|
326
|
+
|
327
|
+
{
|
328
|
+
Locker l(m_mutex);
|
329
|
+
thread_id thread;
|
330
|
+
if (thread_spawn(&socketThread, pair, thread))
|
331
|
+
{
|
332
|
+
addThread(SocketKey(socket, ssl), thread);
|
333
|
+
}
|
334
|
+
else
|
335
|
+
{
|
336
|
+
delete pair;
|
337
|
+
pConnection->disconnect();
|
338
|
+
delete pConnection;
|
339
|
+
SSL_free(ssl);
|
340
|
+
setDisconnected(s);
|
341
|
+
}
|
342
|
+
}
|
343
|
+
}
|
344
|
+
catch (std::exception &)
|
345
|
+
{
|
346
|
+
}
|
347
|
+
}
|
348
|
+
|
349
|
+
void ThreadedSSLSocketInitiator::addThread(SocketKey s, thread_id t)
|
350
|
+
{
|
351
|
+
Locker l(m_mutex);
|
352
|
+
|
353
|
+
m_threads[s] = t;
|
354
|
+
}
|
355
|
+
|
356
|
+
void ThreadedSSLSocketInitiator::removeThread(SocketKey s)
|
357
|
+
{
|
358
|
+
Locker l(m_mutex);
|
359
|
+
SocketToThread::iterator i = m_threads.find(s);
|
360
|
+
|
361
|
+
if (i != m_threads.end())
|
362
|
+
{
|
363
|
+
thread_detach(i->second);
|
364
|
+
if (i->first.second != 0)
|
365
|
+
SSL_free(i->first.second);
|
366
|
+
m_threads.erase(i);
|
367
|
+
}
|
368
|
+
}
|
369
|
+
|
370
|
+
THREAD_PROC ThreadedSSLSocketInitiator::socketThread(void *p)
|
371
|
+
{
|
372
|
+
ThreadPair *pair = reinterpret_cast< ThreadPair * >(p);
|
373
|
+
|
374
|
+
ThreadedSSLSocketInitiator *pInitiator = pair->first;
|
375
|
+
ThreadedSSLSocketConnection *pConnection = pair->second;
|
376
|
+
FIX::SessionID sessionID = pConnection->getSession()->getSessionID();
|
377
|
+
FIX::Session *pSession = FIX::Session::lookupSession(sessionID);
|
378
|
+
int socket = pConnection->getSocket();
|
379
|
+
delete pair;
|
380
|
+
|
381
|
+
pInitiator->lock();
|
382
|
+
|
383
|
+
if (!pConnection->connect())
|
384
|
+
{
|
385
|
+
pInitiator->getLog()->onEvent("Connection failed");
|
386
|
+
pConnection->disconnect();
|
387
|
+
SSL *ssl = pConnection->sslObject();
|
388
|
+
delete pConnection;
|
389
|
+
pInitiator->removeThread(SocketKey(socket, ssl));
|
390
|
+
pInitiator->setDisconnected(sessionID);
|
391
|
+
return 0;
|
392
|
+
}
|
393
|
+
|
394
|
+
// Do the SSL handshake.
|
395
|
+
int rc = SSL_connect(pConnection->sslObject());
|
396
|
+
if (rc <= 0)
|
397
|
+
{
|
398
|
+
int err = SSL_get_error(pConnection->sslObject(), rc);
|
399
|
+
pInitiator->getLog()->onEvent("SSL_connect failed with SSL error " + IntConvertor::convert(err));
|
400
|
+
pConnection->disconnect();
|
401
|
+
SSL *ssl = pConnection->sslObject();
|
402
|
+
delete pConnection;
|
403
|
+
pInitiator->removeThread(SocketKey(socket, ssl));
|
404
|
+
pInitiator->setDisconnected(sessionID);
|
405
|
+
return 0;
|
406
|
+
}
|
407
|
+
|
408
|
+
pInitiator->setConnected(sessionID);
|
409
|
+
pInitiator->getLog()->onEvent("Connection succeeded");
|
410
|
+
|
411
|
+
pSession->next();
|
412
|
+
|
413
|
+
while (pConnection->read())
|
414
|
+
{
|
415
|
+
}
|
416
|
+
|
417
|
+
SSL *ssl = pConnection->sslObject();
|
418
|
+
delete pConnection;
|
419
|
+
if (!pInitiator->isStopped())
|
420
|
+
pInitiator->removeThread(SocketKey(socket, ssl));
|
421
|
+
|
422
|
+
pInitiator->setDisconnected(sessionID);
|
423
|
+
return 0;
|
424
|
+
}
|
425
|
+
|
426
|
+
void ThreadedSSLSocketInitiator::getHost(const SessionID &s,
|
427
|
+
const Dictionary &d,
|
428
|
+
std::string &address, short &port)
|
429
|
+
{
|
430
|
+
int num = 0;
|
431
|
+
SessionToHostNum::iterator i = m_sessionToHostNum.find(s);
|
432
|
+
if (i != m_sessionToHostNum.end())
|
433
|
+
num = i->second;
|
434
|
+
|
435
|
+
std::stringstream hostStream;
|
436
|
+
hostStream << SOCKET_CONNECT_HOST << num;
|
437
|
+
std::string hostString = hostStream.str();
|
438
|
+
|
439
|
+
std::stringstream portStream;
|
440
|
+
portStream << SOCKET_CONNECT_PORT << num;
|
441
|
+
std::string portString = portStream.str();
|
442
|
+
|
443
|
+
if (d.has(hostString) && d.has(portString))
|
444
|
+
{
|
445
|
+
address = d.getString(hostString);
|
446
|
+
port = (short)d.getInt(portString);
|
447
|
+
}
|
448
|
+
else
|
449
|
+
{
|
450
|
+
num = 0;
|
451
|
+
address = d.getString(SOCKET_CONNECT_HOST);
|
452
|
+
port = (short)d.getInt(SOCKET_CONNECT_PORT);
|
453
|
+
}
|
454
|
+
|
455
|
+
m_sessionToHostNum[s] = ++num;
|
456
|
+
}
|
457
|
+
|
458
|
+
int ThreadedSSLSocketInitiator::passwordHandleCallback(char *buf, size_t bufsize,
|
459
|
+
int verify, void *job)
|
460
|
+
{
|
461
|
+
if (m_password.length() > bufsize)
|
462
|
+
return -1;
|
463
|
+
|
464
|
+
std::strcpy(buf, m_password.c_str());
|
465
|
+
return m_password.length();
|
466
|
+
}
|
467
|
+
}
|
468
|
+
|
469
|
+
#endif
|