X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ffilter_z3950_client.cpp;h=dd16ffe4a0557138700e71156a4f771f1c8cedbc;hb=586d78659d671683f33ec55f4a7d32b28e345ccd;hp=6ea58e4f2351d14e2f72d40f6aa7fb6775965158;hpb=f3e215cc00b02e3d92016f095295af2ba4649e2f;p=metaproxy-moved-to-github.git diff --git a/src/filter_z3950_client.cpp b/src/filter_z3950_client.cpp index 6ea58e4..dd16ffe 100644 --- a/src/filter_z3950_client.cpp +++ b/src/filter_z3950_client.cpp @@ -36,6 +36,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #include #include @@ -84,6 +85,9 @@ namespace metaproxy_1 { int m_timeout_sec; int m_max_sockets; bool m_force_close; + bool m_client_ip; + bool m_bind_host; + std::string m_charset; std::string m_default_target; std::string m_force_target; boost::mutex m_mutex; @@ -297,6 +301,8 @@ 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; + m_p->m_bind_host = false; } yf::Z3950Client::~Z3950Client() { @@ -462,6 +468,35 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) return as; } +static void set_charset_proposal(ODR odr, Z_InitRequest *req, const char *charset) +{ + Z_OtherInformation **p = &req->otherInfo; + Z_OtherInformationUnit *oi; + + if (*p) + { + int i; + for (i = 0; i < (*p)->num_elements; i++) + { + Z_External *ext = (*p)->list[i]->information.externallyDefinedInfo; + if ((*p)->list[i]->which == Z_OtherInfo_externallyDefinedInfo + && ext && + ext->which == Z_External_charSetandLanguageNegotiation) + return; + } + } + if ((oi = yaz_oi_update(p, odr, 0, 0, 0))) + { + ODR_MASK_SET(req->options, Z_Options_negotiationModel); + oi->which = Z_OtherInfo_externallyDefinedInfo; + oi->information.externallyDefinedInfo = + yaz_set_proposal_charneg_list(odr, ",", + charset, + 0 /* lang */, + 1 /* records included */); + } +} + void yf::Z3950Client::Rep::send_and_receive(Package &package, yf::Z3950Client::Assoc *c) { @@ -494,7 +529,18 @@ void yf::Z3950Client::Rep::send_and_receive(Package &package, c->m_waiting = true; if (!c->m_connected) { - if (c->client(c->m_host.c_str())) + std::string host(c->m_host); + + if (m_bind_host) + { + std::string bind_host = package.origin().get_bind_address(); + if (bind_host.length()) + { + host.append(" "); + host.append(bind_host); + } + } + if (c->client(host.c_str())) { mp::odr odr; package.response() = @@ -513,27 +559,30 @@ 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); } + if (apdu->which == Z_APDU_initRequest && m_charset.length() > 0) + set_charset_proposal(odr, apdu->u.initRequest, m_charset.c_str()); + // prepare response c->m_time_elapsed = 0; c->m_waiting = true; @@ -620,6 +669,18 @@ 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 if (!strcmp((const char *) ptr->name, "charset")) + { + m_p->m_charset = mp::xml::get_text(ptr); + } + else if (!strcmp((const char *) ptr->name, "bind_host")) + { + m_p->m_bind_host = mp::xml::get_bool(ptr, 0); + } else { throw mp::filter::FilterException("Bad element "