2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: zget.c,v 1.13 2007-04-12 13:52:57 adam Exp $
9 * \brief Implements Z39.50 package creator utilities
12 #include <yaz/proto.h>
13 #include <yaz/oid_db.h>
15 Z_InitRequest *zget_InitRequest(ODR o)
17 Z_InitRequest *r = (Z_InitRequest *)odr_malloc(o, sizeof(*r));
20 r->options = (Odr_bitmask *)odr_malloc(o, sizeof(*r->options));
21 ODR_MASK_ZERO(r->options);
22 r->protocolVersion = (Odr_bitmask *)
23 odr_malloc(o, sizeof(*r->protocolVersion));
25 ODR_MASK_SET(r->options, Z_Options_search);
26 ODR_MASK_SET(r->options, Z_Options_present);
28 ODR_MASK_ZERO(r->protocolVersion);
30 ODR_MASK_SET(r->protocolVersion, Z_ProtocolVersion_1);
31 ODR_MASK_SET(r->protocolVersion, Z_ProtocolVersion_2);
33 r->preferredMessageSize = odr_intdup(o, 1024*1024);
34 r->maximumRecordSize = odr_intdup(o, 1024*1024);
35 r->idAuthentication = 0;
36 r->implementationId = "81";
37 r->implementationName = "YAZ";
38 r->implementationVersion = YAZ_VERSION
46 r->userInformationField = 0;
51 Z_InitResponse *zget_InitResponse(ODR o)
53 Z_InitResponse *r = (Z_InitResponse *)odr_malloc(o, sizeof(*r));
56 r->options = (Odr_bitmask *)odr_malloc(o, sizeof(*r->options));
57 ODR_MASK_ZERO(r->options);
58 r->protocolVersion = (Odr_bitmask *)odr_malloc(o, sizeof(*r->protocolVersion));
59 ODR_MASK_ZERO(r->protocolVersion);
60 r->preferredMessageSize = odr_intdup(o, 30*1024);
61 r->maximumRecordSize = odr_intdup(o, 30*1024);
62 r->result = odr_intdup(o, 1);
63 r->implementationId = "81";
64 r->implementationName = "YAZ";
65 r->implementationVersion = YAZ_VERSION
73 r->userInformationField = 0;
78 Z_SearchRequest *zget_SearchRequest(ODR o)
80 Z_SearchRequest *r = (Z_SearchRequest *)odr_malloc(o, sizeof(*r));
83 r->smallSetUpperBound = odr_intdup(o, 0);
84 r->largeSetLowerBound = odr_intdup(o, 1);
85 r->mediumSetPresentNumber = odr_intdup(o, 0);
86 r->replaceIndicator = odr_intdup(o, 1);
87 r->resultSetName = "default";
88 r->num_databaseNames = 0;
90 r->smallSetElementSetNames = 0;
91 r->mediumSetElementSetNames = 0;
92 r->preferredRecordSyntax = 0;
94 r->additionalSearchInfo = 0;
99 Z_SearchResponse *zget_SearchResponse(ODR o)
101 Z_SearchResponse *r = (Z_SearchResponse *)odr_malloc(o, sizeof(*r));
104 r->resultCount = odr_intdup(o, 0);
105 r->numberOfRecordsReturned = odr_intdup(o, 0);
106 r->nextResultSetPosition = odr_intdup(o, 0);
107 r->searchStatus = odr_intdup(o, 1);
108 r->resultSetStatus = 0;
109 r->presentStatus = 0;
111 r->additionalSearchInfo = 0;
116 Z_PresentRequest *zget_PresentRequest(ODR o)
118 Z_PresentRequest *r = (Z_PresentRequest *)odr_malloc(o, sizeof(*r));
121 r->resultSetId = "default";
122 r->resultSetStartPoint = odr_intdup(o, 1);
123 r->numberOfRecordsRequested = odr_intdup(o, 10);
125 r->additionalRanges = 0;
126 r->recordComposition = 0;
127 r->preferredRecordSyntax = 0;
128 r->maxSegmentCount = 0;
129 r->maxRecordSize = 0;
130 r->maxSegmentSize = 0;
135 Z_PresentResponse *zget_PresentResponse(ODR o)
137 Z_PresentResponse *r = (Z_PresentResponse *)odr_malloc(o, sizeof(*r));
140 r->numberOfRecordsReturned = odr_intdup(o, 0);
141 r->nextResultSetPosition = odr_intdup(o, 0);
142 r->presentStatus = odr_intdup(o, Z_PresentStatus_success);
148 Z_DeleteResultSetRequest *zget_DeleteResultSetRequest(ODR o)
150 Z_DeleteResultSetRequest *r = (Z_DeleteResultSetRequest *)
151 odr_malloc(o, sizeof(*r));
154 r->deleteFunction = odr_intdup(o, Z_DeleteResultSetRequest_list);
155 r->num_resultSetList = 0;
156 r->resultSetList = 0;
161 Z_DeleteResultSetResponse *zget_DeleteResultSetResponse(ODR o)
163 Z_DeleteResultSetResponse *r = (Z_DeleteResultSetResponse *)
164 odr_malloc(o, sizeof(*r));
167 r->deleteOperationStatus = odr_intdup(o, Z_DeleteStatus_success);
168 r->deleteListStatuses = 0;
169 r->numberNotDeleted = 0;
171 r->deleteMessage = 0;
176 Z_ScanRequest *zget_ScanRequest(ODR o)
178 Z_ScanRequest *r = (Z_ScanRequest *)odr_malloc(o, sizeof(*r));
181 r->num_databaseNames = 0;
182 r->databaseNames = 0;
184 r->termListAndStartPoint = 0;
186 r->numberOfTermsRequested = odr_intdup(o, 20);
187 r->preferredPositionInResponse = 0;
192 Z_ScanResponse *zget_ScanResponse(ODR o)
194 Z_ScanResponse *r = (Z_ScanResponse *)odr_malloc(o, sizeof(*r));
198 r->scanStatus = odr_intdup(o, Z_Scan_success);
199 r->numberOfEntriesReturned = odr_intdup(o, 0);
200 r->positionOfTerm =0;
207 Z_TriggerResourceControlRequest *zget_TriggerResourceControlRequest(ODR o)
209 Z_TriggerResourceControlRequest *r = (Z_TriggerResourceControlRequest *)
210 odr_malloc(o, sizeof(*r));
213 r->requestedAction = odr_intdup(o, Z_TriggerResourceControlRequest_resourceReport);
214 r->prefResourceReportFormat = 0;
215 r->resultSetWanted = 0;
220 Z_ResourceControlRequest *zget_ResourceControlRequest(ODR o)
222 Z_ResourceControlRequest *r = (Z_ResourceControlRequest *)
223 odr_malloc(o, sizeof(*r));
226 r->suspendedFlag = 0;
227 r->resourceReport = 0;
228 r->partialResultsAvailable = 0;
229 r->responseRequired = odr_intdup(o, 0);
230 r->triggeredRequestFlag = 0;
235 Z_ResourceControlResponse *zget_ResourceControlResponse(ODR o)
237 Z_ResourceControlResponse *r = (Z_ResourceControlResponse *)
238 odr_malloc(o, sizeof(*r));
241 r->continueFlag = odr_intdup(o, 1);
242 r->resultSetWanted = 0;
247 Z_AccessControlRequest *zget_AccessControlRequest(ODR o)
249 Z_AccessControlRequest *r = (Z_AccessControlRequest *)
250 odr_malloc(o, sizeof(*r));
253 r->which = Z_AccessControlRequest_simpleForm;
259 Z_AccessControlResponse *zget_AccessControlResponse(ODR o)
261 Z_AccessControlResponse *r = (Z_AccessControlResponse *)
262 odr_malloc(o, sizeof(*r));
265 r->which = Z_AccessControlResponse_simpleForm;
272 Z_Segment *zget_Segment(ODR o)
274 Z_Segment *r = (Z_Segment *)odr_malloc(o, sizeof(*r));
277 r->numberOfRecordsReturned = odr_intdup(o, 0);
278 r->num_segmentRecords = 0;
279 r->segmentRecords = (Z_NamePlusRecord **) odr_nullval();
284 Z_Close *zget_Close(ODR o)
286 Z_Close *r = (Z_Close *)odr_malloc(o, sizeof(*r));
289 r->closeReason = odr_intdup(o, Z_Close_finished);
290 r->diagnosticInformation = 0;
291 r->resourceReportFormat = 0;
292 r->resourceReport = 0;
297 Z_ResourceReportRequest *zget_ResourceReportRequest(ODR o)
299 Z_ResourceReportRequest *r = (Z_ResourceReportRequest *)
300 odr_malloc(o, sizeof(*r));
304 r->prefResourceReportFormat = 0;
309 Z_ResourceReportResponse *zget_ResourceReportResponse(ODR o)
311 Z_ResourceReportResponse *r = (Z_ResourceReportResponse *)
312 odr_malloc(o, sizeof(*r));
315 r->resourceReportStatus = odr_intdup(o, Z_ResourceReportResponse_success);
316 r->resourceReport = 0;
321 Z_SortRequest *zget_SortRequest(ODR o)
323 Z_SortRequest *r = (Z_SortRequest *)odr_malloc(o, sizeof(*r));
326 r->inputResultSetNames = 0;
327 r->sortedResultSetName = 0;
333 Z_SortResponse *zget_SortResponse(ODR o)
335 Z_SortResponse *r = (Z_SortResponse *)odr_malloc(o, sizeof(*r));
338 r->sortStatus = odr_intdup(o, Z_SortResponse_success);
339 r->resultSetStatus = odr_intdup(o, Z_SortResponse_empty);
346 Z_ExtendedServicesRequest *zget_ExtendedServicesRequest(ODR o)
348 Z_ExtendedServicesRequest *r = (Z_ExtendedServicesRequest *)
349 odr_malloc(o, sizeof(*r));
352 r->function = odr_intdup(o, Z_ExtendedServicesRequest_create);
356 r->retentionTime = 0;
359 r->taskSpecificParameters = 0;
360 r->waitAction = odr_intdup(o, Z_ExtendedServicesRequest_waitIfPossible);
366 Z_ExtendedServicesResponse *zget_ExtendedServicesResponse(ODR o)
368 Z_ExtendedServicesResponse *r = (Z_ExtendedServicesResponse *)
369 odr_malloc(o, sizeof(*r));
372 r->operationStatus = odr_intdup(o, Z_ExtendedServicesResponse_done);
373 r->num_diagnostics = 0;
380 Z_DuplicateDetectionRequest *zget_DuplicateDetectionRequest(ODR o)
382 Z_DuplicateDetectionRequest *r = (Z_DuplicateDetectionRequest *)
383 odr_malloc(o, sizeof(*r));
386 r->num_inputResultSetIds = 0;
387 r->inputResultSetIds = 0;
388 r->outputResultSetName = 0;
389 r->applicablePortionOfRecord = 0;
390 r->num_duplicateDetectionCriteria = 0;
391 r->duplicateDetectionCriteria = 0;
393 r->num_retentionCriteria = 0;
394 r->retentionCriteria = 0;
395 r->num_sortCriteria = 0;
401 Z_DuplicateDetectionResponse *zget_DuplicateDetectionResponse(ODR o)
403 Z_DuplicateDetectionResponse *r = (Z_DuplicateDetectionResponse *)
404 odr_malloc(o, sizeof(*r));
407 r->status = odr_intdup(o, Z_DuplicateDetectionResponse_success);
408 r->resultSetCount = 0;
409 r->num_diagnostics = 0;
415 Z_APDU *zget_APDU(ODR o, int which)
417 Z_APDU *r = (Z_APDU *)odr_malloc(o, sizeof(*r));
419 switch (r->which = which)
421 case Z_APDU_initRequest:
422 r->u.initRequest = zget_InitRequest(o);
424 case Z_APDU_initResponse:
425 r->u.initResponse = zget_InitResponse(o);
427 case Z_APDU_searchRequest:
428 r->u.searchRequest = zget_SearchRequest(o);
430 case Z_APDU_searchResponse:
431 r->u.searchResponse = zget_SearchResponse(o);
433 case Z_APDU_presentRequest:
434 r->u.presentRequest = zget_PresentRequest(o);
436 case Z_APDU_presentResponse:
437 r->u.presentResponse = zget_PresentResponse(o);
439 case Z_APDU_deleteResultSetRequest:
440 r->u.deleteResultSetRequest = zget_DeleteResultSetRequest(o);
442 case Z_APDU_deleteResultSetResponse:
443 r->u.deleteResultSetResponse = zget_DeleteResultSetResponse(o);
445 case Z_APDU_scanRequest:
446 r->u.scanRequest = zget_ScanRequest(o);
448 case Z_APDU_scanResponse:
449 r->u.scanResponse = zget_ScanResponse(o);
451 case Z_APDU_triggerResourceControlRequest:
452 r->u.triggerResourceControlRequest =
453 zget_TriggerResourceControlRequest(o);
455 case Z_APDU_resourceControlRequest:
456 r->u.resourceControlRequest = zget_ResourceControlRequest(o);
458 case Z_APDU_resourceControlResponse:
459 r->u.resourceControlResponse = zget_ResourceControlResponse(o);
461 case Z_APDU_segmentRequest:
462 r->u.segmentRequest = zget_Segment(o);
465 r->u.close = zget_Close(o);
467 case Z_APDU_accessControlRequest:
468 r->u.accessControlRequest = zget_AccessControlRequest(o);
470 case Z_APDU_accessControlResponse:
471 r->u.accessControlResponse = zget_AccessControlResponse(o);
473 case Z_APDU_resourceReportRequest:
474 r->u.resourceReportRequest = zget_ResourceReportRequest(o);
476 case Z_APDU_resourceReportResponse:
477 r->u.resourceReportResponse = zget_ResourceReportResponse(o);
479 case Z_APDU_sortRequest:
480 r->u.sortRequest = zget_SortRequest(o);
482 case Z_APDU_sortResponse:
483 r->u.sortResponse = zget_SortResponse(o);
485 case Z_APDU_extendedServicesRequest:
486 r->u.extendedServicesRequest = zget_ExtendedServicesRequest(o);
488 case Z_APDU_extendedServicesResponse:
489 r->u.extendedServicesResponse = zget_ExtendedServicesResponse(o);
491 case Z_APDU_duplicateDetectionRequest:
492 r->u.duplicateDetectionRequest = zget_DuplicateDetectionRequest(o);
494 case Z_APDU_duplicateDetectionResponse:
495 r->u.duplicateDetectionResponse = zget_DuplicateDetectionResponse(o);
503 Z_DefaultDiagFormat *zget_DefaultDiagFormat(ODR o, int error,
506 Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
507 odr_malloc (o, sizeof(*dr));
509 dr->diagnosticSetId = yaz_string_to_oid_odr(
510 yaz_oid_std(), CLASS_DIAGSET, OID_STR_BIB1, o);
511 dr->condition = odr_intdup(o, error);
512 dr->which = Z_DefaultDiagFormat_v2Addinfo;
513 dr->u.v2Addinfo = odr_strdup (o, addinfo ? addinfo : "");
517 Z_DiagRec *zget_DiagRec(ODR o, int error, const char *addinfo)
519 Z_DiagRec *dr = (Z_DiagRec*) odr_malloc(o, sizeof(*dr));
520 dr->which = Z_DiagRec_defaultFormat;
521 dr->u.defaultFormat = zget_DefaultDiagFormat(o, error, addinfo);
525 Z_DiagRecs *zget_DiagRecs(ODR o, int error, const char *addinfo)
527 Z_DiagRecs *drecs = (Z_DiagRecs*) odr_malloc(o, sizeof(*drecs));
528 Z_DiagRec **dr = (Z_DiagRec**) odr_malloc(o, sizeof(**dr));
529 drecs->diagRecs = dr;
530 dr[0] = zget_DiagRec(o, error, addinfo);
531 drecs->num_diagRecs = 1;
535 Z_NamePlusRecord *zget_surrogateDiagRec(ODR o, const char *dbname,
536 int error, const char *addinfo)
538 Z_NamePlusRecord *rec = (Z_NamePlusRecord *) odr_malloc (o, sizeof(*rec));
539 Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (o, sizeof(*drec));
542 rec->databaseName = odr_strdup(o, dbname);
544 rec->databaseName = 0;
545 rec->which = Z_NamePlusRecord_surrogateDiagnostic;
546 rec->u.surrogateDiagnostic = drec;
547 drec->which = Z_DiagRec_defaultFormat;
548 drec->u.defaultFormat = zget_DefaultDiagFormat(o, error, addinfo);
552 Z_External *zget_init_diagnostics(ODR odr, int error, const char *addinfo)
555 Z_OtherInformation *u;
556 Z_OtherInformationUnit *l;
557 Z_DiagnosticFormat *d;
558 Z_DiagnosticFormat_s *e;
560 x = (Z_External*) odr_malloc(odr, sizeof *x);
562 x->indirect_reference = 0;
563 x->direct_reference = yaz_string_to_oid_odr(yaz_oid_std(),
567 x->which = Z_External_userInfo1;
569 u = odr_malloc(odr, sizeof *u);
572 u->list = (Z_OtherInformationUnit**) odr_malloc(odr, sizeof *u->list);
573 u->list[0] = (Z_OtherInformationUnit*) odr_malloc(odr, sizeof *u->list[0]);
576 l->which = Z_OtherInfo_externallyDefinedInfo;
578 x2 = (Z_External*) odr_malloc(odr, sizeof *x);
579 l->information.externallyDefinedInfo = x2;
581 x2->indirect_reference = 0;
582 x2->direct_reference = yaz_string_to_oid_odr(yaz_oid_std(),
586 x2->which = Z_External_diag1;
588 d = (Z_DiagnosticFormat*) odr_malloc(odr, sizeof *d);
591 d->elements = (Z_DiagnosticFormat_s**) odr_malloc (odr, sizeof *d->elements);
592 d->elements[0] = (Z_DiagnosticFormat_s*) odr_malloc (odr, sizeof *d->elements[0]);
595 e->which = Z_DiagnosticFormat_s_defaultDiagRec;
596 e->u.defaultDiagRec = zget_DefaultDiagFormat(odr, error, addinfo);
601 Z_External *zget_init_diagnostics_octet(ODR odr, int error,
605 Z_OtherInformation *u;
606 Z_OtherInformationUnit *l;
607 Z_DiagnosticFormat *d;
608 Z_DiagnosticFormat_s *e;
613 u = odr_malloc(odr, sizeof *u);
615 u->list = (Z_OtherInformationUnit**) odr_malloc(odr, sizeof *u->list);
616 u->list[0] = (Z_OtherInformationUnit*) odr_malloc(odr, sizeof *u->list[0]);
619 l->which = Z_OtherInfo_externallyDefinedInfo;
621 x2 = (Z_External*) odr_malloc(odr, sizeof *x);
622 l->information.externallyDefinedInfo = x2;
624 x2->indirect_reference = 0;
626 x2->direct_reference = yaz_string_to_oid_odr(yaz_oid_std(),
630 x2->which = Z_External_diag1;
632 d = (Z_DiagnosticFormat*) odr_malloc(odr, sizeof *d);
635 d->elements = (Z_DiagnosticFormat_s**) odr_malloc (odr, sizeof *d->elements);
636 d->elements[0] = (Z_DiagnosticFormat_s*) odr_malloc (odr, sizeof *d->elements[0]);
639 e->which = Z_DiagnosticFormat_s_defaultDiagRec;
640 e->u.defaultDiagRec = zget_DefaultDiagFormat(odr, error, addinfo);
643 encode = odr_createmem(ODR_ENCODE);
645 z_OtherInformation(encode, &u, 0, 0);
647 octet_buf = odr_getbuf(encode, &octet_len, 0);
649 x = (Z_External*) odr_malloc(odr, sizeof *x);
651 x->indirect_reference = 0;
652 x->direct_reference = yaz_string_to_oid_odr(yaz_oid_std(),
657 x->which = Z_External_octet;
658 x->u.octet_aligned = (Odr_oct *) odr_malloc(odr, sizeof(Odr_oct));
659 x->u.octet_aligned->buf = odr_malloc(odr, octet_len);
660 memcpy(x->u.octet_aligned->buf, octet_buf, octet_len);
661 x->u.octet_aligned->len = octet_len;
671 * indent-tabs-mode: nil
673 * vim: shiftwidth=4 tabstop=8 expandtab