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