2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.6 1995-03-01 14:46:03 quinn
8 * Fixed protocol bug in 8777query.
10 * Revision 1.5 1995/02/14 11:54:22 quinn
13 * Revision 1.4 1995/02/10 15:54:30 quinn
16 * Revision 1.3 1995/02/09 15:51:39 quinn
19 * Revision 1.2 1995/02/06 21:26:07 quinn
20 * Repaired this evening's damages..
22 * Revision 1.1 1995/02/06 16:44:47 quinn
23 * First hack at Z/SR protocol
31 /* ---------------------- GLOBAL DEFS ------------------- */
33 int z_ReferenceId(ODR o, Z_ReferenceId **p, int opt)
35 return odr_implicit(o, odr_octetstring, (Odr_oct**) p, ODR_CONTEXT, 2, opt);
38 int z_DatabaseName(ODR o, Z_DatabaseName **p, int opt)
40 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 105,
44 int z_ResultSetId(ODR o, char **p, int opt)
46 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 31,
50 int z_UserInformationField(ODR o, Z_UserInformationField **p, int opt)
52 return odr_explicit(o, odr_external, (Odr_external **)p, ODR_CONTEXT,
56 /* ---------------------- INITIALIZE SERVICE ------------------- */
58 int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
62 if (!odr_sequence_begin(o, p, sizeof(**p)))
66 z_ReferenceId(o, &pp->referenceId, 1) &&
67 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
69 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
70 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
72 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
74 odr_implicit(o, odr_visiblestring, &pp->idAuthentication, ODR_CONTEXT,
76 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
78 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
80 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
81 ODR_CONTEXT, 112, 1) &&
82 z_UserInformationField(o, &pp->userInformationField, 1) &&
86 int z_InitResponse(ODR o, Z_InitResponse **p, int opt)
90 if (!odr_sequence_begin(o, p, sizeof(**p)))
94 z_ReferenceId(o, &pp->referenceId, 1) &&
95 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
97 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
98 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
100 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
102 odr_implicit(o, odr_bool, &pp->result, ODR_CONTEXT, 12, 0) &&
103 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
105 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
107 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
108 ODR_CONTEXT, 112, 1) &&
109 z_UserInformationField(o, &pp->userInformationField, 1) &&
113 /* ------------------------ SEARCH SERVICE ----------------------- */
115 int z_ElementSetName(ODR o, char **p, int opt)
117 return odr_implicit(o, odr_visiblestring, (char**) p, ODR_CONTEXT, 103,
121 int z_PreferredRecordSyntax(ODR o, Z_PreferredRecordSyntax **p, int opt)
123 return odr_implicit(o, odr_oid, (Odr_oid**) p, ODR_CONTEXT, 104, opt);
126 int z_DatabaseSpecificUnit(ODR o, Z_DatabaseSpecificUnit **p, int opt)
128 if (!odr_sequence_begin(o, p, sizeof(**p)))
131 z_DatabaseName(o, &(*p)->databaseName, 0) &&
132 z_ElementSetName(o, &(*p)->elementSetName, 0) &&
136 int z_DatabaseSpecific(ODR o, Z_DatabaseSpecific **p, int opt)
138 if (o->direction == ODR_DECODE)
139 *p = nalloc(o, sizeof(**p));
143 odr_implicit_settag(o, ODR_CONTEXT, 1);
144 if (odr_sequence_of(o, z_DatabaseSpecificUnit, &(*p)->elements,
145 &(*p)->num_elements))
151 int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
153 static Odr_arm arm[] =
155 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_ElementSetNames_generic,
157 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementSetNames_databaseSpecific,
162 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 19))
165 if (o->direction == ODR_DECODE)
166 *p = nalloc(o, sizeof(**p));
168 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
169 odr_constructed_end(o))
175 /* ----------------------- RPN QUERY -----------------------*/
177 int z_AttributeElement(ODR o, Z_AttributeElement **p, int opt)
179 if (!odr_sequence_begin(o, p, sizeof(**p)))
182 odr_implicit(o, odr_integer, &(*p)->attributeType, ODR_CONTEXT,
184 odr_implicit(o, odr_integer, &(*p)->attributeValue, ODR_CONTEXT,
189 int z_AttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
191 if (!(odr_implicit_settag(o, ODR_CONTEXT, 102) &&
192 odr_sequence_begin(o, p, sizeof(**p))))
195 odr_implicit_settag(o, ODR_CONTEXT, 44) &&
196 odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
197 &(*p)->num_attributes) &&
198 odr_implicit(o, odr_octetstring, &(*p)->term, ODR_CONTEXT, 45, 0) &&
202 int z_Operator(ODR o, Z_Operator **p, int opt)
204 static Odr_arm arm[] =
206 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_Operator_and, odr_null},
207 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Operator_or, odr_null},
208 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Operator_and_not, odr_null},
213 if (!*p && o->direction != ODR_DECODE)
215 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 46))
217 if (o->direction == ODR_DECODE)
218 *p = nalloc(o, sizeof(**p));
220 (*p)->u.and = &dummy;
222 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
223 odr_constructed_end(o))
229 int z_Operand(ODR o, Z_Operand **p, int opt)
231 static Odr_arm arm[] =
233 {-1, -1, -1, Z_Operand_APT, z_AttributesPlusTerm},
234 {-1, -1, -1, Z_Operand_resultSetId, z_ResultSetId},
238 if (o->direction ==ODR_DECODE)
239 *p = nalloc(o, sizeof(**p));
242 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
248 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt);
250 int z_Complex(ODR o, Z_Complex **p, int opt)
252 if (!odr_sequence_begin(o, p, sizeof(**p)))
255 z_RPNStructure(o, &(*p)->s1, 0) &&
256 z_RPNStructure(o, &(*p)->s2, 0) &&
257 z_Operator(o, &(*p)->operator, 0) &&
261 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt)
263 static Odr_arm arm[] =
265 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand},
266 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_RPNStructure_complex, z_Complex},
270 if (o->direction == ODR_DECODE)
271 *p = nalloc(o, sizeof(**p));
274 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
280 int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
282 if (!odr_sequence_begin(o, p, sizeof(**p)))
285 odr_oid(o, &(*p)->attributeSetId, 0) &&
286 z_RPNStructure(o, &(*p)->RPNStructure, 0) &&
290 /* -----------------------END RPN QUERY ----------------------- */
292 int z_Query(ODR o, Z_Query **p, int opt)
294 static Odr_arm arm[] =
296 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Query_type_1, z_RPNQuery},
297 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_octetstring},
301 if (o->direction == ODR_DECODE)
302 *p = nalloc(o, sizeof(**p));
305 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
311 int z_SearchRequest(ODR o, Z_SearchRequest **p, int opt)
315 if (!odr_sequence_begin(o, p, sizeof(**p)))
319 z_ReferenceId(o, &pp->referenceId, 1) &&
320 odr_implicit(o, odr_integer, &pp->smallSetUpperBound, ODR_CONTEXT,
322 odr_implicit(o, odr_integer, &pp->largeSetLowerBound, ODR_CONTEXT,
324 odr_implicit(o, odr_integer, &pp->mediumSetPresentNumber, ODR_CONTEXT,
326 odr_implicit(o, odr_bool, &pp->replaceIndicator, ODR_CONTEXT, 16, 1) &&
327 odr_implicit(o, odr_visiblestring, &pp->resultSetName, ODR_CONTEXT,
329 odr_implicit_settag(o, ODR_CONTEXT, 18) &&
330 odr_sequence_of(o, z_DatabaseName, &pp->databaseNames,
331 &pp->num_databaseNames) &&
332 odr_implicit(o, z_ElementSetNames, &pp->smallSetElementSetNames,
333 ODR_CONTEXT, 100, 1) &&
334 odr_implicit(o, z_ElementSetNames, &pp->mediumSetElementSetNames,
335 ODR_CONTEXT, 101, 1) &&
336 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
337 odr_explicit(o, z_Query, &pp->query, ODR_CONTEXT, 21, 0) &&
341 /* ------------------------ RECORD ------------------------- */
343 int z_DatabaseRecord(ODR o, Z_DatabaseRecord **p, int opt)
345 return odr_external(o, (Odr_external **) p, opt);
348 int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
350 if (!odr_sequence_begin(o, p, sizeof(**p)))
353 odr_oid(o, &(*p)->diagnosticSetId, 1) && /* SHOULD NOT BE OPT */
354 odr_integer(o, &(*p)->condition, 0) &&
355 (odr_visiblestring(o, &(*p)->addinfo, 0) ||
356 odr_implicit(o, odr_cstring, &(*p)->addinfo, ODR_CONTEXT, ODR_VISIBLESTRING, 1)) &&
360 int z_NamePlusRecord(ODR o, Z_NamePlusRecord **p, int opt)
362 static Odr_arm arm[] =
364 {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_NamePlusRecord_databaseRecord,
366 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_NamePlusRecord_surrogateDiagnostic,
371 if (!odr_sequence_begin(o, p, sizeof(**p)))
374 odr_implicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
376 odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 1) &&
377 odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
378 odr_constructed_end(o) &&
382 int z_NamePlusRecordList(ODR o, Z_NamePlusRecordList **p, int opt)
384 if (o->direction == ODR_DECODE)
385 *p = nalloc(o, sizeof(**p));
386 if (odr_sequence_of(o, z_NamePlusRecord, &(*p)->records,
393 int z_Records(ODR o, Z_Records **p, int opt)
397 {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_Records_DBOSD, z_NamePlusRecordList},
398 {ODR_IMPLICIT, ODR_CONTEXT, 130, Z_Records_NSD, z_DiagRec},
402 if (o->direction == ODR_DECODE)
403 *p = nalloc(o, sizeof(**p));
406 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
412 /* ------------------------ SEARCHRESPONSE ----------------*/
414 int z_NumberOfRecordsReturned(ODR o, int **p, int opt)
416 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 24, opt);
419 int z_NextResultSetPosition(ODR o, int **p, int opt)
421 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 25, opt);
424 int z_PresentStatus(ODR o, int **p, int opt)
426 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 27, opt);
429 int z_SearchResponse(ODR o, Z_SearchResponse **p, int opt)
431 Z_SearchResponse *pp;
433 if (!odr_sequence_begin(o, p, sizeof(**p)))
437 z_ReferenceId(o, &pp->referenceId, 1) &&
438 odr_implicit(o, odr_integer, &pp->resultCount, ODR_CONTEXT, 23, 0) &&
439 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
440 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
441 odr_implicit(o, odr_bool, &pp->searchStatus, ODR_CONTEXT, 22, 0) &&
442 odr_implicit(o, odr_integer, &pp->resultSetStatus, ODR_CONTEXT, 26, 1) &&
443 z_PresentStatus(o, &pp->presentStatus, 1) &&
444 z_Records(o, &pp->records, 1) &&
448 /* --------------------- PRESENT SERVICE ---------------------- */
450 int z_PresentRequest(ODR o, Z_PresentRequest **p, int opt)
452 Z_PresentRequest *pp;
454 if (!odr_sequence_begin(o, p, sizeof(**p)))
458 z_ReferenceId(o, &pp->referenceId, 1) &&
459 z_ResultSetId(o, &pp->resultSetId, 0) &&
460 odr_implicit(o, odr_integer, &pp->resultSetStartPoint, ODR_CONTEXT,
462 odr_implicit(o, odr_integer, &pp->numberOfRecordsRequested, ODR_CONTEXT,
464 z_ElementSetNames(o, &pp->elementSetNames, 1) &&
465 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
469 int z_PresentResponse(ODR o, Z_PresentResponse **p, int opt)
471 Z_PresentResponse *pp;
473 if (!odr_sequence_begin(o, p, sizeof(**p)))
477 z_ReferenceId(o, &pp->referenceId, 1) &&
478 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
479 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
480 z_PresentStatus(o, &pp->presentStatus, 0) &&
481 z_Records(o, &pp->records, 1) &&
485 /* ------------------------ APDU ------------------------- */
487 int z_APDU(ODR o, Z_APDU **p, int opt)
489 static Odr_arm arm[] =
491 {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_initRequest, z_InitRequest},
492 {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_initResponse, z_InitResponse},
493 {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_searchRequest, z_SearchRequest},
494 {ODR_IMPLICIT, ODR_CONTEXT, 23, Z_APDU_searchResponse, z_SearchResponse},
495 {ODR_IMPLICIT, ODR_CONTEXT, 24, Z_APDU_presentRequest, z_PresentRequest},
496 {ODR_IMPLICIT, ODR_CONTEXT, 25, Z_APDU_presentResponse, z_PresentResponse},
501 if (o->direction == ODR_DECODE)
502 *p = nalloc(o, sizeof(**p));
503 if (!odr_choice(o, arm, &(*p)->u, &(*p)->which))
505 if (o->direction == ODR_DECODE)