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