2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.9 1995-03-15 08:37:06 quinn
10 * Revision 1.8 1995/03/14 16:59:24 quinn
11 * Fixed OPTIONAL flag in attributeelement
13 * Revision 1.7 1995/03/07 16:29:33 quinn
14 * Added authentication stuff.
16 * Revision 1.6 1995/03/01 14:46:03 quinn
17 * Fixed protocol bug in 8777query.
19 * Revision 1.5 1995/02/14 11:54:22 quinn
22 * Revision 1.4 1995/02/10 15:54:30 quinn
25 * Revision 1.3 1995/02/09 15:51:39 quinn
28 * Revision 1.2 1995/02/06 21:26:07 quinn
29 * Repaired this evening's damages..
31 * Revision 1.1 1995/02/06 16:44:47 quinn
32 * First hack at Z/SR protocol
40 /* ---------------------- GLOBAL DEFS ------------------- */
42 int z_ReferenceId(ODR o, Z_ReferenceId **p, int opt)
44 return odr_implicit(o, odr_octetstring, (Odr_oct**) p, ODR_CONTEXT, 2, opt);
47 int z_DatabaseName(ODR o, Z_DatabaseName **p, int opt)
49 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 105,
53 int z_ResultSetId(ODR o, char **p, int opt)
55 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 31,
59 int z_UserInformationField(ODR o, Z_UserInformationField **p, int opt)
61 return odr_explicit(o, odr_external, (Odr_external **)p, ODR_CONTEXT,
65 /* ---------------------- INITIALIZE SERVICE ------------------- */
67 int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
71 if (!odr_sequence_begin(o, p, sizeof(**p)))
75 z_ReferenceId(o, &pp->referenceId, 1) &&
76 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
78 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
79 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
81 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
83 odr_explicit(o, odr_any, &pp->idAuthentication, ODR_CONTEXT,
85 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
87 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
89 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
90 ODR_CONTEXT, 112, 1) &&
91 z_UserInformationField(o, &pp->userInformationField, 1) &&
95 int z_InitResponse(ODR o, Z_InitResponse **p, int opt)
99 if (!odr_sequence_begin(o, p, sizeof(**p)))
103 z_ReferenceId(o, &pp->referenceId, 1) &&
104 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
106 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
107 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
109 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
111 odr_implicit(o, odr_bool, &pp->result, ODR_CONTEXT, 12, 0) &&
112 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
114 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
116 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
117 ODR_CONTEXT, 112, 1) &&
118 z_UserInformationField(o, &pp->userInformationField, 1) &&
122 int z_NSRAuthentication(ODR o, Z_NSRAuthentication **p, int opt)
124 if (!odr_sequence_begin(o, p, sizeof(**p)))
127 odr_visiblestring(o, &(*p)->user, 0) &&
128 odr_visiblestring(o, &(*p)->password, 0) &&
129 odr_visiblestring(o, &(*p)->account, 0) &&
133 int z_StrAuthentication(ODR o, char **p, int opt)
135 return odr_visiblestring(o, p, opt);
138 /* ------------------------ SEARCH SERVICE ----------------------- */
140 int z_ElementSetName(ODR o, char **p, int opt)
142 return odr_implicit(o, odr_visiblestring, (char**) p, ODR_CONTEXT, 103,
146 int z_PreferredRecordSyntax(ODR o, Z_PreferredRecordSyntax **p, int opt)
148 return odr_implicit(o, odr_oid, (Odr_oid**) p, ODR_CONTEXT, 104, opt);
151 int z_DatabaseSpecificUnit(ODR o, Z_DatabaseSpecificUnit **p, int opt)
153 if (!odr_sequence_begin(o, p, sizeof(**p)))
156 z_DatabaseName(o, &(*p)->databaseName, 0) &&
157 z_ElementSetName(o, &(*p)->elementSetName, 0) &&
161 int z_DatabaseSpecific(ODR o, Z_DatabaseSpecific **p, int opt)
163 if (o->direction == ODR_DECODE)
164 *p = nalloc(o, sizeof(**p));
168 odr_implicit_settag(o, ODR_CONTEXT, 1);
169 if (odr_sequence_of(o, z_DatabaseSpecificUnit, &(*p)->elements,
170 &(*p)->num_elements))
176 int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
178 static Odr_arm arm[] =
180 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_ElementSetNames_generic,
182 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementSetNames_databaseSpecific,
187 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 19))
190 if (o->direction == ODR_DECODE)
191 *p = nalloc(o, sizeof(**p));
193 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
194 odr_constructed_end(o))
200 /* ----------------------- RPN QUERY -----------------------*/
202 int z_AttributeElement(ODR o, Z_AttributeElement **p, int opt)
204 if (!odr_sequence_begin(o, p, sizeof(**p)))
207 odr_implicit(o, odr_integer, &(*p)->attributeType, ODR_CONTEXT,
209 odr_implicit(o, odr_integer, &(*p)->attributeValue, ODR_CONTEXT,
214 int z_AttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
216 if (!(odr_implicit_settag(o, ODR_CONTEXT, 102) &&
217 odr_sequence_begin(o, p, sizeof(**p))))
220 odr_implicit_settag(o, ODR_CONTEXT, 44) &&
221 odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
222 &(*p)->num_attributes) &&
223 odr_implicit(o, odr_octetstring, &(*p)->term, ODR_CONTEXT, 45, 0) &&
227 int z_Operator(ODR o, Z_Operator **p, int opt)
229 static Odr_arm arm[] =
231 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_Operator_and, odr_null},
232 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Operator_or, odr_null},
233 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Operator_and_not, odr_null},
238 if (!*p && o->direction != ODR_DECODE)
240 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 46))
242 if (o->direction == ODR_DECODE)
243 *p = nalloc(o, sizeof(**p));
245 (*p)->u.and = &dummy;
247 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
248 odr_constructed_end(o))
254 int z_Operand(ODR o, Z_Operand **p, int opt)
256 static Odr_arm arm[] =
258 {-1, -1, -1, Z_Operand_APT, z_AttributesPlusTerm},
259 {-1, -1, -1, Z_Operand_resultSetId, z_ResultSetId},
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_RPNStructure(ODR o, Z_RPNStructure **p, int opt);
275 int z_Complex(ODR o, Z_Complex **p, int opt)
277 if (!odr_sequence_begin(o, p, sizeof(**p)))
280 z_RPNStructure(o, &(*p)->s1, 0) &&
281 z_RPNStructure(o, &(*p)->s2, 0) &&
282 z_Operator(o, &(*p)->operator, 0) &&
286 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt)
288 static Odr_arm arm[] =
290 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand},
291 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_RPNStructure_complex, z_Complex},
295 if (o->direction == ODR_DECODE)
296 *p = nalloc(o, sizeof(**p));
299 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
305 int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
307 if (!odr_sequence_begin(o, p, sizeof(**p)))
310 odr_oid(o, &(*p)->attributeSetId, 0) &&
311 z_RPNStructure(o, &(*p)->RPNStructure, 0) &&
315 /* -----------------------END RPN QUERY ----------------------- */
317 int z_Query(ODR o, Z_Query **p, int opt)
319 static Odr_arm arm[] =
321 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Query_type_1, z_RPNQuery},
322 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_octetstring},
326 if (o->direction == ODR_DECODE)
327 *p = nalloc(o, sizeof(**p));
330 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
336 int z_SearchRequest(ODR o, Z_SearchRequest **p, int opt)
340 if (!odr_sequence_begin(o, p, sizeof(**p)))
344 z_ReferenceId(o, &pp->referenceId, 1) &&
345 odr_implicit(o, odr_integer, &pp->smallSetUpperBound, ODR_CONTEXT,
347 odr_implicit(o, odr_integer, &pp->largeSetLowerBound, ODR_CONTEXT,
349 odr_implicit(o, odr_integer, &pp->mediumSetPresentNumber, ODR_CONTEXT,
351 odr_implicit(o, odr_bool, &pp->replaceIndicator, ODR_CONTEXT, 16, 1) &&
352 odr_implicit(o, odr_visiblestring, &pp->resultSetName, ODR_CONTEXT,
354 odr_implicit_settag(o, ODR_CONTEXT, 18) &&
355 odr_sequence_of(o, z_DatabaseName, &pp->databaseNames,
356 &pp->num_databaseNames) &&
357 odr_implicit(o, z_ElementSetNames, &pp->smallSetElementSetNames,
358 ODR_CONTEXT, 100, 1) &&
359 odr_implicit(o, z_ElementSetNames, &pp->mediumSetElementSetNames,
360 ODR_CONTEXT, 101, 1) &&
361 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
362 odr_explicit(o, z_Query, &pp->query, ODR_CONTEXT, 21, 0) &&
366 /* ------------------------ RECORD ------------------------- */
368 int z_DatabaseRecord(ODR o, Z_DatabaseRecord **p, int opt)
370 return odr_external(o, (Odr_external **) p, opt);
373 int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
375 if (!odr_sequence_begin(o, p, sizeof(**p)))
378 odr_oid(o, &(*p)->diagnosticSetId, 1) && /* SHOULD NOT BE OPT */
379 odr_integer(o, &(*p)->condition, 0) &&
380 (odr_visiblestring(o, &(*p)->addinfo, 0) ||
381 odr_implicit(o, odr_cstring, &(*p)->addinfo, ODR_CONTEXT, ODR_VISIBLESTRING, 1)) &&
385 int z_NamePlusRecord(ODR o, Z_NamePlusRecord **p, int opt)
387 static Odr_arm arm[] =
389 {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_NamePlusRecord_databaseRecord,
391 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_NamePlusRecord_surrogateDiagnostic,
396 if (!odr_sequence_begin(o, p, sizeof(**p)))
399 odr_implicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
401 odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 1) &&
402 odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
403 odr_constructed_end(o) &&
407 int z_NamePlusRecordList(ODR o, Z_NamePlusRecordList **p, int opt)
409 if (o->direction == ODR_DECODE)
410 *p = nalloc(o, sizeof(**p));
411 if (odr_sequence_of(o, z_NamePlusRecord, &(*p)->records,
418 int z_Records(ODR o, Z_Records **p, int opt)
422 {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_Records_DBOSD, z_NamePlusRecordList},
423 {ODR_IMPLICIT, ODR_CONTEXT, 130, Z_Records_NSD, z_DiagRec},
427 if (o->direction == ODR_DECODE)
428 *p = nalloc(o, sizeof(**p));
431 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
437 /* ------------------------ SEARCHRESPONSE ----------------*/
439 int z_NumberOfRecordsReturned(ODR o, int **p, int opt)
441 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 24, opt);
444 int z_NextResultSetPosition(ODR o, int **p, int opt)
446 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 25, opt);
449 int z_PresentStatus(ODR o, int **p, int opt)
451 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 27, opt);
454 int z_SearchResponse(ODR o, Z_SearchResponse **p, int opt)
456 Z_SearchResponse *pp;
458 if (!odr_sequence_begin(o, p, sizeof(**p)))
462 z_ReferenceId(o, &pp->referenceId, 1) &&
463 odr_implicit(o, odr_integer, &pp->resultCount, ODR_CONTEXT, 23, 0) &&
464 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
465 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
466 odr_implicit(o, odr_bool, &pp->searchStatus, ODR_CONTEXT, 22, 0) &&
467 odr_implicit(o, odr_integer, &pp->resultSetStatus, ODR_CONTEXT, 26, 1) &&
468 z_PresentStatus(o, &pp->presentStatus, 1) &&
469 z_Records(o, &pp->records, 1) &&
473 /* --------------------- PRESENT SERVICE ---------------------- */
475 int z_PresentRequest(ODR o, Z_PresentRequest **p, int opt)
477 Z_PresentRequest *pp;
479 if (!odr_sequence_begin(o, p, sizeof(**p)))
483 z_ReferenceId(o, &pp->referenceId, 1) &&
484 z_ResultSetId(o, &pp->resultSetId, 0) &&
485 odr_implicit(o, odr_integer, &pp->resultSetStartPoint, ODR_CONTEXT,
487 odr_implicit(o, odr_integer, &pp->numberOfRecordsRequested, ODR_CONTEXT,
489 z_ElementSetNames(o, &pp->elementSetNames, 1) &&
490 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
494 int z_PresentResponse(ODR o, Z_PresentResponse **p, int opt)
496 Z_PresentResponse *pp;
498 if (!odr_sequence_begin(o, p, sizeof(**p)))
502 z_ReferenceId(o, &pp->referenceId, 1) &&
503 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
504 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
505 z_PresentStatus(o, &pp->presentStatus, 0) &&
506 z_Records(o, &pp->records, 1) &&
510 /* ------------------------ APDU ------------------------- */
512 int z_APDU(ODR o, Z_APDU **p, int opt)
514 static Odr_arm arm[] =
516 {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_initRequest, z_InitRequest},
517 {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_initResponse, z_InitResponse},
518 {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_searchRequest, z_SearchRequest},
519 {ODR_IMPLICIT, ODR_CONTEXT, 23, Z_APDU_searchResponse, z_SearchResponse},
520 {ODR_IMPLICIT, ODR_CONTEXT, 24, Z_APDU_presentRequest, z_PresentRequest},
521 {ODR_IMPLICIT, ODR_CONTEXT, 25, Z_APDU_presentResponse, z_PresentResponse},
526 if (o->direction == ODR_DECODE)
527 *p = nalloc(o, sizeof(**p));
528 if (!odr_choice(o, arm, &(*p)->u, &(*p)->which))
530 if (o->direction == ODR_DECODE)