diff options
| -rwxr-xr-x | server/server/p_xml.cpp | 62 | ||||
| -rwxr-xr-x | server/server/p_xml.h | 1 | 
2 files changed, 63 insertions, 0 deletions
| diff --git a/server/server/p_xml.cpp b/server/server/p_xml.cpp index df41655..a42d145 100755 --- a/server/server/p_xml.cpp +++ b/server/server/p_xml.cpp @@ -111,6 +111,11 @@ bool p_save_proxy_list(std::list<config::p_proxy_entry> *list, config *cfg, cons  			proxy_list->remove_all_nodes();
  			proxy_list->remove_all_attributes();
  		}
 +		else
 +		{
 +			proxy_list = doc.allocate_node(node_element, "ProxyList");
 +			doc.append_node(proxy_list);
 +		}
  		for(std::list<config::p_proxy_entry>::iterator i = p_list->begin(), end = p_list->end(); i != end; ++i)
  		{
  			xml_node<> *proxy = doc.allocate_node(node_element, "Proxy");
 @@ -177,6 +182,63 @@ bool p_save_proxy_list(std::list<config::p_proxy_entry> *list, config *cfg, cons  	return false;
  }
 +bool p_sset_default_rule(config::p_proxy_entry *entry, config *cfg, const char *path)
 +{
 +	std::list<config::p_proxy_entry> *p_list = cfg->make_p_proxy_list();
 +	if(p_list->empty())
 +		return false;
 +	std::ifstream infile;
 +	if(!path)
 +		infile.open(std::string(cfg->proxifier_path()+"/Default/Default.ppx").c_str(), std::ios::in); //TODO: handle different locations
 +	else
 +		infile.open(path, std::ios::in);
 +	if(infile.is_open())
 +	{
 +		std::string data((std::istreambuf_iterator<char>(infile)), std::istreambuf_iterator<char>());
 +		infile.close();
 +		xml_document<> doc;
 +		doc.parse<0>(doc.allocate_string(data.c_str()));
 +		xml_node<> *rule_list = doc.first_node()->first_node("RuleList");
 +		if(!rule_list)
 +		{
 +			rule_list = doc.allocate_node(node_element, "RuleList");
 +			doc.append_node(rule_list);
 +		}
 +		xml_node<> *default_rule = NULL;
 +		for(xml_node<> *rule = rule_list->first_node("Chain"); rule; rule = rule->next_sibling("Chain"))
 +		{
 +			xml_node<> *name = rule->first_node("Name");
 +			if(name)
 +			{
 +				if(!strcmp(name->value(), "Default"))
 +				{
 +					default_rule = rule;
 +					break;
 +				}
 +			}
 +		}
 +		char val[8];
 +		snprintf(val, 7, "%d", entry->id);
 +		if(default_rule) //no validation here, assuming valid config
 +		{
 +			default_rule->first_attribute("enabled")->value("true");
 +			xml_node<> *action = default_rule->first_node("Action");
 +			action->first_attribute("type")->value("Proxy");
 +			action->value(doc.allocate_string(val));
 +		}
 +		else
 +		{
 +			default_rule = doc.allocate_node(node_element, "Rule");
 +			rule_list->append_node(default_rule);
 +			default_rule->append_attribute(doc.allocate_attribute("enabled", "true"));
 +			default_rule->append_node(doc.allocate_node(node_element, "Name", "Default"));
 +			xml_node<> *action = doc.allocate_node(node_element, "Action", doc.allocate_string(val));
 +			action->append_attribute(doc.allocate_attribute("type","Proxy"));
 +			default_rule->append_node(action);
 +		}
 +	}
 +}
 +
  bool p_save_proxy_chains(std::list<config::p_proxy_chain> *list, config *cfg, const char *path)
  {
  }
\ No newline at end of file diff --git a/server/server/p_xml.h b/server/server/p_xml.h index 4a754e9..38f9793 100755 --- a/server/server/p_xml.h +++ b/server/server/p_xml.h @@ -4,6 +4,7 @@  bool p_load_proxy_list(std::list<config::p_proxy_entry> *list, config *cfg, const char* path = NULL);
  bool p_load_proxy_chains(std::list<config::p_proxy_chain> *list, config *cfg, const char *path = NULL);
  bool p_save_proxy_list(std::list<config::p_proxy_entry> *list, config *cfg, const char *path = NULL);
 +bool p_sset_default_rule(config::p_proxy_entry *entry, config *cfg, const char *path = NULL);
  bool p_save_proxy_chains(std::list<config::p_proxy_chain> *list, config *cfg, const char *path = NULL);
  #endif
\ No newline at end of file | 
