fb15f2067f80f87a1dcf6024e9a3b0ab449de1ab
[idzebra-moved-to-github.git] / index / attribute.c
1 /*
2  * Copyright (C) 1994-1997, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: attribute.c,v $
7  * Revision 1.7  1997-10-29 12:05:01  adam
8  * Server produces diagnostic "Unsupported Attribute Set" when appropriate.
9  *
10  * Revision 1.6  1997/09/17 12:19:11  adam
11  * Zebra version corresponds to YAZ version 1.4.
12  * Changed Zebra server so that it doesn't depend on global common_resource.
13  *
14  * Revision 1.5  1997/09/05 15:30:08  adam
15  * Changed prototype for chr_map_input - added const.
16  * Added support for C++, headers uses extern "C" for public definitions.
17  *
18  * Revision 1.4  1996/10/29 14:06:48  adam
19  * Include zebrautl.h instead of alexutil.h.
20  *
21  * Revision 1.3  1996/05/09 07:28:54  quinn
22  * Work towards phrases and multiple registers
23  *
24  * Revision 1.2  1995/11/15  19:13:07  adam
25  * Work on record management.
26  *
27  *
28  * This interface is used by other modules (the Z-server in particular)
29  * to normalize the attributes given in queries.
30  */
31
32 #include <stdio.h>
33
34 #include <log.h>
35 #include <res.h>
36 #include <zebrautl.h>
37 #include "zserver.h"
38
39 static void att_loadset(void *p, const char *n, const char *name)
40 {
41     data1_attset *cnew;
42     ZServerInfo *zi = p;
43
44     if (!(cnew = data1_read_attset(zi->dh, (char*) name)))
45     {
46         logf(LOG_WARN|LOG_ERRNO, "%s", name);
47         return;
48     }
49     cnew->next = zi->registered_sets;
50     zi->registered_sets = cnew;
51 }
52
53 static void load_atts(ZServerInfo *zi)
54 {
55     res_trav(zi->res, "attset", zi, att_loadset);
56 }
57
58 static data1_att *getatt(data1_attset *p, int att)
59 {
60     data1_att *a;
61
62     for (; p; p = p->next)
63     {
64         /* scan local set */
65         for (a = p->atts; a; a = a->next)
66             if (a->value == att)
67                 return a;
68         /* scan included sets */
69         if (p->children && (a = getatt(p->children, att)))
70             return a;
71     }
72     return 0;
73 }
74
75 int att_getentbyatt(ZServerInfo *zi, attent *res, oid_value set, int att)
76 {
77     data1_att *r;
78     data1_attset *p;
79
80     if (!zi->registered_sets)
81         load_atts(zi);
82     for (p = zi->registered_sets; p; p = p->next)
83         if (p->reference == set)
84             break;;
85     if (!p)
86         return -2;
87     if (!(r = getatt(p, att)))
88         return -1;
89     res->attset_ordinal = r->parent->ordinal;
90     res->local_attributes = r->locals;
91     return 0;
92 }