IDZEBRA  2.1.2
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 
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
7 version.
8 
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
12 for more details.
13 
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
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;
31  int buf_size;
32  int size;
33  int off;
35  off_t moffset;
36  WRBUF wrbuf;
37 };
38 
39 int 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 
84 static 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 
93 static ZEBRA_RES grs_config_sgml(void *clientData, Res res, const char *args)
94 {
95  return ZEBRA_OK;
96 }
97 
98 static 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 
107 static int grs_extract_sgml(void *clientData, struct recExtractCtrl *ctrl)
108 {
109  return zebra_grs_extract(clientData, ctrl, grs_read_sgml);
110 }
111 
112 static int grs_retrieve_sgml(void *clientData, struct recRetrieveCtrl *ctrl)
113 {
114  return zebra_grs_retrieve(clientData, ctrl, grs_read_sgml);
115 }
116 
117 static struct recType grs_type_sgml =
118 {
119  0,
120  "grs.sgml",
126 };
127 
128 RecType
129 #if IDZEBRA_STATIC_GRS_SGML
130 idzebra_filter_grs_sgml
131 #else
133 #endif
134 
135 [] = {
136  &grs_type_sgml,
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 
static int grs_retrieve_sgml(void *clientData, struct recRetrieveCtrl *ctrl)
Definition: mod_grs_sgml.c:112
data1_node * data1_read_nodex(data1_handle dh, NMEM m, int(*get_byte)(void *fh), void *fh, WRBUF wrbuf)
Definition: d1_read.c:660
#define ZEBRA_OK
Definition: util.h:82
static void grs_destroy_sgml(void *clientData)
Definition: mod_grs_sgml.c:98
static void * grs_init_sgml(Res res, RecType recType)
Definition: mod_grs_sgml.c:84
int zebra_grs_extract(void *clientData, struct recExtractCtrl *p, data1_node *(*grs_read)(struct grs_read_info *))
Definition: recgrs.c:935
void * clientData
Definition: recgrs.h:29
Definition: res.c:46
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
static ZEBRA_RES grs_config_sgml(void *clientData, Res res, const char *args)
Definition: mod_grs_sgml.c:93
int sgml_getc(void *clientData)
Definition: mod_grs_sgml.c:39
static data1_node * grs_read_sgml(struct grs_read_info *p)
Definition: mod_grs_sgml.c:60
static struct recType grs_type_sgml
Definition: mod_grs_sgml.c:117
data1_handle dh
Definition: recgrs.h:31
off_t(* tellf)(struct ZebraRecStream *s)
tell function
Definition: recctrl.h:79
record extract for indexing
Definition: recctrl.h:101
short ZEBRA_RES
Common return type for Zebra API.
Definition: util.h:80
NMEM mem
Definition: recgrs.h:30
int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p, data1_node *(*grs_read)(struct grs_read_info *))
Definition: recgrs.c:1071
struct ZebraRecStream * stream
Definition: recgrs.h:28
RecType idzebra_filter[]
Definition: mod_grs_sgml.c:135
struct ZebraRecStream * stream
Definition: mod_grs_sgml.c:34
record reader stream
Definition: recctrl.h:71
static int grs_extract_sgml(void *clientData, struct recExtractCtrl *ctrl)
Definition: mod_grs_sgml.c:107