source: trunk/gsdl/packages/yaz/zutil/prt-ext.c@ 1343

Last change on this file since 1343 was 1343, checked in by johnmcp, 24 years ago

Added the YAZ toolkit source to the packages directory (for z39.50 stuff)

  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 KB
Line 
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:12:38 johnmcp
8 * Added the YAZ toolkit source to the packages directory (for z39.50 stuff)
9 *
10 * Revision 1.2 1999/11/30 13:47:12 adam
11 * Improved installation. Moved header files to include/yaz.
12 *
13 * Revision 1.1 1999/06/08 10:10:16 adam
14 * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
15 *
16 * Revision 1.22 1999/05/26 15:24:26 adam
17 * Fixed minor bugs regarding DB Update (introduced by previous commit).
18 *
19 * Revision 1.21 1999/05/26 14:47:12 adam
20 * Implemented z_ext_record.
21 *
22 * Revision 1.20 1999/04/20 09:56:48 adam
23 * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun).
24 * Modified all encoders/decoders to reflect this change.
25 *
26 * Revision 1.19 1998/03/31 15:13:19 adam
27 * Development towards compiled ASN.1.
28 *
29 * Revision 1.18 1998/03/31 11:07:44 adam
30 * Furhter work on UNIverse resource report.
31 * Added Extended Services handling in frontend server.
32 *
33 * Revision 1.17 1998/03/20 14:46:06 adam
34 * Added UNIverse Resource Reports.
35 *
36 * Revision 1.16 1998/02/11 11:53:32 adam
37 * Changed code so that it compiles as C++.
38 *
39 * Revision 1.15 1998/02/10 15:31:46 adam
40 * Implemented date and time structure. Changed the Update Extended
41 * Service.
42 *
43 * Revision 1.14 1998/01/05 09:04:57 adam
44 * Fixed bugs in encoders/decoders - Not operator (!) missing.
45 *
46 * Revision 1.13 1997/05/14 06:53:22 adam
47 * C++ support.
48 *
49 * Revision 1.12 1997/04/30 08:52:02 quinn
50 * Null
51 *
52 * Revision 1.11 1996/10/10 12:35:13 quinn
53 * Added Update extended service.
54 *
55 * Revision 1.10 1996/10/09 15:54:55 quinn
56 * Added SearchInfoReport
57 *
58 * Revision 1.9 1996/06/10 08:53:36 quinn
59 * Added Summary,OPAC,ResourceReport
60 *
61 * Revision 1.8 1996/02/20 12:51:44 quinn
62 * Completed SCAN. Fixed problems with EXTERNAL.
63 *
64 * Revision 1.7 1995/10/12 10:34:38 quinn
65 * Added Espec-1.
66 *
67 * Revision 1.6 1995/09/29 17:11:55 quinn
68 * Smallish
69 *
70 * Revision 1.5 1995/09/27 15:02:42 quinn
71 * Modified function heads & prototypes.
72 *
73 * Revision 1.4 1995/08/29 11:17:16 quinn
74 * *** empty log message ***
75 *
76 * Revision 1.3 1995/08/21 09:10:18 quinn
77 * Smallish fixes to suppport new formats.
78 *
79 * Revision 1.2 1995/08/17 12:45:00 quinn
80 * Fixed minor problems with GRS-1. Added support in c&s.
81 *
82 * Revision 1.1 1995/08/15 13:37:41 quinn
83 * Improved EXTERNAL
84 *
85 *
86 */
87
88#include <yaz/proto.h>
89
90/*
91 * The table below should be moved to the ODR structure itself and
92 * be an image of the association context: To help
93 * map indirect references when they show up.
94 */
95static Z_ext_typeent type_table[] =
96{
97 {VAL_SUTRS, Z_External_sutrs, (Odr_fun) z_SUTRS},
98 {VAL_EXPLAIN, Z_External_explainRecord, (Odr_fun)z_ExplainRecord},
99 {VAL_RESOURCE1, Z_External_resourceReport1, (Odr_fun)z_ResourceReport1},
100 {VAL_RESOURCE2, Z_External_resourceReport2, (Odr_fun)z_ResourceReport2},
101 {VAL_PROMPT1, Z_External_promptObject1, (Odr_fun)z_PromptObject1 },
102 {VAL_GRS1, Z_External_grs1, (Odr_fun)z_GenericRecord},
103 {VAL_EXTENDED, Z_External_extendedService, (Odr_fun)z_TaskPackage},
104#ifdef ASN_COMPILED
105 {VAL_ITEMORDER, Z_External_itemOrder, (Odr_fun)z_IOItemOrder},
106#else
107 {VAL_ITEMORDER, Z_External_itemOrder, (Odr_fun)z_ItemOrder},
108#endif
109 {VAL_DIAG1, Z_External_diag1, (Odr_fun)z_DiagnosticFormat},
110 {VAL_ESPEC1, Z_External_espec1, (Odr_fun)z_Espec1},
111 {VAL_SUMMARY, Z_External_summary, (Odr_fun)z_BriefBib},
112 {VAL_OPAC, Z_External_OPAC, (Odr_fun)z_OPACRecord},
113 {VAL_SEARCHRES1, Z_External_searchResult1, (Odr_fun)z_SearchInfoReport},
114 {VAL_DBUPDATE, Z_External_update, (Odr_fun)z_IUUpdate},
115 {VAL_DATETIME, Z_External_dateTime, (Odr_fun)z_DateTime},
116 {VAL_UNIVERSE_REPORT, Z_External_universeReport, (Odr_fun)z_UniverseReport},
117 {VAL_NONE, 0, 0}
118};
119
120Z_ext_typeent *z_ext_getentbyref(oid_value val)
121{
122 Z_ext_typeent *i;
123
124 for (i = type_table; i->dref != VAL_NONE; i++)
125 if (i->dref == val)
126 return i;
127 return 0;
128}
129
130int z_External(ODR o, Z_External **p, int opt, const char *name)
131{
132 oident *oid;
133 Z_ext_typeent *type;
134
135 static Odr_arm arm[] =
136 {
137 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_single,
138 (Odr_fun)odr_any, 0},
139 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_External_octet,
140 (Odr_fun)odr_octetstring, 0},
141 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_External_arbitrary,
142 (Odr_fun)odr_bitstring, 0},
143 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_sutrs,
144 (Odr_fun)z_SUTRS, 0},
145 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_explainRecord,
146 (Odr_fun)z_ExplainRecord, 0},
147 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_resourceReport1,
148 (Odr_fun)z_ResourceReport1, 0},
149 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_resourceReport2,
150 (Odr_fun)z_ResourceReport2, 0},
151 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_promptObject1,
152 (Odr_fun)z_PromptObject1, 0},
153 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_grs1,
154 (Odr_fun)z_GenericRecord, 0},
155 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_extendedService,
156 (Odr_fun)z_TaskPackage, 0},
157#ifdef ASN_COMPILED
158 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_itemOrder,
159 (Odr_fun)z_IOItemOrder, 0},
160#else
161 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_itemOrder,
162 (Odr_fun)z_ItemOrder, 0},
163#endif
164 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_diag1,
165 (Odr_fun)z_DiagnosticFormat, 0},
166 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_espec1,
167 (Odr_fun)z_Espec1, 0},
168 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_summary,
169 (Odr_fun)z_BriefBib, 0},
170 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_OPAC,
171 (Odr_fun)z_OPACRecord, 0},
172 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_searchResult1,
173 (Odr_fun)z_SearchInfoReport, 0},
174 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_update,
175 (Odr_fun)z_IUUpdate, 0},
176 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_dateTime,
177 (Odr_fun)z_DateTime, 0},
178 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_universeReport,
179 (Odr_fun)z_UniverseReport, 0},
180 {-1, -1, -1, -1, 0, 0}
181 };
182
183 odr_implicit_settag(o, ODR_UNIVERSAL, ODR_EXTERNAL);
184 if (!odr_sequence_begin(o, p, sizeof(**p), name))
185 return opt && odr_ok(o);
186 if (!(odr_oid(o, &(*p)->direct_reference, 1, 0) &&
187 odr_integer(o, &(*p)->indirect_reference, 1, 0) &&
188 odr_graphicstring(o, &(*p)->descriptor, 1, 0)))
189 return 0;
190 /*
191 * Do we know this beast?
192 */
193 if (o->direction == ODR_DECODE && (*p)->direct_reference &&
194 (oid = oid_getentbyoid((*p)->direct_reference)) &&
195 (type = z_ext_getentbyref(oid->value)))
196 {
197 int zclass, tag, cons;
198
199 /*
200 * We know it. If it's represented as an ASN.1 type, bias the CHOICE.
201 */
202 if (!odr_peektag(o, &zclass, &tag, &cons))
203 return opt && odr_ok(o);
204 if (zclass == ODR_CONTEXT && tag == 0 && cons == 1)
205 odr_choice_bias(o, type->what);
206 }
207 return
208 odr_choice(o, arm, &(*p)->u, &(*p)->which, name) &&
209 odr_sequence_end(o);
210}
211
212Z_External *z_ext_record(ODR o, int format, const char *buf, int len)
213{
214 Z_External *thisext;
215 oident recform;
216 int oid[OID_SIZE];
217
218 thisext = (Z_External *) odr_malloc(o, sizeof(*thisext));
219 thisext->descriptor = 0;
220 thisext->indirect_reference = 0;
221
222 recform.proto = PROTO_Z3950;
223 recform.oclass = CLASS_RECSYN;
224 recform.value = (enum oid_value) format;
225 if (!oid_ent_to_oid(&recform, oid))
226 return 0;
227 thisext->direct_reference = odr_oiddup(o, oid);
228
229 if (len < 0) /* Structured data */
230 {
231 switch (format)
232 {
233 case VAL_SUTRS:
234 thisext->which = Z_External_sutrs;
235 break;
236 case VAL_GRS1:
237 thisext->which = Z_External_grs1;
238 break;
239 case VAL_EXPLAIN:
240 thisext->which = Z_External_explainRecord;
241 break;
242 case VAL_SUMMARY:
243 thisext->which = Z_External_summary;
244 break;
245 case VAL_OPAC:
246 thisext->which = Z_External_OPAC;
247 break;
248 default:
249 return 0;
250 }
251
252 /*
253 * We cheat on the pointers here. Obviously, the record field
254 * of the backend-fetch structure should have been a union for
255 * correctness, but we're stuck with this for backwards
256 * compatibility.
257 */
258 thisext->u.grs1 = (Z_GenericRecord*) buf;
259 }
260 else if (format == VAL_SUTRS) /* SUTRS is a single-ASN.1-type */
261 {
262 Odr_oct *sutrs = (Odr_oct *)odr_malloc(o, sizeof(*sutrs));
263
264 thisext->which = Z_External_sutrs;
265 thisext->u.sutrs = sutrs;
266 sutrs->buf = (unsigned char *)odr_malloc(o, len);
267 sutrs->len = sutrs->size = len;
268 memcpy(sutrs->buf, buf, len);
269 }
270 else
271 {
272 thisext->which = Z_External_octet;
273 if (!(thisext->u.octet_aligned = (Odr_oct *)
274 odr_malloc(o, sizeof(Odr_oct))))
275 return 0;
276 if (!(thisext->u.octet_aligned->buf = (unsigned char *)
277 odr_malloc(o, len)))
278 return 0;
279 memcpy(thisext->u.octet_aligned->buf, buf, len);
280 thisext->u.octet_aligned->len = thisext->u.octet_aligned->size = len;
281 }
282 return thisext;
283}
284
Note: See TracBrowser for help on using the repository browser.