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,157 @@
1
+ /* -*- C++ -*- */
2
+
3
+ /****************************************************************************
4
+ ** Copyright (c) 2001-2014
5
+ **
6
+ ** This file is part of the QuickFIX FIX Engine
7
+ **
8
+ ** This file may be distributed under the terms of the quickfixengine.org
9
+ ** license as defined by quickfixengine.org and appearing in the file
10
+ ** LICENSE included in the packaging of this file.
11
+ **
12
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14
+ **
15
+ ** See http://www.quickfixengine.org/LICENSE for licensing information.
16
+ **
17
+ ** Contact ask@quickfixengine.org if any conditions of this licensing are
18
+ ** not clear to you.
19
+ **
20
+ ****************************************************************************/
21
+
22
+ #ifndef FIX_POSTGRESQLLOG_H
23
+ #define FIX_POSTGRESQLLOG_H
24
+
25
+ #ifndef HAVE_POSTGRESQL
26
+ #error PostgreSQLLog.h included, but HAVE_POSTGRESQL not defined
27
+ #endif
28
+
29
+ #ifdef HAVE_POSTGRESQL
30
+
31
+ #ifdef _MSC_VER
32
+ #pragma warning(disable : 4503 4355 4786 4290)
33
+ #endif
34
+
35
+ #include "Log.h"
36
+ #include "PostgreSQLConnection.h"
37
+ #include "SessionSettings.h"
38
+ #include <fstream>
39
+ #include <string>
40
+
41
+ namespace FIX {
42
+ /// PostgreSQL based implementation of Log.
43
+ class PostgreSQLLog : public Log {
44
+ public:
45
+ PostgreSQLLog(const SessionID &s, const DatabaseConnectionID &d, PostgreSQLConnectionPool *p);
46
+ PostgreSQLLog(const DatabaseConnectionID &d, PostgreSQLConnectionPool *p);
47
+ PostgreSQLLog(
48
+ const SessionID &s,
49
+ const std::string &database,
50
+ const std::string &user,
51
+ const std::string &password,
52
+ const std::string &host,
53
+ short port);
54
+ PostgreSQLLog(
55
+ const std::string &database,
56
+ const std::string &user,
57
+ const std::string &password,
58
+ const std::string &host,
59
+ short port);
60
+
61
+ ~PostgreSQLLog();
62
+
63
+ void clear();
64
+ void backup();
65
+ void setIncomingTable(const std::string &incomingTable) { m_incomingTable = incomingTable; }
66
+ void setOutgoingTable(const std::string &outgoingTable) { m_outgoingTable = outgoingTable; }
67
+ void setEventTable(const std::string &eventTable) { m_eventTable = eventTable; }
68
+
69
+ void onIncoming(const std::string &value) { insert(m_incomingTable, value); }
70
+ void onOutgoing(const std::string &value) { insert(m_outgoingTable, value); }
71
+ void onEvent(const std::string &value) { insert(m_eventTable, value); }
72
+
73
+ private:
74
+ void init();
75
+ void insert(const std::string &table, const std::string value);
76
+
77
+ std::string m_incomingTable;
78
+ std::string m_outgoingTable;
79
+ std::string m_eventTable;
80
+ PostgreSQLConnection *m_pConnection;
81
+ PostgreSQLConnectionPool *m_pConnectionPool;
82
+ SessionID *m_pSessionID;
83
+ };
84
+
85
+ /// Creates a MySQL based implementation of Log.
86
+ class PostgreSQLLogFactory : public LogFactory {
87
+ public:
88
+ static const std::string DEFAULT_DATABASE;
89
+ static const std::string DEFAULT_USER;
90
+ static const std::string DEFAULT_PASSWORD;
91
+ static const std::string DEFAULT_HOST;
92
+ static const short DEFAULT_PORT;
93
+
94
+ PostgreSQLLogFactory(const SessionSettings &settings)
95
+ : m_settings(settings),
96
+ m_useSettings(true) {
97
+ bool poolConnections = false;
98
+ try {
99
+ poolConnections = settings.get().getBool(POSTGRESQL_LOG_USECONNECTIONPOOL);
100
+ } catch (ConfigError &) {}
101
+
102
+ m_connectionPoolPtr = PostgreSQLConnectionPoolPtr(new PostgreSQLConnectionPool(poolConnections));
103
+ }
104
+
105
+ PostgreSQLLogFactory(
106
+ const std::string &database,
107
+ const std::string &user,
108
+ const std::string &password,
109
+ const std::string &host,
110
+ short port)
111
+ : m_database(database),
112
+ m_user(user),
113
+ m_password(password),
114
+ m_host(host),
115
+ m_port(port),
116
+ m_useSettings(false) {
117
+ m_connectionPoolPtr = PostgreSQLConnectionPoolPtr(new PostgreSQLConnectionPool(false));
118
+ }
119
+
120
+ PostgreSQLLogFactory()
121
+ : m_database(DEFAULT_DATABASE),
122
+ m_user(DEFAULT_USER),
123
+ m_password(DEFAULT_PASSWORD),
124
+ m_host(DEFAULT_HOST),
125
+ m_port(DEFAULT_PORT),
126
+ m_useSettings(false) {
127
+ m_connectionPoolPtr = PostgreSQLConnectionPoolPtr(new PostgreSQLConnectionPool(false));
128
+ }
129
+
130
+ Log *create();
131
+ Log *create(const SessionID &);
132
+ void destroy(Log *);
133
+
134
+ private:
135
+ void init(
136
+ const Dictionary &settings,
137
+ std::string &database,
138
+ std::string &user,
139
+ std::string &password,
140
+ std::string &host,
141
+ short &port);
142
+
143
+ void initLog(const Dictionary &settings, PostgreSQLLog &log);
144
+
145
+ PostgreSQLConnectionPoolPtr m_connectionPoolPtr;
146
+ SessionSettings m_settings;
147
+ std::string m_database;
148
+ std::string m_user;
149
+ std::string m_password;
150
+ std::string m_host;
151
+ short m_port;
152
+ bool m_useSettings;
153
+ };
154
+ } // namespace FIX
155
+
156
+ #endif // FIX_POSTGRESQLLOG_H
157
+ #endif // HAVE_POSTGRESQL
@@ -0,0 +1,327 @@
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
+ #ifdef HAVE_POSTGRESQL
27
+
28
+ #include "FieldConvertors.h"
29
+ #include "Parser.h"
30
+ #include "PostgreSQLStore.h"
31
+ #include "SessionID.h"
32
+ #include "SessionSettings.h"
33
+ #include "Utility.h"
34
+ #include "strptime.h"
35
+ #include <fstream>
36
+ #include <string>
37
+
38
+ namespace FIX {
39
+
40
+ const std::string PostgreSQLStoreFactory::DEFAULT_DATABASE = "quickfix";
41
+ const std::string PostgreSQLStoreFactory::DEFAULT_USER = "postgres";
42
+ const std::string PostgreSQLStoreFactory::DEFAULT_PASSWORD = "";
43
+ const std::string PostgreSQLStoreFactory::DEFAULT_HOST = "localhost";
44
+ const short PostgreSQLStoreFactory::DEFAULT_PORT = 0;
45
+
46
+ PostgreSQLStore::PostgreSQLStore(
47
+ const UtcTimeStamp &now,
48
+ const SessionID &sessionID,
49
+ const DatabaseConnectionID &connection,
50
+ PostgreSQLConnectionPool *pool)
51
+ : m_cache(now),
52
+ m_pConnectionPool(pool),
53
+ m_sessionID(sessionID) {
54
+ m_pConnection = m_pConnectionPool->create(connection);
55
+ populateCache();
56
+ }
57
+
58
+ PostgreSQLStore::PostgreSQLStore(
59
+ const UtcTimeStamp &now,
60
+ const SessionID &sessionID,
61
+ const std::string &database,
62
+ const std::string &user,
63
+ const std::string &password,
64
+ const std::string &host,
65
+ short port)
66
+ : m_cache(now),
67
+ m_pConnectionPool(0),
68
+ m_sessionID(sessionID) {
69
+ m_pConnection = new PostgreSQLConnection(database, user, password, host, port);
70
+ populateCache();
71
+ }
72
+
73
+ PostgreSQLStore::~PostgreSQLStore() {
74
+ if (m_pConnectionPool) {
75
+ m_pConnectionPool->destroy(m_pConnection);
76
+ } else {
77
+ delete m_pConnection;
78
+ }
79
+ }
80
+
81
+ void PostgreSQLStore::populateCache() {
82
+ std::stringstream queryString;
83
+
84
+ queryString << "SELECT creation_time, incoming_seqnum, outgoing_seqnum FROM quickfix.sessions WHERE "
85
+ << "beginstring=" << "'" << m_sessionID.getBeginString().getValue() << "' and "
86
+ << "sendercompid=" << "'" << m_sessionID.getSenderCompID().getValue() << "' and "
87
+ << "targetcompid=" << "'" << m_sessionID.getTargetCompID().getValue() << "' and "
88
+ << "session_qualifier=" << "'" << m_sessionID.getSessionQualifier() << "'";
89
+
90
+ PostgreSQLQuery query(queryString.str());
91
+ if (!m_pConnection->execute(query)) {
92
+ throw ConfigError("Unable to query sessions table");
93
+ }
94
+
95
+ int rows = query.rows();
96
+ if (rows > 1) {
97
+ throw ConfigError("Multiple entries found for session in database");
98
+ }
99
+
100
+ if (rows == 1) {
101
+ struct tm time;
102
+ std::string sqlTime = query.getValue(0, 0);
103
+ strptime(sqlTime.c_str(), "%Y-%m-%d %H:%M:%S", &time);
104
+ m_cache.setCreationTime(UtcTimeStamp(&time));
105
+ m_cache.setNextTargetMsgSeqNum(std::stoull(query.getValue(0, 1)));
106
+ m_cache.setNextSenderMsgSeqNum(std::stoull(query.getValue(0, 2)));
107
+ } else {
108
+ UtcTimeStamp time = m_cache.getCreationTime();
109
+ char sqlTime[100];
110
+ int year, month, day, hour, minute, second, millis;
111
+ time.getYMD(year, month, day);
112
+ time.getHMS(hour, minute, second, millis);
113
+ STRING_SPRINTF(sqlTime, "%d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second);
114
+ std::stringstream queryString2;
115
+ queryString2 << "INSERT INTO quickfix.sessions (beginstring, sendercompid, targetcompid, session_qualifier,"
116
+ << "creation_time, incoming_seqnum, outgoing_seqnum) VALUES("
117
+ << "'" << m_sessionID.getBeginString().getValue() << "',"
118
+ << "'" << m_sessionID.getSenderCompID().getValue() << "',"
119
+ << "'" << m_sessionID.getTargetCompID().getValue() << "',"
120
+ << "'" << m_sessionID.getSessionQualifier() << "',"
121
+ << "'" << sqlTime << "'," << m_cache.getNextTargetMsgSeqNum() << ","
122
+ << m_cache.getNextSenderMsgSeqNum() << ")";
123
+
124
+ PostgreSQLQuery query2(queryString2.str());
125
+ if (!m_pConnection->execute(query2)) {
126
+ throw ConfigError("Unable to create session in database");
127
+ }
128
+ }
129
+ }
130
+
131
+ MessageStore *PostgreSQLStoreFactory::create(const UtcTimeStamp &now, const SessionID &sessionID) {
132
+ if (m_useSettings) {
133
+ return create(now, sessionID, m_settings.get(sessionID));
134
+ } else if (m_useDictionary) {
135
+ return create(now, sessionID, m_dictionary);
136
+ } else {
137
+ DatabaseConnectionID id(m_database, m_user, m_password, m_host, m_port);
138
+ return new PostgreSQLStore(now, sessionID, id, m_connectionPoolPtr.get());
139
+ }
140
+ }
141
+
142
+ MessageStore *PostgreSQLStoreFactory::create(
143
+ const UtcTimeStamp &now,
144
+ const SessionID &sessionID,
145
+ const Dictionary &settings) {
146
+ std::string database = DEFAULT_DATABASE;
147
+ std::string user = DEFAULT_USER;
148
+ std::string password = DEFAULT_PASSWORD;
149
+ std::string host = DEFAULT_HOST;
150
+ short port = DEFAULT_PORT;
151
+
152
+ try {
153
+ database = settings.getString(POSTGRESQL_STORE_DATABASE);
154
+ } catch (ConfigError &) {}
155
+
156
+ try {
157
+ user = settings.getString(POSTGRESQL_STORE_USER);
158
+ } catch (ConfigError &) {}
159
+
160
+ try {
161
+ password = settings.getString(POSTGRESQL_STORE_PASSWORD);
162
+ } catch (ConfigError &) {}
163
+
164
+ try {
165
+ host = settings.getString(POSTGRESQL_STORE_HOST);
166
+ } catch (ConfigError &) {}
167
+
168
+ try {
169
+ port = (short)settings.getInt(POSTGRESQL_STORE_PORT);
170
+ } catch (ConfigError &) {}
171
+
172
+ DatabaseConnectionID id(database, user, password, host, port);
173
+ return new PostgreSQLStore(now, sessionID, id, m_connectionPoolPtr.get());
174
+ }
175
+
176
+ void PostgreSQLStoreFactory::destroy(MessageStore *pStore) { delete pStore; }
177
+
178
+ bool PostgreSQLStore::set(SEQNUM msgSeqNum, const std::string &msg) EXCEPT(IOException) {
179
+ char *msgCopy = new char[(msg.size() * 2) + 1];
180
+ PQescapeString(msgCopy, msg.c_str(), msg.size());
181
+
182
+ std::stringstream queryString;
183
+ queryString << "INSERT INTO quickfix.messages "
184
+ << "(beginstring, sendercompid, targetcompid, session_qualifier, msgseqnum, message) "
185
+ << "VALUES ("
186
+ << "'" << m_sessionID.getBeginString().getValue() << "',"
187
+ << "'" << m_sessionID.getSenderCompID().getValue() << "',"
188
+ << "'" << m_sessionID.getTargetCompID().getValue() << "',"
189
+ << "'" << m_sessionID.getSessionQualifier() << "'," << msgSeqNum << ","
190
+ << "'" << msgCopy << "')";
191
+
192
+ delete[] msgCopy;
193
+
194
+ PostgreSQLQuery query(queryString.str());
195
+ if (!m_pConnection->execute(query)) {
196
+ std::stringstream queryString2;
197
+ queryString2 << "UPDATE quickfix.messages SET message='" << msg << "' WHERE "
198
+ << "beginstring=" << "'" << m_sessionID.getBeginString().getValue() << "' and "
199
+ << "sendercompid=" << "'" << m_sessionID.getSenderCompID().getValue() << "' and "
200
+ << "targetcompid=" << "'" << m_sessionID.getTargetCompID().getValue() << "' and "
201
+ << "session_qualifier=" << "'" << m_sessionID.getSessionQualifier() << "' and "
202
+ << "msgseqnum=" << msgSeqNum;
203
+ PostgreSQLQuery query2(queryString2.str());
204
+ if (!m_pConnection->execute(query2)) {
205
+ query2.throwException();
206
+ }
207
+ }
208
+
209
+ return true;
210
+ }
211
+
212
+ void PostgreSQLStore::get(SEQNUM begin, SEQNUM end, std::vector<std::string> &result) const EXCEPT(IOException) {
213
+ result.clear();
214
+ std::stringstream queryString;
215
+ queryString << "SELECT message FROM quickfix.messages WHERE "
216
+ << "beginstring=" << "'" << m_sessionID.getBeginString().getValue() << "' and "
217
+ << "sendercompid=" << "'" << m_sessionID.getSenderCompID().getValue() << "' and "
218
+ << "targetcompid=" << "'" << m_sessionID.getTargetCompID().getValue() << "' and "
219
+ << "session_qualifier=" << "'" << m_sessionID.getSessionQualifier() << "' and "
220
+ << "msgseqnum>=" << begin << " and " << "msgseqnum<=" << end << " "
221
+ << "ORDER BY msgseqnum";
222
+
223
+ PostgreSQLQuery query(queryString.str());
224
+ if (!m_pConnection->execute(query)) {
225
+ query.throwException();
226
+ }
227
+
228
+ int rows = query.rows();
229
+ for (int row = 0; row < rows; row++) {
230
+ result.push_back(query.getValue(row, 0));
231
+ }
232
+ }
233
+
234
+ SEQNUM PostgreSQLStore::getNextSenderMsgSeqNum() const EXCEPT(IOException) { return m_cache.getNextSenderMsgSeqNum(); }
235
+
236
+ SEQNUM PostgreSQLStore::getNextTargetMsgSeqNum() const EXCEPT(IOException) { return m_cache.getNextTargetMsgSeqNum(); }
237
+
238
+ void PostgreSQLStore::setNextSenderMsgSeqNum(SEQNUM value) EXCEPT(IOException) {
239
+ std::stringstream queryString;
240
+ queryString << "UPDATE quickfix.sessions SET outgoing_seqnum=" << value << " WHERE "
241
+ << "beginstring=" << "'" << m_sessionID.getBeginString().getValue() << "' and "
242
+ << "sendercompid=" << "'" << m_sessionID.getSenderCompID().getValue() << "' and "
243
+ << "targetcompid=" << "'" << m_sessionID.getTargetCompID().getValue() << "' and "
244
+ << "session_qualifier=" << "'" << m_sessionID.getSessionQualifier() << "'";
245
+
246
+ PostgreSQLQuery query(queryString.str());
247
+ if (!m_pConnection->execute(query)) {
248
+ query.throwException();
249
+ }
250
+
251
+ m_cache.setNextSenderMsgSeqNum(value);
252
+ }
253
+
254
+ void PostgreSQLStore::setNextTargetMsgSeqNum(SEQNUM value) EXCEPT(IOException) {
255
+ std::stringstream queryString;
256
+ queryString << "UPDATE quickfix.sessions SET incoming_seqnum=" << value << " WHERE "
257
+ << "beginstring=" << "'" << m_sessionID.getBeginString().getValue() << "' and "
258
+ << "sendercompid=" << "'" << m_sessionID.getSenderCompID().getValue() << "' and "
259
+ << "targetcompid=" << "'" << m_sessionID.getTargetCompID().getValue() << "' and "
260
+ << "session_qualifier=" << "'" << m_sessionID.getSessionQualifier() << "'";
261
+
262
+ PostgreSQLQuery query(queryString.str());
263
+ if (!m_pConnection->execute(query)) {
264
+ query.throwException();
265
+ }
266
+
267
+ m_cache.setNextTargetMsgSeqNum(value);
268
+ }
269
+
270
+ void PostgreSQLStore::incrNextSenderMsgSeqNum() EXCEPT(IOException) {
271
+ m_cache.incrNextSenderMsgSeqNum();
272
+ setNextSenderMsgSeqNum(m_cache.getNextSenderMsgSeqNum());
273
+ }
274
+
275
+ void PostgreSQLStore::incrNextTargetMsgSeqNum() EXCEPT(IOException) {
276
+ m_cache.incrNextTargetMsgSeqNum();
277
+ setNextTargetMsgSeqNum(m_cache.getNextTargetMsgSeqNum());
278
+ }
279
+
280
+ UtcTimeStamp PostgreSQLStore::getCreationTime() const EXCEPT(IOException) { return m_cache.getCreationTime(); }
281
+
282
+ void PostgreSQLStore::reset(const UtcTimeStamp &now) EXCEPT(IOException) {
283
+ std::stringstream queryString;
284
+ queryString << "DELETE FROM quickfix.messages WHERE "
285
+ << "beginstring=" << "'" << m_sessionID.getBeginString().getValue() << "' and "
286
+ << "sendercompid=" << "'" << m_sessionID.getSenderCompID().getValue() << "' and "
287
+ << "targetcompid=" << "'" << m_sessionID.getTargetCompID().getValue() << "' and "
288
+ << "session_qualifier=" << "'" << m_sessionID.getSessionQualifier() << "'";
289
+
290
+ PostgreSQLQuery query(queryString.str());
291
+ if (!m_pConnection->execute(query)) {
292
+ query.throwException();
293
+ }
294
+
295
+ m_cache.reset(now);
296
+ UtcTimeStamp time = m_cache.getCreationTime();
297
+
298
+ int year, month, day, hour, minute, second, millis;
299
+ time.getYMD(year, month, day);
300
+ time.getHMS(hour, minute, second, millis);
301
+
302
+ char sqlTime[100];
303
+ STRING_SPRINTF(sqlTime, "%d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second);
304
+
305
+ std::stringstream queryString2;
306
+ queryString2 << "UPDATE quickfix.sessions SET creation_time='" << sqlTime << "', "
307
+ << "incoming_seqnum=" << m_cache.getNextTargetMsgSeqNum() << ", "
308
+ << "outgoing_seqnum=" << m_cache.getNextSenderMsgSeqNum() << " WHERE "
309
+ << "beginstring=" << "'" << m_sessionID.getBeginString().getValue() << "' and "
310
+ << "sendercompid=" << "'" << m_sessionID.getSenderCompID().getValue() << "' and "
311
+ << "targetcompid=" << "'" << m_sessionID.getTargetCompID().getValue() << "' and "
312
+ << "session_qualifier=" << "'" << m_sessionID.getSessionQualifier() << "'";
313
+
314
+ PostgreSQLQuery query2(queryString2.str());
315
+ if (!m_pConnection->execute(query2)) {
316
+ query2.throwException();
317
+ }
318
+ }
319
+
320
+ void PostgreSQLStore::refresh() EXCEPT(IOException) {
321
+ m_cache.reset(UtcTimeStamp::now());
322
+ populateCache();
323
+ }
324
+
325
+ } // namespace FIX
326
+
327
+ #endif
@@ -0,0 +1,160 @@
1
+ /* -*- C++ -*- */
2
+
3
+ /****************************************************************************
4
+ ** Copyright (c) 2001-2014
5
+ **
6
+ ** This file is part of the QuickFIX FIX Engine
7
+ **
8
+ ** This file may be distributed under the terms of the quickfixengine.org
9
+ ** license as defined by quickfixengine.org and appearing in the file
10
+ ** LICENSE included in the packaging of this file.
11
+ **
12
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14
+ **
15
+ ** See http://www.quickfixengine.org/LICENSE for licensing information.
16
+ **
17
+ ** Contact ask@quickfixengine.org if any conditions of this licensing are
18
+ ** not clear to you.
19
+ **
20
+ ****************************************************************************/
21
+
22
+ #ifndef FIX_POSTGRESQLSTORE_H
23
+ #define FIX_POSTGRESQLSTORE_H
24
+
25
+ #ifndef HAVE_POSTGRESQL
26
+ #error PostgreSQLStore.h included, but HAVE_POSTGRESQL not defined
27
+ #endif
28
+
29
+ #ifdef HAVE_POSTGRESQL
30
+
31
+ #ifdef _MSC_VER
32
+ #pragma warning(disable : 4503 4355 4786 4290)
33
+ #endif
34
+
35
+ #include "MessageStore.h"
36
+ #include "PostgreSQLConnection.h"
37
+ #include "SessionSettings.h"
38
+ #include <fstream>
39
+ #include <string>
40
+
41
+ namespace FIX {
42
+ /// Creates a PostgreSQL based implementation of MessageStore.
43
+ class PostgreSQLStoreFactory : public MessageStoreFactory {
44
+ public:
45
+ static const std::string DEFAULT_DATABASE;
46
+ static const std::string DEFAULT_USER;
47
+ static const std::string DEFAULT_PASSWORD;
48
+ static const std::string DEFAULT_HOST;
49
+ static const short DEFAULT_PORT;
50
+
51
+ PostgreSQLStoreFactory(const SessionSettings &settings)
52
+ : m_settings(settings),
53
+ m_useSettings(true),
54
+ m_useDictionary(false) {
55
+ bool poolConnections = false;
56
+ try {
57
+ poolConnections = settings.get().getBool(POSTGRESQL_STORE_USECONNECTIONPOOL);
58
+ } catch (ConfigError &) {}
59
+
60
+ m_connectionPoolPtr = PostgreSQLConnectionPoolPtr(new PostgreSQLConnectionPool(poolConnections));
61
+ }
62
+
63
+ PostgreSQLStoreFactory(const Dictionary &dictionary)
64
+ : m_dictionary(dictionary),
65
+ m_useSettings(false),
66
+ m_useDictionary(true) {
67
+ m_connectionPoolPtr = PostgreSQLConnectionPoolPtr(new PostgreSQLConnectionPool(false));
68
+ }
69
+
70
+ PostgreSQLStoreFactory(
71
+ const std::string &database,
72
+ const std::string &user,
73
+ const std::string &password,
74
+ const std::string &host,
75
+ short port)
76
+ : m_database(database),
77
+ m_user(user),
78
+ m_password(password),
79
+ m_host(host),
80
+ m_port(port),
81
+ m_useSettings(false),
82
+ m_useDictionary(false) {
83
+ m_connectionPoolPtr = PostgreSQLConnectionPoolPtr(new PostgreSQLConnectionPool(false));
84
+ }
85
+
86
+ PostgreSQLStoreFactory()
87
+ : m_database(DEFAULT_DATABASE),
88
+ m_user(DEFAULT_USER),
89
+ m_password(DEFAULT_PASSWORD),
90
+ m_host(DEFAULT_HOST),
91
+ m_port(DEFAULT_PORT),
92
+ m_useSettings(false),
93
+ m_useDictionary(false) {
94
+ m_connectionPoolPtr = PostgreSQLConnectionPoolPtr(new PostgreSQLConnectionPool(false));
95
+ }
96
+
97
+ MessageStore *create(const UtcTimeStamp &, const SessionID &);
98
+ void destroy(MessageStore *);
99
+
100
+ private:
101
+ MessageStore *create(const UtcTimeStamp &, const SessionID &, const Dictionary &);
102
+
103
+ PostgreSQLConnectionPoolPtr m_connectionPoolPtr;
104
+ SessionSettings m_settings;
105
+ Dictionary m_dictionary;
106
+ std::string m_database;
107
+ std::string m_user;
108
+ std::string m_password;
109
+ std::string m_host;
110
+ short m_port;
111
+ bool m_useSettings;
112
+ bool m_useDictionary;
113
+ };
114
+ /*! @} */
115
+
116
+ /// PostgreSQL based implementation of MessageStore.
117
+ class PostgreSQLStore : public MessageStore {
118
+ public:
119
+ PostgreSQLStore(
120
+ const UtcTimeStamp &now,
121
+ const SessionID &sessionID,
122
+ const DatabaseConnectionID &connection,
123
+ PostgreSQLConnectionPool *pool);
124
+ PostgreSQLStore(
125
+ const UtcTimeStamp &now,
126
+ const SessionID &sessionID,
127
+ const std::string &database,
128
+ const std::string &user,
129
+ const std::string &password,
130
+ const std::string &host,
131
+ short port);
132
+ ~PostgreSQLStore();
133
+
134
+ bool set(SEQNUM, const std::string &) EXCEPT(IOException);
135
+ void get(SEQNUM, SEQNUM, std::vector<std::string> &) const EXCEPT(IOException);
136
+
137
+ SEQNUM getNextSenderMsgSeqNum() const EXCEPT(IOException);
138
+ SEQNUM getNextTargetMsgSeqNum() const EXCEPT(IOException);
139
+ void setNextSenderMsgSeqNum(SEQNUM value) EXCEPT(IOException);
140
+ void setNextTargetMsgSeqNum(SEQNUM value) EXCEPT(IOException);
141
+ void incrNextSenderMsgSeqNum() EXCEPT(IOException);
142
+ void incrNextTargetMsgSeqNum() EXCEPT(IOException);
143
+
144
+ UtcTimeStamp getCreationTime() const EXCEPT(IOException);
145
+
146
+ void reset(const UtcTimeStamp &now) EXCEPT(IOException);
147
+ void refresh() EXCEPT(IOException);
148
+
149
+ private:
150
+ void populateCache();
151
+
152
+ MemoryStore m_cache;
153
+ PostgreSQLConnection *m_pConnection;
154
+ PostgreSQLConnectionPool *m_pConnectionPool;
155
+ SessionID m_sessionID;
156
+ };
157
+ } // namespace FIX
158
+
159
+ #endif // FIX_POSTGRESQLSTORE_H
160
+ #endif // HAVE_POSTGRESQL