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