X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ffilter_zoom.cpp;h=5a4446912ddc1212e83e378fe9243cd95777743b;hb=b57b6423aebc8f0aaeb4913f1a010e821dc6c456;hp=968b96b7f2427770b6b4ca01afece2982e5fc563;hpb=6537605b578008fe0c57c209b72e97b9a9a4f5e5;p=metaproxy-moved-to-github.git diff --git a/src/filter_zoom.cpp b/src/filter_zoom.cpp index 968b96b..5a44469 100644 --- a/src/filter_zoom.cpp +++ b/src/filter_zoom.cpp @@ -51,6 +51,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include namespace mp = metaproxy_1; namespace yf = mp::filter; @@ -1256,15 +1257,17 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( sptr = it->second; else if (torus_url.length() > 0) { + std::string torus_addinfo; std::string torus_query = "udb==" + torus_db; xmlDoc *doc = mp::get_searchable(package,torus_url, torus_db, torus_query, - realm, m_p->proxy); + realm, m_p->proxy, + torus_addinfo); if (!doc) { *error = YAZ_BIB1_UNSPECIFIED_ERROR; - *addinfo = odr_strdup(odr, "Torus server unavailable or " - "incorrectly configured"); + if (torus_addinfo.length()) + *addinfo = odr_strdup(odr, torus_addinfo.c_str()); BackendPtr b; return b; } @@ -2012,10 +2015,12 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::explain_search(mp::Package &package, else if (query->which == Z_Query_type_104 && query->u.type_104->which == Z_External_CQL) { + std::string torus_addinfo; std::string torus_query(query->u.type_104->u.cql); xmlDoc *doc = mp::get_searchable(package, torus_url, "", torus_query, - realm, m_p->proxy); + realm, m_p->proxy, + torus_addinfo); if (m_p->explain_xsp) { xmlDoc *rec_res = xsltApplyStylesheet(m_p->explain_xsp, doc, 0); @@ -2026,8 +2031,8 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::explain_search(mp::Package &package, if (!doc) { *error = YAZ_BIB1_UNSPECIFIED_ERROR; - *addinfo = odr_strdup(odr, "Torus server unavailable or " - "incorrectly configured"); + if (torus_addinfo.length()) + *addinfo = odr_strdup(odr, torus_addinfo.c_str()); } else { @@ -2376,45 +2381,36 @@ next_proxy: if (b->get_option("sru")) { - int status = 0; Z_RPNQuery *zquery; zquery = p_query_rpn(odr, wrbuf_cstr(pqf_wrbuf)); - mp::wrbuf wrb; + mp::wrbuf wrb_cql; + mp::wrbuf wrb_addinfo; if (!strcmp(b->get_option("sru"), "solr")) - { - solr_transform_t cqlt = solr_transform_create(); - - status = solr_transform_rpn2solr_wrbuf(cqlt, wrb, zquery); - - solr_transform_close(cqlt); - } + error = solr_transform_rpn2solr_stream_r(b->cqlt, wrb_addinfo, + wrbuf_vp_puts, wrb_cql, + zquery); else + error = cql_transform_rpn2cql_stream_r(b->cqlt, wrb_addinfo, + wrbuf_vp_puts, wrb_cql, + zquery); + if (error) { - status = cql_transform_rpn2cql_wrbuf(b->cqlt, wrb, zquery); - } - if (status == 0) - { - ZOOM_query_cql(q, wrbuf_cstr(wrb)); - package.log("zoom", YLOG_LOG, "CQL: %s", wrbuf_cstr(wrb)); - b->search(q, &hits, &error, &addinfo, &fl, odr); - } - ZOOM_query_destroy(q); - - if (status) - { - error = YAZ_BIB1_MALFORMED_QUERY; - const char *addinfo = "can not convert from RPN to CQL/Solr"; - log_diagnostic(package, error, addinfo); - apdu_res = odr.create_searchResponse(apdu_req, error, addinfo); + log_diagnostic(package, error, wrb_addinfo.c_str_null()); + apdu_res = odr.create_searchResponse(apdu_req, error, + wrb_addinfo.c_str_null()); package.response() = apdu_res; return; } + ZOOM_query_cql(q, wrb_cql.c_str()); + package.log("zoom", YLOG_LOG, "search CQL: %s", wrb_cql.c_str()); + b->search(q, &hits, &error, &addinfo, &fl, odr); + ZOOM_query_destroy(q); } else { - ZOOM_query_prefix(q, wrbuf_cstr(pqf_wrbuf)); - package.log("zoom", YLOG_LOG, "search PQF: %s", wrbuf_cstr(pqf_wrbuf)); + ZOOM_query_prefix(q, pqf_wrbuf.c_str()); + package.log("zoom", YLOG_LOG, "search PQF: %s", pqf_wrbuf.c_str()); b->search(q, &hits, &error, &addinfo, &fl, odr); ZOOM_query_destroy(q); } @@ -2614,8 +2610,13 @@ void yf::Zoom::Frontend::auth(mp::Package &package, Z_InitRequest *req, } } - std::string ip = package.origin().get_address(); - yaz_log(YLOG_LOG, "IP=%s", ip.c_str()); + Z_OtherInformation **oi = &req->otherInfo; + const char *ip = + yaz_oi_get_string_oid(oi, yaz_oid_userinfo_client_ip, 1, 0); + if (!ip) + ip = package.origin().get_address().c_str(); + + yaz_log(YLOG_LOG, "IP=%s", ip); std::string torus_query; int failure_code; @@ -2628,27 +2629,24 @@ void yf::Zoom::Frontend::auth(mp::Package &package, Z_InitRequest *req, } else { - const char *ip_cstr = ip.c_str(); - const char *cp = strchr(ip_cstr, ':'); - if (cp) - ip_cstr = cp + 1; - torus_query = "ip encloses/net.ipaddress \""; - torus_query += escape_cql_term(std::string(ip_cstr)); + torus_query += escape_cql_term(std::string(ip)); torus_query += "\""; failure_code = YAZ_BIB1_INIT_AC_BLOCKED_NETWORK_ADDRESS; } std::string dummy_db; std::string dummy_realm; + std::string torus_addinfo; xmlDoc *doc = mp::get_searchable(package, m_p->torus_auth_url, dummy_db, - torus_query, dummy_realm, m_p->proxy); + torus_query, dummy_realm, m_p->proxy, + torus_addinfo); if (!doc) { // something fundamental broken in lookup. *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR; - *addinfo = odr_strdup(odr, "zoom: torus server unavailable or " - "incorrectly configured."); + if (torus_addinfo.length()) + *addinfo = odr_strdup(odr, torus_addinfo.c_str()); return; } const xmlNode *ptr = xmlDocGetRootElement(doc);