summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-03-21 19:39:05 +0200
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-03-21 19:39:05 +0200
commitd14df4141a0a881875ae5b36b481508612469fde (patch)
treebe942151741c3cc58067714d56fb334be8ad3720
parentcd7e6b14fae54b023076f1338952a4a100a99648 (diff)
send exactly content of cli_config without defaults, with less verification
-rwxr-xr-xserver/server/config.cpp66
-rwxr-xr-xserver/server/config.h23
-rwxr-xr-xserver/server/main.cpp79
3 files changed, 36 insertions, 132 deletions
diff --git a/server/server/config.cpp b/server/server/config.cpp
index ac0f95e..ad5e3e0 100755
--- a/server/server/config.cpp
+++ b/server/server/config.cpp
@@ -75,18 +75,31 @@ void config::load_cvars()
{
std::ifstream config;
config.open(cli_config_path.c_str(), std::fstream::in);
- if(config.is_open())
+ if(!config.is_open())
+ return;
+ if(!cvars.empty())
+ cvars.clear();
+ std::string cfg_str((std::istreambuf_iterator<char>(config)), std::istreambuf_iterator<char>());
+ config.close();
+ if(!cfg_str.empty())
{
- std::string cfg_str((std::istreambuf_iterator<char>(config)), std::istreambuf_iterator<char>());
- config.close();
- cvars.config_update_interval = get_int(cfg_str, "config_update_interval=", 300);
- cvars.client_update_interval = get_int(cfg_str, "client_update_interval=", 60000);
- cvars.welcome_msg = get_string(cfg_str, "welcome_msg=", "");
- cvars.cfg_downloaded_msg = get_string(cfg_str, "config_downloaded_msg=", "");
- cvars.top_text = get_string(cfg_str, "top_panel_text=", "");
- cvars.bottom_text = get_string(cfg_str, "bottom_panel_text=", "");
- cvars.speed_visibility = get_int(cfg_str, "speed_visibility=", 1);
+ std::string::size_type p1 = 0, p2 = 0, l = 1;
+ if(cfg_str.find("\r\n") != std::string::npos)
+ l = 2;
+ p2 = cfg_str.find(';');
+ while(p2 != std::string::npos)
+ {
+ cvars.push_back(cfg_str.substr(p1, p2-p1));
+ p1 = p2+l+1;
+ p2 = cfg_str.find(';', p1);
+ }
}
+/* cvars.config_update_interval = get_int(cfg_str, "config_update_interval=", 300);
+ cvars.client_update_interval = get_int(cfg_str, "client_update_interval=", 60000);
+ cvars.welcome_msg = get_string(cfg_str, "welcome_msg=", "");
+ cvars.top_text = get_string(cfg_str, "top_panel_text=", "");
+ cvars.bottom_text = get_string(cfg_str, "bottom_panel_text=", "");
+ cvars.speed_visibility = get_int(cfg_str, "speed_visibility=", 1); */
}
config::config(const char *pth): cfg_reload_thr(NULL), speed_test_thr(NULL)
@@ -551,40 +564,11 @@ bool config::ignore_ssl_errors()
return vars.ignore_ssl_errors;
}
-const int config::c_cfg_upd_int()
+std::list<std::string>* config::cli_cfg()
{
- return cvars.config_update_interval;
+ return &cvars;
}
-const int config::c_cli_upd_int()
-{
- return cvars.client_update_interval;
-}
-
-bool config::c_speed_visibility()
-{
- return cvars.speed_visibility;
-}
-
-const std::string& config::c_welcome_msg()
-{
- return cvars.welcome_msg;
-}
-
-const std::string& config::c_cfg_download_msg()
-{
- return cvars.cfg_downloaded_msg;
-}
-
-const std::string& config::c_top_text()
-{
- return cvars.top_text;
-}
-
-const std::string& config::c_bottom_text()
-{
- return cvars.bottom_text;
-}
const std::string& config::speed_test_file_url()
{
return vars.speed_test_file_url;
diff --git a/server/server/config.h b/server/server/config.h
index 5f2ea40..318831e 100755
--- a/server/server/config.h
+++ b/server/server/config.h
@@ -120,13 +120,7 @@ public:
const int check_interval();
const int debug();
const int dos_conn_count();
- const int c_cfg_upd_int();
- const int c_cli_upd_int();
- bool c_speed_visibility();
- const std::string& c_welcome_msg();
- const std::string& c_cfg_download_msg();
- const std::string& c_top_text();
- const std::string& c_bottom_text();
+ std::list<std::string>* cli_cfg();
void load_vars();
void load_cvars();
void load_proxy_list(char* pth = NULL);
@@ -167,26 +161,13 @@ private:
speed_test_file_url = "http://localhost/speed.test";
}
};
- struct cli_cfg_data
- {
- int config_update_interval, client_update_interval;
- std::string welcome_msg, cfg_downloaded_msg, top_text, bottom_text;
- bool speed_visibility;
- cli_cfg_data()
- {
- config_update_interval = 300;
- client_update_interval = 60000;
- speed_visibility = false;
- }
- };
std::string config_path, cli_config_path;
const int get_int(const std::string& data, const char* var, int default_);
const std::string get_string(const std::string& data, const char* var, const std::string& default_);
cfg_data vars;
- cli_cfg_data cvars;
std::list<proxy_entry> proxy_list;
std::list<static_proxy_entry> static_proxy_list;
- std::list<std::string> firewall_list, deleted_list;
+ std::list<std::string> firewall_list, deleted_list, cvars;
std::list<upload_entry> upload_list;
std::list<conn_server> servers_list;
boost::thread *cfg_reload_thr, *speed_test_thr;
diff --git a/server/server/main.cpp b/server/server/main.cpp
index 4ac3c83..96af597 100755
--- a/server/server/main.cpp
+++ b/server/server/main.cpp
@@ -224,78 +224,17 @@ void session::proto_parser(std::vector<byte>& data)
data.push_back('\n');
}
}
- std::string s = "config_update_interval=";
- for(int i = 0; i < s.size(); ++i)
- data.push_back(s[i]);
- char buf[10];
- snprintf(buf, 9, "%d", cfg->c_cfg_upd_int());
- int len = strlen(buf);
- for(int i = 0; i < len; ++i)
- data.push_back(buf[i]);
- data.push_back(';');
- data.push_back('\r');
- data.push_back('\n');
- s = "client_update_interval=";
- for(int i = 0; i < s.size(); ++i)
- data.push_back(s[i]);
- snprintf(buf, 9, "%d", cfg->c_cli_upd_int());
- len = strlen(buf);
- for(int i = 0; i < len; ++i)
- data.push_back(buf[i]);
- data.push_back(';');
- data.push_back('\r');
- data.push_back('\n');
- if(!cfg->c_welcome_msg().empty())
+ if(!cfg->cli_cfg()->empty())
{
- s = "welcome_msg=";
- for(int i = 0; i < s.size(); ++i)
- data.push_back(s[i]);
- for(int i = 0; i < cfg->c_welcome_msg().size(); ++i)
- data.push_back(cfg->c_welcome_msg()[i]);
- data.push_back(';');
- data.push_back('\r');
- data.push_back('\n');
- }
- if(!cfg->c_cfg_download_msg().empty())
- {
- s = "config_downloaded_msg=";
- for(int i = 0; i < s.size(); ++i)
- data.push_back(s[i]);
- for(int i = 0; i < cfg->c_cfg_download_msg().size(); ++i)
- data.push_back(cfg->c_cfg_download_msg()[i]);
- data.push_back(';');
- data.push_back('\r');
- data.push_back('\n');
- }
- if(!cfg->c_top_text().empty())
- {
- s = "top_panel_text=";
- for(int i = 0; i < s.size(); ++i)
- data.push_back(s[i]);
- for(int i = 0; i < cfg->c_top_text().size(); ++i)
- data.push_back(cfg->c_top_text()[i]);
- data.push_back(';');
- data.push_back('\r');
- data.push_back('\n');
- }
- if(!cfg->c_bottom_text().empty())
- {
- s = "bottom_panel_text=";
- for(int i = 0; i < s.size(); ++i)
- data.push_back(s[i]);
- for(int i = 0; i < cfg->c_bottom_text().size(); ++i)
- data.push_back(cfg->c_bottom_text()[i]);
- data.push_back(';');
- data.push_back('\r');
- data.push_back('\n');
+ for(std::list<std::string>::iterator i = cfg->cli_cfg()->begin(), end = cfg->cli_cfg()->end(); i != end; ++i)
+ {
+ for(int ii = 0; ii < i->size(); ++ii)
+ data.push_back((*i)[ii]);
+ data.push_back(';');
+ data.push_back('\r');
+ data.push_back('\n');
+ }
}
- s = "speed_visibility=";
- for(int i = 0; i < s.size(); ++i)
- data.push_back(s[i]);
- data.push_back(cfg->c_speed_visibility()?'1':'0');
- data.push_back(';');
- data.push_back('\r');
- data.push_back('\n');
data.push_back(0x14);
data.push_back(0x14);
write_w_response(data);