X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ffilter_sru_to_z3950.cpp;h=26a6ad2d009cafa99648fbf7b6f59a7f1709436a;hb=5cb1f9609e107e4ba58e0d2726a28e0a3fe33135;hp=06305bb6d9d696247300181b296e26a7882eeabd;hpb=3f4bd901440c6f15c3468cd46a34993d7a2d8571;p=metaproxy-moved-to-github.git diff --git a/src/filter_sru_to_z3950.cpp b/src/filter_sru_to_z3950.cpp index 06305bb..26a6ad2 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,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include +#if YAZ_VERSIONL >= 0x50000 +#include +#endif #include #include @@ -60,6 +64,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; @@ -148,27 +153,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 +216,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) { @@ -264,6 +282,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); } @@ -271,6 +291,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); @@ -302,6 +323,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, @@ -336,6 +358,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, @@ -495,6 +519,19 @@ yf::SRUtoZ3950::Impl::z3950_init_request(mp::Package &package, mp_util::set_vhost_otherinfo(&init_req->otherInfo, odr_en, host, 1); } + Z_GDU *zgdu_req = package.request().get(); + if (zgdu_req->which == Z_GDU_HTTP_Request) + { + Z_HTTP_Request *hreq = zgdu_req->u.HTTP_Request; + const char *peer_name = + z_HTTP_header_lookup(hreq->headers, "X-Forwarded-For"); + if (peer_name) + { + yaz_oi_set_string_oid(&init_req->otherInfo, odr_en, + yaz_oid_userinfo_client_ip, 1, peer_name); + } + } + z3950_package.request() = apdu; // send Z3950 package @@ -597,6 +634,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; @@ -637,7 +682,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; @@ -869,7 +919,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)); @@ -878,22 +934,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)