1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2008 Index Data
3 * See the file LICENSE for details.
7 * \brief Implements Z39.50 package creator utilities
10 #include <yaz/proto.h>
11 #include <yaz/oid_db.h>
13 Z_InitRequest *zget_InitRequest(ODR o)
15 Z_InitRequest *r = (Z_InitRequest *)odr_malloc(o, sizeof(*r));
18 r->options = (Odr_bitmask *)odr_malloc(o, sizeof(*r->options));
19 ODR_MASK_ZERO(r->options);
20 r->protocolVersion = (Odr_bitmask *)
21 odr_malloc(o, sizeof(*r->protocolVersion));
23 ODR_MASK_SET(r->options, Z_Options_search);
24 ODR_MASK_SET(r->options, Z_Options_present);
26 ODR_MASK_ZERO(r->protocolVersion);
28 ODR_MASK_SET(r->protocolVersion, Z_ProtocolVersion_1);
29 ODR_MASK_SET(r->protocolVersion, Z_ProtocolVersion_2);
31 r->preferredMessageSize = odr_intdup(o, 1024*1024);
32 r->maximumRecordSize = odr_intdup(o, 1024*1024);
33 r->idAuthentication = 0;
34 r->implementationId = "81";
35 r->implementationName = "YAZ";
36 r->implementationVersion = YAZ_VERSION
44 r->userInformationField = 0;
49 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_intdup(o, 1);
61 r->implementationId = "81";
62 r->implementationName = "YAZ";
63 r->implementationVersion = YAZ_VERSION
71 r->userInformationField = 0;
76 Z_SearchRequest *zget_SearchRequest(ODR o)
78 Z_SearchRequest *r = (Z_SearchRequest *)odr_malloc(o, sizeof(*r));
81 r->smallSetUpperBound = odr_intdup(o, 0);
82 r->largeSetLowerBound = odr_intdup(o, 1);
83 r->mediumSetPresentNumber = odr_intdup(o, 0);
84 r->replaceIndicator = odr_intdup(o, 1);
85 r->resultSetName = "default";
86 r->num_databaseNames = 0;
88 r->smallSetElementSetNames = 0;
89 r->mediumSetElementSetNames = 0;
90 r->preferredRecordSyntax = 0;
92 r->additionalSearchInfo = 0;
97 Z_SearchResponse *zget_SearchResponse(ODR o)
99 Z_SearchResponse *r = (Z_SearchResponse *)odr_malloc(o, sizeof(*r));
102 r->resultCount = odr_intdup(o, 0);
103 r->numberOfRecordsReturned = odr_intdup(o, 0);
104 r->nextResultSetPosition = odr_intdup(o, 0);
105 r->searchStatus = odr_intdup(o, 1);
106 r->resultSetStatus = 0;
107 r->presentStatus = 0;
109 r->additionalSearchInfo = 0;
114 Z_PresentRequest *zget_PresentRequest(ODR o)
116 Z_PresentRequest *r = (Z_PresentRequest *)odr_malloc(o, sizeof(*r));
119 r->resultSetId = "default";
120 r->resultSetStartPoint = odr_intdup(o, 1);
121 r->numberOfRecordsRequested = odr_intdup(o, 10);
123 r->additionalRanges = 0;
124 r->recordComposition = 0;
125 r->preferredRecordSyntax = 0;
126 r->maxSegmentCount = 0;
127 r->maxRecordSize = 0;
128 r->maxSegmentSize = 0;
133 Z_PresentResponse *zget_PresentResponse(ODR o)
135 Z_PresentResponse *r = (Z_PresentResponse *)odr_malloc(o, sizeof(*r));
138 r->numberOfRecordsReturned = odr_intdup(o, 0);
139 r->nextResultSetPosition = odr_intdup(o, 0);
140 r->presentStatus = odr_intdup(o, Z_PresentStatus_success);
146 Z_DeleteResultSetRequest *zget_DeleteResultSetRequest(ODR o)
148 Z_DeleteResultSetRequest *r = (Z_DeleteResultSetRequest *)
149 odr_malloc(o, sizeof(*r));
152 r->deleteFunction = odr_intdup(o, Z_DeleteResultSetRequest_list);
153 r->num_resultSetList = 0;
154 r->resultSetList = 0;
159 Z_DeleteResultSetResponse *zget_DeleteResultSetResponse(ODR o)
161 Z_DeleteResultSetResponse *r = (Z_DeleteResultSetResponse *)
162 odr_malloc(o, sizeof(*r));
165 r->deleteOperationStatus = odr_intdup(o, Z_DeleteStatus_success);
166 r->deleteListStatuses = 0;
167 r->numberNotDeleted = 0;
169 r->deleteMessage = 0;
174 Z_ScanRequest *zget_ScanRequest(ODR o)
176 Z_ScanRequest *r = (Z_ScanRequest *)odr_malloc(o, sizeof(*r));
179 r->num_databaseNames = 0;
180 r->databaseNames = 0;
182 r->termListAndStartPoint = 0;
184 r->numberOfTermsRequested = odr_intdup(o, 20);
185 r->preferredPositionInResponse = 0;
190 Z_ScanResponse *zget_ScanResponse(ODR o)
192 Z_ScanResponse *r = (Z_ScanResponse *)odr_malloc(o, sizeof(*r));
196 r->scanStatus = odr_intdup(o, Z_Scan_success);
197 r->numberOfEntriesReturned = odr_intdup(o, 0);
198 r->positionOfTerm =0;
205 Z_TriggerResourceControlRequest *zget_TriggerResourceControlRequest(ODR o)
207 Z_TriggerResourceControlRequest *r = (Z_TriggerResourceControlRequest *)
208 odr_malloc(o, sizeof(*r));
211 r->requestedAction = odr_intdup(o, Z_TriggerResourceControlRequest_resourceReport);
212 r->prefResourceReportFormat = 0;
213 r->resultSetWanted = 0;
218 Z_ResourceControlRequest *zget_ResourceControlRequest(ODR o)
220 Z_ResourceControlRequest *r = (Z_ResourceControlRequest *)
221 odr_malloc(o, sizeof(*r));
224 r->suspendedFlag = 0;
225 r->resourceReport = 0;
226 r->partialResultsAvailable = 0;
227 r->responseRequired = odr_intdup(o, 0);
228 r->triggeredRequestFlag = 0;
233 Z_ResourceControlResponse *zget_ResourceControlResponse(ODR o)
235 Z_ResourceControlResponse *r = (Z_ResourceControlResponse *)
236 odr_malloc(o, sizeof(*r));
239 r->continueFlag = odr_intdup(o, 1);
240 r->resultSetWanted = 0;
245 Z_AccessControlRequest *zget_AccessControlRequest(ODR o)
247 Z_AccessControlRequest *r = (Z_AccessControlRequest *)
248 odr_malloc(o, sizeof(*r));
251 r->which = Z_AccessControlRequest_simpleForm;
257 Z_AccessControlResponse *zget_AccessControlResponse(ODR o)
259 Z_AccessControlResponse *r = (Z_AccessControlResponse *)
260 odr_malloc(o, sizeof(*r));
263 r->which = Z_AccessControlResponse_simpleForm;
270 Z_Segment *zget_Segment(ODR o)
272 Z_Segment *r = (Z_Segment *)odr_malloc(o, sizeof(*r));
275 r->numberOfRecordsReturned = odr_intdup(o, 0);
276 r->num_segmentRecords = 0;
277 r->segmentRecords = (Z_NamePlusRecord **) odr_nullval();
282 Z_Close *zget_Close(ODR o)
284 Z_Close *r = (Z_Close *)odr_malloc(o, sizeof(*r));
287 r->closeReason = odr_intdup(o, Z_Close_finished);
288 r->diagnosticInformation = 0;
289 r->resourceReportFormat = 0;
290 r->resourceReport = 0;
295 Z_ResourceReportRequest *zget_ResourceReportRequest(ODR o)
297 Z_ResourceReportRequest *r = (Z_ResourceReportRequest *)
298 odr_malloc(o, sizeof(*r));
302 r->prefResourceReportFormat = 0;
307 Z_ResourceReportResponse *zget_ResourceReportResponse(ODR o)
309 Z_ResourceReportResponse *r = (Z_ResourceReportResponse *)
310 odr_malloc(o, sizeof(*r));
313 r->resourceReportStatus = odr_intdup(o, Z_ResourceReportResponse_success);
314 r->resourceReport = 0;
319 Z_SortRequest *zget_SortRequest(ODR o)
321 Z_SortRequest *r = (Z_SortRequest *)odr_malloc(o, sizeof(*r));
324 r->inputResultSetNames = 0;
325 r->sortedResultSetName = 0;
331 Z_SortResponse *zget_SortResponse(ODR o)
333 Z_SortResponse *r = (Z_SortResponse *)odr_malloc(o, sizeof(*r));
336 r->sortStatus = odr_intdup(o, Z_SortResponse_success);
337 r->resultSetStatus = odr_intdup(o, Z_SortResponse_empty);
344 Z_ExtendedServicesRequest *zget_ExtendedServicesRequest(ODR o)
346 Z_ExtendedServicesRequest *r = (Z_ExtendedServicesRequest *)
347 odr_malloc(o, sizeof(*r));
350 r->function = odr_intdup(o, Z_ExtendedServicesRequest_create);
354 r->retentionTime = 0;
357 r->taskSpecificParameters = 0;
358 r->waitAction = odr_intdup(o, Z_ExtendedServicesRequest_waitIfPossible);
364 Z_ExtendedServicesResponse *zget_ExtendedServicesResponse(ODR o)
366 Z_ExtendedServicesResponse *r = (Z_ExtendedServicesResponse *)
367 odr_malloc(o, sizeof(*r));
370 r->operationStatus = odr_intdup(o, Z_ExtendedServicesResponse_done);
371 r->num_diagnostics = 0;
378 Z_DuplicateDetectionRequest *zget_DuplicateDetectionRequest(ODR o)
380 Z_DuplicateDetectionRequest *r = (Z_DuplicateDetectionRequest *)
381 odr_malloc(o, sizeof(*r));
384 r->num_inputResultSetIds = 0;
385 r->inputResultSetIds = 0;
386 r->outputResultSetName = 0;
387 r->applicablePortionOfRecord = 0;
388 r->num_duplicateDetectionCriteria = 0;
389 r->duplicateDetectionCriteria = 0;
391 r->num_retentionCriteria = 0;
392 r->retentionCriteria = 0;
393 r->num_sortCriteria = 0;
399 Z_DuplicateDetectionResponse *zget_DuplicateDetectionResponse(ODR o)
401 Z_DuplicateDetectionResponse *r = (Z_DuplicateDetectionResponse *)
402 odr_malloc(o, sizeof(*r));
405 r->status = odr_intdup(o, Z_DuplicateDetectionResponse_success);
406 r->resultSetCount = 0;
407 r->num_diagnostics = 0;
413 Z_APDU *zget_APDU(ODR o, int which)
415 Z_APDU *r = (Z_APDU *)odr_malloc(o, sizeof(*r));
417 switch (r->which = which)
419 case Z_APDU_initRequest:
420 r->u.initRequest = zget_InitRequest(o);
422 case Z_APDU_initResponse:
423 r->u.initResponse = zget_InitResponse(o);
425 case Z_APDU_searchRequest:
426 r->u.searchRequest = zget_SearchRequest(o);
428 case Z_APDU_searchResponse:
429 r->u.searchResponse = zget_SearchResponse(o);
431 case Z_APDU_presentRequest:
432 r->u.presentRequest = zget_PresentRequest(o);
434 case Z_APDU_presentResponse:
435 r->u.presentResponse = zget_PresentResponse(o);
437 case Z_APDU_deleteResultSetRequest:
438 r->u.deleteResultSetRequest = zget_DeleteResultSetRequest(o);
440 case Z_APDU_deleteResultSetResponse:
441 r->u.deleteResultSetResponse = zget_DeleteResultSetResponse(o);
443 case Z_APDU_scanRequest:
444 r->u.scanRequest = zget_ScanRequest(o);
446 case Z_APDU_scanResponse:
447 r->u.scanResponse = zget_ScanResponse(o);
449 case Z_APDU_triggerResourceControlRequest:
450 r->u.triggerResourceControlRequest =
451 zget_TriggerResourceControlRequest(o);
453 case Z_APDU_resourceControlRequest:
454 r->u.resourceControlRequest = zget_ResourceControlRequest(o);
456 case Z_APDU_resourceControlResponse:
457 r->u.resourceControlResponse = zget_ResourceControlResponse(o);
459 case Z_APDU_segmentRequest:
460 r->u.segmentRequest = zget_Segment(o);
463 r->u.close = zget_Close(o);
465 case Z_APDU_accessControlRequest:
466 r->u.accessControlRequest = zget_AccessControlRequest(o);
468 case Z_APDU_accessControlResponse:
469 r->u.accessControlResponse = zget_AccessControlResponse(o);
471 case Z_APDU_resourceReportRequest:
472 r->u.resourceReportRequest = zget_ResourceReportRequest(o);
474 case Z_APDU_resourceReportResponse:
475 r->u.resourceReportResponse = zget_ResourceReportResponse(o);
477 case Z_APDU_sortRequest:
478 r->u.sortRequest = zget_SortRequest(o);
480 case Z_APDU_sortResponse:
481 r->u.sortResponse = zget_SortResponse(o);
483 case Z_APDU_extendedServicesRequest:
484 r->u.extendedServicesRequest = zget_ExtendedServicesRequest(o);
486 case Z_APDU_extendedServicesResponse:
487 r->u.extendedServicesResponse = zget_ExtendedServicesResponse(o);
489 case Z_APDU_duplicateDetectionRequest:
490 r->u.duplicateDetectionRequest = zget_DuplicateDetectionRequest(o);
492 case Z_APDU_duplicateDetectionResponse:
493 r->u.duplicateDetectionResponse = zget_DuplicateDetectionResponse(o);
501 Z_DefaultDiagFormat *zget_DefaultDiagFormat(ODR o, int error,
504 Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
505 odr_malloc (o, sizeof(*dr));
507 dr->diagnosticSetId = odr_oiddup(o, yaz_oid_diagset_bib_1);
508 dr->condition = odr_intdup(o, error);
509 dr->which = Z_DefaultDiagFormat_v2Addinfo;
510 dr->u.v2Addinfo = odr_strdup (o, addinfo ? addinfo : "");
514 Z_DiagRec *zget_DiagRec(ODR o, int error, const char *addinfo)
516 Z_DiagRec *dr = (Z_DiagRec*) odr_malloc(o, sizeof(*dr));
517 dr->which = Z_DiagRec_defaultFormat;
518 dr->u.defaultFormat = zget_DefaultDiagFormat(o, error, addinfo);
522 Z_DiagRecs *zget_DiagRecs(ODR o, int error, const char *addinfo)
524 Z_DiagRecs *drecs = (Z_DiagRecs*) odr_malloc(o, sizeof(*drecs));
525 Z_DiagRec **dr = (Z_DiagRec**) odr_malloc(o, sizeof(**dr));
526 drecs->diagRecs = dr;
527 dr[0] = zget_DiagRec(o, error, addinfo);
528 drecs->num_diagRecs = 1;
532 Z_NamePlusRecord *zget_surrogateDiagRec(ODR o, const char *dbname,
533 int error, const char *addinfo)
535 Z_NamePlusRecord *rec = (Z_NamePlusRecord *) odr_malloc (o, sizeof(*rec));
536 Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (o, sizeof(*drec));
539 rec->databaseName = odr_strdup(o, dbname);
541 rec->databaseName = 0;
542 rec->which = Z_NamePlusRecord_surrogateDiagnostic;
543 rec->u.surrogateDiagnostic = drec;
544 drec->which = Z_DiagRec_defaultFormat;
545 drec->u.defaultFormat = zget_DefaultDiagFormat(o, error, addinfo);
549 Z_External *zget_init_diagnostics(ODR odr, int error, const char *addinfo)
552 Z_OtherInformation *u;
553 Z_OtherInformationUnit *l;
554 Z_DiagnosticFormat *d;
555 Z_DiagnosticFormat_s *e;
557 x = (Z_External*) odr_malloc(odr, sizeof *x);
559 x->indirect_reference = 0;
560 x->direct_reference = odr_oiddup(odr, yaz_oid_userinfo_userinfo_1);
561 x->which = Z_External_userInfo1;
563 u = (Z_OtherInformation *) odr_malloc(odr, sizeof *u);
566 u->list = (Z_OtherInformationUnit**) odr_malloc(odr, sizeof *u->list);
567 u->list[0] = (Z_OtherInformationUnit*) odr_malloc(odr, sizeof *u->list[0]);
570 l->which = Z_OtherInfo_externallyDefinedInfo;
572 x2 = (Z_External*) odr_malloc(odr, sizeof *x);
573 l->information.externallyDefinedInfo = x2;
575 x2->indirect_reference = 0;
576 x2->direct_reference = odr_oiddup(odr, yaz_oid_diagset_diag_1);
577 x2->which = Z_External_diag1;
579 d = (Z_DiagnosticFormat*) odr_malloc(odr, sizeof *d);
582 d->elements = (Z_DiagnosticFormat_s**) odr_malloc (odr, sizeof *d->elements);
583 d->elements[0] = (Z_DiagnosticFormat_s*) odr_malloc (odr, sizeof *d->elements[0]);
586 e->which = Z_DiagnosticFormat_s_defaultDiagRec;
587 e->u.defaultDiagRec = zget_DefaultDiagFormat(odr, error, addinfo);
592 Z_External *zget_init_diagnostics_octet(ODR odr, int error,
596 Z_OtherInformation *u;
597 Z_OtherInformationUnit *l;
598 Z_DiagnosticFormat *d;
599 Z_DiagnosticFormat_s *e;
604 u = (Z_OtherInformation *) odr_malloc(odr, sizeof *u);
606 u->list = (Z_OtherInformationUnit**) odr_malloc(odr, sizeof *u->list);
607 u->list[0] = (Z_OtherInformationUnit*) odr_malloc(odr, sizeof *u->list[0]);
610 l->which = Z_OtherInfo_externallyDefinedInfo;
612 x2 = (Z_External*) odr_malloc(odr, sizeof *x);
613 l->information.externallyDefinedInfo = x2;
615 x2->indirect_reference = 0;
617 x2->direct_reference = odr_oiddup(odr, yaz_oid_diagset_diag_1);
618 x2->which = Z_External_diag1;
620 d = (Z_DiagnosticFormat*) odr_malloc(odr, sizeof *d);
623 d->elements = (Z_DiagnosticFormat_s**) odr_malloc (odr, sizeof *d->elements);
624 d->elements[0] = (Z_DiagnosticFormat_s*) odr_malloc (odr, sizeof *d->elements[0]);
627 e->which = Z_DiagnosticFormat_s_defaultDiagRec;
628 e->u.defaultDiagRec = zget_DefaultDiagFormat(odr, error, addinfo);
631 encode = odr_createmem(ODR_ENCODE);
633 z_OtherInformation(encode, &u, 0, 0);
635 octet_buf = odr_getbuf(encode, &octet_len, 0);
637 x = (Z_External*) odr_malloc(odr, sizeof *x);
639 x->indirect_reference = 0;
640 x->direct_reference = odr_oiddup(odr, yaz_oid_userinfo_userinfo_1);
641 x->which = Z_External_octet;
642 x->u.octet_aligned = (Odr_oct *) odr_malloc(odr, sizeof(Odr_oct));
643 x->u.octet_aligned->buf = (unsigned char *) odr_malloc(odr, octet_len);
644 memcpy(x->u.octet_aligned->buf, octet_buf, octet_len);
645 x->u.octet_aligned->len = octet_len;
655 * indent-tabs-mode: nil
657 * vim: shiftwidth=4 tabstop=8 expandtab