1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2011 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <idzebra/util.h>
26 static RSFD r_open(RSET ct, int flag);
27 static void r_close(RSFD rfd);
28 static void r_delete(RSET ct);
29 static int r_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf);
30 static void r_pos(RSFD rfd, double *current, double *total);
31 static int r_read(RSFD rfd, void *buf, TERMID *term);
32 static int r_read_filter(RSFD rfd, void *buf, TERMID *term);
33 static int r_write(RSFD rfd, const void *buf);
35 static const struct rset_control control =
48 static const struct rset_control control_filter =
71 static int log_level = 0;
72 static int log_level_initialized = 0;
74 RSET rsisamb_create(NMEM nmem, struct rset_key_control *kcontrol,
76 ISAMB is, ISAM_P pos, TERMID term)
78 RSET rnew = rset_create_base(
79 kcontrol->filter_func ? &control_filter : &control,
80 nmem, kcontrol, scope, term, 0, 0);
81 struct rset_private *info;
83 if (!log_level_initialized)
85 log_level = yaz_log_module_level("rsisamb");
86 log_level_initialized = 1;
88 info = (struct rset_private *) nmem_malloc(rnew->nmem, sizeof(*info));
92 yaz_log(log_level, "rsisamb_create");
96 static void r_delete(RSET ct)
98 yaz_log(log_level, "rsisamb_delete");
101 RSFD r_open(RSET ct, int flag)
103 struct rset_private *info = (struct rset_private *) ct->priv;
105 struct rfd_private *ptinfo;
107 if (flag & RSETF_WRITE)
109 yaz_log(YLOG_FATAL, "ISAMB set type is read-only");
112 rfd = rfd_create_base(ct);
114 ptinfo = (struct rfd_private *) (rfd->priv);
116 ptinfo = (struct rfd_private *) nmem_malloc(ct->nmem,sizeof(*ptinfo));
117 ptinfo->buf = nmem_malloc(ct->nmem,ct->keycontrol->key_size);
120 ptinfo->pt = isamb_pp_open(info->is, info->pos, ct->scope );
121 yaz_log(log_level, "rsisamb_open");
125 static void r_close(RSFD rfd)
127 struct rfd_private *ptinfo = (struct rfd_private *)(rfd->priv);
128 isamb_pp_close (ptinfo->pt);
129 yaz_log(log_level, "rsisamb_close");
133 static int r_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
135 struct rfd_private *pinfo = (struct rfd_private *)(rfd->priv);
137 rc = isamb_pp_forward(pinfo->pt, buf, untilbuf);
139 *term = rfd->rset->term;
140 yaz_log(log_level, "rsisamb_forward");
144 static void r_pos(RSFD rfd, double *current, double *total)
146 struct rfd_private *pinfo = (struct rfd_private *)(rfd->priv);
148 isamb_pp_pos(pinfo->pt, current, total);
149 yaz_log(log_level, "isamb.r_pos returning %0.1f/%0.1f",
153 static int r_read(RSFD rfd, void *buf, TERMID *term)
155 struct rfd_private *pinfo = (struct rfd_private *)(rfd->priv);
157 rc = isamb_pp_read(pinfo->pt, buf);
159 *term = rfd->rset->term;
160 yaz_log(log_level, "isamb.r_read ");
164 static int r_read_filter(RSFD rfd, void *buf, TERMID *term)
166 struct rfd_private *pinfo = (struct rfd_private *)rfd->priv;
167 const struct rset_key_control *kctrl = rfd->rset->keycontrol;
169 while((rc = isamb_pp_read(pinfo->pt, buf)))
171 int incl = (*kctrl->filter_func)(buf, kctrl->filter_data);
176 *term = rfd->rset->term;
177 yaz_log(log_level, "isamb.r_read_filter");
181 static int r_write(RSFD rfd, const void *buf)
183 yaz_log(YLOG_FATAL, "ISAMB set type is read-only");
189 * c-file-style: "Stroustrup"
190 * indent-tabs-mode: nil
192 * vim: shiftwidth=4 tabstop=8 expandtab