summaryrefslogtreecommitdiff
path: root/server/server/p_xml.cpp
blob: 3fac83766c114c23929f7bc19d0450d6962f52c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "headers.h"
extern config *cfg;

using namespace rapidxml;

bool p_load_proxy_list(std::list<config::p_proxy_entry> *list, char *path)
{
	std::ifstream file;
	if(!path)
		file.open(std::string(cfg->proxifier_path()+"/Default/Default.ppx").c_str(), std::ios::in);
	else
		file.open(path, std::ios::in);
	if(file.is_open())
	{
		std::string data((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
		file.close();
		xml_document<> doc;
		xml_node<> *proxy_list = doc.first_node()->first_node("ProxyList");
		if(!proxy_list)
			return false;
		for(xml_node<> *node = proxy_list->first_node("Proxy"); node; node = node->next_sibling("Proxy"))
		{
			config::p_proxy_entry e;
			e.id = atoi(node->first_attribute("id")->value());
			std::string type = node->first_attribute("type")->value();
			if(type == "HTTPS")
				e.type = config::HTTPS;
			if(type == "SOCKS4")
				e.type = config::SOCKS4;
			if(type == "SOCKS5")
				e.type = config::SOCKS5;
			e.host = node->first_node("Address")->value();
			e.port = atoi(node->first_node("Port")->value());
			e.options = atoi(node->first_node("Options")->value());
			xml_node<> *auth = node->first_node("Authentication");
			if(auth)
			{
				e.enable_auth = atoi(auth->first_attribute("Enabled")->value());
				e.login = auth->first_node("Username")->value();
				e.password = auth->first_node("Password")->value(); //TODO: detect kind of hash, decrypt (needed for set auth settings in proxy list)
			}
			list->push_back(e);
		}
		if(!list->empty())
			return true; // succesfully loaded some entries
	}
	return false;
}

bool p_load_proxy_chains(std::list<config::p_proxy_chain> *list, char *path)
{
	std::ifstream file;
	if(!path)
		file.open(std::string(cfg->proxifier_path()+"/Default/Default.ppx").c_str(), std::ios::in);
	else
		file.open(path, std::ios::in);
	if(file.is_open())
	{
		std::string data((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
		file.close();
		xml_document<> doc;
		xml_node<> *chain_list = doc.first_node()->first_node("ChainList");
		if(!chain_list)
			return false;
		for(xml_node<> *node = chain_list->first_node("Chain"); node; node = node->next_sibling("Chain"))
		{
			config::p_proxy_chain c;
			c.id = atoi(node->first_attribute("id")->value());
			c.name = node->first_node("Name")->value();
			for(xml_node<> *proxy = node->first_node("Proxy"); proxy; proxy = proxy->next_sibling("Proxy"))
			{
				config::p_proxy_chain::chain_entry e;
				e.enabled = atoi(proxy->first_attribute("enabled")->value());
				e.id = atoi(proxy->value());
				c.chain.push_back(e);
			}
			list->push_back(c);
		}
		if(!list->empty())
			return true;
	}
	return false;
}

bool p_save_proxy_list(std::list<config::p_proxy_entry> *list, char *path)
{
}

bool p_save_proxy_chains(std::list<config::p_proxy_chain> *list, char *path)
{
}