1 /* $Id: attribute.c,v 1.30 2007-04-16 21:54:37 adam Exp $
2 Copyright (C) 1995-2007
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>
31 #include <yaz/oid_db.h>
33 static data1_att *getatt(data1_attset *p, int att)
36 data1_attset_child *c;
39 for (a = p->atts; a; a = a->next)
42 /* scan included sets */
43 for (c = p->children; c; c = c->next)
44 if ((a = getatt(c->child, att)))
49 static int att_getentbyatt(ZebraHandle zi, const int *set, int att,
55 if (!(p = data1_attset_search_id (zi->reg->dh, set)))
57 zebraExplain_loadAttsets (zi->reg->dh, zi->res);
58 p = data1_attset_search_id (zi->reg->dh, set);
60 if (!p) /* set undefined */
62 if (!(r = getatt(p, att)))
69 ZEBRA_RES zebra_attr_list_get_ord(ZebraHandle zh,
70 Z_AttributeList *attr_list,
71 zinfo_index_category_t cat,
73 const int *curAttributeSet,
77 const char *use_string = 0;
80 attr_init_AttrList(&use, attr_list, 1);
81 use_value = attr_find_ex(&use, &curAttributeSet, &use_string);
90 /* we have a use attribute and attribute set */
93 r = att_getentbyatt(zh, curAttributeSet, use_value, &use_string);
96 zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_ATTRIBUTE_SET, 0);
101 zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, use_value);
107 zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, 0);
110 *ord = zebraExplain_lookup_attr_str(zh->reg->zei, cat,
111 index_type, use_string);
115 zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, use_string);
117 zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, use_value);
123 ZEBRA_RES zebra_apt_get_ord(ZebraHandle zh,
124 Z_AttributesPlusTerm *zapt,
126 const char *xpath_use,
127 const int *curAttributeSet,
130 ZEBRA_RES res = ZEBRA_OK;
133 zinfo_index_category_t cat = zinfo_index_category_index;
135 attr_init_APT(&relation, zapt, 2);
136 relation_value = attr_find(&relation, NULL);
138 if (relation_value == 103) /* always matches */
139 cat = zinfo_index_category_alwaysmatches;
143 res = zebra_attr_list_get_ord(zh, zapt->attributes,
145 curAttributeSet, ord);
146 /* use attribute not found. But it the relation is
147 always matches and the regulare index attribute is found
148 return a different diagnostic */
149 if (res != ZEBRA_OK &&
150 relation_value == 103
151 && zebra_attr_list_get_ord(
152 zh, zapt->attributes,
153 zinfo_index_category_index, index_type,
154 curAttributeSet, ord) == ZEBRA_OK)
155 zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_RELATION_ATTRIBUTE, 103);
159 *ord = zebraExplain_lookup_attr_str(zh->reg->zei, cat, index_type,
163 yaz_log(YLOG_LOG, "zebra_apt_get_ord FAILED xpath=%s index_type=%c",
164 xpath_use, index_type);
165 zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, 0);
170 yaz_log(YLOG_LOG, "zebra_apt_get_ord OK xpath=%s index_type=%c",
171 xpath_use, index_type);
178 ZEBRA_RES zebra_sort_get_ord(ZebraHandle zh,
179 Z_SortAttributes *sortAttributes,
186 attr_init_AttrList(&structure, sortAttributes->list, 4);
189 structure_value = attr_find(&structure, 0);
190 if (structure_value == 109)
193 if (zebra_attr_list_get_ord(
194 zh, sortAttributes->list,
195 zinfo_index_category_sort,
196 -1 /* any index */, yaz_oid_attset_bib_1, ord) == ZEBRA_OK)
205 * indent-tabs-mode: nil
207 * vim: shiftwidth=4 tabstop=8 expandtab