Renamed logf function to yaz_log. Removed VC++ project files.
[yaz-moved-to-github.git] / asn / prt-grs.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-grs.c,v $
7  * Revision 1.8  1999-04-20 09:56:48  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.7  1998/02/11 11:53:32  adam
12  * Changed code so that it compiles as C++.
13  *
14  * Revision 1.6  1997/05/14 06:53:23  adam
15  * C++ support.
16  *
17  * Revision 1.5  1995/10/18 16:12:20  quinn
18  * Added a couple of special cases to handle the WAIS server.
19  *
20  * Revision 1.4  1995/09/29  17:11:55  quinn
21  * Smallish
22  *
23  * Revision 1.3  1995/09/27  15:02:43  quinn
24  * Modified function heads & prototypes.
25  *
26  * Revision 1.2  1995/08/28  10:58:58  quinn
27  * Added extra choice-entry to data to catch visiblestring.
28  *
29  * Revision 1.1  1995/08/17  12:47:09  quinn
30  * Added GRS-1.
31  *
32  *
33  */
34
35 #include <proto.h>
36
37 int z_TaggedElement(ODR o, Z_TaggedElement **p, int opt, const char *name);
38 int z_ElementData(ODR o, Z_ElementData **p, int opt, const char *name);
39 int z_ElementMetaData(ODR o, Z_ElementMetaData **p, int opt, const char *name);
40 int z_TagUnit(ODR o, Z_TagUnit **p, int opt, const char *name);
41 int z_TagPath(ODR o, Z_TagPath **p, int opt, const char *name);
42 int z_Order(ODR o, Z_Order **p, int opt, const char *name);
43 int z_Usage(ODR o, Z_Usage **p, int opt, const char *name);
44 int z_HitVector(ODR o, Z_HitVector **p, int opt, const char *name);
45 int z_Triple(ODR o, Z_Triple **p, int opt, const char *name);
46 int z_Variant(ODR o, Z_Variant **p, int opt, const char *name);
47
48 int z_GenericRecord(ODR o, Z_GenericRecord **p, int opt, const char *name)
49 {
50     if (o->direction == ODR_DECODE)
51         *p = (Z_GenericRecord *)odr_malloc(o, sizeof(**p));
52     else if (!*p)
53         return opt;
54     if (odr_sequence_of(o, (Odr_fun)z_TaggedElement, &(*p)->elements,
55                         &(*p)->num_elements, 0))
56         return 1;
57     *p = 0;
58     return opt && odr_ok(o);
59 }
60
61 int z_TaggedElement(ODR o, Z_TaggedElement **p, int opt, const char *name)
62 {
63     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
64         return opt && odr_ok(o);
65     return
66         odr_implicit(o, odr_integer, &(*p)->tagType,
67                      ODR_CONTEXT, 1, 1) &&
68         odr_explicit(o, z_StringOrNumeric, &(*p)->tagValue,
69                      ODR_CONTEXT, 2, 0) &&
70         odr_implicit(o, odr_integer, &(*p)->tagOccurrence,
71                      ODR_CONTEXT, 3, 1) &&
72         odr_explicit(o, z_ElementData, &(*p)->content,
73                      ODR_CONTEXT, 4, 0) &&
74         odr_implicit(o, z_ElementMetaData, &(*p)->metaData,
75                      ODR_CONTEXT, 5, 1) &&
76         odr_implicit(o, z_Variant, &(*p)->appliedVariant, ODR_CONTEXT, 6, 1) &&
77         odr_sequence_end(o);
78 }
79
80 int z_ElementData(ODR o, Z_ElementData **p, int opt, const char *name)
81 {
82     static Odr_arm arm[] =
83     {
84         {ODR_NONE, -1, -1, Z_ElementData_octets,
85          (Odr_fun)odr_octetstring, 0},
86         {ODR_NONE, -1, -1, Z_ElementData_numeric,
87          (Odr_fun)odr_integer, 0},
88         {ODR_NONE, -1, -1, Z_ElementData_date,
89          (Odr_fun)odr_generalizedtime, 0},
90         {ODR_NONE, -1, -1, Z_ElementData_ext,
91          (Odr_fun)z_External, 0},
92         {ODR_NONE, -1, -1, Z_ElementData_string,
93          (Odr_fun)z_InternationalString, 0},
94         /* The entry below provides some backwards compatibility */
95         {ODR_NONE, -1, -1, Z_ElementData_string,
96          (Odr_fun)odr_visiblestring, 0},
97         {ODR_NONE, -1, -1, Z_ElementData_trueOrFalse,
98          (Odr_fun)odr_bool, 0},
99         {ODR_NONE, -1, -1, Z_ElementData_oid,
100          (Odr_fun)odr_oid, 0},
101         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementData_intUnit,
102          (Odr_fun)z_IntUnit, 0},
103         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_ElementData_elementNotThere,
104          (Odr_fun)odr_null, 0},
105         {ODR_IMPLICIT, ODR_CONTEXT, 3, Z_ElementData_elementEmpty,
106          (Odr_fun)odr_null, 0},
107         {ODR_IMPLICIT, ODR_CONTEXT, 4, Z_ElementData_noDataRequested,
108          (Odr_fun)odr_null, 0},
109         {ODR_IMPLICIT, ODR_CONTEXT, 5, Z_ElementData_diagnostic,
110          (Odr_fun)z_External, 0},
111         {ODR_EXPLICIT, ODR_CONTEXT, 6, Z_ElementData_subtree,
112          (Odr_fun)z_GenericRecord, 0},
113         {-1, -1, -1, -1, 0, 0}
114     };
115     
116     if (o->direction == ODR_DECODE)
117         *p = (Z_ElementData *)odr_malloc(o, sizeof(**p));
118     else if (!*p)
119         return opt;
120     if (odr_choice(o, arm, &(*p)->u, &(*p)->which, 0))
121         return 1;
122     *p = 0;
123     return opt && odr_ok(o);
124 }
125
126 int z_ElementMetaData(ODR o, Z_ElementMetaData **p, int opt, const char *name)
127 {
128     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
129         return opt && odr_ok(o);
130     return
131         odr_implicit(o, z_Order, &(*p)->seriesOrder, ODR_CONTEXT, 1, 1) &&
132         odr_implicit(o, z_Usage, &(*p)->usageRight, ODR_CONTEXT, 2, 1) &&
133         odr_implicit_settag(o, ODR_CONTEXT, 3) &&
134         (odr_sequence_of(o, (Odr_fun)z_HitVector, &(*p)->hits,
135                          &(*p)->num_hits, 0) ||
136          odr_ok(o)) &&
137         odr_implicit(o, z_InternationalString, &(*p)->displayName,
138                      ODR_CONTEXT, 4, 1) &&
139         odr_implicit_settag(o, ODR_CONTEXT, 5) &&
140         (odr_sequence_of(o, (Odr_fun)z_Variant, &(*p)->supportedVariants,
141                          &(*p)->num_supportedVariants, 0) || odr_ok(o)) &&
142         odr_implicit(o, z_InternationalString, &(*p)->message,
143                      ODR_CONTEXT, 6, 1) &&
144         odr_implicit(o, odr_octetstring, &(*p)->elementDescriptor,
145                      ODR_CONTEXT, 7, 1) &&
146         odr_implicit(o, z_TagPath, &(*p)->surrogateFor, ODR_CONTEXT, 8, 1) &&
147         odr_implicit(o, z_TagPath, &(*p)->surrogateElement,
148                      ODR_CONTEXT, 9, 1) &&
149         odr_implicit(o, z_External, &(*p)->other, ODR_CONTEXT, 99, 1) &&
150         odr_sequence_end(o);
151 }
152
153 int z_TagUnit(ODR o, Z_TagUnit **p, int opt, const char *name)
154 {
155     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
156         return opt && odr_ok(o);
157     return
158         odr_implicit(o, odr_integer, &(*p)->tagType, ODR_CONTEXT, 1, 1) &&
159         odr_explicit(o, z_StringOrNumeric, &(*p)->tagValue,
160                      ODR_CONTEXT, 2, 0) &&
161         odr_implicit(o, odr_integer, &(*p)->tagOccurrence,
162                      ODR_CONTEXT, 3, 1) &&
163         odr_sequence_end(o);
164 }
165
166 int z_TagPath(ODR o, Z_TagPath **p, int opt, const char *name)
167 {
168     if (o->direction == ODR_DECODE)
169         *p = (Z_TagPath *)odr_malloc(o, sizeof(**p));
170     else if (!*p)
171         return opt;
172     if (odr_sequence_of(o, (Odr_fun)z_TagUnit, &(*p)->tags,
173                         &(*p)->num_tags, 0))
174         return 1;
175     *p = 0;
176     return opt && odr_ok(o);
177 }
178
179 int z_Order(ODR o, Z_Order **p, int opt, const char *name)
180 {
181     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
182         return opt && odr_ok(o);
183     return
184         odr_implicit(o, odr_bool, &(*p)->ascending, ODR_CONTEXT, 1, 0) &&
185         odr_implicit(o, odr_integer, &(*p)->order, ODR_CONTEXT, 2, 0) &&
186         odr_sequence_end(o);
187 }
188
189 int z_Usage(ODR o, Z_Usage **p, int opt, const char *name)
190 {
191     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
192         return opt && odr_ok(o);
193     return
194         odr_implicit(o, odr_integer, &(*p)->type, ODR_CONTEXT, 1, 0) &&
195         odr_implicit(o, z_InternationalString, &(*p)->restriction, ODR_CONTEXT,
196                      2, 1) &&
197         odr_sequence_end(o);
198 }
199
200 int z_HitVector(ODR o, Z_HitVector **p, int opt, const char *name)
201 {
202     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
203         return opt && odr_ok(o);
204     return
205         z_Term(o, &(*p)->satisfier, 1, 0) &&
206         odr_implicit(o, z_IntUnit, &(*p)->offsetIntoElement,
207                      ODR_CONTEXT, 1, 1) &&
208         odr_implicit(o, z_IntUnit, &(*p)->length, ODR_CONTEXT, 2, 1) &&
209         odr_implicit(o, odr_integer, &(*p)->hitRank, ODR_CONTEXT, 3, 1) &&
210         odr_implicit(o, odr_octetstring, &(*p)->targetToken, ODR_CONTEXT,
211                      4, 1) &&
212         odr_sequence_end(o);
213 }
214
215 int z_Triple(ODR o, Z_Triple **p, int opt, const char *name)
216 {
217     static Odr_arm arm[] =
218     {
219         {ODR_NONE, -1, -1, Z_Triple_integer,
220          (Odr_fun)odr_integer, 0},
221         {ODR_NONE, -1, -1, Z_Triple_internationalString,
222          (Odr_fun)z_InternationalString, 0},
223         /* The entry below provides some backwards compatibility */
224         {ODR_NONE, -1, -1, Z_Triple_internationalString,
225          (Odr_fun)odr_visiblestring, 0},
226         {ODR_NONE, -1, -1, Z_Triple_octetString,
227          (Odr_fun)odr_octetstring, 0},
228         {ODR_NONE, -1, -1, Z_Triple_oid,
229          (Odr_fun)odr_oid, 0},
230         {ODR_NONE, -1, -1, Z_Triple_boolean,
231          (Odr_fun)odr_bool, 0},
232         {ODR_NONE, -1, -1, Z_Triple_null,
233          (Odr_fun)odr_null, 0},
234         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Triple_unit,
235          (Odr_fun)z_Unit, 0},
236         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Triple_valueAndUnit,
237          (Odr_fun)z_IntUnit, 0},
238         {-1, -1, -1, -1, 0, 0}
239     };
240     
241     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
242         return opt && odr_ok(o);
243     return
244         odr_implicit(o, odr_oid, &(*p)->variantSetId, ODR_CONTEXT, 0, 1) &&
245         odr_implicit(o, odr_integer, &(*p)->zclass, ODR_CONTEXT, 1, 0) &&
246         odr_implicit(o, odr_integer, &(*p)->type, ODR_CONTEXT, 2, 0) &&
247         odr_constructed_begin(o, &(*p)->value, ODR_CONTEXT, 3, 0) &&
248         odr_choice(o, arm, &(*p)->value, &(*p)->which, 0) &&
249         odr_constructed_end(o) &&
250         odr_sequence_end(o);
251 }
252
253 int z_Variant(ODR o, Z_Variant **p, int opt, const char *name)
254 {
255     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
256         return opt && odr_ok(o);
257     return
258         odr_implicit(o, odr_oid, &(*p)->globalVariantSetId,
259                      ODR_CONTEXT, 1, 1) &&
260         odr_implicit_settag(o, ODR_CONTEXT, 2) &&
261         odr_sequence_of(o, (Odr_fun)z_Triple, &(*p)->triples,
262                         &(*p)->num_triples, 0) &&
263         odr_sequence_end(o);
264 }