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