2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.8 1995-03-14 16:59:24 quinn
8 * Fixed OPTIONAL flag in attributeelement
10 * Revision 1.7 1995/03/07 16:29:33 quinn
11 * Added authentication stuff.
13 * Revision 1.6 1995/03/01 14:46:03 quinn
14 * Fixed protocol bug in 8777query.
16 * Revision 1.5 1995/02/14 11:54:22 quinn
19 * Revision 1.4 1995/02/10 15:54:30 quinn
22 * Revision 1.3 1995/02/09 15:51:39 quinn
25 * Revision 1.2 1995/02/06 21:26:07 quinn
26 * Repaired this evening's damages..
28 * Revision 1.1 1995/02/06 16:44:47 quinn
29 * First hack at Z/SR protocol
37 /* ---------------------- GLOBAL DEFS ------------------- */
39 int z_ReferenceId(ODR o, Z_ReferenceId **p, int opt)
41 return odr_implicit(o, odr_octetstring, (Odr_oct**) p, ODR_CONTEXT, 2, opt);
44 int z_DatabaseName(ODR o, Z_DatabaseName **p, int opt)
46 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 105,
50 int z_ResultSetId(ODR o, char **p, int opt)
52 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 31,
56 int z_UserInformationField(ODR o, Z_UserInformationField **p, int opt)
58 return odr_explicit(o, odr_external, (Odr_external **)p, ODR_CONTEXT,
62 /* ---------------------- INITIALIZE SERVICE ------------------- */
64 int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
68 if (!odr_sequence_begin(o, p, sizeof(**p)))
72 z_ReferenceId(o, &pp->referenceId, 1) &&
73 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
75 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
76 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
78 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
80 odr_explicit(o, odr_any, &pp->idAuthentication, ODR_CONTEXT,
82 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
84 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
86 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
87 ODR_CONTEXT, 112, 1) &&
88 z_UserInformationField(o, &pp->userInformationField, 1) &&
92 int z_InitResponse(ODR o, Z_InitResponse **p, int opt)
96 if (!odr_sequence_begin(o, p, sizeof(**p)))
100 z_ReferenceId(o, &pp->referenceId, 1) &&
101 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
103 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
104 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
106 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
108 odr_implicit(o, odr_bool, &pp->result, ODR_CONTEXT, 12, 0) &&
109 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
111 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
113 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
114 ODR_CONTEXT, 112, 1) &&
115 z_UserInformationField(o, &pp->userInformationField, 1) &&
119 int z_NSRAuthentication(ODR o, Z_NSRAuthentication **p, int opt)
121 if (!odr_sequence_begin(o, p, sizeof(**p)))
124 odr_visiblestring(o, &(*p)->user, 0) &&
125 odr_visiblestring(o, &(*p)->password, 0) &&
126 odr_visiblestring(o, &(*p)->account, 0) &&
130 int z_StrAuthentication(ODR o, char **p, int opt)
132 return odr_visiblestring(o, p, opt);
135 /* ------------------------ SEARCH SERVICE ----------------------- */
137 int z_ElementSetName(ODR o, char **p, int opt)
139 return odr_implicit(o, odr_visiblestring, (char**) p, ODR_CONTEXT, 103,
143 int z_PreferredRecordSyntax(ODR o, Z_PreferredRecordSyntax **p, int opt)
145 return odr_implicit(o, odr_oid, (Odr_oid**) p, ODR_CONTEXT, 104, opt);
148 int z_DatabaseSpecificUnit(ODR o, Z_DatabaseSpecificUnit **p, int opt)
150 if (!odr_sequence_begin(o, p, sizeof(**p)))
153 z_DatabaseName(o, &(*p)->databaseName, 0) &&
154 z_ElementSetName(o, &(*p)->elementSetName, 0) &&
158 int z_DatabaseSpecific(ODR o, Z_DatabaseSpecific **p, int opt)
160 if (o->direction == ODR_DECODE)
161 *p = nalloc(o, sizeof(**p));
165 odr_implicit_settag(o, ODR_CONTEXT, 1);
166 if (odr_sequence_of(o, z_DatabaseSpecificUnit, &(*p)->elements,
167 &(*p)->num_elements))
173 int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
175 static Odr_arm arm[] =
177 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_ElementSetNames_generic,
179 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementSetNames_databaseSpecific,
184 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 19))
187 if (o->direction == ODR_DECODE)
188 *p = nalloc(o, sizeof(**p));
190 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
191 odr_constructed_end(o))
197 /* ----------------------- RPN QUERY -----------------------*/
199 int z_AttributeElement(ODR o, Z_AttributeElement **p, int opt)
201 if (!odr_sequence_begin(o, p, sizeof(**p)))
204 odr_implicit(o, odr_integer, &(*p)->attributeType, ODR_CONTEXT,
206 odr_implicit(o, odr_integer, &(*p)->attributeValue, ODR_CONTEXT,
211 int z_AttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
213 if (!(odr_implicit_settag(o, ODR_CONTEXT, 102) &&
214 odr_sequence_begin(o, p, sizeof(**p))))
217 odr_implicit_settag(o, ODR_CONTEXT, 44) &&
218 odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
219 &(*p)->num_attributes) &&
220 odr_implicit(o, odr_octetstring, &(*p)->term, ODR_CONTEXT, 45, 0) &&
224 int z_Operator(ODR o, Z_Operator **p, int opt)
226 static Odr_arm arm[] =
228 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_Operator_and, odr_null},
229 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Operator_or, odr_null},
230 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Operator_and_not, odr_null},
235 if (!*p && o->direction != ODR_DECODE)
237 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 46))
239 if (o->direction == ODR_DECODE)
240 *p = nalloc(o, sizeof(**p));
242 (*p)->u.and = &dummy;
244 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
245 odr_constructed_end(o))
251 int z_Operand(ODR o, Z_Operand **p, int opt)
253 static Odr_arm arm[] =
255 {-1, -1, -1, Z_Operand_APT, z_AttributesPlusTerm},
256 {-1, -1, -1, Z_Operand_resultSetId, z_ResultSetId},
260 if (o->direction ==ODR_DECODE)
261 *p = nalloc(o, sizeof(**p));
264 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
270 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt);
272 int z_Complex(ODR o, Z_Complex **p, int opt)
274 if (!odr_sequence_begin(o, p, sizeof(**p)))
277 z_RPNStructure(o, &(*p)->s1, 0) &&
278 z_RPNStructure(o, &(*p)->s2, 0) &&
279 z_Operator(o, &(*p)->operator, 0) &&
283 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt)
285 static Odr_arm arm[] =
287 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand},
288 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_RPNStructure_complex, z_Complex},
292 if (o->direction == ODR_DECODE)
293 *p = nalloc(o, sizeof(**p));
296 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
302 int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
304 if (!odr_sequence_begin(o, p, sizeof(**p)))
307 odr_oid(o, &(*p)->attributeSetId, 0) &&
308 z_RPNStructure(o, &(*p)->RPNStructure, 0) &&
312 /* -----------------------END RPN QUERY ----------------------- */
314 int z_Query(ODR o, Z_Query **p, int opt)
316 static Odr_arm arm[] =
318 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Query_type_1, z_RPNQuery},
319 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_octetstring},
323 if (o->direction == ODR_DECODE)
324 *p = nalloc(o, sizeof(**p));
327 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
333 int z_SearchRequest(ODR o, Z_SearchRequest **p, int opt)
337 if (!odr_sequence_begin(o, p, sizeof(**p)))
341 z_ReferenceId(o, &pp->referenceId, 1) &&
342 odr_implicit(o, odr_integer, &pp->smallSetUpperBound, ODR_CONTEXT,
344 odr_implicit(o, odr_integer, &pp->largeSetLowerBound, ODR_CONTEXT,
346 odr_implicit(o, odr_integer, &pp->mediumSetPresentNumber, ODR_CONTEXT,
348 odr_implicit(o, odr_bool, &pp->replaceIndicator, ODR_CONTEXT, 16, 1) &&
349 odr_implicit(o, odr_visiblestring, &pp->resultSetName, ODR_CONTEXT,
351 odr_implicit_settag(o, ODR_CONTEXT, 18) &&
352 odr_sequence_of(o, z_DatabaseName, &pp->databaseNames,
353 &pp->num_databaseNames) &&
354 odr_implicit(o, z_ElementSetNames, &pp->smallSetElementSetNames,
355 ODR_CONTEXT, 100, 1) &&
356 odr_implicit(o, z_ElementSetNames, &pp->mediumSetElementSetNames,
357 ODR_CONTEXT, 101, 1) &&
358 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
359 odr_explicit(o, z_Query, &pp->query, ODR_CONTEXT, 21, 0) &&
363 /* ------------------------ RECORD ------------------------- */
365 int z_DatabaseRecord(ODR o, Z_DatabaseRecord **p, int opt)
367 return odr_external(o, (Odr_external **) p, opt);
370 int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
372 if (!odr_sequence_begin(o, p, sizeof(**p)))
375 odr_oid(o, &(*p)->diagnosticSetId, 1) && /* SHOULD NOT BE OPT */
376 odr_integer(o, &(*p)->condition, 0) &&
377 (odr_visiblestring(o, &(*p)->addinfo, 0) ||
378 odr_implicit(o, odr_cstring, &(*p)->addinfo, ODR_CONTEXT, ODR_VISIBLESTRING, 1)) &&
382 int z_NamePlusRecord(ODR o, Z_NamePlusRecord **p, int opt)
384 static Odr_arm arm[] =
386 {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_NamePlusRecord_databaseRecord,
388 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_NamePlusRecord_surrogateDiagnostic,
393 if (!odr_sequence_begin(o, p, sizeof(**p)))
396 odr_implicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
398 odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 1) &&
399 odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
400 odr_constructed_end(o) &&
404 int z_NamePlusRecordList(ODR o, Z_NamePlusRecordList **p, int opt)
406 if (o->direction == ODR_DECODE)
407 *p = nalloc(o, sizeof(**p));
408 if (odr_sequence_of(o, z_NamePlusRecord, &(*p)->records,
415 int z_Records(ODR o, Z_Records **p, int opt)
419 {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_Records_DBOSD, z_NamePlusRecordList},
420 {ODR_IMPLICIT, ODR_CONTEXT, 130, Z_Records_NSD, z_DiagRec},
424 if (o->direction == ODR_DECODE)
425 *p = nalloc(o, sizeof(**p));
428 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
434 /* ------------------------ SEARCHRESPONSE ----------------*/
436 int z_NumberOfRecordsReturned(ODR o, int **p, int opt)
438 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 24, opt);
441 int z_NextResultSetPosition(ODR o, int **p, int opt)
443 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 25, opt);
446 int z_PresentStatus(ODR o, int **p, int opt)
448 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 27, opt);
451 int z_SearchResponse(ODR o, Z_SearchResponse **p, int opt)
453 Z_SearchResponse *pp;
455 if (!odr_sequence_begin(o, p, sizeof(**p)))
459 z_ReferenceId(o, &pp->referenceId, 1) &&
460 odr_implicit(o, odr_integer, &pp->resultCount, ODR_CONTEXT, 23, 0) &&
461 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
462 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
463 odr_implicit(o, odr_bool, &pp->searchStatus, ODR_CONTEXT, 22, 0) &&
464 odr_implicit(o, odr_integer, &pp->resultSetStatus, ODR_CONTEXT, 26, 1) &&
465 z_PresentStatus(o, &pp->presentStatus, 1) &&
466 z_Records(o, &pp->records, 1) &&
470 /* --------------------- PRESENT SERVICE ---------------------- */
472 int z_PresentRequest(ODR o, Z_PresentRequest **p, int opt)
474 Z_PresentRequest *pp;
476 if (!odr_sequence_begin(o, p, sizeof(**p)))
480 z_ReferenceId(o, &pp->referenceId, 1) &&
481 z_ResultSetId(o, &pp->resultSetId, 0) &&
482 odr_implicit(o, odr_integer, &pp->resultSetStartPoint, ODR_CONTEXT,
484 odr_implicit(o, odr_integer, &pp->numberOfRecordsRequested, ODR_CONTEXT,
486 z_ElementSetNames(o, &pp->elementSetNames, 1) &&
487 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
491 int z_PresentResponse(ODR o, Z_PresentResponse **p, int opt)
493 Z_PresentResponse *pp;
495 if (!odr_sequence_begin(o, p, sizeof(**p)))
499 z_ReferenceId(o, &pp->referenceId, 1) &&
500 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
501 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
502 z_PresentStatus(o, &pp->presentStatus, 0) &&
503 z_Records(o, &pp->records, 1) &&
507 /* ------------------------ APDU ------------------------- */
509 int z_APDU(ODR o, Z_APDU **p, int opt)
511 static Odr_arm arm[] =
513 {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_initRequest, z_InitRequest},
514 {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_initResponse, z_InitResponse},
515 {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_searchRequest, z_SearchRequest},
516 {ODR_IMPLICIT, ODR_CONTEXT, 23, Z_APDU_searchResponse, z_SearchResponse},
517 {ODR_IMPLICIT, ODR_CONTEXT, 24, Z_APDU_presentRequest, z_PresentRequest},
518 {ODR_IMPLICIT, ODR_CONTEXT, 25, Z_APDU_presentResponse, z_PresentResponse},
523 if (o->direction == ODR_DECODE)
524 *p = nalloc(o, sizeof(**p));
525 if (!odr_choice(o, arm, &(*p)->u, &(*p)->which))
527 if (o->direction == ODR_DECODE)