X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Ffilter_z3950_client.cpp;h=343e33d9aa99cdcfdb090703c3e61bad982e1305;hb=1f9dc5dc6b1fcaf732cd397370e25834ad891274;hp=d4f78a96555f670bd049f7ce7466efa8df21474e;hpb=0c6eba26ee91d65a80d59cded57a8b7d3c8686fe;p=metaproxy-moved-to-github.git diff --git a/src/filter_z3950_client.cpp b/src/filter_z3950_client.cpp index d4f78a9..343e33d 100644 --- a/src/filter_z3950_client.cpp +++ b/src/filter_z3950_client.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2012 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 @@ -35,6 +35,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #include #include @@ -83,6 +84,7 @@ namespace metaproxy_1 { int m_timeout_sec; int m_max_sockets; bool m_force_close; + bool m_client_ip; std::string m_default_target; std::string m_force_target; boost::mutex m_mutex; @@ -238,9 +240,10 @@ void yf::Z3950Client::Assoc::fixup_init(ODR odr, Z_InitResponse *initrs) odr, (oaddinfo ? strlen(oaddinfo) : 0) + 20 + m_host.length()); + *naddinfo = '\0'; if (oaddinfo && *oaddinfo) { - strcpy(naddinfo, oaddinfo); + strcat(naddinfo, oaddinfo); strcat(naddinfo, " "); } strcat(naddinfo, "(backend="); @@ -295,6 +298,7 @@ yf::Z3950Client::Z3950Client() : m_p(new yf::Z3950Client::Rep) m_p->m_timeout_sec = 30; m_p->m_max_sockets = 0; m_p->m_force_close = false; + m_p->m_client_ip = false; } yf::Z3950Client::~Z3950Client() { @@ -424,12 +428,19 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) mp::odr odr; package.response() = odr.create_initResponse( - apdu, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, "max sessions"); + apdu, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, + "z3950_client: max sessions"); package.session().close(); return 0; } boost::xtime xt; - xtime_get(&xt, boost::TIME_UTC); + xtime_get(&xt, +#if BOOST_VERSION >= 105000 + boost::TIME_UTC_ +#else + boost::TIME_UTC +#endif + ); xt.sec += 15; if (!m_cond_session_ready.timed_wait(lock, xt)) @@ -437,7 +448,8 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) mp::odr odr; package.response() = odr.create_initResponse( - apdu, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, "max sessions"); + apdu, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, + "z3950_client: max sessions"); package.session().close(); return 0; } @@ -477,6 +489,8 @@ void yf::Z3950Client::Rep::send_and_receive(Package &package, if (gdu->u.z3950->which == Z_APDU_close) c->m_has_closed = true; + Z_APDU *apdu = gdu->u.z3950; + // prepare connect c->m_time_elapsed = 0; c->m_waiting = true; @@ -501,7 +515,27 @@ void yf::Z3950Client::Rep::send_and_receive(Package &package, { return; } - + mp::odr odr; + if (m_client_ip) + { + std::string peer_name2 = package.origin().get_address(); + if (apdu->which == Z_APDU_initRequest && peer_name2.length()) + { + Z_OtherInformation **oi = &apdu->u.initRequest->otherInfo; + char *peer_name1 = + yaz_oi_get_string_oid(oi, yaz_oid_userinfo_client_ip, 1, 1); + std::string pcomb; + if (peer_name1) + { + pcomb.append(peer_name1); + pcomb.append(", "); + } + pcomb.append(peer_name2); + yaz_oi_set_string_oid(&apdu->u.initRequest->otherInfo, + odr, yaz_oid_userinfo_client_ip, + 1, pcomb.c_str()); + } + } // prepare response c->m_time_elapsed = 0; c->m_waiting = true; @@ -588,6 +622,10 @@ void yf::Z3950Client::configure(const xmlNode *ptr, bool test_only, { m_p->m_force_close = mp::xml::get_bool(ptr, 0); } + else if (!strcmp((const char *) ptr->name, "client_ip")) + { + m_p->m_client_ip = mp::xml::get_bool(ptr, 0); + } else { throw mp::filter::FilterException("Bad element "