2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.14 1995-03-29 08:06:13 quinn
8 * Added a few v3 elements
10 * Revision 1.13 1995/03/20 11:26:52 quinn
11 * *** empty log message ***
13 * Revision 1.12 1995/03/20 09:45:09 quinn
16 * Revision 1.11 1995/03/17 10:17:25 quinn
17 * Added memory management.
19 * Revision 1.10 1995/03/15 11:17:40 quinn
20 * Fixed some return-checks from choice.. need better ay to handle those..
22 * Revision 1.9 1995/03/15 08:37:06 quinn
23 * Fixed protocol bugs.
25 * Revision 1.8 1995/03/14 16:59:24 quinn
26 * Fixed OPTIONAL flag in attributeelement
28 * Revision 1.7 1995/03/07 16:29:33 quinn
29 * Added authentication stuff.
31 * Revision 1.6 1995/03/01 14:46:03 quinn
32 * Fixed protocol bug in 8777query.
34 * Revision 1.5 1995/02/14 11:54:22 quinn
37 * Revision 1.4 1995/02/10 15:54:30 quinn
40 * Revision 1.3 1995/02/09 15:51:39 quinn
43 * Revision 1.2 1995/02/06 21:26:07 quinn
44 * Repaired this evening's damages..
46 * Revision 1.1 1995/02/06 16:44:47 quinn
47 * First hack at Z/SR protocol
55 /* ---------------------- GLOBAL DEFS ------------------- */
57 int z_ReferenceId(ODR o, Z_ReferenceId **p, int opt)
59 return odr_implicit(o, odr_octetstring, (Odr_oct**) p, ODR_CONTEXT, 2, opt);
62 int z_DatabaseName(ODR o, Z_DatabaseName **p, int opt)
64 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 105,
68 int z_ResultSetId(ODR o, char **p, int opt)
70 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 31,
74 int z_UserInformationField(ODR o, Z_UserInformationField **p, int opt)
76 return odr_explicit(o, odr_external, (Odr_external **)p, ODR_CONTEXT,
80 /* ---------------------- INITIALIZE SERVICE ------------------- */
82 int z_NSRAuthentication(ODR o, Z_NSRAuthentication **p, int opt)
84 if (!odr_sequence_begin(o, p, sizeof(**p)))
87 odr_visiblestring(o, &(*p)->user, 0) &&
88 odr_visiblestring(o, &(*p)->password, 0) &&
89 odr_visiblestring(o, &(*p)->account, 0) &&
93 int z_IdPass(ODR o, Z_IdPass **p, int opt)
95 if (!odr_sequence_begin(o, p, sizeof(**p)))
98 odr_implicit(o, odr_visiblestring, &(*p)->groupId, ODR_CONTEXT, 0, 0) &&
99 odr_implicit(o, odr_visiblestring, &(*p)->userId, ODR_CONTEXT, 1, 0) &&
100 odr_implicit(o, odr_visiblestring, &(*p)->password, ODR_CONTEXT, 2,
105 int z_StrAuthentication(ODR o, char **p, int opt)
107 return odr_visiblestring(o, p, opt);
110 int z_IdAuthentication(ODR o, Z_IdAuthentication **p, int opt)
112 static Odr_arm arm[] =
114 {-1, -1, -1, Z_IdAuthentication_open, z_StrAuthentication},
115 {-1, -1, -1, Z_IdAuthentication_idPass, z_NSRAuthentication},
116 {-1, -1, -1, Z_IdAuthentication_anonymous, odr_null},
117 {-1, -1, -1, Z_IdAuthentication_other, odr_external},
121 if (o->direction == ODR_DECODE)
122 *p = odr_malloc(o, sizeof(**p));
124 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
127 return opt && !o->error;
130 int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
134 if (!odr_sequence_begin(o, p, sizeof(**p)))
138 z_ReferenceId(o, &pp->referenceId, 1) &&
139 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
141 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
142 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
144 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
146 odr_explicit(o, z_IdAuthentication, &pp->idAuthentication, ODR_CONTEXT,
148 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
150 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
152 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
153 ODR_CONTEXT, 112, 1) &&
154 z_UserInformationField(o, &pp->userInformationField, 1) &&
158 int z_InitResponse(ODR o, Z_InitResponse **p, int opt)
162 if (!odr_sequence_begin(o, p, sizeof(**p)))
166 z_ReferenceId(o, &pp->referenceId, 1) &&
167 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
169 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
170 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
172 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
174 odr_implicit(o, odr_bool, &pp->result, ODR_CONTEXT, 12, 0) &&
175 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
177 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
179 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
180 ODR_CONTEXT, 112, 1) &&
181 z_UserInformationField(o, &pp->userInformationField, 1) &&
185 /* ------------------------ SEARCH SERVICE ----------------------- */
187 int z_ElementSetName(ODR o, char **p, int opt)
189 return odr_implicit(o, odr_visiblestring, (char**) p, ODR_CONTEXT, 103,
193 int z_PreferredRecordSyntax(ODR o, Z_PreferredRecordSyntax **p, int opt)
195 return odr_implicit(o, odr_oid, (Odr_oid**) p, ODR_CONTEXT, 104, opt);
198 int z_DatabaseSpecificUnit(ODR o, Z_DatabaseSpecificUnit **p, int opt)
200 if (!odr_sequence_begin(o, p, sizeof(**p)))
203 z_DatabaseName(o, &(*p)->databaseName, 0) &&
204 z_ElementSetName(o, &(*p)->elementSetName, 0) &&
208 int z_DatabaseSpecific(ODR o, Z_DatabaseSpecific **p, int opt)
210 if (o->direction == ODR_DECODE)
211 *p = odr_malloc(o, sizeof(**p));
215 odr_implicit_settag(o, ODR_CONTEXT, 1);
216 if (odr_sequence_of(o, z_DatabaseSpecificUnit, &(*p)->elements,
217 &(*p)->num_elements))
223 int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
225 static Odr_arm arm[] =
227 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_ElementSetNames_generic,
229 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementSetNames_databaseSpecific,
234 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 19))
237 if (o->direction == ODR_DECODE)
238 *p = odr_malloc(o, sizeof(**p));
240 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
241 odr_constructed_end(o))
247 /* ----------------------- RPN QUERY -----------------------*/
249 int z_AttributeElement(ODR o, Z_AttributeElement **p, int opt)
251 if (!odr_sequence_begin(o, p, sizeof(**p)))
254 odr_implicit(o, odr_integer, &(*p)->attributeType, ODR_CONTEXT,
256 odr_implicit(o, odr_integer, &(*p)->attributeValue, ODR_CONTEXT,
261 int z_AttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
263 if (!(odr_implicit_settag(o, ODR_CONTEXT, 102) &&
264 odr_sequence_begin(o, p, sizeof(**p))))
267 odr_implicit_settag(o, ODR_CONTEXT, 44) &&
268 odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
269 &(*p)->num_attributes) &&
270 odr_implicit(o, odr_octetstring, &(*p)->term, ODR_CONTEXT, 45, 0) &&
274 int z_Operator(ODR o, Z_Operator **p, int opt)
276 static Odr_arm arm[] =
278 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_Operator_and, odr_null},
279 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Operator_or, odr_null},
280 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Operator_and_not, odr_null},
285 if (!*p && o->direction != ODR_DECODE)
287 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 46))
289 if (o->direction == ODR_DECODE)
290 *p = odr_malloc(o, sizeof(**p));
292 (*p)->u.and = &dummy;
294 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
295 odr_constructed_end(o))
298 return opt && !o->error;
301 int z_Operand(ODR o, Z_Operand **p, int opt)
303 static Odr_arm arm[] =
305 {-1, -1, -1, Z_Operand_APT, z_AttributesPlusTerm},
306 {-1, -1, -1, Z_Operand_resultSetId, z_ResultSetId},
310 if (o->direction ==ODR_DECODE)
311 *p = odr_malloc(o, sizeof(**p));
314 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
317 return opt && !o->error;
320 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt);
322 int z_Complex(ODR o, Z_Complex **p, int opt)
324 if (!odr_sequence_begin(o, p, sizeof(**p)))
327 z_RPNStructure(o, &(*p)->s1, 0) &&
328 z_RPNStructure(o, &(*p)->s2, 0) &&
329 z_Operator(o, &(*p)->operator, 0) &&
333 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt)
335 static Odr_arm arm[] =
337 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand},
338 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_RPNStructure_complex, z_Complex},
342 if (o->direction == ODR_DECODE)
343 *p = odr_malloc(o, sizeof(**p));
346 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
349 return opt && !o->error;
352 int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
354 if (!odr_sequence_begin(o, p, sizeof(**p)))
357 odr_oid(o, &(*p)->attributeSetId, 0) &&
358 z_RPNStructure(o, &(*p)->RPNStructure, 0) &&
362 /* -----------------------END RPN QUERY ----------------------- */
364 int z_Query(ODR o, Z_Query **p, int opt)
366 static Odr_arm arm[] =
368 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Query_type_1, z_RPNQuery},
369 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_octetstring},
373 if (o->direction == ODR_DECODE)
374 *p = odr_malloc(o, sizeof(**p));
377 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
380 return opt && !o->error;
383 int z_SearchRequest(ODR o, Z_SearchRequest **p, int opt)
387 if (!odr_sequence_begin(o, p, sizeof(**p)))
391 z_ReferenceId(o, &pp->referenceId, 1) &&
392 odr_implicit(o, odr_integer, &pp->smallSetUpperBound, ODR_CONTEXT,
394 odr_implicit(o, odr_integer, &pp->largeSetLowerBound, ODR_CONTEXT,
396 odr_implicit(o, odr_integer, &pp->mediumSetPresentNumber, ODR_CONTEXT,
398 odr_implicit(o, odr_bool, &pp->replaceIndicator, ODR_CONTEXT, 16, 1) &&
399 odr_implicit(o, odr_visiblestring, &pp->resultSetName, ODR_CONTEXT,
401 odr_implicit_settag(o, ODR_CONTEXT, 18) &&
402 odr_sequence_of(o, z_DatabaseName, &pp->databaseNames,
403 &pp->num_databaseNames) &&
404 odr_explicit(o, z_ElementSetNames, &pp->smallSetElementSetNames,
405 ODR_CONTEXT, 100, 1) &&
406 odr_explicit(o, z_ElementSetNames, &pp->mediumSetElementSetNames,
407 ODR_CONTEXT, 101, 1) &&
408 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
409 odr_explicit(o, z_Query, &pp->query, ODR_CONTEXT, 21, 0) &&
413 /* ------------------------ RECORD ------------------------- */
415 int z_DatabaseRecord(ODR o, Z_DatabaseRecord **p, int opt)
417 return odr_external(o, (Odr_external **) p, opt);
420 int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
422 if (!odr_sequence_begin(o, p, sizeof(**p)))
425 odr_oid(o, &(*p)->diagnosticSetId, 1) && /* SHOULD NOT BE OPT */
426 odr_integer(o, &(*p)->condition, 0) &&
427 (odr_visiblestring(o, &(*p)->addinfo, 0) ||
428 odr_implicit(o, odr_cstring, &(*p)->addinfo, ODR_CONTEXT, ODR_VISIBLESTRING, 1)) &&
432 int z_NamePlusRecord(ODR o, Z_NamePlusRecord **p, int opt)
434 static Odr_arm arm[] =
436 {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_NamePlusRecord_databaseRecord,
438 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_NamePlusRecord_surrogateDiagnostic,
443 if (!odr_sequence_begin(o, p, sizeof(**p)))
446 odr_implicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
448 odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 1) &&
449 odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
450 odr_constructed_end(o) &&
454 int z_NamePlusRecordList(ODR o, Z_NamePlusRecordList **p, int opt)
456 if (o->direction == ODR_DECODE)
457 *p = odr_malloc(o, sizeof(**p));
458 if (odr_sequence_of(o, z_NamePlusRecord, &(*p)->records,
465 int z_Records(ODR o, Z_Records **p, int opt)
469 {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_Records_DBOSD, z_NamePlusRecordList},
470 {ODR_IMPLICIT, ODR_CONTEXT, 130, Z_Records_NSD, z_DiagRec},
474 if (o->direction == ODR_DECODE)
475 *p = odr_malloc(o, sizeof(**p));
478 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
481 return opt && !o->error;
484 /* ------------------------ SEARCHRESPONSE ----------------*/
486 int z_NumberOfRecordsReturned(ODR o, int **p, int opt)
488 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 24, opt);
491 int z_NextResultSetPosition(ODR o, int **p, int opt)
493 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 25, opt);
496 int z_PresentStatus(ODR o, int **p, int opt)
498 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 27, opt);
501 int z_SearchResponse(ODR o, Z_SearchResponse **p, int opt)
503 Z_SearchResponse *pp;
505 if (!odr_sequence_begin(o, p, sizeof(**p)))
509 z_ReferenceId(o, &pp->referenceId, 1) &&
510 odr_implicit(o, odr_integer, &pp->resultCount, ODR_CONTEXT, 23, 0) &&
511 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
512 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
513 odr_implicit(o, odr_bool, &pp->searchStatus, ODR_CONTEXT, 22, 0) &&
514 odr_implicit(o, odr_integer, &pp->resultSetStatus, ODR_CONTEXT, 26, 1) &&
515 z_PresentStatus(o, &pp->presentStatus, 1) &&
516 z_Records(o, &pp->records, 1) &&
520 /* --------------------- PRESENT SERVICE ---------------------- */
522 int z_PresentRequest(ODR o, Z_PresentRequest **p, int opt)
524 Z_PresentRequest *pp;
526 if (!odr_sequence_begin(o, p, sizeof(**p)))
530 z_ReferenceId(o, &pp->referenceId, 1) &&
531 z_ResultSetId(o, &pp->resultSetId, 0) &&
532 odr_implicit(o, odr_integer, &pp->resultSetStartPoint, ODR_CONTEXT,
534 odr_implicit(o, odr_integer, &pp->numberOfRecordsRequested, ODR_CONTEXT,
536 z_ElementSetNames(o, &pp->elementSetNames, 1) &&
537 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
541 int z_PresentResponse(ODR o, Z_PresentResponse **p, int opt)
543 Z_PresentResponse *pp;
545 if (!odr_sequence_begin(o, p, sizeof(**p)))
549 z_ReferenceId(o, &pp->referenceId, 1) &&
550 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
551 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
552 z_PresentStatus(o, &pp->presentStatus, 0) &&
553 z_Records(o, &pp->records, 1) &&
557 /* ------------------------ APDU ------------------------- */
559 int z_APDU(ODR o, Z_APDU **p, int opt)
561 static Odr_arm arm[] =
563 {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_initRequest, z_InitRequest},
564 {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_initResponse, z_InitResponse},
565 {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_searchRequest, z_SearchRequest},
566 {ODR_IMPLICIT, ODR_CONTEXT, 23, Z_APDU_searchResponse, z_SearchResponse},
567 {ODR_IMPLICIT, ODR_CONTEXT, 24, Z_APDU_presentRequest, z_PresentRequest},
568 {ODR_IMPLICIT, ODR_CONTEXT, 25, Z_APDU_presentResponse, z_PresentResponse},
573 if (o->direction == ODR_DECODE)
574 *p = odr_malloc(o, sizeof(**p));
575 if (!odr_choice(o, arm, &(*p)->u, &(*p)->which))
577 if (o->direction == ODR_DECODE)
579 return opt && !o->error;