X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ffilter_sru_to_z3950.cpp;h=fa12345d9aeb620c00d12e5e56c57de07bed8f37;hb=09d9b36e4529a5cf42066f4a1e5b3ce635e04f34;hp=44b72bfb60cd1ca9a93650078a088cfdfbab65e4;hpb=6d9867ed4cbb68635f4819a9a9c104a219160780;p=metaproxy-moved-to-github.git diff --git a/src/filter_sru_to_z3950.cpp b/src/filter_sru_to_z3950.cpp index 44b72bf..fa12345 100644 --- a/src/filter_sru_to_z3950.cpp +++ b/src/filter_sru_to_z3950.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2013 Index Data + Copyright (C) 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 @@ -30,6 +30,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#if YAZ_VERSIONL >= 0x50000 +#include +#endif #include #include @@ -60,6 +63,7 @@ namespace metaproxy_1 { FrontendPtr get_frontend(mp::Package &package); void release_frontend(mp::Package &package); std::map m_database_explain; + std::string default_stylesheet; typedef std::map ActiveUrlMap; @@ -94,7 +98,7 @@ namespace metaproxy_1 { Z_SRW_PDU *sru_pdu_res, Z_SRW_searchRetrieveRequest const *sr_req, std::string zurl, - const char *db_append + std::string db_append ) const; bool z3950_present_request( @@ -148,27 +152,40 @@ void yf::SRUtoZ3950::Impl::configure(const xmlNode *confignode) if (dbnode->type != XML_ELEMENT_NODE) continue; - std::string database; - mp::xml::check_element_mp(dbnode, "database"); - - for (struct _xmlAttr *attr = dbnode->properties; - attr; attr = attr->next) + if (!strcmp((const char *) dbnode->name, "database")) { + std::string database; - mp::xml::check_attribute(attr, "", "name"); - database = mp::xml::get_text(attr); - - const xmlNode *explainnode; - for (explainnode = dbnode->children; - explainnode; explainnode = explainnode->next) + for (struct _xmlAttr *attr = dbnode->properties; + attr; attr = attr->next) { - if (explainnode->type != XML_ELEMENT_NODE) - continue; - if (explainnode) - break; + mp::xml::check_attribute(attr, "", "name"); + database = mp::xml::get_text(attr); + + const xmlNode *explainnode; + for (explainnode = dbnode->children; + explainnode; explainnode = explainnode->next) + { + if (explainnode->type == XML_ELEMENT_NODE) + { + m_database_explain.insert( + std::make_pair(database, explainnode)); + break; + } + } } - // assigning explain node to database name - no check yet - m_database_explain.insert(std::make_pair(database, explainnode)); + } + else if (!strcmp((const char *) dbnode->name, "stylesheet")) + { + default_stylesheet = mp::xml::get_text(dbnode); + } + else + { + throw mp::filter::FilterException + ("Bad element " + + std::string((const char *) dbnode->name) + + " in sru_z3950" + ); } } } @@ -198,12 +215,12 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) // decode SRU request Z_SOAP *soap = 0; char *charset = 0; - char *stylesheet = 0; + const char *stylesheet = 0; // filter acts as sink for non-valid SRU requests if (! (sru_pdu_req = mp_util::decode_sru_request(package, odr_de, odr_en, sru_pdu_res, &soap, - charset, stylesheet))) + charset))) { if (soap) { @@ -225,7 +242,7 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) bool enable_package_log = false; std::string zurl; - const char *dbargs = 0; + std::string dbargs; Z_SRW_extra_arg *arg; for ( arg = sru_pdu_req->extra_args; arg; arg = arg->next) @@ -249,9 +266,13 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) package.log_enable(); } } - else if (!strcmp(arg->name, "x-dbargs")) + else if (!strncmp(arg->name, "x-client-", 9) && arg->value) { - dbargs = arg->value; + if (dbargs.length()) + dbargs += '&'; + dbargs += mp_util::uri_encode(arg->name + 9); + dbargs += '='; + dbargs += mp_util::uri_encode(arg->value); } assert(sru_pdu_req); @@ -260,6 +281,8 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) if (sru_pdu_req->which == Z_SRW_explain_request) { Z_SRW_explainRequest *er_req = sru_pdu_req->u.explain_request; + stylesheet = er_req->stylesheet; + mp_util::build_sru_explain(package, odr_en, sru_pdu_res, sruinfo, explainnode, er_req); } @@ -267,6 +290,7 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) && sru_pdu_req->u.request) { // searchRetrieve Z_SRW_searchRetrieveRequest *sr_req = sru_pdu_req->u.request; + stylesheet = sr_req->stylesheet; sru_pdu_res = yaz_srw_get_pdu(odr_en, Z_SRW_searchRetrieve_response, sru_pdu_req->srw_version); @@ -298,6 +322,7 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) { sru_pdu_res = yaz_srw_get_pdu(odr_en, Z_SRW_scan_response, sru_pdu_req->srw_version); + stylesheet = sru_pdu_req->u.scan_request->stylesheet; // we do not do scan at the moment, therefore issuing a diagnostic yaz_add_srw_diagnostic(odr_en, @@ -332,6 +357,8 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) odr_strdup(odr_en, wrbuf_cstr(w)); } } + if (!stylesheet && default_stylesheet.length()) + stylesheet = default_stylesheet.c_str(); // build and send SRU response mp_util::build_sru_response(package, odr_en, soap, @@ -557,7 +584,7 @@ bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package, Z_SRW_searchRetrieveRequest const *sr_req, std::string zurl, - const char *dbappend) const + std::string dbappend) const { assert(sru_pdu_res->u.response); @@ -583,7 +610,7 @@ bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package, else db = "Default"; - if (dbappend) + if (dbappend.length()) { db += ","; db += dbappend; @@ -593,6 +620,14 @@ bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package, odr_malloc(odr_en, sizeof(char *)); z_searchRequest->databaseNames[0] = odr_strdup(odr_en, db.c_str()); } +#if YAZ_VERSIONL >= 0x50000 + // yaz_oi_set_facetlist not public in YAZ 4.2.66 + if (sr_req->facetList) + { + Z_OtherInformation **oi = &z_searchRequest->otherInfo; + yaz_oi_set_facetlist(oi, odr_en, sr_req->facetList); + } +#endif Z_Query *z_query = (Z_Query *) odr_malloc(odr_en, sizeof(Z_Query)); z_searchRequest->query = z_query; @@ -633,7 +668,12 @@ bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package, { return false; } - +#if YAZ_VERSIONL >= 0x50000 + Z_FacetList *fl = yaz_oi_get_facetlist(&sr->additionalSearchInfo); + if (!fl) + fl = yaz_oi_get_facetlist(&sr->otherInfo); + sru_pdu_res->u.response->facetList = fl; +#endif sru_pdu_res->u.response->numberOfRecords = odr_intdup(odr_en, *sr->resultCount); return true; @@ -865,7 +905,13 @@ int yf::SRUtoZ3950::Impl::z3950_build_query( const Z_SRW_searchRetrieveRequest *req ) const { - if (req->query_type == Z_SRW_query_type_cql) + if ( +#ifdef Z_SRW_query_type_cql + req->query_type == Z_SRW_query_type_cql +#else + !strcmp(req->queryType, "cql") +#endif + ) { Z_External *ext = (Z_External *) odr_malloc(odr_en, sizeof(*ext)); @@ -874,22 +920,39 @@ int yf::SRUtoZ3950::Impl::z3950_build_query( ext->indirect_reference = 0; ext->descriptor = 0; ext->which = Z_External_CQL; - ext->u.cql = odr_strdup(odr_en, req->query.cql); + ext->u.cql = odr_strdup(odr_en, +#ifdef Z_SRW_query_type_cql + req->query.cql +#else + req->query +#endif + ); z_query->which = Z_Query_type_104; z_query->u.type_104 = ext; return 0; } - if (req->query_type == Z_SRW_query_type_pqf) + if ( +#ifdef Z_SRW_query_type_pqf + req->query_type == Z_SRW_query_type_pqf +#else + !strcmp(req->queryType, "pqf") +#endif + ) { Z_RPNQuery *RPNquery; YAZ_PQF_Parser pqf_parser; pqf_parser = yaz_pqf_create (); - RPNquery = yaz_pqf_parse (pqf_parser, odr_en, req->query.pqf); - + RPNquery = yaz_pqf_parse (pqf_parser, odr_en, +#ifdef Z_SRW_query_type_pqf + req->query.pqf +#else + req->query +#endif + ); yaz_pqf_destroy(pqf_parser); if (!RPNquery) @@ -942,7 +1005,7 @@ static mp::filter::Base* filter_creator() } extern "C" { - struct metaproxy_1_filter_struct metaproxy_1_filter_sru_to_z3950 = { + struct metaproxy_1_filter_struct metaproxy_1_filter_sru_z3950 = { 0, "sru_z3950", filter_creator