ThreadedSSLSocketInitiator.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_THREADEDSSLSOCKETINITIATOR_H
118 #define FIX_THREADEDSSLSOCKETINITIATOR_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 "Initiator.h"
128 #include <map>
129 
130 namespace FIX
131 {
135 class ThreadedSSLSocketInitiator : public Initiator
137 {
138 public:
139  ThreadedSSLSocketInitiator(Application &, MessageStoreFactory &,
140  const SessionSettings &) throw(ConfigError);
141  ThreadedSSLSocketInitiator(Application &, MessageStoreFactory &,
142  const SessionSettings &,
143  LogFactory &) throw(ConfigError);
144 
145  virtual ~ThreadedSSLSocketInitiator();
146 
147  void setPassword(const std::string &pwd) { m_password.assign(pwd); }
148 
149  void setCertAndKey(X509 *cert, RSA *key)
150  {
151  m_cert = cert;
152  m_key = key;
153  }
154 
155  int passwordHandleCallback(char *buf, size_t bufsize, int verify, void *job);
156 
157  static int passwordHandleCB(char *buf, int bufsize, int verify, void *job);
158 
159 private:
160  typedef std::pair< int, SSL * > SocketKey;
161  typedef std::map< SocketKey, thread_id > SocketToThread;
162  typedef std::map< SessionID, int > SessionToHostNum;
163  typedef std::pair< ThreadedSSLSocketInitiator *,
164  ThreadedSSLSocketConnection * > ThreadPair;
165 
166  void onConfigure(const SessionSettings &) throw(ConfigError);
167  void onInitialize(const SessionSettings &) throw(RuntimeError);
168 
169  void onStart();
170  bool onPoll(double timeout);
171  void onStop();
172 
173  void doConnect(const SessionID &s, const Dictionary &d);
174 
175  void addThread(SocketKey s, thread_id t);
176  void removeThread(SocketKey s);
177  void lock() { Locker l(m_mutex); }
178  static THREAD_PROC socketThread(void *p);
179 
180  void getHost(const SessionID &, const Dictionary &, std::string &, short &);
181 
182  SessionToHostNum m_sessionToHostNum;
183  time_t m_lastConnect;
184  int m_reconnectInterval;
185  bool m_noDelay;
186  int m_sendBufSize;
187  int m_rcvBufSize;
188  SocketToThread m_threads;
189  Mutex m_mutex;
190  bool m_sslInit;
191  SSL_CTX *m_ctx;
192  std::string m_password;
193  X509 *m_cert;
194  RSA *m_key;
195 };
197 }
198 
199 #endif // FIX_THREADEDSOCKETINITIATOR_H
200 
201 #endif
FIX::thread_id
pthread_t thread_id
Definition: Utility.h:190
Initiator.h
ThreadedSSLSocketConnection.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