OSDN Git Service

Created some changes for autotool
[ultramonkey-l7/sslproxy.git] / include / sslproxysession.h
1 /*
2  * @file  sslproxysession.h
3  * @brief SSLproxy session Header
4  *
5  * Copyright (C) 2008  NTT COMWARE Corporation.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  **********************************************************************
23  *
24  * Distributed under the Boost Software Licence, Version 1.0
25  * http://www.boost.org/LICENSE_1_0.txt
26  *
27  **********************************************************************/
28
29 #ifndef __SSLPROXYSESSION_H__
30 #define __SSLPROXYSESSION_H__
31
32 #include <boost/asio.hpp>
33 #include <boost/asio/ssl.hpp>
34 #include <boost/thread.hpp>
35
36 //! SSL socket for client.
37 typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket>  ssl_socket;
38
39 //! TCP socket for server. (target)
40 typedef boost::asio::ip::tcp::socket    nomal_socket;
41
42 class sslproxy_session
43 {
44 protected:
45         nomal_socket                                    server_socket;
46         ssl_socket                                      client_socket;
47         boost::asio::ip::tcp::resolver::iterator        endpoint_iterator;
48         boost::asio::deadline_timer                     timer;
49         int                                             cancel_time;
50         char                                            client_buffer[MAX_BUFFER_SIZE];
51         char                                            server_buffer[MAX_BUFFER_SIZE];
52         bool                                            handshaked;
53         bool                                            istimeout;
54         bool                                            c_r_event;
55         bool                                            c_w_event;
56         bool                                            s_r_event;
57         bool                                            s_w_event;
58         bool                                            finishing;
59         pthread_mutex_t                                 client_socket_mutex;
60         boost::asio::deadline_timer                     cache_timer;
61
62 public:
63         // constructor
64         sslproxy_session(boost::asio::io_service& ioservice,
65                          boost::asio::ssl::context& context,
66                          boost::asio::ip::tcp::resolver::iterator itr);
67         // destructor
68         ~sslproxy_session();
69         // Low level socket getting function.
70         ssl_socket::lowest_layer_type& low_socket();
71         // Get remote endpoint (client address:port) function.
72         std::string get_remote_endpoint() const;
73         // Session start function
74         void start();
75         // Timer cancel function.
76         void cancel(const boost::system::error_code& error);
77         // Cache expire function.
78         void cache_expire(const boost::system::error_code& error);
79         // Session destroy function.
80         void destroy_session(sslproxy_session* session);
81         // Handshake handling function.
82         void handle_handshake(const boost::system::error_code& error);
83         // Connect handling function.
84         void handle_connect(const boost::system::error_code& error);
85         // Client read handling function.
86         void handle_client_read(const boost::system::error_code& error, size_t bytes_transferred);
87         // Server write handling function.
88         void handle_server_write(const boost::system::error_code& error, size_t bytes_transferred);
89         // Server read handling function.
90         void handle_server_read(const boost::system::error_code& error, size_t bytes_transferred);
91         // Client write handling function.
92         void handle_client_write(const boost::system::error_code& error, size_t bytes_transferred);
93     // Edit client message function.
94         void edit_client_message(size_t& bytes_transferred);
95     // Edit server message function.
96         void edit_server_message(size_t& bytes_transferred);
97 };
98
99 #endif //__SSLPROXYSESSION_H__