quickfix_ruby 1.14.3

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 (149) hide show
  1. checksums.yaml +7 -0
  2. data/ext/quickfix/Acceptor.cpp +248 -0
  3. data/ext/quickfix/Acceptor.h +127 -0
  4. data/ext/quickfix/Allocator.h +9 -0
  5. data/ext/quickfix/Application.h +127 -0
  6. data/ext/quickfix/AtomicCount.h +109 -0
  7. data/ext/quickfix/DOMDocument.h +74 -0
  8. data/ext/quickfix/DataDictionary.cpp +618 -0
  9. data/ext/quickfix/DataDictionary.h +539 -0
  10. data/ext/quickfix/DataDictionaryProvider.cpp +71 -0
  11. data/ext/quickfix/DataDictionaryProvider.h +70 -0
  12. data/ext/quickfix/DatabaseConnectionID.h +105 -0
  13. data/ext/quickfix/DatabaseConnectionPool.h +91 -0
  14. data/ext/quickfix/Dictionary.cpp +162 -0
  15. data/ext/quickfix/Dictionary.h +94 -0
  16. data/ext/quickfix/Event.h +95 -0
  17. data/ext/quickfix/Exceptions.h +299 -0
  18. data/ext/quickfix/Field.h +672 -0
  19. data/ext/quickfix/FieldConvertors.h +863 -0
  20. data/ext/quickfix/FieldMap.cpp +238 -0
  21. data/ext/quickfix/FieldMap.h +244 -0
  22. data/ext/quickfix/FieldNumbers.h +46 -0
  23. data/ext/quickfix/FieldTypes.cpp +64 -0
  24. data/ext/quickfix/FieldTypes.h +698 -0
  25. data/ext/quickfix/Fields.h +31 -0
  26. data/ext/quickfix/FileLog.cpp +200 -0
  27. data/ext/quickfix/FileLog.h +112 -0
  28. data/ext/quickfix/FileStore.cpp +332 -0
  29. data/ext/quickfix/FileStore.h +129 -0
  30. data/ext/quickfix/FixFieldNumbers.h +1537 -0
  31. data/ext/quickfix/FixFields.h +1538 -0
  32. data/ext/quickfix/FixValues.h +3281 -0
  33. data/ext/quickfix/FlexLexer.h +188 -0
  34. data/ext/quickfix/Group.cpp +64 -0
  35. data/ext/quickfix/Group.h +73 -0
  36. data/ext/quickfix/HtmlBuilder.h +186 -0
  37. data/ext/quickfix/HttpConnection.cpp +739 -0
  38. data/ext/quickfix/HttpConnection.h +78 -0
  39. data/ext/quickfix/HttpMessage.cpp +149 -0
  40. data/ext/quickfix/HttpMessage.h +133 -0
  41. data/ext/quickfix/HttpParser.cpp +49 -0
  42. data/ext/quickfix/HttpParser.h +54 -0
  43. data/ext/quickfix/HttpServer.cpp +169 -0
  44. data/ext/quickfix/HttpServer.h +78 -0
  45. data/ext/quickfix/Initiator.cpp +289 -0
  46. data/ext/quickfix/Initiator.h +149 -0
  47. data/ext/quickfix/Log.cpp +77 -0
  48. data/ext/quickfix/Log.h +179 -0
  49. data/ext/quickfix/Message.cpp +580 -0
  50. data/ext/quickfix/Message.h +370 -0
  51. data/ext/quickfix/MessageCracker.h +188 -0
  52. data/ext/quickfix/MessageSorters.cpp +105 -0
  53. data/ext/quickfix/MessageSorters.h +156 -0
  54. data/ext/quickfix/MessageStore.cpp +146 -0
  55. data/ext/quickfix/MessageStore.h +174 -0
  56. data/ext/quickfix/Mutex.h +131 -0
  57. data/ext/quickfix/MySQLConnection.h +194 -0
  58. data/ext/quickfix/MySQLLog.cpp +275 -0
  59. data/ext/quickfix/MySQLLog.h +145 -0
  60. data/ext/quickfix/MySQLStore.cpp +331 -0
  61. data/ext/quickfix/MySQLStore.h +142 -0
  62. data/ext/quickfix/NullStore.cpp +54 -0
  63. data/ext/quickfix/NullStore.h +99 -0
  64. data/ext/quickfix/OdbcConnection.h +266 -0
  65. data/ext/quickfix/OdbcLog.cpp +252 -0
  66. data/ext/quickfix/OdbcLog.h +117 -0
  67. data/ext/quickfix/OdbcStore.cpp +338 -0
  68. data/ext/quickfix/OdbcStore.h +113 -0
  69. data/ext/quickfix/PUGIXML_DOMDocument.cpp +112 -0
  70. data/ext/quickfix/PUGIXML_DOMDocument.h +81 -0
  71. data/ext/quickfix/Parser.cpp +103 -0
  72. data/ext/quickfix/Parser.h +57 -0
  73. data/ext/quickfix/PostgreSQLConnection.h +176 -0
  74. data/ext/quickfix/PostgreSQLLog.cpp +276 -0
  75. data/ext/quickfix/PostgreSQLLog.h +144 -0
  76. data/ext/quickfix/PostgreSQLStore.cpp +334 -0
  77. data/ext/quickfix/PostgreSQLStore.h +141 -0
  78. data/ext/quickfix/Queue.h +75 -0
  79. data/ext/quickfix/QuickfixRuby.cpp +252066 -0
  80. data/ext/quickfix/QuickfixRuby.h +34 -0
  81. data/ext/quickfix/Responder.h +43 -0
  82. data/ext/quickfix/Session.cpp +1487 -0
  83. data/ext/quickfix/Session.h +335 -0
  84. data/ext/quickfix/SessionFactory.cpp +274 -0
  85. data/ext/quickfix/SessionFactory.h +86 -0
  86. data/ext/quickfix/SessionID.h +170 -0
  87. data/ext/quickfix/SessionSettings.cpp +189 -0
  88. data/ext/quickfix/SessionSettings.h +171 -0
  89. data/ext/quickfix/SessionState.h +231 -0
  90. data/ext/quickfix/Settings.cpp +100 -0
  91. data/ext/quickfix/Settings.h +53 -0
  92. data/ext/quickfix/SharedArray.h +150 -0
  93. data/ext/quickfix/SocketAcceptor.cpp +222 -0
  94. data/ext/quickfix/SocketAcceptor.h +75 -0
  95. data/ext/quickfix/SocketConnection.cpp +238 -0
  96. data/ext/quickfix/SocketConnection.h +103 -0
  97. data/ext/quickfix/SocketConnector.cpp +116 -0
  98. data/ext/quickfix/SocketConnector.h +67 -0
  99. data/ext/quickfix/SocketInitiator.cpp +260 -0
  100. data/ext/quickfix/SocketInitiator.h +81 -0
  101. data/ext/quickfix/SocketMonitor.cpp +335 -0
  102. data/ext/quickfix/SocketMonitor.h +111 -0
  103. data/ext/quickfix/SocketServer.cpp +177 -0
  104. data/ext/quickfix/SocketServer.h +100 -0
  105. data/ext/quickfix/ThreadedSocketAcceptor.cpp +258 -0
  106. data/ext/quickfix/ThreadedSocketAcceptor.h +98 -0
  107. data/ext/quickfix/ThreadedSocketConnection.cpp +209 -0
  108. data/ext/quickfix/ThreadedSocketConnection.h +82 -0
  109. data/ext/quickfix/ThreadedSocketInitiator.cpp +268 -0
  110. data/ext/quickfix/ThreadedSocketInitiator.h +84 -0
  111. data/ext/quickfix/TimeRange.cpp +173 -0
  112. data/ext/quickfix/TimeRange.h +258 -0
  113. data/ext/quickfix/Utility.cpp +537 -0
  114. data/ext/quickfix/Utility.h +219 -0
  115. data/ext/quickfix/Values.h +62 -0
  116. data/ext/quickfix/config.h +0 -0
  117. data/ext/quickfix/config_windows.h +0 -0
  118. data/ext/quickfix/extconf.rb +12 -0
  119. data/ext/quickfix/index.h +37 -0
  120. data/ext/quickfix/pugiconfig.hpp +72 -0
  121. data/ext/quickfix/pugixml.cpp +10765 -0
  122. data/ext/quickfix/pugixml.hpp +1341 -0
  123. data/ext/quickfix/strptime.h +7 -0
  124. data/lib/quickfix40.rb +274 -0
  125. data/lib/quickfix41.rb +351 -0
  126. data/lib/quickfix42.rb +1184 -0
  127. data/lib/quickfix43.rb +3504 -0
  128. data/lib/quickfix44.rb +10721 -0
  129. data/lib/quickfix50.rb +13426 -0
  130. data/lib/quickfix50sp1.rb +15629 -0
  131. data/lib/quickfix50sp2.rb +17068 -0
  132. data/lib/quickfix_fields.rb +19853 -0
  133. data/lib/quickfix_ruby.rb +82 -0
  134. data/lib/quickfixt11.rb +70 -0
  135. data/spec/FIX40.xml +862 -0
  136. data/spec/FIX41.xml +1285 -0
  137. data/spec/FIX42.xml +2746 -0
  138. data/spec/FIX43.xml +4229 -0
  139. data/spec/FIX44.xml +6596 -0
  140. data/spec/FIX50.xml +8137 -0
  141. data/spec/FIX50SP1.xml +9496 -0
  142. data/spec/FIX50SP2.xml +10011 -0
  143. data/spec/FIXT11.xml +313 -0
  144. data/test/test_DataDictionaryTestCase.rb +268 -0
  145. data/test/test_DictionaryTestCase.rb +112 -0
  146. data/test/test_FieldBaseTestCase.rb +24 -0
  147. data/test/test_MessageTestCase.rb +368 -0
  148. data/test/test_SessionSettingsTestCase.rb +41 -0
  149. metadata +193 -0
@@ -0,0 +1,78 @@
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_HTTPCONNECTION_H
23
+ #define FIX_HTTPCONNECTION_H
24
+
25
+ #ifdef _MSC_VER
26
+ #pragma warning( disable : 4503 4355 4786 4290 )
27
+ #endif
28
+
29
+ #include "HttpParser.h"
30
+ #include <stdio.h>
31
+
32
+ namespace FIX
33
+ {
34
+ class HttpMessage;
35
+
36
+ /// Encapsulates a HTTP socket file descriptor
37
+ class HttpConnection
38
+ {
39
+ public:
40
+ HttpConnection( int s );
41
+
42
+ int getSocket() const { return m_socket; }
43
+ bool read();
44
+
45
+ private:
46
+ bool readMessage( std::string& msg ) throw( SocketRecvFailed );
47
+ void processStream();
48
+ void processRequest( const HttpMessage& );
49
+ void processRoot( const HttpMessage&, std::stringstream& h, std::stringstream& b );
50
+ void processResetSessions( const HttpMessage&, std::stringstream& h, std::stringstream& b );
51
+ void processRefreshSessions( const HttpMessage&, std::stringstream& h, std::stringstream& b );
52
+ void processEnableSessions( const HttpMessage&, std::stringstream& h, std::stringstream& b );
53
+ void processDisableSessions( const HttpMessage&, std::stringstream& h, std::stringstream& b );
54
+ void processSession( const HttpMessage&, std::stringstream& h, std::stringstream& b );
55
+ void processResetSession( const HttpMessage&, std::stringstream& h, std::stringstream& b );
56
+ void processRefreshSession( const HttpMessage&, std::stringstream& h, std::stringstream& b );
57
+
58
+ void showToggle
59
+ ( std::stringstream& s, const std::string& name, bool value, const std::string& url );
60
+ void showRow
61
+ ( std::stringstream& s, const std::string& name, bool value, const std::string& url = "" );
62
+ void showRow
63
+ ( std::stringstream& s, const std::string& name, const std::string& value, const std::string& url = "" );
64
+ void showRow
65
+ ( std::stringstream& s, const std::string& name, int value, const std::string& url = "" );
66
+
67
+ bool send( const std::string& );
68
+ void disconnect( int error = 0 );
69
+
70
+ int m_socket;
71
+ char m_buffer[BUFSIZ];
72
+
73
+ HttpParser m_parser;
74
+ fd_set m_fds;
75
+ };
76
+ }
77
+
78
+ #endif
@@ -0,0 +1,149 @@
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 "HttpMessage.h"
27
+ #include "Utility.h"
28
+ #include <sstream>
29
+ #include <iomanip>
30
+
31
+ namespace FIX
32
+ {
33
+
34
+ HttpMessage::HttpMessage() {}
35
+
36
+ HttpMessage::HttpMessage( const std::string& string )
37
+ throw( InvalidMessage )
38
+ {
39
+ setString( string );
40
+ }
41
+
42
+ std::string HttpMessage::toString() const
43
+ {
44
+ std::string str;
45
+ return toString( str );
46
+ }
47
+
48
+ std::string& HttpMessage::toString( std::string& str ) const
49
+ {
50
+ str = m_root + getParameterString();
51
+ return str;
52
+ }
53
+
54
+ void HttpMessage::setString( const std::string& string )
55
+ throw( InvalidMessage )
56
+ {
57
+ clear();
58
+
59
+ std::string::size_type eolPos = string.find( "\r\n" );
60
+ if( eolPos == std::string::npos ) throw InvalidMessage();
61
+ std::string line = string.substr( 0, eolPos );
62
+ std::string::size_type getPos = line.find( "GET " );
63
+ if( getPos != 0 ) throw InvalidMessage();
64
+ std::string::size_type httpPos = line.rfind( "HTTP", std::string::npos );
65
+ if( httpPos == std::string::npos ) throw InvalidMessage();
66
+
67
+ m_root = line.substr( getPos + 4, httpPos - 5 );
68
+ std::string::size_type paramPos = m_root.find_first_of( '?' );
69
+ if( paramPos == std::string::npos ) return;
70
+ std::string parameters = m_root.substr( paramPos, m_root.size() - paramPos );
71
+ m_root = m_root.substr( 0, paramPos );
72
+ paramPos = 0;
73
+
74
+ while( paramPos != std::string::npos )
75
+ {
76
+ std::string::size_type sepPos = parameters.find_first_of( "=", paramPos );
77
+ if( sepPos == std::string::npos ) break;
78
+ std::string::size_type tempPos = paramPos;
79
+ paramPos = parameters.find_first_of( "&", paramPos + 1 );
80
+ std::string key = parameters.substr(tempPos + 1, sepPos - tempPos - 1);
81
+ std::string value = parameters.substr(sepPos + 1, paramPos - sepPos - 1);
82
+ m_parameters[key] = value;
83
+ }
84
+ }
85
+
86
+ std::string HttpMessage::createResponse( int error, const std::string& text )
87
+ {
88
+ std::string errorString;
89
+ switch( error )
90
+ {
91
+ case 100: errorString = "Continue"; break;
92
+ case 101: errorString = "Switching Protocols"; break;
93
+ case 200: errorString = "OK"; break;
94
+ case 201: errorString = "Created"; break;
95
+ case 202: errorString = "Accepted"; break;
96
+ case 203: errorString = "Non-Authoritative Information"; break;
97
+ case 204: errorString = "No Content"; break;
98
+ case 205: errorString = "Reset Content"; break;
99
+ case 206: errorString = "Partial Content"; break;
100
+ case 300: errorString = "Multiple Choices"; break;
101
+ case 301: errorString = "Moved Permanently"; break;
102
+ case 302: errorString = "Found"; break;
103
+ case 303: errorString = "See Other"; break;
104
+ case 304: errorString = "Not Modified"; break;
105
+ case 305: errorString = "Use Proxy"; break;
106
+ case 307: errorString = "Temporary Redirect"; break;
107
+ case 400: errorString = "Bad Request"; break;
108
+ case 401: errorString = "Unauthorized"; break;
109
+ case 402: errorString = "Payment Required"; break;
110
+ case 403: errorString = "Forbidden"; break;
111
+ case 404: errorString = "Not Found"; break;
112
+ case 405: errorString = "Method Not Allowed"; break;
113
+ case 406: errorString = "Not Acceptable"; break;
114
+ case 407: errorString = "Proxy Authentication Required"; break;
115
+ case 408: errorString = "Request Timeout"; break;
116
+ case 409: errorString = "Conflict"; break;
117
+ case 410: errorString = "Gone"; break;
118
+ case 411: errorString = "Length Required"; break;
119
+ case 412: errorString = "Precondition Failed"; break;
120
+ case 413: errorString = "Request Entity Too Large"; break;
121
+ case 414: errorString = "Request-URI Too Large"; break;
122
+ case 415: errorString = "Unsupported Media Type"; break;
123
+ case 416: errorString = "Requested Range Not Satisfiable"; break;
124
+ case 417: errorString = "Expectation Failed"; break;
125
+ case 500: errorString = "Internal Server Error"; break;
126
+ case 501: errorString = "Not Implemented"; break;
127
+ case 502: errorString = "Bad Gateway"; break;
128
+ case 503: errorString = "Service Unavailable"; break;
129
+ case 504: errorString = "Gateway Timeout"; break;
130
+ case 505: errorString = "HTTP Version not supported"; break;
131
+ default: errorString = "Unknown";
132
+ }
133
+
134
+ std::stringstream response;
135
+ response << "HTTP/1.1 " << error << " " << errorString << "\r\n"
136
+ << "Server: QuickFIX" << "\r\n"
137
+ << "Content-Type: text/html; charset=iso-8859-1" << "\r\n\r\n"
138
+ << "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">";
139
+
140
+ if( error < 200 || error >= 300 )
141
+ response << "<HTML><HEAD><TITLE>" << error << " " << errorString << "</TITLE></HEAD><BODY>"
142
+ << "<H1>" << error << " " << errorString << "</H1>" << text << "</BODY></HTML>";
143
+ else
144
+ response << text;
145
+
146
+ return response.str();
147
+ }
148
+
149
+ }
@@ -0,0 +1,133 @@
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_HTTPMESSAGE
23
+ #define FIX_HTTPMESSAGE
24
+
25
+ #ifdef _MSC_VER
26
+ #pragma warning( disable: 4786 )
27
+ #endif
28
+
29
+ #include "Exceptions.h"
30
+ #include <map>
31
+
32
+ namespace FIX
33
+ {
34
+ /**
35
+ * HTTP Message that implemented GET functionality
36
+ */
37
+ class HttpMessage
38
+ {
39
+ public:
40
+ typedef std::map<std::string, std::string> Parameters;
41
+
42
+ HttpMessage();
43
+
44
+ /// Construct a message from a string
45
+ HttpMessage( const std::string& string )
46
+ throw( InvalidMessage );
47
+
48
+ HttpMessage( const HttpMessage& copy )
49
+ {
50
+ m_root = copy.m_root;
51
+ m_parameters = copy.m_parameters;
52
+ }
53
+
54
+ public:
55
+ /// Get a string representation of the message
56
+ std::string toString() const;
57
+ /// Get a string representation without making a copy
58
+ std::string& toString( std::string& ) const;
59
+
60
+ void setString( const std::string& string )
61
+ throw( InvalidMessage );
62
+
63
+ void clear()
64
+ {
65
+ #if defined(_MSC_VER) && _MSC_VER < 1300
66
+ m_root = "";
67
+ #else
68
+ m_root.clear();
69
+ #endif
70
+ m_parameters.clear();
71
+ }
72
+
73
+ const std::string& getRootString() const
74
+ { return m_root; }
75
+
76
+ const std::string getParameterString() const
77
+ {
78
+ std::string result;
79
+ Parameters::const_iterator i;
80
+ for( i = m_parameters.begin(); i != m_parameters.end(); ++i )
81
+ {
82
+ result += (i == m_parameters.begin()) ? "?" : "&";
83
+ result += i->first + "=" + i->second;
84
+ }
85
+ return result;
86
+ }
87
+
88
+ const Parameters& getParameters() const
89
+ { return m_parameters; }
90
+
91
+ bool hasParameter( const std::string& key ) const
92
+ {
93
+ Parameters::const_iterator find = m_parameters.find( key );
94
+ return find != m_parameters.end();
95
+ }
96
+
97
+ const std::string& getParameter( const std::string& key ) const
98
+ throw( std::logic_error )
99
+ {
100
+ Parameters::const_iterator find = m_parameters.find( key );
101
+ if( find == m_parameters.end() )
102
+ throw std::logic_error( "Parameter " + key + " not found" );
103
+ return find->second;
104
+ }
105
+
106
+ void addParameter( const std::string& key, const std::string& value )
107
+ {
108
+ m_parameters[key] = value;
109
+ }
110
+
111
+ void removeParameter( const std::string& key )
112
+ {
113
+ m_parameters.erase( key );
114
+ }
115
+
116
+ static std::string createResponse( int error = 0, const std::string& text = "" );
117
+
118
+ private:
119
+ std::string m_root;
120
+ Parameters m_parameters;
121
+ };
122
+ /*! @} */
123
+
124
+ inline std::ostream& operator <<
125
+ ( std::ostream& stream, const HttpMessage& message )
126
+ {
127
+ std::string str;
128
+ stream << message.toString( str );
129
+ return stream;
130
+ }
131
+ }
132
+
133
+ #endif //FIX_HTTPMESSAGE
@@ -0,0 +1,49 @@
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 "HttpParser.h"
27
+ #include "Utility.h"
28
+ #include <algorithm>
29
+
30
+ namespace FIX
31
+ {
32
+ bool HttpParser::readHttpMessage( std::string& str )
33
+ throw( MessageParseError )
34
+ {
35
+ std::string::size_type pos = 0;
36
+
37
+ if( m_buffer.length() < 4 )
38
+ return false;
39
+ pos = m_buffer.find( "\r\n\r\n" );
40
+ if( m_buffer.length() > 2048 )
41
+ throw MessageParseError();
42
+ if( pos == std::string::npos )
43
+ return false;
44
+ str.assign( m_buffer, 0, pos + 4 );
45
+ m_buffer.erase( 0, pos + 4 );
46
+
47
+ return true;
48
+ }
49
+ }
@@ -0,0 +1,54 @@
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_HTTPPARSER_H
23
+ #define FIX_HTTPPARSER_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 HTTP messages off an input stream.
36
+ class HttpParser
37
+ {
38
+ public:
39
+ HttpParser() {}
40
+ ~HttpParser() {}
41
+
42
+ bool readHttpMessage( std::string& str )
43
+ throw ( MessageParseError );
44
+
45
+ void addToStream( const char* str, size_t len )
46
+ { m_buffer.append( str, len ); }
47
+ void addToStream( const std::string& str )
48
+ { m_buffer.append( str ); }
49
+
50
+ private:
51
+ std::string m_buffer;
52
+ };
53
+ }
54
+ #endif //FIX_HTTPPARSER_H
@@ -0,0 +1,169 @@
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 "HttpServer.h"
27
+ #include "HttpConnection.h"
28
+ #include "Settings.h"
29
+ #include "Utility.h"
30
+
31
+ namespace FIX
32
+ {
33
+ Mutex HttpServer::s_mutex;
34
+ int HttpServer::s_count = 0;
35
+ HttpServer* HttpServer::s_pServer = 0;
36
+
37
+ void HttpServer::startGlobal( const SessionSettings& s )
38
+ throw ( ConfigError, RuntimeError )
39
+ {
40
+ Locker l( s_mutex );
41
+
42
+ if( !s.get().has(HTTP_ACCEPT_PORT) )
43
+ return;
44
+
45
+ s_count += 1;
46
+ if( !s_pServer )
47
+ {
48
+ s_pServer = new HttpServer( s );
49
+ s_pServer->start();
50
+ }
51
+ }
52
+
53
+ void HttpServer::stopGlobal()
54
+ {
55
+ Locker l( s_mutex );
56
+
57
+ s_count -= 1;
58
+ if( !s_count && s_pServer )
59
+ {
60
+ s_pServer->stop();
61
+ delete s_pServer;
62
+ s_pServer = 0;
63
+ }
64
+ }
65
+
66
+ HttpServer::HttpServer( const SessionSettings& settings ) throw( ConfigError )
67
+ : m_pServer( 0 ), m_settings( settings ), m_threadid( 0 ), m_port( 0 ), m_stop( false ) {}
68
+
69
+ void HttpServer::onConfigure( const SessionSettings& s )
70
+ throw ( ConfigError )
71
+ {
72
+ m_port = s.get().getInt( HTTP_ACCEPT_PORT );
73
+ }
74
+
75
+ void HttpServer::onInitialize( const SessionSettings& s )
76
+ throw ( RuntimeError )
77
+ {
78
+ try
79
+ {
80
+ m_pServer = new SocketServer( 1 );
81
+ m_pServer->add( m_port, true, false, 0, 0 );
82
+ }
83
+ catch( std::exception& )
84
+ {
85
+ throw RuntimeError( "Unable to create, bind, or listen to port " + IntConvertor::convert( (unsigned short)m_port ) );
86
+ }
87
+ }
88
+
89
+ void HttpServer::start() throw ( ConfigError, RuntimeError )
90
+ {
91
+ m_stop = false;
92
+ onConfigure( m_settings );
93
+ onInitialize( m_settings );
94
+
95
+ if( !thread_spawn( &startThread, this, m_threadid ) )
96
+ throw RuntimeError("Unable to spawn thread");
97
+ }
98
+
99
+ void HttpServer::stop()
100
+ {
101
+ if( m_stop ) return;
102
+ m_stop = true;
103
+ onStop();
104
+
105
+ if( m_threadid )
106
+ thread_join( m_threadid );
107
+ m_threadid = 0;
108
+ }
109
+
110
+ void HttpServer::onStart()
111
+ {
112
+ while ( !m_stop && m_pServer && m_pServer->block( *this ) ) {}
113
+
114
+ if( !m_pServer )
115
+ return;
116
+
117
+ m_pServer->close();
118
+ delete m_pServer;
119
+ m_pServer = 0;
120
+ }
121
+
122
+ bool HttpServer::onPoll()
123
+ {
124
+ if( !m_pServer || m_stop )
125
+ return false;
126
+
127
+ m_pServer->block( *this, true );
128
+ return true;
129
+ }
130
+
131
+ void HttpServer::onStop()
132
+ {
133
+ }
134
+
135
+ void HttpServer::onConnect( SocketServer& server, int a, int s )
136
+ {
137
+ if ( !socket_isValid( s ) ) return;
138
+ HttpConnection connection( s );
139
+ while( connection.read() ) {}
140
+ m_pServer->getMonitor().drop( s );
141
+ }
142
+
143
+ void HttpServer::onWrite( SocketServer& server, int s )
144
+ {
145
+ }
146
+
147
+ bool HttpServer::onData( SocketServer& server, int s )
148
+ {
149
+ return true;
150
+ }
151
+
152
+ void HttpServer::onDisconnect( SocketServer&, int s )
153
+ {
154
+ }
155
+
156
+ void HttpServer::onError( SocketServer& ) {}
157
+
158
+ void HttpServer::onTimeout( SocketServer& )
159
+ {
160
+ }
161
+
162
+ THREAD_PROC HttpServer::startThread( void* p )
163
+ {
164
+ HttpServer * pServer = static_cast < HttpServer* > ( p );
165
+ pServer->onStart();
166
+ return 0;
167
+ }
168
+
169
+ }
@@ -0,0 +1,78 @@
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_HTTPSERVER_H
23
+ #define FIX_HTTPSERVER_H
24
+
25
+ #ifdef _MSC_VER
26
+ #pragma warning( disable : 4503 4355 4786 4290 )
27
+ #endif
28
+
29
+ #include "SocketServer.h"
30
+ #include "SessionSettings.h"
31
+ #include "Exceptions.h"
32
+ #include "Mutex.h"
33
+
34
+ namespace FIX
35
+ {
36
+ /// Basic HTTP Server
37
+ class HttpServer : public SocketServer::Strategy
38
+ {
39
+ public:
40
+ HttpServer( const SessionSettings& ) throw( ConfigError );
41
+
42
+ static void startGlobal( const SessionSettings& ) throw ( ConfigError, RuntimeError );
43
+ static void stopGlobal();
44
+
45
+ void start() throw ( ConfigError, RuntimeError );
46
+ void stop();
47
+
48
+ private:
49
+ void onConfigure( const SessionSettings& ) throw ( ConfigError );
50
+ void onInitialize( const SessionSettings& ) throw ( RuntimeError );
51
+
52
+ void onStart();
53
+ bool onPoll();
54
+ void onStop();
55
+
56
+ void onConnect( SocketServer&, int, int );
57
+ void onWrite( SocketServer&, int );
58
+ bool onData( SocketServer&, int );
59
+ void onDisconnect( SocketServer&, int );
60
+ void onError( SocketServer& );
61
+ void onTimeout( SocketServer& );
62
+
63
+ static THREAD_PROC startThread( void* p );
64
+
65
+ SocketServer* m_pServer;
66
+ SessionSettings m_settings;
67
+ thread_id m_threadid;
68
+ int m_port;
69
+ bool m_stop;
70
+
71
+ static Mutex s_mutex;
72
+ static int s_count;
73
+ static HttpServer* s_pServer;
74
+ };
75
+ /*! @} */
76
+ }
77
+
78
+ #endif //FIX_HTTPSERVER_H