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