2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: zget.c,v 1.10 2005-01-27 09:06:12 adam Exp $
9 * \brief Implements Z39.50 package creator utilities
12 #include <yaz/proto.h>
14 Z_InitRequest *zget_InitRequest(ODR o)
16 Z_InitRequest *r = (Z_InitRequest *)odr_malloc(o, sizeof(*r));
19 r->options = (Odr_bitmask *)odr_malloc(o, sizeof(*r->options));
20 ODR_MASK_ZERO(r->options);
21 r->protocolVersion = (Odr_bitmask *)
22 odr_malloc(o, sizeof(*r->protocolVersion));
24 ODR_MASK_SET(r->options, Z_Options_search);
25 ODR_MASK_SET(r->options, Z_Options_present);
27 ODR_MASK_ZERO(r->protocolVersion);
29 ODR_MASK_SET(r->protocolVersion, Z_ProtocolVersion_1);
30 ODR_MASK_SET(r->protocolVersion, Z_ProtocolVersion_2);
32 r->preferredMessageSize = odr_intdup(o, 1024*1024);
33 r->maximumRecordSize = odr_intdup(o, 1024*1024);
34 r->idAuthentication = 0;
35 r->implementationId = "81";
36 r->implementationName = "YAZ";
37 r->implementationVersion = YAZ_VERSION
45 r->userInformationField = 0;
50 Z_InitResponse *zget_InitResponse(ODR o)
52 Z_InitResponse *r = (Z_InitResponse *)odr_malloc(o, sizeof(*r));
55 r->options = (Odr_bitmask *)odr_malloc(o, sizeof(*r->options));
56 ODR_MASK_ZERO(r->options);
57 r->protocolVersion = (Odr_bitmask *)odr_malloc(o, sizeof(*r->protocolVersion));
58 ODR_MASK_ZERO(r->protocolVersion);
59 r->preferredMessageSize = odr_intdup(o, 30*1024);
60 r->maximumRecordSize = odr_intdup(o, 30*1024);
61 r->result = odr_intdup(o, 1);
62 r->implementationId = "81";
63 r->implementationName = "YAZ";
64 r->implementationVersion = YAZ_VERSION
72 r->userInformationField = 0;
77 Z_SearchRequest *zget_SearchRequest(ODR o)
79 Z_SearchRequest *r = (Z_SearchRequest *)odr_malloc(o, sizeof(*r));
82 r->smallSetUpperBound = odr_intdup(o, 0);
83 r->largeSetLowerBound = odr_intdup(o, 1);
84 r->mediumSetPresentNumber = odr_intdup(o, 0);
85 r->replaceIndicator = odr_intdup(o, 1);
86 r->resultSetName = "default";
87 r->num_databaseNames = 0;
89 r->smallSetElementSetNames = 0;
90 r->mediumSetElementSetNames = 0;
91 r->preferredRecordSyntax = 0;
93 r->additionalSearchInfo = 0;
98 Z_SearchResponse *zget_SearchResponse(ODR o)
100 Z_SearchResponse *r = (Z_SearchResponse *)odr_malloc(o, sizeof(*r));
103 r->resultCount = odr_intdup(o, 0);
104 r->numberOfRecordsReturned = odr_intdup(o, 0);
105 r->nextResultSetPosition = odr_intdup(o, 0);
106 r->searchStatus = odr_intdup(o, 1);
107 r->resultSetStatus = 0;
108 r->presentStatus = 0;
110 r->additionalSearchInfo = 0;
115 Z_PresentRequest *zget_PresentRequest(ODR o)
117 Z_PresentRequest *r = (Z_PresentRequest *)odr_malloc(o, sizeof(*r));
120 r->resultSetId = "default";
121 r->resultSetStartPoint = odr_intdup(o, 1);
122 r->numberOfRecordsRequested = odr_intdup(o, 10);
124 r->additionalRanges = 0;
125 r->recordComposition = 0;
126 r->preferredRecordSyntax = 0;
127 r->maxSegmentCount = 0;
128 r->maxRecordSize = 0;
129 r->maxSegmentSize = 0;
134 Z_PresentResponse *zget_PresentResponse(ODR o)
136 Z_PresentResponse *r = (Z_PresentResponse *)odr_malloc(o, sizeof(*r));
139 r->numberOfRecordsReturned = odr_intdup(o, 0);
140 r->nextResultSetPosition = odr_intdup(o, 0);
141 r->presentStatus = odr_intdup(o, Z_PresentStatus_success);
147 Z_DeleteResultSetRequest *zget_DeleteResultSetRequest(ODR o)
149 Z_DeleteResultSetRequest *r = (Z_DeleteResultSetRequest *)
150 odr_malloc(o, sizeof(*r));
153 r->deleteFunction = odr_intdup(o, Z_DeleteResultSetRequest_list);
154 r->num_resultSetList = 0;
155 r->resultSetList = 0;
160 Z_DeleteResultSetResponse *zget_DeleteResultSetResponse(ODR o)
162 Z_DeleteResultSetResponse *r = (Z_DeleteResultSetResponse *)
163 odr_malloc(o, sizeof(*r));
166 r->deleteOperationStatus = odr_intdup(o, Z_DeleteStatus_success);
167 r->deleteListStatuses = 0;
168 r->numberNotDeleted = 0;
170 r->deleteMessage = 0;
175 Z_ScanRequest *zget_ScanRequest(ODR o)
177 Z_ScanRequest *r = (Z_ScanRequest *)odr_malloc(o, sizeof(*r));
180 r->num_databaseNames = 0;
181 r->databaseNames = 0;
183 r->termListAndStartPoint = 0;
185 r->numberOfTermsRequested = odr_intdup(o, 20);
186 r->preferredPositionInResponse = 0;
191 Z_ScanResponse *zget_ScanResponse(ODR o)
193 Z_ScanResponse *r = (Z_ScanResponse *)odr_malloc(o, sizeof(*r));
197 r->scanStatus = odr_intdup(o, Z_Scan_success);
198 r->numberOfEntriesReturned = odr_intdup(o, 0);
199 r->positionOfTerm =0;
206 Z_TriggerResourceControlRequest *zget_TriggerResourceControlRequest(ODR o)
208 Z_TriggerResourceControlRequest *r = (Z_TriggerResourceControlRequest *)
209 odr_malloc(o, sizeof(*r));
212 r->requestedAction = odr_intdup(o, Z_TriggerResourceControlRequest_resourceReport);
213 r->prefResourceReportFormat = 0;
214 r->resultSetWanted = 0;
219 Z_ResourceControlRequest *zget_ResourceControlRequest(ODR o)
221 Z_ResourceControlRequest *r = (Z_ResourceControlRequest *)
222 odr_malloc(o, sizeof(*r));
225 r->suspendedFlag = 0;
226 r->resourceReport = 0;
227 r->partialResultsAvailable = 0;
228 r->responseRequired = odr_intdup(o, 0);
229 r->triggeredRequestFlag = 0;
234 Z_ResourceControlResponse *zget_ResourceControlResponse(ODR o)
236 Z_ResourceControlResponse *r = (Z_ResourceControlResponse *)
237 odr_malloc(o, sizeof(*r));
240 r->continueFlag = odr_intdup(o, 1);
241 r->resultSetWanted = 0;
246 Z_AccessControlRequest *zget_AccessControlRequest(ODR o)
248 Z_AccessControlRequest *r = (Z_AccessControlRequest *)
249 odr_malloc(o, sizeof(*r));
252 r->which = Z_AccessControlRequest_simpleForm;
258 Z_AccessControlResponse *zget_AccessControlResponse(ODR o)
260 Z_AccessControlResponse *r = (Z_AccessControlResponse *)
261 odr_malloc(o, sizeof(*r));
264 r->which = Z_AccessControlResponse_simpleForm;
271 Z_Segment *zget_Segment(ODR o)
273 Z_Segment *r = (Z_Segment *)odr_malloc(o, sizeof(*r));
276 r->numberOfRecordsReturned = odr_intdup(o, 0);
277 r->num_segmentRecords = 0;
278 r->segmentRecords = (Z_NamePlusRecord **) odr_nullval();
283 Z_Close *zget_Close(ODR o)
285 Z_Close *r = (Z_Close *)odr_malloc(o, sizeof(*r));
288 r->closeReason = odr_intdup(o, Z_Close_finished);
289 r->diagnosticInformation = 0;
290 r->resourceReportFormat = 0;
291 r->resourceReport = 0;
296 Z_ResourceReportRequest *zget_ResourceReportRequest(ODR o)
298 Z_ResourceReportRequest *r = (Z_ResourceReportRequest *)
299 odr_malloc(o, sizeof(*r));
303 r->prefResourceReportFormat = 0;
308 Z_ResourceReportResponse *zget_ResourceReportResponse(ODR o)
310 Z_ResourceReportResponse *r = (Z_ResourceReportResponse *)
311 odr_malloc(o, sizeof(*r));
314 r->resourceReportStatus = odr_intdup(o, Z_ResourceReportResponse_success);
315 r->resourceReport = 0;
320 Z_SortRequest *zget_SortRequest(ODR o)
322 Z_SortRequest *r = (Z_SortRequest *)odr_malloc(o, sizeof(*r));
325 r->inputResultSetNames = 0;
326 r->sortedResultSetName = 0;
332 Z_SortResponse *zget_SortResponse(ODR o)
334 Z_SortResponse *r = (Z_SortResponse *)odr_malloc(o, sizeof(*r));
337 r->sortStatus = odr_intdup(o, Z_SortResponse_success);
338 r->resultSetStatus = odr_intdup(o, Z_SortResponse_empty);
345 Z_ExtendedServicesRequest *zget_ExtendedServicesRequest(ODR o)
347 Z_ExtendedServicesRequest *r = (Z_ExtendedServicesRequest *)
348 odr_malloc(o, sizeof(*r));
351 r->function = odr_intdup(o, Z_ExtendedServicesRequest_create);
355 r->retentionTime = 0;
358 r->taskSpecificParameters = 0;
359 r->waitAction = odr_intdup(o, Z_ExtendedServicesRequest_waitIfPossible);
365 Z_ExtendedServicesResponse *zget_ExtendedServicesResponse(ODR o)
367 Z_ExtendedServicesResponse *r = (Z_ExtendedServicesResponse *)
368 odr_malloc(o, sizeof(*r));
371 r->operationStatus = odr_intdup(o, Z_ExtendedServicesResponse_done);
372 r->num_diagnostics = 0;
379 Z_DuplicateDetectionRequest *zget_DuplicateDetectionRequest(ODR o)
381 Z_DuplicateDetectionRequest *r = (Z_DuplicateDetectionRequest *)
382 odr_malloc(o, sizeof(*r));
385 r->num_inputResultSetIds = 0;
386 r->inputResultSetIds = 0;
387 r->outputResultSetName = 0;
388 r->applicablePortionOfRecord = 0;
389 r->num_duplicateDetectionCriteria = 0;
390 r->duplicateDetectionCriteria = 0;
392 r->num_retentionCriteria = 0;
393 r->retentionCriteria = 0;
394 r->num_sortCriteria = 0;
400 Z_DuplicateDetectionResponse *zget_DuplicateDetectionResponse(ODR o)
402 Z_DuplicateDetectionResponse *r = (Z_DuplicateDetectionResponse *)
403 odr_malloc(o, sizeof(*r));
406 r->status = odr_intdup(o, Z_DuplicateDetectionResponse_success);
407 r->resultSetCount = 0;
408 r->num_diagnostics = 0;
414 Z_APDU *zget_APDU(ODR o, int which)
416 Z_APDU *r = (Z_APDU *)odr_malloc(o, sizeof(*r));
418 switch (r->which = which)
420 case Z_APDU_initRequest:
421 r->u.initRequest = zget_InitRequest(o);
423 case Z_APDU_initResponse:
424 r->u.initResponse = zget_InitResponse(o);
426 case Z_APDU_searchRequest:
427 r->u.searchRequest = zget_SearchRequest(o);
429 case Z_APDU_searchResponse:
430 r->u.searchResponse = zget_SearchResponse(o);
432 case Z_APDU_presentRequest:
433 r->u.presentRequest = zget_PresentRequest(o);
435 case Z_APDU_presentResponse:
436 r->u.presentResponse = zget_PresentResponse(o);
438 case Z_APDU_deleteResultSetRequest:
439 r->u.deleteResultSetRequest = zget_DeleteResultSetRequest(o);
441 case Z_APDU_deleteResultSetResponse:
442 r->u.deleteResultSetResponse = zget_DeleteResultSetResponse(o);
444 case Z_APDU_scanRequest:
445 r->u.scanRequest = zget_ScanRequest(o);
447 case Z_APDU_scanResponse:
448 r->u.scanResponse = zget_ScanResponse(o);
450 case Z_APDU_triggerResourceControlRequest:
451 r->u.triggerResourceControlRequest =
452 zget_TriggerResourceControlRequest(o);
454 case Z_APDU_resourceControlRequest:
455 r->u.resourceControlRequest = zget_ResourceControlRequest(o);
457 case Z_APDU_resourceControlResponse:
458 r->u.resourceControlResponse = zget_ResourceControlResponse(o);
460 case Z_APDU_segmentRequest:
461 r->u.segmentRequest = zget_Segment(o);
464 r->u.close = zget_Close(o);
466 case Z_APDU_accessControlRequest:
467 r->u.accessControlRequest = zget_AccessControlRequest(o);
469 case Z_APDU_accessControlResponse:
470 r->u.accessControlResponse = zget_AccessControlResponse(o);
472 case Z_APDU_resourceReportRequest:
473 r->u.resourceReportRequest = zget_ResourceReportRequest(o);
475 case Z_APDU_resourceReportResponse:
476 r->u.resourceReportResponse = zget_ResourceReportResponse(o);
478 case Z_APDU_sortRequest:
479 r->u.sortRequest = zget_SortRequest(o);
481 case Z_APDU_sortResponse:
482 r->u.sortResponse = zget_SortResponse(o);
484 case Z_APDU_extendedServicesRequest:
485 r->u.extendedServicesRequest = zget_ExtendedServicesRequest(o);
487 case Z_APDU_extendedServicesResponse:
488 r->u.extendedServicesResponse = zget_ExtendedServicesResponse(o);
490 case Z_APDU_duplicateDetectionRequest:
491 r->u.duplicateDetectionRequest = zget_DuplicateDetectionRequest(o);
493 case Z_APDU_duplicateDetectionResponse:
494 r->u.duplicateDetectionResponse = zget_DuplicateDetectionResponse(o);
502 Z_DefaultDiagFormat *zget_DefaultDiagFormat(ODR o, int error,
505 Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
506 odr_malloc (o, sizeof(*dr));
508 dr->diagnosticSetId = yaz_oidval_to_z3950oid (o, CLASS_DIAGSET, VAL_BIB1);
509 dr->condition = odr_intdup(o, error);
510 dr->which = Z_DefaultDiagFormat_v2Addinfo;
511 dr->u.v2Addinfo = odr_strdup (o, addinfo ? addinfo : "");
515 Z_DiagRec *zget_DiagRec(ODR o, int error, const char *addinfo)
517 Z_DiagRec *dr = (Z_DiagRec*) odr_malloc(o, sizeof(*dr));
518 dr->which = Z_DiagRec_defaultFormat;
519 dr->u.defaultFormat = zget_DefaultDiagFormat(o, error, addinfo);
523 Z_DiagRecs *zget_DiagRecs(ODR o, int error, const char *addinfo)
525 Z_DiagRecs *drecs = (Z_DiagRecs*) odr_malloc(o, sizeof(*drecs));
526 Z_DiagRec **dr = (Z_DiagRec**) odr_malloc(o, sizeof(**dr));
527 drecs->diagRecs = dr;
528 dr[0] = zget_DiagRec(o, error, addinfo);
529 drecs->num_diagRecs = 1;
533 Z_NamePlusRecord *zget_surrogateDiagRec(ODR o, const char *dbname,
534 int error, const char *addinfo)
536 Z_NamePlusRecord *rec = (Z_NamePlusRecord *) odr_malloc (o, sizeof(*rec));
537 Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (o, sizeof(*drec));
540 rec->databaseName = odr_strdup(o, dbname);
542 rec->databaseName = 0;
543 rec->which = Z_NamePlusRecord_surrogateDiagnostic;
544 rec->u.surrogateDiagnostic = drec;
545 drec->which = Z_DiagRec_defaultFormat;
546 drec->u.defaultFormat = zget_DefaultDiagFormat(o, error, addinfo);
550 Z_External *zget_init_diagnostics(ODR odr, int error, const char *addinfo)
554 Z_OtherInformation *u;
555 Z_OtherInformationUnit *l;
556 Z_DiagnosticFormat *d;
557 Z_DiagnosticFormat_s *e;
559 x = (Z_External*) odr_malloc(odr, sizeof *x);
561 x->indirect_reference = 0;
562 oid.proto = PROTO_Z3950;
563 oid.oclass = CLASS_USERINFO;
564 oid.value = VAL_USERINFO1;
565 x->direct_reference = odr_oiddup(odr, oid_getoidbyent(&oid));
566 x->which = Z_External_userInfo1;
568 u = odr_malloc(odr, sizeof *u);
571 u->list = (Z_OtherInformationUnit**) odr_malloc(odr, sizeof *u->list);
572 u->list[0] = (Z_OtherInformationUnit*) odr_malloc(odr, sizeof *u->list[0]);
575 l->which = Z_OtherInfo_externallyDefinedInfo;
577 x2 = (Z_External*) odr_malloc(odr, sizeof *x);
578 l->information.externallyDefinedInfo = x2;
580 x2->indirect_reference = 0;
581 oid.oclass = CLASS_DIAGSET;
582 oid.value = VAL_DIAG1;
583 x2->direct_reference = odr_oiddup(odr, oid_getoidbyent(&oid));
584 x2->which = Z_External_diag1;
586 d = (Z_DiagnosticFormat*) odr_malloc(odr, sizeof *d);
589 d->elements = (Z_DiagnosticFormat_s**) odr_malloc (odr, sizeof *d->elements);
590 d->elements[0] = (Z_DiagnosticFormat_s*) odr_malloc (odr, sizeof *d->elements[0]);
593 e->which = Z_DiagnosticFormat_s_defaultDiagRec;
594 e->u.defaultDiagRec = zget_DefaultDiagFormat(odr, error, addinfo);
599 Z_External *zget_init_diagnostics_octet(ODR odr, int error,
604 Z_OtherInformation *u;
605 Z_OtherInformationUnit *l;
606 Z_DiagnosticFormat *d;
607 Z_DiagnosticFormat_s *e;
612 u = odr_malloc(odr, sizeof *u);
614 u->list = (Z_OtherInformationUnit**) odr_malloc(odr, sizeof *u->list);
615 u->list[0] = (Z_OtherInformationUnit*) odr_malloc(odr, sizeof *u->list[0]);
618 l->which = Z_OtherInfo_externallyDefinedInfo;
620 x2 = (Z_External*) odr_malloc(odr, sizeof *x);
621 l->information.externallyDefinedInfo = x2;
623 x2->indirect_reference = 0;
624 oid.oclass = CLASS_DIAGSET;
625 oid.proto = PROTO_Z3950;
626 oid.value = VAL_DIAG1;
627 x2->direct_reference = odr_oiddup(odr, oid_getoidbyent(&oid));
628 x2->which = Z_External_diag1;
630 d = (Z_DiagnosticFormat*) odr_malloc(odr, sizeof *d);
633 d->elements = (Z_DiagnosticFormat_s**) odr_malloc (odr, sizeof *d->elements);
634 d->elements[0] = (Z_DiagnosticFormat_s*) odr_malloc (odr, sizeof *d->elements[0]);
637 e->which = Z_DiagnosticFormat_s_defaultDiagRec;
638 e->u.defaultDiagRec = zget_DefaultDiagFormat(odr, error, addinfo);
641 encode = odr_createmem(ODR_ENCODE);
643 z_OtherInformation(encode, &u, 0, 0);
645 octet_buf = odr_getbuf(encode, &octet_len, 0);
647 x = (Z_External*) odr_malloc(odr, sizeof *x);
649 x->indirect_reference = 0;
650 oid.proto = PROTO_Z3950;
651 oid.oclass = CLASS_USERINFO;
652 oid.value = VAL_USERINFO1;
653 x->direct_reference = odr_oiddup(odr, oid_getoidbyent(&oid));
655 x->which = Z_External_octet;
656 x->u.octet_aligned = (Odr_oct *) odr_malloc(odr, sizeof(Odr_oct));
657 x->u.octet_aligned->buf = odr_malloc(odr, octet_len);
658 memcpy(x->u.octet_aligned->buf, octet_buf, octet_len);
659 x->u.octet_aligned->len = octet_len;