1 /* This file is part of the Zebra server.
2 Copyright (C) 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
25 #include <idzebra/util.h>
29 static RSFD r_open(RSET ct, int flag);
30 static void r_close(RSFD rfd);
31 static void r_delete(RSET ct);
32 static int r_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf);
33 static void r_pos(RSFD rfd, double *current, double *total);
34 static int r_read(RSFD rfd, void *buf, TERMID *term);
35 static int r_read_filter(RSFD rfd, void *buf, TERMID *term);
37 static const struct rset_control control =
50 static const struct rset_control control_filter =
73 static int log_level = 0;
74 static int log_level_initialized = 0;
76 RSET rsisamb_create(NMEM nmem, struct rset_key_control *kcontrol,
78 ISAMB is, ISAM_P pos, TERMID term)
80 RSET rnew = rset_create_base(
81 kcontrol->filter_func ? &control_filter : &control,
82 nmem, kcontrol, scope, term, 0, 0);
83 struct rset_private *info;
85 if (!log_level_initialized)
87 log_level = yaz_log_module_level("rsisamb");
88 log_level_initialized = 1;
90 info = (struct rset_private *) nmem_malloc(rnew->nmem, sizeof(*info));
94 yaz_log(log_level, "rsisamb_create");
98 static void r_delete(RSET ct)
100 yaz_log(log_level, "rsisamb_delete");
103 RSFD r_open(RSET ct, int flag)
105 struct rset_private *info = (struct rset_private *) ct->priv;
107 struct rfd_private *ptinfo;
109 if (flag & RSETF_WRITE)
111 yaz_log(YLOG_FATAL, "ISAMB set type is read-only");
114 rfd = rfd_create_base(ct);
116 ptinfo = (struct rfd_private *) (rfd->priv);
118 ptinfo = (struct rfd_private *) nmem_malloc(ct->nmem,sizeof(*ptinfo));
119 ptinfo->buf = nmem_malloc(ct->nmem,ct->keycontrol->key_size);
122 ptinfo->pt = isamb_pp_open(info->is, info->pos, ct->scope );
123 yaz_log(log_level, "rsisamb_open");
127 static void r_close(RSFD rfd)
129 struct rfd_private *ptinfo = (struct rfd_private *)(rfd->priv);
130 isamb_pp_close (ptinfo->pt);
131 yaz_log(log_level, "rsisamb_close");
135 static int r_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
137 struct rfd_private *pinfo = (struct rfd_private *)(rfd->priv);
139 rc = isamb_pp_forward(pinfo->pt, buf, untilbuf);
141 *term = rfd->rset->term;
142 yaz_log(log_level, "rsisamb_forward");
146 static void r_pos(RSFD rfd, double *current, double *total)
148 struct rfd_private *pinfo = (struct rfd_private *)(rfd->priv);
150 isamb_pp_pos(pinfo->pt, current, total);
151 yaz_log(log_level, "isamb.r_pos returning %0.1f/%0.1f",
155 static int r_read(RSFD rfd, void *buf, TERMID *term)
157 struct rfd_private *pinfo = (struct rfd_private *)(rfd->priv);
159 rc = isamb_pp_read(pinfo->pt, buf);
161 *term = rfd->rset->term;
162 yaz_log(log_level, "isamb.r_read ");
166 static int r_read_filter(RSFD rfd, void *buf, TERMID *term)
168 struct rfd_private *pinfo = (struct rfd_private *)rfd->priv;
169 const struct rset_key_control *kctrl = rfd->rset->keycontrol;
171 while((rc = isamb_pp_read(pinfo->pt, buf)))
173 int incl = (*kctrl->filter_func)(buf, kctrl->filter_data);
178 *term = rfd->rset->term;
179 yaz_log(log_level, "isamb.r_read_filter");
186 * c-file-style: "Stroustrup"
187 * indent-tabs-mode: nil
189 * vim: shiftwidth=4 tabstop=8 expandtab