1 /* $Id: gduutil.cpp,v 1.13 2006-09-26 13:15:33 marc Exp $
2 Copyright (c) 2005-2006, Index Data.
4 See the LICENSE file for details
10 #include <yaz/wrbuf.h>
11 #include <yaz/querytowrbuf.h>
16 namespace mp = metaproxy_1;
18 // Doxygen doesn't like mp::gdu, so we use this instead
19 namespace mp_gdu = metaproxy_1::gdu;
21 std::ostream& std::operator<<(std::ostream& os, Z_GDU& zgdu)
23 if (zgdu.which == Z_GDU_Z3950)
27 os << *(zgdu.u.z3950);
29 else if (zgdu.which == Z_GDU_HTTP_Request)
32 if (zgdu.u.HTTP_Request)
33 os << " " << *(zgdu.u.HTTP_Request);
35 else if (zgdu.which == Z_GDU_HTTP_Response)
37 os << "HTTP_Response";
38 if (zgdu.u.HTTP_Response)
39 os << " " << *(zgdu.u.HTTP_Response);
46 std::ostream& std::operator<<(std::ostream& os, Z_HTTP_Request& httpreq)
48 os << httpreq.method << " ";
54 std::ostream& std::operator<<(std::ostream& os, Z_HTTP_Response& httpres)
56 os << httpres.code << " ";
57 os << httpres.content_len;
61 std::ostream& std::operator<<(std::ostream& os, Z_Records & rs)
64 case Z_Records_DBOSD :
67 if (rs.u.nonSurrogateDiagnostic)
68 os << *(rs.u.nonSurrogateDiagnostic);
70 case Z_Records_multipleNSD:
71 os << "Z_Records_multipleNSD";
72 //os << *(rs.u.multipleNonSurDiagnostics);
81 std::ostream& std::operator<<(std::ostream& os, Z_DiagRec& dr)
84 case Z_DiagRec_defaultFormat:
85 if (dr.u.defaultFormat)
86 os << *(dr.u.defaultFormat);
88 case Z_DiagRec_externallyDefined :
89 os << "Z_DiagRec_externallyDefined";
98 std::ostream& std::operator<<(std::ostream& os, Z_DefaultDiagFormat& ddf)
101 os << *(ddf.condition) << " ";
104 case Z_DefaultDiagFormat_v2Addinfo:
105 os << ddf.u.v2Addinfo;
107 case Z_DefaultDiagFormat_v3Addinfo:
108 os << ddf.u.v3Addinfo;
111 os << "Z_DefaultDiagFormat" ;
117 std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu)
119 switch(zapdu.which) {
121 case Z_APDU_initRequest:
122 os << " " << "initRequest" << " ";
126 = zapdu.u.initRequest;
128 Z_IdAuthentication *a = ir->idAuthentication;
129 if (a && a->which == Z_IdAuthentication_idPass )
130 os << a->u.idPass->userId << " ";
131 //<< ":" << a->u.idPass->groupId << " ";
135 std::list<std::string> vhosts;
136 mp::util::get_vhost_otherinfo(ir->otherInfo, vhosts);
138 copy(vhosts.begin(), vhosts.end(),
139 ostream_iterator<string>(os, " "));
144 os << (ir->implementationId) << " "
145 //<< ir->referenceId << " "
146 << (ir->implementationName) << " "
147 << (ir->implementationVersion);
150 case Z_APDU_initResponse:
151 os << " " << "initResponse" << " ";
154 = zapdu.u.initResponse;
155 if (ir->result && *(ir->result))
157 << (ir->implementationId) << " "
158 //<< ir->referenceId << " "
159 << (ir->implementationName) << " "
160 << (ir->implementationVersion) << " ";
165 case Z_APDU_searchRequest:
166 os << " " << "searchRequest" << " ";
169 = zapdu.u.searchRequest;
171 for (int i = 0; i < sr->num_databaseNames; i++)
173 os << sr->databaseNames[i];
174 if (i+1 == sr->num_databaseNames)
180 WRBUF wr = wrbuf_alloc();
181 yaz_query_to_wrbuf(wr, sr->query);
186 case Z_APDU_searchResponse:
187 os << " " << "searchResponse" << " ";
190 = zapdu.u.searchResponse;
191 if (sr->searchStatus && *(sr->searchStatus))
195 os << " " << *(sr->resultCount);
198 //<< sr->referenceId << " "
199 if (sr->numberOfRecordsReturned)
200 os << " " << *(sr->numberOfRecordsReturned);
203 if (sr->nextResultSetPosition)
204 os << " " << *(sr->nextResultSetPosition);
210 os << "DIAG " << *(sr->records);
215 case Z_APDU_presentRequest:
216 os << " " << "presentRequest";
218 Z_PresentRequest *pr = zapdu.u.presentRequest;
220 os << " " << (pr->resultSetId);
223 //<< pr->referenceId << " "
224 if (pr->resultSetStartPoint)
225 os << " " << *(pr->resultSetStartPoint);
228 if (pr->numberOfRecordsRequested)
229 os << " " << *(pr->numberOfRecordsRequested);
232 //if (pr->preferredRecordSyntax)
233 // os << " " << *(pr->preferredRecordSyntax);
238 // os << " " << *(pr->);
243 case Z_APDU_presentResponse:
244 os << " " << "presentResponse" << " ";
246 Z_PresentResponse *pr
247 = zapdu.u.presentResponse;
248 if ((pr->presentStatus) && !*(pr->presentStatus))
251 //<< pr->referenceId << " "
252 if (pr->numberOfRecordsReturned)
253 os << " " << *(pr->numberOfRecordsReturned);
256 if (pr->nextResultSetPosition)
257 os << " " << *(pr->nextResultSetPosition);
263 os << "DIAG " << *(pr->records);
267 //os << "DIAG" << " "
269 //<< pr->referenceId << " "
270 //<< *(pr->numberOfRecordsReturned) << " "
271 //<< *(pr->nextResultSetPosition);
274 case Z_APDU_deleteResultSetRequest:
275 os << " " << "deleteResultSetRequest";
277 case Z_APDU_deleteResultSetResponse:
278 os << " " << "deleteResultSetResponse";
280 case Z_APDU_accessControlRequest:
281 os << " " << "accessControlRequest";
283 case Z_APDU_accessControlResponse:
284 os << " " << "accessControlResponse";
286 case Z_APDU_resourceControlRequest:
287 os << " " << "resourceControlRequest";
289 case Z_APDU_resourceControlResponse:
290 os << " " << "resourceControlResponse";
292 case Z_APDU_triggerResourceControlRequest:
293 os << " " << "triggerResourceControlRequest";
295 case Z_APDU_resourceReportRequest:
296 os << " " << "resourceReportRequest";
298 case Z_APDU_resourceReportResponse:
299 os << " " << "resourceReportResponse";
301 case Z_APDU_scanRequest:
302 os << " " << "scanRequest" << " ";
305 = zapdu.u.scanRequest;
309 for (int i = 0; i < sr->num_databaseNames; i++)
311 os << sr->databaseNames[i];
312 if (i+1 == sr->num_databaseNames)
317 if (sr->numberOfTermsRequested)
318 os << " " << *(sr->numberOfTermsRequested);
321 if (sr->preferredPositionInResponse)
322 os << " " << *(sr->preferredPositionInResponse);
326 os << " " << *(sr->stepSize);
330 if (sr->termListAndStartPoint)
332 WRBUF wr = wrbuf_alloc();
333 yaz_scan_to_wrbuf(wr, sr->termListAndStartPoint, VAL_NONE);
342 case Z_APDU_scanResponse:
343 os << " " << "scanResponse" << " ";
346 = zapdu.u.scanResponse;
349 if ((sr->scanStatus) && !*(sr->scanStatus))
352 //<< *(sr->scanStatus) << " "
353 if (sr->numberOfEntriesReturned)
354 os << " " << *(sr->numberOfEntriesReturned);
357 //<< sr->referenceId << " "
358 if (sr->positionOfTerm)
359 os << " " << *(sr->positionOfTerm);
363 os << " " << *(sr->stepSize);
371 os << " " << *(sr->scanStatus) << " ";
373 switch (*(sr->scanStatus)){
377 case Z_Scan_partial_1:
380 case Z_Scan_partial_2:
383 case Z_Scan_partial_3:
386 case Z_Scan_partial_4:
389 case Z_Scan_partial_5:
399 if (sr->numberOfEntriesReturned)
400 os << " " << *(sr->numberOfEntriesReturned);
407 case Z_APDU_sortRequest:
408 os << " " << "sortRequest" << " ";
410 case Z_APDU_sortResponse:
411 os << " " << "sortResponse" << " ";
413 case Z_APDU_segmentRequest:
414 os << " " << "segmentRequest" << " ";
416 case Z_APDU_extendedServicesRequest:
417 os << " " << "extendedServicesRequest";
419 Z_ExtendedServicesRequest *er
420 = zapdu.u.extendedServicesRequest;
426 switch(*(er->function))
428 case Z_ExtendedServicesRequest_create:
431 case Z_ExtendedServicesRequest_delete:
434 case Z_ExtendedServicesRequest_modify:
446 os << " " << er->userId ;
451 os << " " << er->packageName;
456 os << " " << er->description;
462 case Z_APDU_extendedServicesResponse:
463 os << " " << "extendedServicesResponse";
465 Z_ExtendedServicesResponse *er
466 = zapdu.u.extendedServicesResponse;
469 if (er->operationStatus)
472 switch (*(er->operationStatus)){
473 case Z_ExtendedServicesResponse_done:
476 case Z_ExtendedServicesResponse_accepted:
479 case Z_ExtendedServicesResponse_failure:
480 if (er->num_diagnostics)
481 os << "DIAG " << **(er->diagnostics);
495 os << " " << "close" << " ";
503 os << *(c->closeReason) << " ";
505 switch (*(c->closeReason)) {
506 case Z_Close_finished:
509 case Z_Close_shutdown:
512 case Z_Close_systemProblem:
513 os << "systemProblem";
515 case Z_Close_costLimit:
518 case Z_Close_resources:
521 case Z_Close_securityViolation:
522 os << "securityViolation";
524 case Z_Close_protocolError:
525 os << "protocolError";
527 case Z_Close_lackOfActivity:
528 os << "lackOfActivity";
530 case Z_Close_peerAbort:
533 case Z_Close_unspecified:
541 if (c->diagnosticInformation)
542 os << " " << c->diagnosticInformation;
546 case Z_APDU_duplicateDetectionRequest:
547 os << " " << "duplicateDetectionRequest";
549 case Z_APDU_duplicateDetectionResponse:
550 os << " " << "duplicateDetectionResponse";
553 os << " " << "Z_APDU " << "UNKNOWN";
565 * indent-tabs-mode: nil
566 * c-file-style: "stroustrup"
568 * vim: shiftwidth=4 tabstop=8 expandtab