2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.5 1995-02-14 11:54:22 quinn
10 * Revision 1.4 1995/02/10 15:54:30 quinn
13 * Revision 1.3 1995/02/09 15:51:39 quinn
16 * Revision 1.2 1995/02/06 21:26:07 quinn
17 * Repaired this evening's damages..
19 * Revision 1.1 1995/02/06 16:44:47 quinn
20 * First hack at Z/SR protocol
28 /* ---------------------- GLOBAL DEFS ------------------- */
30 int z_ReferenceId(ODR o, Z_ReferenceId **p, int opt)
32 return odr_implicit(o, odr_octetstring, (Odr_oct**) p, ODR_CONTEXT, 2, opt);
35 int z_DatabaseName(ODR o, Z_DatabaseName **p, int opt)
37 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 105,
41 int z_ResultSetId(ODR o, char **p, int opt)
43 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 31,
47 int z_UserInformationField(ODR o, Z_UserInformationField **p, int opt)
49 return odr_explicit(o, odr_external, (Odr_external **)p, ODR_CONTEXT,
53 /* ---------------------- INITIALIZE SERVICE ------------------- */
55 int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
59 if (!odr_sequence_begin(o, p, sizeof(**p)))
63 z_ReferenceId(o, &pp->referenceId, 1) &&
64 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
66 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
67 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
69 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
71 odr_implicit(o, odr_visiblestring, &pp->idAuthentication, ODR_CONTEXT,
73 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
75 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
77 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
78 ODR_CONTEXT, 112, 1) &&
79 z_UserInformationField(o, &pp->userInformationField, 1) &&
83 int z_InitResponse(ODR o, Z_InitResponse **p, int opt)
87 if (!odr_sequence_begin(o, p, sizeof(**p)))
91 z_ReferenceId(o, &pp->referenceId, 1) &&
92 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
94 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
95 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
97 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
99 odr_implicit(o, odr_bool, &pp->result, ODR_CONTEXT, 12, 0) &&
100 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
102 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
104 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
105 ODR_CONTEXT, 112, 1) &&
106 z_UserInformationField(o, &pp->userInformationField, 1) &&
110 /* ------------------------ SEARCH SERVICE ----------------------- */
112 int z_ElementSetName(ODR o, char **p, int opt)
114 return odr_implicit(o, odr_visiblestring, (char**) p, ODR_CONTEXT, 103,
118 int z_PreferredRecordSyntax(ODR o, Z_PreferredRecordSyntax **p, int opt)
120 return odr_implicit(o, odr_oid, (Odr_oid**) p, ODR_CONTEXT, 104, opt);
123 int z_DatabaseSpecificUnit(ODR o, Z_DatabaseSpecificUnit **p, int opt)
125 if (!odr_sequence_begin(o, p, sizeof(**p)))
128 z_DatabaseName(o, &(*p)->databaseName, 0) &&
129 z_ElementSetName(o, &(*p)->elementSetName, 0) &&
133 int z_DatabaseSpecific(ODR o, Z_DatabaseSpecific **p, int opt)
135 if (o->direction == ODR_DECODE)
136 *p = nalloc(o, sizeof(**p));
140 odr_implicit_settag(o, ODR_CONTEXT, 1);
141 if (odr_sequence_of(o, z_DatabaseSpecificUnit, &(*p)->elements,
142 &(*p)->num_elements))
148 int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
150 static Odr_arm arm[] =
152 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_ElementSetNames_generic,
154 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementSetNames_databaseSpecific,
159 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 19))
162 if (o->direction == ODR_DECODE)
163 *p = nalloc(o, sizeof(**p));
165 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
166 odr_constructed_end(o))
172 /* ----------------------- RPN QUERY -----------------------*/
174 int z_AttributeElement(ODR o, Z_AttributeElement **p, int opt)
176 if (!odr_sequence_begin(o, p, sizeof(**p)))
179 odr_implicit(o, odr_integer, &(*p)->attributeType, ODR_CONTEXT,
181 odr_implicit(o, odr_integer, &(*p)->attributeValue, ODR_CONTEXT,
186 int z_AttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
188 if (!(odr_implicit_settag(o, ODR_CONTEXT, 102) &&
189 odr_sequence_begin(o, p, sizeof(**p))))
192 odr_implicit_settag(o, ODR_CONTEXT, 44) &&
193 odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
194 &(*p)->num_attributes) &&
195 odr_implicit(o, odr_octetstring, &(*p)->term, ODR_CONTEXT, 45, 0) &&
199 int z_Operator(ODR o, Z_Operator **p, int opt)
201 static Odr_arm arm[] =
203 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_Operator_and, odr_null},
204 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Operator_or, odr_null},
205 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Operator_and_not, odr_null},
210 if (!*p && o->direction != ODR_DECODE)
212 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 46))
214 if (o->direction == ODR_DECODE)
215 *p = nalloc(o, sizeof(**p));
217 (*p)->u.and = &dummy;
219 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
220 odr_constructed_end(o))
226 int z_Operand(ODR o, Z_Operand **p, int opt)
228 static Odr_arm arm[] =
230 {-1, -1, -1, Z_Operand_APT, z_AttributesPlusTerm},
231 {-1, -1, -1, Z_Operand_resultSetId, z_ResultSetId},
235 if (o->direction ==ODR_DECODE)
236 *p = nalloc(o, sizeof(**p));
239 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
245 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt);
247 int z_Complex(ODR o, Z_Complex **p, int opt)
249 if (!odr_sequence_begin(o, p, sizeof(**p)))
252 z_RPNStructure(o, &(*p)->s1, 0) &&
253 z_RPNStructure(o, &(*p)->s2, 0) &&
254 z_Operator(o, &(*p)->operator, 0) &&
258 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt)
260 static Odr_arm arm[] =
262 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand},
263 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_RPNStructure_complex, z_Complex},
267 if (o->direction == ODR_DECODE)
268 *p = nalloc(o, sizeof(**p));
271 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
277 int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
279 if (!odr_sequence_begin(o, p, sizeof(**p)))
282 odr_oid(o, &(*p)->attributeSetId, 0) &&
283 z_RPNStructure(o, &(*p)->RPNStructure, 0) &&
287 /* -----------------------END RPN QUERY ----------------------- */
289 int z_Query(ODR o, Z_Query **p, int opt)
291 static Odr_arm arm[] =
293 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Query_type_1, z_RPNQuery},
294 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_octetstring},
298 if (o->direction == ODR_DECODE)
299 *p = nalloc(o, sizeof(**p));
302 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
308 int z_SearchRequest(ODR o, Z_SearchRequest **p, int opt)
312 if (!odr_sequence_begin(o, p, sizeof(**p)))
316 z_ReferenceId(o, &pp->referenceId, 1) &&
317 odr_implicit(o, odr_integer, &pp->smallSetUpperBound, ODR_CONTEXT,
319 odr_implicit(o, odr_integer, &pp->largeSetLowerBound, ODR_CONTEXT,
321 odr_implicit(o, odr_integer, &pp->mediumSetPresentNumber, ODR_CONTEXT,
323 odr_implicit(o, odr_bool, &pp->replaceIndicator, ODR_CONTEXT, 16, 1) &&
324 odr_implicit(o, odr_visiblestring, &pp->resultSetName, ODR_CONTEXT,
326 odr_implicit_settag(o, ODR_CONTEXT, 18) &&
327 odr_sequence_of(o, z_DatabaseName, &pp->databaseNames,
328 &pp->num_databaseNames) &&
329 odr_implicit(o, z_ElementSetNames, &pp->smallSetElementSetNames,
330 ODR_CONTEXT, 100, 1) &&
331 odr_implicit(o, z_ElementSetNames, &pp->mediumSetElementSetNames,
332 ODR_CONTEXT, 101, 1) &&
333 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
334 odr_explicit(o, z_Query, &pp->query, ODR_CONTEXT, 21, 0) &&
338 /* ------------------------ RECORD ------------------------- */
340 int z_DatabaseRecord(ODR o, Z_DatabaseRecord **p, int opt)
342 return odr_external(o, (Odr_external **) p, opt);
345 int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
347 if (!odr_sequence_begin(o, p, sizeof(**p)))
350 odr_oid(o, &(*p)->diagnosticSetId, 1) && /* SHOULD NOT BE OPT */
351 odr_integer(o, &(*p)->condition, 0) &&
352 (odr_visiblestring(o, &(*p)->addinfo, 0) ||
353 odr_implicit(o, odr_cstring, &(*p)->addinfo, ODR_CONTEXT, ODR_VISIBLESTRING, 1)) &&
357 int z_NamePlusRecord(ODR o, Z_NamePlusRecord **p, int opt)
359 static Odr_arm arm[] =
361 {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_NamePlusRecord_databaseRecord,
363 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_NamePlusRecord_surrogateDiagnostic,
368 if (!odr_sequence_begin(o, p, sizeof(**p)))
371 odr_implicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
373 odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 1) &&
374 odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
375 odr_constructed_end(o) &&
379 int z_NamePlusRecordList(ODR o, Z_NamePlusRecordList **p, int opt)
381 if (o->direction == ODR_DECODE)
382 *p = nalloc(o, sizeof(**p));
383 if (odr_sequence_of(o, z_NamePlusRecord, &(*p)->records,
390 int z_Records(ODR o, Z_Records **p, int opt)
394 {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_Records_DBOSD, z_NamePlusRecordList},
395 {ODR_IMPLICIT, ODR_CONTEXT, 130, Z_Records_NSD, z_DiagRec},
399 if (o->direction == ODR_DECODE)
400 *p = nalloc(o, sizeof(**p));
403 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
409 /* ------------------------ SEARCHRESPONSE ----------------*/
411 int z_NumberOfRecordsReturned(ODR o, int **p, int opt)
413 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 24, opt);
416 int z_NextResultSetPosition(ODR o, int **p, int opt)
418 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 25, opt);
421 int z_PresentStatus(ODR o, int **p, int opt)
423 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 27, opt);
426 int z_SearchResponse(ODR o, Z_SearchResponse **p, int opt)
428 Z_SearchResponse *pp;
430 if (!odr_sequence_begin(o, p, sizeof(**p)))
434 z_ReferenceId(o, &pp->referenceId, 1) &&
435 odr_implicit(o, odr_integer, &pp->resultCount, ODR_CONTEXT, 23, 0) &&
436 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
437 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
438 odr_implicit(o, odr_bool, &pp->searchStatus, ODR_CONTEXT, 22, 0) &&
439 odr_implicit(o, odr_integer, &pp->resultSetStatus, ODR_CONTEXT, 26, 1) &&
440 z_PresentStatus(o, &pp->presentStatus, 1) &&
441 z_Records(o, &pp->records, 1) &&
445 /* --------------------- PRESENT SERVICE ---------------------- */
447 int z_PresentRequest(ODR o, Z_PresentRequest **p, int opt)
449 Z_PresentRequest *pp;
451 if (!odr_sequence_begin(o, p, sizeof(**p)))
455 z_ReferenceId(o, &pp->referenceId, 1) &&
456 z_ResultSetId(o, &pp->resultSetId, 0) &&
457 odr_implicit(o, odr_integer, &pp->resultSetStartPoint, ODR_CONTEXT,
459 odr_implicit(o, odr_integer, &pp->numberOfRecordsRequested, ODR_CONTEXT,
461 z_ElementSetNames(o, &pp->elementSetNames, 1) &&
462 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
466 int z_PresentResponse(ODR o, Z_PresentResponse **p, int opt)
468 Z_PresentResponse *pp;
470 if (!odr_sequence_begin(o, p, sizeof(**p)))
474 z_ReferenceId(o, &pp->referenceId, 1) &&
475 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
476 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
477 z_PresentStatus(o, &pp->presentStatus, 0) &&
478 z_Records(o, &pp->records, 1) &&
482 /* ------------------------ APDU ------------------------- */
484 int z_APDU(ODR o, Z_APDU **p, int opt)
486 static Odr_arm arm[] =
488 {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_initRequest, z_InitRequest},
489 {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_initResponse, z_InitResponse},
490 {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_searchRequest, z_SearchRequest},
491 {ODR_IMPLICIT, ODR_CONTEXT, 23, Z_APDU_searchResponse, z_SearchResponse},
492 {ODR_IMPLICIT, ODR_CONTEXT, 24, Z_APDU_presentRequest, z_PresentRequest},
493 {ODR_IMPLICIT, ODR_CONTEXT, 25, Z_APDU_presentResponse, z_PresentResponse},
498 if (o->direction == ODR_DECODE)
499 *p = nalloc(o, sizeof(**p));
500 if (!odr_choice(o, arm, &(*p)->u, &(*p)->which))
502 if (o->direction == ODR_DECODE)