summaryrefslogtreecommitdiff
path: root/server/include
diff options
context:
space:
mode:
Diffstat (limited to 'server/include')
-rw-r--r--server/include/config.h55
-rw-r--r--server/include/main.h16
-rw-r--r--server/include/server.h2
-rw-r--r--server/include/server_session.h12
-rw-r--r--server/include/socket_wraper.h105
5 files changed, 170 insertions, 20 deletions
diff --git a/server/include/config.h b/server/include/config.h
new file mode 100644
index 0000000..2afbde3
--- /dev/null
+++ b/server/include/config.h
@@ -0,0 +1,55 @@
+/*
+ Copyright © 2015 Gluzskiy Alexandr (sss)
+
+ This file is part of Unknown Download Manager (UDM).
+
+ UDM is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ UDM is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with UDM. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#ifndef CONFIG_H_INCLUDED
+#define CONFIG_H_INCLUDED
+
+#include <boost/property_tree/ptree.hpp>
+#include <boost/property_tree/info_parser.hpp>
+
+namespace bpt = boost::property_tree;
+
+class module_metadata_storage;
+
+struct settings_s
+{
+ settings_s()
+ {
+ verbosity = 0;
+ }
+ short verbosity;
+};
+
+struct runtime_config_s
+{
+ //TODO: define metadata and data storage modules per module alongside with default ones
+ bpt::ptree config_file;
+ module_metadata_storage *default_metadata_storage;
+ settings_s settings;
+ runtime_config_s()
+ {
+ default_metadata_storage = nullptr;
+ }
+};
+
+
+
+#endif
diff --git a/server/include/main.h b/server/include/main.h
index 71769b8..4921e36 100644
--- a/server/include/main.h
+++ b/server/include/main.h
@@ -24,22 +24,6 @@
#include "api_module_metadata_storage.h"
-#include <boost/property_tree/ptree.hpp>
-#include <boost/property_tree/info_parser.hpp>
-
-namespace bpt = boost::property_tree;
-
-struct runtime_config_s{
- //TODO: define metadata and data storage modules per module alongside with default ones
- bpt::ptree config_file;
- module_metadata_storage *default_metadata_storage;
- short verbosity;
- runtime_config_s()
- {
- verbosity = 0;
- default_metadata_storage = nullptr;
- }
-};
diff --git a/server/include/server.h b/server/include/server.h
index 83d3b5b..c4ccc97 100644
--- a/server/include/server.h
+++ b/server/include/server.h
@@ -23,6 +23,7 @@
#define SERVER_H
#include <boost/asio.hpp>
+#include <boost/asio/ssl.hpp>
//TODO ssl
@@ -40,6 +41,7 @@ private:
boost::asio::io_service& io_service_;
boost::asio::ip::tcp::acceptor acceptor_;
+ boost::asio::ssl::context *context_;
};
diff --git a/server/include/server_session.h b/server/include/server_session.h
index 0f7fe62..330e0a9 100644
--- a/server/include/server_session.h
+++ b/server/include/server_session.h
@@ -23,28 +23,32 @@
#define SERVER_SESSION_H
#include <boost/asio.hpp>
+#include <boost/asio/ssl.hpp>
class client_msg;
class server_msg;
-
+class socket_wraper;
class server_session
{
public:
- server_session(boost::asio::io_service &s);
+ server_session(boost::asio::io_service &s, boost::asio::ssl::context *c = nullptr);
void run();
void send_message(server_msg *msg);
- boost::asio::ip::tcp::socket& socket();
+ socket_wraper* socket();
virtual ~server_session();
protected:
private:
void handle_read(const boost::system::error_code& error, size_t bytes_transferred);
void handle_write(const boost::system::error_code& error);
void handle_write_no_read(const boost::system::error_code& error);
+ void handle_handshake(const boost::system::error_code& error);
void handle_command(client_msg *msg);
char *recv_data_;
- boost::asio::ip::tcp::socket socket_;
+ socket_wraper *socket_;
+ boost::asio::io_service &io_service_;
+ boost::asio::ssl::context *context_;
};
diff --git a/server/include/socket_wraper.h b/server/include/socket_wraper.h
new file mode 100644
index 0000000..ed929ca
--- /dev/null
+++ b/server/include/socket_wraper.h
@@ -0,0 +1,105 @@
+/*
+ Copyright © 2015 Gluzskiy Alexandr (sss)
+
+ This file is part of Unknown Download Manager (UDM).
+
+ UDM is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ UDM is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with UDM. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#ifndef SOCKET_H_INCLUDED
+#define SOCKET_H_INCLUDED
+
+#include <boost/asio.hpp>
+#include <boost/asio/ssl.hpp>
+
+class socket_wraper
+{
+public:
+ socket_wraper(boost::asio::ssl::stream<boost::asio::ip::tcp::socket> *s) : is_ssl(true)
+ {
+ socket_ssl_ = s;
+ }
+
+ socket_wraper(boost::asio::ip::tcp::socket *s) : is_ssl(false)
+ {
+ socket_ = s;
+ }
+
+ void operator=(boost::asio::ssl::stream<boost::asio::ip::tcp::socket> *s)
+ {
+ socket_ssl_ = s;
+ is_ssl = true;
+ }
+ void operator=(boost::asio::ip::tcp::socket *s)
+ {
+ socket_ = s;
+ is_ssl = false;
+ }
+
+ boost::asio::ip::tcp::socket& get_socket()
+ {
+ return *socket_;
+ }
+
+ boost::asio::ssl::stream<boost::asio::ip::tcp::socket>& get_ssl_socket()
+ {
+ return *socket_ssl_;
+ }
+ template<typename MutableBufferSequence> std::size_t read_some(const MutableBufferSequence & buffers)
+ {
+ if(is_ssl)
+ return socket_ssl_->read_some(buffers);
+ else
+ return socket_->read_some(buffers);
+ }
+ template<typename MutableBufferSequence> std::size_t read_some(const MutableBufferSequence & buffers, boost::system::error_code & ec)
+ {
+ if(is_ssl)
+ return socket_ssl_->read_some(buffers, ec);
+ else
+ return socket_->read_some(buffers, ec);
+ }
+
+ template<typename MutableBufferSequence, typename ReadHandler> void async_read_some(const MutableBufferSequence & buffers, ReadHandler handler)
+ {
+ if(is_ssl)
+ socket_ssl_->async_read_some(buffers, handler);
+ else
+ socket_->async_read_some(buffers, handler);
+ }
+
+ template<typename ConstBufferSequence, typename WriteHandler> void async_write_some(const ConstBufferSequence & buffers, WriteHandler handler)
+ {
+ if(is_ssl)
+ socket_ssl_->async_write_some(buffers, handler);
+ else
+ socket_->async_write_some(buffers, handler);
+ }
+ ~socket_wraper()
+ {
+ if(is_ssl)
+ delete socket_ssl_;
+ else
+ delete socket_;
+ }
+private:
+ bool is_ssl;
+ boost::asio::ip::tcp::socket *socket_;
+ boost::asio::ssl::stream<boost::asio::ip::tcp::socket> *socket_ssl_;
+
+};
+
+
+#endif