-/*
- * Copyright (C) 1994-1995, Index Data I/S
- * All rights reserved.
- * Sebastian Hammer, Adam Dickmeiss
- *
- * $Log: attribute.c,v $
- * Revision 1.2 1995-11-15 19:13:07 adam
- * Work on record management.
- *
- *
- * This interface is used by other modules (the Z-server in particular)
- * to normalize the attributes given in queries.
- */
+/* $Id: attribute.c,v 1.19 2005-01-15 19:38:24 adam Exp $
+ Copyright (C) 1995-2005
+ Index Data ApS
-#include <stdio.h>
+This file is part of the Zebra server.
-#include <log.h>
-#include <alexutil.h>
-#include <res.h>
-#include <d1_attset.h>
+Zebra is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
-#include "attribute.h"
+Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
-static int initialized = 0;
+You should have received a copy of the GNU General Public License
+along with Zebra; see the file LICENSE.zebra. If not, write to the
+Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
+*/
-static data1_attset *registered_sets = 0;
-static void att_loadset(const char *n, const char *name)
-{
- data1_attset *new;
- if (!(new = data1_read_attset((char*) name)))
- {
- logf(LOG_WARN|LOG_ERRNO, "%s", name);
- return;
- }
- new->next = registered_sets;
- registered_sets = new;
- return;
-}
+#include <stdio.h>
-static void load_atts()
-{
- res_trav(common_resource, "attset", att_loadset);
-}
+#include <yaz/log.h>
+#include <idzebra/res.h>
+#include <zebrautl.h>
+#include "index.h"
-static data1_att *getatt(data1_attset *p, int att)
+static data1_att *getatt(data1_attset *p, int att, const char *sattr)
{
data1_att *a;
+ data1_attset_child *c;
- for (; p; p = p->next)
- {
- /* scan local set */
- for (a = p->atts; a; a = a->next)
- if (a->value == att)
- return a;
- /* scan included sets */
- if (p->children && (a = getatt(p->children, att)))
+ /* scan local set */
+ for (a = p->atts; a; a = a->next)
+ if (sattr && !yaz_matchstr(sattr, a->name))
+ return a;
+ else if (a->value == att)
+ return a;
+ /* scan included sets */
+ for (c = p->children; c; c = c->next)
+ if ((a = getatt(c->child, att, sattr)))
return a;
- }
return 0;
}
-attent *att_getentbyatt(oid_value set, int att)
+int att_getentbyatt(ZebraHandle zi, attent *res, oid_value set, int att,
+ const char *sattr)
{
- static attent res;
data1_att *r;
data1_attset *p;
- if (!initialized)
+ if (!(p = data1_attset_search_id (zi->reg->dh, set)))
{
- initialized = 1;
- load_atts();
+ zebraExplain_loadAttsets (zi->reg->dh, zi->res);
+ p = data1_attset_search_id (zi->reg->dh, set);
}
- for (p = registered_sets; p; p = p->next)
- if (p->reference == set && (r = getatt(p, att)))
- break;;
if (!p)
- return 0;
- res.attset_ordinal = r->parent->ordinal;
- res.local_attribute = r->local;
- return &res;
+ return -2;
+ if (!(r = getatt(p, att, sattr)))
+ return -1;
+ res->attset_ordinal = r->parent->reference;
+ res->local_attributes = r->locals;
+ return 0;
}