X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Frouter_flexml.cpp;h=7e5bbbbaf10f8766e36f880900890c2d395e5b59;hb=50597d2f7d3607e91c94601eb8eb495d73be3eae;hp=a904d6efedde139d668b9fc49603ee200273c9d0;hpb=7c5fb946e66c826b048423025d58124e1f005606;p=metaproxy-moved-to-github.git diff --git a/src/router_flexml.cpp b/src/router_flexml.cpp index a904d6e..7e5bbbb 100644 --- a/src/router_flexml.cpp +++ b/src/router_flexml.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2011 Index Data + Copyright (C) 2005-2012 Index Data Metaproxy is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -69,6 +69,9 @@ namespace metaproxy_1 { void parse_xml_filters(xmlDocPtr doc, const xmlNode *node, bool test_only, const char *file_include_path); + void parse_xml_filters1(xmlDocPtr doc, const xmlNode *node, + bool test_only, const char *file_include_path, + Route &route); void parse_xml_routes(xmlDocPtr doc, const xmlNode *node, bool test_only, const char *file_include_path); void check_routes_in_filters(const xmlNode *n); @@ -141,74 +144,51 @@ void mp::RouterFleXML::Rep::parse_xml_filters(xmlDocPtr doc, } } -void mp::RouterFleXML::Rep::parse_xml_routes(xmlDocPtr doc, - const xmlNode *node, - bool test_only, - const char *file_include_path) +void mp::RouterFleXML::Rep::parse_xml_filters1(xmlDocPtr doc, + const xmlNode *node, + bool test_only, + const char *file_include_path, + Route &route) { - mp::xml::check_element_mp(node, "route"); - - unsigned int route_nr = 0; - while (mp::xml::is_element_mp(node, "route")) + while (node) { - route_nr++; - - const struct _xmlAttr *attr; - std::string id_value; - for (attr = node->properties; attr; attr = attr->next) + if (mp::xml::is_element_mp(node, "filters")) { - std::string name = std::string((const char *) attr->name); - std::string value; - - if (attr->children && attr->children->type == XML_TEXT_NODE) - value = std::string((const char *)attr->children->content); - - if (name == "id") - id_value = value; - else - throw mp::XMLError("Only attribute 'id' allowed for" - " element 'route'." - " Got " + name); - } - - Route route; - - // process nodes in third level - const xmlNode* node3 = mp::xml::jump_to_children(node, XML_ELEMENT_NODE); + const xmlNode* node1 = + mp::xml::jump_to_children(node, XML_ELEMENT_NODE); - unsigned int filter3_nr = 0; - while (node3 && mp::xml::check_element_mp(node3, "filter")) + parse_xml_filters1(doc, node1, test_only, file_include_path, route); + } + else if (mp::xml::check_element_mp(node, "filter")) { - filter3_nr++; - const struct _xmlAttr *attr; std::string refid_value; std::string type_value; - for (attr = node3->properties; attr; attr = attr->next) + for (attr = node->properties; attr; attr = attr->next) { std::string name = std::string((const char *) attr->name); std::string value; - + if (attr->children && attr->children->type == XML_TEXT_NODE) value = std::string((const char *)attr->children->content); - + if (name == "refid") refid_value = value; else if (name == "type") type_value = value; else throw mp::XMLError("Only attribute 'refid' or 'type'" - " allowed for element 'filter'." - " Got " + name); + " allowed for element 'filter'." + " Got " + name); } if (refid_value.length()) { std::map >::iterator it; + boost::shared_ptr >::iterator it; it = m_id_filter_map.find(refid_value); if (it == m_id_filter_map.end()) throw mp::XMLError("Unknown filter refid " - + refid_value); + + refid_value); else route.m_list.push_back(it->second); } @@ -221,15 +201,55 @@ void mp::RouterFleXML::Rep::parse_xml_routes(xmlDocPtr doc, m_factory->add_creator_dl(type_value, m_dl_path); } mp::filter::Base* filter_base = m_factory->create(type_value); - - filter_base->configure(node3, test_only, file_include_path); - + + filter_base->configure(node, test_only, file_include_path); + route.m_list.push_back( boost::shared_ptr(filter_base)); } - node3 = mp::xml::jump_to_next(node3, XML_ELEMENT_NODE); + + } + node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE); + } +} + + +void mp::RouterFleXML::Rep::parse_xml_routes(xmlDocPtr doc, + const xmlNode *node, + bool test_only, + const char *file_include_path) +{ + mp::xml::check_element_mp(node, "route"); + + unsigned int route_nr = 0; + while (mp::xml::is_element_mp(node, "route")) + { + route_nr++; + + const struct _xmlAttr *attr; + std::string id_value; + for (attr = node->properties; attr; attr = attr->next) + { + std::string name = std::string((const char *) attr->name); + std::string value; + + if (attr->children && attr->children->type == XML_TEXT_NODE) + value = std::string((const char *)attr->children->content); + if (name == "id") + id_value = value; + else + throw mp::XMLError("Only attribute 'id' allowed for" + " element 'route'." + " Got " + name); } + + Route route; + + // process / nodes in third level + const xmlNode* node3 = mp::xml::jump_to_children(node, XML_ELEMENT_NODE); + parse_xml_filters1(doc, node3, test_only, file_include_path, route); + std::map::iterator it; it = m_routes.find(id_value); if (it != m_routes.end()) @@ -245,7 +265,13 @@ void mp::RouterFleXML::Rep::check_routes_in_filters(const xmlNode *node) { while (node) { - if (mp::xml::is_element_mp(node, "filter")) + if (mp::xml::is_element_mp(node, "filters")) + { + const xmlNode *n = + mp::xml::jump_to_children(node, XML_ELEMENT_NODE); + check_routes_in_filters(n); + } + else if (mp::xml::is_element_mp(node, "filter")) { const xmlNode *n = mp::xml::jump_to_children(node, XML_ELEMENT_NODE);