From a1c8801960987ba4255f15a6fb1fdcb0a126e8f6 Mon Sep 17 00:00:00 2001 From: Marc Cromme Date: Tue, 26 Sep 2006 13:15:33 +0000 Subject: [PATCH] factoring SRU helper utilities into seperate files --- src/filter_sru_to_z3950.cpp | 3 +- src/gduutil.cpp | 185 +------------------------------------------ src/gduutil.hpp | 5 +- src/sru_util.cpp | 150 +++++++++++++++++++++++++++++++++++ src/sru_util.hpp | 37 +++++++++ 5 files changed, 192 insertions(+), 188 deletions(-) create mode 100644 src/sru_util.cpp create mode 100644 src/sru_util.hpp diff --git a/src/filter_sru_to_z3950.cpp b/src/filter_sru_to_z3950.cpp index 68a086b..2d7bcb9 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.13 2006-09-26 11:37:08 marc Exp $ +/* $Id: filter_sru_to_z3950.cpp,v 1.14 2006-09-26 13:15:33 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -9,6 +9,7 @@ #include "package.hpp" #include "util.hpp" #include "gduutil.hpp" +#include "sru_util.hpp" #include "filter_sru_to_z3950.hpp" #include diff --git a/src/gduutil.cpp b/src/gduutil.cpp index 5b48e6e..373918f 100644 --- a/src/gduutil.cpp +++ b/src/gduutil.cpp @@ -1,4 +1,4 @@ -/* $Id: gduutil.cpp,v 1.12 2006-09-22 14:13:03 marc Exp $ +/* $Id: gduutil.cpp,v 1.13 2006-09-26 13:15:33 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -557,189 +557,6 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) } -std::ostream& std::operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu) -{ - os << "SRU"; - - switch(srw_pdu.which) { - case Z_SRW_searchRetrieve_request: - os << " " << "searchRetrieveRequest"; - { - Z_SRW_searchRetrieveRequest *sr = srw_pdu.u.request; - if (sr) - { - if (sr->database) - os << " " << (sr->database); - else - os << " -"; - if (sr->startRecord) - os << " " << *(sr->startRecord); - else - os << " -"; - if (sr->maximumRecords) - os << " " << *(sr->maximumRecords); - else - os << " -"; - if (sr->recordPacking) - os << " " << (sr->recordPacking); - else - os << " -"; - - if (sr->recordSchema) - os << " " << (sr->recordSchema); - else - os << " -"; - - switch (sr->query_type){ - case Z_SRW_query_type_cql: - os << " CQL"; - if (sr->query.cql) - os << " " << sr->query.cql; - break; - case Z_SRW_query_type_xcql: - os << " XCQL"; - break; - case Z_SRW_query_type_pqf: - os << " PQF"; - if (sr->query.pqf) - os << " " << sr->query.pqf; - break; - } - } - } - break; - case Z_SRW_searchRetrieve_response: - os << " " << "searchRetrieveResponse"; - { - Z_SRW_searchRetrieveResponse *sr = srw_pdu.u.response; - if (sr) - { - if (! (sr->num_diagnostics)) - { - os << " OK"; - if (sr->numberOfRecords) - os << " " << *(sr->numberOfRecords); - else - os << " -"; - //if (sr->num_records) - os << " " << (sr->num_records); - //else - //os << " -"; - if (sr->nextRecordPosition) - os << " " << *(sr->nextRecordPosition); - else - os << " -"; - } - else - { - os << " DIAG"; - if (sr->diagnostics && sr->diagnostics->uri) - os << " " << (sr->diagnostics->uri); - else - os << " -"; - if (sr->diagnostics && sr->diagnostics->message) - os << " " << (sr->diagnostics->message); - else - os << " -"; - if (sr->diagnostics && sr->diagnostics->details) - os << " " << (sr->diagnostics->details); - else - os << " -"; - } - - - } - } - break; - case Z_SRW_explain_request: - os << " " << "explainRequest"; - break; - case Z_SRW_explain_response: - os << " " << "explainResponse"; - break; - case Z_SRW_scan_request: - os << " " << "scanRequest"; - break; - case Z_SRW_scan_response: - os << " " << "scanResponse"; - break; - case Z_SRW_update_request: - os << " " << "updateRequest"; - break; - case Z_SRW_update_response: - os << " " << "updateResponse"; - break; - default: - os << " " << "UNKNOWN"; - } - - return os; -} - - -// { -// Z_InitRequest *ir -// = zapdu.u.initRequest; - -// Z_IdAuthentication *a = ir->idAuthentication; -// if (a && a->which == Z_IdAuthentication_idPass ) -// os << a->u.idPass->userId << " "; -// //<< ":" << a->u.idPass->groupId << " "; -// else -// os << "-" << " "; - -// std::list vhosts; -// mp::util::get_vhost_otherinfo(ir->otherInfo, vhosts); -// if (vhosts.size()){ -// copy(vhosts.begin(), vhosts.end(), -// ostream_iterator(os, " ")); -// } -// else -// os << "-" << " " ; - -// 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 && *(ir->result)) -// os << "OK" << " " -// << (ir->implementationId) << " " -// //<< ir->referenceId << " " -// << (ir->implementationName) << " " -// << (ir->implementationVersion) << " "; -// else -// os << "DIAG"; -// } -// break; -// case Z_APDU_searchRequest: -// os << " " << "searchRequest" << " "; -// { -// 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; - /* diff --git a/src/gduutil.hpp b/src/gduutil.hpp index f097ca6..d79f510 100644 --- a/src/gduutil.hpp +++ b/src/gduutil.hpp @@ -1,4 +1,4 @@ -/* $Id: gduutil.hpp,v 1.3 2006-09-19 13:50:17 marc Exp $ +/* $Id: gduutil.hpp,v 1.4 2006-09-26 13:15:33 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -9,7 +9,7 @@ #include #include -#include +//#include #include @@ -17,7 +17,6 @@ namespace std { std::ostream& operator<<(std::ostream& os, Z_GDU& zgdu); std::ostream& operator<<(std::ostream& os, Z_APDU& zapdu); - std::ostream& operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu); std::ostream& operator<<(std::ostream& os, Z_HTTP_Request& httpreq); std::ostream& operator<<(std::ostream& os, Z_HTTP_Response& httpres); std::ostream& operator<<(std::ostream& os, Z_Records & rs); diff --git a/src/sru_util.cpp b/src/sru_util.cpp new file mode 100644 index 0000000..c84c918 --- /dev/null +++ b/src/sru_util.cpp @@ -0,0 +1,150 @@ +/* $Id: sru_util.cpp,v 1.1 2006-09-26 13:15:33 marc Exp $ + Copyright (c) 2005-2006, Index Data. + + See the LICENSE file for details +*/ + +#include "sru_util.hpp" +//#include "util.hpp" + +//#include +//#include + +#include +//#include + +namespace mp = metaproxy_1; + +// Doxygen doesn't like mp::gdu, so we use this instead +namespace mp_sru = metaproxy_1::sru; + + +std::ostream& std::operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu) +{ + os << "SRU"; + + switch(srw_pdu.which) { + case Z_SRW_searchRetrieve_request: + os << " " << "searchRetrieveRequest"; + { + Z_SRW_searchRetrieveRequest *sr = srw_pdu.u.request; + if (sr) + { + if (sr->database) + os << " " << (sr->database); + else + os << " -"; + if (sr->startRecord) + os << " " << *(sr->startRecord); + else + os << " -"; + if (sr->maximumRecords) + os << " " << *(sr->maximumRecords); + else + os << " -"; + if (sr->recordPacking) + os << " " << (sr->recordPacking); + else + os << " -"; + + if (sr->recordSchema) + os << " " << (sr->recordSchema); + else + os << " -"; + + switch (sr->query_type){ + case Z_SRW_query_type_cql: + os << " CQL"; + if (sr->query.cql) + os << " " << sr->query.cql; + break; + case Z_SRW_query_type_xcql: + os << " XCQL"; + break; + case Z_SRW_query_type_pqf: + os << " PQF"; + if (sr->query.pqf) + os << " " << sr->query.pqf; + break; + } + } + } + break; + case Z_SRW_searchRetrieve_response: + os << " " << "searchRetrieveResponse"; + { + Z_SRW_searchRetrieveResponse *sr = srw_pdu.u.response; + if (sr) + { + if (! (sr->num_diagnostics)) + { + os << " OK"; + if (sr->numberOfRecords) + os << " " << *(sr->numberOfRecords); + else + os << " -"; + //if (sr->num_records) + os << " " << (sr->num_records); + //else + //os << " -"; + if (sr->nextRecordPosition) + os << " " << *(sr->nextRecordPosition); + else + os << " -"; + } + else + { + os << " DIAG"; + if (sr->diagnostics && sr->diagnostics->uri) + os << " " << (sr->diagnostics->uri); + else + os << " -"; + if (sr->diagnostics && sr->diagnostics->message) + os << " " << (sr->diagnostics->message); + else + os << " -"; + if (sr->diagnostics && sr->diagnostics->details) + os << " " << (sr->diagnostics->details); + else + os << " -"; + } + + + } + } + break; + case Z_SRW_explain_request: + os << " " << "explainRequest"; + break; + case Z_SRW_explain_response: + os << " " << "explainResponse"; + break; + case Z_SRW_scan_request: + os << " " << "scanRequest"; + break; + case Z_SRW_scan_response: + os << " " << "scanResponse"; + break; + case Z_SRW_update_request: + os << " " << "updateRequest"; + break; + case Z_SRW_update_response: + os << " " << "updateResponse"; + break; + default: + os << " " << "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/sru_util.hpp b/src/sru_util.hpp new file mode 100644 index 0000000..fd9ef5a --- /dev/null +++ b/src/sru_util.hpp @@ -0,0 +1,37 @@ +/* $Id: sru_util.hpp,v 1.1 2006-09-26 13:15:33 marc Exp $ + Copyright (c) 2005-2006, Index Data. + + See the LICENSE file for details + */ + +#ifndef YP2_SDU_UTIL_HPP +#define YP2_SDU_UTIL_HPP + +//#include +//#include +#include + +#include + +namespace std +{ + std::ostream& operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu); + +} + + +namespace metaproxy_1 { + namespace sru { + + } +} + +#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