From 0098e12fb155644a8befc6c5c5a3d04308128e72 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 6 Mar 2014 10:35:54 +0100 Subject: [PATCH] z3950_client: client_ip controls client-IP presence If client_ip setting (boolean) is enabled, z3950_client will generate a client_ip OID as part of init request which includes previous client_ip (if any) and current peer address (immediate client of Metaproxy). By default client_ip is disabled and client_ip will not be generated. --- etc/config1.xml | 1 + src/filter_z3950_client.cpp | 38 +++++++++++++++++++++--------------- xml/schema/filter_z3950_client.rnc | 3 ++- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/etc/config1.xml b/etc/config1.xml index 583a508..5154e71 100644 --- a/etc/config1.xml +++ b/etc/config1.xml @@ -14,6 +14,7 @@ 30 localhost:9999 true + true diff --git a/src/filter_z3950_client.cpp b/src/filter_z3950_client.cpp index 6ea58e4..343e33d 100644 --- a/src/filter_z3950_client.cpp +++ b/src/filter_z3950_client.cpp @@ -84,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; @@ -297,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() { @@ -513,26 +515,26 @@ void yf::Z3950Client::Rep::send_and_receive(Package &package, { return; } - const char *peer_name2 = package.origin().get_address().c_str(); mp::odr odr; - if (apdu->which == Z_APDU_initRequest && peer_name2) + if (m_client_ip) { - Z_OtherInformation **oi = &apdu->u.initRequest->otherInfo; - char *peer_name1 = - yaz_oi_get_string_oid(oi, yaz_oid_userinfo_client_ip, 1, 1); - char *pcomb = (char *) - odr_malloc(odr, (peer_name1 ? strlen(peer_name1) : 0) - + strlen(peer_name2) + 4); - strcpy(pcomb, ""); - if (peer_name1) + std::string peer_name2 = package.origin().get_address(); + if (apdu->which == Z_APDU_initRequest && peer_name2.length()) { - strcat(pcomb, peer_name1); - strcat(pcomb, ", "); + 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()); } - strcat(pcomb, peer_name2); - yaz_oi_set_string_oid(&apdu->u.initRequest->otherInfo, - odr, yaz_oid_userinfo_client_ip, - 1, pcomb); } // prepare response c->m_time_elapsed = 0; @@ -620,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 " diff --git a/xml/schema/filter_z3950_client.rnc b/xml/schema/filter_z3950_client.rnc index 34dab61..04c6b64 100644 --- a/xml/schema/filter_z3950_client.rnc +++ b/xml/schema/filter_z3950_client.rnc @@ -9,5 +9,6 @@ filter_z3950_client = element mp:timeout { xsd:integer }?, element mp:default_target { xsd:string }?, element mp:force_target { xsd:string }?, - element mp:force_close { xsd:boolean }? + element mp:force_close { xsd:boolean }?, + element mp:client_ip { xsd:boolean }? -- 1.7.10.4