From ce4555008a27376b5d04e361bd3128049fdaca26 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 8 Mar 2012 13:18:07 +0100 Subject: [PATCH] multi: allow backend-auth to be given for target element --- include/metaproxy/xmlutil.hpp | 1 + src/filter_multi.cpp | 28 +++++++++++++++++++++------- src/xmlutil.cpp | 9 ++++++++- xml/schema/filter_multi.rnc | 1 + 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/include/metaproxy/xmlutil.hpp b/include/metaproxy/xmlutil.hpp index 849d601..f673211 100644 --- a/include/metaproxy/xmlutil.hpp +++ b/include/metaproxy/xmlutil.hpp @@ -42,6 +42,7 @@ namespace metaproxy_1 { bool check_element_mp(const xmlNode *ptr, const std::string &name); std::string get_route(const xmlNode *node); + std::string get_route(const xmlNode *node, std::string &auth); const xmlNode* jump_to(const xmlNode* node, int node_type); diff --git a/src/filter_multi.cpp b/src/filter_multi.cpp index c05070a..713cf32 100644 --- a/src/filter_multi.cpp +++ b/src/filter_multi.cpp @@ -88,6 +88,7 @@ namespace metaproxy_1 { std::string m_backend_database; std::string m_vhost; std::string m_route; + std::string m_auth; void operator() (void); // thread operation }; struct Multi::Frontend { @@ -111,13 +112,16 @@ namespace metaproxy_1 { class Multi::Map { std::string m_target_pattern; std::string m_route; + std::string m_auth; public: - Map(std::string pattern, std::string route) : - m_target_pattern(pattern), m_route(route) {}; - bool match(const std::string target, std::string *ret) const { + Map(std::string pattern, std::string route, std::string auth) : + m_target_pattern(pattern), m_route(route), m_auth(auth) {}; + bool match(const std::string target, std::string *ret, + std::string *auth) const { if (yaz_match_glob(m_target_pattern.c_str(), target.c_str())) { *ret = m_route; + *auth = m_auth; return true; } return false; @@ -395,7 +399,7 @@ void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu) std::list::const_iterator it = m_p->m_route_patterns.begin(); while (it != m_p->m_route_patterns.end()) { - if (it->match(*t_it, &b->m_route)) + if (it->match(*t_it, &b->m_route, &b->m_auth)) break; it++; } @@ -423,7 +427,16 @@ void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu) Z_InitRequest *breq = init_apdu->u.initRequest; - breq->idAuthentication = req->idAuthentication; + if (b->m_auth.length()) + { + breq->idAuthentication = + (Z_IdAuthentication *) + odr_malloc(odr, sizeof(*breq->idAuthentication)); + breq->idAuthentication->which = Z_IdAuthentication_open; + breq->idAuthentication->u.open = odr_strdup(odr, b->m_auth.c_str()); + } + else + breq->idAuthentication = req->idAuthentication; *breq->preferredMessageSize = *req->preferredMessageSize; *breq->maximumRecordSize = *req->maximumRecordSize; @@ -1293,11 +1306,12 @@ void mp::filter::Multi::configure(const xmlNode * ptr, bool test_only, continue; if (!strcmp((const char *) ptr->name, "target")) { - std::string route = mp::xml::get_route(ptr); + std::string auth; + std::string route = mp::xml::get_route(ptr, auth); std::string target = mp::xml::get_text(ptr); if (target.length() == 0) target = route; - m_p->m_route_patterns.push_back(Multi::Map(target, route)); + m_p->m_route_patterns.push_back(Multi::Map(target, route, auth)); } else if (!strcmp((const char *) ptr->name, "hideunavailable")) { diff --git a/src/xmlutil.cpp b/src/xmlutil.cpp index a5da032..c59f506 100644 --- a/src/xmlutil.cpp +++ b/src/xmlutil.cpp @@ -149,7 +149,7 @@ bool mp_xml::check_element_mp(const xmlNode *ptr, return true; } -std::string mp_xml::get_route(const xmlNode *node) +std::string mp_xml::get_route(const xmlNode *node, std::string &auth) { std::string route_value; if (node) @@ -165,6 +165,8 @@ std::string mp_xml::get_route(const xmlNode *node) if (name == "route") route_value = value; + else if (name == "auth") + auth = value; else throw XMLError("Only attribute route allowed" " in " + std::string((const char *)node->name) @@ -174,6 +176,11 @@ std::string mp_xml::get_route(const xmlNode *node) return route_value; } +std::string mp_xml::get_route(const xmlNode *node) +{ + std::string auth; + return get_route(node, auth); +} const xmlNode* mp_xml::jump_to_children(const xmlNode* node, int xml_node_type) diff --git a/xml/schema/filter_multi.rnc b/xml/schema/filter_multi.rnc index 6ef36e1..4f04b02 100644 --- a/xml/schema/filter_multi.rnc +++ b/xml/schema/filter_multi.rnc @@ -8,6 +8,7 @@ filter_multi = attribute name { xsd:NCName }?, element mp:target { attribute route { xsd:string }, + attribute auth { xsd:string }?, xsd:string }*, element mp:hideunavailable { empty }?, -- 1.7.10.4