2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.10 1995-03-15 11:17:40 quinn
8 * Fixed some return-checks from choice.. need better ay to handle those..
10 * Revision 1.9 1995/03/15 08:37:06 quinn
11 * Fixed protocol bugs.
13 * Revision 1.8 1995/03/14 16:59:24 quinn
14 * Fixed OPTIONAL flag in attributeelement
16 * Revision 1.7 1995/03/07 16:29:33 quinn
17 * Added authentication stuff.
19 * Revision 1.6 1995/03/01 14:46:03 quinn
20 * Fixed protocol bug in 8777query.
22 * Revision 1.5 1995/02/14 11:54:22 quinn
25 * Revision 1.4 1995/02/10 15:54:30 quinn
28 * Revision 1.3 1995/02/09 15:51:39 quinn
31 * Revision 1.2 1995/02/06 21:26:07 quinn
32 * Repaired this evening's damages..
34 * Revision 1.1 1995/02/06 16:44:47 quinn
35 * First hack at Z/SR protocol
43 /* ---------------------- GLOBAL DEFS ------------------- */
45 int z_ReferenceId(ODR o, Z_ReferenceId **p, int opt)
47 return odr_implicit(o, odr_octetstring, (Odr_oct**) p, ODR_CONTEXT, 2, opt);
50 int z_DatabaseName(ODR o, Z_DatabaseName **p, int opt)
52 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 105,
56 int z_ResultSetId(ODR o, char **p, int opt)
58 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 31,
62 int z_UserInformationField(ODR o, Z_UserInformationField **p, int opt)
64 return odr_explicit(o, odr_external, (Odr_external **)p, ODR_CONTEXT,
68 /* ---------------------- INITIALIZE SERVICE ------------------- */
70 int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
74 if (!odr_sequence_begin(o, p, sizeof(**p)))
78 z_ReferenceId(o, &pp->referenceId, 1) &&
79 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
81 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
82 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
84 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
86 odr_explicit(o, odr_any, &pp->idAuthentication, ODR_CONTEXT,
88 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
90 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
92 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
93 ODR_CONTEXT, 112, 1) &&
94 z_UserInformationField(o, &pp->userInformationField, 1) &&
98 int z_InitResponse(ODR o, Z_InitResponse **p, int opt)
102 if (!odr_sequence_begin(o, p, sizeof(**p)))
106 z_ReferenceId(o, &pp->referenceId, 1) &&
107 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
109 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
110 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
112 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
114 odr_implicit(o, odr_bool, &pp->result, ODR_CONTEXT, 12, 0) &&
115 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
117 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
119 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
120 ODR_CONTEXT, 112, 1) &&
121 z_UserInformationField(o, &pp->userInformationField, 1) &&
125 int z_NSRAuthentication(ODR o, Z_NSRAuthentication **p, int opt)
127 if (!odr_sequence_begin(o, p, sizeof(**p)))
130 odr_visiblestring(o, &(*p)->user, 0) &&
131 odr_visiblestring(o, &(*p)->password, 0) &&
132 odr_visiblestring(o, &(*p)->account, 0) &&
136 int z_StrAuthentication(ODR o, char **p, int opt)
138 return odr_visiblestring(o, p, opt);
141 /* ------------------------ SEARCH SERVICE ----------------------- */
143 int z_ElementSetName(ODR o, char **p, int opt)
145 return odr_implicit(o, odr_visiblestring, (char**) p, ODR_CONTEXT, 103,
149 int z_PreferredRecordSyntax(ODR o, Z_PreferredRecordSyntax **p, int opt)
151 return odr_implicit(o, odr_oid, (Odr_oid**) p, ODR_CONTEXT, 104, opt);
154 int z_DatabaseSpecificUnit(ODR o, Z_DatabaseSpecificUnit **p, int opt)
156 if (!odr_sequence_begin(o, p, sizeof(**p)))
159 z_DatabaseName(o, &(*p)->databaseName, 0) &&
160 z_ElementSetName(o, &(*p)->elementSetName, 0) &&
164 int z_DatabaseSpecific(ODR o, Z_DatabaseSpecific **p, int opt)
166 if (o->direction == ODR_DECODE)
167 *p = nalloc(o, sizeof(**p));
171 odr_implicit_settag(o, ODR_CONTEXT, 1);
172 if (odr_sequence_of(o, z_DatabaseSpecificUnit, &(*p)->elements,
173 &(*p)->num_elements))
179 int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
181 static Odr_arm arm[] =
183 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_ElementSetNames_generic,
185 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementSetNames_databaseSpecific,
190 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 19))
193 if (o->direction == ODR_DECODE)
194 *p = nalloc(o, sizeof(**p));
196 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
197 odr_constructed_end(o))
203 /* ----------------------- RPN QUERY -----------------------*/
205 int z_AttributeElement(ODR o, Z_AttributeElement **p, int opt)
207 if (!odr_sequence_begin(o, p, sizeof(**p)))
210 odr_implicit(o, odr_integer, &(*p)->attributeType, ODR_CONTEXT,
212 odr_implicit(o, odr_integer, &(*p)->attributeValue, ODR_CONTEXT,
217 int z_AttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
219 if (!(odr_implicit_settag(o, ODR_CONTEXT, 102) &&
220 odr_sequence_begin(o, p, sizeof(**p))))
223 odr_implicit_settag(o, ODR_CONTEXT, 44) &&
224 odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
225 &(*p)->num_attributes) &&
226 odr_implicit(o, odr_octetstring, &(*p)->term, ODR_CONTEXT, 45, 0) &&
230 int z_Operator(ODR o, Z_Operator **p, int opt)
232 static Odr_arm arm[] =
234 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_Operator_and, odr_null},
235 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Operator_or, odr_null},
236 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Operator_and_not, odr_null},
241 if (!*p && o->direction != ODR_DECODE)
243 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 46))
245 if (o->direction == ODR_DECODE)
246 *p = nalloc(o, sizeof(**p));
248 (*p)->u.and = &dummy;
250 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
251 odr_constructed_end(o))
254 return opt && !o->error;
257 int z_Operand(ODR o, Z_Operand **p, int opt)
259 static Odr_arm arm[] =
261 {-1, -1, -1, Z_Operand_APT, z_AttributesPlusTerm},
262 {-1, -1, -1, Z_Operand_resultSetId, z_ResultSetId},
266 if (o->direction ==ODR_DECODE)
267 *p = nalloc(o, sizeof(**p));
270 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
273 return opt && !o->error;
276 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt);
278 int z_Complex(ODR o, Z_Complex **p, int opt)
280 if (!odr_sequence_begin(o, p, sizeof(**p)))
283 z_RPNStructure(o, &(*p)->s1, 0) &&
284 z_RPNStructure(o, &(*p)->s2, 0) &&
285 z_Operator(o, &(*p)->operator, 0) &&
289 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt)
291 static Odr_arm arm[] =
293 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand},
294 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_RPNStructure_complex, z_Complex},
298 if (o->direction == ODR_DECODE)
299 *p = nalloc(o, sizeof(**p));
302 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
305 return opt && !o->error;
308 int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
310 if (!odr_sequence_begin(o, p, sizeof(**p)))
313 odr_oid(o, &(*p)->attributeSetId, 0) &&
314 z_RPNStructure(o, &(*p)->RPNStructure, 0) &&
318 /* -----------------------END RPN QUERY ----------------------- */
320 int z_Query(ODR o, Z_Query **p, int opt)
322 static Odr_arm arm[] =
324 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Query_type_1, z_RPNQuery},
325 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_octetstring},
329 if (o->direction == ODR_DECODE)
330 *p = nalloc(o, sizeof(**p));
333 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
336 return opt && !o->error;
339 int z_SearchRequest(ODR o, Z_SearchRequest **p, int opt)
343 if (!odr_sequence_begin(o, p, sizeof(**p)))
347 z_ReferenceId(o, &pp->referenceId, 1) &&
348 odr_implicit(o, odr_integer, &pp->smallSetUpperBound, ODR_CONTEXT,
350 odr_implicit(o, odr_integer, &pp->largeSetLowerBound, ODR_CONTEXT,
352 odr_implicit(o, odr_integer, &pp->mediumSetPresentNumber, ODR_CONTEXT,
354 odr_implicit(o, odr_bool, &pp->replaceIndicator, ODR_CONTEXT, 16, 1) &&
355 odr_implicit(o, odr_visiblestring, &pp->resultSetName, ODR_CONTEXT,
357 odr_implicit_settag(o, ODR_CONTEXT, 18) &&
358 odr_sequence_of(o, z_DatabaseName, &pp->databaseNames,
359 &pp->num_databaseNames) &&
360 odr_implicit(o, z_ElementSetNames, &pp->smallSetElementSetNames,
361 ODR_CONTEXT, 100, 1) &&
362 odr_implicit(o, z_ElementSetNames, &pp->mediumSetElementSetNames,
363 ODR_CONTEXT, 101, 1) &&
364 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
365 odr_explicit(o, z_Query, &pp->query, ODR_CONTEXT, 21, 0) &&
369 /* ------------------------ RECORD ------------------------- */
371 int z_DatabaseRecord(ODR o, Z_DatabaseRecord **p, int opt)
373 return odr_external(o, (Odr_external **) p, opt);
376 int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
378 if (!odr_sequence_begin(o, p, sizeof(**p)))
381 odr_oid(o, &(*p)->diagnosticSetId, 1) && /* SHOULD NOT BE OPT */
382 odr_integer(o, &(*p)->condition, 0) &&
383 (odr_visiblestring(o, &(*p)->addinfo, 0) ||
384 odr_implicit(o, odr_cstring, &(*p)->addinfo, ODR_CONTEXT, ODR_VISIBLESTRING, 1)) &&
388 int z_NamePlusRecord(ODR o, Z_NamePlusRecord **p, int opt)
390 static Odr_arm arm[] =
392 {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_NamePlusRecord_databaseRecord,
394 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_NamePlusRecord_surrogateDiagnostic,
399 if (!odr_sequence_begin(o, p, sizeof(**p)))
402 odr_implicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
404 odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 1) &&
405 odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
406 odr_constructed_end(o) &&
410 int z_NamePlusRecordList(ODR o, Z_NamePlusRecordList **p, int opt)
412 if (o->direction == ODR_DECODE)
413 *p = nalloc(o, sizeof(**p));
414 if (odr_sequence_of(o, z_NamePlusRecord, &(*p)->records,
421 int z_Records(ODR o, Z_Records **p, int opt)
425 {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_Records_DBOSD, z_NamePlusRecordList},
426 {ODR_IMPLICIT, ODR_CONTEXT, 130, Z_Records_NSD, z_DiagRec},
430 if (o->direction == ODR_DECODE)
431 *p = nalloc(o, sizeof(**p));
434 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
437 return opt && !o->error;
440 /* ------------------------ SEARCHRESPONSE ----------------*/
442 int z_NumberOfRecordsReturned(ODR o, int **p, int opt)
444 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 24, opt);
447 int z_NextResultSetPosition(ODR o, int **p, int opt)
449 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 25, opt);
452 int z_PresentStatus(ODR o, int **p, int opt)
454 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 27, opt);
457 int z_SearchResponse(ODR o, Z_SearchResponse **p, int opt)
459 Z_SearchResponse *pp;
461 if (!odr_sequence_begin(o, p, sizeof(**p)))
465 z_ReferenceId(o, &pp->referenceId, 1) &&
466 odr_implicit(o, odr_integer, &pp->resultCount, ODR_CONTEXT, 23, 0) &&
467 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
468 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
469 odr_implicit(o, odr_bool, &pp->searchStatus, ODR_CONTEXT, 22, 0) &&
470 odr_implicit(o, odr_integer, &pp->resultSetStatus, ODR_CONTEXT, 26, 1) &&
471 z_PresentStatus(o, &pp->presentStatus, 1) &&
472 z_Records(o, &pp->records, 1) &&
476 /* --------------------- PRESENT SERVICE ---------------------- */
478 int z_PresentRequest(ODR o, Z_PresentRequest **p, int opt)
480 Z_PresentRequest *pp;
482 if (!odr_sequence_begin(o, p, sizeof(**p)))
486 z_ReferenceId(o, &pp->referenceId, 1) &&
487 z_ResultSetId(o, &pp->resultSetId, 0) &&
488 odr_implicit(o, odr_integer, &pp->resultSetStartPoint, ODR_CONTEXT,
490 odr_implicit(o, odr_integer, &pp->numberOfRecordsRequested, ODR_CONTEXT,
492 z_ElementSetNames(o, &pp->elementSetNames, 1) &&
493 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
497 int z_PresentResponse(ODR o, Z_PresentResponse **p, int opt)
499 Z_PresentResponse *pp;
501 if (!odr_sequence_begin(o, p, sizeof(**p)))
505 z_ReferenceId(o, &pp->referenceId, 1) &&
506 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
507 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
508 z_PresentStatus(o, &pp->presentStatus, 0) &&
509 z_Records(o, &pp->records, 1) &&
513 /* ------------------------ APDU ------------------------- */
515 int z_APDU(ODR o, Z_APDU **p, int opt)
517 static Odr_arm arm[] =
519 {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_initRequest, z_InitRequest},
520 {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_initResponse, z_InitResponse},
521 {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_searchRequest, z_SearchRequest},
522 {ODR_IMPLICIT, ODR_CONTEXT, 23, Z_APDU_searchResponse, z_SearchResponse},
523 {ODR_IMPLICIT, ODR_CONTEXT, 24, Z_APDU_presentRequest, z_PresentRequest},
524 {ODR_IMPLICIT, ODR_CONTEXT, 25, Z_APDU_presentResponse, z_PresentResponse},
529 if (o->direction == ODR_DECODE)
530 *p = nalloc(o, sizeof(**p));
531 if (!odr_choice(o, arm, &(*p)->u, &(*p)->which))
533 if (o->direction == ODR_DECODE)
535 return opt && !o->error;