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