1 /* $Id: rsisam.c,v 1.23 2002-08-02 19:26:57 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
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
29 static void *r_create(RSET ct, const struct rset_control *sel, void *parms);
30 static RSFD r_open (RSET ct, int flag);
31 static void r_close (RSFD rfd);
32 static void r_delete (RSET ct);
33 static void r_rewind (RSFD rfd);
34 static int r_count (RSET ct);
35 static int r_read (RSFD rfd, void *buf, int *term_index);
36 static int r_write (RSFD rfd, const void *buf);
38 static const struct rset_control control =
51 const struct rset_control *rset_kind_isam = &control;
53 struct rset_ispt_info {
55 struct rset_ispt_info *next;
56 struct rset_isam_info *info;
59 struct rset_isam_info {
62 struct rset_ispt_info *ispt_list;
65 static void *r_create(RSET ct, const struct rset_control *sel, void *parms)
67 rset_isam_parms *pt = (rset_isam_parms *) parms;
68 struct rset_isam_info *info;
70 ct->flags |= RSET_FLAG_VOLATILE;
71 info = (struct rset_isam_info *) xmalloc (sizeof(struct rset_isam_info));
74 info->ispt_list = NULL;
76 ct->no_rset_terms = 1;
77 ct->rset_terms = (RSET_TERM *) xmalloc (sizeof(*ct->rset_terms));
78 ct->rset_terms[0] = pt->rset_term;
82 RSFD r_open (RSET ct, int flag)
84 struct rset_isam_info *info = (struct rset_isam_info *) ct->buf;
85 struct rset_ispt_info *ptinfo;
87 logf (LOG_DEBUG, "risam_open");
88 if (flag & RSETF_WRITE)
90 logf (LOG_FATAL, "ISAM set type is read-only");
93 ptinfo = (struct rset_ispt_info *) xmalloc (sizeof(*ptinfo));
94 ptinfo->next = info->ispt_list;
95 info->ispt_list = ptinfo;
96 ptinfo->pt = is_position (info->is, info->pos);
99 if (ct->rset_terms[0]->nn < 0)
100 ct->rset_terms[0]->nn = is_numkeys (ptinfo->pt);
104 static void r_close (RSFD rfd)
106 struct rset_isam_info *info = ((struct rset_ispt_info*) rfd)->info;
107 struct rset_ispt_info **ptinfop;
109 for (ptinfop = &info->ispt_list; *ptinfop; ptinfop = &(*ptinfop)->next)
112 is_pt_free ((*ptinfop)->pt);
113 *ptinfop = (*ptinfop)->next;
117 logf (LOG_FATAL, "r_close but no rfd match!");
121 static void r_delete (RSET ct)
123 struct rset_isam_info *info = (struct rset_isam_info *) ct->buf;
125 logf (LOG_DEBUG, "rsisam_delete");
126 assert (info->ispt_list == NULL);
127 rset_term_destroy (ct->rset_terms[0]);
128 xfree (ct->rset_terms);
132 static void r_rewind (RSFD rfd)
134 logf (LOG_DEBUG, "rsisam_rewind");
135 is_rewind( ((struct rset_ispt_info*) rfd)->pt);
138 static int r_count (RSET ct)
143 static int r_read (RSFD rfd, void *buf, int *term_index)
146 return is_readkey( ((struct rset_ispt_info*) rfd)->pt, buf);
149 static int r_write (RSFD rfd, const void *buf)
151 logf (LOG_FATAL, "ISAM set type is read-only");