2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.7 1995-03-07 16:29:33 quinn
8 * Added authentication stuff.
10 * Revision 1.6 1995/03/01 14:46:03 quinn
11 * Fixed protocol bug in 8777query.
13 * Revision 1.5 1995/02/14 11:54:22 quinn
16 * Revision 1.4 1995/02/10 15:54:30 quinn
19 * Revision 1.3 1995/02/09 15:51:39 quinn
22 * Revision 1.2 1995/02/06 21:26:07 quinn
23 * Repaired this evening's damages..
25 * Revision 1.1 1995/02/06 16:44:47 quinn
26 * First hack at Z/SR protocol
34 /* ---------------------- GLOBAL DEFS ------------------- */
36 int z_ReferenceId(ODR o, Z_ReferenceId **p, int opt)
38 return odr_implicit(o, odr_octetstring, (Odr_oct**) p, ODR_CONTEXT, 2, opt);
41 int z_DatabaseName(ODR o, Z_DatabaseName **p, int opt)
43 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 105,
47 int z_ResultSetId(ODR o, char **p, int opt)
49 return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 31,
53 int z_UserInformationField(ODR o, Z_UserInformationField **p, int opt)
55 return odr_explicit(o, odr_external, (Odr_external **)p, ODR_CONTEXT,
59 /* ---------------------- INITIALIZE SERVICE ------------------- */
61 int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
65 if (!odr_sequence_begin(o, p, sizeof(**p)))
69 z_ReferenceId(o, &pp->referenceId, 1) &&
70 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
72 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
73 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
75 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
77 odr_explicit(o, odr_any, &pp->idAuthentication, ODR_CONTEXT,
79 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
81 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
83 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
84 ODR_CONTEXT, 112, 1) &&
85 z_UserInformationField(o, &pp->userInformationField, 1) &&
89 int z_InitResponse(ODR o, Z_InitResponse **p, int opt)
93 if (!odr_sequence_begin(o, p, sizeof(**p)))
97 z_ReferenceId(o, &pp->referenceId, 1) &&
98 odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT,
100 odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
101 odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
103 odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
105 odr_implicit(o, odr_bool, &pp->result, ODR_CONTEXT, 12, 0) &&
106 odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
108 odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
110 odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
111 ODR_CONTEXT, 112, 1) &&
112 z_UserInformationField(o, &pp->userInformationField, 1) &&
116 int z_NSRAuthentication(ODR o, Z_NSRAuthentication **p, int opt)
118 if (!odr_sequence_begin(o, p, sizeof(**p)))
121 odr_visiblestring(o, &(*p)->user, 0) &&
122 odr_visiblestring(o, &(*p)->password, 0) &&
123 odr_visiblestring(o, &(*p)->account, 0) &&
127 int z_StrAuthentication(ODR o, char **p, int opt)
129 return odr_visiblestring(o, p, opt);
132 /* ------------------------ SEARCH SERVICE ----------------------- */
134 int z_ElementSetName(ODR o, char **p, int opt)
136 return odr_implicit(o, odr_visiblestring, (char**) p, ODR_CONTEXT, 103,
140 int z_PreferredRecordSyntax(ODR o, Z_PreferredRecordSyntax **p, int opt)
142 return odr_implicit(o, odr_oid, (Odr_oid**) p, ODR_CONTEXT, 104, opt);
145 int z_DatabaseSpecificUnit(ODR o, Z_DatabaseSpecificUnit **p, int opt)
147 if (!odr_sequence_begin(o, p, sizeof(**p)))
150 z_DatabaseName(o, &(*p)->databaseName, 0) &&
151 z_ElementSetName(o, &(*p)->elementSetName, 0) &&
155 int z_DatabaseSpecific(ODR o, Z_DatabaseSpecific **p, int opt)
157 if (o->direction == ODR_DECODE)
158 *p = nalloc(o, sizeof(**p));
162 odr_implicit_settag(o, ODR_CONTEXT, 1);
163 if (odr_sequence_of(o, z_DatabaseSpecificUnit, &(*p)->elements,
164 &(*p)->num_elements))
170 int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
172 static Odr_arm arm[] =
174 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_ElementSetNames_generic,
176 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementSetNames_databaseSpecific,
181 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 19))
184 if (o->direction == ODR_DECODE)
185 *p = nalloc(o, sizeof(**p));
187 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
188 odr_constructed_end(o))
194 /* ----------------------- RPN QUERY -----------------------*/
196 int z_AttributeElement(ODR o, Z_AttributeElement **p, int opt)
198 if (!odr_sequence_begin(o, p, sizeof(**p)))
201 odr_implicit(o, odr_integer, &(*p)->attributeType, ODR_CONTEXT,
203 odr_implicit(o, odr_integer, &(*p)->attributeValue, ODR_CONTEXT,
208 int z_AttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
210 if (!(odr_implicit_settag(o, ODR_CONTEXT, 102) &&
211 odr_sequence_begin(o, p, sizeof(**p))))
214 odr_implicit_settag(o, ODR_CONTEXT, 44) &&
215 odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
216 &(*p)->num_attributes) &&
217 odr_implicit(o, odr_octetstring, &(*p)->term, ODR_CONTEXT, 45, 0) &&
221 int z_Operator(ODR o, Z_Operator **p, int opt)
223 static Odr_arm arm[] =
225 {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_Operator_and, odr_null},
226 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Operator_or, odr_null},
227 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Operator_and_not, odr_null},
232 if (!*p && o->direction != ODR_DECODE)
234 if (!odr_constructed_begin(o, p, ODR_CONTEXT, 46))
236 if (o->direction == ODR_DECODE)
237 *p = nalloc(o, sizeof(**p));
239 (*p)->u.and = &dummy;
241 if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
242 odr_constructed_end(o))
248 int z_Operand(ODR o, Z_Operand **p, int opt)
250 static Odr_arm arm[] =
252 {-1, -1, -1, Z_Operand_APT, z_AttributesPlusTerm},
253 {-1, -1, -1, Z_Operand_resultSetId, z_ResultSetId},
257 if (o->direction ==ODR_DECODE)
258 *p = nalloc(o, sizeof(**p));
261 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
267 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt);
269 int z_Complex(ODR o, Z_Complex **p, int opt)
271 if (!odr_sequence_begin(o, p, sizeof(**p)))
274 z_RPNStructure(o, &(*p)->s1, 0) &&
275 z_RPNStructure(o, &(*p)->s2, 0) &&
276 z_Operator(o, &(*p)->operator, 0) &&
280 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt)
282 static Odr_arm arm[] =
284 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand},
285 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_RPNStructure_complex, z_Complex},
289 if (o->direction == ODR_DECODE)
290 *p = nalloc(o, sizeof(**p));
293 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
299 int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
301 if (!odr_sequence_begin(o, p, sizeof(**p)))
304 odr_oid(o, &(*p)->attributeSetId, 0) &&
305 z_RPNStructure(o, &(*p)->RPNStructure, 0) &&
309 /* -----------------------END RPN QUERY ----------------------- */
311 int z_Query(ODR o, Z_Query **p, int opt)
313 static Odr_arm arm[] =
315 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Query_type_1, z_RPNQuery},
316 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_octetstring},
320 if (o->direction == ODR_DECODE)
321 *p = nalloc(o, sizeof(**p));
324 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
330 int z_SearchRequest(ODR o, Z_SearchRequest **p, int opt)
334 if (!odr_sequence_begin(o, p, sizeof(**p)))
338 z_ReferenceId(o, &pp->referenceId, 1) &&
339 odr_implicit(o, odr_integer, &pp->smallSetUpperBound, ODR_CONTEXT,
341 odr_implicit(o, odr_integer, &pp->largeSetLowerBound, ODR_CONTEXT,
343 odr_implicit(o, odr_integer, &pp->mediumSetPresentNumber, ODR_CONTEXT,
345 odr_implicit(o, odr_bool, &pp->replaceIndicator, ODR_CONTEXT, 16, 1) &&
346 odr_implicit(o, odr_visiblestring, &pp->resultSetName, ODR_CONTEXT,
348 odr_implicit_settag(o, ODR_CONTEXT, 18) &&
349 odr_sequence_of(o, z_DatabaseName, &pp->databaseNames,
350 &pp->num_databaseNames) &&
351 odr_implicit(o, z_ElementSetNames, &pp->smallSetElementSetNames,
352 ODR_CONTEXT, 100, 1) &&
353 odr_implicit(o, z_ElementSetNames, &pp->mediumSetElementSetNames,
354 ODR_CONTEXT, 101, 1) &&
355 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
356 odr_explicit(o, z_Query, &pp->query, ODR_CONTEXT, 21, 0) &&
360 /* ------------------------ RECORD ------------------------- */
362 int z_DatabaseRecord(ODR o, Z_DatabaseRecord **p, int opt)
364 return odr_external(o, (Odr_external **) p, opt);
367 int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
369 if (!odr_sequence_begin(o, p, sizeof(**p)))
372 odr_oid(o, &(*p)->diagnosticSetId, 1) && /* SHOULD NOT BE OPT */
373 odr_integer(o, &(*p)->condition, 0) &&
374 (odr_visiblestring(o, &(*p)->addinfo, 0) ||
375 odr_implicit(o, odr_cstring, &(*p)->addinfo, ODR_CONTEXT, ODR_VISIBLESTRING, 1)) &&
379 int z_NamePlusRecord(ODR o, Z_NamePlusRecord **p, int opt)
381 static Odr_arm arm[] =
383 {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_NamePlusRecord_databaseRecord,
385 {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_NamePlusRecord_surrogateDiagnostic,
390 if (!odr_sequence_begin(o, p, sizeof(**p)))
393 odr_implicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
395 odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 1) &&
396 odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
397 odr_constructed_end(o) &&
401 int z_NamePlusRecordList(ODR o, Z_NamePlusRecordList **p, int opt)
403 if (o->direction == ODR_DECODE)
404 *p = nalloc(o, sizeof(**p));
405 if (odr_sequence_of(o, z_NamePlusRecord, &(*p)->records,
412 int z_Records(ODR o, Z_Records **p, int opt)
416 {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_Records_DBOSD, z_NamePlusRecordList},
417 {ODR_IMPLICIT, ODR_CONTEXT, 130, Z_Records_NSD, z_DiagRec},
421 if (o->direction == ODR_DECODE)
422 *p = nalloc(o, sizeof(**p));
425 if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
431 /* ------------------------ SEARCHRESPONSE ----------------*/
433 int z_NumberOfRecordsReturned(ODR o, int **p, int opt)
435 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 24, opt);
438 int z_NextResultSetPosition(ODR o, int **p, int opt)
440 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 25, opt);
443 int z_PresentStatus(ODR o, int **p, int opt)
445 return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 27, opt);
448 int z_SearchResponse(ODR o, Z_SearchResponse **p, int opt)
450 Z_SearchResponse *pp;
452 if (!odr_sequence_begin(o, p, sizeof(**p)))
456 z_ReferenceId(o, &pp->referenceId, 1) &&
457 odr_implicit(o, odr_integer, &pp->resultCount, ODR_CONTEXT, 23, 0) &&
458 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
459 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
460 odr_implicit(o, odr_bool, &pp->searchStatus, ODR_CONTEXT, 22, 0) &&
461 odr_implicit(o, odr_integer, &pp->resultSetStatus, ODR_CONTEXT, 26, 1) &&
462 z_PresentStatus(o, &pp->presentStatus, 1) &&
463 z_Records(o, &pp->records, 1) &&
467 /* --------------------- PRESENT SERVICE ---------------------- */
469 int z_PresentRequest(ODR o, Z_PresentRequest **p, int opt)
471 Z_PresentRequest *pp;
473 if (!odr_sequence_begin(o, p, sizeof(**p)))
477 z_ReferenceId(o, &pp->referenceId, 1) &&
478 z_ResultSetId(o, &pp->resultSetId, 0) &&
479 odr_implicit(o, odr_integer, &pp->resultSetStartPoint, ODR_CONTEXT,
481 odr_implicit(o, odr_integer, &pp->numberOfRecordsRequested, ODR_CONTEXT,
483 z_ElementSetNames(o, &pp->elementSetNames, 1) &&
484 z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
488 int z_PresentResponse(ODR o, Z_PresentResponse **p, int opt)
490 Z_PresentResponse *pp;
492 if (!odr_sequence_begin(o, p, sizeof(**p)))
496 z_ReferenceId(o, &pp->referenceId, 1) &&
497 z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
498 z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
499 z_PresentStatus(o, &pp->presentStatus, 0) &&
500 z_Records(o, &pp->records, 1) &&
504 /* ------------------------ APDU ------------------------- */
506 int z_APDU(ODR o, Z_APDU **p, int opt)
508 static Odr_arm arm[] =
510 {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_initRequest, z_InitRequest},
511 {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_initResponse, z_InitResponse},
512 {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_searchRequest, z_SearchRequest},
513 {ODR_IMPLICIT, ODR_CONTEXT, 23, Z_APDU_searchResponse, z_SearchResponse},
514 {ODR_IMPLICIT, ODR_CONTEXT, 24, Z_APDU_presentRequest, z_PresentRequest},
515 {ODR_IMPLICIT, ODR_CONTEXT, 25, Z_APDU_presentResponse, z_PresentResponse},
520 if (o->direction == ODR_DECODE)
521 *p = nalloc(o, sizeof(**p));
522 if (!odr_choice(o, arm, &(*p)->u, &(*p)->which))
524 if (o->direction == ODR_DECODE)