IDZEBRA  2.2.7
d1_handle.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 #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 
32  WRBUF wrbuf;
33  char *tab_path;
34  char *tab_root;
35 
36  char *read_buf;
37  int read_len;
38 
41 
42  char *map_buf;
43  int map_len;
44 
45  NMEM mem;
46 };
47 
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 
67 {
68  return dh->mem;
69 }
70 
72 {
73  return &dh->absyn_cache;
74 }
75 
77 {
78  return &dh->attset_cache;
79 }
80 
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  */
91 
92  wrbuf_destroy(dh->wrbuf);
93  xfree(dh->tab_path);
94  xfree(dh->tab_root);
95  xfree(dh->read_buf);
96  xfree(dh->map_buf);
97  nmem_destroy(dh->mem);
98 
99  xfree(dh);
100 }
101 
103 {
104  return dp->wrbuf;
105 }
106 
107 char **data1_get_read_buf(data1_handle dp, int **lenp)
108 {
109  *lenp = &dp->read_len;
110  yaz_log(YLOG_DEBUG, "data1_get_read_buf lenp=%u", **lenp);
111  return &dp->read_buf;
112 }
113 
114 char **data1_get_map_buf(data1_handle dp, int **lenp)
115 {
116  *lenp = &dp->map_len;
117  yaz_log(YLOG_DEBUG, "data1_get_map_buf lenp=%u", **lenp);
118  return &dp->map_buf;
119 }
120 
121 void data1_set_tabpath(data1_handle dp, const char *p)
122 {
123  xfree(dp->tab_path);
124  dp->tab_path = NULL;
125  if (p)
126  dp->tab_path = xstrdup (p);
127 }
128 
129 void data1_set_tabroot(data1_handle dp, const char *p)
130 {
131  xfree(dp->tab_root);
132  dp->tab_root = NULL;
133  if (p)
134  dp->tab_root = xstrdup(p);
135 }
136 
138 {
139  return dp->tab_path;
140 }
141 
143 {
144  return dp->tab_root;
145 }
146 
147 FILE *data1_path_fopen(data1_handle dh, const char *file, const char *mode)
148 {
149  FILE *f;
150  const char *path = data1_get_tabpath(dh);
151  const char *root = data1_get_tabroot(dh);
152 
153  yaz_log(YLOG_DEBUG, "data1_path_fopen path=%s root=%s "
154  "file=%s mode=%s", path ? path : "NULL",
155  root ? root : "NULL", file, mode);
156  if (!path || !*path)
157  return 0;
158  f = yaz_fopen(path, file, mode, root);
159  if (!f)
160  {
161  yaz_log(YLOG_WARN|YLOG_ERRNO, "Couldn't open %s", file);
162  if (root)
163  yaz_log(YLOG_LOG, "for root=%s", root);
164  if (path)
165  yaz_log(YLOG_LOG, "for profilePath=%s", path);
166  }
167  return f;
168 }
169 
171 {
172  return 1;
173 }
174 /*
175  * Local variables:
176  * c-basic-offset: 4
177  * c-file-style: "Stroustrup"
178  * indent-tabs-mode: nil
179  * End:
180  * vim: shiftwidth=4 tabstop=8 expandtab
181  */
182 
void data1_set_tabroot(data1_handle dp, const char *p)
Definition: d1_handle.c:129
char ** data1_get_map_buf(data1_handle dp, int **lenp)
Definition: d1_handle.c:114
WRBUF data1_get_wrbuf(data1_handle dp)
Definition: d1_handle.c:102
data1_attset_cache * data1_attset_cache_get(data1_handle dh)
Definition: d1_handle.c:76
data1_handle data1_create(void)
Definition: d1_handle.c:48
const char * data1_get_tabroot(data1_handle dp)
Definition: d1_handle.c:142
FILE * data1_path_fopen(data1_handle dh, const char *file, const char *mode)
Definition: d1_handle.c:147
void data1_destroy(data1_handle dh)
Definition: d1_handle.c:81
NMEM data1_nmem_get(data1_handle dh)
Definition: d1_handle.c:66
char ** data1_get_read_buf(data1_handle dp, int **lenp)
Definition: d1_handle.c:107
void data1_set_tabpath(data1_handle dp, const char *p)
Definition: d1_handle.c:121
const char * data1_get_tabpath(data1_handle dp)
Definition: d1_handle.c:137
data1_absyn_cache * data1_absyn_cache_get(data1_handle dh)
Definition: d1_handle.c:71
int data1_is_xmlmode(data1_handle dh)
Definition: d1_handle.c:170
void data1_absyn_destroy(data1_handle dh)
Definition: d1_absyn.c:177
struct data1_handle_info * data1_handle
Definition: data1.h:77
data1_absyn_cache absyn_cache
Definition: d1_handle.c:39
data1_attset_cache attset_cache
Definition: d1_handle.c:40