2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.4 1995-02-10 15:54:30 quinn
10 * Revision 1.3 1995/02/09 15:51:39 quinn
13 * Revision 1.2 1995/02/06 21:26:07 quinn
14 * Repaired this evening's damages..
16 * Revision 1.1 1995/02/06 16:44:47 quinn
17 * First hack at Z/SR protocol
25 /* ---------------------- GLOBAL DEFS ------------------- */
27 int z_ReferenceId(ODR o, Z_ReferenceId **p, int opt)
29 return odr_implicit(o, odr_octetstring, (Odr_oct**) p, ODR_CONTEXT, 2, opt);
32 int z_DatabaseName(ODR o, Z_DatabaseName **p, int opt)
34 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 105,
38 int z_ResultSetId(ODR o, char **p, int opt)
40 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 31,
44 int z_UserInformationField(ODR o, Z_UserInformationField **p, int opt)
46 return odr_explicit(o, odr_external, (Odr_external **)p, ODR_CONTEXT,
50 /* ---------------------- INITIALIZE SERVICE ------------------- */
52 int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
56 if (!odr_sequence_begin(o, p, sizeof(**p)))
60 z_ReferenceId(o, &pp->referenceId, 1) &&
61 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
63 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
64 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
66 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
68 odr_implicit(o, odr_visiblestring, &pp->idAuthentication, ODR_CONTEXT,
70 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
72 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
74 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
75 ODR_CONTEXT, 112, 1) &&
76 z_UserInformationField(o, &pp->userInformationField, 1) &&
80 int z_InitResponse(ODR o, Z_InitResponse **p, int opt)
84 if (!odr_sequence_begin(o, p, sizeof(**p)))
88 z_ReferenceId(o, &pp->referenceId, 1) &&
89 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
91 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
92 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
94 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
96 odr_implicit(o, odr_bool, &pp->result, ODR_CONTEXT, 12, 0) &&
97 odr_implicit(o, odr_visiblestring, &pp->idAuthentication, ODR_CONTEXT,
99 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
101 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
103 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
104 ODR_CONTEXT, 112, 1) &&
105 z_UserInformationField(o, &pp->userInformationField, 1) &&
109 /* ------------------------ SEARCH SERVICE ----------------------- */
111 int z_ElementSetName(ODR o, char **p, int opt)
113 return odr_implicit(o, odr_visiblestring, (char**) p, ODR_CONTEXT, 103,
117 int z_PreferredRecordSyntax(ODR o, Z_PreferredRecordSyntax **p, int opt)
119 return odr_implicit(o, odr_oid, (Odr_oid**) p, ODR_CONTEXT, 104, opt);
122 int z_DatabaseSpecificUnit(ODR o, Z_DatabaseSpecificUnit **p, int opt)
124 if (!odr_sequence_begin(o, p, sizeof(**p)))
127 z_DatabaseName(o, &(*p)->databaseName, 0) &&
128 z_ElementSetName(o, &(*p)->elementSetName, 0) &&
132 int z_DatabaseSpecific(ODR o, Z_DatabaseSpecific **p, int opt)
134 if (o->direction == ODR_DECODE)
135 *p = nalloc(o, sizeof(**p));
139 odr_implicit_settag(o, ODR_CONTEXT, 1);
140 if (odr_sequence_of(o, z_DatabaseSpecificUnit, &(*p)->elements,
141 &(*p)->num_elements))
147 int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
149 static Odr_arm arm[] =
151 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_ElementSetNames_generic,
153 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementSetNames_databaseSpecific,
158 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 19))
161 if (o->direction == ODR_DECODE)
162 *p = nalloc(o, sizeof(**p));
164 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
165 odr_constructed_end(o))
171 /* ----------------------- RPN QUERY -----------------------*/
173 int z_AttributeElement(ODR o, Z_AttributeElement **p, int opt)
175 if (!odr_sequence_begin(o, p, sizeof(**p)))
178 odr_implicit(o, odr_integer, &(*p)->attributeType, ODR_CONTEXT,
180 odr_implicit(o, odr_integer, &(*p)->attributeValue, ODR_CONTEXT,
185 int z_AttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
187 if (!(odr_implicit_settag(o, ODR_CONTEXT, 102) &&
188 odr_sequence_begin(o, p, sizeof(**p))))
191 odr_implicit_settag(o, ODR_CONTEXT, 44) &&
192 odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
193 &(*p)->num_attributes) &&
194 odr_implicit(o, odr_octetstring, &(*p)->term, ODR_CONTEXT, 45, 0) &&
198 int z_Operator(ODR o, Z_Operator **p, int opt)
200 static Odr_arm arm[] =
202 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_Operator_and, odr_null},
203 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Operator_or, odr_null},
204 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Operator_and_not, odr_null},
209 if (!*p && o->direction != ODR_DECODE)
211 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 46))
213 if (o->direction == ODR_DECODE)
214 *p = nalloc(o, sizeof(**p));
216 (*p)->u.and = &dummy;
218 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
219 odr_constructed_end(o))
225 int z_Operand(ODR o, Z_Operand **p, int opt)
227 static Odr_arm arm[] =
229 {-1, -1, -1, Z_Operand_APT, z_AttributesPlusTerm},
230 {-1, -1, -1, Z_Operand_resultSetId, z_ResultSetId},
234 if (o->direction ==ODR_DECODE)
235 *p = nalloc(o, sizeof(**p));
238 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
244 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt);
246 int z_Complex(ODR o, Z_Complex **p, int opt)
248 if (!odr_sequence_begin(o, p, sizeof(**p)))
251 z_RPNStructure(o, &(*p)->s1, 0) &&
252 z_RPNStructure(o, &(*p)->s2, 0) &&
253 z_Operator(o, &(*p)->operator, 0) &&
257 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt)
259 static Odr_arm arm[] =
261 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand},
262 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_RPNStructure_complex, z_Complex},
266 if (o->direction == ODR_DECODE)
267 *p = nalloc(o, sizeof(**p));
270 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
276 int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
278 if (!odr_sequence_begin(o, p, sizeof(**p)))
281 odr_oid(o, &(*p)->attributeSetId, 0) &&
282 z_RPNStructure(o, &(*p)->RPNStructure, 0) &&
286 /* -----------------------END RPN QUERY ----------------------- */
288 int z_Query(ODR o, Z_Query **p, int opt)
290 static Odr_arm arm[] =
292 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Query_type_1, z_RPNQuery},
293 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_octetstring},
297 if (o->direction == ODR_DECODE)
298 *p = nalloc(o, sizeof(**p));
301 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
307 int z_SearchRequest(ODR o, Z_SearchRequest **p, int opt)
311 if (!odr_sequence_begin(o, p, sizeof(**p)))
315 z_ReferenceId(o, &pp->referenceId, 1) &&
316 odr_implicit(o, odr_integer, &pp->smallSetUpperBound, ODR_CONTEXT,
318 odr_implicit(o, odr_integer, &pp->largeSetLowerBound, ODR_CONTEXT,
320 odr_implicit(o, odr_integer, &pp->mediumSetPresentNumber, ODR_CONTEXT,
322 odr_implicit(o, odr_bool, &pp->replaceIndicator, ODR_CONTEXT, 16, 1) &&
323 odr_implicit(o, odr_visiblestring, &pp->resultSetName, ODR_CONTEXT,
325 odr_implicit_settag(o, ODR_CONTEXT, 18) &&
326 odr_sequence_of(o, z_DatabaseName, &pp->databaseNames,
327 &pp->num_databaseNames) &&
328 odr_implicit(o, z_ElementSetNames, &pp->smallSetElementSetNames,
329 ODR_CONTEXT, 100, 1) &&
330 odr_implicit(o, z_ElementSetNames, &pp->mediumSetElementSetNames,
331 ODR_CONTEXT, 101, 1) &&
332 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
333 odr_explicit(o, z_Query, &pp->query, ODR_CONTEXT, 21, 0) &&
337 /* ------------------------ RECORD ------------------------- */
339 int z_DatabaseRecord(ODR o, Z_DatabaseRecord **p, int opt)
341 return odr_external(o, (Odr_external **) p, opt);
344 int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
346 if (!odr_sequence_begin(o, p, sizeof(**p)))
349 odr_oid(o, &(*p)->diagnosticSetId, 1) && /* SHOULD NOT BE OPT */
350 odr_integer(o, &(*p)->condition, 0) &&
351 (odr_visiblestring(o, &(*p)->addinfo, 0) ||
352 odr_implicit(o, odr_cstring, &(*p)->addinfo, ODR_CONTEXT, ODR_VISIBLESTRING, 1)) &&
356 int z_NamePlusRecord(ODR o, Z_NamePlusRecord **p, int opt)
358 static Odr_arm arm[] =
360 {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_NamePlusRecord_databaseRecord,
362 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_NamePlusRecord_surrogateDiagnostic,
367 if (!odr_sequence_begin(o, p, sizeof(**p)))
370 odr_implicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
372 odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 1) &&
373 odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
374 odr_constructed_end(o) &&
378 int z_NamePlusRecordList(ODR o, Z_NamePlusRecordList **p, int opt)
380 if (o->direction == ODR_DECODE)
381 *p = nalloc(o, sizeof(**p));
382 if (odr_sequence_of(o, z_NamePlusRecord, &(*p)->records,
389 int z_Records(ODR o, Z_Records **p, int opt)
393 {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_Records_DBOSD, z_NamePlusRecordList},
394 {ODR_IMPLICIT, ODR_CONTEXT, 130, Z_Records_NSD, z_DiagRec},
398 if (o->direction == ODR_DECODE)
399 *p = nalloc(o, sizeof(**p));
402 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
408 /* ------------------------ SEARCHRESPONSE ----------------*/
410 int z_NumberOfRecordsReturned(ODR o, int **p, int opt)
412 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 24, opt);
415 int z_NextResultSetPosition(ODR o, int **p, int opt)
417 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 25, opt);
420 int z_PresentStatus(ODR o, int **p, int opt)
422 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 27, opt);
425 int z_SearchResponse(ODR o, Z_SearchResponse **p, int opt)
427 Z_SearchResponse *pp;
429 if (!odr_sequence_begin(o, p, sizeof(**p)))
433 z_ReferenceId(o, &pp->referenceId, 1) &&
434 odr_implicit(o, odr_integer, &pp->resultCount, ODR_CONTEXT, 23, 0) &&
435 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
436 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
437 odr_implicit(o, odr_bool, &pp->searchStatus, ODR_CONTEXT, 22, 0) &&
438 odr_implicit(o, odr_integer, &pp->resultSetStatus, ODR_CONTEXT, 26, 1) &&
439 z_PresentStatus(o, &pp->presentStatus, 1) &&
440 z_Records(o, &pp->records, 1) &&
444 /* --------------------- PRESENT SERVICE ---------------------- */
446 int z_PresentRequest(ODR o, Z_PresentRequest **p, int opt)
448 Z_PresentRequest *pp;
450 if (!odr_sequence_begin(o, p, sizeof(**p)))
454 z_ReferenceId(o, &pp->referenceId, 1) &&
455 z_ResultSetId(o, &pp->resultSetId, 0) &&
456 odr_implicit(o, odr_integer, &pp->resultSetStartPoint, ODR_CONTEXT,
458 odr_implicit(o, odr_integer, &pp->numberOfRecordsRequested, ODR_CONTEXT,
460 z_ElementSetNames(o, &pp->elementSetNames, 1) &&
461 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
465 int z_PresentResponse(ODR o, Z_PresentResponse **p, int opt)
467 Z_PresentResponse *pp;
469 if (!odr_sequence_begin(o, p, sizeof(**p)))
473 z_ReferenceId(o, &pp->referenceId, 1) &&
474 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
475 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
476 z_PresentStatus(o, &pp->presentStatus, 0) &&
477 z_Records(o, &pp->records, 1) &&
481 /* ------------------------ APDU ------------------------- */
483 int z_APDU(ODR o, Z_APDU **p, int opt)
485 static Odr_arm arm[] =
487 {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_initRequest, z_InitRequest},
488 {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_initResponse, z_InitResponse},
489 {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_searchRequest, z_SearchRequest},
490 {ODR_IMPLICIT, ODR_CONTEXT, 23, Z_APDU_searchResponse, z_SearchResponse},
491 {ODR_IMPLICIT, ODR_CONTEXT, 24, Z_APDU_presentRequest, z_PresentRequest},
492 {ODR_IMPLICIT, ODR_CONTEXT, 25, Z_APDU_presentResponse, z_PresentResponse},
497 if (o->direction == ODR_DECODE)
498 *p = nalloc(o, sizeof(**p));
499 if (!odr_choice(o, arm, &(*p)->u, &(*p)->which))
501 if (o->direction == ODR_DECODE)