1 /* $Id: gduutil.cpp,v 1.22 2007-05-22 13:03:32 adam Exp $
2 Copyright (c) 2005-2007, Index Data.
4 This file is part of Metaproxy.
6 Metaproxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with Metaproxy; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "gduutil.hpp"
25 #include <yaz/wrbuf.h>
26 #include <yaz/oid_db.h>
27 #include <yaz/querytowrbuf.h>
32 namespace mp = metaproxy_1;
34 // Doxygen doesn't like mp::gdu, so we use this instead
35 namespace mp_util = metaproxy_1::util;
40 std::ostream& std::operator<<(std::ostream& os, Z_GDU& zgdu)
42 if (zgdu.which == Z_GDU_Z3950)
46 os << *(zgdu.u.z3950);
48 else if (zgdu.which == Z_GDU_HTTP_Request)
51 if (zgdu.u.HTTP_Request)
52 os << " " << *(zgdu.u.HTTP_Request);
54 else if (zgdu.which == Z_GDU_HTTP_Response)
56 os << "HTTP_Response";
57 if (zgdu.u.HTTP_Response)
58 os << " " << *(zgdu.u.HTTP_Response);
65 std::ostream& std::operator<<(std::ostream& os, Z_HTTP_Request& httpreq)
67 os << httpreq.method << " ";
73 std::ostream& std::operator<<(std::ostream& os, Z_HTTP_Response& httpres)
75 os << httpres.code << " ";
76 os << httpres.content_len;
80 std::ostream& std::operator<<(std::ostream& os, Z_Records & rs)
83 case Z_Records_DBOSD :
86 if (rs.u.nonSurrogateDiagnostic)
87 os << *(rs.u.nonSurrogateDiagnostic);
89 case Z_Records_multipleNSD:
90 os << "Z_Records_multipleNSD";
91 //os << *(rs.u.multipleNonSurDiagnostics);
100 std::ostream& std::operator<<(std::ostream& os, Z_DiagRec& dr)
103 case Z_DiagRec_defaultFormat:
104 if (dr.u.defaultFormat)
105 os << *(dr.u.defaultFormat);
107 case Z_DiagRec_externallyDefined :
108 os << "Z_DiagRec_externallyDefined";
117 std::ostream& std::operator<<(std::ostream& os, Z_DefaultDiagFormat& ddf)
120 os << *(ddf.condition) << " ";
123 case Z_DefaultDiagFormat_v2Addinfo:
124 os << ddf.u.v2Addinfo;
126 case Z_DefaultDiagFormat_v3Addinfo:
127 os << ddf.u.v3Addinfo;
130 os << "Z_DefaultDiagFormat" ;
136 static void dump_opt_string(std::ostream& os, const char *s)
145 static void dump_opt_int(std::ostream& os, const int *i)
154 std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu)
156 switch(zapdu.which) {
158 case Z_APDU_initRequest:
159 os << " " << "initRequest";
163 = zapdu.u.initRequest;
165 Z_IdAuthentication *a = ir->idAuthentication;
166 if (a && a->which == Z_IdAuthentication_idPass)
167 dump_opt_string(os, a->u.idPass->userId);
168 else if (a && a->which == Z_IdAuthentication_open)
169 dump_opt_string(os, a->u.open);
171 dump_opt_string(os, 0);
174 std::list<std::string> vhosts;
175 mp::util::get_vhost_otherinfo(ir->otherInfo, vhosts);
177 copy(vhosts.begin(), vhosts.end(),
178 ostream_iterator<string>(os, " "));
183 dump_opt_string(os, ir->implementationId);
184 dump_opt_string(os, ir->implementationName);
185 dump_opt_string(os, ir->implementationVersion);
188 case Z_APDU_initResponse:
189 os << " " << "initResponse ";
192 = zapdu.u.initResponse;
193 if (ir->result && *(ir->result))
201 dump_opt_string(os, ir->implementationId);
202 dump_opt_string(os, ir->implementationName);
203 dump_opt_string(os, ir->implementationVersion);
206 case Z_APDU_searchRequest:
207 os << " " << "searchRequest" << " ";
210 = zapdu.u.searchRequest;
212 for (int i = 0; i < sr->num_databaseNames; i++)
214 os << sr->databaseNames[i];
215 if (i+1 != sr->num_databaseNames)
219 dump_opt_string(os, sr->resultSetName);
222 if (sr->preferredRecordSyntax)
224 char oid_name_str[OID_STR_MAX];
225 const char *oid_name = yaz_oid_to_string_buf(
226 sr->preferredRecordSyntax, 0, oid_name_str);
234 WRBUF wr = wrbuf_alloc();
235 yaz_query_to_wrbuf(wr, sr->query);
236 os << wrbuf_cstr(wr);
240 case Z_APDU_searchResponse:
241 os << " " << "searchResponse ";
244 = zapdu.u.searchResponse;
245 if (sr->searchStatus && *(sr->searchStatus))
248 dump_opt_int(os, sr->resultCount);
249 dump_opt_int(os, sr->numberOfRecordsReturned);
250 dump_opt_int(os, sr->nextResultSetPosition);
254 os << "DIAG " << *(sr->records);
259 case Z_APDU_presentRequest:
260 os << " " << "presentRequest";
262 Z_PresentRequest *pr = zapdu.u.presentRequest;
263 dump_opt_string(os, pr->resultSetId);
264 dump_opt_int(os, pr->resultSetStartPoint);
265 dump_opt_int(os, pr->numberOfRecordsRequested);
266 if (pr->preferredRecordSyntax)
268 char oid_name_str[OID_STR_MAX];
269 const char *oid_name = yaz_oid_to_string_buf(
270 pr->preferredRecordSyntax, 0, oid_name_str);
272 os << " " << oid_name;
276 const char * msg = 0;
277 if (pr->recordComposition)
278 msg = mp_util::record_composition_to_esn(pr->recordComposition);
279 dump_opt_string(os, msg);
282 case Z_APDU_presentResponse:
283 os << " " << "presentResponse" << " ";
285 Z_PresentResponse *pr
286 = zapdu.u.presentResponse;
287 if ((pr->presentStatus) && !*(pr->presentStatus))
290 //<< pr->referenceId << " "
291 if (pr->numberOfRecordsReturned)
292 os << " " << *(pr->numberOfRecordsReturned);
295 if (pr->nextResultSetPosition)
296 os << " " << *(pr->nextResultSetPosition);
302 os << "DIAG " << *(pr->records);
306 //os << "DIAG" << " "
308 //<< pr->referenceId << " "
309 //<< *(pr->numberOfRecordsReturned) << " "
310 //<< *(pr->nextResultSetPosition);
313 case Z_APDU_deleteResultSetRequest:
314 os << " " << "deleteResultSetRequest";
316 case Z_APDU_deleteResultSetResponse:
317 os << " " << "deleteResultSetResponse";
319 case Z_APDU_accessControlRequest:
320 os << " " << "accessControlRequest";
322 case Z_APDU_accessControlResponse:
323 os << " " << "accessControlResponse";
325 case Z_APDU_resourceControlRequest:
326 os << " " << "resourceControlRequest";
328 case Z_APDU_resourceControlResponse:
329 os << " " << "resourceControlResponse";
331 case Z_APDU_triggerResourceControlRequest:
332 os << " " << "triggerResourceControlRequest";
334 case Z_APDU_resourceReportRequest:
335 os << " " << "resourceReportRequest";
337 case Z_APDU_resourceReportResponse:
338 os << " " << "resourceReportResponse";
340 case Z_APDU_scanRequest:
341 os << " " << "scanRequest" << " ";
344 = zapdu.u.scanRequest;
348 for (int i = 0; i < sr->num_databaseNames; i++)
350 os << sr->databaseNames[i];
351 if (i+1 != sr->num_databaseNames)
354 dump_opt_int(os, sr->numberOfTermsRequested);
355 dump_opt_int(os, sr->preferredPositionInResponse);
356 dump_opt_int(os, sr->stepSize);
359 if (sr->termListAndStartPoint)
361 WRBUF wr = wrbuf_alloc();
362 yaz_scan_to_wrbuf(wr, sr->termListAndStartPoint,
364 os << wrbuf_cstr(wr);
372 case Z_APDU_scanResponse:
373 os << " " << "scanResponse" << " ";
376 = zapdu.u.scanResponse;
385 switch (*(sr->scanStatus)){
389 case Z_Scan_partial_1:
392 case Z_Scan_partial_2:
395 case Z_Scan_partial_3:
398 case Z_Scan_partial_4:
401 case Z_Scan_partial_5:
411 dump_opt_int(os, sr->numberOfEntriesReturned);
412 dump_opt_int(os, sr->positionOfTerm);
413 dump_opt_int(os, sr->stepSize);
417 case Z_APDU_sortRequest:
418 os << " " << "sortRequest" << " ";
420 case Z_APDU_sortResponse:
421 os << " " << "sortResponse" << " ";
423 case Z_APDU_segmentRequest:
424 os << " " << "segmentRequest" << " ";
426 case Z_APDU_extendedServicesRequest:
427 os << " " << "extendedServicesRequest";
429 Z_ExtendedServicesRequest *er
430 = zapdu.u.extendedServicesRequest;
436 switch(*(er->function))
438 case Z_ExtendedServicesRequest_create:
441 case Z_ExtendedServicesRequest_delete:
444 case Z_ExtendedServicesRequest_modify:
456 os << " " << er->userId ;
461 os << " " << er->packageName;
466 os << " " << er->description;
472 case Z_APDU_extendedServicesResponse:
473 os << " " << "extendedServicesResponse";
475 Z_ExtendedServicesResponse *er
476 = zapdu.u.extendedServicesResponse;
479 if (er->operationStatus)
482 switch (*(er->operationStatus)){
483 case Z_ExtendedServicesResponse_done:
486 case Z_ExtendedServicesResponse_accepted:
489 case Z_ExtendedServicesResponse_failure:
490 if (er->num_diagnostics)
491 os << "DIAG " << **(er->diagnostics);
505 os << " " << "close" << " ";
513 os << *(c->closeReason) << " ";
515 switch (*(c->closeReason)) {
516 case Z_Close_finished:
519 case Z_Close_shutdown:
522 case Z_Close_systemProblem:
523 os << "systemProblem";
525 case Z_Close_costLimit:
528 case Z_Close_resources:
531 case Z_Close_securityViolation:
532 os << "securityViolation";
534 case Z_Close_protocolError:
535 os << "protocolError";
537 case Z_Close_lackOfActivity:
538 os << "lackOfActivity";
540 case Z_Close_peerAbort:
543 case Z_Close_unspecified:
551 if (c->diagnosticInformation)
552 os << " " << c->diagnosticInformation;
556 case Z_APDU_duplicateDetectionRequest:
557 os << " " << "duplicateDetectionRequest";
559 case Z_APDU_duplicateDetectionResponse:
560 os << " " << "duplicateDetectionResponse";
563 os << " " << "Z_APDU " << "UNKNOWN";
575 * indent-tabs-mode: nil
576 * c-file-style: "stroustrup"
578 * vim: shiftwidth=4 tabstop=8 expandtab