2 * Copyright (c) 1995-1999, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.9 1999-11-30 13:47:11 adam
8 * Improved installation. Moved header files to include/yaz.
10 * Revision 1.8 1999/04/20 09:56:48 adam
11 * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun).
12 * Modified all encoders/decoders to reflect this change.
14 * Revision 1.7 1998/02/11 11:53:32 adam
15 * Changed code so that it compiles as C++.
17 * Revision 1.6 1997/05/14 06:53:23 adam
20 * Revision 1.5 1995/10/18 16:12:20 quinn
21 * Added a couple of special cases to handle the WAIS server.
23 * Revision 1.4 1995/09/29 17:11:55 quinn
26 * Revision 1.3 1995/09/27 15:02:43 quinn
27 * Modified function heads & prototypes.
29 * Revision 1.2 1995/08/28 10:58:58 quinn
30 * Added extra choice-entry to data to catch visiblestring.
32 * Revision 1.1 1995/08/17 12:47:09 quinn
38 #include <yaz/proto.h>
40 int z_TaggedElement(ODR o, Z_TaggedElement **p, int opt, const char *name);
41 int z_ElementData(ODR o, Z_ElementData **p, int opt, const char *name);
42 int z_ElementMetaData(ODR o, Z_ElementMetaData **p, int opt, const char *name);
43 int z_TagUnit(ODR o, Z_TagUnit **p, int opt, const char *name);
44 int z_TagPath(ODR o, Z_TagPath **p, int opt, const char *name);
45 int z_Order(ODR o, Z_Order **p, int opt, const char *name);
46 int z_Usage(ODR o, Z_Usage **p, int opt, const char *name);
47 int z_HitVector(ODR o, Z_HitVector **p, int opt, const char *name);
48 int z_Triple(ODR o, Z_Triple **p, int opt, const char *name);
49 int z_Variant(ODR o, Z_Variant **p, int opt, const char *name);
51 int z_GenericRecord(ODR o, Z_GenericRecord **p, int opt, const char *name)
53 if (o->direction == ODR_DECODE)
54 *p = (Z_GenericRecord *)odr_malloc(o, sizeof(**p));
57 if (odr_sequence_of(o, (Odr_fun)z_TaggedElement, &(*p)->elements,
58 &(*p)->num_elements, 0))
61 return opt && odr_ok(o);
64 int z_TaggedElement(ODR o, Z_TaggedElement **p, int opt, const char *name)
66 if (!odr_sequence_begin(o, p, sizeof(**p), 0))
67 return opt && odr_ok(o);
69 odr_implicit(o, odr_integer, &(*p)->tagType,
71 odr_explicit(o, z_StringOrNumeric, &(*p)->tagValue,
73 odr_implicit(o, odr_integer, &(*p)->tagOccurrence,
75 odr_explicit(o, z_ElementData, &(*p)->content,
77 odr_implicit(o, z_ElementMetaData, &(*p)->metaData,
79 odr_implicit(o, z_Variant, &(*p)->appliedVariant, ODR_CONTEXT, 6, 1) &&
83 int z_ElementData(ODR o, Z_ElementData **p, int opt, const char *name)
85 static Odr_arm arm[] =
87 {ODR_NONE, -1, -1, Z_ElementData_octets,
88 (Odr_fun)odr_octetstring, 0},
89 {ODR_NONE, -1, -1, Z_ElementData_numeric,
90 (Odr_fun)odr_integer, 0},
91 {ODR_NONE, -1, -1, Z_ElementData_date,
92 (Odr_fun)odr_generalizedtime, 0},
93 {ODR_NONE, -1, -1, Z_ElementData_ext,
94 (Odr_fun)z_External, 0},
95 {ODR_NONE, -1, -1, Z_ElementData_string,
96 (Odr_fun)z_InternationalString, 0},
97 /* The entry below provides some backwards compatibility */
98 {ODR_NONE, -1, -1, Z_ElementData_string,
99 (Odr_fun)odr_visiblestring, 0},
100 {ODR_NONE, -1, -1, Z_ElementData_trueOrFalse,
101 (Odr_fun)odr_bool, 0},
102 {ODR_NONE, -1, -1, Z_ElementData_oid,
103 (Odr_fun)odr_oid, 0},
104 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ElementData_intUnit,
105 (Odr_fun)z_IntUnit, 0},
106 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_ElementData_elementNotThere,
107 (Odr_fun)odr_null, 0},
108 {ODR_IMPLICIT, ODR_CONTEXT, 3, Z_ElementData_elementEmpty,
109 (Odr_fun)odr_null, 0},
110 {ODR_IMPLICIT, ODR_CONTEXT, 4, Z_ElementData_noDataRequested,
111 (Odr_fun)odr_null, 0},
112 {ODR_IMPLICIT, ODR_CONTEXT, 5, Z_ElementData_diagnostic,
113 (Odr_fun)z_External, 0},
114 {ODR_EXPLICIT, ODR_CONTEXT, 6, Z_ElementData_subtree,
115 (Odr_fun)z_GenericRecord, 0},
116 {-1, -1, -1, -1, 0, 0}
119 if (o->direction == ODR_DECODE)
120 *p = (Z_ElementData *)odr_malloc(o, sizeof(**p));
123 if (odr_choice(o, arm, &(*p)->u, &(*p)->which, 0))
126 return opt && odr_ok(o);
129 int z_ElementMetaData(ODR o, Z_ElementMetaData **p, int opt, const char *name)
131 if (!odr_sequence_begin(o, p, sizeof(**p), 0))
132 return opt && odr_ok(o);
134 odr_implicit(o, z_Order, &(*p)->seriesOrder, ODR_CONTEXT, 1, 1) &&
135 odr_implicit(o, z_Usage, &(*p)->usageRight, ODR_CONTEXT, 2, 1) &&
136 odr_implicit_settag(o, ODR_CONTEXT, 3) &&
137 (odr_sequence_of(o, (Odr_fun)z_HitVector, &(*p)->hits,
138 &(*p)->num_hits, 0) ||
140 odr_implicit(o, z_InternationalString, &(*p)->displayName,
141 ODR_CONTEXT, 4, 1) &&
142 odr_implicit_settag(o, ODR_CONTEXT, 5) &&
143 (odr_sequence_of(o, (Odr_fun)z_Variant, &(*p)->supportedVariants,
144 &(*p)->num_supportedVariants, 0) || odr_ok(o)) &&
145 odr_implicit(o, z_InternationalString, &(*p)->message,
146 ODR_CONTEXT, 6, 1) &&
147 odr_implicit(o, odr_octetstring, &(*p)->elementDescriptor,
148 ODR_CONTEXT, 7, 1) &&
149 odr_implicit(o, z_TagPath, &(*p)->surrogateFor, ODR_CONTEXT, 8, 1) &&
150 odr_implicit(o, z_TagPath, &(*p)->surrogateElement,
151 ODR_CONTEXT, 9, 1) &&
152 odr_implicit(o, z_External, &(*p)->other, ODR_CONTEXT, 99, 1) &&
156 int z_TagUnit(ODR o, Z_TagUnit **p, int opt, const char *name)
158 if (!odr_sequence_begin(o, p, sizeof(**p), 0))
159 return opt && odr_ok(o);
161 odr_implicit(o, odr_integer, &(*p)->tagType, ODR_CONTEXT, 1, 1) &&
162 odr_explicit(o, z_StringOrNumeric, &(*p)->tagValue,
163 ODR_CONTEXT, 2, 0) &&
164 odr_implicit(o, odr_integer, &(*p)->tagOccurrence,
165 ODR_CONTEXT, 3, 1) &&
169 int z_TagPath(ODR o, Z_TagPath **p, int opt, const char *name)
171 if (o->direction == ODR_DECODE)
172 *p = (Z_TagPath *)odr_malloc(o, sizeof(**p));
175 if (odr_sequence_of(o, (Odr_fun)z_TagUnit, &(*p)->tags,
179 return opt && odr_ok(o);
182 int z_Order(ODR o, Z_Order **p, int opt, const char *name)
184 if (!odr_sequence_begin(o, p, sizeof(**p), 0))
185 return opt && odr_ok(o);
187 odr_implicit(o, odr_bool, &(*p)->ascending, ODR_CONTEXT, 1, 0) &&
188 odr_implicit(o, odr_integer, &(*p)->order, ODR_CONTEXT, 2, 0) &&
192 int z_Usage(ODR o, Z_Usage **p, int opt, const char *name)
194 if (!odr_sequence_begin(o, p, sizeof(**p), 0))
195 return opt && odr_ok(o);
197 odr_implicit(o, odr_integer, &(*p)->type, ODR_CONTEXT, 1, 0) &&
198 odr_implicit(o, z_InternationalString, &(*p)->restriction, ODR_CONTEXT,
203 int z_HitVector(ODR o, Z_HitVector **p, int opt, const char *name)
205 if (!odr_sequence_begin(o, p, sizeof(**p), 0))
206 return opt && odr_ok(o);
208 z_Term(o, &(*p)->satisfier, 1, 0) &&
209 odr_implicit(o, z_IntUnit, &(*p)->offsetIntoElement,
210 ODR_CONTEXT, 1, 1) &&
211 odr_implicit(o, z_IntUnit, &(*p)->length, ODR_CONTEXT, 2, 1) &&
212 odr_implicit(o, odr_integer, &(*p)->hitRank, ODR_CONTEXT, 3, 1) &&
213 odr_implicit(o, odr_octetstring, &(*p)->targetToken, ODR_CONTEXT,
218 int z_Triple(ODR o, Z_Triple **p, int opt, const char *name)
220 static Odr_arm arm[] =
222 {ODR_NONE, -1, -1, Z_Triple_integer,
223 (Odr_fun)odr_integer, 0},
224 {ODR_NONE, -1, -1, Z_Triple_internationalString,
225 (Odr_fun)z_InternationalString, 0},
226 /* The entry below provides some backwards compatibility */
227 {ODR_NONE, -1, -1, Z_Triple_internationalString,
228 (Odr_fun)odr_visiblestring, 0},
229 {ODR_NONE, -1, -1, Z_Triple_octetString,
230 (Odr_fun)odr_octetstring, 0},
231 {ODR_NONE, -1, -1, Z_Triple_oid,
232 (Odr_fun)odr_oid, 0},
233 {ODR_NONE, -1, -1, Z_Triple_boolean,
234 (Odr_fun)odr_bool, 0},
235 {ODR_NONE, -1, -1, Z_Triple_null,
236 (Odr_fun)odr_null, 0},
237 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Triple_unit,
239 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Triple_valueAndUnit,
240 (Odr_fun)z_IntUnit, 0},
241 {-1, -1, -1, -1, 0, 0}
244 if (!odr_sequence_begin(o, p, sizeof(**p), 0))
245 return opt && odr_ok(o);
247 odr_implicit(o, odr_oid, &(*p)->variantSetId, ODR_CONTEXT, 0, 1) &&
248 odr_implicit(o, odr_integer, &(*p)->zclass, ODR_CONTEXT, 1, 0) &&
249 odr_implicit(o, odr_integer, &(*p)->type, ODR_CONTEXT, 2, 0) &&
250 odr_constructed_begin(o, &(*p)->value, ODR_CONTEXT, 3, 0) &&
251 odr_choice(o, arm, &(*p)->value, &(*p)->which, 0) &&
252 odr_constructed_end(o) &&
256 int z_Variant(ODR o, Z_Variant **p, int opt, const char *name)
258 if (!odr_sequence_begin(o, p, sizeof(**p), 0))
259 return opt && odr_ok(o);
261 odr_implicit(o, odr_oid, &(*p)->globalVariantSetId,
262 ODR_CONTEXT, 1, 1) &&
263 odr_implicit_settag(o, ODR_CONTEXT, 2) &&
264 odr_sequence_of(o, (Odr_fun)z_Triple, &(*p)->triples,
265 &(*p)->num_triples, 0) &&