f2b4118f0ac4c36bdee8e39d21006e1c1be40631
[yaz-moved-to-github.git] / asn / proto.c
1 /*
2  * Copyright (c) 1995, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: proto.c,v $
7  * Revision 1.43  1996-02-10 12:22:49  quinn
8  * Work on SCAN
9  *
10  * Revision 1.42  1996/01/22  09:46:31  quinn
11  * Added Sort PDU. Moved StringList to main protocol file.
12  *
13  * Revision 1.41  1996/01/10  15:21:24  quinn
14  * Added links to access control PDUs
15  *
16  * Revision 1.40  1996/01/02  11:46:40  quinn
17  * Changed 'operator' to 'roperator' to avoid C++ conflict.
18  *
19  * Revision 1.39  1995/09/29  17:11:53  quinn
20  * Smallish
21  *
22  * Revision 1.38  1995/09/27  15:02:40  quinn
23  * Modified function heads & prototypes.
24  *
25  * Revision 1.37  1995/08/21  09:10:15  quinn
26  * Smallish fixes to suppport new formats.
27  *
28  * Revision 1.36  1995/08/15  11:59:39  quinn
29  * Updated External
30  *
31  * Revision 1.35  1995/08/10  08:53:59  quinn
32  * Added Explain
33  *
34  * Revision 1.34  1995/06/19  17:01:48  quinn
35  * This should bring us in sync with the version distributed as 1.0b
36  *
37  * Revision 1.33  1995/06/19  13:39:56  quinn
38  * *** empty log message ***
39  *
40  * Revision 1.32  1995/06/19  12:37:28  quinn
41  * Fixed a bug in the compspec.
42  *
43  * Revision 1.31  1995/06/16  13:15:56  quinn
44  * Fixed Defaultdiagformat.
45  *
46  * Revision 1.30  1995/06/15  15:42:01  quinn
47  * Fixed some v3 bugs
48  *
49  * Revision 1.29  1995/06/15  07:44:49  quinn
50  * Moving to v3.
51  *
52  * Revision 1.28  1995/06/14  15:26:35  quinn
53  * *** empty log message ***
54  *
55  * Revision 1.27  1995/06/07  14:36:22  quinn
56  * Added CLOSE
57  *
58  * Revision 1.26  1995/06/02  09:49:13  quinn
59  * Adding access control
60  *
61  * Revision 1.25  1995/05/25  11:00:08  quinn
62  * *** empty log message ***
63  *
64  * Revision 1.24  1995/05/22  13:58:18  quinn
65  * Fixed an ODR_NULLVAL.
66  *
67  * Revision 1.23  1995/05/22  11:30:18  quinn
68  * Adding Z39.50-1992 stuff to proto.c. Adding zget.c
69  *
70  * Revision 1.22  1995/05/17  08:40:56  quinn
71  * Added delete. Fixed some sequence_begins. Smallish.
72  *
73  * Revision 1.21  1995/05/16  08:50:24  quinn
74  * License, documentation, and memory fixes
75  *
76  * Revision 1.20  1995/05/15  11:55:25  quinn
77  * Smallish.
78  *
79  * Revision 1.19  1995/04/11  11:58:35  quinn
80  * Fixed bug.
81  *
82  * Revision 1.18  1995/04/11  11:52:02  quinn
83  * Fixed possible buf in proto.c
84  *
85  * Revision 1.17  1995/04/10  10:22:22  quinn
86  * Added SCAN.
87  *
88  * Revision 1.16  1995/03/30  10:26:43  quinn
89  * Added Term structure
90  *
91  * Revision 1.15  1995/03/30  09:08:39  quinn
92  * Added Resource control protocol
93  *
94  * Revision 1.14  1995/03/29  08:06:13  quinn
95  * Added a few v3 elements
96  *
97  * Revision 1.13  1995/03/20  11:26:52  quinn
98  * *** empty log message ***
99  *
100  * Revision 1.12  1995/03/20  09:45:09  quinn
101  * Working towards v3
102  *
103  * Revision 1.11  1995/03/17  10:17:25  quinn
104  * Added memory management.
105  *
106  * Revision 1.10  1995/03/15  11:17:40  quinn
107  * Fixed some return-checks from choice.. need better ay to handle those..
108  *
109  * Revision 1.9  1995/03/15  08:37:06  quinn
110  * Fixed protocol bugs.
111  *
112  * Revision 1.8  1995/03/14  16:59:24  quinn
113  * Fixed OPTIONAL flag in attributeelement
114  *
115  * Revision 1.7  1995/03/07  16:29:33  quinn
116  * Added authentication stuff.
117  *
118  * Revision 1.6  1995/03/01  14:46:03  quinn
119  * Fixed protocol bug in 8777query.
120  *
121  * Revision 1.5  1995/02/14  11:54:22  quinn
122  * Fixing include.
123  *
124  * Revision 1.4  1995/02/10  15:54:30  quinn
125  * Small adjustments.
126  *
127  * Revision 1.3  1995/02/09  15:51:39  quinn
128  * Works better now.
129  *
130  * Revision 1.2  1995/02/06  21:26:07  quinn
131  * Repaired this evening's damages..
132  *
133  * Revision 1.1  1995/02/06  16:44:47  quinn
134  * First hack at Z/SR protocol
135  *
136  */
137
138 #include <odr.h>
139
140 #include <proto.h>
141
142 /* ---------------------- GLOBAL DEFS ------------------- */
143
144 /*
145  * We'll use a general octetstring here, since string operations are
146  * clumsy on long strings.
147  */
148 int z_SUTRS(ODR o, Odr_oct **p, int opt)
149 {
150     return odr_implicit(o, odr_octetstring, p, ODR_UNIVERSAL,
151         ODR_GENERALSTRING, opt);
152 }
153
154 int z_ReferenceId(ODR o, Z_ReferenceId **p, int opt)
155 {
156     return odr_implicit(o, odr_octetstring, (Odr_oct**) p, ODR_CONTEXT, 2, opt);
157 }
158
159 int z_DatabaseName(ODR o, Z_DatabaseName **p, int opt)
160 {
161     return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 105,
162         opt);
163 }
164
165 int z_ResultSetId(ODR o, char **p, int opt)
166 {
167     return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 31,
168         opt);
169 }
170
171 int z_ElementSetName(ODR o, char **p, int opt)
172 {
173     return odr_implicit(o, odr_visiblestring, p, ODR_CONTEXT, 103, opt);
174 }
175
176 int z_UserInformationField(ODR o, Z_External **p, int opt)
177 {
178     return odr_explicit(o, z_External, (Z_External **)p, ODR_CONTEXT,
179         11, opt);
180 }
181
182 int z_InternationalString(ODR o, char **p, int opt)
183 {
184     return odr_generalstring(o, p, opt);
185 }
186
187 int z_InfoCategory(ODR o, Z_InfoCategory **p, int opt)
188 {
189     if (!odr_sequence_begin(o, p, sizeof(**p)))
190         return opt && odr_ok(o);
191     return
192         odr_implicit(o, odr_oid, &(*p)->categoryTypeId, ODR_CONTEXT, 1, 1) &&
193         odr_implicit(o, odr_integer, &(*p)->categoryValue, ODR_CONTEXT, 2, 0) &&
194         odr_sequence_end(o);
195 }
196
197 int z_OtherInformationUnit(ODR o, Z_OtherInformationUnit **p, int opt)
198 {
199     static Odr_arm arm[] =
200     {
201         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_OtherInfo_characterInfo,
202             odr_visiblestring},
203         {ODR_IMPLICIT, ODR_CONTEXT, 3, Z_OtherInfo_binaryInfo,
204             odr_octetstring},
205         {ODR_IMPLICIT, ODR_CONTEXT, 4, Z_OtherInfo_externallyDefinedInfo,
206             z_External},
207         {ODR_IMPLICIT, ODR_CONTEXT, 5, Z_OtherInfo_oid, odr_oid},
208         {-1, -1, -1, -1, 0}
209     };
210
211     if (!odr_sequence_begin(o, p, sizeof(**p)))
212         return opt && odr_ok(o);
213     return
214         odr_implicit(o, z_InfoCategory, &(*p)->category, ODR_CONTEXT, 1, 1) &&
215         odr_choice(o, arm, &(*p)->which, &(*p)->information) &&
216         odr_sequence_end(o);
217 }
218     
219 int z_OtherInformation(ODR o, Z_OtherInformation **p, int opt)
220 {
221     if (o->direction == ODR_DECODE)
222         *p = odr_malloc(o, sizeof(**p));
223     else if (!*p)
224         return opt;
225     odr_implicit_settag(o, ODR_CONTEXT, 201);
226     if (odr_sequence_of(o, z_OtherInformationUnit, &(*p)->list,
227         &(*p)->num_elements))
228         return 1;
229     *p = 0;
230     return opt && odr_ok(o);
231 }
232
233 int z_StringOrNumeric(ODR o, Z_StringOrNumeric **p, int opt)
234 {
235     static Odr_arm arm[] =
236     {
237         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_StringOrNumeric_string,
238             odr_visiblestring},
239         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_StringOrNumeric_numeric,
240             odr_integer},
241         {-1, -1, -1, -1, 0}
242     };
243
244     if (o->direction == ODR_DECODE)
245         *p = odr_malloc(o, sizeof(**p));
246     else if (!*p)
247         return opt;
248     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
249         return 1;
250     *p = 0;
251     return opt && odr_ok(o);
252 }
253
254 /*
255  * check tagging!!
256  */
257 int z_Unit(ODR o, Z_Unit **p, int opt)
258 {
259     if (!odr_sequence_begin(o, p, sizeof(**p)))
260         return opt && odr_ok(o);
261     return
262         odr_implicit(o, odr_visiblestring, &(*p)->unitSystem, ODR_CONTEXT,
263             1, 1) &&
264         odr_explicit(o, z_StringOrNumeric, &(*p)->unitType, ODR_CONTEXT,
265             2, 1) &&
266         odr_explicit(o, z_StringOrNumeric, &(*p)->unit, ODR_CONTEXT, 3, 1) &&
267         odr_implicit(o, odr_integer, &(*p)->scaleFactor, ODR_CONTEXT, 4, 1) &&
268         odr_sequence_end(o);
269 }
270
271 int z_IntUnit(ODR o, Z_IntUnit **p, int opt)
272 {
273     if (!odr_sequence_begin(o, p, sizeof(**p)))
274         return opt && odr_ok(o);
275     return
276         odr_implicit(o, odr_integer, &(*p)->value, ODR_CONTEXT, 1, 0) &&
277         odr_implicit(o, z_Unit, &(*p)->unitUsed, ODR_CONTEXT, 2, 0) &&
278         odr_sequence_end(o);
279 }
280
281 int z_StringList(ODR o, Z_StringList **p, int opt)
282 {
283     if (o->direction == ODR_DECODE)
284         *p = odr_malloc(o, sizeof(**p));
285     else if (!*p)
286         return opt;
287     if (odr_sequence_of(o, z_InternationalString, &(*p)->strings,
288         &(*p)->num_strings))
289         return 1;
290     *p = 0;
291     return opt && odr_ok(o);
292 }
293
294 /* ---------------------- INITIALIZE SERVICE ------------------- */
295
296 #if 0
297 int z_NSRAuthentication(ODR o, Z_NSRAuthentication **p, int opt)
298 {
299     if (!odr_sequence_begin(o, p, sizeof(**p)))
300         return opt && odr_ok(o);
301     return
302         odr_visiblestring(o, &(*p)->user, 0) &&
303         odr_visiblestring(o, &(*p)->password, 0) &&
304         odr_visiblestring(o, &(*p)->account, 0) &&
305         odr_sequence_end(o);
306 }
307 #endif
308
309 int z_IdPass(ODR o, Z_IdPass **p, int opt)
310 {
311     if (!odr_sequence_begin(o, p, sizeof(**p)))
312         return opt && odr_ok(o);
313     return
314         odr_implicit(o, odr_visiblestring, &(*p)->groupId, ODR_CONTEXT, 0, 1) &&
315         odr_implicit(o, odr_visiblestring, &(*p)->userId, ODR_CONTEXT, 1, 1) &&
316         odr_implicit(o, odr_visiblestring, &(*p)->password, ODR_CONTEXT, 2,
317             1) &&
318         odr_sequence_end(o);
319 }
320
321 int z_StrAuthentication(ODR o, char **p, int opt)
322 {
323     return odr_visiblestring(o, p, opt);
324 }
325
326 int z_IdAuthentication(ODR o, Z_IdAuthentication **p, int opt)
327 {
328     static Odr_arm arm[] =
329     {
330         {-1, -1, -1, Z_IdAuthentication_open, z_StrAuthentication},
331         {-1, -1, -1, Z_IdAuthentication_idPass, z_IdPass},
332         {-1, -1, -1, Z_IdAuthentication_anonymous, odr_null},
333         {-1, -1, -1, Z_IdAuthentication_other, z_External},
334         {-1, -1, -1, -1, 0}
335     };
336
337     if (o->direction == ODR_DECODE)
338         *p = odr_malloc(o, sizeof(**p));
339     else if (!*p)
340         return opt;
341
342     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
343         return 1;
344     *p = 0;
345     return opt && odr_ok(o);
346 }
347
348 int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
349 {
350     Z_InitRequest *pp;
351
352     if (!odr_sequence_begin(o, p, sizeof(**p)))
353         return opt && odr_ok(o);
354     pp = *p;
355     return
356         z_ReferenceId(o, &pp->referenceId, 1) &&
357         odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT, 
358             3, 0) &&
359         odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
360         odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
361             5, 0) &&
362         odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
363             6, 0) &&
364         odr_explicit(o, z_IdAuthentication, &pp->idAuthentication, ODR_CONTEXT,
365             7, 1) &&
366         odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
367             110, 1) &&
368         odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
369             111, 1) &&
370         odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
371             ODR_CONTEXT, 112, 1) &&
372         z_UserInformationField(o, &pp->userInformationField, 1) &&
373 #ifdef Z_95
374         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
375 #endif
376         odr_sequence_end(o);
377 }
378
379 int z_InitResponse(ODR o, Z_InitResponse **p, int opt)
380 {
381     Z_InitResponse *pp;
382
383     if (!odr_sequence_begin(o, p, sizeof(**p)))
384         return opt && odr_ok(o);
385     pp = *p;
386     return
387         z_ReferenceId(o, &pp->referenceId, 1) &&
388         odr_implicit(o, odr_bitstring, &pp->protocolVersion, ODR_CONTEXT, 
389             3, 0) &&
390         odr_implicit(o, odr_bitstring, &pp->options, ODR_CONTEXT, 4, 0) &&
391         odr_implicit(o, odr_integer, &pp->preferredMessageSize, ODR_CONTEXT,
392             5, 0) &&
393         odr_implicit(o, odr_integer, &pp->maximumRecordSize, ODR_CONTEXT,
394             6, 0) &&
395         odr_implicit(o, odr_bool, &pp->result, ODR_CONTEXT, 12, 0) &&
396         odr_implicit(o, odr_visiblestring, &pp->implementationId, ODR_CONTEXT,
397             110, 1) &&
398         odr_implicit(o, odr_visiblestring, &pp->implementationName, ODR_CONTEXT,
399             111, 1) &&
400         odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
401             ODR_CONTEXT, 112, 1) &&
402         z_UserInformationField(o, &pp->userInformationField, 1) &&
403 #ifdef Z_95
404         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
405 #endif
406         odr_sequence_end(o);
407 }
408
409 /* ------------------ RESOURCE CONTROL ----------------*/
410
411 int z_TriggerResourceControlRequest(ODR o, Z_TriggerResourceControlRequest **p,
412                                     int opt)
413 {
414     if (!odr_sequence_begin(o, p, sizeof(**p)))
415         return opt && odr_ok(o);
416     return
417         z_ReferenceId(o, &(*p)->referenceId, 1) &&
418         odr_implicit(o, odr_integer, &(*p)->requestedAction, ODR_CONTEXT,
419             46, 0) &&
420         odr_implicit(o, odr_oid, &(*p)->prefResourceReportFormat,
421             ODR_CONTEXT, 47, 1) &&
422         odr_implicit(o, odr_bool, &(*p)->resultSetWanted, ODR_CONTEXT,
423             48, 1) &&
424 #ifdef Z_95
425         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
426 #endif
427         odr_sequence_end(o);
428 }
429
430 int z_ResourceControlRequest(ODR o, Z_ResourceControlRequest **p, int opt)
431 {
432     if (!odr_sequence_begin(o, p, sizeof(**p)))
433         return opt && odr_ok(o);
434     return
435         z_ReferenceId(o, &(*p)->referenceId, 1) &&
436         odr_implicit(o, odr_bool, &(*p)->suspendedFlag, ODR_CONTEXT, 39, 1)&&
437         odr_explicit(o, z_External, &(*p)->resourceReport, ODR_CONTEXT,
438             40, 1) &&
439         odr_implicit(o, odr_integer, &(*p)->partialResultsAvailable,
440             ODR_CONTEXT, 41, 1) &&
441         odr_implicit(o, odr_bool, &(*p)->responseRequired, ODR_CONTEXT,
442             42, 0) &&
443         odr_implicit(o, odr_bool, &(*p)->triggeredRequestFlag,
444             ODR_CONTEXT, 43, 1) &&
445 #ifdef Z_95
446         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
447 #endif
448         odr_sequence_end(o);
449 }
450
451 int z_ResourceControlResponse(ODR o, Z_ResourceControlResponse **p, int opt)
452 {
453     if (!odr_sequence_begin(o, p, sizeof(**p)))
454         return opt && odr_ok(o);
455     return
456         z_ReferenceId(o, &(*p)->referenceId, 1) &&
457         odr_implicit(o, odr_bool, &(*p)->continueFlag, ODR_CONTEXT, 44, 0) &&
458         odr_implicit(o, odr_bool, &(*p)->resultSetWanted, ODR_CONTEXT,
459             45, 1) &&
460 #ifdef Z_95
461         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
462 #endif
463         odr_sequence_end(o);
464 }
465
466 /* ------------------------ SEARCH SERVICE ----------------------- */
467
468 int z_DatabaseSpecificUnit(ODR o, Z_DatabaseSpecificUnit **p, int opt)
469 {
470     if (!odr_sequence_begin(o, p, sizeof(**p)))
471         return opt && odr_ok(o);
472     return
473         z_DatabaseName(o, &(*p)->databaseName, 0) &&
474         z_ElementSetName(o, &(*p)->elementSetName, 0) &&
475         odr_sequence_end(o);
476 }
477
478 int z_DatabaseSpecific(ODR o, Z_DatabaseSpecific **p, int opt)
479 {
480     if (o->direction == ODR_DECODE)
481         *p = odr_malloc(o, sizeof(**p));
482     else if (!*p)
483         return opt;
484
485     odr_implicit_settag(o, ODR_CONTEXT, 1);
486     if (odr_sequence_of(o, z_DatabaseSpecificUnit, &(*p)->elements,
487         &(*p)->num_elements))
488         return 1;
489     *p = 0;
490     return 0;
491 }
492
493 int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
494 {
495     static Odr_arm arm[] =
496     {
497         {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_ElementSetNames_generic,
498             z_ElementSetName},
499         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementSetNames_databaseSpecific,
500             z_DatabaseSpecific},
501         {-1, -1, -1, -1, 0}
502     };
503
504     if (o->direction == ODR_DECODE)
505         *p = odr_malloc(o, sizeof(**p));
506     else if (!*p)
507         return opt && odr_ok(o);
508
509     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
510         return 1;
511     *p = 0;
512     return 0;
513 }
514
515 /* ----------------------- RPN QUERY -----------------------*/
516
517 int z_ComplexAttribute(ODR o, Z_ComplexAttribute **p, int opt)
518 {
519     if (!odr_sequence_begin(o, p, sizeof(**p)))
520         return opt && odr_ok(o);
521     return
522         odr_implicit_settag(o, ODR_CONTEXT, 1) &&
523         odr_sequence_of(o, z_StringOrNumeric, &(*p)->list,
524             &(*p)->num_list) &&
525         odr_implicit_settag(o, ODR_CONTEXT, 2) &&
526         (odr_sequence_of(o, odr_integer, &(*p)->semanticAction,
527             &(*p)->num_semanticAction) || odr_ok(o)) &&
528         odr_sequence_end(o);
529 }
530
531 int z_AttributeElement(ODR o, Z_AttributeElement **p, int opt)
532 {
533 #ifdef Z_95
534     static Odr_arm arm[] =
535     {
536         {ODR_IMPLICIT, ODR_CONTEXT, 121, Z_AttributeValue_numeric,
537             odr_integer},
538         {ODR_IMPLICIT, ODR_CONTEXT, 224, Z_AttributeValue_complex,
539             z_ComplexAttribute},
540         {-1, -1, -1, -1, 0}
541     };
542 #endif
543
544     if (!odr_sequence_begin(o, p, sizeof(**p)))
545         return opt && odr_ok(o);
546     return
547 #ifdef Z_95
548         odr_implicit(o, odr_oid, &(*p)->attributeSet, ODR_CONTEXT, 1, 1) &&
549 #endif
550         odr_implicit(o, odr_integer, &(*p)->attributeType, ODR_CONTEXT,
551             120, 0) &&
552 #ifdef Z_95
553         odr_choice(o, arm, &(*p)->value, &(*p)->which) &&
554 #else
555         odr_implicit(o, odr_integer, &(*p)->attributeValue, ODR_CONTEXT,
556             121, 0) &&
557 #endif
558         odr_sequence_end(o);
559 }
560
561 int z_Term(ODR o, Z_Term **p, int opt)
562 {
563     static Odr_arm arm[] =
564     {
565         {ODR_IMPLICIT, ODR_CONTEXT, 45, Z_Term_general, odr_octetstring},
566         {ODR_IMPLICIT, ODR_CONTEXT, 215, Z_Term_numeric, odr_integer},
567         {ODR_IMPLICIT, ODR_CONTEXT, 216, Z_Term_characterString,
568             odr_visiblestring},
569         {ODR_IMPLICIT, ODR_CONTEXT, 217, Z_Term_oid, odr_oid},
570         {ODR_IMPLICIT, ODR_CONTEXT, 218, Z_Term_dateTime, odr_cstring},
571         {ODR_IMPLICIT, ODR_CONTEXT, 219, Z_Term_external, z_External},
572         /* add intUnit here */
573         {ODR_IMPLICIT, ODR_CONTEXT, 221, Z_Term_null, odr_null},
574         {-1, -1, -1, -1, 0}
575     };
576
577     if (o->direction ==ODR_DECODE)
578         *p = odr_malloc(o, sizeof(**p));
579     else if (!*p)
580         return opt;
581     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
582         return 1;
583     *p = 0;
584     return opt && odr_ok(o);
585 }
586
587 int z_AttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
588 {
589     if (!(odr_implicit_settag(o, ODR_CONTEXT, 102) &&
590         odr_sequence_begin(o, p, sizeof(**p))))
591         return opt && odr_ok(o);
592     return
593         odr_implicit_settag(o, ODR_CONTEXT, 44) &&
594         odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
595             &(*p)->num_attributes) &&
596         z_Term(o, &(*p)->term, 0) &&
597         odr_sequence_end(o);
598 }
599
600 int z_ResultSetPlusAttributes(ODR o, Z_ResultSetPlusAttributes **p, int opt)
601 {
602     if (!(odr_implicit_settag(o, ODR_CONTEXT, 214) &&
603         odr_sequence_begin(o, p, sizeof(**p))))
604         return opt && odr_ok(o);
605     return
606         z_ResultSetId(o, &(*p)->resultSet, 0) &&
607         odr_implicit_settag(o, ODR_CONTEXT, 44) &&
608         odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
609             &(*p)->num_attributes) &&
610         odr_sequence_end(o);
611 }
612
613 int z_ProximityOperator(ODR o, Z_ProximityOperator **p, int opt)
614 {
615     static Odr_arm arm[] =
616     {
617         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ProxCode_known, odr_integer},
618         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ProxCode_private, odr_integer},
619         {-1, -1, -1, -1, 0}
620     };
621
622     if (!odr_sequence_begin(o, p, sizeof(**p)))
623         return opt && odr_ok(o);
624     return
625         odr_implicit(o, odr_bool, &(*p)->exclusion, ODR_CONTEXT, 1, 1) &&
626         odr_implicit(o, odr_integer, &(*p)->distance, ODR_CONTEXT, 2, 0) &&
627         odr_implicit(o, odr_bool, &(*p)->ordered, ODR_CONTEXT, 3, 0) &&
628         odr_implicit(o, odr_integer, &(*p)->relationType, ODR_CONTEXT, 4, 0) &&
629         odr_constructed_begin(o, &(*p)->proximityUnitCode, ODR_CONTEXT, 5) &&
630         odr_choice(o, arm, &(*p)->proximityUnitCode, &(*p)->which) &&
631         odr_constructed_end(o) &&
632         odr_sequence_end(o);
633 }
634
635 int z_Operator(ODR o, Z_Operator **p, int opt)
636 {
637     static Odr_arm arm[] =
638     {
639         {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_Operator_and, odr_null},
640         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Operator_or, odr_null},
641         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Operator_and_not, odr_null},
642         {ODR_IMPLICIT, ODR_CONTEXT, 3, Z_Operator_prox, z_ProximityOperator},
643         {-1, -1, -1, -1, 0}
644     };
645
646     if (!*p && o->direction != ODR_DECODE)
647         return opt;
648     if (!odr_constructed_begin(o, p, ODR_CONTEXT, 46))
649         return opt && odr_ok(o);
650     if (o->direction == ODR_DECODE)
651         *p = odr_malloc(o, sizeof(**p));
652
653     if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
654         odr_constructed_end(o))
655         return 1;
656     *p = 0;
657     return opt && odr_ok(o);
658 }
659
660 int z_Operand(ODR o, Z_Operand **p, int opt)
661 {
662     static Odr_arm arm[] =
663     {
664         {-1, -1, -1, Z_Operand_APT, z_AttributesPlusTerm},
665         {-1, -1, -1, Z_Operand_resultSetId, z_ResultSetId},
666         {-1, -1, -1, Z_Operand_resultAttr, z_ResultSetPlusAttributes},
667         {-1, -1, -1, -1, 0}
668     };
669
670     if (o->direction == ODR_DECODE)
671         *p = odr_malloc(o, sizeof(**p));
672     else if (!*p)
673         return opt;
674     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
675         return 1;
676     *p = 0;
677     return opt && odr_ok(o);
678 }
679
680 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt);
681
682 int z_Complex(ODR o, Z_Complex **p, int opt)
683 {
684     if (!odr_sequence_begin(o, p, sizeof(**p)))
685         return opt && odr_ok(o);
686     return
687         z_RPNStructure(o, &(*p)->s1, 0) &&
688         z_RPNStructure(o, &(*p)->s2, 0) &&
689         z_Operator(o, &(*p)->roperator, 0) &&
690         odr_sequence_end(o);
691 }
692
693 int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt)
694 {
695     static Odr_arm arm[] = 
696     {
697         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand},
698         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_RPNStructure_complex, z_Complex},
699         {-1 -1, -1, -1, 0}
700     };
701
702     if (o->direction == ODR_DECODE)
703         *p = odr_malloc(o, sizeof(**p));
704     else if (!*p)
705         return opt;
706     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
707         return 1;
708     *p = 0;
709     return opt && odr_ok(o);
710 }
711
712 int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
713 {
714     if (!odr_sequence_begin(o, p, sizeof(**p)))
715         return opt && odr_ok(o);
716     return
717         odr_oid(o, &(*p)->attributeSetId, 0) &&
718         z_RPNStructure(o, &(*p)->RPNStructure, 0) &&
719         odr_sequence_end(o);
720 }
721
722 /* -----------------------END RPN QUERY ----------------------- */
723
724 int z_Query(ODR o, Z_Query **p, int opt)
725 {
726     static Odr_arm arm[] = 
727     {
728         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Query_type_1, z_RPNQuery},
729         {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_octetstring},
730         {ODR_EXPLICIT, ODR_CONTEXT, 101, Z_Query_type_101, z_RPNQuery},
731         {-1, -1, -1, -1, 0}
732     };
733
734     if (o->direction == ODR_DECODE)
735         *p = odr_malloc(o, sizeof(**p));
736     else if (!*p)
737         return opt;
738     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
739         return 1;
740     *p = 0;
741     return opt && odr_ok(o);
742 }
743
744 int z_SearchRequest(ODR o, Z_SearchRequest **p, int opt)
745 {
746     Z_SearchRequest *pp;
747
748     if (!odr_sequence_begin(o, p, sizeof(**p)))
749         return opt && odr_ok(o);
750     pp = *p;
751     return
752         z_ReferenceId(o, &pp->referenceId, 1) &&
753         odr_implicit(o, odr_integer, &pp->smallSetUpperBound, ODR_CONTEXT,
754             13, 0) &&
755         odr_implicit(o, odr_integer, &pp->largeSetLowerBound, ODR_CONTEXT,
756             14, 0) &&
757         odr_implicit(o, odr_integer, &pp->mediumSetPresentNumber, ODR_CONTEXT,
758             15, 0) &&
759         odr_implicit(o, odr_bool, &pp->replaceIndicator, ODR_CONTEXT, 16, 1) &&
760         odr_implicit(o, odr_visiblestring, &pp->resultSetName, ODR_CONTEXT,
761             17, 9) &&
762         odr_implicit_settag(o, ODR_CONTEXT, 18) &&
763         odr_sequence_of(o, z_DatabaseName, &pp->databaseNames,
764             &pp->num_databaseNames) &&
765         odr_explicit(o, z_ElementSetNames, &pp->smallSetElementSetNames,
766             ODR_CONTEXT, 100, 1) &&
767         odr_explicit(o, z_ElementSetNames, &pp->mediumSetElementSetNames,
768             ODR_CONTEXT, 101, 1) &&
769         odr_implicit(o, odr_oid, &pp->preferredRecordSyntax,
770             ODR_CONTEXT, 104, 1) &&
771         odr_explicit(o, z_Query, &pp->query, ODR_CONTEXT, 21, 0) &&
772 #ifdef Z_95
773         odr_implicit(o, z_OtherInformation, &(*p)->additionalSearchInfo,
774             ODR_CONTEXT, 203, 1) &&
775         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
776 #endif
777         odr_sequence_end(o);
778 }
779
780 /* ------------------------ RECORD ------------------------- */
781
782 int z_DatabaseRecord(ODR o, Z_DatabaseRecord **p, int opt)
783 {
784     return z_External(o, (Z_External **) p, opt);
785 }
786
787 #ifdef Z_95
788
789 int z_DefaultDiagFormat(ODR o, Z_DefaultDiagFormat **p, int opt)
790 {
791     static Odr_arm arm[] =
792     {
793         {-1, -1, -1, Z_DiagForm_v2AddInfo, odr_visiblestring},
794         {-1, -1, -1, Z_DiagForm_v3AddInfo, z_InternationalString},
795         {ODR_IMPLICIT, ODR_CONTEXT, ODR_VISIBLESTRING, Z_DiagForm_v2AddInfo,
796             odr_visiblestring}, /* To cater to a bug in the CNIDR servers */
797         {-1, -1, -1, -1, 0}
798     };
799     if (!odr_sequence_begin(o, p, sizeof(**p)))
800         return opt && odr_ok(o);
801     return
802         odr_oid(o, &(*p)->diagnosticSetId, 1) && /* SHOULD NOT BE OPT! */
803         odr_integer(o, &(*p)->condition, 0) &&
804         /*
805          * I no longer recall what server tagged the addinfo.. but it isn't
806          * hurting anyone, so...
807          * We need to turn it into a choice, or something, because of
808          * that damn generalstring in v3.
809          */
810         odr_choice(o, arm, &(*p)->addinfo, &(*p)->which) &&
811         odr_sequence_end(o);
812 }
813
814 int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
815 {
816     static Odr_arm arm[] = 
817     {
818         {-1, -1, -1, Z_DiagRec_defaultFormat, z_DefaultDiagFormat},
819         {-1, -1, -1, Z_DiagRec_externallyDefined, z_External},
820         {-1, -1, -1, -1, 0}
821     };
822
823     if (o->direction == ODR_DECODE)
824         *p = odr_malloc(o, sizeof(**p));
825     else if (!*p)
826         return opt;
827     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
828         return 1;
829     *p = 0;
830     return opt && odr_ok(o);
831 }
832
833 #else
834
835 int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
836 {
837     if (!odr_sequence_begin(o, p, sizeof(**p)))
838         return opt && odr_ok(o);
839     return
840         odr_oid(o, &(*p)->diagnosticSetId, 1) && /* SHOULD NOT BE OPT! */
841         odr_integer(o, &(*p)->condition, 0) &&
842         /*
843          * I no longer recall what server tagged the addinfo.. but it isn't
844          * hurting anyone, so...
845          * We need to turn it into a choice, or something, because of
846          * that damn generalstring in v3.
847          */
848         (odr_visiblestring(o, &(*p)->addinfo, 0) ||
849             odr_implicit(o, odr_cstring, &(*p)->addinfo, ODR_CONTEXT,
850             ODR_VISIBLESTRING, 1)) &&
851         odr_sequence_end(o);
852 }
853
854 #endif
855
856 int z_DiagRecs(ODR o, Z_DiagRecs **p, int opt)
857 {
858     if (o->direction == ODR_DECODE)
859         *p = odr_malloc(o, sizeof(**p));
860     else if (!*p)
861         return opt;
862
863         if (odr_sequence_of(o, z_DiagRec, &(*p)->diagRecs,
864         &(*p)->num_diagRecs))
865         return 1;
866     *p = 0;
867     return 0;
868 }
869
870 int z_NamePlusRecord(ODR o, Z_NamePlusRecord **p, int opt)
871 {
872     static Odr_arm arm[] =
873     {
874         {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_NamePlusRecord_databaseRecord,
875             z_DatabaseRecord},
876         {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_NamePlusRecord_surrogateDiagnostic,
877             z_DiagRec},
878         {-1, -1, -1, -1, 0}
879     };
880
881     if (!odr_sequence_begin(o, p, sizeof(**p)))
882         return opt && odr_ok(o);
883     return
884         odr_implicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
885             0, 1) &&
886         odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 1) &&
887         odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
888         odr_constructed_end(o) &&
889         odr_sequence_end(o);
890 }
891
892 int z_NamePlusRecordList(ODR o, Z_NamePlusRecordList **p, int opt)
893 {
894     if (o->direction == ODR_DECODE)
895         *p = odr_malloc(o, sizeof(**p));
896     else if (!*p)
897         return opt;
898     if (odr_sequence_of(o, z_NamePlusRecord, &(*p)->records,
899         &(*p)->num_records))
900         return 1;
901     *p = 0;
902     return 0;
903 }
904
905 int z_Records(ODR o, Z_Records **p, int opt)
906 {
907     static Odr_arm arm[] = 
908     {
909         {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_Records_DBOSD, z_NamePlusRecordList},
910         {ODR_IMPLICIT, ODR_CONTEXT, 130, Z_Records_NSD, z_DiagRec},
911         {ODR_IMPLICIT, ODR_CONTEXT, 205, Z_Records_multipleNSD,
912             z_DiagRecs},
913         {-1, -1, -1, -1, 0}
914     };
915
916     if (o->direction == ODR_DECODE)
917         *p = odr_malloc(o, sizeof(**p));
918     else if (!*p)
919         return opt;
920     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
921         return 1;
922     *p = 0;
923     return opt && odr_ok(o);
924 }
925
926 /* ------------------------ ACCESS CTRL SERVICE ----------------------- */
927
928 int z_AccessControlRequest(ODR o, Z_AccessControlRequest **p, int opt)
929 {
930     static Odr_arm arm[] = 
931     {
932         {ODR_IMPLICIT, ODR_CONTEXT, 37, Z_AccessRequest_simpleForm,
933             odr_octetstring},
934         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_AccessRequest_externallyDefined,
935             z_External},
936         {-1, -1, -1, -1, 0}
937     };
938     if (!odr_sequence_begin(o, p, sizeof(**p)))
939         return opt && odr_ok(o);
940     return
941         z_ReferenceId(o, &(*p)->referenceId, 1) &&
942         odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
943 #ifdef Z_95
944         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
945 #endif
946         odr_sequence_end(o);
947 }
948
949 int z_AccessControlResponse(ODR o, Z_AccessControlResponse **p, int opt)
950 {
951     static Odr_arm arm[] = 
952     {
953         {ODR_IMPLICIT, ODR_CONTEXT, 38, Z_AccessResponse_simpleForm,
954             odr_octetstring},
955         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_AccessResponse_externallyDefined,
956             z_External},
957         {-1, -1, -1, -1, 0}
958     };
959     if (!odr_sequence_begin(o, p, sizeof(**p)))
960         return opt && odr_ok(o);
961     return
962         z_ReferenceId(o, &(*p)->referenceId, 1) &&
963         odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
964         odr_explicit(o, z_DiagRec, &(*p)->diagnostic, ODR_CONTEXT, 223, 1) &&
965 #ifdef Z_95
966         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
967 #endif
968         odr_sequence_end(o);
969 }
970
971 /* ------------------------ SCAN SERVICE -------------------- */
972
973 int z_AttributeList(ODR o, Z_AttributeList **p, int opt)
974 {
975     if (o->direction == ODR_DECODE)
976         *p = odr_malloc(o, sizeof(**p));
977     else if (!*p)
978         return opt;
979
980     odr_implicit_settag(o, ODR_CONTEXT, 44);
981     if (odr_sequence_of(o, z_AttributeElement, &(*p)->attributes,
982         &(*p)->num_attributes))
983         return 1;
984     *p = 0;
985     return opt && odr_ok(o);
986 }
987
988 /*
989  * This is a temporary hack. We don't know just *what* old version of the
990  * protocol willow uses, so we'll just patiently wait for them to update
991  */
992 static int willow_scan = 0;
993
994 int z_WillowAttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
995 {
996     if (!*p && o->direction != ODR_DECODE)
997         return opt;
998     if (!odr_constructed_begin(o, p, ODR_CONTEXT, 4))
999     {
1000         o->t_class = -1;
1001         return opt && odr_ok(o);
1002     }
1003     if (!odr_constructed_begin(o, p, ODR_CONTEXT, 1))
1004         return 0;
1005     if (!odr_constructed_begin(o, p, ODR_UNIVERSAL, ODR_SEQUENCE))
1006         return 0;
1007     if (!odr_implicit_settag(o, ODR_CONTEXT, 44))
1008         return 0;
1009     if (o->direction == ODR_DECODE)
1010         *p = odr_malloc(o, sizeof(**p));
1011     if (!odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
1012         &(*p)->num_attributes))
1013         return 0;
1014     if (!odr_sequence_end(o) || !odr_sequence_end(o))
1015         return 0;
1016     if (!z_Term(o, &(*p)->term, 0))
1017         return 0;
1018     if (!odr_constructed_end(o))
1019         return 0;
1020     willow_scan = 1;
1021     return 1;
1022 }
1023
1024 int z_AlternativeTerm(ODR o, Z_AlternativeTerm **p, int opt)
1025 {
1026     if (o->direction == ODR_DECODE)
1027         *p = odr_malloc(o, sizeof(**p));
1028     else if (!*p)
1029     {
1030         o->t_class = -1;
1031         return opt && odr_ok(o);
1032     }
1033
1034     if (odr_sequence_of(o, z_AttributesPlusTerm, &(*p)->terms,
1035         &(*p)->num_terms))
1036         return 1;
1037     *p = 0;
1038     return opt && !o->error;
1039 }
1040
1041 int z_OccurrenceByAttributes(ODR o, Z_OccurrenceByAttributes **p, int opt)
1042 {
1043     if (!odr_sequence_begin(o, p, sizeof(**p)))
1044         return opt && odr_ok(o);
1045     return
1046         odr_explicit(o, z_AttributeList, &(*p)->attributes, ODR_CONTEXT, 1, 1)&&
1047         odr_explicit(o, odr_integer, &(*p)->global, ODR_CONTEXT, 2, 1) &&
1048         odr_sequence_end(o);
1049 }
1050
1051 int z_TermInfo(ODR o, Z_TermInfo **p, int opt)
1052 {
1053     if (!odr_sequence_begin(o, p, sizeof(**p)))
1054         return opt && odr_ok(o);
1055     return
1056         (willow_scan ? 
1057             odr_implicit(o, z_Term, &(*p)->term, ODR_CONTEXT, 1, 0) :
1058             z_Term(o, &(*p)->term, 0)) &&
1059         z_AttributeList(o, &(*p)->suggestedAttributes, 1) &&
1060         odr_implicit(o, z_AlternativeTerm, &(*p)->alternativeTerm,
1061             ODR_CONTEXT, 4, 1) &&
1062         odr_implicit(o, odr_integer, &(*p)->globalOccurrences, ODR_CONTEXT,
1063             2, 1) &&
1064         odr_implicit(o, z_OccurrenceByAttributes, &(*p)->byAttributes,
1065             ODR_CONTEXT, 3, 1) &&
1066         odr_sequence_end(o);
1067 }
1068
1069 int z_Entry(ODR o, Z_Entry **p, int opt)
1070 {
1071     static Odr_arm arm[] =
1072     {
1073         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Entry_termInfo, z_TermInfo},
1074         {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_Entry_surrogateDiagnostic,
1075             z_DiagRec},
1076         {-1, -1, -1, -1, 0}
1077     };
1078
1079     if (o->direction == ODR_DECODE)
1080         *p = odr_malloc(o, sizeof(**p));
1081     else if (!*p)
1082         return opt;
1083
1084     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
1085         return 1;
1086     *p = 0;
1087     return opt && odr_ok(o);
1088 }
1089
1090 int z_Entries(ODR o, Z_Entries **p, int opt)
1091 {
1092     if (o->direction == ODR_DECODE)
1093         *p = odr_malloc(o, sizeof(**p));
1094     else if (!*p)
1095         return opt;
1096
1097     if (odr_sequence_of(o, z_Entry, &(*p)->entries,
1098         &(*p)->num_entries))
1099         return 1;
1100     *p = 0;
1101     return 0;
1102 }
1103
1104 int z_ListEntries(ODR o, Z_ListEntries **p, int opt)
1105 {
1106     static Odr_arm arm[] =
1107     {
1108         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ListEntries_entries, z_Entries},
1109         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_ListEntries_nonSurrogateDiagnostics,
1110             z_DiagRecs},
1111         {-1, -1, -1, -1, 0}
1112     };
1113
1114     if (o->direction == ODR_DECODE)
1115         *p = odr_malloc(o, sizeof(**p));
1116     else if (!*p)
1117         return opt;
1118
1119     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
1120         return 1;
1121     *p = 0;
1122     return opt && odr_ok(o);
1123 }
1124
1125 int z_ScanRequest(ODR o, Z_ScanRequest **p, int opt)
1126 {
1127     if (!odr_sequence_begin(o, p, sizeof(**p)))
1128         return opt && odr_ok(o);
1129     willow_scan = 0;
1130     return
1131         z_ReferenceId(o, &(*p)->referenceId, 1) &&
1132         odr_implicit_settag(o, ODR_CONTEXT, 3) &&
1133         odr_sequence_of(o, z_DatabaseName, &(*p)->databaseNames,
1134             &(*p)->num_databaseNames) &&
1135         odr_oid(o, &(*p)->attributeSet, 1) &&
1136         (z_AttributesPlusTerm(o, &(*p)->termListAndStartPoint, 1) ?
1137             ((*p)->termListAndStartPoint ? 1 : 
1138         z_WillowAttributesPlusTerm(o, &(*p)->termListAndStartPoint, 0)) : 0) &&
1139         odr_implicit(o, odr_integer, &(*p)->stepSize, ODR_CONTEXT, 5, 1) &&
1140         odr_implicit(o, odr_integer, &(*p)->numberOfTermsRequested,
1141             ODR_CONTEXT, 6, 0) &&
1142         odr_implicit(o, odr_integer, &(*p)->preferredPositionInResponse,
1143             ODR_CONTEXT, 7, 1) &&
1144         odr_sequence_end(o);
1145 }
1146
1147 int z_ScanResponse(ODR o, Z_ScanResponse **p, int opt)
1148 {
1149     if (!odr_sequence_begin(o, p, sizeof(**p)))
1150         return opt && odr_ok(o);
1151     return
1152         z_ReferenceId(o, &(*p)->referenceId, 1) &&
1153         odr_implicit(o, odr_integer, &(*p)->stepSize, ODR_CONTEXT, 3, 1) &&
1154         odr_implicit(o, odr_integer, &(*p)->scanStatus, ODR_CONTEXT, 4, 0) &&
1155         odr_implicit(o, odr_integer, &(*p)->numberOfEntriesReturned,
1156             ODR_CONTEXT, 5, 0) &&
1157         odr_implicit(o, odr_integer, &(*p)->positionOfTerm, ODR_CONTEXT, 6, 1)&&
1158         odr_explicit(o, z_ListEntries, &(*p)->entries, ODR_CONTEXT, 7, 1) &&
1159         odr_implicit(o, odr_oid, &(*p)->attributeSet, ODR_CONTEXT, 8, 1) &&
1160         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
1161         odr_sequence_end(o);
1162 }
1163
1164 /* ------------------------ SEARCHRESPONSE ----------------*/
1165
1166 int z_NumberOfRecordsReturned(ODR o, int **p, int opt)
1167 {
1168     return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 24, opt);
1169 }
1170
1171 int z_NextResultSetPosition(ODR o, int **p, int opt)
1172 {
1173     return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 25, opt);
1174 }
1175
1176 int z_PresentStatus(ODR o, int **p, int opt)
1177 {
1178     return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 27, opt);
1179 }
1180
1181 int z_SearchResponse(ODR o, Z_SearchResponse **p, int opt)
1182 {
1183     Z_SearchResponse *pp;
1184
1185     if (!odr_sequence_begin(o, p, sizeof(**p)))
1186         return opt && odr_ok(o);
1187     pp = *p;
1188     return
1189         z_ReferenceId(o, &pp->referenceId, 1) &&
1190         odr_implicit(o, odr_integer, &pp->resultCount, ODR_CONTEXT, 23, 0) &&
1191         z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
1192         z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
1193         odr_implicit(o, odr_bool, &pp->searchStatus, ODR_CONTEXT, 22, 0) &&
1194         odr_implicit(o, odr_integer, &pp->resultSetStatus, ODR_CONTEXT, 26,
1195             1) &&
1196         z_PresentStatus(o, &pp->presentStatus, 1) &&
1197         z_Records(o, &pp->records, 1) &&
1198 #ifdef Z_95
1199         odr_implicit(o, z_OtherInformation, &(*p)->additionalSearchInfo,
1200             ODR_CONTEXT, 203, 1) &&
1201         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
1202 #endif
1203         odr_sequence_end(o);
1204 }
1205
1206 /* --------------------- PRESENT SERVICE ---------------------- */
1207
1208 int z_ElementSpec(ODR o, Z_ElementSpec **p, int opt)
1209 {
1210     static Odr_arm arm[] =
1211     {
1212         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementSpec_elementSetName,
1213             odr_visiblestring},
1214         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_ElementSpec_externalSpec,
1215             z_External},
1216         {-1, -1, -1, -1, 0}
1217     };
1218
1219     if (o->direction == ODR_DECODE)
1220         *p = odr_malloc(o, sizeof(**p));
1221     else if (!*p)
1222         return opt;
1223
1224     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
1225         return 1;
1226     *p = 0;
1227     return opt && odr_ok(o);
1228 }
1229
1230 int z_Specification(ODR o, Z_Specification **p, int opt)
1231 {
1232     if (!odr_sequence_begin(o, p, sizeof(**p)))
1233         return opt && odr_ok(o);
1234     return
1235         odr_implicit(o, odr_oid, &(*p)->schema, ODR_CONTEXT, 1, 1) &&
1236         z_ElementSpec(o, &(*p)->elementSpec, 1) &&
1237         odr_sequence_end(o);
1238 }
1239
1240 int z_DbSpecific(ODR o, Z_DbSpecific **p, int opt)
1241 {
1242     if (!odr_sequence_begin(o, p, sizeof(**p)))
1243         return opt && odr_ok(o);
1244     return
1245         odr_explicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
1246             1, 0) &&
1247         odr_implicit(o, z_Specification, &(*p)->spec, ODR_CONTEXT, 2, 0) &&
1248         odr_sequence_end(o);
1249 }
1250
1251 int z_CompSpec(ODR o, Z_CompSpec **p, int opt)
1252 {
1253     if (!odr_sequence_begin(o, p, sizeof(**p)))
1254         return opt && odr_ok(o);
1255     return
1256         odr_implicit(o, odr_bool, &(*p)->selectAlternativeSyntax, ODR_CONTEXT,
1257             1, 0) &&
1258         odr_implicit(o, z_Specification, &(*p)->generic, ODR_CONTEXT, 2, 1) &&
1259         odr_implicit_settag(o, ODR_CONTEXT, 3) &&
1260         (odr_sequence_of(o, z_DbSpecific, &(*p)->dbSpecific,
1261             &(*p)->num_dbSpecific) || odr_ok(o)) &&
1262         odr_implicit_settag(o, ODR_CONTEXT, 4) &&
1263         (odr_sequence_of(o, odr_oid, &(*p)->recordSyntax,
1264             &(*p)->num_recordSyntax) || odr_ok(o)) &&
1265         odr_sequence_end(o);
1266 }
1267
1268 int z_RecordComposition(ODR o, Z_RecordComposition **p, int opt)
1269 {
1270     static Odr_arm arm[] =
1271     {
1272         {ODR_EXPLICIT, ODR_CONTEXT, 19, Z_RecordComp_simple,
1273             z_ElementSetNames},
1274         {ODR_IMPLICIT, ODR_CONTEXT, 209, Z_RecordComp_complex,
1275             z_CompSpec},
1276         {-1, -1, -1, -1, 0}
1277     };
1278
1279     if (o->direction == ODR_DECODE)
1280         *p = odr_malloc(o, sizeof(**p));
1281     else if (!*p)
1282         return opt;
1283
1284     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
1285         return 1;
1286     *p = 0;
1287     return opt && odr_ok(o);
1288 }
1289
1290 int z_Range(ODR o, Z_Range **p, int opt)
1291 {
1292     if (!odr_sequence_begin(o, p, sizeof(**p)))
1293         return opt && odr_ok(o);
1294     return
1295         odr_implicit(o, odr_integer, &(*p)->startingPosition, ODR_CONTEXT,
1296             1, 0) &&
1297         odr_implicit(o, odr_integer, &(*p)->numberOfRecords, ODR_CONTEXT,
1298             2, 0) &&
1299         odr_sequence_end(o);
1300 }
1301
1302 int z_PresentRequest(ODR o, Z_PresentRequest **p, int opt)
1303 {
1304     Z_PresentRequest *pp;
1305
1306     if (!odr_sequence_begin(o, p, sizeof(**p)))
1307         return opt && odr_ok(o);
1308     pp = *p;
1309     return
1310         z_ReferenceId(o, &pp->referenceId, 1) &&
1311         z_ResultSetId(o, &pp->resultSetId, 0) &&
1312         odr_implicit(o, odr_integer, &pp->resultSetStartPoint, ODR_CONTEXT,
1313             30, 0) &&
1314         odr_implicit(o, odr_integer, &pp->numberOfRecordsRequested, ODR_CONTEXT,
1315             29, 0) &&
1316 #ifdef Z_95
1317         odr_implicit_settag(o, ODR_CONTEXT, 212) &&
1318         (odr_sequence_of(o, z_Range, &(*p)->additionalRanges,
1319             &(*p)->num_ranges) || odr_ok(o)) &&
1320         z_RecordComposition(o, &(*p)->recordComposition, 1) &&
1321 #else
1322         odr_explicit(o, z_ElementSetNames, &pp->elementSetNames, ODR_CONTEXT,
1323             19, 1) &&
1324 #endif
1325         odr_implicit(o, odr_oid, &(*p)->preferredRecordSyntax, ODR_CONTEXT,
1326             104, 1) &&
1327 #ifdef Z_95
1328         odr_implicit(o, odr_integer, &(*p)->maxSegmentCount, ODR_CONTEXT,
1329             204, 1) &&
1330         odr_implicit(o, odr_integer, &(*p)->maxRecordSize, ODR_CONTEXT,
1331             206, 1) &&
1332         odr_implicit(o, odr_integer, &(*p)->maxSegmentSize, ODR_CONTEXT,
1333             207, 1) &&
1334         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
1335 #endif
1336         odr_sequence_end(o);
1337 }
1338
1339 int z_PresentResponse(ODR o, Z_PresentResponse **p, int opt)
1340 {
1341     Z_PresentResponse *pp;
1342
1343     if (!odr_sequence_begin(o, p, sizeof(**p)))
1344         return opt && odr_ok(o);
1345     pp = *p;
1346     return
1347         z_ReferenceId(o, &pp->referenceId, 1) &&
1348         z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
1349         z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
1350         z_PresentStatus(o, &pp->presentStatus, 0) &&
1351         z_Records(o, &pp->records, 1) &&
1352 #ifdef Z_95
1353         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
1354 #endif
1355         odr_sequence_end(o);
1356 }
1357
1358 /* ----------------------DELETE -------------------------- */
1359
1360 int z_DeleteSetStatus(ODR o, int **p, int opt)
1361 {
1362     return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 33, opt);
1363 }
1364
1365 int z_ListStatus(ODR o, Z_ListStatus **p, int opt)
1366 {
1367     if (!odr_sequence_begin(o, p, sizeof(**p)))
1368         return opt && odr_ok(o);
1369     return
1370         z_ResultSetId(o, &(*p)->id, 0) &&
1371         z_DeleteSetStatus(o, &(*p)->status, 0) &&
1372         odr_sequence_end(o);
1373 }
1374
1375 int z_DeleteResultSetRequest(ODR o, Z_DeleteResultSetRequest **p, int opt)
1376 {
1377     if (!odr_sequence_begin(o, p, sizeof(**p)))
1378         return opt && odr_ok(o);
1379     return
1380         z_ReferenceId(o, &(*p)->referenceId, 1) &&
1381         odr_implicit(o, odr_integer, &(*p)->deleteFunction, ODR_CONTEXT, 32,
1382             0) &&
1383         (odr_sequence_of(o, z_ListStatus, &(*p)->resultSetList,
1384             &(*p)->num_ids) || odr_ok(o)) &&
1385 #ifdef Z_95
1386         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
1387 #endif
1388         odr_sequence_end(o);
1389 }
1390
1391 int z_DeleteResultSetResponse(ODR o, Z_DeleteResultSetResponse **p, int opt)
1392 {
1393     if (!odr_sequence_begin(o, p, sizeof(**p)))
1394         return opt && odr_ok(o);
1395     return
1396         z_ReferenceId(o, &(*p)->referenceId, 1) &&
1397         odr_implicit(o, z_DeleteSetStatus, &(*p)->deleteOperationStatus,
1398             ODR_CONTEXT, 0, 1) &&
1399         odr_implicit_settag(o, ODR_CONTEXT, 1) &&
1400         (odr_sequence_of(o, z_ListStatus, &(*p)->deleteListStatuses,
1401             &(*p)->num_statuses) || odr_ok(o)) &&
1402         odr_implicit(o, odr_integer, &(*p)->numberNotDeleted, ODR_CONTEXT,
1403             34, 1) &&
1404         odr_implicit_settag(o, ODR_CONTEXT, 35) &&
1405         (odr_sequence_of(o, z_ListStatus, &(*p)->bulkStatuses,
1406             &(*p)->num_bulkStatuses) || odr_ok(o)) &&
1407         odr_implicit(o, odr_visiblestring, &(*p)->deleteMessage, ODR_CONTEXT,
1408             36, 1) &&
1409 #ifdef Z_95
1410         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
1411 #endif
1412         odr_sequence_end(o);
1413 }
1414
1415 /* ------------------------ SEGMENT SERVICE -------------- */
1416
1417 int z_Segment(ODR o, Z_Segment **p, int opt)
1418 {
1419     if (!odr_sequence_begin(o, p, sizeof(**p)))
1420         return opt && odr_ok(o);
1421     return
1422         z_ReferenceId(o, &(*p)->referenceId, 1) &&
1423         odr_implicit(o, odr_integer, &(*p)->numberOfRecordsReturned,
1424             ODR_CONTEXT, 24, 0) &&
1425         odr_implicit_settag(o, ODR_CONTEXT, 0) &&
1426         odr_sequence_of(o, z_NamePlusRecord, &(*p)->segmentRecords,
1427             &(*p)->num_segmentRecords) &&
1428         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
1429         odr_sequence_end(o);
1430 }
1431
1432 /* ------------------------ CLOSE SERVICE ---------------- */
1433
1434 int z_Close(ODR o, Z_Close **p, int opt)
1435 {
1436     if (!odr_sequence_begin(o, p, sizeof(**p)))
1437         return opt && odr_ok(o);
1438     return
1439         z_ReferenceId(o, &(*p)->referenceId, 1) &&
1440         odr_implicit(o, odr_integer, &(*p)->closeReason, ODR_CONTEXT, 211, 0) &&
1441         odr_implicit(o, odr_visiblestring, &(*p)->diagnosticInformation,
1442             ODR_CONTEXT, 3, 1) &&
1443         odr_implicit(o, odr_oid, &(*p)->resourceReportFormat, ODR_CONTEXT,
1444             4, 1) &&
1445         odr_implicit(o, z_External, &(*p)->resourceReport, ODR_CONTEXT,
1446             5, 1) &&
1447 #ifdef Z_95
1448         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
1449 #endif
1450         odr_sequence_end(o);
1451 }
1452
1453 /* ------------------------ APDU ------------------------- */
1454
1455 int z_Permissions(ODR o, Z_Permissions **p, int opt)
1456 {
1457     if (!odr_sequence_begin(o, p, sizeof(**p)))
1458         return opt && odr_ok(o);
1459     return
1460         odr_implicit(o, z_InternationalString, &(*p)->userId, ODR_CONTEXT,
1461             1, 0) &&
1462         odr_implicit_settag(o, ODR_CONTEXT, 2) &&
1463         odr_sequence_of(o, odr_integer, &(*p)->allowableFunctions,
1464             &(*p)->num_allowableFunctions) &&
1465         odr_sequence_end(o);
1466 }
1467
1468 int z_ExtendedServicesRequest(ODR o, Z_ExtendedServicesRequest **p, int opt)
1469 {
1470     if (!odr_sequence_begin(o, p, sizeof(**p)))
1471         return opt && odr_ok(o);
1472     return
1473         z_ReferenceId(o, &(*p)->referenceId, 1) &&
1474         odr_implicit(o, odr_integer, &(*p)->function, ODR_CONTEXT, 3, 0) &&
1475         odr_implicit(o, odr_oid, &(*p)->packageType, ODR_CONTEXT, 4, 0) &&
1476         odr_implicit(o, z_InternationalString, &(*p)->packageName, ODR_CONTEXT, 5, 1) &&
1477         odr_implicit(o, z_InternationalString, &(*p)->userId, ODR_CONTEXT, 6, 1) &&
1478         odr_implicit(o, z_IntUnit, &(*p)->retentionTime, ODR_CONTEXT, 7, 1) &&
1479         odr_implicit(o, z_Permissions, &(*p)->permissions, ODR_CONTEXT, 8, 1) &&
1480         odr_implicit(o, z_InternationalString, &(*p)->description, ODR_CONTEXT, 9, 1) &&
1481         odr_implicit(o, z_External, &(*p)->taskSpecificParameters, ODR_CONTEXT, 10, 1) &&
1482         odr_implicit(o, odr_integer, &(*p)->waitAction, ODR_CONTEXT, 11, 0) &&
1483         z_ElementSetName(o, &(*p)->elements, 1) &&
1484         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
1485         odr_sequence_end(o);
1486 }
1487
1488 int z_ExtendedServicesResponse(ODR o, Z_ExtendedServicesResponse **p, int opt)
1489 {
1490     if (!odr_sequence_begin(o, p, sizeof(**p)))
1491         return opt && odr_ok(o);
1492     return
1493         z_ReferenceId(o, &(*p)->referenceId, 1) &&
1494         odr_implicit(o, odr_integer, &(*p)->operationStatus, ODR_CONTEXT, 3, 0) &&
1495         odr_implicit_settag(o, ODR_CONTEXT, 4) &&
1496         (odr_sequence_of(o, z_DiagRec, &(*p)->diagnostics,
1497             &(*p)->num_diagnostics) || odr_ok(o)) &&
1498         odr_implicit(o, z_External, &(*p)->taskPackage, ODR_CONTEXT, 5, 1) &&
1499         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
1500         odr_sequence_end(o);
1501 }
1502
1503 /* ------------------------ SORT ------------------------- */
1504
1505 int z_SortAttributes(ODR o, Z_SortAttributes **p, int opt)
1506 {
1507     if (!odr_sequence_begin(o, p, sizeof(**p)))
1508         return opt && odr_ok(o);
1509     return
1510         odr_oid(o, &(*p)->id, 0) &&
1511         z_AttributeList(o, &(*p)->list, 0) &&
1512         odr_sequence_end(o);
1513 }
1514
1515 int z_SortKey(ODR o, Z_SortKey **p, int opt)
1516 {
1517     static Odr_arm arm[] =
1518     {
1519         {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_SortKey_sortField,
1520             z_InternationalString},
1521         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_SortKey_elementSpec, z_Specification},
1522         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_SortKey_sortAttributes,
1523             z_SortAttributes},
1524         {-1, -1, -1, -1, 0}
1525     };
1526
1527     if (!odr_initmember(o, p, sizeof(**p)))
1528         return opt && odr_ok(o);
1529     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
1530         return 1;
1531     *p = 0;
1532     return opt && odr_ok(o);
1533 }
1534
1535 int z_SortDbSpecific(ODR o, Z_SortDbSpecific **p, int opt)
1536 {
1537     if (!odr_sequence_begin(o, p, sizeof(**p)))
1538         return opt && odr_ok(o);
1539     return
1540         z_DatabaseName(o, &(*p)->databaseName, 0) &&
1541         z_SortKey(o, &(*p)->dbSort, 0) &&
1542         odr_sequence_end(o);
1543 }
1544
1545 int z_SortDbSpecificList(ODR o, Z_SortDbSpecificList **p, int opt)
1546 {
1547     if (!odr_initmember(o, p, sizeof(**p)))
1548         return opt && odr_ok(o);
1549     if (odr_sequence_of(o, z_SortDbSpecific, &(*p)->dbSpecific,
1550         &(*p)->num_dbSpecific))
1551         return 1;
1552     *p = 0;
1553     return opt && odr_ok(o);
1554 }
1555
1556 int z_SortElement(ODR o, Z_SortElement **p, int opt)
1557 {
1558     static Odr_arm arm[] =
1559     {
1560         {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_SortElement_generic, z_SortKey},
1561         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_SortElement_databaseSpecific,
1562             z_SortDbSpecificList},
1563         {-1, -1, -1, -1, 0}
1564     };
1565
1566     if (!odr_initmember(o, p, sizeof(**p)))
1567         return opt && odr_ok(o);
1568     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
1569         return 1;
1570     *p = 0;
1571     return opt && odr_ok(o);
1572 }
1573
1574 int z_SortMissingValueAction(ODR o, Z_SortMissingValueAction **p, int opt)
1575 {
1576     static Odr_arm arm[] =
1577     {
1578         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_SortMissingValAct_abort, odr_null},
1579         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_SortMissingValAct_null, odr_null},
1580         {ODR_IMPLICIT, ODR_CONTEXT, 3, Z_SortMissingValAct_valData,
1581             odr_octetstring},
1582         {-1, -1, -1, -1, 0}
1583     };
1584
1585     if (!odr_initmember(o, p, sizeof(**p)))
1586         return opt && odr_ok(o);
1587     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
1588         return 1;
1589     *p = 0;
1590     return opt && odr_ok(o);
1591 }
1592
1593 int z_SortKeySpec(ODR o, Z_SortKeySpec **p, int opt)
1594 {
1595     if (!odr_sequence_begin(o, p, sizeof(**p)))
1596         return opt && odr_ok(o);
1597     return
1598         z_SortElement(o, &(*p)->sortElement, 0) &&
1599         odr_implicit(o, odr_integer, &(*p)->sortRelation, ODR_CONTEXT, 1, 0) &&
1600         odr_implicit(o, odr_integer, &(*p)->caseSensitivity, ODR_CONTEXT,
1601             2, 0) &&
1602         odr_explicit(o, z_SortMissingValueAction, &(*p)->missingValueAction,
1603             ODR_CONTEXT, 3, 1) &&
1604         odr_sequence_end(o);
1605 }
1606
1607 int z_SortResponse(ODR o, Z_SortResponse **p, int opt)
1608 {
1609     if (!odr_sequence_begin(o, p, sizeof(**p)))
1610         return opt && odr_ok(o);
1611     return
1612         z_ReferenceId(o, &(*p)->referenceId, 1) &&
1613         odr_implicit(o, odr_integer, &(*p)->sortStatus, ODR_CONTEXT,
1614             3, 0) &&
1615         odr_implicit(o, odr_integer, &(*p)->resultSetStatus, ODR_CONTEXT,
1616             4, 1) &&
1617         odr_implicit(o, z_DiagRecs, &(*p)->diagnostics, ODR_CONTEXT, 5, 1) &&
1618         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
1619         odr_sequence_end(o);
1620 }
1621
1622 int z_SortKeySpecList(ODR o, Z_SortKeySpecList **p, int opt)
1623 {
1624     if (!odr_initmember(o, p, sizeof(**p)))
1625         return opt && odr_ok(o);
1626     if (odr_sequence_of(o, z_SortKeySpec, &(*p)->specs, &(*p)->num_specs))
1627         return 1;
1628     *p = 0;
1629     return opt && odr_ok(o);
1630 }
1631
1632 int z_SortRequest(ODR o, Z_SortRequest **p, int opt)
1633 {
1634     if (!odr_sequence_begin(o, p, sizeof(**p)))
1635         return opt && odr_ok(o);
1636     return
1637         z_ReferenceId(o, &(*p)->referenceId, 1) &&
1638         odr_implicit(o, z_StringList, &(*p)->inputResultSetNames, 
1639             ODR_CONTEXT, 3, 0) &&
1640         odr_implicit(o, z_InternationalString, &(*p)->sortedResultSetName,
1641             ODR_CONTEXT, 4, 0) &&
1642         odr_implicit(o, z_SortKeySpecList, &(*p)->sortSequence, ODR_CONTEXT,
1643             5, 0) &&
1644         z_OtherInformation(o, &(*p)->otherInfo, 1) &&
1645         odr_sequence_end(o);
1646 }
1647
1648 /* ------------------------ APDU ------------------------- */
1649
1650 int z_APDU(ODR o, Z_APDU **p, int opt)
1651 {
1652     static Odr_arm arm[] =
1653     {
1654         {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_initRequest, z_InitRequest},
1655         {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_initResponse, z_InitResponse},
1656         {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_searchRequest, z_SearchRequest},
1657         {ODR_IMPLICIT, ODR_CONTEXT, 23, Z_APDU_searchResponse,
1658             z_SearchResponse},
1659         {ODR_IMPLICIT, ODR_CONTEXT, 24, Z_APDU_presentRequest,
1660             z_PresentRequest},
1661         {ODR_IMPLICIT, ODR_CONTEXT, 25, Z_APDU_presentResponse,
1662             z_PresentResponse},
1663         {ODR_IMPLICIT, ODR_CONTEXT, 26, Z_APDU_deleteResultSetRequest,
1664             z_DeleteResultSetRequest},
1665         {ODR_IMPLICIT, ODR_CONTEXT, 27, Z_APDU_deleteResultSetResponse,
1666             z_DeleteResultSetResponse},
1667         {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_APDU_accessControlRequest,
1668             z_AccessControlRequest},
1669         {ODR_IMPLICIT, ODR_CONTEXT, 29, Z_APDU_accessControlResponse,
1670             z_AccessControlResponse},
1671         {ODR_IMPLICIT, ODR_CONTEXT, 30, Z_APDU_resourceControlRequest,
1672             z_ResourceControlRequest},
1673         {ODR_IMPLICIT, ODR_CONTEXT, 31, Z_APDU_resourceControlResponse,
1674             z_ResourceControlResponse},
1675         {ODR_IMPLICIT, ODR_CONTEXT, 32, Z_APDU_triggerResourceControlRequest,
1676             z_TriggerResourceControlRequest},
1677         {ODR_IMPLICIT, ODR_CONTEXT, 35, Z_APDU_scanRequest, z_ScanRequest},
1678         {ODR_IMPLICIT, ODR_CONTEXT, 36, Z_APDU_scanResponse, z_ScanResponse},
1679         {ODR_IMPLICIT, ODR_CONTEXT, 43, Z_APDU_sortRequest, z_SortRequest},
1680         {ODR_IMPLICIT, ODR_CONTEXT, 44, Z_APDU_sortResponse, z_SortResponse},
1681         {ODR_IMPLICIT, ODR_CONTEXT, 45, Z_APDU_segmentRequest, z_Segment},
1682         {ODR_IMPLICIT, ODR_CONTEXT, 46, Z_APDU_extendedServicesRequest,
1683             z_ExtendedServicesRequest},
1684         {ODR_IMPLICIT, ODR_CONTEXT, 47, Z_APDU_extendedServicesResponse,
1685             z_ExtendedServicesResponse},
1686         {ODR_IMPLICIT, ODR_CONTEXT, 48, Z_APDU_close, z_Close},
1687
1688         {-1, -1, -1, -1, 0}
1689     };
1690
1691     if (o->direction == ODR_DECODE)
1692         *p = odr_malloc(o, sizeof(**p));
1693     if (!odr_choice(o, arm, &(*p)->u, &(*p)->which))
1694     {
1695         if (o->direction == ODR_DECODE)
1696             *p = 0;
1697         return opt && odr_ok(o);
1698     }
1699     return 1;
1700 }