Declarations for the rset_forward function. No actual code yet
[idzebra-moved-to-github.git] / rset / rset.c
1 /* $Id: rset.c,v 1.18 2004-01-16 15:27:35 heikki Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
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
24
25 #include <stdio.h>
26 #include <string.h>
27 #include <zebrautl.h>
28
29 #include <rset.h>
30
31 RSET rset_create(const struct rset_control *sel, void *parms)
32 {
33     RSET rnew;
34     int i;
35
36     logf (LOG_DEBUG, "rs_create(%s)", sel->desc);
37     rnew = (RSET) xmalloc(sizeof(*rnew));
38     rnew->control = sel;
39     rnew->flags = 0;
40     rnew->count = 1;
41     rnew->rset_terms = NULL;
42     rnew->no_rset_terms = 0;
43     rnew->buf = (*sel->f_create)(rnew, sel, parms);
44     logf (LOG_DEBUG, "no_rset_terms: %d", rnew->no_rset_terms);
45     for (i = 0; i<rnew->no_rset_terms; i++)
46         logf (LOG_DEBUG, " %s", rnew->rset_terms[i]->name);
47     return rnew;
48 }
49
50 void rset_delete (RSET rs)
51 {
52     (rs->count)--;
53     if (!rs->count)
54     {
55         (*rs->control->f_delete)(rs);
56         xfree(rs);
57     }
58 }
59
60 RSET rset_dup (RSET rs)
61 {
62     (rs->count)++;
63     return rs;
64 }
65
66 int rset_default_forward(RSFD rfd, void *buf, const void *untilbuf)
67 {
68     logf (LOG_FATAL, "rset_default-forward not yet implemented (%s)");
69 }
70
71 RSET_TERM *rset_terms(RSET rs, int *no)
72 {
73     *no = rs->no_rset_terms;
74     return rs->rset_terms;
75 }
76
77 RSET_TERM rset_term_create (const char *name, int length, const char *flags,
78                             int type)
79 {
80     RSET_TERM t = (RSET_TERM) xmalloc (sizeof(*t));
81     if (!name)
82         t->name = NULL;
83     else if (length == -1)
84         t->name = xstrdup (name);
85     else
86     {
87         t->name = (char*) xmalloc (length+1);
88         memcpy (t->name, name, length);
89         t->name[length] = '\0';
90     }
91     if (!flags)
92         t->flags = NULL;
93     else
94         t->flags = xstrdup (flags);
95     t->nn = -1;
96     t->count = 0;
97     t->type = type;
98     return t;
99 }
100
101 void rset_term_destroy (RSET_TERM t)
102 {
103     xfree (t->name);
104     xfree (t->flags);
105     xfree (t);
106 }
107
108 RSET_TERM rset_term_dup (RSET_TERM t)
109 {
110     RSET_TERM nt = (RSET_TERM) xmalloc (sizeof(*nt));
111     if (t->name)
112         nt->name = xstrdup (t->name);
113     else
114         nt->name = NULL;
115     if (t->flags)
116         nt->flags = xstrdup (t->flags);
117     else
118         nt->flags = NULL;
119     nt->nn = t->nn;
120     return nt;
121 }