summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2015-08-27 01:25:05 +0300
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2015-08-27 01:25:05 +0300
commitba8247eaf522e8a129b7fbbf09a6fab010746e3a (patch)
treef87e5abdc7f049c819131c853d84db9660e8fde4 /server/src
parent3175fbe96c91a2de6f687d5c6bfe0fc7f02a34f4 (diff)
protocol:
still thinking of... client: bits of proto implementation server: config variables sigint handler bits of proto implementation
Diffstat (limited to 'server/src')
-rw-r--r--server/src/main.cpp52
-rw-r--r--server/src/modules_handler.cpp22
-rw-r--r--server/src/server_session.cpp34
3 files changed, 96 insertions, 12 deletions
diff --git a/server/src/main.cpp b/server/src/main.cpp
index 2786435..b856fd4 100644
--- a/server/src/main.cpp
+++ b/server/src/main.cpp
@@ -23,6 +23,8 @@
#include <iostream>
#include <map>
+#include <signal.h>
+
#include "api_module_metadata_storage.h"
#include "modules_handler.h"
#include "utilities.h"
@@ -47,9 +49,15 @@ server *serv = nullptr;
//TODO: "core" config section architecture, define base settings
+void sigint_handler(int sig)
+{
+ bpt::write_info(runtime_config.config_file_path, runtime_config.config_file); //save config on sigint
+ exit(0);
+}
-int main(int argc, char *argv[])
+extern "C" int main(int argc, char *argv[])
{
+ signal(SIGINT, sigint_handler);
bpo::options_description desc("Available commands and options");
desc.add_options()
("help,h", "this message")
@@ -78,6 +86,48 @@ int main(int argc, char *argv[])
bpt::read_info(parsed_config_path, runtime_config.config_file); //TODO: finish this
else
std::cerr<<"failed to load config: \"" + config_path + "\", file does not exists or is not regular file\n";
+ runtime_config.config_file_path = parsed_config_path;
+ }
+ {
+ auto server_pt = runtime_config.config_file.find("server");
+ if(server_pt == runtime_config.config_file.not_found())
+ {
+ runtime_config.config_file.put("server", "");
+ server_pt = runtime_config.config_file.find("server");
+ }
+ auto it = server_pt->second.find("port");
+ if(it == server_pt->second.not_found())
+ server_pt->second.put("port", 6613);
+ it = server_pt->second.find("password");
+ if(it == server_pt->second.not_found())
+ server_pt->second.put("password", "");
+ it = server_pt->second.find("default_download_directory");
+ if(it == server_pt->second.not_found())
+ server_pt->second.put("default_download_directory", "~/udm/downloads");
+ it = server_pt->second.find("default_metadata_module");
+ if(it == server_pt->second.not_found())
+ server_pt->second.put("default_metadata_module", "flat_files_metadata");
+ it = server_pt->second.find("daemon");
+ if(it == server_pt->second.not_found())
+ server_pt->second.put("daemon", false);
+ it = server_pt->second.find("verbosity");
+ if(it == server_pt->second.not_found())
+ server_pt->second.put("verbosity", 0);
+ it = server_pt->second.find("enable_encryption");
+ if(it == server_pt->second.not_found())
+ server_pt->second.put("enable_encryption", false);
+ it = server_pt->second.find("ssl_certificate");
+ if(it == server_pt->second.not_found())
+ server_pt->second.put("ssl_certificate", "~/config/udm/cert.crt");
+ it = server_pt->second.find("ssl_key");
+ if(it == server_pt->second.not_found())
+ server_pt->second.put("ssl_key", "~/config/udm/cert.key");
+ it = server_pt->second.find("ssl_ca");
+ if(it == server_pt->second.not_found())
+ server_pt->second.put("ssl_ca", "~/config/udm/ca.crt");
+ it = server_pt->second.find("ssl_dh");
+ if(it == server_pt->second.not_found())
+ server_pt->second.put("ssl_dh", "~/config/udm/dh.pem");
}
//load all config variables here
runtime_config.settings.verbosity = runtime_config.config_file.get<short>("server.verbosity", 0);
diff --git a/server/src/modules_handler.cpp b/server/src/modules_handler.cpp
index 78a6ad7..32c3b9f 100644
--- a/server/src/modules_handler.cpp
+++ b/server/src/modules_handler.cpp
@@ -123,21 +123,21 @@ std::string modules_handler::list_modules()
std::string modules_handler::list_modules_single_type_internal(const std::list<module_base*> &modules)
{
std::string buf;
- for(auto i = modules.begin(), end = modules.end(); i != end; ++i)
+ for(auto i : modules)
{
buf += "\tName: ";
- buf += (*i)->get_module_info().name;
- buf += "\n\tDescription: " +(*i)->get_module_info().description;
- buf += "\n\tVersion: " + (*i)->get_module_info().version;
+ buf += i->get_module_info().name;
+ buf += "\n\tDescription: " + i->get_module_info().description;
+ buf += "\n\tVersion: " + i->get_module_info().version;
if(runtime_config.settings.verbosity >= 1)
{
buf += "\n\tAvailable options:";
- for(auto i1 = (*i)->get_module_info().default_settings.begin(), end = (*i)->get_module_info().default_settings.end(); i1 != end; ++i1)
+ for(auto i1 : i->get_module_info().default_settings)
{
buf += "\n\t\t";
- buf += i1->first;
+ buf += i1.first;
buf += " = ";
- buf += i1->second;
+ buf += i1.second;
}
}
buf += "\n\n";
@@ -147,12 +147,12 @@ std::string modules_handler::list_modules_single_type_internal(const std::list<m
void modules_handler::sync_module_settings(module_base *m)
{
- for(auto i = m->get_module_info().default_settings.begin(), end = m->get_module_info().default_settings.end(); i != end; ++i)
+ for(auto i : m->get_module_info().default_settings)
{
- std::string setting = "modules." + m->get_module_info().name + "." + i->first;
- std::string current_val = runtime_config.config_file.get<std::string>(setting, "not set"), default_val = i->second;
+ std::string setting = "modules." + m->get_module_info().name + "." + i.first;
+ std::string current_val = runtime_config.config_file.get<std::string>(setting, "not set"), default_val = i.second;
if(current_val == "not set" || current_val != default_val)
- runtime_config.config_file.put(setting, i->second);
+ runtime_config.config_file.put(setting, i.second);
}
}
diff --git a/server/src/server_session.cpp b/server/src/server_session.cpp
index 25e7820..64f2cfe 100644
--- a/server/src/server_session.cpp
+++ b/server/src/server_session.cpp
@@ -190,6 +190,40 @@ void server_session::handle_command(client_msg *msg)
send_message(&m);
}
break;
+ case CLIENT_MSG_TYPE::CLIENT_MODULES_REQUEST:
+ {
+ //TODO:
+ }
+ break;
+ case CLIENT_MSG_TYPE::CLIENT_CORE_INFO_REQUEST:
+ {
+ server_msg msg;
+ msg.set_type(SERVER_MSG_TYPE::SERVER_CORE_INFO_REPLY);
+ msg.mutable_server_core_info_reply()->set_version(1);
+ 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;
+ setting *i = msg.mutable_server_core_info_reply()->add_settings();
+ i->set_name(it.first);
+ //TODO: is it possible to set something better than just list of core setting names ?
+ }
+ }
+ catch(...)
+ {
+ //TODO:
+ }
+ send_message(&msg);
+
+ }
+ break;
+ case CLIENT_MSG_TYPE::CLIENT_DOWNLOADS_LIST_REQUEST:
+ {
+ //TODO:
+ }
+ break;
default:
break;
}