X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Frouter_flexml.cpp;h=483990ead1c1c21975cf4fc711de9a053e680e1c;hb=48f4e384860829966eacf4881fbf1ccbed38be6a;hp=47501df0ae101e2af7bcfa8ff08c2d35bc81cf6e;hpb=111438f9a883ac784b4ce743a7e83fb8a5b3ff4d;p=metaproxy-moved-to-github.git diff --git a/src/router_flexml.cpp b/src/router_flexml.cpp index 47501df..483990e 100644 --- a/src/router_flexml.cpp +++ b/src/router_flexml.cpp @@ -1,4 +1,4 @@ -/* $Id: router_flexml.cpp,v 1.6 2005-12-08 22:32:57 adam Exp $ +/* $Id: router_flexml.cpp,v 1.8 2006-01-04 14:15:45 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -6,6 +6,8 @@ #include "config.hpp" #include "router_flexml.hpp" +#include "filter_factory.hpp" +#include "factory_static.hpp" #include #include @@ -23,15 +25,11 @@ namespace yp2 { friend class RouterFleXML; Rep(); - typedef std::map > - IdFilterMap ; - typedef std::list FilterIdList; - typedef std::map IdRouteMap ; + typedef std::map > + IdFilterMap ; - bool m_xinclude; IdFilterMap m_id_filter_map; - FilterIdList m_filter_id_list; - IdRouteMap m_id_route_map; void create_filter(std::string type, const xmlDoc * xmldoc, @@ -54,6 +52,9 @@ namespace yp2 { const xmlNode* jump_to_next(const xmlNode* node, int xml_node_type); const xmlNode* jump_to_children(const xmlNode* node, int xml_node_type); + bool m_xinclude; + private: + FilterFactory *m_factory; // TODO shared_ptr }; } @@ -139,6 +140,40 @@ void yp2::RouterFleXML::Rep::parse_xml_config_dom(xmlDocPtr doc) filter_nr++; std::cout << "processing /yp2/filters/filter[" << filter_nr << "]" << std::endl; + + const struct _xmlAttr *attr; + std::string id_value; + std::string type_value; + for (attr = node2->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 if (name == "type") + type_value = value; + else + throw XMLError("Error. Only attribute id or type allowed in filter element. Got " + name); + + std::cout << "attr " << name << "=" << value << "\n"; + + //const xmlNode *val; + } + + yp2::filter::Base* filter_base = m_factory->create(type_value); + + filter_base->configure(node2); + + if (m_id_filter_map.find(id_value) != m_id_filter_map.end()) + throw XMLError("Filter " + id_value + " already defined"); + + m_id_filter_map[id_value] = + boost::shared_ptr(filter_base); + node2 = jump_to_next(node2, XML_ELEMENT_NODE); } @@ -190,9 +225,12 @@ yp2::RouterFleXML::Rep::Rep() : { } -yp2::RouterFleXML::RouterFleXML(std::string xmlconf) +yp2::RouterFleXML::RouterFleXML(std::string xmlconf, yp2::FilterFactory &factory) : m_p(new Rep) { + + m_p->m_factory = &factory; + LIBXML_TEST_VERSION; xmlDocPtr doc = xmlParseMemory(xmlconf.c_str(),