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.
- checksums.yaml +7 -0
- data/ext/quickfix/Acceptor.cpp +257 -0
- data/ext/quickfix/Acceptor.h +127 -0
- data/ext/quickfix/Allocator.h +9 -0
- data/ext/quickfix/Application.h +137 -0
- data/ext/quickfix/DOMDocument.h +70 -0
- data/ext/quickfix/DataDictionary.cpp +679 -0
- data/ext/quickfix/DataDictionary.h +607 -0
- data/ext/quickfix/DataDictionaryProvider.cpp +66 -0
- data/ext/quickfix/DataDictionaryProvider.h +67 -0
- data/ext/quickfix/DatabaseConnectionID.h +98 -0
- data/ext/quickfix/DatabaseConnectionPool.h +84 -0
- data/ext/quickfix/Dictionary.cpp +157 -0
- data/ext/quickfix/Dictionary.h +89 -0
- data/ext/quickfix/Event.h +89 -0
- data/ext/quickfix/Except.h +39 -0
- data/ext/quickfix/Exceptions.h +257 -0
- data/ext/quickfix/Field.h +654 -0
- data/ext/quickfix/FieldConvertors.cpp +86 -0
- data/ext/quickfix/FieldConvertors.h +800 -0
- data/ext/quickfix/FieldMap.cpp +254 -0
- data/ext/quickfix/FieldMap.h +327 -0
- data/ext/quickfix/FieldNumbers.h +44 -0
- data/ext/quickfix/FieldTypes.cpp +62 -0
- data/ext/quickfix/FieldTypes.h +817 -0
- data/ext/quickfix/Fields.h +30 -0
- data/ext/quickfix/FileLog.cpp +176 -0
- data/ext/quickfix/FileLog.h +110 -0
- data/ext/quickfix/FileStore.cpp +369 -0
- data/ext/quickfix/FileStore.h +131 -0
- data/ext/quickfix/FixCommonFields.h +13 -0
- data/ext/quickfix/FixFieldNumbers.h +6132 -0
- data/ext/quickfix/FixFields.h +6133 -0
- data/ext/quickfix/FixValues.h +5790 -0
- data/ext/quickfix/Group.cpp +44 -0
- data/ext/quickfix/Group.h +78 -0
- data/ext/quickfix/HostDetailsProvider.cpp +79 -0
- data/ext/quickfix/HostDetailsProvider.h +44 -0
- data/ext/quickfix/HtmlBuilder.h +178 -0
- data/ext/quickfix/HttpConnection.cpp +914 -0
- data/ext/quickfix/HttpConnection.h +74 -0
- data/ext/quickfix/HttpMessage.cpp +229 -0
- data/ext/quickfix/HttpMessage.h +112 -0
- data/ext/quickfix/HttpParser.cpp +49 -0
- data/ext/quickfix/HttpParser.h +49 -0
- data/ext/quickfix/HttpServer.cpp +152 -0
- data/ext/quickfix/HttpServer.h +76 -0
- data/ext/quickfix/Initiator.cpp +310 -0
- data/ext/quickfix/Initiator.h +151 -0
- data/ext/quickfix/Log.cpp +71 -0
- data/ext/quickfix/Log.h +254 -0
- data/ext/quickfix/Message.cpp +617 -0
- data/ext/quickfix/Message.h +419 -0
- data/ext/quickfix/MessageCracker.h +171 -0
- data/ext/quickfix/MessageSorters.cpp +101 -0
- data/ext/quickfix/MessageSorters.h +185 -0
- data/ext/quickfix/MessageStore.cpp +182 -0
- data/ext/quickfix/MessageStore.h +164 -0
- data/ext/quickfix/Mutex.h +120 -0
- data/ext/quickfix/MySQLConnection.h +187 -0
- data/ext/quickfix/MySQLLog.cpp +262 -0
- data/ext/quickfix/MySQLLog.h +158 -0
- data/ext/quickfix/MySQLStore.cpp +323 -0
- data/ext/quickfix/MySQLStore.h +161 -0
- data/ext/quickfix/MySQLStubs.h +203 -0
- data/ext/quickfix/NullStore.cpp +40 -0
- data/ext/quickfix/NullStore.h +89 -0
- data/ext/quickfix/OdbcConnection.h +241 -0
- data/ext/quickfix/OdbcLog.cpp +230 -0
- data/ext/quickfix/OdbcLog.h +109 -0
- data/ext/quickfix/OdbcStore.cpp +313 -0
- data/ext/quickfix/OdbcStore.h +124 -0
- data/ext/quickfix/PUGIXML_DOMDocument.cpp +112 -0
- data/ext/quickfix/PUGIXML_DOMDocument.h +81 -0
- data/ext/quickfix/Parser.cpp +111 -0
- data/ext/quickfix/Parser.h +50 -0
- data/ext/quickfix/PostgreSQLConnection.h +163 -0
- data/ext/quickfix/PostgreSQLLog.cpp +263 -0
- data/ext/quickfix/PostgreSQLLog.h +157 -0
- data/ext/quickfix/PostgreSQLStore.cpp +327 -0
- data/ext/quickfix/PostgreSQLStore.h +160 -0
- data/ext/quickfix/PostgreSQLStubs.h +203 -0
- data/ext/quickfix/Queue.h +66 -0
- data/ext/quickfix/QuickfixRuby.cpp +131900 -0
- data/ext/quickfix/QuickfixRuby.h +56 -0
- data/ext/quickfix/Responder.h +41 -0
- data/ext/quickfix/SSLSocketAcceptor.cpp +409 -0
- data/ext/quickfix/SSLSocketAcceptor.h +186 -0
- data/ext/quickfix/SSLSocketConnection.cpp +434 -0
- data/ext/quickfix/SSLSocketConnection.h +221 -0
- data/ext/quickfix/SSLSocketInitiator.cpp +558 -0
- data/ext/quickfix/SSLSocketInitiator.h +203 -0
- data/ext/quickfix/SSLStubs.h +129 -0
- data/ext/quickfix/Session.cpp +1437 -0
- data/ext/quickfix/Session.h +343 -0
- data/ext/quickfix/SessionFactory.cpp +314 -0
- data/ext/quickfix/SessionFactory.h +84 -0
- data/ext/quickfix/SessionID.h +136 -0
- data/ext/quickfix/SessionSettings.cpp +165 -0
- data/ext/quickfix/SessionSettings.h +283 -0
- data/ext/quickfix/SessionState.h +260 -0
- data/ext/quickfix/Settings.cpp +160 -0
- data/ext/quickfix/Settings.h +56 -0
- data/ext/quickfix/SharedArray.h +274 -0
- data/ext/quickfix/SocketAcceptor.cpp +216 -0
- data/ext/quickfix/SocketAcceptor.h +77 -0
- data/ext/quickfix/SocketConnection.cpp +256 -0
- data/ext/quickfix/SocketConnection.h +102 -0
- data/ext/quickfix/SocketConnector.cpp +112 -0
- data/ext/quickfix/SocketConnector.h +76 -0
- data/ext/quickfix/SocketInitiator.cpp +241 -0
- data/ext/quickfix/SocketInitiator.h +76 -0
- data/ext/quickfix/SocketMonitor.h +26 -0
- data/ext/quickfix/SocketMonitor_UNIX.cpp +238 -0
- data/ext/quickfix/SocketMonitor_UNIX.h +101 -0
- data/ext/quickfix/SocketMonitor_WIN32.cpp +248 -0
- data/ext/quickfix/SocketMonitor_WIN32.h +99 -0
- data/ext/quickfix/SocketServer.cpp +163 -0
- data/ext/quickfix/SocketServer.h +100 -0
- data/ext/quickfix/ThreadedSSLSocketAcceptor.cpp +436 -0
- data/ext/quickfix/ThreadedSSLSocketAcceptor.h +209 -0
- data/ext/quickfix/ThreadedSSLSocketConnection.cpp +364 -0
- data/ext/quickfix/ThreadedSSLSocketConnection.h +191 -0
- data/ext/quickfix/ThreadedSSLSocketInitiator.cpp +434 -0
- data/ext/quickfix/ThreadedSSLSocketInitiator.h +193 -0
- data/ext/quickfix/ThreadedSocketAcceptor.cpp +242 -0
- data/ext/quickfix/ThreadedSocketAcceptor.h +95 -0
- data/ext/quickfix/ThreadedSocketConnection.cpp +227 -0
- data/ext/quickfix/ThreadedSocketConnection.h +89 -0
- data/ext/quickfix/ThreadedSocketInitiator.cpp +238 -0
- data/ext/quickfix/ThreadedSocketInitiator.h +78 -0
- data/ext/quickfix/TimeRange.cpp +227 -0
- data/ext/quickfix/TimeRange.h +215 -0
- data/ext/quickfix/Utility.cpp +639 -0
- data/ext/quickfix/Utility.h +255 -0
- data/ext/quickfix/UtilitySSL.cpp +1612 -0
- data/ext/quickfix/UtilitySSL.h +274 -0
- data/ext/quickfix/Values.h +63 -0
- data/ext/quickfix/config-all.h +10 -0
- data/ext/quickfix/config.h +10 -0
- data/ext/quickfix/config_unix.h +178 -0
- data/ext/quickfix/config_windows.h +0 -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 +374 -0
- data/ext/quickfix/extconf.rb +76 -0
- data/ext/quickfix/index.h +37 -0
- data/ext/quickfix/pugiconfig.hpp +77 -0
- data/ext/quickfix/pugixml.cpp +13237 -0
- data/ext/quickfix/pugixml.hpp +1516 -0
- data/ext/quickfix/scope_guard.hpp +215 -0
- data/ext/quickfix/stdint_msvc.h +254 -0
- data/ext/quickfix/strptime.h +7 -0
- data/lib/2.4/quickfix.so +0 -0
- data/lib/2.5/quickfix.so +0 -0
- data/lib/2.6/quickfix.so +0 -0
- data/lib/2.7/quickfix.so +0 -0
- data/lib/3.0/quickfix.so +0 -0
- data/lib/3.1/quickfix.so +0 -0
- data/lib/3.2/quickfix.so +0 -0
- data/lib/3.3/quickfix.so +0 -0
- data/lib/3.4/quickfix.so +0 -0
- data/lib/quickfix40.rb +274 -0
- data/lib/quickfix41.rb +351 -0
- data/lib/quickfix42.rb +1184 -0
- data/lib/quickfix43.rb +3504 -0
- data/lib/quickfix44.rb +14040 -0
- data/lib/quickfix50.rb +20051 -0
- data/lib/quickfix50sp1.rb +23596 -0
- data/lib/quickfix50sp2.rb +412444 -0
- data/lib/quickfix_fields.rb +79393 -0
- data/lib/quickfix_ruby.rb +82 -0
- data/lib/quickfixt11.rb +65 -0
- data/spec/FIX40.xml +862 -0
- data/spec/FIX41.xml +1282 -0
- data/spec/FIX42.xml +2743 -0
- data/spec/FIX43.xml +4230 -0
- data/spec/FIX44.xml +6600 -0
- data/spec/FIX50.xml +8142 -0
- data/spec/FIX50SP1.xml +9506 -0
- data/spec/FIX50SP2.xml +26069 -0
- data/spec/FIXT11.xml +252 -0
- data/test/DataDictionaryTestCase.rb +268 -0
- data/test/DictionaryTestCase.rb +112 -0
- data/test/FieldBaseTestCase.rb +24 -0
- data/test/MessageStoreTestCase.rb +19 -0
- data/test/MessageTestCase.rb +368 -0
- data/test/SessionSettingsTestCase.rb +41 -0
- metadata +247 -0
@@ -0,0 +1,111 @@
|
|
1
|
+
/****************************************************************************
|
2
|
+
** Copyright (c) 2001-2014
|
3
|
+
**
|
4
|
+
** This file is part of the QuickFIX FIX Engine
|
5
|
+
**
|
6
|
+
** This file may be distributed under the terms of the quickfixengine.org
|
7
|
+
** license as defined by quickfixengine.org and appearing in the file
|
8
|
+
** LICENSE included in the packaging of this file.
|
9
|
+
**
|
10
|
+
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
11
|
+
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
+
**
|
13
|
+
** See http://www.quickfixengine.org/LICENSE for licensing information.
|
14
|
+
**
|
15
|
+
** Contact ask@quickfixengine.org if any conditions of this licensing are
|
16
|
+
** not clear to you.
|
17
|
+
**
|
18
|
+
****************************************************************************/
|
19
|
+
|
20
|
+
#ifdef _MSC_VER
|
21
|
+
#include "stdafx.h"
|
22
|
+
#else
|
23
|
+
#include "config.h"
|
24
|
+
#endif
|
25
|
+
|
26
|
+
#include "FieldConvertors.h"
|
27
|
+
#include "Parser.h"
|
28
|
+
#include "Utility.h"
|
29
|
+
#include <algorithm>
|
30
|
+
|
31
|
+
namespace FIX {
|
32
|
+
bool Parser::extractLength(int &length, std::string::size_type &pos, const std::string &buffer)
|
33
|
+
EXCEPT(MessageParseError) {
|
34
|
+
if (!buffer.size()) {
|
35
|
+
return false;
|
36
|
+
}
|
37
|
+
|
38
|
+
std::string::size_type startPos = buffer.find("\0019=", 0);
|
39
|
+
if (startPos == std::string::npos) {
|
40
|
+
return false;
|
41
|
+
}
|
42
|
+
startPos += 3;
|
43
|
+
std::string::size_type endPos = buffer.find("\001", startPos);
|
44
|
+
if (endPos == std::string::npos) {
|
45
|
+
return false;
|
46
|
+
}
|
47
|
+
|
48
|
+
std::string strLength(buffer, startPos, endPos - startPos);
|
49
|
+
|
50
|
+
try {
|
51
|
+
length = IntConvertor::convert(strLength);
|
52
|
+
if (length < 0) {
|
53
|
+
throw MessageParseError();
|
54
|
+
}
|
55
|
+
} catch (FieldConvertError &) {
|
56
|
+
throw MessageParseError();
|
57
|
+
}
|
58
|
+
|
59
|
+
pos = endPos + 1;
|
60
|
+
return true;
|
61
|
+
}
|
62
|
+
|
63
|
+
bool Parser::readFixMessage(std::string &str) EXCEPT(MessageParseError) {
|
64
|
+
std::string::size_type pos = 0;
|
65
|
+
|
66
|
+
if (m_buffer.length() < 2) {
|
67
|
+
return false;
|
68
|
+
}
|
69
|
+
pos = m_buffer.find("8=");
|
70
|
+
if (pos == std::string::npos) {
|
71
|
+
return false;
|
72
|
+
}
|
73
|
+
m_buffer.erase(0, pos);
|
74
|
+
|
75
|
+
int length = 0;
|
76
|
+
|
77
|
+
try {
|
78
|
+
if (extractLength(length, pos, m_buffer)) {
|
79
|
+
pos += length;
|
80
|
+
if (m_buffer.size() < pos) {
|
81
|
+
return false;
|
82
|
+
}
|
83
|
+
|
84
|
+
pos = m_buffer.find("\00110=", pos - 1);
|
85
|
+
if (pos == std::string::npos) {
|
86
|
+
return false;
|
87
|
+
}
|
88
|
+
pos += 4;
|
89
|
+
pos = m_buffer.find("\001", pos);
|
90
|
+
if (pos == std::string::npos) {
|
91
|
+
return false;
|
92
|
+
}
|
93
|
+
pos += 1;
|
94
|
+
|
95
|
+
str.assign(m_buffer, 0, pos);
|
96
|
+
m_buffer.erase(0, pos);
|
97
|
+
return true;
|
98
|
+
}
|
99
|
+
} catch (MessageParseError &e) {
|
100
|
+
if (length > 0) {
|
101
|
+
m_buffer.erase(0, pos + length);
|
102
|
+
} else {
|
103
|
+
m_buffer.erase();
|
104
|
+
}
|
105
|
+
|
106
|
+
throw e;
|
107
|
+
}
|
108
|
+
|
109
|
+
return false;
|
110
|
+
}
|
111
|
+
} // namespace FIX
|
@@ -0,0 +1,50 @@
|
|
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_PARSER_H
|
23
|
+
#define FIX_PARSER_H
|
24
|
+
|
25
|
+
#ifdef _MSC_VER
|
26
|
+
#pragma warning(disable : 4503 4355 4786 4290)
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#include "Exceptions.h"
|
30
|
+
#include <iostream>
|
31
|
+
#include <string>
|
32
|
+
|
33
|
+
namespace FIX {
|
34
|
+
/// Parses %FIX messages off an input stream.
|
35
|
+
class Parser {
|
36
|
+
public:
|
37
|
+
Parser() {}
|
38
|
+
~Parser() {}
|
39
|
+
|
40
|
+
bool extractLength(int &length, std::string::size_type &pos, const std::string &buffer) EXCEPT(MessageParseError);
|
41
|
+
bool readFixMessage(std::string &str) EXCEPT(MessageParseError);
|
42
|
+
|
43
|
+
void addToStream(const char *str, size_t len) { m_buffer.append(str, len); }
|
44
|
+
void addToStream(const std::string &str) { m_buffer.append(str); }
|
45
|
+
|
46
|
+
private:
|
47
|
+
std::string m_buffer;
|
48
|
+
};
|
49
|
+
} // namespace FIX
|
50
|
+
#endif // FIX_PARSER_H
|
@@ -0,0 +1,163 @@
|
|
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_POSTGRESQLCONNECTION_H
|
23
|
+
#define FIX_POSTGRESQLCONNECTION_H
|
24
|
+
|
25
|
+
#ifndef HAVE_POSTGRESQL
|
26
|
+
#error PostgreSQLConnection.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
|
+
#pragma comment(lib, "libpq")
|
34
|
+
#endif
|
35
|
+
|
36
|
+
#include "DatabaseConnectionID.h"
|
37
|
+
#include "DatabaseConnectionPool.h"
|
38
|
+
#include "Mutex.h"
|
39
|
+
#include <libpq-fe.h>
|
40
|
+
|
41
|
+
namespace FIX {
|
42
|
+
class PostgreSQLQuery {
|
43
|
+
public:
|
44
|
+
PostgreSQLQuery(const std::string &query)
|
45
|
+
: m_result(0),
|
46
|
+
m_query(query) {}
|
47
|
+
|
48
|
+
~PostgreSQLQuery() {
|
49
|
+
if (m_result) {
|
50
|
+
PQclear(m_result);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
bool execute(PGconn *pConnection) {
|
55
|
+
int retry = 0;
|
56
|
+
|
57
|
+
do {
|
58
|
+
if (m_result) {
|
59
|
+
PQclear(m_result);
|
60
|
+
}
|
61
|
+
m_result = PQexec(pConnection, m_query.c_str());
|
62
|
+
m_status = PQresultStatus(m_result);
|
63
|
+
if (success()) {
|
64
|
+
return true;
|
65
|
+
}
|
66
|
+
PQreset(pConnection);
|
67
|
+
retry++;
|
68
|
+
} while (retry <= 1);
|
69
|
+
return success();
|
70
|
+
}
|
71
|
+
|
72
|
+
bool success() { return m_status == PGRES_TUPLES_OK || m_status == PGRES_COMMAND_OK; }
|
73
|
+
|
74
|
+
int rows() { return PQntuples(m_result); }
|
75
|
+
|
76
|
+
char *reason() { return PQresultErrorMessage(m_result); }
|
77
|
+
|
78
|
+
char *getValue(int row, int column) { return PQgetvalue(m_result, row, column); }
|
79
|
+
|
80
|
+
void throwException() EXCEPT(IOException) {
|
81
|
+
if (!success()) {
|
82
|
+
throw IOException("Query failed [" + m_query + "] ");
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
private:
|
87
|
+
PGresult *m_result;
|
88
|
+
ExecStatusType m_status;
|
89
|
+
std::string m_query;
|
90
|
+
};
|
91
|
+
|
92
|
+
class PostgreSQLConnection {
|
93
|
+
public:
|
94
|
+
PostgreSQLConnection(const DatabaseConnectionID &id)
|
95
|
+
: m_connectionID(id) {
|
96
|
+
connect();
|
97
|
+
}
|
98
|
+
|
99
|
+
PostgreSQLConnection(
|
100
|
+
const std::string &database,
|
101
|
+
const std::string &user,
|
102
|
+
const std::string &password,
|
103
|
+
const std::string &host,
|
104
|
+
short port)
|
105
|
+
: m_connectionID(database, user, password, host, port) {
|
106
|
+
connect();
|
107
|
+
}
|
108
|
+
|
109
|
+
~PostgreSQLConnection() {
|
110
|
+
if (m_pConnection) {
|
111
|
+
PQfinish(m_pConnection);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
const DatabaseConnectionID &connectionID() { return m_connectionID; }
|
116
|
+
|
117
|
+
bool connected() {
|
118
|
+
Locker locker(m_mutex);
|
119
|
+
return PQstatus(m_pConnection) == CONNECTION_OK;
|
120
|
+
}
|
121
|
+
|
122
|
+
bool reconnect() {
|
123
|
+
Locker locker(m_mutex);
|
124
|
+
PQreset(m_pConnection);
|
125
|
+
return connected();
|
126
|
+
}
|
127
|
+
|
128
|
+
bool execute(PostgreSQLQuery &pQuery) {
|
129
|
+
Locker locker(m_mutex);
|
130
|
+
return pQuery.execute(m_pConnection);
|
131
|
+
}
|
132
|
+
|
133
|
+
private:
|
134
|
+
void connect() {
|
135
|
+
short port = m_connectionID.getPort();
|
136
|
+
|
137
|
+
m_pConnection = PQsetdbLogin(
|
138
|
+
m_connectionID.getHost().c_str(),
|
139
|
+
port == 0 ? "" : IntConvertor::convert(port).c_str(),
|
140
|
+
"",
|
141
|
+
"",
|
142
|
+
m_connectionID.getDatabase().c_str(),
|
143
|
+
m_connectionID.getUser().c_str(),
|
144
|
+
m_connectionID.getPassword().c_str());
|
145
|
+
|
146
|
+
if (!connected()) {
|
147
|
+
throw ConfigError(
|
148
|
+
"Unable to connect to postgres database '" + m_connectionID.getDatabase() + "': " + m_connectionID.getUser()
|
149
|
+
+ '@' + m_connectionID.getHost() + ":" + std::to_string(port));
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
PGconn *m_pConnection;
|
154
|
+
DatabaseConnectionID m_connectionID;
|
155
|
+
Mutex m_mutex;
|
156
|
+
};
|
157
|
+
|
158
|
+
typedef DatabaseConnectionPool<PostgreSQLConnection> PostgreSQLConnectionPool;
|
159
|
+
typedef std::unique_ptr<PostgreSQLConnectionPool> PostgreSQLConnectionPoolPtr;
|
160
|
+
} // namespace FIX
|
161
|
+
|
162
|
+
#endif // FIX_POSTGRESQLCONNECTION_H
|
163
|
+
#endif // HAVE_POSTGRESQL
|
@@ -0,0 +1,263 @@
|
|
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 "PostgreSQLLog.h"
|
29
|
+
#include "SessionID.h"
|
30
|
+
#include "SessionSettings.h"
|
31
|
+
#include "Utility.h"
|
32
|
+
#include "strptime.h"
|
33
|
+
#include <fstream>
|
34
|
+
|
35
|
+
namespace FIX {
|
36
|
+
|
37
|
+
const std::string PostgreSQLLogFactory::DEFAULT_DATABASE = "quickfix";
|
38
|
+
const std::string PostgreSQLLogFactory::DEFAULT_USER = "postgres";
|
39
|
+
const std::string PostgreSQLLogFactory::DEFAULT_PASSWORD = "";
|
40
|
+
const std::string PostgreSQLLogFactory::DEFAULT_HOST = "localhost";
|
41
|
+
const short PostgreSQLLogFactory::DEFAULT_PORT = 0;
|
42
|
+
|
43
|
+
PostgreSQLLog::PostgreSQLLog(const SessionID &s, const DatabaseConnectionID &d, PostgreSQLConnectionPool *p)
|
44
|
+
: m_pConnectionPool(p) {
|
45
|
+
init();
|
46
|
+
m_pSessionID = new SessionID(s);
|
47
|
+
m_pConnection = m_pConnectionPool->create(d);
|
48
|
+
}
|
49
|
+
|
50
|
+
PostgreSQLLog::PostgreSQLLog(const DatabaseConnectionID &d, PostgreSQLConnectionPool *p)
|
51
|
+
: m_pConnectionPool(p),
|
52
|
+
m_pSessionID(0) {
|
53
|
+
init();
|
54
|
+
m_pConnection = m_pConnectionPool->create(d);
|
55
|
+
}
|
56
|
+
|
57
|
+
PostgreSQLLog::PostgreSQLLog(
|
58
|
+
const SessionID &s,
|
59
|
+
const std::string &database,
|
60
|
+
const std::string &user,
|
61
|
+
const std::string &password,
|
62
|
+
const std::string &host,
|
63
|
+
short port)
|
64
|
+
: m_pConnectionPool(0) {
|
65
|
+
init();
|
66
|
+
m_pSessionID = new SessionID(s);
|
67
|
+
m_pConnection = new PostgreSQLConnection(database, user, password, host, port);
|
68
|
+
}
|
69
|
+
|
70
|
+
PostgreSQLLog::PostgreSQLLog(
|
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_pConnectionPool(0),
|
77
|
+
m_pSessionID(0) {
|
78
|
+
init();
|
79
|
+
m_pConnection = new PostgreSQLConnection(database, user, password, host, port);
|
80
|
+
}
|
81
|
+
|
82
|
+
void PostgreSQLLog::init() {
|
83
|
+
setIncomingTable("messages_log");
|
84
|
+
setOutgoingTable("messages_log");
|
85
|
+
setEventTable("event_log");
|
86
|
+
}
|
87
|
+
|
88
|
+
PostgreSQLLog::~PostgreSQLLog() {
|
89
|
+
if (m_pConnectionPool) {
|
90
|
+
m_pConnectionPool->destroy(m_pConnection);
|
91
|
+
} else {
|
92
|
+
delete m_pConnection;
|
93
|
+
}
|
94
|
+
delete m_pSessionID;
|
95
|
+
}
|
96
|
+
|
97
|
+
Log *PostgreSQLLogFactory::create() {
|
98
|
+
std::string database;
|
99
|
+
std::string user;
|
100
|
+
std::string password;
|
101
|
+
std::string host;
|
102
|
+
short port;
|
103
|
+
|
104
|
+
init(m_settings.get(), database, user, password, host, port);
|
105
|
+
DatabaseConnectionID id(database, user, password, host, port);
|
106
|
+
PostgreSQLLog *result = new PostgreSQLLog(id, m_connectionPoolPtr.get());
|
107
|
+
initLog(m_settings.get(), *result);
|
108
|
+
return result;
|
109
|
+
}
|
110
|
+
|
111
|
+
Log *PostgreSQLLogFactory::create(const SessionID &s) {
|
112
|
+
std::string database;
|
113
|
+
std::string user;
|
114
|
+
std::string password;
|
115
|
+
std::string host;
|
116
|
+
short port;
|
117
|
+
|
118
|
+
Dictionary settings;
|
119
|
+
if (m_settings.has(s)) {
|
120
|
+
settings = m_settings.get(s);
|
121
|
+
}
|
122
|
+
|
123
|
+
init(settings, database, user, password, host, port);
|
124
|
+
DatabaseConnectionID id(database, user, password, host, port);
|
125
|
+
PostgreSQLLog *result = new PostgreSQLLog(s, id, m_connectionPoolPtr.get());
|
126
|
+
initLog(settings, *result);
|
127
|
+
return result;
|
128
|
+
}
|
129
|
+
|
130
|
+
void PostgreSQLLogFactory::init(
|
131
|
+
const Dictionary &settings,
|
132
|
+
std::string &database,
|
133
|
+
std::string &user,
|
134
|
+
std::string &password,
|
135
|
+
std::string &host,
|
136
|
+
short &port) {
|
137
|
+
database = DEFAULT_DATABASE;
|
138
|
+
user = DEFAULT_USER;
|
139
|
+
password = DEFAULT_PASSWORD;
|
140
|
+
host = DEFAULT_HOST;
|
141
|
+
port = DEFAULT_PORT;
|
142
|
+
|
143
|
+
if (m_useSettings) {
|
144
|
+
try {
|
145
|
+
database = settings.getString(POSTGRESQL_LOG_DATABASE);
|
146
|
+
} catch (ConfigError &) {}
|
147
|
+
|
148
|
+
try {
|
149
|
+
user = settings.getString(POSTGRESQL_LOG_USER);
|
150
|
+
} catch (ConfigError &) {}
|
151
|
+
|
152
|
+
try {
|
153
|
+
password = settings.getString(POSTGRESQL_LOG_PASSWORD);
|
154
|
+
} catch (ConfigError &) {}
|
155
|
+
|
156
|
+
try {
|
157
|
+
host = settings.getString(POSTGRESQL_LOG_HOST);
|
158
|
+
} catch (ConfigError &) {}
|
159
|
+
|
160
|
+
try {
|
161
|
+
port = (short)settings.getInt(POSTGRESQL_LOG_PORT);
|
162
|
+
} catch (ConfigError &) {}
|
163
|
+
} else {
|
164
|
+
database = m_database;
|
165
|
+
user = m_user;
|
166
|
+
password = m_password;
|
167
|
+
host = m_host;
|
168
|
+
port = m_port;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
172
|
+
void PostgreSQLLogFactory::initLog(const Dictionary &settings, PostgreSQLLog &log) {
|
173
|
+
try {
|
174
|
+
log.setIncomingTable(settings.getString(POSTGRESQL_LOG_INCOMING_TABLE));
|
175
|
+
} catch (ConfigError &) {}
|
176
|
+
|
177
|
+
try {
|
178
|
+
log.setOutgoingTable(settings.getString(POSTGRESQL_LOG_OUTGOING_TABLE));
|
179
|
+
} catch (ConfigError &) {}
|
180
|
+
|
181
|
+
try {
|
182
|
+
log.setEventTable(settings.getString(POSTGRESQL_LOG_EVENT_TABLE));
|
183
|
+
} catch (ConfigError &) {}
|
184
|
+
}
|
185
|
+
|
186
|
+
void PostgreSQLLogFactory::destroy(Log *pLog) { delete pLog; }
|
187
|
+
|
188
|
+
void PostgreSQLLog::clear() {
|
189
|
+
std::stringstream whereClause;
|
190
|
+
|
191
|
+
whereClause << "WHERE ";
|
192
|
+
|
193
|
+
if (m_pSessionID) {
|
194
|
+
whereClause << "BeginString = '" << m_pSessionID->getBeginString().getValue() << "' "
|
195
|
+
<< "AND SenderCompID = '" << m_pSessionID->getSenderCompID().getValue() << "' "
|
196
|
+
<< "AND TargetCompID = '" << m_pSessionID->getTargetCompID().getValue() << "' ";
|
197
|
+
|
198
|
+
if (m_pSessionID->getSessionQualifier().size()) {
|
199
|
+
whereClause << "AND SessionQualifier = '" << m_pSessionID->getSessionQualifier() << "'";
|
200
|
+
}
|
201
|
+
} else {
|
202
|
+
whereClause << "BeginString = NULL AND SenderCompID = NULL && TargetCompID = NULL";
|
203
|
+
}
|
204
|
+
|
205
|
+
std::stringstream incomingQuery;
|
206
|
+
std::stringstream outgoingQuery;
|
207
|
+
std::stringstream eventQuery;
|
208
|
+
|
209
|
+
incomingQuery << "DELETE FROM " << m_incomingTable << " " << whereClause.str();
|
210
|
+
outgoingQuery << "DELETE FROM " << m_outgoingTable << " " << whereClause.str();
|
211
|
+
eventQuery << "DELETE FROM " << m_eventTable << " " << whereClause.str();
|
212
|
+
|
213
|
+
PostgreSQLQuery incoming(incomingQuery.str());
|
214
|
+
PostgreSQLQuery outgoing(outgoingQuery.str());
|
215
|
+
PostgreSQLQuery event(eventQuery.str());
|
216
|
+
m_pConnection->execute(incoming);
|
217
|
+
m_pConnection->execute(outgoing);
|
218
|
+
m_pConnection->execute(event);
|
219
|
+
}
|
220
|
+
|
221
|
+
void PostgreSQLLog::backup() {}
|
222
|
+
|
223
|
+
void PostgreSQLLog::insert(const std::string &table, const std::string value) {
|
224
|
+
UtcTimeStamp time = UtcTimeStamp::now();
|
225
|
+
int year, month, day, hour, minute, second, millis;
|
226
|
+
time.getYMD(year, month, day);
|
227
|
+
time.getHMS(hour, minute, second, millis);
|
228
|
+
|
229
|
+
char sqlTime[100];
|
230
|
+
STRING_SPRINTF(sqlTime, "%d-%02d-%02d %02d:%02d:%02d.%03d", year, month, day, hour, minute, second, millis);
|
231
|
+
|
232
|
+
char *valueCopy = new char[(value.size() * 2) + 1];
|
233
|
+
PQescapeString(valueCopy, value.c_str(), value.size());
|
234
|
+
|
235
|
+
std::stringstream queryString;
|
236
|
+
queryString << "INSERT INTO " << table << " "
|
237
|
+
<< "(time, beginstring, sendercompid, targetcompid, session_qualifier, text) "
|
238
|
+
<< "VALUES ("
|
239
|
+
<< "'" << sqlTime << "',";
|
240
|
+
|
241
|
+
if (m_pSessionID) {
|
242
|
+
queryString << "'" << m_pSessionID->getBeginString().getValue() << "',"
|
243
|
+
<< "'" << m_pSessionID->getSenderCompID().getValue() << "',"
|
244
|
+
<< "'" << m_pSessionID->getTargetCompID().getValue() << "',";
|
245
|
+
if (m_pSessionID->getSessionQualifier() == "") {
|
246
|
+
queryString << "NULL" << ",";
|
247
|
+
} else {
|
248
|
+
queryString << "'" << m_pSessionID->getSessionQualifier() << "',";
|
249
|
+
}
|
250
|
+
} else {
|
251
|
+
queryString << "NULL, NULL, NULL, NULL, ";
|
252
|
+
}
|
253
|
+
|
254
|
+
queryString << "'" << valueCopy << "')";
|
255
|
+
delete[] valueCopy;
|
256
|
+
|
257
|
+
PostgreSQLQuery query(queryString.str());
|
258
|
+
m_pConnection->execute(query);
|
259
|
+
}
|
260
|
+
|
261
|
+
} // namespace FIX
|
262
|
+
|
263
|
+
#endif // HAVE_POSTGRESQL
|