IDZEBRA 2.2.8
mod_grs_sgml.c
Go to the documentation of this file.
1/* This file is part of the Zebra server.
2 Copyright (C) Index Data
3
4Zebra is free software; you can redistribute it and/or modify it under
5the terms of the GNU General Public License as published by the Free
6Software Foundation; either version 2, or (at your option) any later
7version.
8
9Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10WARRANTY; without even the implied warranty of MERCHANTABILITY or
11FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
18*/
19
20
21#if HAVE_CONFIG_H
22#include <config.h>
23#endif
24#include <assert.h>
25#include <yaz/log.h>
26
27#include <idzebra/recgrs.h>
28
30 char *buf;
32 int size;
33 int off;
35 off_t moffset;
36 WRBUF wrbuf;
37};
38
39int sgml_getc (void *clientData)
40{
41 struct sgml_getc_info *p = (struct sgml_getc_info *) clientData;
42 int res;
43
44 if (p->off < p->size)
45 return p->buf[(p->off)++];
46 if (p->size < p->buf_size)
47 return 0;
48 p->moffset += p->off;
49 p->off = 0;
50 p->size = 0;
51 res = p->stream->readf(p->stream, p->buf, p->buf_size);
52 if (res > 0)
53 {
54 p->size += res;
55 return p->buf[(p->off)++];
56 }
57 return 0;
58}
59
61{
62 struct sgml_getc_info *sgi = (struct sgml_getc_info *) p->clientData;
63 data1_node *node;
64 int res;
65
66 sgi->moffset = p->stream->tellf(p->stream);
67 sgi->stream = p->stream;
68 sgi->off = 0;
69 sgi->size = 0;
70 res = sgi->stream->readf(sgi->stream, sgi->buf, sgi->buf_size);
71 if (res > 0)
72 sgi->size += res;
73 else
74 return 0;
75 node = data1_read_nodex(p->dh, p->mem, sgml_getc, sgi, sgi->wrbuf);
76 if (node && p->stream->endf)
77 {
78 off_t end_offset = sgi->moffset + sgi->off;
79 p->stream->endf(sgi->stream, &end_offset);
80 }
81 return node;
82}
83
84static void *grs_init_sgml(Res res, RecType recType)
85{
86 struct sgml_getc_info *p = (struct sgml_getc_info *) xmalloc (sizeof(*p));
87 p->buf_size = 512;
88 p->buf = xmalloc (p->buf_size);
89 p->wrbuf = wrbuf_alloc();
90 return p;
91}
92
93static ZEBRA_RES grs_config_sgml(void *clientData, Res res, const char *args)
94{
95 return ZEBRA_OK;
96}
97
98static void grs_destroy_sgml(void *clientData)
99{
100 struct sgml_getc_info *p = (struct sgml_getc_info *) clientData;
101
102 wrbuf_destroy(p->wrbuf);
103 xfree(p->buf);
104 xfree(p);
105}
106
107static int grs_extract_sgml(void *clientData, struct recExtractCtrl *ctrl)
108{
109 return zebra_grs_extract(clientData, ctrl, grs_read_sgml);
110}
111
112static int grs_retrieve_sgml(void *clientData, struct recRetrieveCtrl *ctrl)
113{
114 return zebra_grs_retrieve(clientData, ctrl, grs_read_sgml);
115}
116
117static struct recType grs_type_sgml =
118{
119 0,
120 "grs.sgml",
126};
127
129#if IDZEBRA_STATIC_GRS_SGML
130idzebra_filter_grs_sgml
131#else
133#endif
134
135[] = {
137 0,
138};
139/*
140 * Local variables:
141 * c-basic-offset: 4
142 * c-file-style: "Stroustrup"
143 * indent-tabs-mode: nil
144 * End:
145 * vim: shiftwidth=4 tabstop=8 expandtab
146 */
147
data1_node * data1_read_nodex(data1_handle dh, NMEM m, int(*get_byte)(void *fh), void *fh, WRBUF wrbuf)
Definition d1_read.c:632
RecType idzebra_filter[]
static data1_node * grs_read_sgml(struct grs_read_info *p)
static ZEBRA_RES grs_config_sgml(void *clientData, Res res, const char *args)
static void grs_destroy_sgml(void *clientData)
static struct recType grs_type_sgml
int sgml_getc(void *clientData)
static int grs_extract_sgml(void *clientData, struct recExtractCtrl *ctrl)
static void * grs_init_sgml(Res res, RecType recType)
static int grs_retrieve_sgml(void *clientData, struct recRetrieveCtrl *ctrl)
int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p, data1_node *(*grs_read)(struct grs_read_info *))
Definition recgrs.c:1072
int zebra_grs_extract(void *clientData, struct recExtractCtrl *p, data1_node *(*grs_read)(struct grs_read_info *))
Definition recgrs.c:936
record reader stream
Definition recctrl.h:71
off_t(* endf)(struct ZebraRecStream *s, off_t *offset)
set and get of record position
Definition recctrl.h:81
int(* readf)(struct ZebraRecStream *s, char *buf, size_t count)
read function
Definition recctrl.h:75
off_t(* tellf)(struct ZebraRecStream *s)
tell function
Definition recctrl.h:79
data1_handle dh
Definition recgrs.h:31
struct ZebraRecStream * stream
Definition recgrs.h:28
void * clientData
Definition recgrs.h:29
record extract for indexing
Definition recctrl.h:101
struct ZebraRecStream * stream
#define ZEBRA_OK
Definition util.h:82
short ZEBRA_RES
Common return type for Zebra API.
Definition util.h:80