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