From 5f2548e1ed0e214ad7f921e292fc23224cf4cff4 Mon Sep 17 00:00:00 2001 From: Marc Cromme Date: Mon, 2 Oct 2006 12:01:06 +0000 Subject: [PATCH] added socket listen_host and listen_port to Origin class added parsing of HTTP server_host and server_port added use of HTTP server_host and server_port in SRU short explain --- src/filter_sru_to_z3950.cpp | 31 ++++++++++++++++++++++++++++--- src/origin.cpp | 27 +++++++++++++++++++-------- src/origin.hpp | 22 ++++++++++++++-------- 3 files changed, 61 insertions(+), 19 deletions(-) diff --git a/src/filter_sru_to_z3950.cpp b/src/filter_sru_to_z3950.cpp index d3a672d..d8469c9 100644 --- a/src/filter_sru_to_z3950.cpp +++ b/src/filter_sru_to_z3950.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_sru_to_z3950.cpp,v 1.16 2006-09-29 09:48:36 marc Exp $ +/* $Id: filter_sru_to_z3950.cpp,v 1.17 2006-10-02 12:01:06 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -254,6 +254,8 @@ bool yf::SRUtoZ3950::Impl::build_simple_explain(mp::Package &package, const *er_req) const { + + // z3950'fy recordPacking int record_packing = Z_SRW_recordPacking_XML; if (er_req->recordPacking && 's' == *(er_req->recordPacking)) @@ -264,16 +266,39 @@ bool yf::SRUtoZ3950::Impl::build_simple_explain(mp::Package &package, if (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); + } + } + } + // building SRU explain record std::string explain_xml = mp_util::to_string( "\n" " \n" " ") - + package.origin().server_host() + + host + mp_util::to_string("\n" " ") - + mp_util::to_string(package.origin().server_port()) + + port + mp_util::to_string("\n" " ") + database diff --git a/src/origin.cpp b/src/origin.cpp index 0880c3a..e4454a5 100644 --- a/src/origin.cpp +++ b/src/origin.cpp @@ -1,4 +1,4 @@ -/* $Id: origin.cpp,v 1.3 2006-09-26 13:02:50 marc Exp $ +/* $Id: origin.cpp,v 1.4 2006-10-02 12:01:06 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -12,23 +12,34 @@ namespace mp = metaproxy_1; -mp::Origin::Origin(std::string server_host, - unsigned int server_port) +mp::Origin::Origin(std::string listen_host, + unsigned int listen_port) : m_type(API), m_address(""), m_origin_id(0), - m_server_host(server_host), m_server_port(server_port) + m_listen_host(listen_host), m_listen_port(listen_port) { } -std::string mp::Origin::server_host() const +std::string mp::Origin::listen_host() const { - return m_server_host; + return m_listen_host; }; -unsigned int mp::Origin::server_port() const +std::string & mp::Origin::listen_host() { - return m_server_port; + return m_listen_host; }; +unsigned int mp::Origin::listen_port() const +{ + return m_listen_port; +}; + +unsigned int & mp::Origin::listen_port() +{ + return m_listen_port; +}; + + void mp::Origin::set_tcpip_address(std::string addr, unsigned long s) { diff --git a/src/origin.hpp b/src/origin.hpp index 00df465..8799ff9 100644 --- a/src/origin.hpp +++ b/src/origin.hpp @@ -1,4 +1,4 @@ -/* $Id: origin.hpp,v 1.1 2006-09-26 13:04:07 marc Exp $ +/* $Id: origin.hpp,v 1.2 2006-10-02 12:01:06 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -22,14 +22,20 @@ namespace metaproxy_1 { class Origin { public: - Origin(std::string server_host = "", unsigned int server_port = 0); + Origin(std::string listen_host = "", unsigned int listen_port = 0); /// get function - right val in assignment - std::string server_host() const; - + std::string listen_host() const; + + /// set function - left val in assignment + std::string & listen_host(); + /// get function - right val in assignment - unsigned int server_port() const; + unsigned int listen_port() const; + /// set function - left val in assignment + unsigned int & listen_port(); + /// set client IP info - left val in assignment void set_tcpip_address(std::string addr, unsigned long id); @@ -43,9 +49,9 @@ namespace metaproxy_1 { TCPIP } m_type; std::string m_address; // UNIX+TCPIP - unsigned long m_origin_id; - std::string m_server_host; - unsigned int m_server_port; + unsigned int m_origin_id; + std::string m_listen_host; + unsigned int m_listen_port; }; } -- 1.7.10.4