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