From 7e2a07a78f7bf299a40b04bda27e9bd6f3ae05b1 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Sat, 3 Dec 2011 01:18:17 +0100 Subject: [PATCH] First go at Package logger SRU to Z39.50 filter captures log from package and makes a extra response data with log content inside element 'log'. --- include/metaproxy/package.hpp | 12 ++++++++---- src/filter_sru_to_z3950.cpp | 16 ++++++++++++++++ src/package.cpp | 29 +++++++++++++++++++++++------ 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/include/metaproxy/package.hpp b/include/metaproxy/package.hpp index 735f11d..bb9d4ba 100644 --- a/include/metaproxy/package.hpp +++ b/include/metaproxy/package.hpp @@ -77,22 +77,26 @@ namespace metaproxy_1 { /// get function - right val in assignment Session session() const; - void log(const char *module, int level, const char *fmt, ...) const; + void log(const char *module, int level, const char *fmt, ...); + + void reset_log(std::string &res); + + class PackageLogger; + typedef boost::shared_ptr PackageLoggerPtr; + private: Session m_session; Origin m_origin; RoutePos *m_route_pos; - //int m_data; + PackageLoggerPtr p_logger; yazpp_1::GDU m_request_gdu; yazpp_1::GDU m_response_gdu; }; } - - #endif /* * Local variables: diff --git a/src/filter_sru_to_z3950.cpp b/src/filter_sru_to_z3950.cpp index 17e5b55..62a542b 100644 --- a/src/filter_sru_to_z3950.cpp +++ b/src/filter_sru_to_z3950.cpp @@ -289,6 +289,22 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) YAZ_SRW_UNSUPP_OPERATION, "unknown"); } + + std::string l; + package.reset_log(l); + if (l.length()) + { + WRBUF w = wrbuf_alloc(); + + wrbuf_puts(w, "\n"); + wrbuf_xmlputs(w, l.c_str()); + wrbuf_puts(w, ""); + + sru_pdu_res->extraResponseData_len = wrbuf_len(w); + sru_pdu_res->extraResponseData_buf = odr_strdup(odr_en, wrbuf_cstr(w)); + wrbuf_destroy(w); + } + // build and send SRU response mp_util::build_sru_response(package, odr_en, soap, sru_pdu_res, charset, stylesheet); diff --git a/src/package.cpp b/src/package.cpp index 23c745a..488b0eb 100644 --- a/src/package.cpp +++ b/src/package.cpp @@ -25,8 +25,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA namespace mp = metaproxy_1; +namespace metaproxy_1 { + class Package::PackageLogger : boost::noncopyable { + friend class Package; + std::string str; + }; +} + mp::Package::Package() - : m_route_pos(0) + : m_route_pos(0), p_logger(new PackageLogger) { } @@ -37,7 +44,7 @@ mp::Package::~Package() mp::Package::Package(mp::Session &session, const mp::Origin &origin) : m_session(session), m_origin(origin), - m_route_pos(0) + m_route_pos(0), p_logger(new PackageLogger) { } @@ -46,6 +53,7 @@ mp::Package & mp::Package::copy_filter(const Package &p) { delete m_route_pos; m_route_pos = p.m_route_pos->clone(); + p_logger = p.p_logger; return *this; } @@ -116,22 +124,31 @@ std::ostream& std::operator<<(std::ostream& os, const mp::Package& p) return os; } -void mp::Package::log(const char *module, int level, const char *fmt, ...) const +void mp::Package::log(const char *module, int level, const char *fmt, ...) { char buf[4096]; va_list ap; va_start(ap, fmt); - yaz_vsnprintf(buf, sizeof(buf)-30, fmt, ap); + buf[0] = ' '; + yaz_vsnprintf(buf + 1, sizeof(buf)-30, fmt, ap); std::ostringstream os; - os << module << " " << *this << " " << buf; + os << module << " " << *this << buf; va_end(ap); yaz_log(level, "%s", os.str().c_str()); + + p_logger->str += std::string(module) + std::string(buf) + std::string("\n"); } - + +void mp::Package::reset_log(std::string &res) +{ + res = p_logger->str; + p_logger->str.clear(); +} + /* * Local variables: * c-basic-offset: 4 -- 1.7.10.4