quickfix_ruby 1.14.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/quickfix/Acceptor.cpp +248 -0
- data/ext/quickfix/Acceptor.h +127 -0
- data/ext/quickfix/Allocator.h +9 -0
- data/ext/quickfix/Application.h +127 -0
- data/ext/quickfix/AtomicCount.h +109 -0
- data/ext/quickfix/DOMDocument.h +74 -0
- data/ext/quickfix/DataDictionary.cpp +618 -0
- data/ext/quickfix/DataDictionary.h +539 -0
- data/ext/quickfix/DataDictionaryProvider.cpp +71 -0
- data/ext/quickfix/DataDictionaryProvider.h +70 -0
- data/ext/quickfix/DatabaseConnectionID.h +105 -0
- data/ext/quickfix/DatabaseConnectionPool.h +91 -0
- data/ext/quickfix/Dictionary.cpp +162 -0
- data/ext/quickfix/Dictionary.h +94 -0
- data/ext/quickfix/Event.h +95 -0
- data/ext/quickfix/Exceptions.h +299 -0
- data/ext/quickfix/Field.h +672 -0
- data/ext/quickfix/FieldConvertors.h +863 -0
- data/ext/quickfix/FieldMap.cpp +238 -0
- data/ext/quickfix/FieldMap.h +244 -0
- data/ext/quickfix/FieldNumbers.h +46 -0
- data/ext/quickfix/FieldTypes.cpp +64 -0
- data/ext/quickfix/FieldTypes.h +698 -0
- data/ext/quickfix/Fields.h +31 -0
- data/ext/quickfix/FileLog.cpp +200 -0
- data/ext/quickfix/FileLog.h +112 -0
- data/ext/quickfix/FileStore.cpp +332 -0
- data/ext/quickfix/FileStore.h +129 -0
- data/ext/quickfix/FixFieldNumbers.h +1537 -0
- data/ext/quickfix/FixFields.h +1538 -0
- data/ext/quickfix/FixValues.h +3281 -0
- data/ext/quickfix/FlexLexer.h +188 -0
- data/ext/quickfix/Group.cpp +64 -0
- data/ext/quickfix/Group.h +73 -0
- data/ext/quickfix/HtmlBuilder.h +186 -0
- data/ext/quickfix/HttpConnection.cpp +739 -0
- data/ext/quickfix/HttpConnection.h +78 -0
- data/ext/quickfix/HttpMessage.cpp +149 -0
- data/ext/quickfix/HttpMessage.h +133 -0
- data/ext/quickfix/HttpParser.cpp +49 -0
- data/ext/quickfix/HttpParser.h +54 -0
- data/ext/quickfix/HttpServer.cpp +169 -0
- data/ext/quickfix/HttpServer.h +78 -0
- data/ext/quickfix/Initiator.cpp +289 -0
- data/ext/quickfix/Initiator.h +149 -0
- data/ext/quickfix/Log.cpp +77 -0
- data/ext/quickfix/Log.h +179 -0
- data/ext/quickfix/Message.cpp +580 -0
- data/ext/quickfix/Message.h +370 -0
- data/ext/quickfix/MessageCracker.h +188 -0
- data/ext/quickfix/MessageSorters.cpp +105 -0
- data/ext/quickfix/MessageSorters.h +156 -0
- data/ext/quickfix/MessageStore.cpp +146 -0
- data/ext/quickfix/MessageStore.h +174 -0
- data/ext/quickfix/Mutex.h +131 -0
- data/ext/quickfix/MySQLConnection.h +194 -0
- data/ext/quickfix/MySQLLog.cpp +275 -0
- data/ext/quickfix/MySQLLog.h +145 -0
- data/ext/quickfix/MySQLStore.cpp +331 -0
- data/ext/quickfix/MySQLStore.h +142 -0
- data/ext/quickfix/NullStore.cpp +54 -0
- data/ext/quickfix/NullStore.h +99 -0
- data/ext/quickfix/OdbcConnection.h +266 -0
- data/ext/quickfix/OdbcLog.cpp +252 -0
- data/ext/quickfix/OdbcLog.h +117 -0
- data/ext/quickfix/OdbcStore.cpp +338 -0
- data/ext/quickfix/OdbcStore.h +113 -0
- data/ext/quickfix/PUGIXML_DOMDocument.cpp +112 -0
- data/ext/quickfix/PUGIXML_DOMDocument.h +81 -0
- data/ext/quickfix/Parser.cpp +103 -0
- data/ext/quickfix/Parser.h +57 -0
- data/ext/quickfix/PostgreSQLConnection.h +176 -0
- data/ext/quickfix/PostgreSQLLog.cpp +276 -0
- data/ext/quickfix/PostgreSQLLog.h +144 -0
- data/ext/quickfix/PostgreSQLStore.cpp +334 -0
- data/ext/quickfix/PostgreSQLStore.h +141 -0
- data/ext/quickfix/Queue.h +75 -0
- data/ext/quickfix/QuickfixRuby.cpp +252066 -0
- data/ext/quickfix/QuickfixRuby.h +34 -0
- data/ext/quickfix/Responder.h +43 -0
- data/ext/quickfix/Session.cpp +1487 -0
- data/ext/quickfix/Session.h +335 -0
- data/ext/quickfix/SessionFactory.cpp +274 -0
- data/ext/quickfix/SessionFactory.h +86 -0
- data/ext/quickfix/SessionID.h +170 -0
- data/ext/quickfix/SessionSettings.cpp +189 -0
- data/ext/quickfix/SessionSettings.h +171 -0
- data/ext/quickfix/SessionState.h +231 -0
- data/ext/quickfix/Settings.cpp +100 -0
- data/ext/quickfix/Settings.h +53 -0
- data/ext/quickfix/SharedArray.h +150 -0
- data/ext/quickfix/SocketAcceptor.cpp +222 -0
- data/ext/quickfix/SocketAcceptor.h +75 -0
- data/ext/quickfix/SocketConnection.cpp +238 -0
- data/ext/quickfix/SocketConnection.h +103 -0
- data/ext/quickfix/SocketConnector.cpp +116 -0
- data/ext/quickfix/SocketConnector.h +67 -0
- data/ext/quickfix/SocketInitiator.cpp +260 -0
- data/ext/quickfix/SocketInitiator.h +81 -0
- data/ext/quickfix/SocketMonitor.cpp +335 -0
- data/ext/quickfix/SocketMonitor.h +111 -0
- data/ext/quickfix/SocketServer.cpp +177 -0
- data/ext/quickfix/SocketServer.h +100 -0
- data/ext/quickfix/ThreadedSocketAcceptor.cpp +258 -0
- data/ext/quickfix/ThreadedSocketAcceptor.h +98 -0
- data/ext/quickfix/ThreadedSocketConnection.cpp +209 -0
- data/ext/quickfix/ThreadedSocketConnection.h +82 -0
- data/ext/quickfix/ThreadedSocketInitiator.cpp +268 -0
- data/ext/quickfix/ThreadedSocketInitiator.h +84 -0
- data/ext/quickfix/TimeRange.cpp +173 -0
- data/ext/quickfix/TimeRange.h +258 -0
- data/ext/quickfix/Utility.cpp +537 -0
- data/ext/quickfix/Utility.h +219 -0
- data/ext/quickfix/Values.h +62 -0
- data/ext/quickfix/config.h +0 -0
- data/ext/quickfix/config_windows.h +0 -0
- data/ext/quickfix/extconf.rb +12 -0
- data/ext/quickfix/index.h +37 -0
- data/ext/quickfix/pugiconfig.hpp +72 -0
- data/ext/quickfix/pugixml.cpp +10765 -0
- data/ext/quickfix/pugixml.hpp +1341 -0
- data/ext/quickfix/strptime.h +7 -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 +10721 -0
- data/lib/quickfix50.rb +13426 -0
- data/lib/quickfix50sp1.rb +15629 -0
- data/lib/quickfix50sp2.rb +17068 -0
- data/lib/quickfix_fields.rb +19853 -0
- data/lib/quickfix_ruby.rb +82 -0
- data/lib/quickfixt11.rb +70 -0
- data/spec/FIX40.xml +862 -0
- data/spec/FIX41.xml +1285 -0
- data/spec/FIX42.xml +2746 -0
- data/spec/FIX43.xml +4229 -0
- data/spec/FIX44.xml +6596 -0
- data/spec/FIX50.xml +8137 -0
- data/spec/FIX50SP1.xml +9496 -0
- data/spec/FIX50SP2.xml +10011 -0
- data/spec/FIXT11.xml +313 -0
- data/test/test_DataDictionaryTestCase.rb +268 -0
- data/test/test_DictionaryTestCase.rb +112 -0
- data/test/test_FieldBaseTestCase.rb +24 -0
- data/test/test_MessageTestCase.rb +368 -0
- data/test/test_SessionSettingsTestCase.rb +41 -0
- metadata +193 -0
@@ -0,0 +1,103 @@
|
|
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 "Parser.h"
|
27
|
+
#include "Utility.h"
|
28
|
+
#include "FieldConvertors.h"
|
29
|
+
#include <algorithm>
|
30
|
+
|
31
|
+
namespace FIX
|
32
|
+
{
|
33
|
+
bool Parser::extractLength( int& length, std::string::size_type& pos,
|
34
|
+
const std::string& buffer )
|
35
|
+
throw( MessageParseError )
|
36
|
+
{
|
37
|
+
if( !buffer.size() ) return false;
|
38
|
+
|
39
|
+
std::string::size_type startPos = buffer.find( "\0019=", 0 );
|
40
|
+
if( startPos == std::string::npos ) return false;
|
41
|
+
startPos += 3;
|
42
|
+
std::string::size_type endPos = buffer.find( "\001", startPos );
|
43
|
+
if( endPos == std::string::npos ) return false;
|
44
|
+
|
45
|
+
std::string strLength( buffer, startPos, endPos - startPos );
|
46
|
+
|
47
|
+
try
|
48
|
+
{
|
49
|
+
length = IntConvertor::convert( strLength );
|
50
|
+
if( length < 0 ) throw MessageParseError();
|
51
|
+
}
|
52
|
+
catch( FieldConvertError& )
|
53
|
+
{ throw MessageParseError(); }
|
54
|
+
|
55
|
+
pos = endPos + 1;
|
56
|
+
return true;
|
57
|
+
}
|
58
|
+
|
59
|
+
bool Parser::readFixMessage( std::string& str )
|
60
|
+
throw( MessageParseError )
|
61
|
+
{
|
62
|
+
std::string::size_type pos = 0;
|
63
|
+
|
64
|
+
if( m_buffer.length() < 2 ) return false;
|
65
|
+
pos = m_buffer.find( "8=" );
|
66
|
+
if( pos == std::string::npos ) return false;
|
67
|
+
m_buffer.erase( 0, pos );
|
68
|
+
|
69
|
+
int length = 0;
|
70
|
+
|
71
|
+
try
|
72
|
+
{
|
73
|
+
if( extractLength(length, pos, m_buffer) )
|
74
|
+
{
|
75
|
+
pos += length;
|
76
|
+
if( m_buffer.size() < pos )
|
77
|
+
return false;
|
78
|
+
|
79
|
+
pos = m_buffer.find( "\00110=", pos-1 );
|
80
|
+
if( pos == std::string::npos ) return false;
|
81
|
+
pos += 4;
|
82
|
+
pos = m_buffer.find( "\001", pos );
|
83
|
+
if( pos == std::string::npos ) return false;
|
84
|
+
pos += 1;
|
85
|
+
|
86
|
+
str.assign( m_buffer, 0, pos );
|
87
|
+
m_buffer.erase( 0, pos );
|
88
|
+
return true;
|
89
|
+
}
|
90
|
+
}
|
91
|
+
catch( MessageParseError& e )
|
92
|
+
{
|
93
|
+
if( length > 0 )
|
94
|
+
m_buffer.erase( 0, pos + length );
|
95
|
+
else
|
96
|
+
m_buffer.erase();
|
97
|
+
|
98
|
+
throw e;
|
99
|
+
}
|
100
|
+
|
101
|
+
return false;
|
102
|
+
}
|
103
|
+
}
|
@@ -0,0 +1,57 @@
|
|
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
|
+
{
|
35
|
+
/// Parses %FIX messages off an input stream.
|
36
|
+
class Parser
|
37
|
+
{
|
38
|
+
public:
|
39
|
+
Parser() {}
|
40
|
+
~Parser() {}
|
41
|
+
|
42
|
+
bool extractLength( int& length, std::string::size_type& pos,
|
43
|
+
const std::string& buffer )
|
44
|
+
throw ( MessageParseError );
|
45
|
+
bool readFixMessage( std::string& str )
|
46
|
+
throw ( MessageParseError );
|
47
|
+
|
48
|
+
void addToStream( const char* str, size_t len )
|
49
|
+
{ m_buffer.append( str, len ); }
|
50
|
+
void addToStream( const std::string& str )
|
51
|
+
{ m_buffer.append( str ); }
|
52
|
+
|
53
|
+
private:
|
54
|
+
std::string m_buffer;
|
55
|
+
};
|
56
|
+
}
|
57
|
+
#endif //FIX_PARSER_H
|
@@ -0,0 +1,176 @@
|
|
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 HAVE_POSTGRESQL
|
23
|
+
#error PostgreSQLConnection.h included, but HAVE_POSTGRESQL not defined
|
24
|
+
#endif
|
25
|
+
|
26
|
+
#ifdef HAVE_POSTGRESQL
|
27
|
+
#ifndef FIX_POSTGRESQLCONNECTION_H
|
28
|
+
#define FIX_POSTGRESQLCONNECTION_H
|
29
|
+
|
30
|
+
#ifdef _MSC_VER
|
31
|
+
#pragma warning( disable : 4503 4355 4786 4290 )
|
32
|
+
#pragma comment( lib, "libpq" )
|
33
|
+
#endif
|
34
|
+
|
35
|
+
#include <libpq-fe.h>
|
36
|
+
#include "DatabaseConnectionID.h"
|
37
|
+
#include "DatabaseConnectionPool.h"
|
38
|
+
#include "Mutex.h"
|
39
|
+
|
40
|
+
namespace FIX
|
41
|
+
{
|
42
|
+
class PostgreSQLQuery
|
43
|
+
{
|
44
|
+
public:
|
45
|
+
PostgreSQLQuery( const std::string& query )
|
46
|
+
: m_result( 0 ), m_query( query )
|
47
|
+
{}
|
48
|
+
|
49
|
+
~PostgreSQLQuery()
|
50
|
+
{
|
51
|
+
if( m_result )
|
52
|
+
PQclear( m_result );
|
53
|
+
}
|
54
|
+
|
55
|
+
bool execute( PGconn* pConnection )
|
56
|
+
{
|
57
|
+
int retry = 0;
|
58
|
+
|
59
|
+
do
|
60
|
+
{
|
61
|
+
if( m_result ) PQclear( m_result );
|
62
|
+
m_result = PQexec( pConnection, m_query.c_str() );
|
63
|
+
m_status = PQresultStatus( m_result );
|
64
|
+
if( success() ) return true;
|
65
|
+
PQreset( pConnection );
|
66
|
+
retry++;
|
67
|
+
} while( retry <= 1 );
|
68
|
+
return success();
|
69
|
+
}
|
70
|
+
|
71
|
+
bool success()
|
72
|
+
{
|
73
|
+
return m_status == PGRES_TUPLES_OK
|
74
|
+
|| m_status == PGRES_COMMAND_OK;
|
75
|
+
}
|
76
|
+
|
77
|
+
int rows()
|
78
|
+
{
|
79
|
+
return PQntuples( m_result );
|
80
|
+
}
|
81
|
+
|
82
|
+
char* reason()
|
83
|
+
{
|
84
|
+
return PQresultErrorMessage( m_result );
|
85
|
+
}
|
86
|
+
|
87
|
+
char* getValue( int row, int column )
|
88
|
+
{
|
89
|
+
return PQgetvalue( m_result, row, column );
|
90
|
+
}
|
91
|
+
|
92
|
+
void throwException() throw( IOException )
|
93
|
+
{
|
94
|
+
if( !success() )
|
95
|
+
throw IOException( "Query failed [" + m_query + "] " );
|
96
|
+
}
|
97
|
+
|
98
|
+
private:
|
99
|
+
PGresult* m_result;
|
100
|
+
ExecStatusType m_status;
|
101
|
+
std::string m_query;
|
102
|
+
};
|
103
|
+
|
104
|
+
class PostgreSQLConnection
|
105
|
+
{
|
106
|
+
public:
|
107
|
+
PostgreSQLConnection
|
108
|
+
( const DatabaseConnectionID& id )
|
109
|
+
: m_connectionID( id )
|
110
|
+
{
|
111
|
+
connect();
|
112
|
+
}
|
113
|
+
|
114
|
+
PostgreSQLConnection
|
115
|
+
( const std::string& database, const std::string& user,
|
116
|
+
const std::string& password, const std::string& host, short port )
|
117
|
+
: m_connectionID( database, user, password, host, port )
|
118
|
+
{
|
119
|
+
connect();
|
120
|
+
}
|
121
|
+
|
122
|
+
~PostgreSQLConnection()
|
123
|
+
{
|
124
|
+
if( m_pConnection )
|
125
|
+
PQfinish( m_pConnection );
|
126
|
+
}
|
127
|
+
|
128
|
+
const DatabaseConnectionID& connectionID()
|
129
|
+
{
|
130
|
+
return m_connectionID;
|
131
|
+
}
|
132
|
+
|
133
|
+
bool connected()
|
134
|
+
{
|
135
|
+
Locker locker( m_mutex );
|
136
|
+
return PQstatus( m_pConnection ) == CONNECTION_OK;
|
137
|
+
}
|
138
|
+
|
139
|
+
bool reconnect()
|
140
|
+
{
|
141
|
+
Locker locker( m_mutex );
|
142
|
+
PQreset( m_pConnection );
|
143
|
+
return connected();
|
144
|
+
}
|
145
|
+
|
146
|
+
bool execute( PostgreSQLQuery& pQuery )
|
147
|
+
{
|
148
|
+
Locker locker( m_mutex );
|
149
|
+
return pQuery.execute( m_pConnection );
|
150
|
+
}
|
151
|
+
|
152
|
+
private:
|
153
|
+
void connect()
|
154
|
+
{
|
155
|
+
short port = m_connectionID.getPort();
|
156
|
+
m_pConnection = PQsetdbLogin
|
157
|
+
( m_connectionID.getHost().c_str(), port == 0 ? "" : IntConvertor::convert( port ).c_str(),
|
158
|
+
"", "", m_connectionID.getDatabase().c_str(), m_connectionID.getUser().c_str(), m_connectionID.getPassword().c_str() );
|
159
|
+
|
160
|
+
if( !connected() )
|
161
|
+
throw ConfigError( "Unable to connect to database" );
|
162
|
+
}
|
163
|
+
|
164
|
+
PGconn* m_pConnection;
|
165
|
+
DatabaseConnectionID m_connectionID;
|
166
|
+
Mutex m_mutex;
|
167
|
+
};
|
168
|
+
|
169
|
+
typedef DatabaseConnectionPool<PostgreSQLConnection>
|
170
|
+
PostgreSQLConnectionPool;
|
171
|
+
typedef std::auto_ptr< PostgreSQLConnectionPool >
|
172
|
+
PostgreSQLConnectionPoolPtr;
|
173
|
+
}
|
174
|
+
|
175
|
+
#endif //FIX_POSTGRESQLCONNECTION_H
|
176
|
+
#endif //HAVE_POSTGRESQL
|
@@ -0,0 +1,276 @@
|
|
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
|
+
|
38
|
+
const std::string PostgreSQLLogFactory::DEFAULT_DATABASE = "quickfix";
|
39
|
+
const std::string PostgreSQLLogFactory::DEFAULT_USER = "postgres";
|
40
|
+
const std::string PostgreSQLLogFactory::DEFAULT_PASSWORD = "";
|
41
|
+
const std::string PostgreSQLLogFactory::DEFAULT_HOST = "localhost";
|
42
|
+
const short PostgreSQLLogFactory::DEFAULT_PORT = 0;
|
43
|
+
|
44
|
+
PostgreSQLLog::PostgreSQLLog
|
45
|
+
( const SessionID& s, const DatabaseConnectionID& d, PostgreSQLConnectionPool* p )
|
46
|
+
: m_pConnectionPool( p )
|
47
|
+
{
|
48
|
+
init();
|
49
|
+
m_pSessionID = new SessionID( s );
|
50
|
+
m_pConnection = m_pConnectionPool->create( d );
|
51
|
+
}
|
52
|
+
|
53
|
+
PostgreSQLLog::PostgreSQLLog
|
54
|
+
( const DatabaseConnectionID& d, PostgreSQLConnectionPool* p )
|
55
|
+
: m_pConnectionPool( p ), m_pSessionID( 0 )
|
56
|
+
{
|
57
|
+
init();
|
58
|
+
m_pConnection = m_pConnectionPool->create( d );
|
59
|
+
}
|
60
|
+
|
61
|
+
PostgreSQLLog::PostgreSQLLog
|
62
|
+
( const SessionID& s, const std::string& database, const std::string& user,
|
63
|
+
const std::string& password, const std::string& host, short port )
|
64
|
+
: m_pConnectionPool( 0 )
|
65
|
+
{
|
66
|
+
init();
|
67
|
+
m_pSessionID = new SessionID( s );
|
68
|
+
m_pConnection = new PostgreSQLConnection( database, user, password, host, port );
|
69
|
+
}
|
70
|
+
|
71
|
+
PostgreSQLLog::PostgreSQLLog
|
72
|
+
( const std::string& database, const std::string& user,
|
73
|
+
const std::string& password, const std::string& host, short port )
|
74
|
+
: m_pConnectionPool( 0 ), m_pSessionID( 0 )
|
75
|
+
{
|
76
|
+
init();
|
77
|
+
m_pConnection = new PostgreSQLConnection( database, user, password, host, port );
|
78
|
+
}
|
79
|
+
|
80
|
+
void PostgreSQLLog::init()
|
81
|
+
{
|
82
|
+
setIncomingTable( "messages_log" );
|
83
|
+
setOutgoingTable( "messages_log" );
|
84
|
+
setEventTable( "event_log" );
|
85
|
+
}
|
86
|
+
|
87
|
+
PostgreSQLLog::~PostgreSQLLog()
|
88
|
+
{
|
89
|
+
if( m_pConnectionPool )
|
90
|
+
m_pConnectionPool->destroy( m_pConnection );
|
91
|
+
else
|
92
|
+
delete m_pConnection;
|
93
|
+
delete m_pSessionID;
|
94
|
+
}
|
95
|
+
|
96
|
+
Log* PostgreSQLLogFactory::create()
|
97
|
+
{
|
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
|
+
{
|
113
|
+
std::string database;
|
114
|
+
std::string user;
|
115
|
+
std::string password;
|
116
|
+
std::string host;
|
117
|
+
short port;
|
118
|
+
|
119
|
+
Dictionary settings;
|
120
|
+
if( m_settings.has(s) )
|
121
|
+
settings = m_settings.get( s );
|
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( const Dictionary& settings,
|
131
|
+
std::string& database,
|
132
|
+
std::string& user,
|
133
|
+
std::string& password,
|
134
|
+
std::string& host,
|
135
|
+
short &port )
|
136
|
+
{
|
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
|
+
{
|
145
|
+
try { database = settings.getString( POSTGRESQL_LOG_DATABASE ); }
|
146
|
+
catch( ConfigError& ) {}
|
147
|
+
|
148
|
+
try { user = settings.getString( POSTGRESQL_LOG_USER ); }
|
149
|
+
catch( ConfigError& ) {}
|
150
|
+
|
151
|
+
try { password = settings.getString( POSTGRESQL_LOG_PASSWORD ); }
|
152
|
+
catch( ConfigError& ) {}
|
153
|
+
|
154
|
+
try { host = settings.getString( POSTGRESQL_LOG_HOST ); }
|
155
|
+
catch( ConfigError& ) {}
|
156
|
+
|
157
|
+
try { port = ( short ) settings.getInt( POSTGRESQL_LOG_PORT ); }
|
158
|
+
catch( ConfigError& ) {}
|
159
|
+
}
|
160
|
+
else
|
161
|
+
{
|
162
|
+
database = m_database;
|
163
|
+
user = m_user;
|
164
|
+
password = m_password;
|
165
|
+
host = m_host;
|
166
|
+
port = m_port;
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
170
|
+
void PostgreSQLLogFactory::initLog( const Dictionary& settings, PostgreSQLLog& log )
|
171
|
+
{
|
172
|
+
try { log.setIncomingTable( settings.getString( POSTGRESQL_LOG_INCOMING_TABLE ) ); }
|
173
|
+
catch( ConfigError& ) {}
|
174
|
+
|
175
|
+
try { log.setOutgoingTable( settings.getString( POSTGRESQL_LOG_OUTGOING_TABLE ) ); }
|
176
|
+
catch( ConfigError& ) {}
|
177
|
+
|
178
|
+
try { log.setEventTable( settings.getString( POSTGRESQL_LOG_EVENT_TABLE ) ); }
|
179
|
+
catch( ConfigError& ) {}
|
180
|
+
}
|
181
|
+
|
182
|
+
void PostgreSQLLogFactory::destroy( Log* pLog )
|
183
|
+
{
|
184
|
+
delete pLog;
|
185
|
+
}
|
186
|
+
|
187
|
+
void PostgreSQLLog::clear()
|
188
|
+
{
|
189
|
+
std::stringstream whereClause;
|
190
|
+
|
191
|
+
whereClause << "WHERE ";
|
192
|
+
|
193
|
+
if( m_pSessionID )
|
194
|
+
{
|
195
|
+
whereClause
|
196
|
+
<< "BeginString = '" << m_pSessionID->getBeginString().getValue() << "' "
|
197
|
+
<< "AND SenderCompID = '" << m_pSessionID->getSenderCompID().getValue() << "' "
|
198
|
+
<< "AND TargetCompID = '" << m_pSessionID->getTargetCompID().getValue() << "' ";
|
199
|
+
|
200
|
+
if( m_pSessionID->getSessionQualifier().size() )
|
201
|
+
whereClause << "AND SessionQualifier = '" << m_pSessionID->getSessionQualifier() << "'";
|
202
|
+
}
|
203
|
+
else
|
204
|
+
{
|
205
|
+
whereClause << "BeginString = NULL AND SenderCompID = NULL && TargetCompID = NULL";
|
206
|
+
}
|
207
|
+
|
208
|
+
std::stringstream incomingQuery;
|
209
|
+
std::stringstream outgoingQuery;
|
210
|
+
std::stringstream eventQuery;
|
211
|
+
|
212
|
+
incomingQuery
|
213
|
+
<< "DELETE FROM " << m_incomingTable << " " << whereClause.str();
|
214
|
+
outgoingQuery
|
215
|
+
<< "DELETE FROM " << m_outgoingTable << " " << whereClause.str();
|
216
|
+
eventQuery
|
217
|
+
<< "DELETE FROM " << m_eventTable << " " << whereClause.str();
|
218
|
+
|
219
|
+
PostgreSQLQuery incoming( incomingQuery.str() );
|
220
|
+
PostgreSQLQuery outgoing( outgoingQuery.str() );
|
221
|
+
PostgreSQLQuery event( eventQuery.str() );
|
222
|
+
m_pConnection->execute( incoming );
|
223
|
+
m_pConnection->execute( outgoing );
|
224
|
+
m_pConnection->execute( event );
|
225
|
+
}
|
226
|
+
|
227
|
+
void PostgreSQLLog::backup()
|
228
|
+
{
|
229
|
+
}
|
230
|
+
|
231
|
+
void PostgreSQLLog::insert( const std::string& table, const std::string value )
|
232
|
+
{
|
233
|
+
UtcTimeStamp time;
|
234
|
+
int year, month, day, hour, minute, second, millis;
|
235
|
+
time.getYMD( year, month, day );
|
236
|
+
time.getHMS( hour, minute, second, millis );
|
237
|
+
|
238
|
+
char sqlTime[ 24 ];
|
239
|
+
STRING_SPRINTF( sqlTime, "%d-%02d-%02d %02d:%02d:%02d.%003d",
|
240
|
+
year, month, day, hour, minute, second, millis );
|
241
|
+
|
242
|
+
char* valueCopy = new char[ (value.size() * 2) + 1 ];
|
243
|
+
PQescapeString( valueCopy, value.c_str(), value.size() );
|
244
|
+
|
245
|
+
std::stringstream queryString;
|
246
|
+
queryString << "INSERT INTO " << table << " "
|
247
|
+
<< "(time, beginstring, sendercompid, targetcompid, session_qualifier, text) "
|
248
|
+
<< "VALUES ("
|
249
|
+
<< "'" << sqlTime << "',";
|
250
|
+
|
251
|
+
if( m_pSessionID )
|
252
|
+
{
|
253
|
+
queryString
|
254
|
+
<< "'" << m_pSessionID->getBeginString().getValue() << "',"
|
255
|
+
<< "'" << m_pSessionID->getSenderCompID().getValue() << "',"
|
256
|
+
<< "'" << m_pSessionID->getTargetCompID().getValue() << "',";
|
257
|
+
if( m_pSessionID->getSessionQualifier() == "" )
|
258
|
+
queryString << "NULL" << ",";
|
259
|
+
else
|
260
|
+
queryString << "'" << m_pSessionID->getSessionQualifier() << "',";
|
261
|
+
}
|
262
|
+
else
|
263
|
+
{
|
264
|
+
queryString << "NULL, NULL, NULL, NULL, ";
|
265
|
+
}
|
266
|
+
|
267
|
+
queryString << "'" << valueCopy << "')";
|
268
|
+
delete [] valueCopy;
|
269
|
+
|
270
|
+
PostgreSQLQuery query( queryString.str() );
|
271
|
+
m_pConnection->execute( query );
|
272
|
+
}
|
273
|
+
|
274
|
+
} // namespace FIX
|
275
|
+
|
276
|
+
#endif //HAVE_POSTGRESQL
|