1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2013 Index Data
3 * See the file LICENSE for details.
7 * \brief Implements Z39.50 package creator utilities
13 #include <yaz/proto.h>
14 #include <yaz/oid_db.h>
16 static Z_InitRequest *zget_InitRequest(ODR o)
18 Z_InitRequest *r = (Z_InitRequest *)odr_malloc(o, sizeof(*r));
21 r->options = (Odr_bitmask *)odr_malloc(o, sizeof(*r->options));
22 ODR_MASK_ZERO(r->options);
23 r->protocolVersion = (Odr_bitmask *)
24 odr_malloc(o, sizeof(*r->protocolVersion));
26 ODR_MASK_SET(r->options, Z_Options_search);
27 ODR_MASK_SET(r->options, Z_Options_present);
29 ODR_MASK_ZERO(r->protocolVersion);
31 ODR_MASK_SET(r->protocolVersion, Z_ProtocolVersion_1);
32 ODR_MASK_SET(r->protocolVersion, Z_ProtocolVersion_2);
34 r->preferredMessageSize = odr_intdup(o, 1024*1024);
35 r->maximumRecordSize = odr_intdup(o, 1024*1024);
36 r->idAuthentication = 0;
37 r->implementationId = "81";
38 r->implementationName = "YAZ";
39 r->implementationVersion = YAZ_VERSION
40 #ifdef YAZ_VERSION_SHA1
44 r->userInformationField = 0;
49 static Z_InitResponse *zget_InitResponse(ODR o)
51 Z_InitResponse *r = (Z_InitResponse *)odr_malloc(o, sizeof(*r));
54 r->options = (Odr_bitmask *)odr_malloc(o, sizeof(*r->options));
55 ODR_MASK_ZERO(r->options);
56 r->protocolVersion = (Odr_bitmask *)odr_malloc(o, sizeof(*r->protocolVersion));
57 ODR_MASK_ZERO(r->protocolVersion);
58 r->preferredMessageSize = odr_intdup(o, 30*1024);
59 r->maximumRecordSize = odr_intdup(o, 30*1024);
60 r->result = odr_booldup(o, 1);
61 r->implementationId = "81";
62 r->implementationName = "YAZ";
63 r->implementationVersion = YAZ_VERSION
64 #ifdef YAZ_VERSION_SHA1
68 r->userInformationField = 0;
73 static Z_SearchRequest *zget_SearchRequest(ODR o)
75 Z_SearchRequest *r = (Z_SearchRequest *)odr_malloc(o, sizeof(*r));
78 r->smallSetUpperBound = odr_intdup(o, 0);
79 r->largeSetLowerBound = odr_intdup(o, 1);
80 r->mediumSetPresentNumber = odr_intdup(o, 0);
81 r->replaceIndicator = odr_booldup(o, 1);
82 r->resultSetName = "default";
83 r->num_databaseNames = 0;
85 r->smallSetElementSetNames = 0;
86 r->mediumSetElementSetNames = 0;
87 r->preferredRecordSyntax = 0;
89 r->additionalSearchInfo = 0;
94 static Z_SearchResponse *zget_SearchResponse(ODR o)
96 Z_SearchResponse *r = (Z_SearchResponse *)odr_malloc(o, sizeof(*r));
99 r->resultCount = odr_intdup(o, 0);
100 r->numberOfRecordsReturned = odr_intdup(o, 0);
101 r->nextResultSetPosition = odr_intdup(o, 0);
102 r->searchStatus = odr_booldup(o, 1);
103 r->resultSetStatus = 0;
104 r->presentStatus = 0;
106 r->additionalSearchInfo = 0;
111 static Z_PresentRequest *zget_PresentRequest(ODR o)
113 Z_PresentRequest *r = (Z_PresentRequest *)odr_malloc(o, sizeof(*r));
116 r->resultSetId = "default";
117 r->resultSetStartPoint = odr_intdup(o, 1);
118 r->numberOfRecordsRequested = odr_intdup(o, 10);
120 r->additionalRanges = 0;
121 r->recordComposition = 0;
122 r->preferredRecordSyntax = 0;
123 r->maxSegmentCount = 0;
124 r->maxRecordSize = 0;
125 r->maxSegmentSize = 0;
130 static Z_PresentResponse *zget_PresentResponse(ODR o)
132 Z_PresentResponse *r = (Z_PresentResponse *)odr_malloc(o, sizeof(*r));
135 r->numberOfRecordsReturned = odr_intdup(o, 0);
136 r->nextResultSetPosition = odr_intdup(o, 0);
137 r->presentStatus = odr_intdup(o, Z_PresentStatus_success);
143 static Z_DeleteResultSetRequest *zget_DeleteResultSetRequest(ODR o)
145 Z_DeleteResultSetRequest *r = (Z_DeleteResultSetRequest *)
146 odr_malloc(o, sizeof(*r));
149 r->deleteFunction = odr_intdup(o, Z_DeleteResultSetRequest_list);
150 r->num_resultSetList = 0;
151 r->resultSetList = 0;
156 static Z_DeleteResultSetResponse *zget_DeleteResultSetResponse(ODR o)
158 Z_DeleteResultSetResponse *r = (Z_DeleteResultSetResponse *)
159 odr_malloc(o, sizeof(*r));
162 r->deleteOperationStatus = odr_intdup(o, Z_DeleteStatus_success);
163 r->deleteListStatuses = 0;
164 r->numberNotDeleted = 0;
166 r->deleteMessage = 0;
171 static Z_ScanRequest *zget_ScanRequest(ODR o)
173 Z_ScanRequest *r = (Z_ScanRequest *)odr_malloc(o, sizeof(*r));
176 r->num_databaseNames = 0;
177 r->databaseNames = 0;
179 r->termListAndStartPoint = 0;
181 r->numberOfTermsRequested = odr_intdup(o, 20);
182 r->preferredPositionInResponse = 0;
187 static Z_ScanResponse *zget_ScanResponse(ODR o)
189 Z_ScanResponse *r = (Z_ScanResponse *)odr_malloc(o, sizeof(*r));
193 r->scanStatus = odr_intdup(o, Z_Scan_success);
194 r->numberOfEntriesReturned = odr_intdup(o, 0);
195 r->positionOfTerm =0;
202 static Z_TriggerResourceControlRequest *zget_TriggerResourceControlRequest(ODR o)
204 Z_TriggerResourceControlRequest *r = (Z_TriggerResourceControlRequest *)
205 odr_malloc(o, sizeof(*r));
208 r->requestedAction = odr_intdup(o, Z_TriggerResourceControlRequest_resourceReport);
209 r->prefResourceReportFormat = 0;
210 r->resultSetWanted = 0;
215 static Z_ResourceControlRequest *zget_ResourceControlRequest(ODR o)
217 Z_ResourceControlRequest *r = (Z_ResourceControlRequest *)
218 odr_malloc(o, sizeof(*r));
221 r->suspendedFlag = 0;
222 r->resourceReport = 0;
223 r->partialResultsAvailable = 0;
224 r->responseRequired = odr_booldup(o, 0);
225 r->triggeredRequestFlag = 0;
230 static Z_ResourceControlResponse *zget_ResourceControlResponse(ODR o)
232 Z_ResourceControlResponse *r = (Z_ResourceControlResponse *)
233 odr_malloc(o, sizeof(*r));
236 r->continueFlag = odr_booldup(o, 1);
237 r->resultSetWanted = 0;
242 static Z_AccessControlRequest *zget_AccessControlRequest(ODR o)
244 Z_AccessControlRequest *r = (Z_AccessControlRequest *)
245 odr_malloc(o, sizeof(*r));
248 r->which = Z_AccessControlRequest_simpleForm;
254 static Z_AccessControlResponse *zget_AccessControlResponse(ODR o)
256 Z_AccessControlResponse *r = (Z_AccessControlResponse *)
257 odr_malloc(o, sizeof(*r));
260 r->which = Z_AccessControlResponse_simpleForm;
267 static Z_Segment *zget_Segment(ODR o)
269 Z_Segment *r = (Z_Segment *)odr_malloc(o, sizeof(*r));
272 r->numberOfRecordsReturned = odr_intdup(o, 0);
273 r->num_segmentRecords = 0;
274 r->segmentRecords = (Z_NamePlusRecord **) odr_nullval();
279 static Z_Close *zget_Close(ODR o)
281 Z_Close *r = (Z_Close *)odr_malloc(o, sizeof(*r));
284 r->closeReason = odr_intdup(o, Z_Close_finished);
285 r->diagnosticInformation = 0;
286 r->resourceReportFormat = 0;
287 r->resourceReport = 0;
292 static Z_ResourceReportRequest *zget_ResourceReportRequest(ODR o)
294 Z_ResourceReportRequest *r = (Z_ResourceReportRequest *)
295 odr_malloc(o, sizeof(*r));
299 r->prefResourceReportFormat = 0;
304 static Z_ResourceReportResponse *zget_ResourceReportResponse(ODR o)
306 Z_ResourceReportResponse *r = (Z_ResourceReportResponse *)
307 odr_malloc(o, sizeof(*r));
310 r->resourceReportStatus = odr_intdup(o, Z_ResourceReportResponse_success);
311 r->resourceReport = 0;
316 static Z_SortRequest *zget_SortRequest(ODR o)
318 Z_SortRequest *r = (Z_SortRequest *)odr_malloc(o, sizeof(*r));
321 r->inputResultSetNames = 0;
322 r->sortedResultSetName = 0;
328 static Z_SortResponse *zget_SortResponse(ODR o)
330 Z_SortResponse *r = (Z_SortResponse *)odr_malloc(o, sizeof(*r));
333 r->sortStatus = odr_intdup(o, Z_SortResponse_success);
334 r->resultSetStatus = odr_intdup(o, Z_SortResponse_empty);
341 static Z_ExtendedServicesRequest *zget_ExtendedServicesRequest(ODR o)
343 Z_ExtendedServicesRequest *r = (Z_ExtendedServicesRequest *)
344 odr_malloc(o, sizeof(*r));
347 r->function = odr_intdup(o, Z_ExtendedServicesRequest_create);
351 r->retentionTime = 0;
354 r->taskSpecificParameters = 0;
355 r->waitAction = odr_intdup(o, Z_ExtendedServicesRequest_waitIfPossible);
361 static Z_ExtendedServicesResponse *zget_ExtendedServicesResponse(ODR o)
363 Z_ExtendedServicesResponse *r = (Z_ExtendedServicesResponse *)
364 odr_malloc(o, sizeof(*r));
367 r->operationStatus = odr_intdup(o, Z_ExtendedServicesResponse_done);
368 r->num_diagnostics = 0;
375 static Z_DuplicateDetectionRequest *zget_DuplicateDetectionRequest(ODR o)
377 Z_DuplicateDetectionRequest *r = (Z_DuplicateDetectionRequest *)
378 odr_malloc(o, sizeof(*r));
381 r->num_inputResultSetIds = 0;
382 r->inputResultSetIds = 0;
383 r->outputResultSetName = 0;
384 r->applicablePortionOfRecord = 0;
385 r->num_duplicateDetectionCriteria = 0;
386 r->duplicateDetectionCriteria = 0;
388 r->num_retentionCriteria = 0;
389 r->retentionCriteria = 0;
390 r->num_sortCriteria = 0;
396 static Z_DuplicateDetectionResponse *zget_DuplicateDetectionResponse(ODR o)
398 Z_DuplicateDetectionResponse *r = (Z_DuplicateDetectionResponse *)
399 odr_malloc(o, sizeof(*r));
402 r->status = odr_intdup(o, Z_DuplicateDetectionResponse_success);
403 r->resultSetCount = 0;
404 r->num_diagnostics = 0;
410 Z_APDU *zget_APDU(ODR o, int which)
412 Z_APDU *r = (Z_APDU *)odr_malloc(o, sizeof(*r));
414 switch (r->which = which)
416 case Z_APDU_initRequest:
417 r->u.initRequest = zget_InitRequest(o);
419 case Z_APDU_initResponse:
420 r->u.initResponse = zget_InitResponse(o);
422 case Z_APDU_searchRequest:
423 r->u.searchRequest = zget_SearchRequest(o);
425 case Z_APDU_searchResponse:
426 r->u.searchResponse = zget_SearchResponse(o);
428 case Z_APDU_presentRequest:
429 r->u.presentRequest = zget_PresentRequest(o);
431 case Z_APDU_presentResponse:
432 r->u.presentResponse = zget_PresentResponse(o);
434 case Z_APDU_deleteResultSetRequest:
435 r->u.deleteResultSetRequest = zget_DeleteResultSetRequest(o);
437 case Z_APDU_deleteResultSetResponse:
438 r->u.deleteResultSetResponse = zget_DeleteResultSetResponse(o);
440 case Z_APDU_scanRequest:
441 r->u.scanRequest = zget_ScanRequest(o);
443 case Z_APDU_scanResponse:
444 r->u.scanResponse = zget_ScanResponse(o);
446 case Z_APDU_triggerResourceControlRequest:
447 r->u.triggerResourceControlRequest =
448 zget_TriggerResourceControlRequest(o);
450 case Z_APDU_resourceControlRequest:
451 r->u.resourceControlRequest = zget_ResourceControlRequest(o);
453 case Z_APDU_resourceControlResponse:
454 r->u.resourceControlResponse = zget_ResourceControlResponse(o);
456 case Z_APDU_segmentRequest:
457 r->u.segmentRequest = zget_Segment(o);
460 r->u.close = zget_Close(o);
462 case Z_APDU_accessControlRequest:
463 r->u.accessControlRequest = zget_AccessControlRequest(o);
465 case Z_APDU_accessControlResponse:
466 r->u.accessControlResponse = zget_AccessControlResponse(o);
468 case Z_APDU_resourceReportRequest:
469 r->u.resourceReportRequest = zget_ResourceReportRequest(o);
471 case Z_APDU_resourceReportResponse:
472 r->u.resourceReportResponse = zget_ResourceReportResponse(o);
474 case Z_APDU_sortRequest:
475 r->u.sortRequest = zget_SortRequest(o);
477 case Z_APDU_sortResponse:
478 r->u.sortResponse = zget_SortResponse(o);
480 case Z_APDU_extendedServicesRequest:
481 r->u.extendedServicesRequest = zget_ExtendedServicesRequest(o);
483 case Z_APDU_extendedServicesResponse:
484 r->u.extendedServicesResponse = zget_ExtendedServicesResponse(o);
486 case Z_APDU_duplicateDetectionRequest:
487 r->u.duplicateDetectionRequest = zget_DuplicateDetectionRequest(o);
489 case Z_APDU_duplicateDetectionResponse:
490 r->u.duplicateDetectionResponse = zget_DuplicateDetectionResponse(o);
498 Z_DefaultDiagFormat *zget_DefaultDiagFormat(ODR o, int error,
501 Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
502 odr_malloc(o, sizeof(*dr));
504 dr->diagnosticSetId = odr_oiddup(o, yaz_oid_diagset_bib_1);
505 dr->condition = odr_intdup(o, error);
506 dr->which = Z_DefaultDiagFormat_v2Addinfo;
507 dr->u.v2Addinfo = odr_strdup (o, addinfo ? addinfo : "");
511 Z_DiagRec *zget_DiagRec(ODR o, int error, const char *addinfo)
513 Z_DiagRec *dr = (Z_DiagRec*) odr_malloc(o, sizeof(*dr));
514 dr->which = Z_DiagRec_defaultFormat;
515 dr->u.defaultFormat = zget_DefaultDiagFormat(o, error, addinfo);
519 Z_DiagRecs *zget_DiagRecs(ODR o, int error, const char *addinfo)
521 Z_DiagRecs *drecs = (Z_DiagRecs*) odr_malloc(o, sizeof(*drecs));
522 Z_DiagRec **dr = (Z_DiagRec**) odr_malloc(o, sizeof(**dr));
523 drecs->diagRecs = dr;
524 dr[0] = zget_DiagRec(o, error, addinfo);
525 drecs->num_diagRecs = 1;
529 Z_NamePlusRecord *zget_surrogateDiagRec(ODR o, const char *dbname,
530 int error, const char *addinfo)
532 Z_NamePlusRecord *rec = (Z_NamePlusRecord *) odr_malloc(o, sizeof(*rec));
533 Z_DiagRec *drec = (Z_DiagRec *)odr_malloc(o, sizeof(*drec));
536 rec->databaseName = odr_strdup(o, dbname);
538 rec->databaseName = 0;
539 rec->which = Z_NamePlusRecord_surrogateDiagnostic;
540 rec->u.surrogateDiagnostic = drec;
541 drec->which = Z_DiagRec_defaultFormat;
542 drec->u.defaultFormat = zget_DefaultDiagFormat(o, error, addinfo);
546 Z_External *zget_init_diagnostics(ODR odr, int error, const char *addinfo)
549 Z_OtherInformation *u;
550 Z_OtherInformationUnit *l;
551 Z_DiagnosticFormat *d;
552 Z_DiagnosticFormat_s *e;
554 x = (Z_External*) odr_malloc(odr, sizeof *x);
556 x->indirect_reference = 0;
557 x->direct_reference = odr_oiddup(odr, yaz_oid_userinfo_userinfo_1);
558 x->which = Z_External_userInfo1;
560 u = (Z_OtherInformation *) odr_malloc(odr, sizeof *u);
563 u->list = (Z_OtherInformationUnit**) odr_malloc(odr, sizeof *u->list);
564 u->list[0] = (Z_OtherInformationUnit*) odr_malloc(odr, sizeof *u->list[0]);
567 l->which = Z_OtherInfo_externallyDefinedInfo;
569 x2 = (Z_External*) odr_malloc(odr, sizeof *x);
570 l->information.externallyDefinedInfo = x2;
572 x2->indirect_reference = 0;
573 x2->direct_reference = odr_oiddup(odr, yaz_oid_diagset_diag_1);
574 x2->which = Z_External_diag1;
576 d = (Z_DiagnosticFormat*) odr_malloc(odr, sizeof *d);
579 d->elements = (Z_DiagnosticFormat_s**) odr_malloc(odr, sizeof *d->elements);
580 d->elements[0] = (Z_DiagnosticFormat_s*) odr_malloc(odr, sizeof *d->elements[0]);
583 e->which = Z_DiagnosticFormat_s_defaultDiagRec;
584 e->u.defaultDiagRec = zget_DefaultDiagFormat(odr, error, addinfo);
589 Z_External *zget_init_diagnostics_octet(ODR odr, int error,
593 Z_OtherInformation *u;
594 Z_OtherInformationUnit *l;
595 Z_DiagnosticFormat *d;
596 Z_DiagnosticFormat_s *e;
601 u = (Z_OtherInformation *) odr_malloc(odr, sizeof *u);
603 u->list = (Z_OtherInformationUnit**) odr_malloc(odr, sizeof *u->list);
604 u->list[0] = (Z_OtherInformationUnit*) odr_malloc(odr, sizeof *u->list[0]);
607 l->which = Z_OtherInfo_externallyDefinedInfo;
609 x2 = (Z_External*) odr_malloc(odr, sizeof *x);
610 l->information.externallyDefinedInfo = x2;
612 x2->indirect_reference = 0;
614 x2->direct_reference = odr_oiddup(odr, yaz_oid_diagset_diag_1);
615 x2->which = Z_External_diag1;
617 d = (Z_DiagnosticFormat*) odr_malloc(odr, sizeof *d);
620 d->elements = (Z_DiagnosticFormat_s**) odr_malloc(odr, sizeof *d->elements);
621 d->elements[0] = (Z_DiagnosticFormat_s*) odr_malloc(odr, sizeof *d->elements[0]);
624 e->which = Z_DiagnosticFormat_s_defaultDiagRec;
625 e->u.defaultDiagRec = zget_DefaultDiagFormat(odr, error, addinfo);
628 encode = odr_createmem(ODR_ENCODE);
630 z_OtherInformation(encode, &u, 0, 0);
632 octet_buf = odr_getbuf(encode, &octet_len, 0);
634 x = (Z_External*) odr_malloc(odr, sizeof *x);
636 x->indirect_reference = 0;
637 x->direct_reference = odr_oiddup(odr, yaz_oid_userinfo_userinfo_1);
638 x->which = Z_External_octet;
639 x->u.octet_aligned = odr_create_Odr_oct(odr, octet_buf, octet_len);
649 * c-file-style: "Stroustrup"
650 * indent-tabs-mode: nil
652 * vim: shiftwidth=4 tabstop=8 expandtab