From 9ac41f74e33f58fbbb507f0b3ae9ccdce306f525 Mon Sep 17 00:00:00 2001 From: Marc Cromme Date: Wed, 29 Nov 2006 13:00:53 +0000 Subject: [PATCH] changed config file root element from to adjusted all sources, config files, documentation and schemas according to this change updated sources to generate better error messages when incorrect XML is provided in config files --- doc/book.xml | 22 ++++++++-------- doc/virt_db.xml | 6 ++--- etc/config-bytarget.xml | 6 ++--- etc/config-local.xml | 6 ++--- etc/config-record-transform.xml | 6 ++--- etc/config-shared1.xml | 6 ++--- etc/config-simple-multi.xml | 4 +-- etc/config-sru-to-z3950.xml | 6 ++--- etc/config-zurg.xml | 6 ++--- etc/config0.xml | 6 ++--- etc/config1.xml | 6 ++--- etc/config2.xml | 6 ++--- etc/config3.xml | 6 ++--- etc/config4.xml | 6 ++--- etc/config5.xml | 6 ++--- src/filter_http_file.cpp | 6 ++--- src/filter_virt_db.cpp | 6 ++--- src/router_flexml.cpp | 20 +++++++-------- src/test_filter_query_rewrite.cpp | 4 +-- src/test_filter_record_transform.cpp | 4 +-- src/test_filter_sru_to_z3950.cpp | 4 +-- src/test_router_flexml.cpp | 47 ++++++++++++++++++---------------- src/xmlutil.cpp | 32 +++++++++++++++++------ src/xmlutil.hpp | 6 ++--- xml/schema/metaproxy.rnc | 9 ++++--- 25 files changed, 131 insertions(+), 111 deletions(-) diff --git a/doc/book.xml b/doc/book.xml index 10f54bd..26fd0a5 100644 --- a/doc/book.xml +++ b/doc/book.xml @@ -17,7 +17,7 @@ --> ]> - + Metaproxy - User's Guide and Reference @@ -957,15 +957,15 @@ Figure out what additional information we need in: Overview of the config file XML structure All elements and attributes are in the namespace - . + . This is most easily achieved by setting the default namespace on the top-level element, as here: - <yp2 xmlns="http://indexdata.dk/yp2/config/1"> + <metaproxy xmlns="http://indexdata.com/metaproxy" version="1.0"> - The top-level element is <yp2>. This contains a + The top-level element is <metaproxy>. This contains a <start> element, a <filters> element and a <routes> element, in that order. <filters> is optional; the other two are mandatory. All three are @@ -1021,7 +1021,7 @@ Figure out what additional information we need in: client-server dialogues. - + @@ -1038,7 +1038,7 @@ Figure out what additional information we need in: - + ]]> It works by defining a single route, called @@ -1162,7 +1162,7 @@ Figure out what additional information we need in: marc - indexdata.dk/marc + indexdata.com/marc ]]> @@ -1187,7 +1187,7 @@ Figure out what additional information we need in: Index Data's tiny testing database of MARC records: - + @@ -1202,12 +1202,12 @@ Figure out what additional information we need in: marc - indexdata.dk/marc + indexdata.com/marc all z3950.loc.gov:7090/voyager - indexdata.dk/marc + indexdata.com/marc @@ -1217,7 +1217,7 @@ Figure out what additional information we need in: -]]> +]]> (Using a virt_db diff --git a/doc/virt_db.xml b/doc/virt_db.xml index d4a21c8..26ea673 100644 --- a/doc/virt_db.xml +++ b/doc/virt_db.xml @@ -2,7 +2,7 @@ "http://www.oasis-open.org/docbook/xml/4.1/docbookx.dtd" [ ]> - + virt_db @@ -33,11 +33,11 @@ db2 - indexdata.dk/gils + indexdata.com/gils combined - indexdata.dk/gils + indexdata.com/gils localhost:9999/Default diff --git a/etc/config-bytarget.xml b/etc/config-bytarget.xml index 9557f25..a40446d 100644 --- a/etc/config-bytarget.xml +++ b/etc/config-bytarget.xml @@ -1,6 +1,6 @@ - - + + @@ -61,4 +61,4 @@ - + diff --git a/etc/config-local.xml b/etc/config-local.xml index 576d4eb..4b7ff36 100644 --- a/etc/config-local.xml +++ b/etc/config-local.xml @@ -1,6 +1,6 @@ - - + + @@ -33,4 +33,4 @@ - + diff --git a/etc/config-record-transform.xml b/etc/config-record-transform.xml index b3e775d..79c8c3c 100644 --- a/etc/config-record-transform.xml +++ b/etc/config-record-transform.xml @@ -1,6 +1,6 @@ - - + + @@ -55,5 +55,5 @@ - + diff --git a/etc/config-shared1.xml b/etc/config-shared1.xml index 18656ac..b608f09 100644 --- a/etc/config-shared1.xml +++ b/etc/config-shared1.xml @@ -1,6 +1,6 @@ - - + + @@ -28,5 +28,5 @@ - + diff --git a/etc/config-simple-multi.xml b/etc/config-simple-multi.xml index 2677c3d..3e1429c 100644 --- a/etc/config-simple-multi.xml +++ b/etc/config-simple-multi.xml @@ -1,5 +1,5 @@ - + @@ -29,4 +29,4 @@ - + diff --git a/etc/config-sru-to-z3950.xml b/etc/config-sru-to-z3950.xml index ea978d9..ec8ca67 100644 --- a/etc/config-sru-to-z3950.xml +++ b/etc/config-sru-to-z3950.xml @@ -1,6 +1,6 @@ - - + + @@ -36,5 +36,5 @@ - + diff --git a/etc/config-zurg.xml b/etc/config-zurg.xml index 09be83c..c88210a 100644 --- a/etc/config-zurg.xml +++ b/etc/config-zurg.xml @@ -1,6 +1,6 @@ - - + + @@ -79,5 +79,5 @@ - + diff --git a/etc/config0.xml b/etc/config0.xml index fc4333a..40791ca 100644 --- a/etc/config0.xml +++ b/etc/config0.xml @@ -1,6 +1,6 @@ - - + + @@ -14,5 +14,5 @@ - + diff --git a/etc/config1.xml b/etc/config1.xml index 393a4bc..8746325 100644 --- a/etc/config1.xml +++ b/etc/config1.xml @@ -1,6 +1,6 @@ - - + + @@ -21,5 +21,5 @@ - + diff --git a/etc/config2.xml b/etc/config2.xml index 98089fa..aa54ad1 100644 --- a/etc/config2.xml +++ b/etc/config2.xml @@ -1,6 +1,6 @@ - - + + @@ -63,5 +63,5 @@ - + diff --git a/etc/config3.xml b/etc/config3.xml index 8242396..3b5f806 100644 --- a/etc/config3.xml +++ b/etc/config3.xml @@ -1,6 +1,6 @@ - - + + @@ -59,5 +59,5 @@ - + diff --git a/etc/config4.xml b/etc/config4.xml index c0044ca..37a4932 100644 --- a/etc/config4.xml +++ b/etc/config4.xml @@ -1,6 +1,6 @@ - - + + @@ -22,5 +22,5 @@ - + diff --git a/etc/config5.xml b/etc/config5.xml index 9151604..185fa36 100644 --- a/etc/config5.xml +++ b/etc/config5.xml @@ -1,7 +1,7 @@ - + - + @@ -29,5 +29,5 @@ - + diff --git a/src/filter_http_file.cpp b/src/filter_http_file.cpp index c7410e5..0aa2b24 100644 --- a/src/filter_http_file.cpp +++ b/src/filter_http_file.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_http_file.cpp,v 1.6 2006-08-29 10:34:32 marc Exp $ +/* $Id: filter_http_file.cpp,v 1.7 2006-11-29 13:00:54 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -235,9 +235,9 @@ void mp::filter::HttpFile::configure(const xmlNode * ptr) if (a_node->type != XML_ELEMENT_NODE) continue; - if (mp::xml::is_element_yp2(a_node, "documentroot")) + if (mp::xml::is_element_mp(a_node, "documentroot")) a.m_file_root = mp::xml::get_text(a_node); - else if (mp::xml::is_element_yp2(a_node, "prefix")) + else if (mp::xml::is_element_mp(a_node, "prefix")) a.m_url_path_prefix = mp::xml::get_text(a_node); else throw mp::filter::FilterException diff --git a/src/filter_virt_db.cpp b/src/filter_virt_db.cpp index 5d4d749..daf43f3 100644 --- a/src/filter_virt_db.cpp +++ b/src/filter_virt_db.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_virt_db.cpp,v 1.46 2006-09-29 08:42:47 marc Exp $ +/* $Id: filter_virt_db.cpp,v 1.47 2006-11-29 13:00:54 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -783,9 +783,9 @@ void mp::filter::VirtualDB::configure(const xmlNode * ptr) if (v_node->type != XML_ELEMENT_NODE) continue; - if (mp::xml::is_element_yp2(v_node, "database")) + if (mp::xml::is_element_mp(v_node, "database")) database = mp::xml::get_text(v_node); - else if (mp::xml::is_element_yp2(v_node, "target")) + else if (mp::xml::is_element_mp(v_node, "target")) targets.push_back(mp::xml::get_text(v_node)); else throw mp::filter::FilterException diff --git a/src/router_flexml.cpp b/src/router_flexml.cpp index 2564aae..b6bafa9 100644 --- a/src/router_flexml.cpp +++ b/src/router_flexml.cpp @@ -1,4 +1,4 @@ -/* $Id: router_flexml.cpp,v 1.18 2006-06-10 14:29:12 adam Exp $ +/* $Id: router_flexml.cpp,v 1.19 2006-11-29 13:00:54 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -75,7 +75,7 @@ void mp::RouterFleXML::Rep::parse_xml_filters(xmlDocPtr doc, const xmlNode *node) { unsigned int filter_nr = 0; - while(node && mp::xml::check_element_yp2(node, "filter")) + while(node && mp::xml::check_element_mp(node, "filter")) { filter_nr++; @@ -122,10 +122,10 @@ void mp::RouterFleXML::Rep::parse_xml_filters(xmlDocPtr doc, void mp::RouterFleXML::Rep::parse_xml_routes(xmlDocPtr doc, const xmlNode *node) { - mp::xml::check_element_yp2(node, "route"); + mp::xml::check_element_mp(node, "route"); unsigned int route_nr = 0; - while(mp::xml::is_element_yp2(node, "route")) + while(mp::xml::is_element_mp(node, "route")) { route_nr++; @@ -153,7 +153,7 @@ void mp::RouterFleXML::Rep::parse_xml_routes(xmlDocPtr doc, const xmlNode* node3 = mp::xml::jump_to_children(node, XML_ELEMENT_NODE); unsigned int filter3_nr = 0; - while(node3 && mp::xml::check_element_yp2(node3, "filter")) + while(node3 && mp::xml::check_element_mp(node3, "filter")) { filter3_nr++; @@ -224,17 +224,17 @@ void mp::RouterFleXML::Rep::parse_xml_config_dom(xmlDocPtr doc) const xmlNode* root = xmlDocGetRootElement(doc); - mp::xml::check_element_yp2(root, "yp2"); + mp::xml::check_element_mp(root, "metaproxy"); const xmlNode* node = mp::xml::jump_to_children(root, XML_ELEMENT_NODE); - if (mp::xml::is_element_yp2(node, "dlpath")) + if (mp::xml::is_element_mp(node, "dlpath")) { m_dl_path = mp::xml::get_text(node); node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE); } // process node which is expected first element node - if (mp::xml::check_element_yp2(node, "start")) + if (mp::xml::check_element_mp(node, "start")) { const struct _xmlAttr *attr; std::string id_value; @@ -255,7 +255,7 @@ void mp::RouterFleXML::Rep::parse_xml_config_dom(xmlDocPtr doc) node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE); } // process node if given - if (mp::xml::is_element_yp2(node, "filters")) + if (mp::xml::is_element_mp(node, "filters")) { parse_xml_filters(doc, mp::xml::jump_to_children(node, XML_ELEMENT_NODE)); @@ -263,7 +263,7 @@ void mp::RouterFleXML::Rep::parse_xml_config_dom(xmlDocPtr doc) node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE); } // process node which is expected third element node - mp::xml::check_element_yp2(node, "routes"); + mp::xml::check_element_mp(node, "routes"); parse_xml_routes(doc, mp::xml::jump_to_children(node, XML_ELEMENT_NODE)); diff --git a/src/test_filter_query_rewrite.cpp b/src/test_filter_query_rewrite.cpp index 484bac5..385c320 100644 --- a/src/test_filter_query_rewrite.cpp +++ b/src/test_filter_query_rewrite.cpp @@ -1,4 +1,4 @@ -/* $Id: test_filter_query_rewrite.cpp,v 1.10 2006-06-10 14:29:12 adam Exp $ +/* $Id: test_filter_query_rewrite.cpp,v 1.11 2006-11-29 13:00:54 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -187,7 +187,7 @@ BOOST_AUTO_UNIT_TEST( test_filter_query_rewrite3 ) std::string xmlconf = "\n" - "\n" "\n" ; diff --git a/src/test_filter_record_transform.cpp b/src/test_filter_record_transform.cpp index 8ca06f7..33b4574 100644 --- a/src/test_filter_record_transform.cpp +++ b/src/test_filter_record_transform.cpp @@ -1,4 +1,4 @@ -/* $Id: test_filter_record_transform.cpp,v 1.2 2006-10-04 11:21:47 marc Exp $ +/* $Id: test_filter_record_transform.cpp,v 1.3 2006-11-29 13:00:54 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -72,7 +72,7 @@ BOOST_AUTO_UNIT_TEST( test_filter_record_transform_3 ) std::string xmlconf = "\n" - "\n" "" "\n" -// "\n" // "\n" // ; diff --git a/src/test_router_flexml.cpp b/src/test_router_flexml.cpp index 95b05ef..55425c0 100644 --- a/src/test_router_flexml.cpp +++ b/src/test_router_flexml.cpp @@ -1,4 +1,4 @@ -/* $Id: test_router_flexml.cpp,v 1.17 2006-06-10 14:29:13 adam Exp $ +/* $Id: test_router_flexml.cpp,v 1.18 2006-11-29 13:00:54 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -38,7 +38,8 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_1 ) try { std::string xmlconf = "\n" - "\n" + "\n" " \n" " \n" " \n" @@ -62,7 +63,7 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_1 ) " \n" " \n" " \n" - "\n"; + "\n"; mp::FactoryStatic factory; factory.add_creator("tfilter", filter_creator); @@ -86,7 +87,7 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_2 ) try { std::string xmlconf_invalid = "\n" - "\n" + "\n" " \n" " \n" " \n" @@ -114,23 +115,24 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_3 ) try { std::string xmlconf = "\n" - "\n" - " \n" - " \n" - " \n" + "\n" + " \n" + " \n" + " \n" " @:210\n" - " \n" - " \n" + " \n" + " \n" " my msg\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - "\n"; + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; mp::FactoryStatic factory; mp::RouterFleXML rflexml(xmlconf, factory); @@ -151,8 +153,9 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_4 ) try { std::string xmlconf = "\n" - "\n" - " \n" + "\n" + " \n" " \n" " \n" " @:210\n" @@ -163,7 +166,7 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_4 ) " \n" " \n" " \n" - "\n"; + "\n"; mp::FactoryStatic factory; factory.add_creator("tfilter", filter_creator); diff --git a/src/xmlutil.cpp b/src/xmlutil.cpp index 7fa3667..6356f60 100644 --- a/src/xmlutil.cpp +++ b/src/xmlutil.cpp @@ -1,4 +1,4 @@ -/* $Id: xmlutil.cpp,v 1.9 2006-06-21 09:16:54 adam Exp $ +/* $Id: xmlutil.cpp,v 1.10 2006-11-29 13:00:54 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -11,6 +11,8 @@ namespace mp = metaproxy_1; // Doxygen doesn't like mp::xml, so we use this instead namespace mp_xml = metaproxy_1::xml; +static const std::string metaproxy_ns = "http://indexdata.com/metaproxy"; + std::string mp_xml::get_text(const xmlNode *ptr) { std::string c; @@ -52,18 +54,32 @@ bool mp_xml::is_element(const xmlNode *ptr, return false; } -bool mp_xml::is_element_yp2(const xmlNode *ptr, - const std::string &name) +bool mp_xml::is_element_mp(const xmlNode *ptr, + const std::string &name) { - return mp::xml::is_element(ptr, "http://indexdata.dk/yp2/config/1", name); + return mp::xml::is_element(ptr, metaproxy_ns, name); } -bool mp_xml::check_element_yp2(const xmlNode *ptr, - const std::string &name) +bool mp_xml::check_element_mp(const xmlNode *ptr, + const std::string &name) { - if (!mp::xml::is_element_yp2(ptr, name)) - throw mp::XMLError("Expected element name " + name); + if (!mp::xml::is_element_mp(ptr, name)) + { + std::string got_element = "<"; + if (ptr && ptr->name) + got_element += std::string((const char *)ptr->name); + if (ptr && ptr->ns && ptr->ns->href){ + got_element += " xmlns=\""; + got_element += std::string((const char *)ptr->ns->href); + got_element += "\""; + } + got_element += ">"; + + throw mp::XMLError("Expected XML element <" + name + + " xmlns=\"" + metaproxy_ns + "\">" + + ", not " + got_element); + } return true; } diff --git a/src/xmlutil.hpp b/src/xmlutil.hpp index ed27947..bfab08c 100644 --- a/src/xmlutil.hpp +++ b/src/xmlutil.hpp @@ -1,4 +1,4 @@ -/* $Id: xmlutil.hpp,v 1.8 2006-06-21 09:16:54 adam Exp $ +/* $Id: xmlutil.hpp,v 1.9 2006-11-29 13:00:54 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -19,8 +19,8 @@ namespace metaproxy_1 { bool is_element(const xmlNode *ptr, const std::string &ns, const std::string &name); - bool is_element_yp2(const xmlNode *ptr, const std::string &name); - bool check_element_yp2(const xmlNode *ptr, + bool is_element_mp(const xmlNode *ptr, const std::string &name); + bool check_element_mp(const xmlNode *ptr, const std::string &name); std::string get_route(const xmlNode *node); diff --git a/xml/schema/metaproxy.rnc b/xml/schema/metaproxy.rnc index cea817e..0394549 100644 --- a/xml/schema/metaproxy.rnc +++ b/xml/schema/metaproxy.rnc @@ -1,5 +1,5 @@ # Metaproxy XML config file schemas -# $Id: metaproxy.rnc,v 1.6 2006-11-17 14:03:47 adam Exp $ +# $Id: metaproxy.rnc,v 1.7 2006-11-29 13:00:54 marc Exp $ # # Copyright (c) 2005-2006, Index Data. # @@ -19,14 +19,15 @@ # For information on RelaxNG see http://relaxng.org # see also http://books.xmlschemata.org/relaxng/ -default namespace = "http://indexdata.dk/yp2/config/1" +default namespace = "http://indexdata.com/metaproxy" start = metaproxy metaproxy = - element yp2 { + element metaproxy { + attribute version { xsd:float }, element start { - attribute route { xsd:NCName } + attribute route { xsd:NCName } }, element filters { filter+ }?, element routes { route+ } -- 1.7.10.4