summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2015-08-23 13:51:45 +0300
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2015-08-23 13:51:45 +0300
commit9dcd333d8f7ac35cadffd03325a0f72933a0dcc7 (patch)
tree608536f2616e410cf1b69f1424b784f5d297d818
parentc77cb85e69a830d3b41ba1d55fdc7ff69d330491 (diff)
server:
started first downloader module implementation added api to get core settings downloads_dir in config
-rw-r--r--server/docs/udm.conf.sample1
-rw-r--r--server/include/api_core.h1
-rw-r--r--server/modules/downloaders/curl/curl.cbp46
-rw-r--r--server/modules/downloaders/curl/main.cpp107
-rw-r--r--server/modules/downloaders/curl/main.h53
-rw-r--r--server/src/api_core.cpp35
-rw-r--r--server/src/modules_handler.cpp16
-rw-r--r--udm.workspace1
8 files changed, 246 insertions, 14 deletions
diff --git a/server/docs/udm.conf.sample b/server/docs/udm.conf.sample
index 47a5642..97b9cbb 100644
--- a/server/docs/udm.conf.sample
+++ b/server/docs/udm.conf.sample
@@ -13,4 +13,5 @@ server ;section for core server settings
;ssl_certificate /path/to/cert/file.pem ; path to server certificate
;ssl_key /path/to/key/file.pem ; server certificate key
;ssl_dh /path/to/dh/file ; dh parameters for ssl encryption
+ ;download_dir ~/.udm/downloads ; directory for downloads
}
diff --git a/server/include/api_core.h b/server/include/api_core.h
index 7dcec4d..341bfc2 100644
--- a/server/include/api_core.h
+++ b/server/include/api_core.h
@@ -33,6 +33,7 @@ class core_api
public:
//core
virtual std::map<std::string, std::string> get_module_settings(module_base *m);
+ virtual std::map<std::string, std::string> get_core_settings();
//metadata
virtual bool metadata_set(module_base *m, const std::string &setting_name, const std::vector<char> &data);
diff --git a/server/modules/downloaders/curl/curl.cbp b/server/modules/downloaders/curl/curl.cbp
new file mode 100644
index 0000000..f9ded9a
--- /dev/null
+++ b/server/modules/downloaders/curl/curl.cbp
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_project_file>
+ <FileVersion major="1" minor="6" />
+ <Project>
+ <Option title="curl" />
+ <Option pch_mode="2" />
+ <Option compiler="gcc" />
+ <Build>
+ <Target title="Debug">
+ <Option output="bin/Debug/curl" prefix_auto="1" extension_auto="1" />
+ <Option object_output="obj/Debug/" />
+ <Option type="3" />
+ <Option compiler="gcc" />
+ <Option createDefFile="1" />
+ <Option createStaticLib="1" />
+ <Compiler>
+ <Add option="-g" />
+ </Compiler>
+ </Target>
+ <Target title="Release">
+ <Option output="bin/Release/curl" prefix_auto="1" extension_auto="1" />
+ <Option object_output="obj/Release/" />
+ <Option type="3" />
+ <Option compiler="gcc" />
+ <Option createDefFile="1" />
+ <Option createStaticLib="1" />
+ <Compiler>
+ <Add option="-O2" />
+ </Compiler>
+ <Linker>
+ <Add option="-s" />
+ </Linker>
+ </Target>
+ </Build>
+ <Compiler>
+ <Add option="-Wall" />
+ <Add option="-fexceptions -fPIC" />
+ </Compiler>
+ <Unit filename="main.cpp" />
+ <Unit filename="main.h" />
+ <Extensions>
+ <code_completion />
+ <debugger />
+ </Extensions>
+ </Project>
+</CodeBlocks_project_file>
diff --git a/server/modules/downloaders/curl/main.cpp b/server/modules/downloaders/curl/main.cpp
new file mode 100644
index 0000000..bafd2fb
--- /dev/null
+++ b/server/modules/downloaders/curl/main.cpp
@@ -0,0 +1,107 @@
+
+/*
+ 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/>.
+
+*/
+
+#include "main.h"
+#include <boost/bind.hpp>
+
+
+
+module_base::~module_base()
+{
+}
+
+
+downloader::downloader()
+{
+}
+
+void downloader::on_modules_loaded()
+{
+}
+
+void downloader::load(core_api *a)
+{
+ api = a;
+
+ info.name = "curl";
+ info.description = "basic http/ftp downloader via libcurl, also example how to write downloader modules";
+ info.version = "0.0.0.1draft";
+ info.on_modules_loaded = boost::bind(&downloader::on_modules_loaded, this); //optional definition of function which is called after all modules loaded
+}
+
+const module_info &downloader::get_module_info()
+{
+ return info;
+}
+
+void downloader::set_module_settings(const std::map<std::string, std::string> &settings)
+{
+ this->settings = settings;
+}
+
+
+int add_download(std::map<std::string, std::string> params)
+{
+ //TODO:
+ return 0;
+}
+
+bool stop_download(int download_id)
+{
+ //TODO:
+ return true;
+}
+
+bool start_download(int download_id)
+{
+ //TODO:
+ return true;
+}
+
+bool delete_download(int download_id, bool delete_data)
+{
+ //TODO:
+ return true;
+}
+
+bool execute_action_on_download(int download_id, std::string action_id)
+{
+ //TODO:
+ return true;
+}
+
+std::list<download_s> get_downloads(std::map<std::string, std::string> params)
+{
+ //TODO:
+ return std::list<download_s>();
+}
+
+download_s get_download_info(int download_id, std::map<std::string, std::string> params)
+{
+ //TODO:
+ return download_s();
+}
+
+extern "C" module_downloader* udm_downloader_module_load()
+{
+ return new downloader;
+}
+
diff --git a/server/modules/downloaders/curl/main.h b/server/modules/downloaders/curl/main.h
new file mode 100644
index 0000000..16580ec
--- /dev/null
+++ b/server/modules/downloaders/curl/main.h
@@ -0,0 +1,53 @@
+/*
+ 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 MAIN_H_INCLUDED
+#define MAIN_H_INCLUDED
+
+#include <api_module_downloader.h>
+
+class downloader : public module_downloader
+{
+public:
+ //core module api
+ downloader();
+ void load(core_api *a);
+ const module_info &get_module_info();
+ void set_module_settings(const std::map<std::string, std::string> &settings); //will called with settings stored in config
+ ~downloader();
+ //downloader module api
+ int add_download(std::map<std::string, std::string> params); //add download, this function must return unique for current session and current downloader download id
+ bool stop_download(int download_id); //stop download by id received via add_download, return true on success, false otherwise
+ bool start_download(int download_id); //start download by id received via add_download, return true on success, false otherwise
+ bool delete_download(int download_id, bool delete_data = false); //delete download by id received via add_download, if "delete_data" is set, also remove all downloaded data from storage, return true on success, false otherwise
+ bool execute_action_on_download(int download_id, std::string action_id); //execute module defined action on download, by id received via add_download
+ std::list<download_s> get_downloads(std::map<std::string, std::string> params = std::map<std::string, std::string>()); //this function must return list of downloads, additional options may be passed via params map
+ download_s get_download_info(int download_id, std::map<std::string, std::string> params = std::map<std::string, std::string>()); //same as above, except this one is for single download, not a complete list
+private:
+ void on_modules_loaded();
+ downloader_module_info info;
+ core_api *api = nullptr;
+ std::map<std::string, std::string> settings;
+};
+
+
+
+#endif // MAIN_H_INCLUDED
diff --git a/server/src/api_core.cpp b/server/src/api_core.cpp
index 66df614..b407928 100644
--- a/server/src/api_core.cpp
+++ b/server/src/api_core.cpp
@@ -30,7 +30,6 @@ extern runtime_config_s runtime_config;
bool core_api::metadata_set(module_base *m, const std::string &setting_name, const std::vector<char> &data)
{
- //TODO: respect per module metadata modules definition
//print data
/* std::cout<<"printing data in core set api:\n";
for(auto i = data.begin(), end = data.end(); i != end; ++i)
@@ -44,27 +43,51 @@ bool core_api::metadata_set(module_base *m, const std::string &setting_name, con
bool core_api::metadata_get(module_base *m, const std::string &setting_name, std::vector<char> &data)
{
- //TODO
runtime_config.default_metadata_storage->get(m->get_module_info().name, setting_name, data);
return true;
}
bool core_api::metadata_remove(module_base *m, const std::string &setting_name)
{
- //TODO
runtime_config.default_metadata_storage->remove(m->get_module_info().name, setting_name);
return true;
}
std::map<std::string, std::string> core_api::get_module_settings(module_base *m)
{
- //TODO:
std::map<std::string, std::string> settings;
std::string module = "modules.";
module += m->get_module_info().name;
- for(auto i = runtime_config.config_file.get_child(module).begin(), end = runtime_config.config_file.get_child(module).end(); i != end; ++i)
+ try{
+ for(auto i : runtime_config.config_file.get_child(module))
{
- settings[i->first] = i->second.get_value<std::string>("");
+ settings[i.first] = i.second.get_value<std::string>("");
+ }
+ }
+ catch(...)
+ {
+ //TODO:
}
return settings;
}
+
+
+std::map<std::string, std::string> core_api::get_core_settings()
+{
+ std::map<std::string, std::string> settings_;
+ try{
+ for(auto it : runtime_config.config_file.get_child("server")) //load server node
+ {
+ std::string val = it.second.get_value<std::string>("empty_value"); //TODO: something better here. we need to avoid subtrees and empty vars
+ if(val == "" || val == "empty_value")
+ continue;
+
+ settings_[it.first] = it.second.get_value<std::string>("");
+ }
+ }
+ catch(...)
+ {
+ //TODO:
+ }
+ return settings_;
+}
diff --git a/server/src/modules_handler.cpp b/server/src/modules_handler.cpp
index 65148ef..78a6ad7 100644
--- a/server/src/modules_handler.cpp
+++ b/server/src/modules_handler.cpp
@@ -49,7 +49,7 @@ void modules_handler::load_metadata_modules(const std::string &path)
if(!lib)
{
printf("failed to open library \"%s\" with error: %s\n", i->path().c_str(), dlerror());
- return;
+ continue;
}
void *fptr = dlsym(lib, "udm_metadata_module_load");
@@ -57,7 +57,7 @@ void modules_handler::load_metadata_modules(const std::string &path)
{
printf("failed to find symbol \"udm_metadata_module_load\" in library %s with error %s\n", i->path().c_str(), dlerror());
dlclose(lib);
- return;
+ continue;
}
module_metadata_storage *(*f)(void);
f = (module_metadata_storage *(*)(void))fptr;
@@ -76,18 +76,18 @@ void modules_handler::load_downloader_modules(const std::string &path)
{
for(boost::filesystem::directory_iterator i(path), end = boost::filesystem::directory_iterator(); i != end; ++i)
{
- void *lib = dlopen(i->path().generic_string().c_str(), RTLD_LAZY);
+ void *lib = dlopen(i->path().generic_string().c_str(), RTLD_LAZY |RTLD_GLOBAL);
if(!lib)
{
printf("failed to open library \"%s\" with error: %s\n", i->path().c_str(), dlerror());
- return;
+ continue;
}
void *fptr = dlsym(lib, "udm_downloader_module_load");
if(!fptr)
{
printf("failed to find symbol \"udm_downloader_module_load\" in library %s with error %s\n", i->path().c_str(), dlerror());
dlclose(lib);
- return;
+ continue;
}
module_downloader *(*f)(void);
f = (module_downloader *(*)(void))fptr;
@@ -169,9 +169,9 @@ void modules_handler::load_modules()
load_metadata_modules(self_dir + "/modules/metadata");
load_metadata_modules(replace_home_var("~/.share/udm/modules/metadata"));
load_metadata_modules("/usr/lib/udm/modules/metadata");
- load_downloader_modules(self_dir + "/modules/downloader");
- load_downloader_modules(replace_home_var("~/.share/udm/modules/downloader"));
- load_downloader_modules("/usr/lib/udm/modules/downloader");
+ load_downloader_modules(self_dir + "/modules/downloaders");
+ load_downloader_modules(replace_home_var("~/.share/udm/modules/downloaders"));
+ load_downloader_modules("/usr/lib/udm/modules/downloaders");
load_modules_settings();
}
diff --git a/udm.workspace b/udm.workspace
index 26a7646..9531397 100644
--- a/udm.workspace
+++ b/udm.workspace
@@ -3,5 +3,6 @@
<Workspace title="udm">
<Project filename="server/udm-server.cbp" />
<Project filename="server/modules/metadata/flat_files/flat_files.cbp" />
+ <Project filename="server/modules/downloaders/curl/curl.cbp" />
</Workspace>
</CodeBlocks_workspace_file>