summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2016-01-16 09:01:18 +0300
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2016-01-16 09:01:18 +0300
commitbb8cd8a9ff7d80046cc2c7d41742c74d8f811c62 (patch)
tree9353ecb0293fd89b8d08d893332ca7e912c3efa3
parent454ed688836c9de52039b84ea381ffd22890a6e8 (diff)
i am alive )
updated copyrights (new year) server: started implementation of api for module events (module should be able to fire event which will be delivered to clients which have subscribed for this event type)
-rw-r--r--protocol/auth.proto2
-rw-r--r--protocol/core.proto2
-rw-r--r--protocol/download.proto2
-rw-r--r--protocol/events.proto2
-rw-r--r--protocol/misc.proto2
-rw-r--r--protocol/module.proto2
-rw-r--r--protocol/settings.proto2
-rw-r--r--protocol/udm.proto2
-rw-r--r--protocol/ui.proto2
-rw-r--r--server/include/api_core.h5
-rw-r--r--server/include/api_core_events.h38
-rw-r--r--server/include/api_module_base.h2
-rw-r--r--server/include/api_module_downloader.h2
-rw-r--r--server/include/api_module_metadata_storage.h2
-rw-r--r--server/include/client.h2
-rw-r--r--server/include/config.h2
-rw-r--r--server/include/download_internal.h2
-rw-r--r--server/include/event_subscription_base.h2
-rw-r--r--server/include/event_subscription_event.h2
-rw-r--r--server/include/event_subscription_repeated.h2
-rw-r--r--server/include/main.h2
-rw-r--r--server/include/modules_handler.h2
-rw-r--r--server/include/protocol.h2
-rw-r--r--server/include/server.h2
-rw-r--r--server/include/server_session.h8
-rw-r--r--server/include/socket_wraper.h2
-rw-r--r--server/include/utilities.h2
-rw-r--r--server/modules/downloaders/curl/include/curl_download.h24
-rw-r--r--server/modules/downloaders/curl/main.cpp2
-rw-r--r--server/modules/downloaders/curl/main.h2
-rw-r--r--server/modules/downloaders/curl/src/curl_download.cpp31
-rw-r--r--server/modules/metadata/flat_files/main.cpp2
-rw-r--r--server/modules/metadata/flat_files/main.h2
-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
-rw-r--r--server/udm-server.project2
45 files changed, 182 insertions, 50 deletions
diff --git a/protocol/auth.proto b/protocol/auth.proto
index a39d2ad..d77bde4 100644
--- a/protocol/auth.proto
+++ b/protocol/auth.proto
@@ -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/protocol/core.proto b/protocol/core.proto
index 53f887a..bc93902 100644
--- a/protocol/core.proto
+++ b/protocol/core.proto
@@ -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/protocol/download.proto b/protocol/download.proto
index 7684db3..c043bfe 100644
--- a/protocol/download.proto
+++ b/protocol/download.proto
@@ -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/protocol/events.proto b/protocol/events.proto
index 8521e55..84903cf 100644
--- a/protocol/events.proto
+++ b/protocol/events.proto
@@ -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/protocol/misc.proto b/protocol/misc.proto
index 152c7f5..dd0a7b9 100644
--- a/protocol/misc.proto
+++ b/protocol/misc.proto
@@ -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/protocol/module.proto b/protocol/module.proto
index 2376b7b..3e94dc7 100644
--- a/protocol/module.proto
+++ b/protocol/module.proto
@@ -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/protocol/settings.proto b/protocol/settings.proto
index ff0e9a3..e66b329 100644
--- a/protocol/settings.proto
+++ b/protocol/settings.proto
@@ -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/protocol/udm.proto b/protocol/udm.proto
index 8b09867..bc0eac1 100644
--- a/protocol/udm.proto
+++ b/protocol/udm.proto
@@ -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/protocol/ui.proto b/protocol/ui.proto
index 387e17c..2a215cc 100644
--- a/protocol/ui.proto
+++ b/protocol/ui.proto
@@ -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/include/api_core.h b/server/include/api_core.h
index adf0a70..33ed70f 100644
--- a/server/include/api_core.h
+++ b/server/include/api_core.h
@@ -1,5 +1,5 @@
/*
- Copyright © 2015 Gluzskiy Alexandr (sss)
+ Copyright © 2015-2016 Gluzskiy Alexandr (sss)
This file is part of Unknown Download Manager (UDM).
@@ -26,10 +26,11 @@
#include <map>
#include "settings.h"
+#include "api_core_events.h"
class module_base;
-class core_api
+class core_api : public core_events::core_events
{
public:
//core
diff --git a/server/include/api_core_events.h b/server/include/api_core_events.h
new file mode 100644
index 0000000..e7e0dac
--- /dev/null
+++ b/server/include/api_core_events.h
@@ -0,0 +1,38 @@
+/*
+ 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/>.
+
+*/
+
+#ifndef API_CORE_EVENTS_H
+#define API_CORE_EVENTS_H
+
+namespace core_events
+{
+
+enum download_state {download_stopped, download_running, download_completed, download_error};
+
+class core_events
+{
+public:
+ virtual void download_state_changed(int download_id, download_state state);
+};
+
+};
+
+
+#endif
diff --git a/server/include/api_module_base.h b/server/include/api_module_base.h
index 9c1b639..42deee9 100644
--- a/server/include/api_module_base.h
+++ b/server/include/api_module_base.h
@@ -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/include/api_module_downloader.h b/server/include/api_module_downloader.h
index 6445772..703683e 100644
--- a/server/include/api_module_downloader.h
+++ b/server/include/api_module_downloader.h
@@ -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/include/api_module_metadata_storage.h b/server/include/api_module_metadata_storage.h
index adaa614..cbc1642 100644
--- a/server/include/api_module_metadata_storage.h
+++ b/server/include/api_module_metadata_storage.h
@@ -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/include/client.h b/server/include/client.h
index 22b2ce8..e755fac 100644
--- a/server/include/client.h
+++ b/server/include/client.h
@@ -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/include/config.h b/server/include/config.h
index 74112ad..58a8aae 100644
--- a/server/include/config.h
+++ b/server/include/config.h
@@ -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/include/download_internal.h b/server/include/download_internal.h
index 60d9608..92280a9 100644
--- a/server/include/download_internal.h
+++ b/server/include/download_internal.h
@@ -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/include/event_subscription_base.h b/server/include/event_subscription_base.h
index 4cae7e1..b181dfd 100644
--- a/server/include/event_subscription_base.h
+++ b/server/include/event_subscription_base.h
@@ -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/include/event_subscription_event.h b/server/include/event_subscription_event.h
index 16172cf..7d39183 100644
--- a/server/include/event_subscription_event.h
+++ b/server/include/event_subscription_event.h
@@ -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/include/event_subscription_repeated.h b/server/include/event_subscription_repeated.h
index 3b2936b..fc0d857 100644
--- a/server/include/event_subscription_repeated.h
+++ b/server/include/event_subscription_repeated.h
@@ -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/include/main.h b/server/include/main.h
index 4921e36..e5c88ed 100644
--- a/server/include/main.h
+++ b/server/include/main.h
@@ -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/include/modules_handler.h b/server/include/modules_handler.h
index 7c8bc71..bec2fe3 100644
--- a/server/include/modules_handler.h
+++ b/server/include/modules_handler.h
@@ -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/include/protocol.h b/server/include/protocol.h
index 7aa9c93..c6020a4 100644
--- a/server/include/protocol.h
+++ b/server/include/protocol.h
@@ -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/include/server.h b/server/include/server.h
index e8fb3ad..4a3b3fe 100644
--- a/server/include/server.h
+++ b/server/include/server.h
@@ -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/include/server_session.h b/server/include/server_session.h
index b03a38b..c0220f0 100644
--- a/server/include/server_session.h
+++ b/server/include/server_session.h
@@ -1,5 +1,5 @@
/*
- Copyright © 2015 Gluzskiy Alexandr (sss)
+ Copyright © 2015-2016 Gluzskiy Alexandr (sss)
This file is part of Unknown Download Manager (UDM).
@@ -41,7 +41,8 @@ public:
std::map<int, download_internal_s>& downloads,
boost::asio::ssl::context* c = nullptr);
void run();
- void send_message(server_msg* msg);
+ void send_message(server_msg* msg); //TODO: thread safety
+ void fire_event(SUBSCRIPTION_TYPE type, server_msg &msg);
socket_wraper* socket();
virtual ~server_session();
@@ -53,10 +54,9 @@ private:
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);
- bool handle_command(client_msg* msg);
+ bool handle_command(client_msg* msg); //TODO: thread safety ?
void send_download_list();
- void fire_event(SUBSCRIPTION_TYPE type, server_msg &msg);
char* recv_data_ = nullptr;
socket_wraper* socket_ = nullptr;
diff --git a/server/include/socket_wraper.h b/server/include/socket_wraper.h
index 6e8dd76..8619580 100644
--- a/server/include/socket_wraper.h
+++ b/server/include/socket_wraper.h
@@ -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/include/utilities.h b/server/include/utilities.h
index aa78d29..40eb38f 100644
--- a/server/include/utilities.h
+++ b/server/include/utilities.h
@@ -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/modules/downloaders/curl/include/curl_download.h b/server/modules/downloaders/curl/include/curl_download.h
index 6956ce4..514d4f2 100644
--- a/server/modules/downloaders/curl/include/curl_download.h
+++ b/server/modules/downloaders/curl/include/curl_download.h
@@ -1,11 +1,29 @@
+/*
+ Copyright © 2015-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/>.
+
+*/
+
#ifndef CURL_DOWNLOAD_H
#define CURL_DOWNLOAD_H
#include <api_module_downloader.h>
#include <curl/curl.h>
-enum download_state {download_running, download_stopped};
-
class curl_download : public download_s
{
public:
@@ -27,7 +45,7 @@ class curl_download : public download_s
void perform_internal();
CURL *easy_handle = nullptr;
bool cancel_transfer = false;
- download_state state = download_stopped;
+ core_events::download_state state = core_events::download_stopped;
std::string download_path;
};
diff --git a/server/modules/downloaders/curl/main.cpp b/server/modules/downloaders/curl/main.cpp
index 1a5e02b..c21d8b3 100644
--- a/server/modules/downloaders/curl/main.cpp
+++ b/server/modules/downloaders/curl/main.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/modules/downloaders/curl/main.h b/server/modules/downloaders/curl/main.h
index 7040d8b..85569f6 100644
--- a/server/modules/downloaders/curl/main.h
+++ b/server/modules/downloaders/curl/main.h
@@ -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/modules/downloaders/curl/src/curl_download.cpp b/server/modules/downloaders/curl/src/curl_download.cpp
index 29bdc21..9df06a1 100644
--- a/server/modules/downloaders/curl/src/curl_download.cpp
+++ b/server/modules/downloaders/curl/src/curl_download.cpp
@@ -1,3 +1,23 @@
+/*
+ Copyright © 2015-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 "curl_download.h"
#include <boost/thread.hpp>
@@ -41,14 +61,14 @@ curl_download::curl_download(std::map<int, std::string> params, core_api *a)
bool curl_download::start()
{
boost::thread(boost::bind(&curl_download::perform_internal, this));
- state = download_running;
+ state = core_events::download_running;
return true; //TODO:
}
bool curl_download::stop()
{
cancel_transfer = true;
- state = download_stopped;
+ state = core_events::download_stopped;
return true; //TODO:
}
@@ -61,7 +81,12 @@ bool curl_download::delete_download()
void curl_download::perform_internal()
{
- curl_easy_perform(easy_handle);
+ auto status = curl_easy_perform(easy_handle);
+ if(status != CURLE_OK)
+ state = core_events::download_error;
+ else
+ state = core_events::download_completed;
+ //TODO: fire event
}
curl_download::~curl_download()
diff --git a/server/modules/metadata/flat_files/main.cpp b/server/modules/metadata/flat_files/main.cpp
index 079644f..f58f782 100644
--- a/server/modules/metadata/flat_files/main.cpp
+++ b/server/modules/metadata/flat_files/main.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/modules/metadata/flat_files/main.h b/server/modules/metadata/flat_files/main.h
index df62488..eec9f6a 100644
--- a/server/modules/metadata/flat_files/main.h
+++ b/server/modules/metadata/flat_files/main.h
@@ -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/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).
diff --git a/server/udm-server.project b/server/udm-server.project
index d8d0899..bc75b55 100644
--- a/server/udm-server.project
+++ b/server/udm-server.project
@@ -39,6 +39,7 @@
<File Name="src/utilities.cpp"/>
<File Name="src/event_subscription_event.cpp"/>
<File Name="src/event_subscription_repeated.cpp"/>
+ <File Name="src/api_core_events.cpp"/>
</VirtualDirectory>
<VirtualDirectory Name="include">
<File Name="../protocol/udm.pb.h"/>
@@ -59,6 +60,7 @@
<File Name="include/event_subscription_base.h"/>
<File Name="include/event_subscription_event.h"/>
<File Name="include/event_subscription_repeated.h"/>
+ <File Name="include/api_core_events.h"/>
</VirtualDirectory>
<Dependencies Name="Debug"/>
<VirtualDirectory Name="protocol">