1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 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
37 #ifdef YAZ_VERSION_SHA1
41 r->userInformationField = 0;
46 Z_InitResponse *zget_InitResponse(ODR o)
48 Z_InitResponse *r = (Z_InitResponse *)odr_malloc(o, sizeof(*r));
51 r->options = (Odr_bitmask *)odr_malloc(o, sizeof(*r->options));
52 ODR_MASK_ZERO(r->options);
53 r->protocolVersion = (Odr_bitmask *)odr_malloc(o, sizeof(*r->protocolVersion));
54 ODR_MASK_ZERO(r->protocolVersion);
55 r->preferredMessageSize = odr_intdup(o, 30*1024);
56 r->maximumRecordSize = odr_intdup(o, 30*1024);
57 r->result = odr_intdup(o, 1);
58 r->implementationId = "81";
59 r->implementationName = "YAZ";
60 r->implementationVersion = YAZ_VERSION
61 #ifdef YAZ_VERSION_SHA1
65 r->userInformationField = 0;
70 Z_SearchRequest *zget_SearchRequest(ODR o)
72 Z_SearchRequest *r = (Z_SearchRequest *)odr_malloc(o, sizeof(*r));
75 r->smallSetUpperBound = odr_intdup(o, 0);
76 r->largeSetLowerBound = odr_intdup(o, 1);
77 r->mediumSetPresentNumber = odr_intdup(o, 0);
78 r->replaceIndicator = odr_intdup(o, 1);
79 r->resultSetName = "default";
80 r->num_databaseNames = 0;
82 r->smallSetElementSetNames = 0;
83 r->mediumSetElementSetNames = 0;
84 r->preferredRecordSyntax = 0;
86 r->additionalSearchInfo = 0;
91 Z_SearchResponse *zget_SearchResponse(ODR o)
93 Z_SearchResponse *r = (Z_SearchResponse *)odr_malloc(o, sizeof(*r));
96 r->resultCount = odr_intdup(o, 0);
97 r->numberOfRecordsReturned = odr_intdup(o, 0);
98 r->nextResultSetPosition = odr_intdup(o, 0);
99 r->searchStatus = odr_intdup(o, 1);
100 r->resultSetStatus = 0;
101 r->presentStatus = 0;
103 r->additionalSearchInfo = 0;
108 Z_PresentRequest *zget_PresentRequest(ODR o)
110 Z_PresentRequest *r = (Z_PresentRequest *)odr_malloc(o, sizeof(*r));
113 r->resultSetId = "default";
114 r->resultSetStartPoint = odr_intdup(o, 1);
115 r->numberOfRecordsRequested = odr_intdup(o, 10);
117 r->additionalRanges = 0;
118 r->recordComposition = 0;
119 r->preferredRecordSyntax = 0;
120 r->maxSegmentCount = 0;
121 r->maxRecordSize = 0;
122 r->maxSegmentSize = 0;
127 Z_PresentResponse *zget_PresentResponse(ODR o)
129 Z_PresentResponse *r = (Z_PresentResponse *)odr_malloc(o, sizeof(*r));
132 r->numberOfRecordsReturned = odr_intdup(o, 0);
133 r->nextResultSetPosition = odr_intdup(o, 0);
134 r->presentStatus = odr_intdup(o, Z_PresentStatus_success);
140 Z_DeleteResultSetRequest *zget_DeleteResultSetRequest(ODR o)
142 Z_DeleteResultSetRequest *r = (Z_DeleteResultSetRequest *)
143 odr_malloc(o, sizeof(*r));
146 r->deleteFunction = odr_intdup(o, Z_DeleteResultSetRequest_list);
147 r->num_resultSetList = 0;
148 r->resultSetList = 0;
153 Z_DeleteResultSetResponse *zget_DeleteResultSetResponse(ODR o)
155 Z_DeleteResultSetResponse *r = (Z_DeleteResultSetResponse *)
156 odr_malloc(o, sizeof(*r));
159 r->deleteOperationStatus = odr_intdup(o, Z_DeleteStatus_success);
160 r->deleteListStatuses = 0;
161 r->numberNotDeleted = 0;
163 r->deleteMessage = 0;
168 Z_ScanRequest *zget_ScanRequest(ODR o)
170 Z_ScanRequest *r = (Z_ScanRequest *)odr_malloc(o, sizeof(*r));
173 r->num_databaseNames = 0;
174 r->databaseNames = 0;
176 r->termListAndStartPoint = 0;
178 r->numberOfTermsRequested = odr_intdup(o, 20);
179 r->preferredPositionInResponse = 0;
184 Z_ScanResponse *zget_ScanResponse(ODR o)
186 Z_ScanResponse *r = (Z_ScanResponse *)odr_malloc(o, sizeof(*r));
190 r->scanStatus = odr_intdup(o, Z_Scan_success);
191 r->numberOfEntriesReturned = odr_intdup(o, 0);
192 r->positionOfTerm =0;
199 Z_TriggerResourceControlRequest *zget_TriggerResourceControlRequest(ODR o)
201 Z_TriggerResourceControlRequest *r = (Z_TriggerResourceControlRequest *)
202 odr_malloc(o, sizeof(*r));
205 r->requestedAction = odr_intdup(o, Z_TriggerResourceControlRequest_resourceReport);
206 r->prefResourceReportFormat = 0;
207 r->resultSetWanted = 0;
212 Z_ResourceControlRequest *zget_ResourceControlRequest(ODR o)
214 Z_ResourceControlRequest *r = (Z_ResourceControlRequest *)
215 odr_malloc(o, sizeof(*r));
218 r->suspendedFlag = 0;
219 r->resourceReport = 0;
220 r->partialResultsAvailable = 0;
221 r->responseRequired = odr_intdup(o, 0);
222 r->triggeredRequestFlag = 0;
227 Z_ResourceControlResponse *zget_ResourceControlResponse(ODR o)
229 Z_ResourceControlResponse *r = (Z_ResourceControlResponse *)
230 odr_malloc(o, sizeof(*r));
233 r->continueFlag = odr_intdup(o, 1);
234 r->resultSetWanted = 0;
239 Z_AccessControlRequest *zget_AccessControlRequest(ODR o)
241 Z_AccessControlRequest *r = (Z_AccessControlRequest *)
242 odr_malloc(o, sizeof(*r));
245 r->which = Z_AccessControlRequest_simpleForm;
251 Z_AccessControlResponse *zget_AccessControlResponse(ODR o)
253 Z_AccessControlResponse *r = (Z_AccessControlResponse *)
254 odr_malloc(o, sizeof(*r));
257 r->which = Z_AccessControlResponse_simpleForm;
264 Z_Segment *zget_Segment(ODR o)
266 Z_Segment *r = (Z_Segment *)odr_malloc(o, sizeof(*r));
269 r->numberOfRecordsReturned = odr_intdup(o, 0);
270 r->num_segmentRecords = 0;
271 r->segmentRecords = (Z_NamePlusRecord **) odr_nullval();
276 Z_Close *zget_Close(ODR o)
278 Z_Close *r = (Z_Close *)odr_malloc(o, sizeof(*r));
281 r->closeReason = odr_intdup(o, Z_Close_finished);
282 r->diagnosticInformation = 0;
283 r->resourceReportFormat = 0;
284 r->resourceReport = 0;
289 Z_ResourceReportRequest *zget_ResourceReportRequest(ODR o)
291 Z_ResourceReportRequest *r = (Z_ResourceReportRequest *)
292 odr_malloc(o, sizeof(*r));
296 r->prefResourceReportFormat = 0;
301 Z_ResourceReportResponse *zget_ResourceReportResponse(ODR o)
303 Z_ResourceReportResponse *r = (Z_ResourceReportResponse *)
304 odr_malloc(o, sizeof(*r));
307 r->resourceReportStatus = odr_intdup(o, Z_ResourceReportResponse_success);
308 r->resourceReport = 0;
313 Z_SortRequest *zget_SortRequest(ODR o)
315 Z_SortRequest *r = (Z_SortRequest *)odr_malloc(o, sizeof(*r));
318 r->inputResultSetNames = 0;
319 r->sortedResultSetName = 0;
325 Z_SortResponse *zget_SortResponse(ODR o)
327 Z_SortResponse *r = (Z_SortResponse *)odr_malloc(o, sizeof(*r));
330 r->sortStatus = odr_intdup(o, Z_SortResponse_success);
331 r->resultSetStatus = odr_intdup(o, Z_SortResponse_empty);
338 Z_ExtendedServicesRequest *zget_ExtendedServicesRequest(ODR o)
340 Z_ExtendedServicesRequest *r = (Z_ExtendedServicesRequest *)
341 odr_malloc(o, sizeof(*r));
344 r->function = odr_intdup(o, Z_ExtendedServicesRequest_create);
348 r->retentionTime = 0;
351 r->taskSpecificParameters = 0;
352 r->waitAction = odr_intdup(o, Z_ExtendedServicesRequest_waitIfPossible);
358 Z_ExtendedServicesResponse *zget_ExtendedServicesResponse(ODR o)
360 Z_ExtendedServicesResponse *r = (Z_ExtendedServicesResponse *)
361 odr_malloc(o, sizeof(*r));
364 r->operationStatus = odr_intdup(o, Z_ExtendedServicesResponse_done);
365 r->num_diagnostics = 0;
372 Z_DuplicateDetectionRequest *zget_DuplicateDetectionRequest(ODR o)
374 Z_DuplicateDetectionRequest *r = (Z_DuplicateDetectionRequest *)
375 odr_malloc(o, sizeof(*r));
378 r->num_inputResultSetIds = 0;
379 r->inputResultSetIds = 0;
380 r->outputResultSetName = 0;
381 r->applicablePortionOfRecord = 0;
382 r->num_duplicateDetectionCriteria = 0;
383 r->duplicateDetectionCriteria = 0;
385 r->num_retentionCriteria = 0;
386 r->retentionCriteria = 0;
387 r->num_sortCriteria = 0;
393 Z_DuplicateDetectionResponse *zget_DuplicateDetectionResponse(ODR o)
395 Z_DuplicateDetectionResponse *r = (Z_DuplicateDetectionResponse *)
396 odr_malloc(o, sizeof(*r));
399 r->status = odr_intdup(o, Z_DuplicateDetectionResponse_success);
400 r->resultSetCount = 0;
401 r->num_diagnostics = 0;
407 Z_APDU *zget_APDU(ODR o, int which)
409 Z_APDU *r = (Z_APDU *)odr_malloc(o, sizeof(*r));
411 switch (r->which = which)
413 case Z_APDU_initRequest:
414 r->u.initRequest = zget_InitRequest(o);
416 case Z_APDU_initResponse:
417 r->u.initResponse = zget_InitResponse(o);
419 case Z_APDU_searchRequest:
420 r->u.searchRequest = zget_SearchRequest(o);
422 case Z_APDU_searchResponse:
423 r->u.searchResponse = zget_SearchResponse(o);
425 case Z_APDU_presentRequest:
426 r->u.presentRequest = zget_PresentRequest(o);
428 case Z_APDU_presentResponse:
429 r->u.presentResponse = zget_PresentResponse(o);
431 case Z_APDU_deleteResultSetRequest:
432 r->u.deleteResultSetRequest = zget_DeleteResultSetRequest(o);
434 case Z_APDU_deleteResultSetResponse:
435 r->u.deleteResultSetResponse = zget_DeleteResultSetResponse(o);
437 case Z_APDU_scanRequest:
438 r->u.scanRequest = zget_ScanRequest(o);
440 case Z_APDU_scanResponse:
441 r->u.scanResponse = zget_ScanResponse(o);
443 case Z_APDU_triggerResourceControlRequest:
444 r->u.triggerResourceControlRequest =
445 zget_TriggerResourceControlRequest(o);
447 case Z_APDU_resourceControlRequest:
448 r->u.resourceControlRequest = zget_ResourceControlRequest(o);
450 case Z_APDU_resourceControlResponse:
451 r->u.resourceControlResponse = zget_ResourceControlResponse(o);
453 case Z_APDU_segmentRequest:
454 r->u.segmentRequest = zget_Segment(o);
457 r->u.close = zget_Close(o);
459 case Z_APDU_accessControlRequest:
460 r->u.accessControlRequest = zget_AccessControlRequest(o);
462 case Z_APDU_accessControlResponse:
463 r->u.accessControlResponse = zget_AccessControlResponse(o);
465 case Z_APDU_resourceReportRequest:
466 r->u.resourceReportRequest = zget_ResourceReportRequest(o);
468 case Z_APDU_resourceReportResponse:
469 r->u.resourceReportResponse = zget_ResourceReportResponse(o);
471 case Z_APDU_sortRequest:
472 r->u.sortRequest = zget_SortRequest(o);
474 case Z_APDU_sortResponse:
475 r->u.sortResponse = zget_SortResponse(o);
477 case Z_APDU_extendedServicesRequest:
478 r->u.extendedServicesRequest = zget_ExtendedServicesRequest(o);
480 case Z_APDU_extendedServicesResponse:
481 r->u.extendedServicesResponse = zget_ExtendedServicesResponse(o);
483 case Z_APDU_duplicateDetectionRequest:
484 r->u.duplicateDetectionRequest = zget_DuplicateDetectionRequest(o);
486 case Z_APDU_duplicateDetectionResponse:
487 r->u.duplicateDetectionResponse = zget_DuplicateDetectionResponse(o);
495 Z_DefaultDiagFormat *zget_DefaultDiagFormat(ODR o, int error,
498 Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
499 odr_malloc (o, sizeof(*dr));
501 dr->diagnosticSetId = odr_oiddup(o, yaz_oid_diagset_bib_1);
502 dr->condition = odr_intdup(o, error);
503 dr->which = Z_DefaultDiagFormat_v2Addinfo;
504 dr->u.v2Addinfo = odr_strdup (o, addinfo ? addinfo : "");
508 Z_DiagRec *zget_DiagRec(ODR o, int error, const char *addinfo)
510 Z_DiagRec *dr = (Z_DiagRec*) odr_malloc(o, sizeof(*dr));
511 dr->which = Z_DiagRec_defaultFormat;
512 dr->u.defaultFormat = zget_DefaultDiagFormat(o, error, addinfo);
516 Z_DiagRecs *zget_DiagRecs(ODR o, int error, const char *addinfo)
518 Z_DiagRecs *drecs = (Z_DiagRecs*) odr_malloc(o, sizeof(*drecs));
519 Z_DiagRec **dr = (Z_DiagRec**) odr_malloc(o, sizeof(**dr));
520 drecs->diagRecs = dr;
521 dr[0] = zget_DiagRec(o, error, addinfo);
522 drecs->num_diagRecs = 1;
526 Z_NamePlusRecord *zget_surrogateDiagRec(ODR o, const char *dbname,
527 int error, const char *addinfo)
529 Z_NamePlusRecord *rec = (Z_NamePlusRecord *) odr_malloc (o, sizeof(*rec));
530 Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (o, sizeof(*drec));
533 rec->databaseName = odr_strdup(o, dbname);
535 rec->databaseName = 0;
536 rec->which = Z_NamePlusRecord_surrogateDiagnostic;
537 rec->u.surrogateDiagnostic = drec;
538 drec->which = Z_DiagRec_defaultFormat;
539 drec->u.defaultFormat = zget_DefaultDiagFormat(o, error, addinfo);
543 Z_External *zget_init_diagnostics(ODR odr, int error, const char *addinfo)
546 Z_OtherInformation *u;
547 Z_OtherInformationUnit *l;
548 Z_DiagnosticFormat *d;
549 Z_DiagnosticFormat_s *e;
551 x = (Z_External*) odr_malloc(odr, sizeof *x);
553 x->indirect_reference = 0;
554 x->direct_reference = odr_oiddup(odr, yaz_oid_userinfo_userinfo_1);
555 x->which = Z_External_userInfo1;
557 u = (Z_OtherInformation *) odr_malloc(odr, sizeof *u);
560 u->list = (Z_OtherInformationUnit**) odr_malloc(odr, sizeof *u->list);
561 u->list[0] = (Z_OtherInformationUnit*) odr_malloc(odr, sizeof *u->list[0]);
564 l->which = Z_OtherInfo_externallyDefinedInfo;
566 x2 = (Z_External*) odr_malloc(odr, sizeof *x);
567 l->information.externallyDefinedInfo = x2;
569 x2->indirect_reference = 0;
570 x2->direct_reference = odr_oiddup(odr, yaz_oid_diagset_diag_1);
571 x2->which = Z_External_diag1;
573 d = (Z_DiagnosticFormat*) odr_malloc(odr, sizeof *d);
576 d->elements = (Z_DiagnosticFormat_s**) odr_malloc (odr, sizeof *d->elements);
577 d->elements[0] = (Z_DiagnosticFormat_s*) odr_malloc (odr, sizeof *d->elements[0]);
580 e->which = Z_DiagnosticFormat_s_defaultDiagRec;
581 e->u.defaultDiagRec = zget_DefaultDiagFormat(odr, error, addinfo);
586 Z_External *zget_init_diagnostics_octet(ODR odr, int error,
590 Z_OtherInformation *u;
591 Z_OtherInformationUnit *l;
592 Z_DiagnosticFormat *d;
593 Z_DiagnosticFormat_s *e;
598 u = (Z_OtherInformation *) odr_malloc(odr, sizeof *u);
600 u->list = (Z_OtherInformationUnit**) odr_malloc(odr, sizeof *u->list);
601 u->list[0] = (Z_OtherInformationUnit*) odr_malloc(odr, sizeof *u->list[0]);
604 l->which = Z_OtherInfo_externallyDefinedInfo;
606 x2 = (Z_External*) odr_malloc(odr, sizeof *x);
607 l->information.externallyDefinedInfo = x2;
609 x2->indirect_reference = 0;
611 x2->direct_reference = odr_oiddup(odr, yaz_oid_diagset_diag_1);
612 x2->which = Z_External_diag1;
614 d = (Z_DiagnosticFormat*) odr_malloc(odr, sizeof *d);
617 d->elements = (Z_DiagnosticFormat_s**) odr_malloc (odr, sizeof *d->elements);
618 d->elements[0] = (Z_DiagnosticFormat_s*) odr_malloc (odr, sizeof *d->elements[0]);
621 e->which = Z_DiagnosticFormat_s_defaultDiagRec;
622 e->u.defaultDiagRec = zget_DefaultDiagFormat(odr, error, addinfo);
625 encode = odr_createmem(ODR_ENCODE);
627 z_OtherInformation(encode, &u, 0, 0);
629 octet_buf = odr_getbuf(encode, &octet_len, 0);
631 x = (Z_External*) odr_malloc(odr, sizeof *x);
633 x->indirect_reference = 0;
634 x->direct_reference = odr_oiddup(odr, yaz_oid_userinfo_userinfo_1);
635 x->which = Z_External_octet;
636 x->u.octet_aligned = (Odr_oct *) odr_malloc(odr, sizeof(Odr_oct));
637 x->u.octet_aligned->buf = (unsigned char *) odr_malloc(odr, octet_len);
638 memcpy(x->u.octet_aligned->buf, octet_buf, octet_len);
639 x->u.octet_aligned->len = octet_len;
649 * indent-tabs-mode: nil
651 * vim: shiftwidth=4 tabstop=8 expandtab