1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2009 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <yaz/xmalloc.h>
24 #include <yaz/diagbib1.h>
27 #define ZEBRA_LIMIT_DEBUG 0
34 void zebra_limit_destroy(struct zebra_limit *zl)
43 struct zebra_limit *zebra_limit_create(int complement_flag, zint *ids)
45 struct zebra_limit *zl = 0;
49 for (i = 0; ids[i]; i++)
51 zl = xmalloc(sizeof(*zl));
52 zl->ids = xmalloc((i+1) * sizeof(*ids));
53 memcpy(zl->ids, ids, (i+1) * sizeof(*ids));
54 zl->complement_flag = complement_flag;
59 static int zebra_limit_filter_cb(const void *buf, void *data)
61 struct zebra_limit *zl = data;
62 const struct it_key *key = buf;
66 yaz_log(YLOG_LOG, "zebra_limit_filter_cb zl=%p key->len=%d", zl, key->len);
68 for (i = 0; zl->ids[i]; i++)
71 yaz_log(YLOG_LOG, " i=%d ids=" ZINT_FORMAT " mem=" ZINT_FORMAT,
72 i, zl->ids[i], key->mem[1]);
74 if (zl->ids[i] == key->mem[1])
77 yaz_log(YLOG_LOG, " match. Ret=%d", zl->complement_flag ? 0:1);
79 return zl->complement_flag ? 0 : 1;
83 yaz_log(YLOG_LOG, " no match. Ret=%d", zl->complement_flag ? 1:0);
85 return zl->complement_flag ? 1 : 0;
88 static void zebra_limit_destroy_cb(void *data)
90 zebra_limit_destroy(data);
93 void zebra_limit_for_rset(struct zebra_limit *zl,
94 int (**filter_func)(const void *buf, void *data),
95 void (**filter_destroy)(void *data),
99 yaz_log(YLOG_LOG, "zebra_limit_for_rset debug enabled zl=%p", zl);
103 struct zebra_limit *hl;
105 #if ZEBRA_LIMIT_DEBUG
106 yaz_log(YLOG_LOG, "enable limit");
108 hl = zebra_limit_create(zl->complement_flag, zl->ids);
110 *filter_func = zebra_limit_filter_cb;
111 *filter_destroy = zebra_limit_destroy_cb;
124 * c-file-style: "Stroustrup"
125 * indent-tabs-mode: nil
127 * vim: shiftwidth=4 tabstop=8 expandtab