2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.13 1995-03-20 11:26:52 quinn
8 * *** empty log message ***
10 * Revision 1.12 1995/03/20 09:45:09 quinn
13 * Revision 1.11 1995/03/17 10:17:25 quinn
14 * Added memory management.
16 * Revision 1.10 1995/03/15 11:17:40 quinn
17 * Fixed some return-checks from choice.. need better ay to handle those..
19 * Revision 1.9 1995/03/15 08:37:06 quinn
20 * Fixed protocol bugs.
22 * Revision 1.8 1995/03/14 16:59:24 quinn
23 * Fixed OPTIONAL flag in attributeelement
25 * Revision 1.7 1995/03/07 16:29:33 quinn
26 * Added authentication stuff.
28 * Revision 1.6 1995/03/01 14:46:03 quinn
29 * Fixed protocol bug in 8777query.
31 * Revision 1.5 1995/02/14 11:54:22 quinn
34 * Revision 1.4 1995/02/10 15:54:30 quinn
37 * Revision 1.3 1995/02/09 15:51:39 quinn
40 * Revision 1.2 1995/02/06 21:26:07 quinn
41 * Repaired this evening's damages..
43 * Revision 1.1 1995/02/06 16:44:47 quinn
44 * First hack at Z/SR protocol
52 /* ---------------------- GLOBAL DEFS ------------------- */
54 int z_ReferenceId(ODR o, Z_ReferenceId **p, int opt)
56 return odr_implicit(o, odr_octetstring, (Odr_oct**) p, ODR_CONTEXT, 2, opt);
59 int z_DatabaseName(ODR o, Z_DatabaseName **p, int opt)
61 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 105,
65 int z_ResultSetId(ODR o, char **p, int opt)
67 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 31,
71 int z_UserInformationField(ODR o, Z_UserInformationField **p, int opt)
73 return odr_explicit(o, odr_external, (Odr_external **)p, ODR_CONTEXT,
77 /* ---------------------- INITIALIZE SERVICE ------------------- */
79 int z_NSRAuthentication(ODR o, Z_NSRAuthentication **p, int opt)
81 if (!odr_sequence_begin(o, p, sizeof(**p)))
84 odr_visiblestring(o, &(*p)->user, 0) &&
85 odr_visiblestring(o, &(*p)->password, 0) &&
86 odr_visiblestring(o, &(*p)->account, 0) &&
90 int z_StrAuthentication(ODR o, char **p, int opt)
92 return odr_visiblestring(o, p, opt);
96 int z_IdAuthentication(ODR o, Z_IdAuthentication **p, int opt)
98 static Odr_arm arm[] =
100 {-1, -1, -1, Z_IdAuthentication_open, z_StrAuthentication},
101 {-1, -1, -1, Z_IdAuthentication_NSR, z_NSRAuthentication},
105 if (o->direction == ODR_DECODE)
106 *p = odr_malloc(o, sizeof(**p));
108 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
111 return opt && !o->error;
115 int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
119 if (!odr_sequence_begin(o, p, sizeof(**p)))
123 z_ReferenceId(o, &pp->referenceId, 1) &&
124 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
126 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
127 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
129 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
131 odr_explicit(o, odr_null, &pp->idAuthentication, ODR_CONTEXT,
133 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
135 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
137 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
138 ODR_CONTEXT, 112, 1) &&
139 z_UserInformationField(o, &pp->userInformationField, 1) &&
143 int z_InitResponse(ODR o, Z_InitResponse **p, int opt)
147 if (!odr_sequence_begin(o, p, sizeof(**p)))
151 z_ReferenceId(o, &pp->referenceId, 1) &&
152 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
154 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
155 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
157 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
159 odr_implicit(o, odr_bool, &pp->result, ODR_CONTEXT, 12, 0) &&
160 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
162 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
164 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
165 ODR_CONTEXT, 112, 1) &&
166 z_UserInformationField(o, &pp->userInformationField, 1) &&
170 /* ------------------------ SEARCH SERVICE ----------------------- */
172 int z_ElementSetName(ODR o, char **p, int opt)
174 return odr_implicit(o, odr_visiblestring, (char**) p, ODR_CONTEXT, 103,
178 int z_PreferredRecordSyntax(ODR o, Z_PreferredRecordSyntax **p, int opt)
180 return odr_implicit(o, odr_oid, (Odr_oid**) p, ODR_CONTEXT, 104, opt);
183 int z_DatabaseSpecificUnit(ODR o, Z_DatabaseSpecificUnit **p, int opt)
185 if (!odr_sequence_begin(o, p, sizeof(**p)))
188 z_DatabaseName(o, &(*p)->databaseName, 0) &&
189 z_ElementSetName(o, &(*p)->elementSetName, 0) &&
193 int z_DatabaseSpecific(ODR o, Z_DatabaseSpecific **p, int opt)
195 if (o->direction == ODR_DECODE)
196 *p = odr_malloc(o, sizeof(**p));
200 odr_implicit_settag(o, ODR_CONTEXT, 1);
201 if (odr_sequence_of(o, z_DatabaseSpecificUnit, &(*p)->elements,
202 &(*p)->num_elements))
208 int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
210 static Odr_arm arm[] =
212 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_ElementSetNames_generic,
214 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementSetNames_databaseSpecific,
219 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 19))
222 if (o->direction == ODR_DECODE)
223 *p = odr_malloc(o, sizeof(**p));
225 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
226 odr_constructed_end(o))
232 /* ----------------------- RPN QUERY -----------------------*/
234 int z_AttributeElement(ODR o, Z_AttributeElement **p, int opt)
236 if (!odr_sequence_begin(o, p, sizeof(**p)))
239 odr_implicit(o, odr_integer, &(*p)->attributeType, ODR_CONTEXT,
241 odr_implicit(o, odr_integer, &(*p)->attributeValue, ODR_CONTEXT,
246 int z_AttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
248 if (!(odr_implicit_settag(o, ODR_CONTEXT, 102) &&
249 odr_sequence_begin(o, p, sizeof(**p))))
252 odr_implicit_settag(o, ODR_CONTEXT, 44) &&
253 odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
254 &(*p)->num_attributes) &&
255 odr_implicit(o, odr_octetstring, &(*p)->term, ODR_CONTEXT, 45, 0) &&
259 int z_Operator(ODR o, Z_Operator **p, int opt)
261 static Odr_arm arm[] =
263 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_Operator_and, odr_null},
264 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Operator_or, odr_null},
265 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Operator_and_not, odr_null},
270 if (!*p && o->direction != ODR_DECODE)
272 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 46))
274 if (o->direction == ODR_DECODE)
275 *p = odr_malloc(o, sizeof(**p));
277 (*p)->u.and = &dummy;
279 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
280 odr_constructed_end(o))
283 return opt && !o->error;
286 int z_Operand(ODR o, Z_Operand **p, int opt)
288 static Odr_arm arm[] =
290 {-1, -1, -1, Z_Operand_APT, z_AttributesPlusTerm},
291 {-1, -1, -1, Z_Operand_resultSetId, z_ResultSetId},
295 if (o->direction ==ODR_DECODE)
296 *p = odr_malloc(o, sizeof(**p));
299 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
302 return opt && !o->error;
305 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt);
307 int z_Complex(ODR o, Z_Complex **p, int opt)
309 if (!odr_sequence_begin(o, p, sizeof(**p)))
312 z_RPNStructure(o, &(*p)->s1, 0) &&
313 z_RPNStructure(o, &(*p)->s2, 0) &&
314 z_Operator(o, &(*p)->operator, 0) &&
318 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt)
320 static Odr_arm arm[] =
322 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand},
323 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_RPNStructure_complex, z_Complex},
327 if (o->direction == ODR_DECODE)
328 *p = odr_malloc(o, sizeof(**p));
331 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
334 return opt && !o->error;
337 int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
339 if (!odr_sequence_begin(o, p, sizeof(**p)))
342 odr_oid(o, &(*p)->attributeSetId, 0) &&
343 z_RPNStructure(o, &(*p)->RPNStructure, 0) &&
347 /* -----------------------END RPN QUERY ----------------------- */
349 int z_Query(ODR o, Z_Query **p, int opt)
351 static Odr_arm arm[] =
353 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Query_type_1, z_RPNQuery},
354 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_octetstring},
358 if (o->direction == ODR_DECODE)
359 *p = odr_malloc(o, sizeof(**p));
362 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
365 return opt && !o->error;
368 int z_SearchRequest(ODR o, Z_SearchRequest **p, int opt)
372 if (!odr_sequence_begin(o, p, sizeof(**p)))
376 z_ReferenceId(o, &pp->referenceId, 1) &&
377 odr_implicit(o, odr_integer, &pp->smallSetUpperBound, ODR_CONTEXT,
379 odr_implicit(o, odr_integer, &pp->largeSetLowerBound, ODR_CONTEXT,
381 odr_implicit(o, odr_integer, &pp->mediumSetPresentNumber, ODR_CONTEXT,
383 odr_implicit(o, odr_bool, &pp->replaceIndicator, ODR_CONTEXT, 16, 1) &&
384 odr_implicit(o, odr_visiblestring, &pp->resultSetName, ODR_CONTEXT,
386 odr_implicit_settag(o, ODR_CONTEXT, 18) &&
387 odr_sequence_of(o, z_DatabaseName, &pp->databaseNames,
388 &pp->num_databaseNames) &&
389 odr_explicit(o, z_ElementSetNames, &pp->smallSetElementSetNames,
390 ODR_CONTEXT, 100, 1) &&
391 odr_explicit(o, z_ElementSetNames, &pp->mediumSetElementSetNames,
392 ODR_CONTEXT, 101, 1) &&
393 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
394 odr_explicit(o, z_Query, &pp->query, ODR_CONTEXT, 21, 0) &&
398 /* ------------------------ RECORD ------------------------- */
400 int z_DatabaseRecord(ODR o, Z_DatabaseRecord **p, int opt)
402 return odr_external(o, (Odr_external **) p, opt);
405 int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
407 if (!odr_sequence_begin(o, p, sizeof(**p)))
410 odr_oid(o, &(*p)->diagnosticSetId, 1) && /* SHOULD NOT BE OPT */
411 odr_integer(o, &(*p)->condition, 0) &&
412 (odr_visiblestring(o, &(*p)->addinfo, 0) ||
413 odr_implicit(o, odr_cstring, &(*p)->addinfo, ODR_CONTEXT, ODR_VISIBLESTRING, 1)) &&
417 int z_NamePlusRecord(ODR o, Z_NamePlusRecord **p, int opt)
419 static Odr_arm arm[] =
421 {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_NamePlusRecord_databaseRecord,
423 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_NamePlusRecord_surrogateDiagnostic,
428 if (!odr_sequence_begin(o, p, sizeof(**p)))
431 odr_implicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
433 odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 1) &&
434 odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
435 odr_constructed_end(o) &&
439 int z_NamePlusRecordList(ODR o, Z_NamePlusRecordList **p, int opt)
441 if (o->direction == ODR_DECODE)
442 *p = odr_malloc(o, sizeof(**p));
443 if (odr_sequence_of(o, z_NamePlusRecord, &(*p)->records,
450 int z_Records(ODR o, Z_Records **p, int opt)
454 {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_Records_DBOSD, z_NamePlusRecordList},
455 {ODR_IMPLICIT, ODR_CONTEXT, 130, Z_Records_NSD, z_DiagRec},
459 if (o->direction == ODR_DECODE)
460 *p = odr_malloc(o, sizeof(**p));
463 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
466 return opt && !o->error;
469 /* ------------------------ SEARCHRESPONSE ----------------*/
471 int z_NumberOfRecordsReturned(ODR o, int **p, int opt)
473 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 24, opt);
476 int z_NextResultSetPosition(ODR o, int **p, int opt)
478 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 25, opt);
481 int z_PresentStatus(ODR o, int **p, int opt)
483 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 27, opt);
486 int z_SearchResponse(ODR o, Z_SearchResponse **p, int opt)
488 Z_SearchResponse *pp;
490 if (!odr_sequence_begin(o, p, sizeof(**p)))
494 z_ReferenceId(o, &pp->referenceId, 1) &&
495 odr_implicit(o, odr_integer, &pp->resultCount, ODR_CONTEXT, 23, 0) &&
496 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
497 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
498 odr_implicit(o, odr_bool, &pp->searchStatus, ODR_CONTEXT, 22, 0) &&
499 odr_implicit(o, odr_integer, &pp->resultSetStatus, ODR_CONTEXT, 26, 1) &&
500 z_PresentStatus(o, &pp->presentStatus, 1) &&
501 z_Records(o, &pp->records, 1) &&
505 /* --------------------- PRESENT SERVICE ---------------------- */
507 int z_PresentRequest(ODR o, Z_PresentRequest **p, int opt)
509 Z_PresentRequest *pp;
511 if (!odr_sequence_begin(o, p, sizeof(**p)))
515 z_ReferenceId(o, &pp->referenceId, 1) &&
516 z_ResultSetId(o, &pp->resultSetId, 0) &&
517 odr_implicit(o, odr_integer, &pp->resultSetStartPoint, ODR_CONTEXT,
519 odr_implicit(o, odr_integer, &pp->numberOfRecordsRequested, ODR_CONTEXT,
521 z_ElementSetNames(o, &pp->elementSetNames, 1) &&
522 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
526 int z_PresentResponse(ODR o, Z_PresentResponse **p, int opt)
528 Z_PresentResponse *pp;
530 if (!odr_sequence_begin(o, p, sizeof(**p)))
534 z_ReferenceId(o, &pp->referenceId, 1) &&
535 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
536 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
537 z_PresentStatus(o, &pp->presentStatus, 0) &&
538 z_Records(o, &pp->records, 1) &&
542 /* ------------------------ APDU ------------------------- */
544 int z_APDU(ODR o, Z_APDU **p, int opt)
546 static Odr_arm arm[] =
548 {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_initRequest, z_InitRequest},
549 {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_initResponse, z_InitResponse},
550 {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_searchRequest, z_SearchRequest},
551 {ODR_IMPLICIT, ODR_CONTEXT, 23, Z_APDU_searchResponse, z_SearchResponse},
552 {ODR_IMPLICIT, ODR_CONTEXT, 24, Z_APDU_presentRequest, z_PresentRequest},
553 {ODR_IMPLICIT, ODR_CONTEXT, 25, Z_APDU_presentResponse, z_PresentResponse},
558 if (o->direction == ODR_DECODE)
559 *p = odr_malloc(o, sizeof(**p));
560 if (!odr_choice(o, arm, &(*p)->u, &(*p)->which))
562 if (o->direction == ODR_DECODE)
564 return opt && !o->error;