From a87bf7d5c0ec0a99ef07f6f79c41ef33108c6ecb Mon Sep 17 00:00:00 2001 From: Marc Cromme Date: Fri, 5 Jan 2007 12:26:50 +0000 Subject: [PATCH] more work on zeerex explain filter, to be continued --- src/filter_zeerex_explain.cpp | 9 +-------- src/sru_util.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- src/sru_util.hpp | 20 +++++++++++++++++++- 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/filter_zeerex_explain.cpp b/src/filter_zeerex_explain.cpp index a721413..eae42cd 100644 --- a/src/filter_zeerex_explain.cpp +++ b/src/filter_zeerex_explain.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_zeerex_explain.cpp,v 1.1 2006-12-28 14:59:44 marc Exp $ +/* $Id: filter_zeerex_explain.cpp,v 1.2 2007-01-05 12:26:50 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -99,13 +99,6 @@ void yf::ZeeRexExplain::Impl::process(mp::Package &package) const return; } - - // SRU request package translation to Z3950 package - //if (sru_pdu_req) - // std::cout << *sru_pdu_req << "\n"; - //else - // std::cout << "SRU empty\n"; - if (sru_pdu_req->which != Z_SRW_explain_request){ // Let pass all other SRU actions diff --git a/src/sru_util.cpp b/src/sru_util.cpp index 881a86c..4b46ac9 100644 --- a/src/sru_util.cpp +++ b/src/sru_util.cpp @@ -1,4 +1,4 @@ -/* $Id: sru_util.cpp,v 1.3 2006-12-28 13:26:06 marc Exp $ +/* $Id: sru_util.cpp,v 1.4 2007-01-05 12:26:50 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -35,6 +35,42 @@ bool mp_util::build_sru_debug_package(mp::Package &package) return false; } +void mp_util::get_sru_server_info(mp::Package &package, + Z_SRW_explainRequest + const *er_req) +{ + + SRUServerInfo sruinfo; + + // getting database info + std::string database("Default"); + if (er_req && er_req->database) + database = er_req->database; + + // getting host and port info + std::string host = package.origin().listen_host(); + std::string port = mp_util::to_string(package.origin().listen_port()); + + // overwriting host and port info if set from HTTP Host header + Z_GDU *zgdu_req = package.request().get(); + if (zgdu_req && zgdu_req->which == Z_GDU_HTTP_Request) + { + Z_HTTP_Request* http_req = zgdu_req->u.HTTP_Request; + if (http_req) + { + std::string http_host_address + = mp_util::http_header_value(http_req->headers, "Host"); + + std::string::size_type i = http_host_address.rfind(":"); + if (i != std::string::npos) + { + host.assign(http_host_address, 0, i); + port.assign(http_host_address, i + 1, std::string::npos); + } + } + } +} + bool mp_util::build_simple_explain(mp::Package &package, mp::odr &odr_en, @@ -78,7 +114,7 @@ bool mp_util::build_simple_explain(mp::Package &package, // building SRU explain record std::string explain_xml = mp_util::to_string( - "\n" + "\n" " \n" " ") + host diff --git a/src/sru_util.hpp b/src/sru_util.hpp index da8598d..323ea4a 100644 --- a/src/sru_util.hpp +++ b/src/sru_util.hpp @@ -1,4 +1,4 @@ -/* $Id: sru_util.hpp,v 1.4 2006-12-28 13:26:06 marc Exp $ +/* $Id: sru_util.hpp,v 1.5 2007-01-05 12:26:50 marc Exp $ - Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -35,6 +35,10 @@ namespace metaproxy_1 { bool build_sru_debug_package(metaproxy_1::Package &package); + void get_sru_server_info(metaproxy_1::Package &package, + Z_SRW_explainRequest + const *er_req); + bool build_simple_explain(metaproxy_1::Package &package, metaproxy_1::odr &odr_en, Z_SRW_PDU *sru_pdu_res, @@ -63,6 +67,20 @@ namespace metaproxy_1 { Z_ElementSetNames * build_esn_from_schema(metaproxy_1::odr &odr_en, const char *schema); + + class SRUServerInfo + { + public: + SRUServerInfo () + : database("Default") + {} + public: + std::string database; + std::string host; + std::string port; + }; + + // class SRU -- 1.7.10.4