X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Fgduutil.cpp;h=9b1ae5ac1679d3f2fc981e85f16650cb13c49ac2;hb=637a685d61a9ff0e3f398a59da426979815c4d68;hp=5b48e6e67cbe4afe735153fae4ead847386bf067;hpb=9df178cd376007f26b4336c71abeccba1854b4b6;p=metaproxy-moved-to-github.git diff --git a/src/gduutil.cpp b/src/gduutil.cpp index 5b48e6e..9b1ae5a 100644 --- a/src/gduutil.cpp +++ b/src/gduutil.cpp @@ -1,13 +1,29 @@ -/* $Id: gduutil.cpp,v 1.12 2006-09-22 14:13:03 marc Exp $ - Copyright (c) 2005-2006, Index Data. +/* $Id: gduutil.cpp,v 1.21 2007-05-09 21:23:09 adam Exp $ + Copyright (c) 2005-2007, Index Data. - See the LICENSE file for details -*/ +This file is part of Metaproxy. + +Metaproxy is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Metaproxy; see the file LICENSE. If not, write to the +Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. + */ #include "gduutil.hpp" #include "util.hpp" #include +#include #include #include @@ -16,7 +32,10 @@ namespace mp = metaproxy_1; // Doxygen doesn't like mp::gdu, so we use this instead -namespace mp_gdu = metaproxy_1::gdu; +namespace mp_util = metaproxy_1::util; + + + std::ostream& std::operator<<(std::ostream& os, Z_GDU& zgdu) { @@ -126,7 +145,8 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) = zapdu.u.initRequest; Z_IdAuthentication *a = ir->idAuthentication; - if (a && a->which == Z_IdAuthentication_idPass ) + if (a && a->which == Z_IdAuthentication_idPass + && a->u.idPass->userId) os << a->u.idPass->userId << " "; //<< ":" << a->u.idPass->groupId << " "; else @@ -141,10 +161,13 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) else os << "-" << " " ; - os << (ir->implementationId) << " " - //<< ir->referenceId << " " - << (ir->implementationName) << " " - << (ir->implementationVersion); + if (ir->implementationId) + os << (ir->implementationId) << " "; + //<< ir->referenceId << " " + if (ir->implementationName) + os<< (ir->implementationName) << " "; + if (ir->implementationVersion) + os << (ir->implementationVersion) << " "; } break; case Z_APDU_initResponse: @@ -152,12 +175,16 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) { Z_InitResponse *ir = zapdu.u.initResponse; - if (ir->result && *(ir->result)) - os << "OK" << " " - << (ir->implementationId) << " " + if (ir->result && *(ir->result)){ + os << "OK" << " "; + if (ir->implementationId) + os << (ir->implementationId) << " "; //<< ir->referenceId << " " - << (ir->implementationName) << " " - << (ir->implementationVersion) << " "; + if (ir->implementationName) + os<< (ir->implementationName) << " "; + if (ir->implementationVersion) + os << (ir->implementationVersion) << " "; + } else os << "DIAG"; } @@ -179,8 +206,8 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) WRBUF wr = wrbuf_alloc(); yaz_query_to_wrbuf(wr, sr->query); - os << wrbuf_buf(wr); - wrbuf_free(wr, 1); + os << wrbuf_cstr(wr); + wrbuf_destroy(wr); } break; case Z_APDU_searchResponse: @@ -229,15 +256,22 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) os << " " << *(pr->numberOfRecordsRequested); else os << " -"; - //if (pr->preferredRecordSyntax) - // os << " " << *(pr->preferredRecordSyntax); - //else - // os << " -"; - //elements - //if (pr->) - // os << " " << *(pr->); - //else - // os << " -"; + if (pr->preferredRecordSyntax) + { + char oid_name_str[OID_STR_MAX]; + const char *oid_name = yaz_oid_to_string_buf( + pr->preferredRecordSyntax, 0, oid_name_str); + + os << " " << oid_name; + } + else + os << " -"; + const char * msg = 0; + if (pr->recordComposition + && (msg = mp_util::record_composition_to_esn(pr->recordComposition))) + os << " " << msg; + else + os << " -"; } break; case Z_APDU_presentResponse: @@ -330,9 +364,10 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) if (sr->termListAndStartPoint) { WRBUF wr = wrbuf_alloc(); - yaz_scan_to_wrbuf(wr, sr->termListAndStartPoint, VAL_NONE); - os << wrbuf_buf(wr); - wrbuf_free(wr, 1); + yaz_scan_to_wrbuf(wr, sr->termListAndStartPoint, + sr->attributeSet); + os << wrbuf_cstr(wr); + wrbuf_destroy(wr); } else os << " -"; @@ -557,189 +592,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; - /*