2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.16 1995-03-30 10:26:43 quinn
10 * Revision 1.15 1995/03/30 09:08:39 quinn
11 * Added Resource control protocol
13 * Revision 1.14 1995/03/29 08:06:13 quinn
14 * Added a few v3 elements
16 * Revision 1.13 1995/03/20 11:26:52 quinn
17 * *** empty log message ***
19 * Revision 1.12 1995/03/20 09:45:09 quinn
22 * Revision 1.11 1995/03/17 10:17:25 quinn
23 * Added memory management.
25 * Revision 1.10 1995/03/15 11:17:40 quinn
26 * Fixed some return-checks from choice.. need better ay to handle those..
28 * Revision 1.9 1995/03/15 08:37:06 quinn
29 * Fixed protocol bugs.
31 * Revision 1.8 1995/03/14 16:59:24 quinn
32 * Fixed OPTIONAL flag in attributeelement
34 * Revision 1.7 1995/03/07 16:29:33 quinn
35 * Added authentication stuff.
37 * Revision 1.6 1995/03/01 14:46:03 quinn
38 * Fixed protocol bug in 8777query.
40 * Revision 1.5 1995/02/14 11:54:22 quinn
43 * Revision 1.4 1995/02/10 15:54:30 quinn
46 * Revision 1.3 1995/02/09 15:51:39 quinn
49 * Revision 1.2 1995/02/06 21:26:07 quinn
50 * Repaired this evening's damages..
52 * Revision 1.1 1995/02/06 16:44:47 quinn
53 * First hack at Z/SR protocol
61 /* ---------------------- GLOBAL DEFS ------------------- */
63 int z_ReferenceId(ODR o, Z_ReferenceId **p, int opt)
65 return odr_implicit(o, odr_octetstring, (Odr_oct**) p, ODR_CONTEXT, 2, opt);
68 int z_DatabaseName(ODR o, Z_DatabaseName **p, int opt)
70 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 105,
74 int z_ResultSetId(ODR o, char **p, int opt)
76 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 31,
80 int z_UserInformationField(ODR o, Z_UserInformationField **p, int opt)
82 return odr_explicit(o, odr_external, (Odr_external **)p, ODR_CONTEXT,
86 /* ---------------------- INITIALIZE SERVICE ------------------- */
88 int z_NSRAuthentication(ODR o, Z_NSRAuthentication **p, int opt)
90 if (!odr_sequence_begin(o, p, sizeof(**p)))
93 odr_visiblestring(o, &(*p)->user, 0) &&
94 odr_visiblestring(o, &(*p)->password, 0) &&
95 odr_visiblestring(o, &(*p)->account, 0) &&
99 int z_IdPass(ODR o, Z_IdPass **p, int opt)
101 if (!odr_sequence_begin(o, p, sizeof(**p)))
104 odr_implicit(o, odr_visiblestring, &(*p)->groupId, ODR_CONTEXT, 0, 0) &&
105 odr_implicit(o, odr_visiblestring, &(*p)->userId, ODR_CONTEXT, 1, 0) &&
106 odr_implicit(o, odr_visiblestring, &(*p)->password, ODR_CONTEXT, 2,
111 int z_StrAuthentication(ODR o, char **p, int opt)
113 return odr_visiblestring(o, p, opt);
116 int z_IdAuthentication(ODR o, Z_IdAuthentication **p, int opt)
118 static Odr_arm arm[] =
120 {-1, -1, -1, Z_IdAuthentication_open, z_StrAuthentication},
121 {-1, -1, -1, Z_IdAuthentication_idPass, z_NSRAuthentication},
122 {-1, -1, -1, Z_IdAuthentication_anonymous, odr_null},
123 {-1, -1, -1, Z_IdAuthentication_other, odr_external},
127 if (o->direction == ODR_DECODE)
128 *p = odr_malloc(o, sizeof(**p));
130 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
133 return opt && !o->error;
136 int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
140 if (!odr_sequence_begin(o, p, sizeof(**p)))
144 z_ReferenceId(o, &pp->referenceId, 1) &&
145 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
147 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
148 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
150 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
152 odr_explicit(o, z_IdAuthentication, &pp->idAuthentication, ODR_CONTEXT,
154 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
156 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
158 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
159 ODR_CONTEXT, 112, 1) &&
160 z_UserInformationField(o, &pp->userInformationField, 1) &&
164 int z_InitResponse(ODR o, Z_InitResponse **p, int opt)
168 if (!odr_sequence_begin(o, p, sizeof(**p)))
172 z_ReferenceId(o, &pp->referenceId, 1) &&
173 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
175 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
176 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
178 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
180 odr_implicit(o, odr_bool, &pp->result, ODR_CONTEXT, 12, 0) &&
181 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
183 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
185 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
186 ODR_CONTEXT, 112, 1) &&
187 z_UserInformationField(o, &pp->userInformationField, 1) &&
191 /* ------------------ RESOURCE CONTROL ----------------*/
193 int z_TriggerResourceControlRequest(ODR o, Z_TriggerResourceControlRequest **p,
196 if (!odr_sequence_begin(o, p, sizeof(**p)))
199 z_ReferenceId(o, &(*p)->referenceId, 1) &&
200 odr_implicit(o, odr_integer, &(*p)->requestedAction, ODR_CONTEXT,
202 odr_implicit(o, odr_oid, &(*p)->prefResourceReportFormat,
203 ODR_CONTEXT, 47, 1) &&
204 odr_implicit(o, odr_bool, &(*p)->resultSetWanted, ODR_CONTEXT,
209 int z_ResourceControlRequest(ODR o, Z_ResourceControlRequest **p, int opt)
211 if (!odr_sequence_begin(o, p, sizeof(**p)))
214 z_ReferenceId(o, &(*p)->referenceId, 1) &&
215 odr_implicit(o, odr_bool, &(*p)->suspendedFlag, ODR_CONTEXT, 39, 1)&&
216 odr_explicit(o, odr_external, &(*p)->resourceReport, ODR_CONTEXT,
218 odr_implicit(o, odr_integer, &(*p)->partialResultsAvailable,
219 ODR_CONTEXT, 41, 1) &&
220 odr_implicit(o, odr_bool, &(*p)->responseRequired, ODR_CONTEXT,
222 odr_implicit(o, odr_bool, &(*p)->triggeredRequestFlag,
223 ODR_CONTEXT, 43, 1) &&
227 int z_ResourceControlResponse(ODR o, Z_ResourceControlResponse **p, int opt)
229 if (!odr_sequence_begin(o, p, sizeof(**p)))
232 z_ReferenceId(o, &(*p)->referenceId, 1) &&
233 odr_implicit(o, odr_bool, &(*p)->continueFlag, ODR_CONTEXT, 44, 0) &&
234 odr_implicit(o, odr_bool, &(*p)->resultSetWanted, ODR_CONTEXT,
239 /* ------------------------ SEARCH SERVICE ----------------------- */
241 int z_ElementSetName(ODR o, char **p, int opt)
243 return odr_implicit(o, odr_visiblestring, (char**) p, ODR_CONTEXT, 103,
247 int z_PreferredRecordSyntax(ODR o, Z_PreferredRecordSyntax **p, int opt)
249 return odr_implicit(o, odr_oid, (Odr_oid**) p, ODR_CONTEXT, 104, opt);
252 int z_DatabaseSpecificUnit(ODR o, Z_DatabaseSpecificUnit **p, int opt)
254 if (!odr_sequence_begin(o, p, sizeof(**p)))
257 z_DatabaseName(o, &(*p)->databaseName, 0) &&
258 z_ElementSetName(o, &(*p)->elementSetName, 0) &&
262 int z_DatabaseSpecific(ODR o, Z_DatabaseSpecific **p, int opt)
264 if (o->direction == ODR_DECODE)
265 *p = odr_malloc(o, sizeof(**p));
269 odr_implicit_settag(o, ODR_CONTEXT, 1);
270 if (odr_sequence_of(o, z_DatabaseSpecificUnit, &(*p)->elements,
271 &(*p)->num_elements))
277 int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
279 static Odr_arm arm[] =
281 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_ElementSetNames_generic,
283 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementSetNames_databaseSpecific,
288 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 19))
291 if (o->direction == ODR_DECODE)
292 *p = odr_malloc(o, sizeof(**p));
294 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
295 odr_constructed_end(o))
301 /* ----------------------- RPN QUERY -----------------------*/
303 int z_AttributeElement(ODR o, Z_AttributeElement **p, int opt)
305 if (!odr_sequence_begin(o, p, sizeof(**p)))
308 odr_implicit(o, odr_integer, &(*p)->attributeType, ODR_CONTEXT,
310 odr_implicit(o, odr_integer, &(*p)->attributeValue, ODR_CONTEXT,
317 int z_Term(ODR o, Z_Term **p, int opt)
319 static Odr_arm arm[] =
321 {ODR_IMPLICIT, ODR_CONTEXT, 45, Z_Term_general, odr_octetstring},
322 {ODR_IMPLICIT, ODR_CONTEXT, 215, Z_Term_numeric, odr_integer},
323 {ODR_IMPLICIT, ODR_CONTEXT, 216, Z_Term_characterString,
325 {ODR_IMPLICIT, ODR_CONTEXT, 217, Z_Term_oid, odr_oid},
326 {ODR_IMPLICIT, ODR_CONTEXT, 218, Z_Term_dateTime, odr_cstring},
327 {ODR_IMPLICIT, ODR_CONTEXT, 219, Z_Term_external, odr_external},
328 /* add intUnit here */
329 {ODR_IMPLICIT, ODR_CONTEXT, 221, Z_Term_null, odr_null},
333 if (o->direction ==ODR_DECODE)
334 *p = odr_malloc(o, sizeof(**p));
337 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
340 return opt && !o->error;
345 int z_AttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
347 if (!(odr_implicit_settag(o, ODR_CONTEXT, 102) &&
348 odr_sequence_begin(o, p, sizeof(**p))))
351 odr_implicit_settag(o, ODR_CONTEXT, 44) &&
352 odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
353 &(*p)->num_attributes) &&
355 z_Term(o, &(*p)->term, 0) &&
357 odr_implicit(o, odr_octetstring, &(*p)->term, ODR_CONTEXT, 45, 0) &&
362 int z_Operator(ODR o, Z_Operator **p, int opt)
364 static Odr_arm arm[] =
366 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_Operator_and, odr_null},
367 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Operator_or, odr_null},
368 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Operator_and_not, odr_null},
373 if (!*p && o->direction != ODR_DECODE)
375 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 46))
377 if (o->direction == ODR_DECODE)
378 *p = odr_malloc(o, sizeof(**p));
380 (*p)->u.and = &dummy;
382 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
383 odr_constructed_end(o))
386 return opt && !o->error;
389 int z_Operand(ODR o, Z_Operand **p, int opt)
391 static Odr_arm arm[] =
393 {-1, -1, -1, Z_Operand_APT, z_AttributesPlusTerm},
394 {-1, -1, -1, Z_Operand_resultSetId, z_ResultSetId},
398 if (o->direction ==ODR_DECODE)
399 *p = odr_malloc(o, sizeof(**p));
402 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
405 return opt && !o->error;
408 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt);
410 int z_Complex(ODR o, Z_Complex **p, int opt)
412 if (!odr_sequence_begin(o, p, sizeof(**p)))
415 z_RPNStructure(o, &(*p)->s1, 0) &&
416 z_RPNStructure(o, &(*p)->s2, 0) &&
417 z_Operator(o, &(*p)->operator, 0) &&
421 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt)
423 static Odr_arm arm[] =
425 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand},
426 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_RPNStructure_complex, z_Complex},
430 if (o->direction == ODR_DECODE)
431 *p = odr_malloc(o, sizeof(**p));
434 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
437 return opt && !o->error;
440 int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
442 if (!odr_sequence_begin(o, p, sizeof(**p)))
445 odr_oid(o, &(*p)->attributeSetId, 0) &&
446 z_RPNStructure(o, &(*p)->RPNStructure, 0) &&
450 /* -----------------------END RPN QUERY ----------------------- */
452 int z_Query(ODR o, Z_Query **p, int opt)
454 static Odr_arm arm[] =
456 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Query_type_1, z_RPNQuery},
457 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_octetstring},
461 if (o->direction == ODR_DECODE)
462 *p = odr_malloc(o, sizeof(**p));
465 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
468 return opt && !o->error;
471 int z_SearchRequest(ODR o, Z_SearchRequest **p, int opt)
475 if (!odr_sequence_begin(o, p, sizeof(**p)))
479 z_ReferenceId(o, &pp->referenceId, 1) &&
480 odr_implicit(o, odr_integer, &pp->smallSetUpperBound, ODR_CONTEXT,
482 odr_implicit(o, odr_integer, &pp->largeSetLowerBound, ODR_CONTEXT,
484 odr_implicit(o, odr_integer, &pp->mediumSetPresentNumber, ODR_CONTEXT,
486 odr_implicit(o, odr_bool, &pp->replaceIndicator, ODR_CONTEXT, 16, 1) &&
487 odr_implicit(o, odr_visiblestring, &pp->resultSetName, ODR_CONTEXT,
489 odr_implicit_settag(o, ODR_CONTEXT, 18) &&
490 odr_sequence_of(o, z_DatabaseName, &pp->databaseNames,
491 &pp->num_databaseNames) &&
492 odr_explicit(o, z_ElementSetNames, &pp->smallSetElementSetNames,
493 ODR_CONTEXT, 100, 1) &&
494 odr_explicit(o, z_ElementSetNames, &pp->mediumSetElementSetNames,
495 ODR_CONTEXT, 101, 1) &&
496 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
497 odr_explicit(o, z_Query, &pp->query, ODR_CONTEXT, 21, 0) &&
501 /* ------------------------ RECORD ------------------------- */
503 int z_DatabaseRecord(ODR o, Z_DatabaseRecord **p, int opt)
505 return odr_external(o, (Odr_external **) p, opt);
508 int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
510 if (!odr_sequence_begin(o, p, sizeof(**p)))
513 odr_oid(o, &(*p)->diagnosticSetId, 1) && /* SHOULD NOT BE OPT */
514 odr_integer(o, &(*p)->condition, 0) &&
515 (odr_visiblestring(o, &(*p)->addinfo, 0) ||
516 odr_implicit(o, odr_cstring, &(*p)->addinfo, ODR_CONTEXT, ODR_VISIBLESTRING, 1)) &&
520 int z_NamePlusRecord(ODR o, Z_NamePlusRecord **p, int opt)
522 static Odr_arm arm[] =
524 {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_NamePlusRecord_databaseRecord,
526 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_NamePlusRecord_surrogateDiagnostic,
531 if (!odr_sequence_begin(o, p, sizeof(**p)))
534 odr_implicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
536 odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 1) &&
537 odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
538 odr_constructed_end(o) &&
542 int z_NamePlusRecordList(ODR o, Z_NamePlusRecordList **p, int opt)
544 if (o->direction == ODR_DECODE)
545 *p = odr_malloc(o, sizeof(**p));
546 if (odr_sequence_of(o, z_NamePlusRecord, &(*p)->records,
553 int z_Records(ODR o, Z_Records **p, int opt)
557 {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_Records_DBOSD, z_NamePlusRecordList},
558 {ODR_IMPLICIT, ODR_CONTEXT, 130, Z_Records_NSD, z_DiagRec},
562 if (o->direction == ODR_DECODE)
563 *p = odr_malloc(o, sizeof(**p));
566 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
569 return opt && !o->error;
572 /* ------------------------ SEARCHRESPONSE ----------------*/
574 int z_NumberOfRecordsReturned(ODR o, int **p, int opt)
576 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 24, opt);
579 int z_NextResultSetPosition(ODR o, int **p, int opt)
581 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 25, opt);
584 int z_PresentStatus(ODR o, int **p, int opt)
586 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 27, opt);
589 int z_SearchResponse(ODR o, Z_SearchResponse **p, int opt)
591 Z_SearchResponse *pp;
593 if (!odr_sequence_begin(o, p, sizeof(**p)))
597 z_ReferenceId(o, &pp->referenceId, 1) &&
598 odr_implicit(o, odr_integer, &pp->resultCount, ODR_CONTEXT, 23, 0) &&
599 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
600 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
601 odr_implicit(o, odr_bool, &pp->searchStatus, ODR_CONTEXT, 22, 0) &&
602 odr_implicit(o, odr_integer, &pp->resultSetStatus, ODR_CONTEXT, 26, 1) &&
603 z_PresentStatus(o, &pp->presentStatus, 1) &&
604 z_Records(o, &pp->records, 1) &&
608 /* --------------------- PRESENT SERVICE ---------------------- */
610 int z_PresentRequest(ODR o, Z_PresentRequest **p, int opt)
612 Z_PresentRequest *pp;
614 if (!odr_sequence_begin(o, p, sizeof(**p)))
618 z_ReferenceId(o, &pp->referenceId, 1) &&
619 z_ResultSetId(o, &pp->resultSetId, 0) &&
620 odr_implicit(o, odr_integer, &pp->resultSetStartPoint, ODR_CONTEXT,
622 odr_implicit(o, odr_integer, &pp->numberOfRecordsRequested, ODR_CONTEXT,
624 z_ElementSetNames(o, &pp->elementSetNames, 1) &&
625 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
629 int z_PresentResponse(ODR o, Z_PresentResponse **p, int opt)
631 Z_PresentResponse *pp;
633 if (!odr_sequence_begin(o, p, sizeof(**p)))
637 z_ReferenceId(o, &pp->referenceId, 1) &&
638 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
639 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
640 z_PresentStatus(o, &pp->presentStatus, 0) &&
641 z_Records(o, &pp->records, 1) &&
645 /* ------------------------ APDU ------------------------- */
647 int z_APDU(ODR o, Z_APDU **p, int opt)
649 static Odr_arm arm[] =
651 {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_initRequest, z_InitRequest},
652 {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_initResponse, z_InitResponse},
653 {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_searchRequest, z_SearchRequest},
654 {ODR_IMPLICIT, ODR_CONTEXT, 23, Z_APDU_searchResponse, z_SearchResponse},
655 {ODR_IMPLICIT, ODR_CONTEXT, 24, Z_APDU_presentRequest, z_PresentRequest},
656 {ODR_IMPLICIT, ODR_CONTEXT, 25, Z_APDU_presentResponse, z_PresentResponse},
661 if (o->direction == ODR_DECODE)
662 *p = odr_malloc(o, sizeof(**p));
663 if (!odr_choice(o, arm, &(*p)->u, &(*p)->which))
665 if (o->direction == ODR_DECODE)
667 return opt && !o->error;