1 /* This file is part of the Zebra server.
2 Copyright (C) 2004-2013 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 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include <stdio.h>
24 #include <stdlib.h>
25
26 #include <yaz/log.h>
27 #include <idzebra/data1.h>
28
29 #define DATA1_FLAG_XML 1
30
31 struct data1_handle_info {
32 WRBUF wrbuf;
33 char *tab_path;
34 char *tab_root;
35
36 char *read_buf;
37 int read_len;
38
39 data1_absyn_cache absyn_cache;
40 data1_attset_cache attset_cache;
41
42 char *map_buf;
43 int map_len;
44
45 NMEM mem;
46 };
47
data1_create(void)48 data1_handle data1_create(void)
49 {
50 data1_handle p = (data1_handle)xmalloc (sizeof(*p));
51 if (!p)
52 return 0;
53 p->tab_path = NULL;
54 p->tab_root = NULL;
55 p->wrbuf = wrbuf_alloc();
56 p->read_buf = NULL;
57 p->read_len = 0;
58 p->map_buf = NULL;
59 p->map_len = 0;
60 p->absyn_cache = NULL;
61 p->attset_cache = NULL;
62 p->mem = nmem_create ();
63 return p;
64 }
65
data1_nmem_get(data1_handle dh)66 NMEM data1_nmem_get (data1_handle dh)
67 {
68 return dh->mem;
69 }
70
data1_absyn_cache_get(data1_handle dh)71 data1_absyn_cache *data1_absyn_cache_get (data1_handle dh)
72 {
73 return &dh->absyn_cache;
74 }
75
data1_attset_cache_get(data1_handle dh)76 data1_attset_cache *data1_attset_cache_get (data1_handle dh)
77 {
78 return &dh->attset_cache;
79 }
80
data1_destroy(data1_handle dh)81 void data1_destroy (data1_handle dh)
82 {
83 if (!dh)
84 return;
85
86 /* *ostrich*
87 We need to destroy DFAs, in xp_element (xelm) definitions
88 pop, 2002-12-13
89 */
90 data1_absyn_destroy(dh);
91
92 wrbuf_destroy(dh->wrbuf);
93 if (dh->tab_path)
94 xfree (dh->tab_path);
95 if (dh->tab_root)
96 xfree (dh->tab_root);
97 if (dh->read_buf)
98 xfree (dh->read_buf);
99 if (dh->map_buf)
100 xfree (dh->map_buf);
101 nmem_destroy (dh->mem);
102
103 xfree (dh);
104 }
105
data1_get_wrbuf(data1_handle dp)106 WRBUF data1_get_wrbuf (data1_handle dp)
107 {
108 return dp->wrbuf;
109 }
110
data1_get_read_buf(data1_handle dp,int ** lenp)111 char **data1_get_read_buf (data1_handle dp, int **lenp)
112 {
113 *lenp = &dp->read_len;
114 yaz_log (YLOG_DEBUG, "data1_get_read_buf lenp=%u", **lenp);
115 return &dp->read_buf;
116 }
117
data1_get_map_buf(data1_handle dp,int ** lenp)118 char **data1_get_map_buf (data1_handle dp, int **lenp)
119 {
120 *lenp = &dp->map_len;
121 yaz_log (YLOG_DEBUG, "data1_get_map_buf lenp=%u", **lenp);
122 return &dp->map_buf;
123 }
124
data1_set_tabpath(data1_handle dp,const char * p)125 void data1_set_tabpath (data1_handle dp, const char *p)
126 {
127 xfree (dp->tab_path);
128 dp->tab_path = NULL;
129 if (p)
130 dp->tab_path = xstrdup (p);
131 }
132
data1_set_tabroot(data1_handle dp,const char * p)133 void data1_set_tabroot (data1_handle dp, const char *p)
134 {
135 xfree (dp->tab_root);
136 dp->tab_root = NULL;
137 if (p)
138 dp->tab_root = xstrdup (p);
139 }
140
data1_get_tabpath(data1_handle dp)141 const char *data1_get_tabpath (data1_handle dp)
142 {
143 return dp->tab_path;
144 }
145
data1_get_tabroot(data1_handle dp)146 const char *data1_get_tabroot (data1_handle dp)
147 {
148 return dp->tab_root;
149 }
150
data1_path_fopen(data1_handle dh,const char * file,const char * mode)151 FILE *data1_path_fopen (data1_handle dh, const char *file, const char *mode)
152 {
153 FILE *f;
154 const char *path = data1_get_tabpath(dh);
155 const char *root = data1_get_tabroot(dh);
156
157 yaz_log(YLOG_DEBUG, "data1_path_fopen path=%s root=%s "
158 "file=%s mode=%s", path ? path : "NULL",
159 root ? root : "NULL", file, mode);
160 if (!path || !*path)
161 return 0;
162 f = yaz_fopen(path, file, mode, root);
163 if (!f)
164 {
165 yaz_log(YLOG_WARN|YLOG_ERRNO, "Couldn't open %s", file);
166 if (root)
167 yaz_log(YLOG_LOG, "for root=%s", root);
168 if (path)
169 yaz_log(YLOG_LOG, "for profilePath=%s", path);
170 }
171 return f;
172 }
173
data1_is_xmlmode(data1_handle dh)174 int data1_is_xmlmode(data1_handle dh)
175 {
176 return 1;
177 }
178 /*
179 * Local variables:
180 * c-basic-offset: 4
181 * c-file-style: "Stroustrup"
182 * indent-tabs-mode: nil
183 * End:
184 * vim: shiftwidth=4 tabstop=8 expandtab
185 */
186
187