1 /* $Id: rsisams.c,v 1.10 2004-08-24 14:25:16 heikki 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
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_read (RSFD rfd, void *buf);
35 static int r_write (RSFD rfd, const void *buf);
37 static const struct rset_control control =
50 const struct rset_control *rset_kind_isams = &control;
54 struct rset_pp_info *next;
55 struct rset_isams_info *info;
58 struct rset_isams_info {
61 struct rset_pp_info *ispt_list;
65 RSET rsisams_create( NMEM nmem, int key_size,
66 int (*cmp)(const void *p1, const void *p2),
67 ISAMS is, ISAMS_P pos)
69 RSET rnew=rset_create_base(&control, nmem);
70 struct rset_isams_info *info;
71 info = (struct rset_isams_info *) nmem_malloc(rnew->nmem,sizeof(*info));
72 assert(key_size); /* FIXME - these belong to the general rset */
76 info->ispt_list = NULL;
81 static void r_delete (RSET ct)
83 struct rset_isams_info *info = (struct rset_isams_info *) ct->priv;
85 logf (LOG_DEBUG, "rsisams_delete");
86 assert (info->ispt_list == NULL);
91 static void *r_create(RSET ct, const struct rset_control *sel, void *parms)
93 rset_isams_parms *pt = (struct rset_isams_parms *) parms;
94 struct rset_isams_info *info;
96 info = (struct rset_isams_info *) xmalloc (sizeof(*info));
99 info->ispt_list = NULL;
104 RSFD r_open (RSET ct, int flag)
106 struct rset_isams_info *info = (struct rset_isams_info *) ct->priv;
107 struct rset_pp_info *ptinfo;
109 logf (LOG_DEBUG, "risams_open");
110 if (flag & RSETF_WRITE)
112 logf (LOG_FATAL, "ISAMS set type is read-only");
115 ptinfo = (struct rset_pp_info *) xmalloc (sizeof(*ptinfo));
116 ptinfo->next = info->ispt_list;
117 info->ispt_list = ptinfo;
118 ptinfo->pt = isams_pp_open (info->is, info->pos);
123 static void r_close (RSFD rfd)
125 struct rset_isams_info *info = ((struct rset_pp_info*) rfd)->info;
126 struct rset_pp_info **ptinfop;
128 for (ptinfop = &info->ispt_list; *ptinfop; ptinfop = &(*ptinfop)->next)
131 isams_pp_close ((*ptinfop)->pt);
132 *ptinfop = (*ptinfop)->next;
136 logf (LOG_FATAL, "r_close but no rfd match!");
140 static void r_rewind (RSFD rfd)
142 logf (LOG_DEBUG, "rsisams_rewind");
147 static int r_read (RSFD rfd, void *buf)
149 return isams_pp_read( ((struct rset_pp_info*) rfd)->pt, buf);
152 static int r_write (RSFD rfd, const void *buf)
154 logf (LOG_FATAL, "ISAMS set type is read-only");