SSLSocketConnection.h
Go to the documentation of this file.
1 /* ====================================================================
2  * Copyright (c) 1998-2006 Ralf S. Engelschall. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following
13  * disclaimer in the documentation and/or other materials
14  * provided with the distribution.
15  *
16  * 3. All advertising materials mentioning features or use of this
17  * software must display the following acknowledgment:
18  * "This product includes software developed by
19  * Ralf S. Engelschall <rse@engelschall.com> for use in the
20  * mod_ssl project (http://www.modssl.org/)."
21  *
22  * 4. The names "mod_ssl" must not be used to endorse or promote
23  * products derived from this software without prior written
24  * permission. For written permission, please contact
25  * rse@engelschall.com.
26  *
27  * 5. Products derived from this software may not be called "mod_ssl"
28  * nor may "mod_ssl" appear in their names without prior
29  * written permission of Ralf S. Engelschall.
30  *
31  * 6. Redistributions of any form whatsoever must retain the following
32  * acknowledgment:
33  * "This product includes software developed by
34  * Ralf S. Engelschall <rse@engelschall.com> for use in the
35  * mod_ssl project (http://www.modssl.org/)."
36  *
37  * THIS SOFTWARE IS PROVIDED BY RALF S. ENGELSCHALL ``AS IS'' AND ANY
38  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RALF S. ENGELSCHALL OR
41  * HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
46  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48  * OF THE POSSIBILITY OF SUCH DAMAGE.
49  * ====================================================================
50  */
51 
52 /* ====================================================================
53  * Copyright (c) 1995-1999 Ben Laurie. All rights reserved.
54  *
55  * Redistribution and use in source and binary forms, with or without
56  * modification, are permitted provided that the following conditions
57  * are met:
58  *
59  * 1. Redistributions of source code must retain the above copyright
60  * notice, this list of conditions and the following disclaimer.
61  *
62  * 2. Redistributions in binary form must reproduce the above copyright
63  * notice, this list of conditions and the following disclaimer in
64  * the documentation and/or other materials provided with the
65  * distribution.
66  *
67  * 3. All advertising materials mentioning features or use of this
68  * software must display the following acknowledgment:
69  * "This product includes software developed by Ben Laurie
70  * for use in the Apache-SSL HTTP server project."
71  *
72  * 4. The name "Apache-SSL Server" must not be used to
73  * endorse or promote products derived from this software without
74  * prior written permission.
75  *
76  * 5. Redistributions of any form whatsoever must retain the following
77  * acknowledgment:
78  * "This product includes software developed by Ben Laurie
79  * for use in the Apache-SSL HTTP server project."
80  *
81  * THIS SOFTWARE IS PROVIDED BY BEN LAURIE ``AS IS'' AND ANY
82  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
83  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
84  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BEN LAURIE OR
85  * HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
86  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
87  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
88  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
89  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
90  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
91  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
92  * OF THE POSSIBILITY OF SUCH DAMAGE.
93  * ====================================================================
94  */
95 
96 /* -*- C++ -*- */
97 
98 /****************************************************************************
99 ** Copyright (c) 2001-2014
100 **
101 ** This file is part of the QuickFIX FIX Engine
102 **
103 ** This file may be distributed under the terms of the quickfixengine.org
104 ** license as defined by quickfixengine.org and appearing in the file
105 ** LICENSE included in the packaging of this file.
106 **
107 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
108 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
109 **
110 ** See http://www.quickfixengine.org/LICENSE for licensing information.
111 **
112 ** Contact ask@quickfixengine.org if any conditions of this licensing are
113 ** not clear to you.
114 **
115 ****************************************************************************/
116 
117 #ifndef FIX_SSLSOCKETCONNECTION_H
118 #define FIX_SSLSOCKETCONNECTION_H
119 
120 #if (HAVE_SSL > 0)
121 
122 #ifdef _MSC_VER
123 #pragma warning( disable : 4503 4355 4786 4290 )
124 #endif
125 
126 #include "Parser.h"
127 #include "Responder.h"
128 #include "SessionID.h"
129 #include "SocketMonitor.h"
130 #include "Utility.h"
131 #include "UtilitySSL.h"
132 #include "Mutex.h"
133 #include <set>
134 
135 namespace FIX
136 {
137 class SSLSocketAcceptor;
138 class SocketServer;
139 class SocketConnector;
140 class SSLSocketInitiator;
141 class Session;
142 
144 class SSLSocketConnection : Responder
145 {
146 public:
147  typedef std::set<SessionID> Sessions;
148 
149  SSLSocketConnection( int s, SSL *ssl, Sessions sessions, SocketMonitor* pMonitor );
150  SSLSocketConnection( SSLSocketInitiator&, const SessionID&, int, SSL *, SocketMonitor* );
151  virtual ~SSLSocketConnection();
152 
153  int getSocket() const { return m_socket; }
154  Session* getSession() const { return m_pSession; }
155 
156  bool read( SocketConnector& s );
157  bool read( SSLSocketAcceptor&, SocketServer& );
158  bool processQueue();
159 
160  void signal()
161  {
162  Locker l( m_mutex );
163  if( m_sendQueue.size() == 1 )
164  m_pMonitor->signal( m_socket );
165  }
166 
167  void unsignal()
168  {
169  Locker l( m_mutex );
170  if( m_sendQueue.size() == 0 )
171  m_pMonitor->unsignal( m_socket );
172  }
173 
174  void onTimeout();
175 
176  SSL *sslObject() { return m_ssl; }
177 
178 private:
179  typedef std::deque<std::string, ALLOCATOR<std::string> >
180  Queue;
181 
182  bool isValidSession();
183  void readFromSocket() throw( SocketRecvFailed );
184  bool readMessage( std::string& msg );
185  void readMessages( SocketMonitor& s );
186  bool send( const std::string& );
187  void disconnect();
188 
189  int m_socket;
190  SSL *m_ssl;
191  char m_buffer[BUFSIZ];
192 
193  Parser m_parser;
194  Queue m_sendQueue;
195  unsigned m_sendLength;
196  Sessions m_sessions;
197  Session* m_pSession;
198  SocketMonitor* m_pMonitor;
199  Mutex m_mutex;
200  fd_set m_fds;
201 };
202 }
203 
204 #endif
205 
206 #endif //FIX_SSLSOCKETCONNECTION_H
SessionID.h
UtilitySSL.h
Mutex.h
SocketMonitor.h
Parser.h
FIX
Definition: Acceptor.cpp:34
Responder.h
Utility.h

Generated on Wed Apr 29 2020 19:41:30 for QuickFIX by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2001