ThreadedSSLSocketAcceptor.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 #ifndef FIX_THREADEDSSLSOCKETACCEPTOR_H
117 #define FIX_THREADEDSSLSOCKETACCEPTOR_H
118 
119 #if (HAVE_SSL > 0)
120 
121 #ifdef _MSC_VER
122 #pragma warning(disable : 4503 4355 4786 4290)
123 #endif
124 
125 #include "Acceptor.h"
127 #include "Mutex.h"
128 
129 namespace FIX
130 {
132 class ThreadedSSLSocketAcceptor : public Acceptor
133 {
134  friend class SocketConnection;
135 
136 public:
137  ThreadedSSLSocketAcceptor(Application &, MessageStoreFactory &,
138  const SessionSettings &) throw(ConfigError);
139  ThreadedSSLSocketAcceptor(Application &, MessageStoreFactory &,
140  const SessionSettings &,
141  LogFactory &) throw(ConfigError);
142 
143  virtual ~ThreadedSSLSocketAcceptor();
144 
145  void setPassword(const std::string &pwd) { m_password.assign(pwd); }
146 
147  int passwordHandleCallback(char *buf, size_t bufsize, int verify, void *job);
148 
149  static int passPhraseHandleCB(char *buf, int bufsize, int verify, void *job);
150 
151 private:
152  struct AcceptorThreadInfo
153  {
154  AcceptorThreadInfo(ThreadedSSLSocketAcceptor *pAcceptor, int socket,
155  int port)
156  : m_pAcceptor(pAcceptor), m_socket(socket), m_port(port)
157  {
158  }
159 
160  ThreadedSSLSocketAcceptor *m_pAcceptor;
161  int m_socket;
162  int m_port;
163  };
164 
165  struct ConnectionThreadInfo
166  {
167  ConnectionThreadInfo(ThreadedSSLSocketAcceptor *pAcceptor,
168  ThreadedSSLSocketConnection *pConnection)
169  : m_pAcceptor(pAcceptor), m_pConnection(pConnection)
170  {
171  }
172 
173  ThreadedSSLSocketAcceptor *m_pAcceptor;
174  ThreadedSSLSocketConnection *m_pConnection;
175  };
176 
177  bool readSettings(const SessionSettings &);
178 
179  typedef std::set< int > Sockets;
180  typedef std::set< SessionID > Sessions;
181  typedef std::map< int, Sessions > PortToSessions;
182  typedef std::map< int, int > SocketToPort;
183  typedef std::pair< int, SSL * > SocketKey;
184  typedef std::map< SocketKey, thread_id > SocketToThread;
185 
186  void onConfigure(const SessionSettings &) throw(ConfigError);
187  void onInitialize(const SessionSettings &) throw(RuntimeError);
188 
189  void onStart();
190  bool onPoll(double timeout);
191  void onStop();
192 
193  void addThread(SocketKey s, thread_id t);
194  void removeThread(SocketKey s);
195  static THREAD_PROC socketAcceptorThread(void *p);
196  static THREAD_PROC socketConnectionThread(void *p);
197 
198  SSL_CTX *sslContext() { return m_ctx; }
199  X509_STORE *revocationStore() { return m_revocationStore; }
200 
201  Sockets m_sockets;
202  PortToSessions m_portToSessions;
203  SocketToPort m_socketToPort;
204  SocketToThread m_threads;
205  Mutex m_mutex;
206  bool m_sslInit;
207  int m_verify;
208  SSL_CTX *m_ctx;
209  X509_STORE *m_revocationStore;
210  std::string m_password;
211 };
213 }
214 
215 #endif // FIX_THREADEDSOCKETACCEPTOR_H
216 
217 #endif
FIX::thread_id
pthread_t thread_id
Definition: Utility.h:190
Acceptor.h
ThreadedSSLSocketConnection.h
Mutex.h
THREAD_PROC
#define THREAD_PROC
Definition: Utility.h:184
FIX
Definition: Acceptor.cpp:34

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