2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1995-02-09 15:51:39 quinn
10 * Revision 1.2 1995/02/06 21:26:07 quinn
11 * Repaired this evening's damages..
13 * Revision 1.1 1995/02/06 16:44:47 quinn
14 * First hack at Z/SR protocol
22 /* ---------------------- GLOBAL DEFS ------------------- */
24 int z_ReferenceId(ODR o, Z_ReferenceId **p, int opt)
26 return odr_implicit(o, odr_octetstring, (Odr_oct**) p, ODR_CONTEXT, 2, opt);
29 int z_DatabaseName(ODR o, Z_DatabaseName **p, int opt)
31 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 105,
35 int z_ResultSetId(ODR o, char **p, int opt)
37 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 31,
41 int z_UserInformationField(ODR o, Z_UserInformationField **p, int opt)
43 return odr_explicit(o, odr_external, (Odr_external **)p, ODR_CONTEXT,
47 /* ---------------------- INITIALIZE SERVICE ------------------- */
49 int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
53 if (!odr_sequence_begin(o, p, sizeof(**p)))
57 z_ReferenceId(o, &pp->referenceId, 1) &&
58 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
60 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
61 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
63 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
65 odr_implicit(o, odr_visiblestring, &pp->idAuthentication, ODR_CONTEXT,
67 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
69 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
71 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
72 ODR_CONTEXT, 112, 1) &&
73 z_UserInformationField(o, &pp->userInformationField, 1) &&
77 int z_InitResponse(ODR o, Z_InitResponse **p, int opt)
81 if (!odr_sequence_begin(o, p, sizeof(**p)))
85 z_ReferenceId(o, &pp->referenceId, 1) &&
86 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
88 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
89 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
91 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
93 odr_implicit(o, odr_bool, &pp->result, ODR_CONTEXT, 12, 0) &&
94 odr_implicit(o, odr_visiblestring, &pp->idAuthentication, ODR_CONTEXT,
96 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
98 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
100 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
101 ODR_CONTEXT, 112, 1) &&
102 z_UserInformationField(o, &pp->userInformationField, 1) &&
106 /* ------------------------ SEARCH SERVICE ----------------------- */
108 int z_ElementSetName(ODR o, char **p, int opt)
110 return odr_implicit(o, odr_visiblestring, (char**) p, ODR_CONTEXT, 103,
114 int z_PreferredRecordSyntax(ODR o, Z_PreferredRecordSyntax **p, int opt)
116 return odr_implicit(o, odr_oid, (Odr_oid**) p, ODR_CONTEXT, 104, opt);
119 int z_DatabaseSpecificUnit(ODR o, Z_DatabaseSpecificUnit **p, int opt)
121 if (!odr_sequence_begin(o, p, sizeof(**p)))
124 z_DatabaseName(o, &(*p)->databaseName, 0) &&
125 z_ElementSetName(o, &(*p)->elementSetName, 0) &&
129 int z_DatabaseSpecific(ODR o, Z_DatabaseSpecific **p, int opt)
131 if (o->direction == ODR_DECODE)
132 *p = nalloc(o, sizeof(**p));
136 odr_implicit_settag(o, ODR_CONTEXT, 1);
137 if (odr_sequence_of(o, z_DatabaseSpecificUnit, &(*p)->elements,
138 &(*p)->num_elements))
144 int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
146 static Odr_arm arm[] =
148 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_ElementSetNames_generic,
150 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementSetNames_databaseSpecific,
155 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 19))
158 if (o->direction == ODR_DECODE)
159 *p = nalloc(o, sizeof(**p));
161 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
162 odr_constructed_end(o))
168 /* ----------------------- RPN QUERY -----------------------*/
170 int z_AttributeElement(ODR o, Z_AttributeElement **p, int opt)
172 if (!odr_sequence_begin(o, p, sizeof(**p)))
175 odr_implicit(o, odr_integer, &(*p)->attributeType, ODR_CONTEXT,
177 odr_implicit(o, odr_integer, &(*p)->attributeValue, ODR_CONTEXT,
182 int z_AttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
184 if (!(odr_implicit_settag(o, ODR_CONTEXT, 102) &&
185 odr_sequence_begin(o, p, sizeof(**p))))
188 odr_implicit_settag(o, ODR_CONTEXT, 44) &&
189 odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
190 &(*p)->num_attributes) &&
191 odr_implicit(o, odr_octetstring, &(*p)->term, ODR_CONTEXT, 45, 0) &&
195 int z_Operator(ODR o, Z_Operator **p, int opt)
197 static Odr_arm arm[] =
199 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_Operator_and, odr_null},
200 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Operator_or, odr_null},
201 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Operator_and_not, odr_null},
206 if (!*p && o->direction != ODR_DECODE)
208 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 46))
210 if (o->direction == ODR_DECODE)
211 *p = nalloc(o, sizeof(**p));
213 (*p)->u.and = &dummy;
215 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
216 odr_constructed_end(o))
222 int z_Operand(ODR o, Z_Operand **p, int opt)
224 static Odr_arm arm[] =
226 {-1, -1, -1, Z_Operand_APT, z_AttributesPlusTerm},
227 {-1, -1, -1, Z_Operand_resultSetId, z_ResultSetId},
231 if (o->direction ==ODR_DECODE)
232 *p = nalloc(o, sizeof(**p));
235 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
241 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt);
243 int z_Complex(ODR o, Z_Complex **p, int opt)
245 if (!odr_sequence_begin(o, p, sizeof(**p)))
248 z_RPNStructure(o, &(*p)->s1, 0) &&
249 z_RPNStructure(o, &(*p)->s2, 0) &&
250 z_Operator(o, &(*p)->operator, 0) &&
254 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt)
256 static Odr_arm arm[] =
258 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand},
259 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_RPNStructure_complex, z_Complex},
263 if (o->direction == ODR_DECODE)
264 *p = nalloc(o, sizeof(**p));
267 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
273 int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
275 if (!odr_sequence_begin(o, p, sizeof(**p)))
278 odr_oid(o, &(*p)->attributeSetId, 0) &&
279 z_RPNStructure(o, &(*p)->RPNStructure, 0) &&
283 /* -----------------------END RPN QUERY ----------------------- */
285 int z_Query(ODR o, Z_Query **p, int opt)
287 static Odr_arm arm[] =
289 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Query_type_1, z_RPNQuery},
290 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_octetstring},
294 if (o->direction == ODR_DECODE)
295 *p = nalloc(o, sizeof(**p));
298 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
304 int z_SearchRequest(ODR o, Z_SearchRequest **p, int opt)
308 if (!odr_sequence_begin(o, p, sizeof(**p)))
312 z_ReferenceId(o, &pp->referenceId, 1) &&
313 odr_implicit(o, odr_integer, &pp->smallSetUpperBound, ODR_CONTEXT,
315 odr_implicit(o, odr_integer, &pp->largeSetLowerBound, ODR_CONTEXT,
317 odr_implicit(o, odr_integer, &pp->mediumSetPresentNumber, ODR_CONTEXT,
319 odr_implicit(o, odr_bool, &pp->replaceIndicator, ODR_CONTEXT, 16, 1) &&
320 odr_implicit(o, odr_visiblestring, &pp->resultSetName, ODR_CONTEXT,
322 odr_implicit_settag(o, ODR_CONTEXT, 18) &&
323 odr_sequence_of(o, z_DatabaseName, &pp->databaseNames,
324 &pp->num_databaseNames) &&
325 odr_implicit(o, z_ElementSetNames, &pp->smallSetElementSetNames,
326 ODR_CONTEXT, 100, 1) &&
327 odr_implicit(o, z_ElementSetNames, &pp->mediumSetElementSetNames,
328 ODR_CONTEXT, 101, 1) &&
329 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
330 odr_explicit(o, z_Query, &pp->query, ODR_CONTEXT, 21, 0) &&
334 /* ------------------------ RECORD ------------------------- */
336 int z_DatabaseRecord(ODR o, Z_DatabaseRecord **p, int opt)
338 return odr_external(o, (Odr_external **) p, opt);
341 int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
343 if (!odr_sequence_begin(o, p, sizeof(**p)))
346 odr_oid(o, &(*p)->diagnosticSetId, 1) && /* SHOULD NOT BE OPT */
347 odr_integer(o, &(*p)->condition, 0) &&
348 (odr_visiblestring(o, &(*p)->addinfo, 0) ||
349 odr_implicit(o, odr_cstring, &(*p)->addinfo, ODR_CONTEXT, ODR_VISIBLESTRING, 1)) &&
353 int z_NamePlusRecord(ODR o, Z_NamePlusRecord **p, int opt)
355 static Odr_arm arm[] =
357 {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_NamePlusRecord_databaseRecord,
359 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_NamePlusRecord_surrogateDiagnostic,
364 if (!odr_sequence_begin(o, p, sizeof(**p)))
367 odr_implicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
369 odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 1) &&
370 odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
371 odr_constructed_end(o) &&
375 int z_NamePlusRecordList(ODR o, Z_NamePlusRecordList **p, int opt)
377 if (o->direction == ODR_DECODE)
378 *p = nalloc(o, sizeof(**p));
379 if (odr_sequence_of(o, z_NamePlusRecordList, &(*p)->records,
386 int z_Records(ODR o, Z_Records **p, int opt)
390 {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_Records_DBOSD, z_NamePlusRecordList},
391 {ODR_IMPLICIT, ODR_CONTEXT, 130, Z_Records_NSD, z_DiagRec},
395 if (o->direction == ODR_DECODE)
396 *p = nalloc(o, sizeof(**p));
399 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
405 /* ------------------------ SEARCHRESPONSE ----------------*/
407 int z_NumberOfRecordsReturned(ODR o, int **p, int opt)
409 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 24, opt);
412 int z_NextResultSetPosition(ODR o, int **p, int opt)
414 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 25, opt);
417 int z_PresentStatus(ODR o, int **p, int opt)
419 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 27, opt);
422 int z_SearchResponse(ODR o, Z_SearchResponse **p, int opt)
424 Z_SearchResponse *pp;
426 if (!odr_sequence_begin(o, p, sizeof(**p)))
430 z_ReferenceId(o, &pp->referenceId, 1) &&
431 odr_implicit(o, odr_integer, &pp->resultCount, ODR_CONTEXT, 23, 0) &&
432 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
433 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
434 odr_implicit(o, odr_bool, &pp->searchStatus, ODR_CONTEXT, 22, 0) &&
435 odr_implicit(o, odr_integer, &pp->resultSetStatus, ODR_CONTEXT, 26, 1) &&
436 z_PresentStatus(o, &pp->presentStatus, 1) &&
437 z_Records(o, &pp->records, 1) &&
441 /* --------------------- PRESENT SERVICE ---------------------- */
443 int z_PresentRequest(ODR o, Z_PresentRequest **p, int opt)
445 Z_PresentRequest *pp;
447 if (!odr_sequence_begin(o, p, sizeof(**p)))
451 z_ReferenceId(o, &pp->referenceId, 1) &&
452 z_ResultSetId(o, &pp->resultSetId, 0) &&
453 odr_implicit(o, odr_integer, &pp->resultSetStartPoint, ODR_CONTEXT,
455 odr_implicit(o, odr_integer, &pp->numberOfRecordsRequested, ODR_CONTEXT,
457 z_ElementSetNames(o, &pp->elementSetNames, 1) &&
458 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
462 int z_PresentResponse(ODR o, Z_PresentResponse **p, int opt)
464 Z_PresentResponse *pp;
466 if (!odr_sequence_begin(o, p, sizeof(**p)))
470 z_ReferenceId(o, &pp->referenceId, 1) &&
471 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
472 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
473 z_PresentStatus(o, &pp->presentStatus, 0) &&
474 z_Records(o, &pp->records, 1) &&
478 /* ------------------------ APDU ------------------------- */
480 int z_APDU(ODR o, Z_APDU **p, int opt)
482 static Odr_arm arm[] =
484 {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_initRequest, z_InitRequest},
485 {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_initResponse, z_InitResponse},
486 {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_searchRequest, z_SearchRequest},
487 {ODR_IMPLICIT, ODR_CONTEXT, 23, Z_APDU_searchResponse, z_SearchResponse},
488 {ODR_IMPLICIT, ODR_CONTEXT, 24, Z_APDU_presentRequest, z_PresentRequest},
489 {ODR_IMPLICIT, ODR_CONTEXT, 25, Z_APDU_presentResponse, z_PresentResponse},
494 if (o->direction == ODR_DECODE)
495 *p = nalloc(o, sizeof(**p));
496 if (!odr_choice(o, arm, &(*p)->u, &(*p)->which))
498 if (o->direction == ODR_DECODE)