2 * Copyright (c) 1995-2002, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Id: d1_doespec.c,v 1.1 2002-10-22 12:53:33 adam Exp $
13 #include <yaz/proto.h>
16 static int match_children(data1_handle dh, data1_node *n,
17 Z_Espec1 *e, int i, Z_ETagUnit **t,
20 static int match_children_wildpath(data1_handle dh, data1_node *n,
22 Z_ETagUnit **t, int num)
28 * Locate a specific triple within a variant.
29 * set is the set to look for, universal set is the set that applies to a
30 * triple with an unknown set.
32 static Z_Triple *find_triple(Z_Variant *var, oid_value universalset,
33 oid_value set, int zclass, int type)
36 oident *defaultsetent = oid_getentbyoid(var->globalVariantSetId);
37 oid_value defaultset = defaultsetent ? defaultsetent->value :
40 for (i = 0; i < var->num_triples; i++)
43 oid_getentbyoid(var->triples[i]->variantSetId);
44 oid_value curset = cursetent ? cursetent->value : defaultset;
47 *var->triples[i]->zclass == zclass &&
48 *var->triples[i]->type == type)
49 return var->triples[i];
54 static void mark_subtree(data1_node *n, int make_variantlist, int no_data,
55 int get_bytes, Z_Variant *vreq)
60 if (n->which == DATA1N_tag)
62 if (n->which == DATA1N_tag && (!n->child || n->child->which != DATA1N_tag))
64 * This seems to cause multi-level elements to fall out when only a
65 * top-level elementRequest has been given... Problem is, I can't figure
66 * out what it was supposed to ACHIEVE.... delete when code has been
71 n->u.tag.node_selected = 1;
72 n->u.tag.make_variantlist = make_variantlist;
73 n->u.tag.no_data_requested = no_data;
74 n->u.tag.get_bytes = get_bytes;
77 for (c = n->child; c; c = c->next)
79 if (c->which == DATA1N_tag && (!n->child ||
80 n->child->which != DATA1N_tag))
82 c->u.tag.node_selected = 1;
83 c->u.tag.make_variantlist = make_variantlist;
84 c->u.tag.no_data_requested = no_data;
85 c->u.tag.get_bytes = get_bytes;
87 mark_subtree(c, make_variantlist, no_data, get_bytes, vreq);
92 static void match_triple (data1_handle dh, Z_Variant *vreq,
94 oid_value var1, data1_node *n)
100 if (n->which != DATA1N_variant)
108 assert ((*c)->which == DATA1N_variant);
110 if ((*c)->u.variant.type->zclass->zclass == 4 &&
111 (*c)->u.variant.type->type == 1)
113 if ((r = find_triple(vreq, defsetval, var1, 4, 1)) &&
114 (r->which == Z_Triple_internationalString))
116 const char *string_value =
117 r->value.internationalString;
118 if (strcmp ((*c)->u.variant.value, string_value))
124 data1_free_tree (dh, *c);
129 match_triple (dh, vreq, defsetval, var1, *c);
135 static int match_children_here (data1_handle dh, data1_node *n,
137 Z_ETagUnit **t, int num)
139 int counter = 0, hits = 0;
142 Z_Occurrences *occur;
144 for (c = n->child; c ; c = c->next)
148 if (c->which != DATA1N_tag)
151 if (tp->which == Z_ETagUnit_specificTag)
153 Z_SpecificTag *want = tp->u.specificTag;
154 occur = want->occurrences;
155 if (c->u.tag.element)
156 tag = c->u.tag.element->tag;
157 if (*want->tagType != ((tag && tag->tagset) ? tag->tagset->type :
160 if (want->tagValue->which == Z_StringOrNumeric_numeric)
162 if (!tag || tag->which != DATA1T_numeric)
164 if (*want->tagValue->u.numeric != tag->value.numeric)
169 assert(want->tagValue->which == Z_StringOrNumeric_string);
170 if (tag && tag->which != DATA1T_string)
172 if (data1_matchstr(want->tagValue->u.string,
173 tag ? tag->value.string : c->u.tag.tag))
178 occur = tp->u.wildThing;
181 * Ok, so we have a matching tag. Are we within occurrences-range?
184 if (occur && occur->which == Z_Occurrences_last)
186 yaz_log(LOG_WARN, "Can't do occurrences=last (yet)");
189 if (!occur || occur->which == Z_Occurrences_all ||
190 (occur->which == Z_Occurrences_values && counter >=
191 *occur->u.values->start))
193 if (match_children(dh, c, e, i, t + 1, num - 1))
195 c->u.tag.node_selected = 1;
197 * Consider the variant specification if this is a complete
202 int show_variantlist = 0;
207 e->elements[i]->u.simpleElement->variantRequest;
208 oident *defset = oid_getentbyoid(e->defaultVariantSetId);
209 oid_value defsetval = defset ? defset->value : VAL_NONE;
210 oid_value var1 = oid_getvalbyname("Variant-1");
213 vreq = e->defaultVariantRequest;
220 * 6,5: meta-data requested, variant list.
222 if (find_triple(vreq, defsetval, var1, 6, 5))
223 show_variantlist = 1;
225 * 9,1: Miscellaneous, no data requested.
227 if (find_triple(vreq, defsetval, var1, 9, 1))
231 if ((r = find_triple(vreq, defsetval, var1, 5, 5)))
232 if (r->which == Z_Triple_integer)
233 get_bytes = *r->value.integer;
235 if (!show_variantlist)
236 match_triple (dh, vreq, defsetval, var1, c);
238 mark_subtree(c, show_variantlist, no_data, get_bytes, vreq);
242 * have we looked at enough children?
244 if (!occur || (occur->which == Z_Occurrences_values &&
245 (!occur->u.values->howMany ||
246 counter - *occur->u.values->start >=
247 *occur->u.values->howMany - 1)))
255 static int match_children(data1_handle dh, data1_node *n, Z_Espec1 *e,
256 int i, Z_ETagUnit **t, int num)
264 case Z_ETagUnit_wildThing:
265 case Z_ETagUnit_specificTag:
266 res = match_children_here(dh, n, e, i, t, num); break;
267 case Z_ETagUnit_wildPath:
268 res = match_children_wildpath(dh, n, e, i, t, num); break;
275 int data1_doespec1 (data1_handle dh, data1_node *n, Z_Espec1 *e)
279 n = data1_get_root_tag (dh, n);
280 if (n && n->which == DATA1N_tag)
281 n->u.tag.node_selected = 1;
283 for (i = 0; i < e->num_elements; i++)
285 if (e->elements[i]->which != Z_ERequest_simpleElement)
287 match_children(dh, n, e, i,
288 e->elements[i]->u.simpleElement->path->tags,
289 e->elements[i]->u.simpleElement->path->num_tags);