From: Adam Dickmeiss Date: Mon, 5 Dec 2011 10:46:11 +0000 (+0100) Subject: PackageLogger control by SRU opt x-log-anable X-Git-Tag: v1.3.18~16 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=1cdd720a9a3ba872aa092c80b28413d8b2579eed;p=metaproxy-moved-to-github.git PackageLogger control by SRU opt x-log-anable The log also includes APDUs from ZOOM - requires new YAZ utility ZOOM_connection_save_apdu_wrbuf. --- diff --git a/include/metaproxy/package.hpp b/include/metaproxy/package.hpp index bb9d4ba..8930f0e 100644 --- a/include/metaproxy/package.hpp +++ b/include/metaproxy/package.hpp @@ -49,9 +49,12 @@ namespace metaproxy_1 { Package(metaproxy_1::Session &session, const metaproxy_1::Origin &origin); - /// shallow copy constructor which only copies the filter chain info + /// copy constructor which copies route pos + logger Package & copy_filter(const Package &p); + /// copy constructor which only copies the filter chain info + void copy_route(const Package &p); + /// send Package to it's next Filter defined in Router void move(); @@ -78,8 +81,9 @@ namespace metaproxy_1 { Session session() const; void log(const char *module, int level, const char *fmt, ...); - - void reset_log(std::string &res); + void log_write(const char *buf, size_t sz); + void log_enable(void); + void log_reset(std::string &res); class PackageLogger; typedef boost::shared_ptr PackageLoggerPtr; diff --git a/src/filter_frontend_net.cpp b/src/filter_frontend_net.cpp index 715eb58..7457fae 100644 --- a/src/filter_frontend_net.cpp +++ b/src/filter_frontend_net.cpp @@ -224,7 +224,7 @@ void mp::ZAssocChild::recv_GDU(Z_GDU *z_pdu, int len) mp::Package *p = new mp::Package(m_session, m_origin); mp::ThreadPoolPackage *tp = new mp::ThreadPoolPackage(p, this); - p->copy_filter(*m_package); + p->copy_route(*m_package); p->request() = yazpp_1::GDU(z_pdu); m_thread_pool_observer->put(tp); } @@ -245,7 +245,7 @@ void mp::ZAssocChild::failNotify() mp::Package *p = new mp::Package(m_session, m_origin); mp::ThreadPoolPackage *tp = new mp::ThreadPoolPackage(p, this); - p->copy_filter(*m_package); + p->copy_route(*m_package); m_thread_pool_observer->put(tp); } diff --git a/src/filter_sru_to_z3950.cpp b/src/filter_sru_to_z3950.cpp index 62a542b..8c18dab 100644 --- a/src/filter_sru_to_z3950.cpp +++ b/src/filter_sru_to_z3950.cpp @@ -227,7 +227,11 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) { package.origin().set_custom_session(arg->value); } - + else if (!strcmp(arg->name, "x-log-enable")) + { + if (*arg->value == '1') + package.log_enable(); + } assert(sru_pdu_req); // filter acts as sink for SRU explain requests @@ -291,7 +295,7 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) std::string l; - package.reset_log(l); + package.log_reset(l); if (l.length()) { WRBUF w = wrbuf_alloc(); diff --git a/src/filter_zoom.cpp b/src/filter_zoom.cpp index e999281..b48b58f 100644 --- a/src/filter_zoom.cpp +++ b/src/filter_zoom.cpp @@ -21,10 +21,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include "filter_zoom.hpp" -#include -#include -#include -#include #include #include #include @@ -35,6 +31,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include + +#include +#include +#include #include #include #include @@ -48,6 +48,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include namespace mp = metaproxy_1; namespace yf = mp::filter; @@ -84,6 +85,7 @@ namespace metaproxy_1 { friend class Impl; friend class Frontend; std::string zurl; + WRBUF m_apdu_wrbuf; ZOOM_connection m_connection; ZOOM_resultset m_resultset; std::string m_frontend_database; @@ -200,7 +202,9 @@ void yf::Zoom::process(mp::Package &package) const yf::Zoom::Backend::Backend(SearchablePtr ptr) : sptr(ptr) { + m_apdu_wrbuf = wrbuf_alloc(); m_connection = ZOOM_connection_create(0); + ZOOM_connection_save_apdu_wrbuf(m_connection, m_apdu_wrbuf); m_resultset = 0; xsp = 0; } @@ -1627,6 +1631,9 @@ void yf::Zoom::Frontend::handle_package(mp::Package &package) else if (gdu->which == Z_GDU_Z3950) { Z_APDU *apdu_req = gdu->u.z3950; + + if (m_backend) + wrbuf_rewind(m_backend->m_apdu_wrbuf); if (apdu_req->which == Z_APDU_initRequest) { mp::odr odr; @@ -1652,6 +1659,11 @@ void yf::Zoom::Frontend::handle_package(mp::Package &package) "zoom filter cannot handle this APDU"); package.session().close(); } + if (m_backend) + { + WRBUF w = m_backend->m_apdu_wrbuf; + package.log_write(wrbuf_buf(w), wrbuf_len(w)); + } } else { diff --git a/src/package.cpp b/src/package.cpp index 488b0eb..4cb84e5 100644 --- a/src/package.cpp +++ b/src/package.cpp @@ -33,7 +33,7 @@ namespace metaproxy_1 { } mp::Package::Package() - : m_route_pos(0), p_logger(new PackageLogger) + : m_route_pos(0) { } @@ -44,19 +44,22 @@ mp::Package::~Package() mp::Package::Package(mp::Session &session, const mp::Origin &origin) : m_session(session), m_origin(origin), - m_route_pos(0), p_logger(new PackageLogger) + m_route_pos(0) { } - 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; + copy_route(p); return *this; } +void mp::Package::copy_route(const Package &p) +{ + delete m_route_pos; + m_route_pos = p.m_route_pos->clone(); +} void mp::Package::move() { @@ -140,13 +143,29 @@ void mp::Package::log(const char *module, int level, const char *fmt, ...) va_end(ap); yaz_log(level, "%s", os.str().c_str()); - p_logger->str += std::string(module) + std::string(buf) + std::string("\n"); + if (p_logger) + p_logger->str += std::string(module) + std::string(buf) + std::string("\n"); } -void mp::Package::reset_log(std::string &res) +void mp::Package::log_enable(void) { - res = p_logger->str; - p_logger->str.clear(); + p_logger.reset(new PackageLogger); +} + +void mp::Package::log_write(const char *buf, size_t sz) +{ + if (p_logger) + p_logger->str += std::string(buf, sz); +} + +void mp::Package::log_reset(std::string &res) +{ + if (p_logger) + { + res = p_logger->str; + // p_logger->str.clear(); + p_logger.reset(); + } } /*