summaryrefslogtreecommitdiff
path: root/server/modules
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2015-09-10 00:15:07 +0300
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2015-09-10 00:15:07 +0300
commitccffc685c412183b56f822438da5cc8a575d757e (patch)
tree4ff9b3abb4ac1d94941ff5aa5aee9ee4cbe74a3e /server/modules
parentb5af51e358073145cdf66470cc890d98547a6dac (diff)
client-qt:
handle disconnect basic downloads model (still draft with unimplemented basic features like dynamic columns count, dynamic columns will be implemented next) basic handler for download list (in theory it's already working now, but untested) basic modules info handler (just store data in memory for now, all basic features still unimplemented, download info ui templates generation will be implemented next here) basic core info handler (just store data in memory for now, core settings and core info ui will be implemented next here.) server: api: added client metadata manipulation api for downloader modules added metadata map to download structure in downloader modules curl_downloader: implemented new api's
Diffstat (limited to 'server/modules')
-rw-r--r--server/modules/downloaders/curl/main.cpp58
-rw-r--r--server/modules/downloaders/curl/main.h7
2 files changed, 65 insertions, 0 deletions
diff --git a/server/modules/downloaders/curl/main.cpp b/server/modules/downloaders/curl/main.cpp
index b3a2f36..f3da19e 100644
--- a/server/modules/downloaders/curl/main.cpp
+++ b/server/modules/downloaders/curl/main.cpp
@@ -166,6 +166,64 @@ download_s downloader::get_download(int download_id, std::map<int, std::string>
return d;
}
+std::string compute_var_name(int download_id, std::string setting_name)
+{
+ std::string var_name = "download_";
+ char id_s[64];
+ snprintf(id_s, 63, "%d", download_id);
+ var_name += id_s;
+ var_name += "_";
+ var_name += setting_name;
+ return var_name;
+}
+
+bool downloader::metadata_set(int download_id, std::map<std::string, std::string> metadata)
+{
+ downloads[download_id].metadata = metadata;
+ for(auto i : downloads[download_id].metadata)
+ api->metadata_set(this, compute_var_name(download_id, i.first), std::vector<char>(i.second.begin(), i.second.end()));
+ return true;
+}
+
+bool downloader::metadata_update(int download_id, std::map<std::string, std::string> metadata)
+{
+ for(auto i : metadata)
+ downloads[download_id].metadata[i.first] = i.second;
+ for(auto i : downloads[download_id].metadata)
+ api->metadata_set(this, compute_var_name(download_id, i.first), std::vector<char>(i.second.begin(), i.second.end()));
+ return true;
+}
+
+bool downloader::metadata_drop(int download_id, std::string var)
+{
+ if(!var.empty())
+ {
+ downloads[download_id].metadata.erase(var);
+ api->metadata_remove(this, compute_var_name(download_id, var));
+ }
+ else
+ {
+ for(auto i : downloads[download_id].metadata)
+ api->metadata_remove(this, compute_var_name(download_id, i.first));
+ downloads[download_id].metadata.clear();
+ }
+ return true;
+}
+std::map<std::string, std::string> downloader::metadata_get(int download_id)
+{
+ return downloads[download_id].metadata;
+}
+
+std::string downloader::metadata_get(int download_id, std::string var)
+{
+ auto i = downloads[download_id].metadata.find(var);
+ if(i != downloads[download_id].metadata.end())
+ return i->second;
+ return std::string();
+}
+
+
+
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
index 4c4cbe9..f5e589b 100644
--- a/server/modules/downloaders/curl/main.h
+++ b/server/modules/downloaders/curl/main.h
@@ -48,6 +48,13 @@ public:
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(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
+ //downloader metadata manipulations
+ bool metadata_set(int download_id, std::map<std::string, std::string> metadata); //replace download metadata with provided one
+ bool metadata_update(int download_id, std::map<std::string, std::string> metadata); //updated matching metadata entries, create non existent
+ bool metadata_drop(int download_id, std::string var = std::string()); //remove all metadata if no variable specified, otherwise delete specified variable
+ std::map<std::string, std::string> metadata_get(int download_id); //get download metadata
+ std::string metadata_get(int download_id, std::string var); //get value of specified metadata variable
+
private:
void on_modules_loaded();
std::map<int, my_download> downloads; //map of id, download