2 * Copyright (c) 1995-2001, Index Data.
3 * See the file LICENSE for details.
5 * $Id: prt-ext.c,v 1.2 2001-11-13 23:00:43 adam Exp $
11 * The table below should be moved to the ODR structure itself and
12 * be an image of the association context: To help
13 * map indirect references when they show up.
15 static Z_ext_typeent type_table[] =
17 {VAL_SUTRS, Z_External_sutrs, (Odr_fun) z_SUTRS},
18 {VAL_EXPLAIN, Z_External_explainRecord, (Odr_fun)z_ExplainRecord},
19 {VAL_RESOURCE1, Z_External_resourceReport1, (Odr_fun)z_ResourceReport1},
20 {VAL_RESOURCE2, Z_External_resourceReport2, (Odr_fun)z_ResourceReport2},
21 {VAL_PROMPT1, Z_External_promptObject1, (Odr_fun)z_PromptObject1 },
22 {VAL_GRS1, Z_External_grs1, (Odr_fun)z_GenericRecord},
23 {VAL_EXTENDED, Z_External_extendedService, (Odr_fun)z_TaskPackage},
24 {VAL_ITEMORDER, Z_External_itemOrder, (Odr_fun)z_IOItemOrder},
25 {VAL_DIAG1, Z_External_diag1, (Odr_fun)z_DiagnosticFormat},
26 {VAL_ESPEC1, Z_External_espec1, (Odr_fun)z_Espec1},
27 {VAL_SUMMARY, Z_External_summary, (Odr_fun)z_BriefBib},
28 {VAL_OPAC, Z_External_OPAC, (Odr_fun)z_OPACRecord},
29 {VAL_SEARCHRES1, Z_External_searchResult1, (Odr_fun)z_SearchInfoReport},
30 {VAL_DBUPDATE, Z_External_update, (Odr_fun)z_IUUpdate},
31 {VAL_DATETIME, Z_External_dateTime, (Odr_fun)z_DateTime},
32 {VAL_UNIVERSE_REPORT, Z_External_universeReport,(Odr_fun)z_UniverseReport},
33 {VAL_ADMINSERVICE, Z_External_ESAdmin, (Odr_fun)z_Admin},
37 Z_ext_typeent *z_ext_getentbyref(oid_value val)
41 for (i = type_table; i->dref != VAL_NONE; i++)
47 int z_External(ODR o, Z_External **p, int opt, const char *name)
52 static Odr_arm arm[] =
54 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_single,
56 {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_External_octet,
57 (Odr_fun)odr_octetstring, 0},
58 {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_External_arbitrary,
59 (Odr_fun)odr_bitstring, 0},
60 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_sutrs,
62 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_explainRecord,
63 (Odr_fun)z_ExplainRecord, 0},
64 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_resourceReport1,
65 (Odr_fun)z_ResourceReport1, 0},
66 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_resourceReport2,
67 (Odr_fun)z_ResourceReport2, 0},
68 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_promptObject1,
69 (Odr_fun)z_PromptObject1, 0},
70 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_grs1,
71 (Odr_fun)z_GenericRecord, 0},
72 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_extendedService,
73 (Odr_fun)z_TaskPackage, 0},
74 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_itemOrder,
75 (Odr_fun)z_IOItemOrder, 0},
76 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_diag1,
77 (Odr_fun)z_DiagnosticFormat, 0},
78 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_espec1,
79 (Odr_fun)z_Espec1, 0},
80 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_summary,
81 (Odr_fun)z_BriefBib, 0},
82 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_OPAC,
83 (Odr_fun)z_OPACRecord, 0},
84 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_searchResult1,
85 (Odr_fun)z_SearchInfoReport, 0},
86 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_update,
87 (Odr_fun)z_IUUpdate, 0},
88 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_dateTime,
89 (Odr_fun)z_DateTime, 0},
90 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_universeReport,
91 (Odr_fun)z_UniverseReport, 0},
92 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_ESAdmin,
94 {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_update0,
95 (Odr_fun)z_IU0Update, 0},
96 {-1, -1, -1, -1, 0, 0}
99 odr_implicit_settag(o, ODR_UNIVERSAL, ODR_EXTERNAL);
100 if (!odr_sequence_begin(o, p, sizeof(**p), name))
101 return opt && odr_ok(o);
102 if (!(odr_oid(o, &(*p)->direct_reference, 1, 0) &&
103 odr_integer(o, &(*p)->indirect_reference, 1, 0) &&
104 odr_graphicstring(o, &(*p)->descriptor, 1, 0)))
107 * Do we know this beast?
109 if (o->direction == ODR_DECODE && (*p)->direct_reference &&
110 (oid = oid_getentbyoid((*p)->direct_reference)) &&
111 (type = z_ext_getentbyref(oid->value)))
113 int zclass, tag, cons;
116 * We know it. If it's represented as an ASN.1 type, bias the CHOICE.
118 if (!odr_peektag(o, &zclass, &tag, &cons))
119 return opt && odr_ok(o);
120 if (zclass == ODR_CONTEXT && tag == 0 && cons == 1)
121 odr_choice_bias(o, type->what);
124 odr_choice(o, arm, &(*p)->u, &(*p)->which, name) &&
128 Z_External *z_ext_record(ODR o, int format, const char *buf, int len)
132 thisext = (Z_External *) odr_malloc(o, sizeof(*thisext));
133 thisext->descriptor = 0;
134 thisext->indirect_reference = 0;
136 thisext->direct_reference =
137 yaz_oidval_to_z3950oid (o, CLASS_RECSYN, format);
138 if (!thisext->direct_reference)
141 if (len < 0) /* Structured data */
145 * We cheat on the pointers here. Obviously, the record field
146 * of the backend-fetch structure should have been a union for
147 * correctness, but we're stuck with this for backwards
150 thisext->u.grs1 = (Z_GenericRecord*) buf;
155 thisext->which = Z_External_sutrs;
158 thisext->which = Z_External_grs1;
161 thisext->which = Z_External_explainRecord;
164 thisext->which = Z_External_summary;
167 thisext->which = Z_External_OPAC;
170 thisext->which = Z_External_extendedService;
176 else if (format == VAL_SUTRS) /* SUTRS is a single-ASN.1-type */
178 Odr_oct *sutrs = (Odr_oct *)odr_malloc(o, sizeof(*sutrs));
180 thisext->which = Z_External_sutrs;
181 thisext->u.sutrs = sutrs;
182 sutrs->buf = (unsigned char *)odr_malloc(o, len);
183 sutrs->len = sutrs->size = len;
184 memcpy(sutrs->buf, buf, len);
188 thisext->which = Z_External_octet;
189 if (!(thisext->u.octet_aligned = (Odr_oct *)
190 odr_malloc(o, sizeof(Odr_oct))))
192 if (!(thisext->u.octet_aligned->buf = (unsigned char *)
195 memcpy(thisext->u.octet_aligned->buf, buf, len);
196 thisext->u.octet_aligned->len = thisext->u.octet_aligned->size = len;