1 /* $Id: limit.c,v 1.3 2005-05-09 10:28:09 adam Exp $
2 Copyright (C) 1995-2005
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 Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include <yaz/xmalloc.h>
27 #include <yaz/diagbib1.h>
35 void zebra_limit_destroy(struct zebra_limit *zl)
44 struct zebra_limit *zebra_limit_create(int complement_flag, zint *ids)
46 struct zebra_limit *zl = 0;
50 for (i = 0; ids[i]; i++)
52 zl = xmalloc(sizeof(*zl));
53 zl->ids = xmalloc((i+1) * sizeof(*ids));
54 memcpy(zl->ids, ids, (i+1) * sizeof(*ids));
55 zl->complement_flag = complement_flag;
60 static int zebra_limit_filter_cb(const void *buf, void *data)
62 struct zebra_limit *zl = data;
63 const struct it_key *key = buf;
68 for (i = 0; zl->ids[i]; i++)
69 if (zl->ids[i] == key->mem[1])
70 return zl->complement_flag ? 0 : 1;
71 return zl->complement_flag ? 1 : 0;
74 static void zebra_limit_destroy_cb(void *data)
76 zebra_limit_destroy(data);
79 void zebra_limit_for_rset(struct zebra_limit *zl,
80 int (**filter_func)(const void *buf, void *data),
81 void (**filter_destroy)(void *data),
86 struct zebra_limit *hl;
88 hl = zebra_limit_create(zl->complement_flag, zl->ids);
90 *filter_func = zebra_limit_filter_cb;
91 *filter_destroy = zebra_limit_destroy_cb;