X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ffilter_zoom.cpp;h=a29f243b51a278878749738b804d5df4accd4cc6;hb=c4e649b6b0210d9c714cf166f246a3f2d66c12c8;hp=2a93af5670a84cec872ac1df73870710bf862fe5;hpb=b1d299c751b81d4c9bc113a0300daf0667063710;p=metaproxy-moved-to-github.git diff --git a/src/filter_zoom.cpp b/src/filter_zoom.cpp index 2a93af5..a29f243 100644 --- a/src/filter_zoom.cpp +++ b/src/filter_zoom.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 @@ -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; @@ -112,6 +113,7 @@ namespace metaproxy_1 { void present(Odr_int start, Odr_int number, ZOOM_record *recs, int *error, char **addinfo, ODR odr); void set_option(const char *name, const char *value); + void set_option(const char *name, const char *value, size_t l); void set_option(const char *name, std::string value); const char *get_option(const char *name); void get_zoom_error(int *error, char **addinfo, ODR odr); @@ -458,6 +460,12 @@ void yf::Zoom::Backend::present(Odr_int start, Odr_int number, get_zoom_error(error, addinfo, odr); } + +void yf::Zoom::Backend::set_option(const char *name, const char *value, size_t l) +{ + ZOOM_connection_option_setl(m_connection, name, value, l); +} + void yf::Zoom::Backend::set_option(const char *name, const char *value) { ZOOM_connection_option_set(m_connection, name, value); @@ -1483,54 +1491,31 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( } else { - if (sptr->sru.length() == 0) - b->set_option("user", authentication); /* Z39.50 */ + const char *auth = authentication.c_str(); + const char *cp1 = strchr(auth, ' '); + if (!cp1 && sptr->sru.length()) + cp1 = strchr(auth, '/'); + if (!cp1) + { + /* Z39.50 user/password style, or no password for SRU */ + b->set_option("user", auth); + } else { - std::string user; - std::string password; - std::string authtype = sptr->authenticationMode; + /* now consider group as well */ + const char *cp2 = strchr(cp1 + 1, ' '); - { - const char *cstr = authentication.c_str(); - const char *cp1 = strchr(cstr, '/'); - if (cp1) - { - password.assign(cp1 + 1); - user.assign(cstr, cp1 - cstr); - } - else - user.assign(cstr); - } - - if (authtype.compare("url") == 0) - { - /* SRU URL encoding of auth stuff */ - ODR o = odr_createmem(ODR_ENCODE); - char *path = 0; - const char *names[3]; - const char *values[3]; - - names[0] = "x-username"; - values[0] = user.c_str(); - names[1] = "x-password"; - values[1] = password.c_str(); - names[2] = 0; - values[2] = 0; - - yaz_array_to_uri(&path, o, (char **) names, (char **) values); - if (extraArgs.length()) - extraArgs.append("&"); - extraArgs.append(path); - odr_destroy(o); - } + b->set_option("user", auth, cp1 - auth); + if (!cp2) + b->set_option("password", cp1 + 1); else { - b->set_option("user", user); - if (password.length()) - b->set_option("password", password); + b->set_option("group", cp1 + 1, cp2 - cp1 - 1); + b->set_option("password", cp2 + 1); } } + if (sptr->authenticationMode.length()) + b->set_option("authenticationMode", sptr->authenticationMode); if (proxy.length()) b->set_option("proxy", proxy); } @@ -2392,45 +2377,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); } @@ -2630,8 +2606,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; @@ -2644,13 +2625,8 @@ 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; }