KISSCPP
a C++ library for rapid application development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
connection.hpp
Go to the documentation of this file.
1 // File : connection.hpp
2 // Author: Dirk J. Botha <bothadj@gmail.com>
3 //
4 // This file is part of kisscpp library.
5 //
6 // The kisscpp library is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // The kisscpp library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with the kisscpp library. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef _SERVER_CONNECTION_HPP
20 #define _SERVER_CONNECTION_HPP
21 
22 #include <iostream>
23 #include <sstream>
24 #include <string>
25 
26 #include <boost/asio.hpp>
27 #include <boost/array.hpp>
28 #include <boost/noncopyable.hpp>
29 #include <boost/shared_ptr.hpp>
30 #include <boost/enable_shared_from_this.hpp>
31 #include <boost/asio/basic_streambuf.hpp>
32 
33 #include "boost_ptree.hpp"
34 #include "request_router.hpp"
35 #include "logstream.hpp"
36 #include "configuration.hpp"
37 
38 namespace kisscpp
39 {
40  // Represents a single connection from a client.
41  class Connection : public boost::enable_shared_from_this<Connection>,
42  private boost::noncopyable
43  {
44  public:
45  explicit Connection(boost::asio::io_service& io_service, RequestRouter& handler); // Construct a connection with the given io_service.
46 
47  ~Connection() { socket_.close(); };
48 
49  boost::asio::ip::tcp::socket& socket(); // Get the socket associated with the connection.
50 
51  void start();
52 
53  private:
54  bool allowedIpAddress(const std::string &ip_address);
55  bool allowedClient ();
56 
57  boost::asio::ip::tcp::socket socket_;
58  RequestRouter &request_router_;
59  boost::asio::streambuf incomming_stream_buffer_;
60  boost::asio::streambuf outgoing_stream_buffer_;
61  BoostPtree parsed_request_;
62  BoostPtree raw_response_;
63  };
64 
65  typedef boost::shared_ptr<Connection> ConnectionPtr;
66 }
67 
68 #endif
Definition: request_router.hpp:43
void start()
Definition: connection.cpp:39
boost::shared_ptr< Connection > ConnectionPtr
Definition: connection.hpp:65
boost::property_tree::ptree BoostPtree
Definition: boost_ptree.hpp:31
Connection(boost::asio::io_service &io_service, RequestRouter &handler)
Definition: connection.cpp:24
boost::asio::ip::tcp::socket & socket()
Definition: connection.cpp:32
~Connection()
Definition: connection.hpp:47
Definition: connection.hpp:41