summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/api_core.cpp2
-rw-r--r--server/src/api_core_events.cpp36
-rw-r--r--server/src/client.cpp2
-rw-r--r--server/src/event_subscription_event.cpp2
-rw-r--r--server/src/event_subscription_repeated.cpp2
-rw-r--r--server/src/main.cpp4
-rw-r--r--server/src/modules_handler.cpp2
-rw-r--r--server/src/protocol.cpp2
-rw-r--r--server/src/server.cpp9
-rw-r--r--server/src/server_session.cpp5
-rw-r--r--server/src/utilities.cpp2
11 files changed, 58 insertions, 10 deletions
diff --git a/server/src/api_core.cpp b/server/src/api_core.cpp
index aa5b58c..aa2c17f 100644
--- a/server/src/api_core.cpp
+++ b/server/src/api_core.cpp
@@ -1,6 +1,6 @@
/*
- Copyright © 2015 Gluzskiy Alexandr (sss)
+ Copyright © 2015-2016 Gluzskiy Alexandr (sss)
This file is part of Unknown Download Manager (UDM).
diff --git a/server/src/api_core_events.cpp b/server/src/api_core_events.cpp
new file mode 100644
index 0000000..0259973
--- /dev/null
+++ b/server/src/api_core_events.cpp
@@ -0,0 +1,36 @@
+/*
+ Copyright © 2016 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/>.
+
+*/
+
+
+#include <list>
+
+#include "api_core_events.h"
+#include "server_session.h"
+
+extern std::list<server_session*> sessions;
+
+namespace core_events
+{
+
+void core_events::download_state_changed(int download_id, download_state state)
+{
+}
+
+};
diff --git a/server/src/client.cpp b/server/src/client.cpp
index 20d519a..67acdb0 100644
--- a/server/src/client.cpp
+++ b/server/src/client.cpp
@@ -1,5 +1,5 @@
/*
- Copyright © 2015 Gluzskiy Alexandr (sss)
+ Copyright © 2015-2016 Gluzskiy Alexandr (sss)
This file is part of Unknown Download Manager (UDM).
diff --git a/server/src/event_subscription_event.cpp b/server/src/event_subscription_event.cpp
index f209f67..a702d60 100644
--- a/server/src/event_subscription_event.cpp
+++ b/server/src/event_subscription_event.cpp
@@ -1,5 +1,5 @@
/*
- Copyright © 2015 Gluzskiy Alexandr (sss)
+ Copyright © 2015-2016 Gluzskiy Alexandr (sss)
This file is part of Unknown Download Manager (UDM).
diff --git a/server/src/event_subscription_repeated.cpp b/server/src/event_subscription_repeated.cpp
index bc41f7a..4291dfa 100644
--- a/server/src/event_subscription_repeated.cpp
+++ b/server/src/event_subscription_repeated.cpp
@@ -1,5 +1,5 @@
/*
- Copyright © 2015 Gluzskiy Alexandr (sss)
+ Copyright © 2015-2016 Gluzskiy Alexandr (sss)
This file is part of Unknown Download Manager (UDM).
diff --git a/server/src/main.cpp b/server/src/main.cpp
index 5ca4422..47dba02 100644
--- a/server/src/main.cpp
+++ b/server/src/main.cpp
@@ -1,5 +1,5 @@
/*
- Copyright © 2015 Gluzskiy Alexandr (sss)
+ Copyright © 2015-2016 Gluzskiy Alexandr (sss)
This file is part of Unknown Download Manager (UDM).
@@ -47,6 +47,8 @@ runtime_config_s runtime_config;
std::map<int, download_internal_s> downloads;
+std::list<server_session*> sessions; //sessions to access from apis for modules, should be mutex guarded fro thread safety
+
server *serv = nullptr;
diff --git a/server/src/modules_handler.cpp b/server/src/modules_handler.cpp
index 90328b1..4b65a02 100644
--- a/server/src/modules_handler.cpp
+++ b/server/src/modules_handler.cpp
@@ -1,5 +1,5 @@
/*
- Copyright © 2015 Gluzskiy Alexandr (sss)
+ Copyright © 2015-2016 Gluzskiy Alexandr (sss)
This file is part of Unknown Download Manager (UDM).
diff --git a/server/src/protocol.cpp b/server/src/protocol.cpp
index 976857a..fe080ef 100644
--- a/server/src/protocol.cpp
+++ b/server/src/protocol.cpp
@@ -1,5 +1,5 @@
/*
- Copyright © 2015 Gluzskiy Alexandr (sss)
+ Copyright © 2015-2016 Gluzskiy Alexandr (sss)
This file is part of Unknown Download Manager (UDM).
diff --git a/server/src/server.cpp b/server/src/server.cpp
index 9eb44f4..3c769d3 100644
--- a/server/src/server.cpp
+++ b/server/src/server.cpp
@@ -1,5 +1,5 @@
/*
- Copyright © 2015 Gluzskiy Alexandr (sss)
+ Copyright © 2015-2016 Gluzskiy Alexandr (sss)
This file is part of Unknown Download Manager (UDM).
@@ -28,6 +28,8 @@
#include "../../protocol/udm.pb.h"
#include "socket_wraper.h"
+extern std::list<server_session*> sessions;
+
@@ -49,6 +51,7 @@ server::server(boost::asio::io_service& io_service,runtime_config_s &config, std
void server::start_accept()
{
server_session* new_session = new server_session(io_service_, runtime_config, clients, downloads);
+ sessions.push_back(new_session);
if(runtime_config.config_file.get<bool>("server.enable_encryption", false))
acceptor_.async_accept(new_session->socket()->get_ssl_socket().lowest_layer(), boost::bind(&server::handle_accept, this, new_session, boost::asio::placeholders::error));
else
@@ -63,6 +66,10 @@ void server::handle_accept(server_session* new_session, const boost::system::err
}
else
{
+ //TODO: implement thread safety ?
+ auto s = std::find(sessions.begin(), sessions.end(), new_session);
+ if(s != sessions.end())
+ sessions.erase(s);
delete new_session;
}
start_accept();
diff --git a/server/src/server_session.cpp b/server/src/server_session.cpp
index a79d5b6..5a15e5b 100644
--- a/server/src/server_session.cpp
+++ b/server/src/server_session.cpp
@@ -1,5 +1,5 @@
/*
- Copyright © 2015 Gluzskiy Alexandr (sss)
+ Copyright © 2015-2016 Gluzskiy Alexandr (sss)
This file is part of Unknown Download Manager (UDM).
@@ -271,6 +271,7 @@ void add_download_content_menu_element(module_download_menu_element_info_s &elem
bool server_session::handle_command(client_msg *msg)
{
+ //TODO: thread safety ?
if(msg->type() != CLIENT_MSG_TYPE::CLIENT_AUTH_REQUEST && clients.find(msg->auth_token()) == clients.end())
{
BOOST_LOG_TRIVIAL(error)<<"unauthorized client trying to execute command";
@@ -631,6 +632,7 @@ void server_session::send_download_list()
void server_session::send_message(server_msg *msg)
{
+ //TODO: thread safety
int size = 0;
std::shared_ptr<char*> ptr = pack_msg(msg, &size);
boost::asio::async_write(*socket_, boost::asio::buffer(*ptr, size), boost::bind(&server_session::handle_write, this, boost::asio::placeholders::error));
@@ -653,6 +655,7 @@ void server_session::handle_write(const boost::system::error_code& error)
void server_session::fire_event(SUBSCRIPTION_TYPE type, server_msg &msg)
{
+ //TODO: thread safety
for(auto i : clients)
{
for(auto s : i.second->get_subscriptions())
diff --git a/server/src/utilities.cpp b/server/src/utilities.cpp
index c8510c9..41d5264 100644
--- a/server/src/utilities.cpp
+++ b/server/src/utilities.cpp
@@ -1,5 +1,5 @@
/*
- Copyright © 2015 Gluzskiy Alexandr (sss)
+ Copyright © 2015-2016 Gluzskiy Alexandr (sss)
This file is part of Unknown Download Manager (UDM).