summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/include/api_module_downloader.h10
-rw-r--r--server/modules/downloaders/curl/include/curl_download.h7
-rw-r--r--server/modules/downloaders/curl/main.cpp47
-rw-r--r--server/modules/downloaders/curl/main.h8
-rw-r--r--server/modules/downloaders/curl/src/curl_download.cpp20
5 files changed, 64 insertions, 28 deletions
diff --git a/server/include/api_module_downloader.h b/server/include/api_module_downloader.h
index 4a31085..ae91943 100644
--- a/server/include/api_module_downloader.h
+++ b/server/include/api_module_downloader.h
@@ -79,20 +79,20 @@ struct download_s {
int id;
std::string name; //id generated via download_add or via session restore and it's unique for current session and current dowloader
int64_t size, downloaded, download_speed; //download size and size of downloaded data, also download speed all vars in bytes
- std::map<std::string, std::string> info_map; //any additional info provided by downloader module can be stored here
+ std::map<int, std::string> info_map; //any additional info provided by downloader module can be stored here
std::list<download_content_entry_s> content; //download content can be set for download, structure described above
};
class module_downloader : public module_base
{
public:
- virtual int add_download(std::map<std::string, std::string> params) = 0; //add download, this function must return unique for current session and current downloader download id
+ virtual int add_download(std::map<int, std::string> params) = 0; //add download, this function must return unique for current session and current downloader download id
virtual bool stop_download(int download_id) = 0; //stop download by id received via add_download, return true on success, false otherwise
virtual bool start_download(int download_id) = 0; //start download by id received via add_download, return true on success, false otherwise
virtual bool delete_download(int download_id, bool delete_data = false) = 0; //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
- virtual bool execute_action_on_download(int download_id, std::string action_id) = 0; //execute module defined action on download, by id received via add_download
- virtual std::list<download_s> get_downloads(std::map<std::string, std::string> params = std::map<std::string, std::string>()) = 0; //this function must return list of downloads, additional options may be passed via params map
- virtual download_s get_download_info(int download_id, std::map<std::string, std::string> params = std::map<std::string, std::string>()) = 0; //same as above, except this one is for single download, not a complete list
+ virtual bool execute_action_on_download(int download_id, int action_id) = 0; //execute module defined action on download, by id received via add_download
+ virtual std::list<download_s> get_downloads(std::map<int, std::string> params = std::map<int, std::string>()) = 0; //this function must return list of downloads, additional options may be passed via params map
+ virtual download_s get_download_info(int download_id, std::map<int, std::string> params = std::map<int, std::string>()) = 0; //same as above, except this one is for single download, not a complete list
};
diff --git a/server/modules/downloaders/curl/include/curl_download.h b/server/modules/downloaders/curl/include/curl_download.h
index 1a43b29..e542de9 100644
--- a/server/modules/downloaders/curl/include/curl_download.h
+++ b/server/modules/downloaders/curl/include/curl_download.h
@@ -9,11 +9,12 @@ enum download_state {running, stopped};
class curl_download
{
public:
- curl_download(std::map<std::string, std::string> params, core_api *a);
+ curl_download(std::map<int, std::string> params, core_api *a);
virtual ~curl_download();
- void start();
- void stop();
+ bool start();
+ bool stop();
+ bool delete_download();
const bool get_cancel_state()
{
return cancel_transfer;
diff --git a/server/modules/downloaders/curl/main.cpp b/server/modules/downloaders/curl/main.cpp
index 17c8f67..66f89b4 100644
--- a/server/modules/downloaders/curl/main.cpp
+++ b/server/modules/downloaders/curl/main.cpp
@@ -77,15 +77,15 @@ void downloader::set_module_settings(const std::map<std::string, std::string> &s
}
-int downloader::add_download(std::map<std::string, std::string> params)
+int downloader::add_download(std::map<int, std::string> params)
{
curl_download *d = new curl_download(params, api);
my_download md;
std::string download_name;
{
- auto p1 = params["0"].rfind("/");
+ auto p1 = params[0].rfind("/");
if(p1 != std::string::npos)
- md.name = params["0"].substr(p1);
+ md.name = params[0].substr(p1);
}
md.curl_d = d;
int id = 0;
@@ -106,37 +106,64 @@ int downloader::add_download(std::map<std::string, std::string> params)
bool downloader::stop_download(int download_id)
{
//TODO:
+ bool status = downloads[download_id].curl_d->stop();
+ if(!status)
+ {
+ //TODO: handle error
+ return false;
+ }
return true;
}
bool downloader::start_download(int download_id)
{
//TODO:
+ bool status = downloads[download_id].curl_d->start();
+ if(!status)
+ {
+ //TODO: handle error
+ return false;
+ }
return true;
}
bool downloader::delete_download(int download_id, bool delete_data)
{
+ bool status = downloads[download_id].curl_d->delete_download();
+ if(!status)
+ {
+ //TODO: handle errror
+ return false;
+ }
+ else
+ {
+ downloads[download_id].curl_d = nullptr;
+ }
//TODO:
return true;
}
-bool downloader::execute_action_on_download(int download_id, std::string action_id)
+bool downloader::execute_action_on_download(int download_id, int action_id)
{
//TODO:
return true;
}
-std::list<download_s> downloader::get_downloads(std::map<std::string, std::string> params)
+std::list<download_s> downloader::get_downloads(std::map<int, std::string> params)
{
- //TODO:
- return std::list<download_s>();
+ std::list<download_s> l;
+ for(auto i : downloads)
+ l.push_back(i.second);
+ //TODO: fill aditional data fields
+
+ return l;
}
-download_s downloader::get_download_info(int download_id, std::map<std::string, std::string> params)
+download_s downloader::get_download_info(int download_id, std::map<int, std::string> params)
{
- //TODO:
- return download_s();
+ download_s d = downloads[download_id];
+ //TODO: fill additional data fields
+ return d;
}
extern "C" module_downloader* udm_downloader_module_load()
diff --git a/server/modules/downloaders/curl/main.h b/server/modules/downloaders/curl/main.h
index 2fa2a66..aff5cb3 100644
--- a/server/modules/downloaders/curl/main.h
+++ b/server/modules/downloaders/curl/main.h
@@ -41,13 +41,13 @@ public:
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
+ int add_download(std::map<int, 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
+ bool execute_action_on_download(int download_id, int action_id); //execute module defined action on download, by id received via add_download
+ std::list<download_s> get_downloads(std::map<int, std::string> params = std::map<int, 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<int, std::string> params = std::map<int, 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;
diff --git a/server/modules/downloaders/curl/src/curl_download.cpp b/server/modules/downloaders/curl/src/curl_download.cpp
index d474464..16866b5 100644
--- a/server/modules/downloaders/curl/src/curl_download.cpp
+++ b/server/modules/downloaders/curl/src/curl_download.cpp
@@ -17,7 +17,7 @@ size_t curl_w_callback(char *ptr, size_t size, size_t nmemb, void *userdata)
return size_;
}
-curl_download::curl_download(std::map<std::string, std::string> params, core_api *a) : cancel_transfer(false), state(stopped)
+curl_download::curl_download(std::map<int, std::string> params, core_api *a) : cancel_transfer(false), state(stopped)
{
//for now we use single transfer connection for url
//TODO: support multiple connections in parallel for multithreaded download
@@ -25,11 +25,11 @@ curl_download::curl_download(std::map<std::string, std::string> params, core_api
if(!easy_handle)
; //TODO: handle error
- curl_easy_setopt(easy_handle, CURLOPT_URL, params["0"].c_str()); //Url as set in module_info
+ curl_easy_setopt(easy_handle, CURLOPT_URL, params[0].c_str()); //Url as set in module_info
curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, curl_w_callback);
curl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, this);
- if(!params["0"].empty())
- download_path = params["0"];
+ if(!params[1].empty())
+ download_path = params[1];
else
download_path = a->get_core_settings()["download_dir"];
//curl_easy_setopt(h, CURLOPT_DEFAULT_PROTOCOL, "http"); //require curl >= 7.45
@@ -37,17 +37,25 @@ curl_download::curl_download(std::map<std::string, std::string> params, core_api
}
-void curl_download::start()
+bool curl_download::start()
{
boost::thread(boost::bind(&curl_download::perform_internal, this));
state = running;
+ return true; //TODO:
}
-void curl_download::stop()
+bool curl_download::stop()
{
cancel_transfer = true;
+ return true; //TODO:
}
+bool curl_download::delete_download()
+{
+ cancel_transfer = true;
+ curl_easy_cleanup(easy_handle);
+ return true; //TODO:
+}
void curl_download::perform_internal()
{