Removed the count function from the rset f-table, in preparation
[idzebra-moved-to-github.git] / rset / rsisams.c
1 /* $Id: rsisams.c,v 1.5 2004-08-03 12:15:45 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 <assert.h>
27 #include <rsisams.h>
28 #include <zebrautl.h>
29
30 static void *r_create(RSET ct, const struct rset_control *sel, void *parms);
31 static RSFD r_open (RSET ct, int flag);
32 static void r_close (RSFD rfd);
33 static void r_delete (RSET ct);
34 static void r_rewind (RSFD rfd);
35 /* static int r_count (RSET ct); */
36 static int r_read (RSFD rfd, void *buf, int *term_index);
37 static int r_write (RSFD rfd, const void *buf);
38
39 static const struct rset_control control = 
40 {
41     "isams",
42     r_create,
43     r_open,
44     r_close,
45     r_delete,
46     r_rewind,
47     rset_default_forward,
48     /* r_count, */
49     r_read,
50     r_write,
51 };
52
53 const struct rset_control *rset_kind_isams = &control;
54
55 struct rset_pp_info {
56     ISAMS_PP pt;
57     struct rset_pp_info *next;
58     struct rset_isams_info *info;
59 };
60
61 struct rset_isams_info {
62     ISAMS   is;
63     ISAMS_P pos;
64     struct rset_pp_info *ispt_list;
65 };
66
67 static void *r_create(RSET ct, const struct rset_control *sel, void *parms)
68 {
69     rset_isams_parms *pt = (struct rset_isams_parms *) parms;
70     struct rset_isams_info *info;
71
72     ct->flags |= RSET_FLAG_VOLATILE;
73     info = (struct rset_isams_info *) xmalloc (sizeof(*info));
74     info->is = pt->is;
75     info->pos = pt->pos;
76     info->ispt_list = NULL;
77     ct->no_rset_terms = 1;
78     ct->rset_terms = (RSET_TERM *) xmalloc (sizeof(*ct->rset_terms));
79     ct->rset_terms[0] = pt->rset_term;
80     return info;
81 }
82
83 RSFD r_open (RSET ct, int flag)
84 {
85     struct rset_isams_info *info = (struct rset_isams_info *) ct->buf;
86     struct rset_pp_info *ptinfo;
87
88     logf (LOG_DEBUG, "risams_open");
89     if (flag & RSETF_WRITE)
90     {
91         logf (LOG_FATAL, "ISAMS set type is read-only");
92         return NULL;
93     }
94     ptinfo = (struct rset_pp_info *) xmalloc (sizeof(*ptinfo));
95     ptinfo->next = info->ispt_list;
96     info->ispt_list = ptinfo;
97     ptinfo->pt = isams_pp_open (info->is, info->pos);
98     ptinfo->info = info;
99     if (ct->rset_terms[0]->nn < 0)
100         ct->rset_terms[0]->nn = isams_pp_num (ptinfo->pt);
101     return ptinfo;
102 }
103
104 static void r_close (RSFD rfd)
105 {
106     struct rset_isams_info *info = ((struct rset_pp_info*) rfd)->info;
107     struct rset_pp_info **ptinfop;
108
109     for (ptinfop = &info->ispt_list; *ptinfop; ptinfop = &(*ptinfop)->next)
110         if (*ptinfop == rfd)
111         {
112             isams_pp_close ((*ptinfop)->pt);
113             *ptinfop = (*ptinfop)->next;
114             xfree (rfd);
115             return;
116         }
117     logf (LOG_FATAL, "r_close but no rfd match!");
118     assert (0);
119 }
120
121 static void r_delete (RSET ct)
122 {
123     struct rset_isams_info *info = (struct rset_isams_info *) ct->buf;
124
125     logf (LOG_DEBUG, "rsisams_delete");
126     assert (info->ispt_list == NULL);
127     rset_term_destroy (ct->rset_terms[0]);
128     xfree (ct->rset_terms);
129     xfree (info);
130 }
131
132 static void r_rewind (RSFD rfd)
133 {   
134     logf (LOG_DEBUG, "rsisams_rewind");
135     abort ();
136 }
137
138 /*
139 static int r_count (RSET ct)
140 {
141     return 0;
142 }
143 */
144
145 static int r_read (RSFD rfd, void *buf, int *term_index)
146 {
147     *term_index = 0;
148     return isams_pp_read( ((struct rset_pp_info*) rfd)->pt, buf);
149 }
150
151 static int r_write (RSFD rfd, const void *buf)
152 {
153     logf (LOG_FATAL, "ISAMS set type is read-only");
154     return -1;
155 }