Fixed problem with proto.h.
[yaz-moved-to-github.git] / asn / prt-esp.c
1 /*
2  * Copyright (c) 1995-1999, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: prt-esp.c,v $
7  * Revision 1.4  1999-04-20 09:56:47  adam
8  * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun).
9  * Modified all encoders/decoders to reflect this change.
10  *
11  * Revision 1.3  1998/02/11 11:53:32  adam
12  * Changed code so that it compiles as C++.
13  *
14  * Revision 1.2  1998/02/10 15:31:46  adam
15  * Implemented date and time structure. Changed the Update Extended
16  * Service.
17  *
18  * Revision 1.1  1995/10/12 10:34:37  quinn
19  * Added Espec-1.
20  *
21  *
22  */
23
24 #include <proto.h>
25
26 int z_OccurValues(ODR o, Z_OccurValues **p, int opt, const char *name)
27 {
28     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
29         return opt && odr_ok(o);
30     return
31         odr_implicit(o, odr_integer, &(*p)->start, ODR_CONTEXT, 1, 0) &&
32         odr_implicit(o, odr_integer, &(*p)->howMany, ODR_CONTEXT, 2, 1) &&
33         odr_sequence_end(o);
34 }
35
36 int z_Occurrences(ODR o, Z_Occurrences **p, int opt, const char *name)
37 {
38     static Odr_arm arm[] =
39     {
40         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Occurrences_all,
41          (Odr_fun)odr_null, 0},
42         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Occurrences_last,
43          (Odr_fun)odr_null, 0},
44         {ODR_IMPLICIT, ODR_CONTEXT, 3, Z_Occurrences_values,
45          (Odr_fun)z_OccurValues, 0},
46         {-1, -1, -1, -1, 0, 0}
47     };
48     
49     if (o->direction == ODR_DECODE)
50         *p = (Z_Occurrences *)odr_malloc(o, sizeof(**p));
51     else if (!*p)
52         return opt;
53     if (odr_choice(o, arm, &(*p)->u, &(*p)->which, 0))
54         return 1;
55     *p = 0;
56     return opt && odr_ok(o);
57 }
58
59 int z_SpecificTag(ODR o, Z_SpecificTag **p, int opt, const char *name)
60 {
61     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
62         return opt && odr_ok(o);
63     return
64         odr_implicit(o, odr_oid, &(*p)->schemaId, ODR_CONTEXT, 0, 1) &&
65         odr_implicit(o, odr_integer, &(*p)->tagType, ODR_CONTEXT, 1, 1) &&
66         odr_explicit(o, z_StringOrNumeric, &(*p)->tagValue, ODR_CONTEXT,
67                      2, 0) &&
68         odr_explicit(o, z_Occurrences, &(*p)->occurrences,
69                      ODR_CONTEXT, 3, 1) &&
70         odr_sequence_end(o);
71 }
72
73 int z_ETagUnit(ODR o, Z_ETagUnit **p, int opt, const char *name)
74 {
75     static Odr_arm arm[] =
76     {
77         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ETagUnit_specificTag,
78          (Odr_fun)z_SpecificTag, 0},
79         {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_ETagUnit_wildThing,
80          (Odr_fun)z_Occurrences, 0},
81         {ODR_IMPLICIT, ODR_CONTEXT, 3, Z_ETagUnit_wildPath,
82          (Odr_fun)odr_null, 0},
83         {-1, -1, -1 -1, 0, 0}
84     };
85     
86     if (o->direction == ODR_DECODE)
87         *p = (Z_ETagUnit *)odr_malloc(o, sizeof(**p));
88     else if (!*p)
89         return opt;
90     if (odr_choice(o, arm, &(*p)->u, &(*p)->which, 0))
91         return 1;
92     *p = 0;
93     return opt && odr_ok(o);
94 }
95
96 int z_ETagPath(ODR o, Z_ETagPath **p, int opt, const char *name)
97 {
98     if (o->direction == ODR_DECODE)
99         *p = (Z_ETagPath *)odr_malloc(o, sizeof(**p));
100     else if (!*p)
101         return opt;
102     if (odr_sequence_of(o, (Odr_fun)z_ETagUnit, &(*p)->tags,
103                         &(*p)->num_tags, 0))
104         return 1;
105     *p = 0;
106     return opt && odr_ok(o);
107 }
108
109 int z_SimpleElement(ODR o, Z_SimpleElement **p, int opt, const char *name)
110 {
111     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
112         return opt && odr_ok(o);
113     return
114         odr_implicit(o, z_ETagPath, &(*p)->path, ODR_CONTEXT, 1, 0) &&
115         odr_implicit(o, z_Variant, &(*p)->variantRequest,
116                      ODR_CONTEXT, 2, 1) &&
117         odr_sequence_end(o);
118 }
119
120 int z_CompoPrimitives(ODR o, Z_CompoPrimitives **p, int opt, const char *name)
121 {
122     if (o->direction == ODR_DECODE)
123         *p = (Z_CompoPrimitives *)odr_malloc(o, sizeof(**p));
124     else if (!*p)
125         return opt;
126     if (odr_sequence_of(o, z_InternationalString, &(*p)->primitives,
127                         &(*p)->num_primitives, 0))
128         return 1;
129     *p = 0;
130     return opt && odr_ok(o);
131 }
132
133 int z_CompoSpecs(ODR o, Z_CompoSpecs **p, int opt, const char *name)
134 {
135     if (o->direction == ODR_DECODE)
136         *p = (Z_CompoSpecs *)odr_malloc(o, sizeof(**p));
137     else if (!*p)
138         return opt;
139     if (odr_sequence_of(o, (Odr_fun)z_SimpleElement, &(*p)->specs,
140                         &(*p)->num_specs, 0))
141         return 1;
142     *p = 0;
143     return opt && odr_ok(o);
144 }
145
146 int z_CompositeElement(ODR o, Z_CompositeElement **p, int opt,
147                        const char *name)
148 {
149     static Odr_arm arm[] =
150     {
151         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_CompoElement_primitives,
152          (Odr_fun)z_CompoPrimitives, 0},
153         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_CompoElement_specs,
154          (Odr_fun)z_CompoSpecs, 0},
155         {-1, -1, -1, -1, 0, 0}
156     };
157     
158     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
159         return opt && odr_ok(o);
160     return
161         odr_constructed_begin(o, &(*p)->elementList, ODR_CONTEXT, 1, 0) &&
162         odr_choice(o, arm, &(*p)->elementList, &(*p)->which, 0) &&
163         odr_constructed_end(o) &&
164         odr_implicit(o, z_ETagPath, &(*p)->deliveryTag, ODR_CONTEXT, 2, 0) &&
165         odr_implicit(o, z_Variant, &(*p)->variantRequest, ODR_CONTEXT, 3, 1) &&
166         odr_sequence_end(o);
167 }
168
169 int z_ElementRequest(ODR o, Z_ElementRequest **p, int opt, const char *name)
170 {
171     static Odr_arm arm[] =
172     {
173         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ERequest_simpleElement,
174          (Odr_fun)z_SimpleElement, 0},
175         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_ERequest_compositeElement,
176          (Odr_fun)z_CompositeElement, 0},
177         {-1, -1, -1 -1, 0, 0}
178     };
179     
180     if (o->direction == ODR_DECODE)
181         *p = (Z_ElementRequest *)odr_malloc(o, sizeof(**p));
182     else if (!*p)
183         return opt;
184     if (odr_choice(o, arm, &(*p)->u, &(*p)->which, 0))
185         return 1;
186     *p = 0;
187     return opt && odr_ok(o);
188 }
189
190 int z_Espec1(ODR o, Z_Espec1 **p, int opt, const char *name)
191 {
192     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
193         return opt && odr_ok(o);
194     return
195         odr_implicit_settag(o, ODR_CONTEXT, 1) &&
196         (odr_sequence_of(o, z_InternationalString, &(*p)->elementSetNames,
197                          &(*p)->num_elementSetNames, 0) || odr_ok(o)) &&
198         odr_implicit(o, odr_oid, &(*p)->defaultVariantSetId,
199                      ODR_CONTEXT, 2, 1) &&
200         odr_implicit(o, z_Variant, &(*p)->defaultVariantRequest,
201                      ODR_CONTEXT, 3, 1) &&
202         odr_implicit(o, odr_integer, &(*p)->defaultTagType,
203                      ODR_CONTEXT, 4, 1) &&
204         odr_implicit_settag(o, ODR_CONTEXT, 5) &&
205         (odr_sequence_of(o, (Odr_fun)z_ElementRequest, &(*p)->elements,
206                          &(*p)->num_elements, 0) || odr_ok(o)) &&
207         odr_sequence_end(o);
208 }