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