Working on and operation which deals with segments (matches within fields)
[idzebra-moved-to-github.git] / index / kcontrol.c
1 /* $Id: kcontrol.c,v 1.3 2006-07-04 14:10:30 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 <assert.h>
24 #include "index.h"
25
26 struct context_control {
27     int ref_count;
28     void (*filter_destroy)(void *data);
29 };
30
31 static void my_inc(struct rset_key_control *kc)
32 {
33     struct context_control *cp;
34
35     assert(kc);
36     cp = kc->context;
37     (cp->ref_count)++;
38 }
39
40 static void my_dec(struct rset_key_control *kc)
41 {
42     struct context_control *cp;
43
44     assert(kc);
45     cp = kc->context;
46     (cp->ref_count)--;
47     if (cp->ref_count == 0)
48     {
49         if (cp->filter_destroy)
50             (*cp->filter_destroy)(kc->filter_data);
51         xfree(cp);
52         xfree(kc);
53     }
54 }
55
56
57 struct rset_key_control *zebra_key_control_create(ZebraHandle zh)
58 {
59     const char *res_val;
60     struct rset_key_control *kc = xmalloc(sizeof(*kc));
61     struct context_control *cp = xmalloc(sizeof(*cp));
62
63     kc->context = cp;
64     kc->key_size = sizeof(struct it_key);
65     kc->scope = 2;
66     kc->cmp = key_compare_it;
67     kc->key_logdump_txt = key_logdump_txt;
68     kc->getseq = key_get_seq;
69     res_val = zebra_get_resource(zh, "segment", 0);
70     kc->get_segment = 0;
71     if (res_val && atoi(res_val))
72     {
73         kc->get_segment = key_get_segment;
74     }
75     zebra_limit_for_rset(zh->m_limit, 
76                          &kc->filter_func,
77                          &cp->filter_destroy,
78                          &kc->filter_data);
79     kc->inc = my_inc;
80     kc->dec = my_dec;
81     cp->ref_count = 1;
82     return kc;
83 }
84
85 /*
86  * Local variables:
87  * c-basic-offset: 4
88  * indent-tabs-mode: nil
89  * End:
90  * vim: shiftwidth=4 tabstop=8 expandtab
91  */
92