cfeb007726a1701feffcfb6974e677c6786c0e05
[idzebra-moved-to-github.git] / index / attribute.c
1 /* $Id: attribute.c,v 1.21 2006-02-22 08:42:16 adam Exp $
2    Copyright (C) 1995-2005
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
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
10 version.
11
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
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23 #include <stdio.h>
24
25 #include <yaz/log.h>
26 #include <idzebra/res.h>
27 #include <idzebra/util.h>
28 #include "index.h"
29
30 static data1_att *getatt(data1_attset *p, int att, const char *sattr)
31 {
32     data1_att *a;
33     data1_attset_child *c;
34
35     /* scan local set */
36     for (a = p->atts; a; a = a->next)
37         if (sattr && !yaz_matchstr(sattr, a->name))
38             return a;
39         else if (a->value == att)
40             return a;
41     /* scan included sets */
42     for (c = p->children; c; c = c->next)
43         if ((a = getatt(c->child, att, sattr)))
44             return a;
45     return 0;
46 }
47
48 int att_getentbyatt(ZebraHandle zi, attent *res, oid_value set, int att,
49                 const char *sattr)
50 {
51     data1_att *r;
52     data1_attset *p;
53
54     if (!(p = data1_attset_search_id (zi->reg->dh, set)))
55     {
56         zebraExplain_loadAttsets (zi->reg->dh, zi->res);
57         p = data1_attset_search_id (zi->reg->dh, set);
58     }
59     if (!p)   /* set undefined */
60     {
61         if (sattr)     
62             return -1; /* return bad string attribute */
63         else
64             return -2; /* return bad set */
65     }
66     if (!(r = getatt(p, att, sattr)))
67         return -1;
68     res->attset_ordinal = r->parent->reference;
69     res->local_attributes = r->locals;
70     return 0;
71 }