summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2011-10-18 02:09:24 +0300
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2011-10-18 02:09:24 +0300
commitb7c741ecba97c00d8f5ade3ea388fe42a4511b04 (patch)
treea8c376f4a4405734419bb790de228a9380f0846d
parent0bbdc1dbe38965efa0de8cc3147935e62898849a (diff)
парсер статических проксей
примеры конфингов
-rw-r--r--server/server/config.cpp62
-rw-r--r--server/server/config.h11
-rw-r--r--server/server/config_samples/proxy_list.cfg3
-rw-r--r--server/server/config_samples/static_proxy_list.cfg2
4 files changed, 72 insertions, 6 deletions
diff --git a/server/server/config.cpp b/server/server/config.cpp
index 264ba22..53386a4 100644
--- a/server/server/config.cpp
+++ b/server/server/config.cpp
@@ -20,6 +20,7 @@ config::config(const char *pth)
vars.log_path = get_string(cfg_str, "LogPath=", "./server.log");
vars.dos_log_path = get_string(cfg_str, "DosLogPath=", "./server_dos.log");
load_proxy_list();
+ load_static_proxy_list();
}
const int config::get_int(const std::string& data, const char* var, int default_)
{
@@ -85,13 +86,13 @@ void config::load_proxy_list(char *pth)
port = atoi(line.substr(lp1, lp2-lp1).c_str());
lp1 = lp2+2;
lp2 = line.find('"', lp1);
- country = line.substr(lp1, lp2-lp1).c_str();
+ country = line.substr(lp1, lp2-lp1);
lp1 = lp2+3;
lp2 = line.find('"', lp1);
- state = line.substr(lp1, lp2-lp1).c_str();
+ state = line.substr(lp1, lp2-lp1);
lp1 = lp2+3;
lp2 = line.find('"', lp1);
- city = line.substr(lp1, lp2-lp1).c_str();
+ city = line.substr(lp1, lp2-lp1);
}
else
{
@@ -102,13 +103,13 @@ void config::load_proxy_list(char *pth)
port = atoi(line.substr(lp1, lp2-lp1).c_str());
lp1 = lp2+2;
lp2 = line.find('"', lp1);
- country = line.substr(lp1, lp2-lp1).c_str();
+ country = line.substr(lp1, lp2-lp1);
lp1 = lp2+3;
lp2 = line.find('"', lp1);
- state = line.substr(lp1, lp2-lp1).c_str();
+ state = line.substr(lp1, lp2-lp1);
lp1 = lp2+3;
lp2 = line.find('"', lp1);
- city = line.substr(lp1, lp2-lp1).c_str();
+ city = line.substr(lp1, lp2-lp1);
}
proxy_list.push_back(proxy_entry(login, password, host, port, country, state, city));
p2 = cfg_str.find(';', p1);
@@ -125,6 +126,55 @@ void config::load_static_proxy_list(char *pth)
config.open(pth, std::fstream::in);
std::string cfg_str((std::istreambuf_iterator<char>(config)), std::istreambuf_iterator<char>());
config.close();
+ if(!cfg_str.empty())
+ {
+ std::string::size_type p1 = 0, p2 = 0;
+ p2 = cfg_str.find(';');
+ while(p2 != std::string::npos)
+ {
+ std::string line = cfg_str.substr(p1, p2-p1);
+ p1 = p2+1;
+ std::string::size_type lp1 = 0, lp2 = 0;
+ std::string host, login, password, label;
+ int port = 0, position = 0;
+ if(line.find('@') != std::string::npos)
+ {
+ lp2 = line.find(':', lp1);
+ login = line.substr(lp1, lp2-lp1);
+ lp1 = lp2+1;
+ lp2 = line.find('@', lp1);
+ password = line.substr(lp1, lp2-lp1);
+ lp1 = lp2+1;
+ lp2 = line.find(':', lp1);
+ host = line.substr(lp1, lp2-lp1);
+ lp1 = lp2+1;
+ lp2 = line.find("\x20", lp1);
+ port = atoi(line.substr(lp1, lp2-lp1).c_str());
+ lp1 = lp2+2;
+ lp2 = line.find('"', lp1);
+ label = line.substr(lp1, lp2-lp1);
+ lp1 = lp2+2;
+ lp2 = line.size();
+ position = atoi(line.substr(lp1, lp2-lp1).c_str());
+ }
+ else
+ {
+ lp2 = line.find(':'), lp1;
+ host = line.substr(lp1, lp2-lp1);
+ lp1 = lp2+1;
+ lp2 = line.find("\x20", lp1);
+ port = atoi(line.substr(lp1, lp2-lp1).c_str());
+ lp1 = lp2+2;
+ lp2 = line.find('"', lp1);
+ label = line.substr(lp1, lp2-lp1);
+ lp1 = lp2+2;
+ lp2 = line.size();
+ position = atoi(line.substr(lp1, lp2-lp1).c_str());
+ }
+ static_proxy_list.push_back(static_proxy_entry(login, password, host, port, label, position));
+ p2 = cfg_str.find(';', p1);
+ }
+ }
}
const int config::ban_time()
diff --git a/server/server/config.h b/server/server/config.h
index 12ff54b..4c76bfe 100644
--- a/server/server/config.h
+++ b/server/server/config.h
@@ -26,6 +26,17 @@ struct static_proxy_entry
{
int port, position;
std::string host, login, password, label;
+ static_proxy_entry(): port(0), position(0)
+ {}
+ static_proxy_entry(std::string login_, std::string password_, std::string host_, int port_, std::string label_, int position_)
+ {
+ login = login_;
+ password = password_;
+ host = host_;
+ port = port_;
+ label = label_;
+ position = position_;
+ }
};
class config
diff --git a/server/server/config_samples/proxy_list.cfg b/server/server/config_samples/proxy_list.cfg
new file mode 100644
index 0000000..a1e0e7d
--- /dev/null
+++ b/server/server/config_samples/proxy_list.cfg
@@ -0,0 +1,3 @@
+user:password@server.com:123 "hzc" "hzst" "hzs";
+server.com2:213 "asdasd" "sdffdgfdg" "retfdfg";
+sdf:wer@sfds.sdf:666 "ertert" "fdgdfg" "rtertert";
diff --git a/server/server/config_samples/static_proxy_list.cfg b/server/server/config_samples/static_proxy_list.cfg
new file mode 100644
index 0000000..4bc40bd
--- /dev/null
+++ b/server/server/config_samples/static_proxy_list.cfg
@@ -0,0 +1,2 @@
+asdsad:qweqwe@qweqwe.df:324 "lbl" 1;
+sdfsdf:234 "asdd" 2;