1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
7 * \brief Implements handling of various Z39.50 Externals
13 #include <yaz/proto.h>
15 #include <yaz/oid_db.h>
17 #define PRT_EXT_DEBUG 0
24 * The table below should be moved to the ODR structure itself and
25 * be an image of the association context: To help
26 * map indirect references when they show up.
28 static Z_ext_typeent type_table[] =
30 {{1, 2, 840, 10003, 5, 101,-1}, Z_External_sutrs, (Odr_fun) z_SUTRS},
31 {{1, 2, 840, 10003, 5, 100,-1}, Z_External_explainRecord, (Odr_fun)z_ExplainRecord},
32 {{1, 2, 840, 10003, 7, 1,-1}, Z_External_resourceReport1, (Odr_fun)z_ResourceReport1},
33 {{1, 2, 840, 10003, 7, 2,-1}, Z_External_resourceReport2, (Odr_fun)z_ResourceReport2},
34 {{1, 2, 840, 10003, 8, 1,-1}, Z_External_promptObject1, (Odr_fun)z_PromptObject1 },
35 {{1, 2, 840, 10003, 5, 105,-1}, Z_External_grs1, (Odr_fun)z_GenericRecord},
36 {{1, 2, 840, 10003, 5, 106,-1}, Z_External_extendedService, (Odr_fun)z_TaskPackage},
37 {{1, 2, 840, 10003, 9, 4,-1}, Z_External_itemOrder, (Odr_fun)z_IOItemOrder},
38 {{1, 2, 840, 10003, 4, 2,-1}, Z_External_diag1, (Odr_fun)z_DiagnosticFormat},
39 {{1, 2, 840, 10003, 11, 1,-1}, Z_External_espec1, (Odr_fun)z_Espec1},
40 {{1, 2, 840, 10003, 5, 103,-1}, Z_External_summary, (Odr_fun)z_BriefBib},
41 {{1, 2, 840, 10003, 5, 102,-1}, Z_External_OPAC, (Odr_fun)z_OPACRecord},
42 {{1, 2, 840, 10003, 10, 1,-1}, Z_External_searchResult1, (Odr_fun)z_SearchInfoReport},
43 {{1, 2, 840, 10003, 9, 5,-1}, Z_External_update0, (Odr_fun)z_IU0Update},
44 {{1, 2, 840, 10003, 9, 5, 1,-1}, Z_External_update0, (Odr_fun)z_IU0Update},
45 {{1, 2, 840, 10003, 9, 5, 1, 1,-1}, Z_External_update, (Odr_fun)z_IUUpdate},
46 {{1, 2, 840, 10003, 10, 6,-1}, Z_External_dateTime, (Odr_fun)z_DateTime},
47 {{1, 2, 840, 10003, 7, 1000, 81, 1,-1}, Z_External_universeReport,(Odr_fun)z_UniverseReport},
48 {{1, 2, 840, 10003, 9, 1000, 81, 1,-1}, Z_External_ESAdmin, (Odr_fun)z_Admin},
49 {{1, 2, 840, 10003, 10, 3,-1}, Z_External_userInfo1, (Odr_fun) z_OtherInformation},
50 {{1, 2, 840, 10003, 10, 1000, 81, 5,-1}, Z_External_userFacets, (Odr_fun) z_FacetList},
51 {{1, 2, 840, 10003, 15, 3,-1}, Z_External_charSetandLanguageNegotiation, (Odr_fun)
52 z_CharSetandLanguageNegotiation},
53 {{1, 2, 840, 10003, 8, 1,-1}, Z_External_acfPrompt1, (Odr_fun) z_PromptObject1},
54 {{1, 2, 840, 10003, 8, 2,-1}, Z_External_acfDes1, (Odr_fun) z_DES_RN_Object},
55 {{1, 2, 840, 10003, 8, 3,-1}, Z_External_acfKrb1, (Odr_fun) z_KRBObject},
56 {{1, 2, 840, 10003, 10, 5,-1}, Z_External_multisrch2, (Odr_fun) z_MultipleSearchTerms_2},
57 {{1, 2, 840, 10003, 16, 2, -1}, Z_External_CQL, (Odr_fun) z_InternationalString},
58 {{1, 2, 840, 10003, 9, 1,-1}, Z_External_persistentResultSet, (Odr_fun)z_PRPersistentResultSet},
59 {{1, 2, 840, 10003, 9, 2,-1}, Z_External_persistentQuery, (Odr_fun)z_PQueryPersistentQuery},
60 {{1, 2, 840, 10003, 9, 3,-1}, Z_External_periodicQuerySchedule, (Odr_fun)z_PQSPeriodicQuerySchedule},
61 {{1, 2, 840, 10003, 9, 6,-1}, Z_External_exportSpecification, (Odr_fun)z_ESExportSpecification},
62 {{1, 2, 840, 10003, 9, 7,-1}, Z_External_exportInvocation, (Odr_fun)z_EIExportInvocation},
66 Z_ext_typeent *z_ext_getentbyref(const Odr_oid *oid)
70 for (p = type_table; p->oid[0] != -1; p++)
71 if (!oid_oidcmp(oid, p->oid))
77 This routine is the BER codec for the EXTERNAL type.
78 It handles information in single-ASN1-type and octet-aligned
82 [UNIVERSAL 8] IMPLICIT SEQUENCE {
83 direct-reference OBJECT IDENTIFIER OPTIONAL,
84 indirect-reference INTEGER OPTIONAL,
85 data-value-descriptor ObjectDescriptor OPTIONAL,
87 single-ASN1-type [0] ABSTRACT_SYNTAX.&Type,
88 octet-aligned [1] IMPLICIT OCTET STRING,
89 arbitrary [2] IMPLICIT BIT STRING
93 arbitrary BIT STRING not handled yet.
95 int z_External(ODR o, Z_External **p, int opt, const char *name)
99 static Odr_arm arm[] =
101 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_single,
102 (Odr_fun)odr_any, 0},
103 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_External_octet,
104 (Odr_fun)odr_octetstring, 0},
105 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_External_arbitrary,
106 (Odr_fun)odr_bitstring, 0},
107 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_sutrs,
108 (Odr_fun)z_SUTRS, 0},
109 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_explainRecord,
110 (Odr_fun)z_ExplainRecord, 0},
112 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_resourceReport1,
113 (Odr_fun)z_ResourceReport1, 0},
114 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_resourceReport2,
115 (Odr_fun)z_ResourceReport2, 0},
116 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_promptObject1,
117 (Odr_fun)z_PromptObject1, 0},
118 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_grs1,
119 (Odr_fun)z_GenericRecord, 0},
120 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_extendedService,
121 (Odr_fun)z_TaskPackage, 0},
123 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_itemOrder,
124 (Odr_fun)z_IOItemOrder, 0},
125 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_diag1,
126 (Odr_fun)z_DiagnosticFormat, 0},
127 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_espec1,
128 (Odr_fun)z_Espec1, 0},
129 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_summary,
130 (Odr_fun)z_BriefBib, 0},
131 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_OPAC,
132 (Odr_fun)z_OPACRecord, 0},
134 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_searchResult1,
135 (Odr_fun)z_SearchInfoReport, 0},
136 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_update,
137 (Odr_fun)z_IUUpdate, 0},
138 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_dateTime,
139 (Odr_fun)z_DateTime, 0},
140 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_universeReport,
141 (Odr_fun)z_UniverseReport, 0},
142 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_ESAdmin,
143 (Odr_fun)z_Admin, 0},
145 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_update0,
146 (Odr_fun)z_IU0Update, 0},
147 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_userInfo1,
148 (Odr_fun)z_OtherInformation, 0},
149 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_userFacets,
150 (Odr_fun)z_FacetList, "FacetList" },
151 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_charSetandLanguageNegotiation,
152 (Odr_fun)z_CharSetandLanguageNegotiation, 0},
153 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_acfPrompt1,
154 (Odr_fun)z_PromptObject1, 0},
155 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_acfDes1,
156 (Odr_fun)z_DES_RN_Object, 0},
158 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_acfKrb1,
159 (Odr_fun)z_KRBObject, 0},
160 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_multisrch2,
161 (Odr_fun)z_MultipleSearchTerms_2, 0},
162 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_CQL,
163 (Odr_fun)z_InternationalString, 0},
164 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_OCLCUserInfo,
165 (Odr_fun)z_OCLC_UserInformation, 0},
166 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_persistentResultSet,
167 (Odr_fun)z_PRPersistentResultSet, 0},
169 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_persistentQuery,
170 (Odr_fun)z_PQueryPersistentQuery, 0},
171 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_periodicQuerySchedule,
172 (Odr_fun)z_PQSPeriodicQuerySchedule, 0},
173 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_exportSpecification,
174 (Odr_fun)z_ESExportSpecification, 0},
175 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_exportInvocation,
176 (Odr_fun)z_EIExportInvocation, 0},
177 {-1, -1, -1, -1, 0, 0}
180 odr_implicit_settag(o, ODR_UNIVERSAL, ODR_EXTERNAL);
181 if (!odr_sequence_begin(o, p, sizeof(**p), name))
182 return opt && odr_ok(o);
183 if (!(odr_oid(o, &(*p)->direct_reference, 1, 0) &&
184 odr_integer(o, &(*p)->indirect_reference, 1, 0) &&
185 odr_graphicstring(o, &(*p)->descriptor, 1, 0)))
188 /* debugging purposes only */
189 if (o->direction == ODR_DECODE)
191 yaz_log(YLOG_LOG, "z_external decode");
192 if ((*p)->direct_reference)
194 yaz_log(YLOG_LOG, "direct reference");
195 if ((oid = oid_getentbyoid((*p)->direct_reference)))
197 yaz_log(YLOG_LOG, "oid %s", oid->desc);
198 if ((type = z_ext_getentbyref(oid->value)))
199 yaz_log(YLOG_LOG, "type");
204 /* Do we know this beast? */
205 if (o->direction == ODR_DECODE && (*p)->direct_reference &&
206 (type = z_ext_getentbyref((*p)->direct_reference)))
208 int zclass, tag, cons;
209 /* OID is present and we know it */
211 if (!odr_peektag(o, &zclass, &tag, &cons))
212 return opt && odr_ok(o);
214 yaz_log(YLOG_LOG, "odr_peektag OK tag=%d cons=%d zclass=%d what=%d",
215 tag, cons, zclass, type->what);
217 if (zclass == ODR_CONTEXT && tag == 1 && cons == 0)
219 /* we have an OCTET STRING. decode BER contents from it */
226 if (!odr_implicit_tag(o, odr_octetstring, &oct,
227 ODR_CONTEXT, 1, 0, "octetaligned"))
230 /* Save our decoding ODR members */
233 o_size = o->op->size;
235 /* Set up the OCTET STRING buffer */
236 o->op->bp = o->op->buf = oct->buf;
237 o->op->size = oct->len;
239 /* and decode that */
240 r = (*type->fun)(o, &voidp, 0, 0);
241 (*p)->which = type->what;
242 (*p)->u.single_ASN1_type = (Odr_any*) voidp;
244 /* Restore our decoding ODR member */
247 o->op->size = o_size;
249 return r && odr_sequence_end(o);
251 if (zclass == ODR_CONTEXT && tag == 0 && cons == 1)
253 /* It's single ASN.1 type, bias the CHOICE. */
254 odr_choice_bias(o, type->what);
258 odr_choice(o, arm, &(*p)->u, &(*p)->which, name) &&
262 Z_External *z_ext_record_oid_nmem(NMEM nmem, const Odr_oid *oid,
263 const char *buf, int len)
269 thisext = (Z_External *) nmem_malloc(nmem, sizeof(*thisext));
270 thisext->descriptor = 0;
271 thisext->indirect_reference = 0;
272 thisext->direct_reference = odr_oiddup_nmem(nmem, oid);
274 if (len < 0) /* Structured data */
277 * We cheat on the pointers here. Obviously, the record field
278 * of the backend-fetch structure should have been a union for
279 * correctness, but we're stuck with this for backwards
282 thisext->u.grs1 = (Z_GenericRecord*) buf;
284 if (!oid_oidcmp(oid, yaz_oid_recsyn_sutrs))
286 thisext->which = Z_External_sutrs;
288 else if (!oid_oidcmp(oid, yaz_oid_recsyn_grs_1))
290 thisext->which = Z_External_grs1;
292 else if (!oid_oidcmp(oid, yaz_oid_recsyn_explain))
294 thisext->which = Z_External_explainRecord;
296 else if (!oid_oidcmp(oid, yaz_oid_recsyn_summary))
298 thisext->which = Z_External_summary;
300 else if (!oid_oidcmp(oid, yaz_oid_recsyn_opac))
302 thisext->which = Z_External_OPAC;
304 else if (!oid_oidcmp(oid, yaz_oid_recsyn_extended))
306 thisext->which = Z_External_extendedService;
313 else if (!oid_oidcmp(oid, yaz_oid_recsyn_sutrs))
314 { /* SUTRS is a single-ASN.1-type */
315 Odr_oct *sutrs = (Odr_oct *)nmem_malloc(nmem, sizeof(*sutrs));
317 thisext->which = Z_External_sutrs;
318 thisext->u.sutrs = sutrs;
319 sutrs->buf = (char *)nmem_malloc(nmem, len);
321 memcpy(sutrs->buf, buf, len);
325 thisext->which = Z_External_octet;
326 if (!(thisext->u.octet_aligned = (Odr_oct *)
327 nmem_malloc(nmem, sizeof(Odr_oct))))
329 if (!(thisext->u.octet_aligned->buf = (char *)
330 nmem_malloc(nmem, len)))
332 memcpy(thisext->u.octet_aligned->buf, buf, len);
333 thisext->u.octet_aligned->len = len;
338 Z_External *z_ext_record_oid(ODR o, const Odr_oid *oid,
339 const char *buf, int len)
341 return z_ext_record_oid_nmem(o->mem, oid, buf, len);
344 Z_External *z_ext_record_oid_any(ODR o, const Odr_oid *oid,
345 const char *buf, int len)
351 thisext = (Z_External *) odr_malloc(o, sizeof(*thisext));
352 thisext->descriptor = 0;
353 thisext->indirect_reference = 0;
354 thisext->direct_reference = odr_oiddup(o, oid);
356 thisext->which = Z_External_single;
357 thisext->u.single_ASN1_type = (Odr_any *) odr_malloc(o, sizeof(Odr_any));
358 if (!thisext->u.single_ASN1_type)
360 thisext->u.single_ASN1_type->buf = (char *) odr_malloc(o, len);
361 if (!thisext->u.single_ASN1_type->buf)
363 memcpy(thisext->u.single_ASN1_type->buf, buf, len);
364 thisext->u.single_ASN1_type->len = len;
368 Z_External *z_ext_record_xml(ODR o, const char *buf, int len)
370 return z_ext_record_oid(o, yaz_oid_recsyn_xml, buf, len);
373 Z_External *z_ext_record_sutrs(ODR o, const char *buf, int len)
375 return z_ext_record_oid(o, yaz_oid_recsyn_sutrs, buf, len);
378 Z_External *z_ext_record_usmarc(ODR o, const char *buf, int len)
380 return z_ext_record_oid(o, yaz_oid_recsyn_usmarc, buf, len);
386 * c-file-style: "Stroustrup"
387 * indent-tabs-mode: nil
389 * vim: shiftwidth=4 tabstop=8 expandtab