1 /* $Id: attribute.c,v 1.27 2006-09-20 10:51:25 adam Exp $
2 Copyright (C) 1995-2006
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <yaz/diagbib1.h>
27 #include <idzebra/res.h>
28 #include <idzebra/util.h>
32 static data1_att *getatt(data1_attset *p, int att)
35 data1_attset_child *c;
38 for (a = p->atts; a; a = a->next)
41 /* scan included sets */
42 for (c = p->children; c; c = c->next)
43 if ((a = getatt(c->child, att)))
48 static int att_getentbyatt(ZebraHandle zi, oid_value set, int att,
54 if (!(p = data1_attset_search_id (zi->reg->dh, set)))
56 zebraExplain_loadAttsets (zi->reg->dh, zi->res);
57 p = data1_attset_search_id (zi->reg->dh, set);
59 if (!p) /* set undefined */
61 if (!(r = getatt(p, att)))
68 ZEBRA_RES zebra_attr_list_get_ord(ZebraHandle zh,
69 Z_AttributeList *attr_list,
70 zinfo_index_category_t cat,
72 oid_value curAttributeSet,
76 const char *use_string = 0;
79 attr_init_AttrList(&use, attr_list, 1);
80 use_value = attr_find_ex(&use, &curAttributeSet, &use_string);
89 /* we have a use attribute and attribute set */
92 r = att_getentbyatt(zh, curAttributeSet, use_value, &use_string);
95 zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_ATTRIBUTE_SET, 0);
100 zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, use_value);
106 zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, 0);
109 *ord = zebraExplain_lookup_attr_str(zh->reg->zei, cat,
110 index_type, use_string);
114 zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, use_string);
116 zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, use_value);
122 ZEBRA_RES zebra_apt_get_ord(ZebraHandle zh,
123 Z_AttributesPlusTerm *zapt,
125 const char *xpath_use,
126 oid_value curAttributeSet,
129 ZEBRA_RES res = ZEBRA_OK;
132 zinfo_index_category_t cat = zinfo_index_category_index;
134 attr_init_APT(&relation, zapt, 2);
135 relation_value = attr_find(&relation, NULL);
137 if (relation_value == 103) /* always matches */
138 cat = zinfo_index_category_alwaysmatches;
142 res = zebra_attr_list_get_ord(zh, zapt->attributes,
144 curAttributeSet, ord);
145 /* use attribute not found. But it the relation is
146 always matches and the regulare index attribute is found
147 return a different diagnostic */
148 if (res != ZEBRA_OK &&
149 relation_value == 103
150 && zebra_attr_list_get_ord(
151 zh, zapt->attributes,
152 zinfo_index_category_index, index_type,
153 curAttributeSet, ord) == ZEBRA_OK)
154 zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_RELATION_ATTRIBUTE, 103);
158 *ord = zebraExplain_lookup_attr_str(zh->reg->zei, cat, index_type,
162 yaz_log(YLOG_LOG, "zebra_apt_get_ord FAILED xpath=%s index_type=%c",
163 xpath_use, index_type);
164 zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, 0);
169 yaz_log(YLOG_LOG, "zebra_apt_get_ord OK xpath=%s index_type=%c",
170 xpath_use, index_type);
177 ZEBRA_RES zebra_sort_get_ord(ZebraHandle zh,
178 Z_SortAttributes *sortAttributes,
184 attr_init_AttrList(&structure, sortAttributes->list, 4);
187 structure_value = attr_find(&structure, 0);
188 if (structure_value == 109)
191 if (zebra_attr_list_get_ord(zh, sortAttributes->list,
192 zinfo_index_category_sort,
193 -1 /* any index */, VAL_BIB1, ord)== ZEBRA_OK)
202 * indent-tabs-mode: nil
204 * vim: shiftwidth=4 tabstop=8 expandtab