diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2015-08-27 01:25:05 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2015-08-27 01:25:05 +0300 |
commit | ba8247eaf522e8a129b7fbbf09a6fab010746e3a (patch) | |
tree | f87e5abdc7f049c819131c853d84db9660e8fde4 | |
parent | 3175fbe96c91a2de6f687d5c6bfe0fc7f02a34f4 (diff) |
protocol:
still thinking of...
client:
bits of proto implementation
server:
config variables
sigint handler
bits of proto implementation
-rw-r--r-- | client-qt/udm-client-qt/udm_main.cpp | 16 | ||||
-rw-r--r-- | protocol/udm.proto | 33 | ||||
-rw-r--r-- | server/docs/udm.conf.sample | 12 | ||||
-rw-r--r-- | server/include/config.h | 1 | ||||
-rw-r--r-- | server/modules/downloaders/curl/curl.cbp | 1 | ||||
-rw-r--r-- | server/src/main.cpp | 52 | ||||
-rw-r--r-- | server/src/modules_handler.cpp | 22 | ||||
-rw-r--r-- | server/src/server_session.cpp | 34 |
8 files changed, 141 insertions, 30 deletions
diff --git a/client-qt/udm-client-qt/udm_main.cpp b/client-qt/udm-client-qt/udm_main.cpp index 17744aa..3f94450 100644 --- a/client-qt/udm-client-qt/udm_main.cpp +++ b/client-qt/udm-client-qt/udm_main.cpp @@ -173,7 +173,7 @@ void udm_main::server_message_received(server_msg msg) //request modules and settings here { client_msg msg; - msg.set_type(CLIENT_MSG_TYPE::CLIENT_CORE_SETTINGS_REQUEST); + msg.set_type(CLIENT_MSG_TYPE::CLIENT_CORE_INFO_REQUEST); session->send_message(msg); } { @@ -197,6 +197,20 @@ void udm_main::server_message_received(server_msg msg) } break; + case SERVER_MSG_TYPE::SERVER_CORE_INFO_REPLY: + { + } + break; + case SERVER_MSG_TYPE::SERVER_MODULES_REPLY: + { + + } + break; + case SERVER_MSG_TYPE::SERVER_DOWNLOADS_LIST_REPLY: + { + + } + break; default: break; } diff --git a/protocol/udm.proto b/protocol/udm.proto index 2dd0ebf..a801b00 100644 --- a/protocol/udm.proto +++ b/protocol/udm.proto @@ -34,9 +34,10 @@ enum MODULE_UI_ELEMENT_TYPE { message module_download_ui_element_info { optional MODULE_UI_ELEMENT_TYPE type = 1 [default = UI_EMPTY]; - repeated module_download_ui_element_info children = 2; - required int32 id = 3; //internal element id used to get element value (should be unique for every loaded module) - optional string name = 4 [default = "not set"]; //can be non unique + required int32 id = 2; //internal element id used to get element value (should be unique for every loaded module) + optional string name = 3 [default = "not set"]; //can be non unique + optional string description = 4; + repeated module_download_ui_element_info children = 5; } message module_download_menu_element_info { @@ -192,9 +193,8 @@ message setting { //module related messages begin enum SERVER_MODULE_TYPE { - SERVER_MODULE_CORE = 0; - SERVER_MODULE_DOWNLOADER = 1; - SERVER_MODULE_METADATA_STORAGE = 2; + SERVER_MODULE_DOWNLOADER = 0; + SERVER_MODULE_METADATA_STORAGE = 1; } message string_pair @@ -204,13 +204,13 @@ message string_pair } -message module_info +message module_info //general module info for client including settings, download info ui and module specific menus { required SERVER_MODULE_TYPE type = 1; required string name = 2; //unique (used as module id) required string version = 3; optional string decription = 4 [default = "no description specified"]; - repeated setting_info settings = 5; + repeated setting settings = 5; repeated module_download_ui_element_info download_info_ui = 6; //always complete here repeated module_download_ui_element_info download_creation_ui = 7; repeated module_download_menu_element_info download_menu = 8; @@ -220,6 +220,17 @@ message module_info //module related messages end +//core related messages begin + +message core_info //core info for client currently for editable server settings, server version and proto version only +{ + optional int32 proto_version = 1 [default = 1]; + required int32 version = 2; + repeated setting settings = 3; +} + +//core related messages end + //auth proto part begin @@ -266,7 +277,7 @@ enum CLIENT_MSG_TYPE { CLIENT_DATA_TRANSFER_REQUEST = 1; CLIENT_UI_DATA_REQUEST = 2; CLIENT_MODULES_REQUEST = 3; - CLIENT_CORE_SETTINGS_REQUEST = 4; + CLIENT_CORE_INFO_REQUEST = 4; CLIENT_SUBSCRIPTIONS_REQUEST = 5; CLIENT_UNSUBSCRIPTIONS_REQUEST = 6; CLIENT_DOWNLOADS_LIST_REQUEST = 7; @@ -288,7 +299,7 @@ enum SERVER_MSG_TYPE { SERVER_AUTH_REPLY = 0; SERVER_UI_DATA_REPLY = 1; SERVER_MODULES_REPLY = 2; - SERVER_CORE_SETTINGS_REPLY = 3; + SERVER_CORE_INFO_REPLY = 3; SERVER_SUBSCRIPTIONS_REPLY = 4; SERVER_UNSUBSCRIPTIONS_REPLY = 5; SERVER_DOWNLOADS_LIST_REPLY = 6; @@ -301,7 +312,7 @@ message server_msg { optional server_download_ui_data_reply download_ui_data_reply = 2; optional server_auth_reply auth_reply = 3; repeated module_info server_modules_reply = 4; - optional module_info server_core_settings_reply = 5; + optional core_info server_core_info_reply = 5; repeated server_event_subscription_reply subscription_reply = 6; repeated server_event_unsubscription_reply unsubscription_reply = 7; optional server_downloads_reply downloads = 8; diff --git a/server/docs/udm.conf.sample b/server/docs/udm.conf.sample index 97b9cbb..e26b524 100644 --- a/server/docs/udm.conf.sample +++ b/server/docs/udm.conf.sample @@ -4,14 +4,14 @@ server ;section for core server settings { ;port 6613; server port ;password "client_passwod"; client password to connect - ;default_download_directory ~/udm_downloads ; default directory to store downloads + ;default_download_directory ~/udm/downloads ; default directory to store downloads ;default_metadata_module flat_files_metadata ; first loaded metadata module used by default if not set - ;default_data_storage_module <not set> ; first loaded data_storage module used by default if not set - ;daemon false ; for to background on startup (0 or 1) - ;verbosiry false; set server log level (higher is more noisy, also affects modules) - ;enable_encription 0; use tls encryption for client<-> server connection + ;default_data_storage_module <not set> ; first loaded data_storage module used by default if not set (not implemented) + ;daemon false ; for to background on startup (false or true) + ;verbosity 0; set server log level (higher is more noisy, also affects modules) + ;enable_encryption 0; use tls encryption for client<-> server connection ;ssl_certificate /path/to/cert/file.pem ; path to server certificate ;ssl_key /path/to/key/file.pem ; server certificate key + ;ssl_ca /path/to/ca/file.pem ; ca file to verify clients ;ssl_dh /path/to/dh/file ; dh parameters for ssl encryption - ;download_dir ~/.udm/downloads ; directory for downloads } diff --git a/server/include/config.h b/server/include/config.h index 2afbde3..74112ad 100644 --- a/server/include/config.h +++ b/server/include/config.h @@ -48,6 +48,7 @@ struct runtime_config_s { default_metadata_storage = nullptr; } + std::string config_file_path; }; diff --git a/server/modules/downloaders/curl/curl.cbp b/server/modules/downloaders/curl/curl.cbp index b0971b5..cec0d49 100644 --- a/server/modules/downloaders/curl/curl.cbp +++ b/server/modules/downloaders/curl/curl.cbp @@ -41,6 +41,7 @@ </Compiler> <Linker> <Add library="boost_system" /> + <Add library="curl" /> </Linker> <Unit filename="include/curl_download.h" /> <Unit filename="main.cpp" /> 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; } |