From ba1d95aa261abbe9f85b0bffa1926a34432aeadd Mon Sep 17 00:00:00 2001 From: Marc Cromme Date: Tue, 29 Aug 2006 10:06:31 +0000 Subject: [PATCH] Package logging of Z_GDU structs re-factored into own operator<< --- src/Makefile.am | 3 +- src/filter_log.cpp | 304 ++++++---------------------------------------------- src/gduutil.cpp | 228 +++++++++++++++++++++++++++++++++++++++ src/gduutil.hpp | 37 +++++++ 4 files changed, 297 insertions(+), 275 deletions(-) create mode 100644 src/gduutil.cpp create mode 100644 src/gduutil.hpp diff --git a/src/Makefile.am b/src/Makefile.am index 9b6cbab..c0a8584 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.50 2006-03-16 10:40:59 adam Exp $ +## $Id: Makefile.am,v 1.51 2006-08-29 10:06:31 marc Exp $ MAINTAINERCLEANFILES = Makefile.in config.in config.hpp @@ -26,6 +26,7 @@ libmetaproxy_la_SOURCES = \ filter_template.cpp filter_template.hpp \ filter_virt_db.cpp filter_virt_db.hpp \ filter_z3950_client.cpp filter_z3950_client.hpp \ + gduutil.cpp gduutil.hpp \ package.cpp package.hpp \ pipe.cpp pipe.hpp \ plainfile.cpp \ diff --git a/src/filter_log.cpp b/src/filter_log.cpp index 917cc1b..95f6600 100644 --- a/src/filter_log.cpp +++ b/src/filter_log.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_log.cpp,v 1.22 2006-08-28 21:40:24 marc Exp $ +/* $Id: filter_log.cpp,v 1.23 2006-08-29 10:06:31 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -12,6 +12,7 @@ #include #include +#include "gduutil.hpp" #include "util.hpp" #include "xmlutil.hpp" #include "filter_log.hpp" @@ -109,149 +110,17 @@ void yf::Log::process(mp::Package &package) const if (m_p->m_access) { - gdu = package.request().get(); - WRBUF wr = wrbuf_alloc(); - - if (gdu && gdu->which == Z_GDU_Z3950) - { - - msg_request << "Z39.50" << " "; - - switch(gdu->u.z3950->which) - { - case Z_APDU_initRequest: - msg_request - << "initRequest" << " " - << "OK" << " "; - - { - Z_InitRequest *ir - = gdu->u.z3950->u.initRequest; - msg_request_2 - << (ir->implementationId) << " " - //<< ir->referenceId << " " - << (ir->implementationName) << " " - << (ir->implementationVersion) << " "; - } - break; - case Z_APDU_searchRequest: - msg_request - << "searchRequest" << " " - << "OK" << " "; - { - Z_SearchRequest *sr - = gdu->u.z3950->u.searchRequest; - - for (int i = 0; i < sr->num_databaseNames; i++) - { - msg_request << sr->databaseNames[i]; - if (i+1 == sr->num_databaseNames) - msg_request << " "; - else - msg_request << "+"; - } - - yaz_query_to_wrbuf(wr, sr->query); - } - msg_request_2 << wrbuf_buf(wr) << " "; - break; - case Z_APDU_presentRequest: - msg_request - << "presentRequest" << " " - << "OK" << " "; - { - Z_PresentRequest *pr - = gdu->u.z3950->u.presentRequest; - msg_request_2 - << pr->resultSetId << " " - //<< pr->referenceId << " " - << *(pr->resultSetStartPoint) << " " - << *(pr->numberOfRecordsRequested) << " "; - } - break; - case Z_APDU_deleteResultSetRequest: - msg_request - << "deleteResultSetRequest" << " " - << "OK" << " "; - break; - case Z_APDU_accessControlRequest: - msg_request - << "accessControlRequest" << " " - << "OK" << " "; - break; - case Z_APDU_resourceControlRequest: - msg_request - << "resourceControlRequest" << " " - << "OK" << " "; - break; - case Z_APDU_triggerResourceControlRequest: - msg_request - << "triggerResourceControlRequest" << " " - << "OK" << " "; - break; - case Z_APDU_resourceReportRequest: - msg_request - << "resourceReportRequest" << " " - << "OK" << " "; - break; - case Z_APDU_scanRequest: - msg_request - << "scanRequest" << " " - << "OK" << " "; - break; - case Z_APDU_sortRequest: - msg_request - << "sortRequest" << " " - << "OK" << " "; - break; - case Z_APDU_segmentRequest: - msg_request - << "segmentRequest" << " " - << "OK" << " "; - break; - case Z_APDU_extendedServicesRequest: - msg_request - << "extendedServicesRequest" << " " - << "OK" << " "; - break; - case Z_APDU_close: - msg_response - << "close" << " " - << "OK" << " "; - break; - case Z_APDU_duplicateDetectionRequest: - msg_request - << "duplicateDetectionRequest" << " " - << "OK" << " "; - break; - default: - msg_request - << "unknown" << " " - << "ERROR" << " "; - } - } - else if (gdu && gdu->which == Z_GDU_HTTP_Request) - msg_request << "HTTP " << "unknown " ; - else if (gdu && gdu->which == Z_GDU_HTTP_Response) - msg_request << "HTTP-Response " << "unknown " ; - else - msg_request << "unknown " << "unknown " ; - - wrbuf_free(wr, 1); - - m_p->m_file->out - << m_p->m_msg_config << " " - << package.session().id() << " " - << receive_time << " " - // << send_time << " " - << "00:00:00.000000" << " " - // << duration << " " - << msg_request.str() - << msg_request_2.str() - //<< msg_response.str() - //<< msg_response_2.str() - << "\n"; + if (gdu) + { + m_p->m_file->out + << m_p->m_msg_config << " " + << package.session().id() << " " + << receive_time << " " + << "00:00:00.000000" << " " + << *gdu + << "\n"; + } } if (m_p->m_req_session) @@ -262,6 +131,7 @@ void yf::Log::process(mp::Package &package) const << (package.session().is_closed() ? "yes" : "no") << "\n"; } + if (m_p->m_init_options) { gdu = package.request().get(); @@ -275,7 +145,7 @@ void yf::Log::process(mp::Package &package) const m_p->m_file->out << "\n"; } } - + if (m_p->m_req_apdu) { gdu = package.request().get(); @@ -288,7 +158,7 @@ void yf::Log::process(mp::Package &package) const } m_p->m_file->out.flush(); } - + // unlocked during move package.move(); @@ -301,139 +171,22 @@ void yf::Log::process(mp::Package &package) const // scope for locking Ostream { boost::mutex::scoped_lock scoped_lock(m_p->m_file->m_mutex); + if (m_p->m_access) { gdu = package.response().get(); - //WRBUF wr = wrbuf_alloc(); - - - if (gdu && gdu->which == Z_GDU_Z3950) - { - - msg_response << "Z39.50" << " "; - - switch(gdu->u.z3950->which) - { - case Z_APDU_initResponse: - msg_response << "initResponse" << " "; - { - Z_InitResponse *ir - = gdu->u.z3950->u.initResponse; - if (*(ir->result)) - msg_response_2 - << "OK" << " " - << (ir->implementationId) << " " - //<< ir->referenceId << " " - << (ir->implementationName) << " " - << (ir->implementationVersion) << " "; - else - msg_response_2 - << "ERROR" << " " - << "- - -" << " "; - - } - break; - case Z_APDU_searchResponse: - msg_response << "searchResponse" << " "; - { - Z_SearchResponse *sr - = gdu->u.z3950->u.searchResponse; - if (*(sr->searchStatus)) - msg_response_2 - << "OK" << " " - << *(sr->resultCount) << " " - //<< sr->referenceId << " " - << *(sr->numberOfRecordsReturned) << " " - << *(sr->nextResultSetPosition) << " "; - else - msg_response_2 - << "ERROR" << " " - << "- - -" << " "; - - } - //msg_response << wrbuf_buf(wr) << " "; - break; - case Z_APDU_presentResponse: - msg_response << "presentResponse" << " "; - { - Z_PresentResponse *pr - = gdu->u.z3950->u.presentResponse; - if (!*(pr->presentStatus)) - msg_response_2 - << "OK" << " " - << "-" << " " - //<< pr->referenceId << " " - << *(pr->numberOfRecordsReturned) << " " - << *(pr->nextResultSetPosition) << " "; - else - msg_response_2 - << "ERROR" << " " - << "-" << " " - //<< pr->referenceId << " " - << *(pr->numberOfRecordsReturned) << " " - << *(pr->nextResultSetPosition) << " "; - //<< "- - -" << " "; - } - break; - case Z_APDU_deleteResultSetResponse: - msg_response << "deleteResultSetResponse" << " "; - break; - case Z_APDU_accessControlResponse: - msg_response << "accessControlResponse" << " "; - break; - case Z_APDU_resourceControlResponse: - msg_response << "resourceControlResponse" << " "; - break; - //case Z_APDU_triggerResourceControlResponse: - //msg_response << "triggerResourceControlResponse" << " "; - //break; - case Z_APDU_resourceReportResponse: - msg_response << "resourceReportResponse" << " "; - break; - case Z_APDU_scanResponse: - msg_response << "scanResponse" << " "; - break; - case Z_APDU_sortResponse: - msg_response << "sortResponse" << " "; - break; - // case Z_APDU_segmentResponse: - // msg_response << "segmentResponse" << " "; - // break; - case Z_APDU_extendedServicesResponse: - msg_response << "extendedServicesResponse" << " "; - break; - case Z_APDU_close: - msg_response << "close" << " "; - break; - case Z_APDU_duplicateDetectionResponse: - msg_response << "duplicateDetectionResponse" << " "; - break; - default: - msg_response << "unknown" << " "; - } - } - else if (gdu && gdu->which == Z_GDU_HTTP_Request) - msg_response << "HTTP " << "unknown " ; - else if (gdu && gdu->which == Z_GDU_HTTP_Response) - msg_response << "HTTP-Response " << "unknown " ; - else - msg_response << "unknown " << "unknown " ; - - m_p->m_file->out - << m_p->m_msg_config << " " - << package.session().id() << " " - // << receive_time << " " - << send_time << " " - //<< "-" << " " - << duration << " " - //<< msg_request.str() - //<< msg_request_2.str() - << msg_response.str() - << msg_response_2.str() - << "\n"; - - //wrbuf_free(wr, 1); + if (gdu) + { + m_p->m_file->out + << m_p->m_msg_config << " " + << package.session().id() << " " + << send_time << " " + << duration << " " + << *gdu + << "\n"; + } } + if (m_p->m_res_session) { m_p->m_file->out << send_time << " " << m_p->m_msg_config; @@ -443,6 +196,7 @@ void yf::Log::process(mp::Package &package) const << "duration=" << duration << "\n"; } + if (m_p->m_init_options) { gdu = package.response().get(); @@ -456,6 +210,7 @@ void yf::Log::process(mp::Package &package) const m_p->m_file->out << "\n"; } } + if (m_p->m_res_apdu) { gdu = package.response().get(); @@ -466,6 +221,7 @@ void yf::Log::process(mp::Package &package) const z_GDU(odr, &gdu, 0, 0); } } + m_p->m_file->out.flush(); } } diff --git a/src/gduutil.cpp b/src/gduutil.cpp new file mode 100644 index 0000000..1f455ae --- /dev/null +++ b/src/gduutil.cpp @@ -0,0 +1,228 @@ +/* $Id: gduutil.cpp,v 1.1 2006-08-29 10:06:31 marc Exp $ + Copyright (c) 2005-2006, Index Data. + + See the LICENSE file for details + */ + +#include "gduutil.hpp" + +#include +#include + +#include + +namespace mp = metaproxy_1; + +// Doxygen doesn't like mp::gdu, so we use this instead +namespace mp_gdu = metaproxy_1::gdu; + +std::ostream& std::operator<<(std::ostream& os, Z_GDU& zgdu) +{ + if (zgdu.which == Z_GDU_Z3950) + os << "Z3950" << " " << *(zgdu.u.z3950) ; + else if (zgdu.which == Z_GDU_HTTP_Request) + os << "HTTP_Request" << " "; + else if (zgdu.which == Z_GDU_HTTP_Response) + os << "HTTP_Response" << " "; + else + os << "Z_GDU" << " "; + return os; +} + +std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) +{ + switch(zapdu.which) { + + case Z_APDU_initRequest: + os << "initRequest" << " " + << "OK" << " "; + + { + Z_InitRequest *ir + = zapdu.u.initRequest; + os + << (ir->implementationId) << " " + //<< ir->referenceId << " " + << (ir->implementationName) << " " + << (ir->implementationVersion) << " "; + } + break; + case Z_APDU_initResponse: + os<< "initResponse" << " "; + { + Z_InitResponse *ir + = zapdu.u.initResponse; + if (*(ir->result)) + os + << "OK" << " " + << (ir->implementationId) << " " + //<< ir->referenceId << " " + << (ir->implementationName) << " " + << (ir->implementationVersion) << " "; + else + os + << "ERROR" << " " + << "- - -" << " "; + + } + break; + case Z_APDU_searchRequest: + os << "searchRequest" << " " + << "OK" << " "; + { + Z_SearchRequest *sr + = zapdu.u.searchRequest; + + for (int i = 0; i < sr->num_databaseNames; i++) + { + os << sr->databaseNames[i]; + if (i+1 == sr->num_databaseNames) + os<< " "; + else + os<< "+"; + } + + WRBUF wr = wrbuf_alloc(); + yaz_query_to_wrbuf(wr, sr->query); + os << wrbuf_buf(wr) << " "; + wrbuf_free(wr, 1); + } + break; + case Z_APDU_searchResponse: + os<< "searchResponse" << " "; + { + Z_SearchResponse *sr + = zapdu.u.searchResponse; + if (*(sr->searchStatus)) + os + << "OK" << " " + << *(sr->resultCount) << " " + //<< sr->referenceId << " " + << *(sr->numberOfRecordsReturned) << " " + << *(sr->nextResultSetPosition) << " "; + else + os + << "ERROR" << " " + << "- - -" << " "; + + } + //os<< wrbuf_buf(wr) << " "; + break; + case Z_APDU_presentRequest: + os << "presentRequest" << " " + << "OK" << " "; + { + Z_PresentRequest *pr = zapdu.u.presentRequest; + os << pr->resultSetId << " " + //<< pr->referenceId << " " + << *(pr->resultSetStartPoint) << " " + << *(pr->numberOfRecordsRequested) << " "; + } + break; + case Z_APDU_presentResponse: + os<< "presentResponse" << " "; + { + Z_PresentResponse *pr + = zapdu.u.presentResponse; + if (!*(pr->presentStatus)) + os + << "OK" << " " + << "-" << " " + //<< pr->referenceId << " " + << *(pr->numberOfRecordsReturned) << " " + << *(pr->nextResultSetPosition) << " "; + else + os + << "ERROR" << " " + << "-" << " " + //<< pr->referenceId << " " + << *(pr->numberOfRecordsReturned) << " " + << *(pr->nextResultSetPosition) << " "; + //<< "- - -" << " "; + } + break; + case Z_APDU_deleteResultSetRequest: + os << "deleteResultSetRequest" << " " + << "OK" << " "; + break; + case Z_APDU_deleteResultSetResponse: + os << "deleteResultSetResponse" << " "; + break; + case Z_APDU_accessControlRequest: + os << "accessControlRequest" << " " + << "OK" << " "; + break; + case Z_APDU_accessControlResponse: + os << "accessControlResponse" << " "; + break; + case Z_APDU_resourceControlRequest: + os << "resourceControlRequest" << " " + << "OK" << " "; + break; + case Z_APDU_resourceControlResponse: + os << "resourceControlResponse" << " "; + break; + case Z_APDU_triggerResourceControlRequest: + os << "triggerResourceControlRequest" << " " + << "OK" << " "; + break; + case Z_APDU_resourceReportRequest: + os << "resourceReportRequest" << " " + << "OK" << " "; + break; + case Z_APDU_resourceReportResponse: + os << "resourceReportResponse" << " "; + break; + case Z_APDU_scanRequest: + os << "scanRequest" << " " + << "OK" << " "; + break; + case Z_APDU_scanResponse: + os << "scanResponse" << " "; + break; + case Z_APDU_sortRequest: + os << "sortRequest" << " " + << "OK" << " "; + break; + case Z_APDU_sortResponse: + os << "sortResponse" << " "; + break; + case Z_APDU_segmentRequest: + os << "segmentRequest" << " " + << "OK" << " "; + break; + case Z_APDU_extendedServicesRequest: + os << "extendedServicesRequest" << " " + << "OK" << " "; + break; + case Z_APDU_extendedServicesResponse: + os << "extendedServicesResponse" << " "; + break; + case Z_APDU_close: + os << "close" << " " + << "OK" << " "; + break; + case Z_APDU_duplicateDetectionRequest: + os << "duplicateDetectionRequest" << " " + << "OK" << " "; + break; + case Z_APDU_duplicateDetectionResponse: + os << "duplicateDetectionResponse" << " "; + break; + default: + os << "Z_APDU " + << "UNKNOWN" << " "; + } + + return os; +} + + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * c-file-style: "stroustrup" + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ diff --git a/src/gduutil.hpp b/src/gduutil.hpp new file mode 100644 index 0000000..c4e3024 --- /dev/null +++ b/src/gduutil.hpp @@ -0,0 +1,37 @@ +/* $Id: gduutil.hpp,v 1.1 2006-08-29 10:06:31 marc Exp $ + Copyright (c) 2005-2006, Index Data. + + See the LICENSE file for details + */ + +#ifndef YP2_GDUUTIL_HPP +#define YP2_GDUUTIL_HPP + +#include +#include + +#include + +namespace std +{ + std::ostream& operator<<(std::ostream& os, Z_GDU& zgdu); + std::ostream& operator<<(std::ostream& os, Z_APDU& zapdu); +} + + +namespace metaproxy_1 { + namespace gdu { + + + } +} + +#endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * c-file-style: "stroustrup" + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ -- 1.7.10.4