2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.11 1995-03-17 10:17:25 quinn
8 * Added memory management.
10 * Revision 1.10 1995/03/15 11:17:40 quinn
11 * Fixed some return-checks from choice.. need better ay to handle those..
13 * Revision 1.9 1995/03/15 08:37:06 quinn
14 * Fixed protocol bugs.
16 * Revision 1.8 1995/03/14 16:59:24 quinn
17 * Fixed OPTIONAL flag in attributeelement
19 * Revision 1.7 1995/03/07 16:29:33 quinn
20 * Added authentication stuff.
22 * Revision 1.6 1995/03/01 14:46:03 quinn
23 * Fixed protocol bug in 8777query.
25 * Revision 1.5 1995/02/14 11:54:22 quinn
28 * Revision 1.4 1995/02/10 15:54:30 quinn
31 * Revision 1.3 1995/02/09 15:51:39 quinn
34 * Revision 1.2 1995/02/06 21:26:07 quinn
35 * Repaired this evening's damages..
37 * Revision 1.1 1995/02/06 16:44:47 quinn
38 * First hack at Z/SR protocol
46 /* ---------------------- GLOBAL DEFS ------------------- */
48 int z_ReferenceId(ODR o, Z_ReferenceId **p, int opt)
50 return odr_implicit(o, odr_octetstring, (Odr_oct**) p, ODR_CONTEXT, 2, opt);
53 int z_DatabaseName(ODR o, Z_DatabaseName **p, int opt)
55 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 105,
59 int z_ResultSetId(ODR o, char **p, int opt)
61 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 31,
65 int z_UserInformationField(ODR o, Z_UserInformationField **p, int opt)
67 return odr_explicit(o, odr_external, (Odr_external **)p, ODR_CONTEXT,
71 /* ---------------------- INITIALIZE SERVICE ------------------- */
73 int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
77 if (!odr_sequence_begin(o, p, sizeof(**p)))
81 z_ReferenceId(o, &pp->referenceId, 1) &&
82 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
84 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
85 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
87 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
89 odr_explicit(o, odr_any, &pp->idAuthentication, ODR_CONTEXT,
91 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
93 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
95 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
96 ODR_CONTEXT, 112, 1) &&
97 z_UserInformationField(o, &pp->userInformationField, 1) &&
101 int z_InitResponse(ODR o, Z_InitResponse **p, int opt)
105 if (!odr_sequence_begin(o, p, sizeof(**p)))
109 z_ReferenceId(o, &pp->referenceId, 1) &&
110 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
112 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
113 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
115 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
117 odr_implicit(o, odr_bool, &pp->result, ODR_CONTEXT, 12, 0) &&
118 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
120 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
122 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
123 ODR_CONTEXT, 112, 1) &&
124 z_UserInformationField(o, &pp->userInformationField, 1) &&
128 int z_NSRAuthentication(ODR o, Z_NSRAuthentication **p, int opt)
130 if (!odr_sequence_begin(o, p, sizeof(**p)))
133 odr_visiblestring(o, &(*p)->user, 0) &&
134 odr_visiblestring(o, &(*p)->password, 0) &&
135 odr_visiblestring(o, &(*p)->account, 0) &&
139 int z_StrAuthentication(ODR o, char **p, int opt)
141 return odr_visiblestring(o, p, opt);
144 /* ------------------------ SEARCH SERVICE ----------------------- */
146 int z_ElementSetName(ODR o, char **p, int opt)
148 return odr_implicit(o, odr_visiblestring, (char**) p, ODR_CONTEXT, 103,
152 int z_PreferredRecordSyntax(ODR o, Z_PreferredRecordSyntax **p, int opt)
154 return odr_implicit(o, odr_oid, (Odr_oid**) p, ODR_CONTEXT, 104, opt);
157 int z_DatabaseSpecificUnit(ODR o, Z_DatabaseSpecificUnit **p, int opt)
159 if (!odr_sequence_begin(o, p, sizeof(**p)))
162 z_DatabaseName(o, &(*p)->databaseName, 0) &&
163 z_ElementSetName(o, &(*p)->elementSetName, 0) &&
167 int z_DatabaseSpecific(ODR o, Z_DatabaseSpecific **p, int opt)
169 if (o->direction == ODR_DECODE)
170 *p = odr_malloc(o, sizeof(**p));
174 odr_implicit_settag(o, ODR_CONTEXT, 1);
175 if (odr_sequence_of(o, z_DatabaseSpecificUnit, &(*p)->elements,
176 &(*p)->num_elements))
182 int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
184 static Odr_arm arm[] =
186 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_ElementSetNames_generic,
188 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementSetNames_databaseSpecific,
193 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 19))
196 if (o->direction == ODR_DECODE)
197 *p = odr_malloc(o, sizeof(**p));
199 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
200 odr_constructed_end(o))
206 /* ----------------------- RPN QUERY -----------------------*/
208 int z_AttributeElement(ODR o, Z_AttributeElement **p, int opt)
210 if (!odr_sequence_begin(o, p, sizeof(**p)))
213 odr_implicit(o, odr_integer, &(*p)->attributeType, ODR_CONTEXT,
215 odr_implicit(o, odr_integer, &(*p)->attributeValue, ODR_CONTEXT,
220 int z_AttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
222 if (!(odr_implicit_settag(o, ODR_CONTEXT, 102) &&
223 odr_sequence_begin(o, p, sizeof(**p))))
226 odr_implicit_settag(o, ODR_CONTEXT, 44) &&
227 odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
228 &(*p)->num_attributes) &&
229 odr_implicit(o, odr_octetstring, &(*p)->term, ODR_CONTEXT, 45, 0) &&
233 int z_Operator(ODR o, Z_Operator **p, int opt)
235 static Odr_arm arm[] =
237 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_Operator_and, odr_null},
238 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Operator_or, odr_null},
239 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Operator_and_not, odr_null},
244 if (!*p && o->direction != ODR_DECODE)
246 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 46))
248 if (o->direction == ODR_DECODE)
249 *p = odr_malloc(o, sizeof(**p));
251 (*p)->u.and = &dummy;
253 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
254 odr_constructed_end(o))
257 return opt && !o->error;
260 int z_Operand(ODR o, Z_Operand **p, int opt)
262 static Odr_arm arm[] =
264 {-1, -1, -1, Z_Operand_APT, z_AttributesPlusTerm},
265 {-1, -1, -1, Z_Operand_resultSetId, z_ResultSetId},
269 if (o->direction ==ODR_DECODE)
270 *p = odr_malloc(o, sizeof(**p));
273 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
276 return opt && !o->error;
279 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt);
281 int z_Complex(ODR o, Z_Complex **p, int opt)
283 if (!odr_sequence_begin(o, p, sizeof(**p)))
286 z_RPNStructure(o, &(*p)->s1, 0) &&
287 z_RPNStructure(o, &(*p)->s2, 0) &&
288 z_Operator(o, &(*p)->operator, 0) &&
292 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt)
294 static Odr_arm arm[] =
296 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand},
297 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_RPNStructure_complex, z_Complex},
301 if (o->direction == ODR_DECODE)
302 *p = odr_malloc(o, sizeof(**p));
305 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
308 return opt && !o->error;
311 int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
313 if (!odr_sequence_begin(o, p, sizeof(**p)))
316 odr_oid(o, &(*p)->attributeSetId, 0) &&
317 z_RPNStructure(o, &(*p)->RPNStructure, 0) &&
321 /* -----------------------END RPN QUERY ----------------------- */
323 int z_Query(ODR o, Z_Query **p, int opt)
325 static Odr_arm arm[] =
327 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Query_type_1, z_RPNQuery},
328 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_octetstring},
332 if (o->direction == ODR_DECODE)
333 *p = odr_malloc(o, sizeof(**p));
336 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
339 return opt && !o->error;
342 int z_SearchRequest(ODR o, Z_SearchRequest **p, int opt)
346 if (!odr_sequence_begin(o, p, sizeof(**p)))
350 z_ReferenceId(o, &pp->referenceId, 1) &&
351 odr_implicit(o, odr_integer, &pp->smallSetUpperBound, ODR_CONTEXT,
353 odr_implicit(o, odr_integer, &pp->largeSetLowerBound, ODR_CONTEXT,
355 odr_implicit(o, odr_integer, &pp->mediumSetPresentNumber, ODR_CONTEXT,
357 odr_implicit(o, odr_bool, &pp->replaceIndicator, ODR_CONTEXT, 16, 1) &&
358 odr_implicit(o, odr_visiblestring, &pp->resultSetName, ODR_CONTEXT,
360 odr_implicit_settag(o, ODR_CONTEXT, 18) &&
361 odr_sequence_of(o, z_DatabaseName, &pp->databaseNames,
362 &pp->num_databaseNames) &&
363 odr_implicit(o, z_ElementSetNames, &pp->smallSetElementSetNames,
364 ODR_CONTEXT, 100, 1) &&
365 odr_implicit(o, z_ElementSetNames, &pp->mediumSetElementSetNames,
366 ODR_CONTEXT, 101, 1) &&
367 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
368 odr_explicit(o, z_Query, &pp->query, ODR_CONTEXT, 21, 0) &&
372 /* ------------------------ RECORD ------------------------- */
374 int z_DatabaseRecord(ODR o, Z_DatabaseRecord **p, int opt)
376 return odr_external(o, (Odr_external **) p, opt);
379 int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
381 if (!odr_sequence_begin(o, p, sizeof(**p)))
384 odr_oid(o, &(*p)->diagnosticSetId, 1) && /* SHOULD NOT BE OPT */
385 odr_integer(o, &(*p)->condition, 0) &&
386 (odr_visiblestring(o, &(*p)->addinfo, 0) ||
387 odr_implicit(o, odr_cstring, &(*p)->addinfo, ODR_CONTEXT, ODR_VISIBLESTRING, 1)) &&
391 int z_NamePlusRecord(ODR o, Z_NamePlusRecord **p, int opt)
393 static Odr_arm arm[] =
395 {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_NamePlusRecord_databaseRecord,
397 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_NamePlusRecord_surrogateDiagnostic,
402 if (!odr_sequence_begin(o, p, sizeof(**p)))
405 odr_implicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
407 odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 1) &&
408 odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
409 odr_constructed_end(o) &&
413 int z_NamePlusRecordList(ODR o, Z_NamePlusRecordList **p, int opt)
415 if (o->direction == ODR_DECODE)
416 *p = odr_malloc(o, sizeof(**p));
417 if (odr_sequence_of(o, z_NamePlusRecord, &(*p)->records,
424 int z_Records(ODR o, Z_Records **p, int opt)
428 {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_Records_DBOSD, z_NamePlusRecordList},
429 {ODR_IMPLICIT, ODR_CONTEXT, 130, Z_Records_NSD, z_DiagRec},
433 if (o->direction == ODR_DECODE)
434 *p = odr_malloc(o, sizeof(**p));
437 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
440 return opt && !o->error;
443 /* ------------------------ SEARCHRESPONSE ----------------*/
445 int z_NumberOfRecordsReturned(ODR o, int **p, int opt)
447 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 24, opt);
450 int z_NextResultSetPosition(ODR o, int **p, int opt)
452 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 25, opt);
455 int z_PresentStatus(ODR o, int **p, int opt)
457 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 27, opt);
460 int z_SearchResponse(ODR o, Z_SearchResponse **p, int opt)
462 Z_SearchResponse *pp;
464 if (!odr_sequence_begin(o, p, sizeof(**p)))
468 z_ReferenceId(o, &pp->referenceId, 1) &&
469 odr_implicit(o, odr_integer, &pp->resultCount, ODR_CONTEXT, 23, 0) &&
470 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
471 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
472 odr_implicit(o, odr_bool, &pp->searchStatus, ODR_CONTEXT, 22, 0) &&
473 odr_implicit(o, odr_integer, &pp->resultSetStatus, ODR_CONTEXT, 26, 1) &&
474 z_PresentStatus(o, &pp->presentStatus, 1) &&
475 z_Records(o, &pp->records, 1) &&
479 /* --------------------- PRESENT SERVICE ---------------------- */
481 int z_PresentRequest(ODR o, Z_PresentRequest **p, int opt)
483 Z_PresentRequest *pp;
485 if (!odr_sequence_begin(o, p, sizeof(**p)))
489 z_ReferenceId(o, &pp->referenceId, 1) &&
490 z_ResultSetId(o, &pp->resultSetId, 0) &&
491 odr_implicit(o, odr_integer, &pp->resultSetStartPoint, ODR_CONTEXT,
493 odr_implicit(o, odr_integer, &pp->numberOfRecordsRequested, ODR_CONTEXT,
495 z_ElementSetNames(o, &pp->elementSetNames, 1) &&
496 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
500 int z_PresentResponse(ODR o, Z_PresentResponse **p, int opt)
502 Z_PresentResponse *pp;
504 if (!odr_sequence_begin(o, p, sizeof(**p)))
508 z_ReferenceId(o, &pp->referenceId, 1) &&
509 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
510 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
511 z_PresentStatus(o, &pp->presentStatus, 0) &&
512 z_Records(o, &pp->records, 1) &&
516 /* ------------------------ APDU ------------------------- */
518 int z_APDU(ODR o, Z_APDU **p, int opt)
520 static Odr_arm arm[] =
522 {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_initRequest, z_InitRequest},
523 {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_initResponse, z_InitResponse},
524 {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_searchRequest, z_SearchRequest},
525 {ODR_IMPLICIT, ODR_CONTEXT, 23, Z_APDU_searchResponse, z_SearchResponse},
526 {ODR_IMPLICIT, ODR_CONTEXT, 24, Z_APDU_presentRequest, z_PresentRequest},
527 {ODR_IMPLICIT, ODR_CONTEXT, 25, Z_APDU_presentResponse, z_PresentResponse},
532 if (o->direction == ODR_DECODE)
533 *p = odr_malloc(o, sizeof(**p));
534 if (!odr_choice(o, arm, &(*p)->u, &(*p)->which))
536 if (o->direction == ODR_DECODE)
538 return opt && !o->error;