2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.15 1995-03-30 09:08:39 quinn
8 * Added Resource control protocol
10 * Revision 1.14 1995/03/29 08:06:13 quinn
11 * Added a few v3 elements
13 * Revision 1.13 1995/03/20 11:26:52 quinn
14 * *** empty log message ***
16 * Revision 1.12 1995/03/20 09:45:09 quinn
19 * Revision 1.11 1995/03/17 10:17:25 quinn
20 * Added memory management.
22 * Revision 1.10 1995/03/15 11:17:40 quinn
23 * Fixed some return-checks from choice.. need better ay to handle those..
25 * Revision 1.9 1995/03/15 08:37:06 quinn
26 * Fixed protocol bugs.
28 * Revision 1.8 1995/03/14 16:59:24 quinn
29 * Fixed OPTIONAL flag in attributeelement
31 * Revision 1.7 1995/03/07 16:29:33 quinn
32 * Added authentication stuff.
34 * Revision 1.6 1995/03/01 14:46:03 quinn
35 * Fixed protocol bug in 8777query.
37 * Revision 1.5 1995/02/14 11:54:22 quinn
40 * Revision 1.4 1995/02/10 15:54:30 quinn
43 * Revision 1.3 1995/02/09 15:51:39 quinn
46 * Revision 1.2 1995/02/06 21:26:07 quinn
47 * Repaired this evening's damages..
49 * Revision 1.1 1995/02/06 16:44:47 quinn
50 * First hack at Z/SR protocol
58 /* ---------------------- GLOBAL DEFS ------------------- */
60 int z_ReferenceId(ODR o, Z_ReferenceId **p, int opt)
62 return odr_implicit(o, odr_octetstring, (Odr_oct**) p, ODR_CONTEXT, 2, opt);
65 int z_DatabaseName(ODR o, Z_DatabaseName **p, int opt)
67 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 105,
71 int z_ResultSetId(ODR o, char **p, int opt)
73 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 31,
77 int z_UserInformationField(ODR o, Z_UserInformationField **p, int opt)
79 return odr_explicit(o, odr_external, (Odr_external **)p, ODR_CONTEXT,
83 /* ---------------------- INITIALIZE SERVICE ------------------- */
85 int z_NSRAuthentication(ODR o, Z_NSRAuthentication **p, int opt)
87 if (!odr_sequence_begin(o, p, sizeof(**p)))
90 odr_visiblestring(o, &(*p)->user, 0) &&
91 odr_visiblestring(o, &(*p)->password, 0) &&
92 odr_visiblestring(o, &(*p)->account, 0) &&
96 int z_IdPass(ODR o, Z_IdPass **p, int opt)
98 if (!odr_sequence_begin(o, p, sizeof(**p)))
101 odr_implicit(o, odr_visiblestring, &(*p)->groupId, ODR_CONTEXT, 0, 0) &&
102 odr_implicit(o, odr_visiblestring, &(*p)->userId, ODR_CONTEXT, 1, 0) &&
103 odr_implicit(o, odr_visiblestring, &(*p)->password, ODR_CONTEXT, 2,
108 int z_StrAuthentication(ODR o, char **p, int opt)
110 return odr_visiblestring(o, p, opt);
113 int z_IdAuthentication(ODR o, Z_IdAuthentication **p, int opt)
115 static Odr_arm arm[] =
117 {-1, -1, -1, Z_IdAuthentication_open, z_StrAuthentication},
118 {-1, -1, -1, Z_IdAuthentication_idPass, z_NSRAuthentication},
119 {-1, -1, -1, Z_IdAuthentication_anonymous, odr_null},
120 {-1, -1, -1, Z_IdAuthentication_other, odr_external},
124 if (o->direction == ODR_DECODE)
125 *p = odr_malloc(o, sizeof(**p));
127 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
130 return opt && !o->error;
133 int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
137 if (!odr_sequence_begin(o, p, sizeof(**p)))
141 z_ReferenceId(o, &pp->referenceId, 1) &&
142 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
144 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
145 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
147 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
149 odr_explicit(o, z_IdAuthentication, &pp->idAuthentication, ODR_CONTEXT,
151 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
153 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
155 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
156 ODR_CONTEXT, 112, 1) &&
157 z_UserInformationField(o, &pp->userInformationField, 1) &&
161 int z_InitResponse(ODR o, Z_InitResponse **p, int opt)
165 if (!odr_sequence_begin(o, p, sizeof(**p)))
169 z_ReferenceId(o, &pp->referenceId, 1) &&
170 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
172 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
173 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
175 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
177 odr_implicit(o, odr_bool, &pp->result, ODR_CONTEXT, 12, 0) &&
178 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
180 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
182 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
183 ODR_CONTEXT, 112, 1) &&
184 z_UserInformationField(o, &pp->userInformationField, 1) &&
188 /* ------------------ RESOURCE CONTROL ----------------*/
190 int z_TriggerResourceControlRequest(ODR o, Z_TriggerResourceControlRequest **p,
193 if (!odr_sequence_begin(o, p, sizeof(**p)))
196 z_ReferenceId(o, &(*p)->referenceId, 1) &&
197 odr_implicit(o, odr_integer, &(*p)->requestedAction, ODR_CONTEXT,
199 odr_implicit(o, odr_oid, &(*p)->prefResourceReportFormat,
200 ODR_CONTEXT, 47, 1) &&
201 odr_implicit(o, odr_bool, &(*p)->resultSetWanted, ODR_CONTEXT,
206 int z_ResourceControlRequest(ODR o, Z_ResourceControlRequest **p, int opt)
208 if (!odr_sequence_begin(o, p, sizeof(**p)))
211 z_ReferenceId(o, &(*p)->referenceId, 1) &&
212 odr_implicit(o, odr_bool, &(*p)->suspendedFlag, ODR_CONTEXT, 39, 1)&&
213 odr_explicit(o, odr_external, &(*p)->resourceReport, ODR_CONTEXT,
215 odr_implicit(o, odr_integer, &(*p)->partialResultsAvailable,
216 ODR_CONTEXT, 41, 1) &&
217 odr_implicit(o, odr_bool, &(*p)->responseRequired, ODR_CONTEXT,
219 odr_implicit(o, odr_bool, &(*p)->triggeredRequestFlag,
220 ODR_CONTEXT, 43, 1) &&
224 int z_ResourceControlResponse(ODR o, Z_ResourceControlResponse **p, int opt)
226 if (!odr_sequence_begin(o, p, sizeof(**p)))
229 z_ReferenceId(o, &(*p)->referenceId, 1) &&
230 odr_implicit(o, odr_bool, &(*p)->continueFlag, ODR_CONTEXT, 44, 0) &&
231 odr_implicit(o, odr_bool, &(*p)->resultSetWanted, ODR_CONTEXT,
236 /* ------------------------ SEARCH SERVICE ----------------------- */
238 int z_ElementSetName(ODR o, char **p, int opt)
240 return odr_implicit(o, odr_visiblestring, (char**) p, ODR_CONTEXT, 103,
244 int z_PreferredRecordSyntax(ODR o, Z_PreferredRecordSyntax **p, int opt)
246 return odr_implicit(o, odr_oid, (Odr_oid**) p, ODR_CONTEXT, 104, opt);
249 int z_DatabaseSpecificUnit(ODR o, Z_DatabaseSpecificUnit **p, int opt)
251 if (!odr_sequence_begin(o, p, sizeof(**p)))
254 z_DatabaseName(o, &(*p)->databaseName, 0) &&
255 z_ElementSetName(o, &(*p)->elementSetName, 0) &&
259 int z_DatabaseSpecific(ODR o, Z_DatabaseSpecific **p, int opt)
261 if (o->direction == ODR_DECODE)
262 *p = odr_malloc(o, sizeof(**p));
266 odr_implicit_settag(o, ODR_CONTEXT, 1);
267 if (odr_sequence_of(o, z_DatabaseSpecificUnit, &(*p)->elements,
268 &(*p)->num_elements))
274 int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
276 static Odr_arm arm[] =
278 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_ElementSetNames_generic,
280 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementSetNames_databaseSpecific,
285 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 19))
288 if (o->direction == ODR_DECODE)
289 *p = odr_malloc(o, sizeof(**p));
291 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
292 odr_constructed_end(o))
298 /* ----------------------- RPN QUERY -----------------------*/
300 int z_AttributeElement(ODR o, Z_AttributeElement **p, int opt)
302 if (!odr_sequence_begin(o, p, sizeof(**p)))
305 odr_implicit(o, odr_integer, &(*p)->attributeType, ODR_CONTEXT,
307 odr_implicit(o, odr_integer, &(*p)->attributeValue, ODR_CONTEXT,
312 int z_AttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
314 if (!(odr_implicit_settag(o, ODR_CONTEXT, 102) &&
315 odr_sequence_begin(o, p, sizeof(**p))))
318 odr_implicit_settag(o, ODR_CONTEXT, 44) &&
319 odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
320 &(*p)->num_attributes) &&
321 odr_implicit(o, odr_octetstring, &(*p)->term, ODR_CONTEXT, 45, 0) &&
325 int z_Operator(ODR o, Z_Operator **p, int opt)
327 static Odr_arm arm[] =
329 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_Operator_and, odr_null},
330 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Operator_or, odr_null},
331 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Operator_and_not, odr_null},
336 if (!*p && o->direction != ODR_DECODE)
338 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 46))
340 if (o->direction == ODR_DECODE)
341 *p = odr_malloc(o, sizeof(**p));
343 (*p)->u.and = &dummy;
345 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
346 odr_constructed_end(o))
349 return opt && !o->error;
352 int z_Operand(ODR o, Z_Operand **p, int opt)
354 static Odr_arm arm[] =
356 {-1, -1, -1, Z_Operand_APT, z_AttributesPlusTerm},
357 {-1, -1, -1, Z_Operand_resultSetId, z_ResultSetId},
361 if (o->direction ==ODR_DECODE)
362 *p = odr_malloc(o, sizeof(**p));
365 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
368 return opt && !o->error;
371 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt);
373 int z_Complex(ODR o, Z_Complex **p, int opt)
375 if (!odr_sequence_begin(o, p, sizeof(**p)))
378 z_RPNStructure(o, &(*p)->s1, 0) &&
379 z_RPNStructure(o, &(*p)->s2, 0) &&
380 z_Operator(o, &(*p)->operator, 0) &&
384 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt)
386 static Odr_arm arm[] =
388 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand},
389 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_RPNStructure_complex, z_Complex},
393 if (o->direction == ODR_DECODE)
394 *p = odr_malloc(o, sizeof(**p));
397 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
400 return opt && !o->error;
403 int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
405 if (!odr_sequence_begin(o, p, sizeof(**p)))
408 odr_oid(o, &(*p)->attributeSetId, 0) &&
409 z_RPNStructure(o, &(*p)->RPNStructure, 0) &&
413 /* -----------------------END RPN QUERY ----------------------- */
415 int z_Query(ODR o, Z_Query **p, int opt)
417 static Odr_arm arm[] =
419 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Query_type_1, z_RPNQuery},
420 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_octetstring},
424 if (o->direction == ODR_DECODE)
425 *p = odr_malloc(o, sizeof(**p));
428 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
431 return opt && !o->error;
434 int z_SearchRequest(ODR o, Z_SearchRequest **p, int opt)
438 if (!odr_sequence_begin(o, p, sizeof(**p)))
442 z_ReferenceId(o, &pp->referenceId, 1) &&
443 odr_implicit(o, odr_integer, &pp->smallSetUpperBound, ODR_CONTEXT,
445 odr_implicit(o, odr_integer, &pp->largeSetLowerBound, ODR_CONTEXT,
447 odr_implicit(o, odr_integer, &pp->mediumSetPresentNumber, ODR_CONTEXT,
449 odr_implicit(o, odr_bool, &pp->replaceIndicator, ODR_CONTEXT, 16, 1) &&
450 odr_implicit(o, odr_visiblestring, &pp->resultSetName, ODR_CONTEXT,
452 odr_implicit_settag(o, ODR_CONTEXT, 18) &&
453 odr_sequence_of(o, z_DatabaseName, &pp->databaseNames,
454 &pp->num_databaseNames) &&
455 odr_explicit(o, z_ElementSetNames, &pp->smallSetElementSetNames,
456 ODR_CONTEXT, 100, 1) &&
457 odr_explicit(o, z_ElementSetNames, &pp->mediumSetElementSetNames,
458 ODR_CONTEXT, 101, 1) &&
459 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
460 odr_explicit(o, z_Query, &pp->query, ODR_CONTEXT, 21, 0) &&
464 /* ------------------------ RECORD ------------------------- */
466 int z_DatabaseRecord(ODR o, Z_DatabaseRecord **p, int opt)
468 return odr_external(o, (Odr_external **) p, opt);
471 int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
473 if (!odr_sequence_begin(o, p, sizeof(**p)))
476 odr_oid(o, &(*p)->diagnosticSetId, 1) && /* SHOULD NOT BE OPT */
477 odr_integer(o, &(*p)->condition, 0) &&
478 (odr_visiblestring(o, &(*p)->addinfo, 0) ||
479 odr_implicit(o, odr_cstring, &(*p)->addinfo, ODR_CONTEXT, ODR_VISIBLESTRING, 1)) &&
483 int z_NamePlusRecord(ODR o, Z_NamePlusRecord **p, int opt)
485 static Odr_arm arm[] =
487 {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_NamePlusRecord_databaseRecord,
489 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_NamePlusRecord_surrogateDiagnostic,
494 if (!odr_sequence_begin(o, p, sizeof(**p)))
497 odr_implicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
499 odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 1) &&
500 odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
501 odr_constructed_end(o) &&
505 int z_NamePlusRecordList(ODR o, Z_NamePlusRecordList **p, int opt)
507 if (o->direction == ODR_DECODE)
508 *p = odr_malloc(o, sizeof(**p));
509 if (odr_sequence_of(o, z_NamePlusRecord, &(*p)->records,
516 int z_Records(ODR o, Z_Records **p, int opt)
520 {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_Records_DBOSD, z_NamePlusRecordList},
521 {ODR_IMPLICIT, ODR_CONTEXT, 130, Z_Records_NSD, z_DiagRec},
525 if (o->direction == ODR_DECODE)
526 *p = odr_malloc(o, sizeof(**p));
529 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
532 return opt && !o->error;
535 /* ------------------------ SEARCHRESPONSE ----------------*/
537 int z_NumberOfRecordsReturned(ODR o, int **p, int opt)
539 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 24, opt);
542 int z_NextResultSetPosition(ODR o, int **p, int opt)
544 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 25, opt);
547 int z_PresentStatus(ODR o, int **p, int opt)
549 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 27, opt);
552 int z_SearchResponse(ODR o, Z_SearchResponse **p, int opt)
554 Z_SearchResponse *pp;
556 if (!odr_sequence_begin(o, p, sizeof(**p)))
560 z_ReferenceId(o, &pp->referenceId, 1) &&
561 odr_implicit(o, odr_integer, &pp->resultCount, ODR_CONTEXT, 23, 0) &&
562 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
563 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
564 odr_implicit(o, odr_bool, &pp->searchStatus, ODR_CONTEXT, 22, 0) &&
565 odr_implicit(o, odr_integer, &pp->resultSetStatus, ODR_CONTEXT, 26, 1) &&
566 z_PresentStatus(o, &pp->presentStatus, 1) &&
567 z_Records(o, &pp->records, 1) &&
571 /* --------------------- PRESENT SERVICE ---------------------- */
573 int z_PresentRequest(ODR o, Z_PresentRequest **p, int opt)
575 Z_PresentRequest *pp;
577 if (!odr_sequence_begin(o, p, sizeof(**p)))
581 z_ReferenceId(o, &pp->referenceId, 1) &&
582 z_ResultSetId(o, &pp->resultSetId, 0) &&
583 odr_implicit(o, odr_integer, &pp->resultSetStartPoint, ODR_CONTEXT,
585 odr_implicit(o, odr_integer, &pp->numberOfRecordsRequested, ODR_CONTEXT,
587 z_ElementSetNames(o, &pp->elementSetNames, 1) &&
588 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
592 int z_PresentResponse(ODR o, Z_PresentResponse **p, int opt)
594 Z_PresentResponse *pp;
596 if (!odr_sequence_begin(o, p, sizeof(**p)))
600 z_ReferenceId(o, &pp->referenceId, 1) &&
601 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
602 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
603 z_PresentStatus(o, &pp->presentStatus, 0) &&
604 z_Records(o, &pp->records, 1) &&
608 /* ------------------------ APDU ------------------------- */
610 int z_APDU(ODR o, Z_APDU **p, int opt)
612 static Odr_arm arm[] =
614 {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_initRequest, z_InitRequest},
615 {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_initResponse, z_InitResponse},
616 {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_searchRequest, z_SearchRequest},
617 {ODR_IMPLICIT, ODR_CONTEXT, 23, Z_APDU_searchResponse, z_SearchResponse},
618 {ODR_IMPLICIT, ODR_CONTEXT, 24, Z_APDU_presentRequest, z_PresentRequest},
619 {ODR_IMPLICIT, ODR_CONTEXT, 25, Z_APDU_presentResponse, z_PresentResponse},
624 if (o->direction == ODR_DECODE)
625 *p = odr_malloc(o, sizeof(**p));
626 if (!odr_choice(o, arm, &(*p)->u, &(*p)->which))
628 if (o->direction == ODR_DECODE)
630 return opt && !o->error;