1 /* $Id: rsisamc.c,v 1.21 2004-08-24 14:25:16 heikki Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
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
32 static RSFD r_open (RSET ct, int flag);
33 static void r_close (RSFD rfd);
34 static void r_delete (RSET ct);
35 static void r_rewind (RSFD rfd);
36 static int r_read (RSFD rfd, void *buf);
37 static int r_write (RSFD rfd, const void *buf);
39 static const struct rset_control control =
52 const struct rset_control *rset_kind_isamc = &control;
56 struct rset_pp_info *next;
57 struct rset_isamc_info *info;
61 struct rset_isamc_info {
65 int (*cmp)(const void *p1, const void *p2);
66 struct rset_pp_info *ispt_list;
69 RSET rsisamc_create( NMEM nmem, int key_size,
70 int (*cmp)(const void *p1, const void *p2),
71 ISAMC is, ISAMC_P pos)
73 RSET rnew=rset_create_base(&control, nmem);
74 struct rset_isamc_info *info;
75 info = (struct rset_isamc_info *) nmem_malloc(rnew->nmem,sizeof(*info));
76 info->key_size = key_size;
78 info->ispt_list = NULL;
85 static void r_delete (RSET ct)
87 struct rset_isamc_info *info = (struct rset_isamc_info *) ct->priv;
89 logf (LOG_DEBUG, "rsisamc_delete");
90 assert (info->ispt_list == NULL);
94 static void *r_create(RSET ct, const struct rset_control *sel, void *parms)
96 rset_isamc_parms *pt = (rset_isamc_parms *) parms;
97 struct rset_isamc_info *info;
99 info = (struct rset_isamc_info *) xmalloc (sizeof(*info));
102 info->key_size = pt->key_size;
104 info->ispt_list = NULL;
109 RSFD r_open (RSET ct, int flag)
111 struct rset_isamc_info *info = (struct rset_isamc_info *) ct->priv;
112 struct rset_pp_info *ptinfo;
114 logf (LOG_DEBUG, "risamc_open");
115 if (flag & RSETF_WRITE)
117 logf (LOG_FATAL, "ISAMC set type is read-only");
120 ptinfo = (struct rset_pp_info *) xmalloc (sizeof(*ptinfo));
121 ptinfo->next = info->ispt_list;
122 info->ispt_list = ptinfo;
123 ptinfo->pt = isc_pp_open (info->is, info->pos);
125 ptinfo->buf = xmalloc (info->key_size);
129 static void r_close (RSFD rfd)
131 struct rset_isamc_info *info = ((struct rset_pp_info*) rfd)->info;
132 struct rset_pp_info **ptinfop;
134 for (ptinfop = &info->ispt_list; *ptinfop; ptinfop = &(*ptinfop)->next)
137 xfree ((*ptinfop)->buf);
138 isc_pp_close ((*ptinfop)->pt);
139 *ptinfop = (*ptinfop)->next;
143 logf (LOG_FATAL, "r_close but no rfd match!");
148 static void r_rewind (RSFD rfd)
150 logf (LOG_DEBUG, "rsisamc_rewind");
154 static int r_read (RSFD rfd, void *buf)
156 struct rset_pp_info *pinfo = (struct rset_pp_info *) rfd;
158 r = isc_pp_read(pinfo->pt, buf);
162 static int r_write (RSFD rfd, const void *buf)
164 logf (LOG_FATAL, "ISAMC set type is read-only");