X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ffilter_zoom.cpp;h=2062b1c0ce5621b57314403680fc9fbfabef1646;hb=dbcf08a20fbdaf78c823c365b77b5876a07e8de7;hp=b9567e6ea56590513a092c2779a75ed7b60cd9d6;hpb=6c53f69359d38fb81ed546c97e558c42826706b6;p=metaproxy-moved-to-github.git diff --git a/src/filter_zoom.cpp b/src/filter_zoom.cpp index b9567e6..2062b1c 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); @@ -426,14 +428,23 @@ void yf::Zoom::Backend::search(ZOOM_query q, Odr_int *hits, ae->value.complex->semanticAction = 0; int num_terms = ZOOM_facet_field_term_count(ff); - fl->elements[i] = facet_field_create(odr, al, num_terms); + fl->elements[i] = (Z_FacetField *) + odr_malloc(odr, sizeof(Z_FacetField)); + fl->elements[i]->attributes = al; + fl->elements[i]->num_terms = num_terms; + fl->elements[i]->terms = (Z_FacetTerm **) + odr_malloc(odr, num_terms * sizeof(Z_FacetTerm *)); int j; for (j = 0; j < num_terms; j++) { int freq; const char *a_term = ZOOM_facet_field_get_term(ff, j, &freq); - fl->elements[i]->terms[j] = - facet_term_create_cstr(odr, a_term, freq); + Z_FacetTerm *ft = (Z_FacetTerm *) odr_malloc(odr, sizeof(*ft)); + ft->term = z_Term_create(odr, Z_Term_general, a_term, + strlen(a_term)); + ft->count = odr_intdup(odr, freq); + + fl->elements[i]->terms[j] = ft; } } fl->num = i; @@ -449,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); @@ -1463,6 +1480,9 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( out_names[no_out_args] = "subdatabase"; out_values[no_out_args++] = odr_strdup(odr, sptr->cfSubDB.c_str()); } + if (!param_nocproxy && b->sptr->contentConnector.length()) + param_nocproxy = "1"; + if (param_nocproxy) { out_names[no_out_args] = "nocproxy"; @@ -1471,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); } @@ -2618,8 +2615,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; @@ -2632,13 +2634,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; }