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