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