2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.12 1995-03-20 09:45:09 quinn
10 * Revision 1.11 1995/03/17 10:17:25 quinn
11 * Added memory management.
13 * Revision 1.10 1995/03/15 11:17:40 quinn
14 * Fixed some return-checks from choice.. need better ay to handle those..
16 * Revision 1.9 1995/03/15 08:37:06 quinn
17 * Fixed protocol bugs.
19 * Revision 1.8 1995/03/14 16:59:24 quinn
20 * Fixed OPTIONAL flag in attributeelement
22 * Revision 1.7 1995/03/07 16:29:33 quinn
23 * Added authentication stuff.
25 * Revision 1.6 1995/03/01 14:46:03 quinn
26 * Fixed protocol bug in 8777query.
28 * Revision 1.5 1995/02/14 11:54:22 quinn
31 * Revision 1.4 1995/02/10 15:54:30 quinn
34 * Revision 1.3 1995/02/09 15:51:39 quinn
37 * Revision 1.2 1995/02/06 21:26:07 quinn
38 * Repaired this evening's damages..
40 * Revision 1.1 1995/02/06 16:44:47 quinn
41 * First hack at Z/SR protocol
49 /* ---------------------- GLOBAL DEFS ------------------- */
51 int z_ReferenceId(ODR o, Z_ReferenceId **p, int opt)
53 return odr_implicit(o, odr_octetstring, (Odr_oct**) p, ODR_CONTEXT, 2, opt);
56 int z_DatabaseName(ODR o, Z_DatabaseName **p, int opt)
58 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 105,
62 int z_ResultSetId(ODR o, char **p, int opt)
64 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 31,
68 int z_UserInformationField(ODR o, Z_UserInformationField **p, int opt)
70 return odr_explicit(o, odr_external, (Odr_external **)p, ODR_CONTEXT,
74 /* ---------------------- INITIALIZE SERVICE ------------------- */
76 int z_NSRAuthentication(ODR o, Z_NSRAuthentication **p, int opt)
78 if (!odr_sequence_begin(o, p, sizeof(**p)))
81 odr_visiblestring(o, &(*p)->user, 0) &&
82 odr_visiblestring(o, &(*p)->password, 0) &&
83 odr_visiblestring(o, &(*p)->account, 0) &&
87 int z_StrAuthentication(ODR o, char **p, int opt)
89 return odr_visiblestring(o, p, opt);
93 int z_IdAuthentication(ODR o, Z_IdAuthentication **p, int opt)
95 static Odr_arm arm[] =
97 {-1, -1, -1, Z_IdAuthentication_open, z_StrAuthentication},
98 {-1, -1, -1, Z_IdAuthentication_NSR, z_NSRAuthentication},
102 if (o->direction == ODR_DECODE)
103 *p = odr_malloc(o, sizeof(**p));
105 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
108 return opt && !o->error;
112 int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
116 if (!odr_sequence_begin(o, p, sizeof(**p)))
120 z_ReferenceId(o, &pp->referenceId, 1) &&
121 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
123 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
124 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
126 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
128 odr_explicit(o, odr_null, &pp->idAuthentication, ODR_CONTEXT,
130 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
132 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
134 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
135 ODR_CONTEXT, 112, 1) &&
136 z_UserInformationField(o, &pp->userInformationField, 1) &&
140 int z_InitResponse(ODR o, Z_InitResponse **p, int opt)
144 if (!odr_sequence_begin(o, p, sizeof(**p)))
148 z_ReferenceId(o, &pp->referenceId, 1) &&
149 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
151 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
152 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
154 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
156 odr_implicit(o, odr_bool, &pp->result, ODR_CONTEXT, 12, 0) &&
157 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
159 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
161 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
162 ODR_CONTEXT, 112, 1) &&
163 z_UserInformationField(o, &pp->userInformationField, 1) &&
167 /* ------------------------ SEARCH SERVICE ----------------------- */
169 int z_ElementSetName(ODR o, char **p, int opt)
171 return odr_implicit(o, odr_visiblestring, (char**) p, ODR_CONTEXT, 103,
175 int z_PreferredRecordSyntax(ODR o, Z_PreferredRecordSyntax **p, int opt)
177 return odr_implicit(o, odr_oid, (Odr_oid**) p, ODR_CONTEXT, 104, opt);
180 int z_DatabaseSpecificUnit(ODR o, Z_DatabaseSpecificUnit **p, int opt)
182 if (!odr_sequence_begin(o, p, sizeof(**p)))
185 z_DatabaseName(o, &(*p)->databaseName, 0) &&
186 z_ElementSetName(o, &(*p)->elementSetName, 0) &&
190 int z_DatabaseSpecific(ODR o, Z_DatabaseSpecific **p, int opt)
192 if (o->direction == ODR_DECODE)
193 *p = odr_malloc(o, sizeof(**p));
197 odr_implicit_settag(o, ODR_CONTEXT, 1);
198 if (odr_sequence_of(o, z_DatabaseSpecificUnit, &(*p)->elements,
199 &(*p)->num_elements))
205 int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
207 static Odr_arm arm[] =
209 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_ElementSetNames_generic,
211 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementSetNames_databaseSpecific,
216 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 19))
219 if (o->direction == ODR_DECODE)
220 *p = odr_malloc(o, sizeof(**p));
222 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
223 odr_constructed_end(o))
229 /* ----------------------- RPN QUERY -----------------------*/
231 int z_AttributeElement(ODR o, Z_AttributeElement **p, int opt)
233 if (!odr_sequence_begin(o, p, sizeof(**p)))
236 odr_implicit(o, odr_integer, &(*p)->attributeType, ODR_CONTEXT,
238 odr_implicit(o, odr_integer, &(*p)->attributeValue, ODR_CONTEXT,
243 int z_AttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
245 if (!(odr_implicit_settag(o, ODR_CONTEXT, 102) &&
246 odr_sequence_begin(o, p, sizeof(**p))))
249 odr_implicit_settag(o, ODR_CONTEXT, 44) &&
250 odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
251 &(*p)->num_attributes) &&
252 odr_implicit(o, odr_octetstring, &(*p)->term, ODR_CONTEXT, 45, 0) &&
256 int z_Operator(ODR o, Z_Operator **p, int opt)
258 static Odr_arm arm[] =
260 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_Operator_and, odr_null},
261 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Operator_or, odr_null},
262 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Operator_and_not, odr_null},
267 if (!*p && o->direction != ODR_DECODE)
269 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 46))
271 if (o->direction == ODR_DECODE)
272 *p = odr_malloc(o, sizeof(**p));
274 (*p)->u.and = &dummy;
276 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
277 odr_constructed_end(o))
280 return opt && !o->error;
283 int z_Operand(ODR o, Z_Operand **p, int opt)
285 static Odr_arm arm[] =
287 {-1, -1, -1, Z_Operand_APT, z_AttributesPlusTerm},
288 {-1, -1, -1, Z_Operand_resultSetId, z_ResultSetId},
292 if (o->direction ==ODR_DECODE)
293 *p = odr_malloc(o, sizeof(**p));
296 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
299 return opt && !o->error;
302 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt);
304 int z_Complex(ODR o, Z_Complex **p, int opt)
306 if (!odr_sequence_begin(o, p, sizeof(**p)))
309 z_RPNStructure(o, &(*p)->s1, 0) &&
310 z_RPNStructure(o, &(*p)->s2, 0) &&
311 z_Operator(o, &(*p)->operator, 0) &&
315 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt)
317 static Odr_arm arm[] =
319 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand},
320 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_RPNStructure_complex, z_Complex},
324 if (o->direction == ODR_DECODE)
325 *p = odr_malloc(o, sizeof(**p));
328 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
331 return opt && !o->error;
334 int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
336 if (!odr_sequence_begin(o, p, sizeof(**p)))
339 odr_oid(o, &(*p)->attributeSetId, 0) &&
340 z_RPNStructure(o, &(*p)->RPNStructure, 0) &&
344 /* -----------------------END RPN QUERY ----------------------- */
346 int z_Query(ODR o, Z_Query **p, int opt)
348 static Odr_arm arm[] =
350 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Query_type_1, z_RPNQuery},
351 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_octetstring},
355 if (o->direction == ODR_DECODE)
356 *p = odr_malloc(o, sizeof(**p));
359 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
362 return opt && !o->error;
365 int z_SearchRequest(ODR o, Z_SearchRequest **p, int opt)
369 if (!odr_sequence_begin(o, p, sizeof(**p)))
373 z_ReferenceId(o, &pp->referenceId, 1) &&
374 odr_implicit(o, odr_integer, &pp->smallSetUpperBound, ODR_CONTEXT,
376 odr_implicit(o, odr_integer, &pp->largeSetLowerBound, ODR_CONTEXT,
378 odr_implicit(o, odr_integer, &pp->mediumSetPresentNumber, ODR_CONTEXT,
380 odr_implicit(o, odr_bool, &pp->replaceIndicator, ODR_CONTEXT, 16, 1) &&
381 odr_implicit(o, odr_visiblestring, &pp->resultSetName, ODR_CONTEXT,
383 odr_implicit_settag(o, ODR_CONTEXT, 18) &&
384 odr_sequence_of(o, z_DatabaseName, &pp->databaseNames,
385 &pp->num_databaseNames) &&
386 odr_implicit(o, z_ElementSetNames, &pp->smallSetElementSetNames,
387 ODR_CONTEXT, 100, 1) &&
388 odr_implicit(o, z_ElementSetNames, &pp->mediumSetElementSetNames,
389 ODR_CONTEXT, 101, 1) &&
390 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
391 odr_explicit(o, z_Query, &pp->query, ODR_CONTEXT, 21, 0) &&
395 /* ------------------------ RECORD ------------------------- */
397 int z_DatabaseRecord(ODR o, Z_DatabaseRecord **p, int opt)
399 return odr_external(o, (Odr_external **) p, opt);
402 int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
404 if (!odr_sequence_begin(o, p, sizeof(**p)))
407 odr_oid(o, &(*p)->diagnosticSetId, 1) && /* SHOULD NOT BE OPT */
408 odr_integer(o, &(*p)->condition, 0) &&
409 (odr_visiblestring(o, &(*p)->addinfo, 0) ||
410 odr_implicit(o, odr_cstring, &(*p)->addinfo, ODR_CONTEXT, ODR_VISIBLESTRING, 1)) &&
414 int z_NamePlusRecord(ODR o, Z_NamePlusRecord **p, int opt)
416 static Odr_arm arm[] =
418 {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_NamePlusRecord_databaseRecord,
420 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_NamePlusRecord_surrogateDiagnostic,
425 if (!odr_sequence_begin(o, p, sizeof(**p)))
428 odr_implicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
430 odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 1) &&
431 odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
432 odr_constructed_end(o) &&
436 int z_NamePlusRecordList(ODR o, Z_NamePlusRecordList **p, int opt)
438 if (o->direction == ODR_DECODE)
439 *p = odr_malloc(o, sizeof(**p));
440 if (odr_sequence_of(o, z_NamePlusRecord, &(*p)->records,
447 int z_Records(ODR o, Z_Records **p, int opt)
451 {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_Records_DBOSD, z_NamePlusRecordList},
452 {ODR_IMPLICIT, ODR_CONTEXT, 130, Z_Records_NSD, z_DiagRec},
456 if (o->direction == ODR_DECODE)
457 *p = odr_malloc(o, sizeof(**p));
460 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
463 return opt && !o->error;
466 /* ------------------------ SEARCHRESPONSE ----------------*/
468 int z_NumberOfRecordsReturned(ODR o, int **p, int opt)
470 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 24, opt);
473 int z_NextResultSetPosition(ODR o, int **p, int opt)
475 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 25, opt);
478 int z_PresentStatus(ODR o, int **p, int opt)
480 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 27, opt);
483 int z_SearchResponse(ODR o, Z_SearchResponse **p, int opt)
485 Z_SearchResponse *pp;
487 if (!odr_sequence_begin(o, p, sizeof(**p)))
491 z_ReferenceId(o, &pp->referenceId, 1) &&
492 odr_implicit(o, odr_integer, &pp->resultCount, ODR_CONTEXT, 23, 0) &&
493 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
494 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
495 odr_implicit(o, odr_bool, &pp->searchStatus, ODR_CONTEXT, 22, 0) &&
496 odr_implicit(o, odr_integer, &pp->resultSetStatus, ODR_CONTEXT, 26, 1) &&
497 z_PresentStatus(o, &pp->presentStatus, 1) &&
498 z_Records(o, &pp->records, 1) &&
502 /* --------------------- PRESENT SERVICE ---------------------- */
504 int z_PresentRequest(ODR o, Z_PresentRequest **p, int opt)
506 Z_PresentRequest *pp;
508 if (!odr_sequence_begin(o, p, sizeof(**p)))
512 z_ReferenceId(o, &pp->referenceId, 1) &&
513 z_ResultSetId(o, &pp->resultSetId, 0) &&
514 odr_implicit(o, odr_integer, &pp->resultSetStartPoint, ODR_CONTEXT,
516 odr_implicit(o, odr_integer, &pp->numberOfRecordsRequested, ODR_CONTEXT,
518 z_ElementSetNames(o, &pp->elementSetNames, 1) &&
519 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
523 int z_PresentResponse(ODR o, Z_PresentResponse **p, int opt)
525 Z_PresentResponse *pp;
527 if (!odr_sequence_begin(o, p, sizeof(**p)))
531 z_ReferenceId(o, &pp->referenceId, 1) &&
532 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
533 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
534 z_PresentStatus(o, &pp->presentStatus, 0) &&
535 z_Records(o, &pp->records, 1) &&
539 /* ------------------------ APDU ------------------------- */
541 int z_APDU(ODR o, Z_APDU **p, int opt)
543 static Odr_arm arm[] =
545 {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_initRequest, z_InitRequest},
546 {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_initResponse, z_InitResponse},
547 {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_searchRequest, z_SearchRequest},
548 {ODR_IMPLICIT, ODR_CONTEXT, 23, Z_APDU_searchResponse, z_SearchResponse},
549 {ODR_IMPLICIT, ODR_CONTEXT, 24, Z_APDU_presentRequest, z_PresentRequest},
550 {ODR_IMPLICIT, ODR_CONTEXT, 25, Z_APDU_presentResponse, z_PresentResponse},
555 if (o->direction == ODR_DECODE)
556 *p = odr_malloc(o, sizeof(**p));
557 if (!odr_choice(o, arm, &(*p)->u, &(*p)->which))
559 if (o->direction == ODR_DECODE)
561 return opt && !o->error;