Fixed data1_gettagbyname. Bug introduced by previous revision.
[yaz-moved-to-github.git] / retrieval / d1_handle.c
1 /*
2  * Copyright (c) 1995-1997, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: d1_handle.c,v $
7  * Revision 1.4  1998-05-18 13:07:05  adam
8  * Changed the way attribute sets are handled by the retriaval module.
9  * Extended Explain conversion / schema.
10  * Modified server and client to work with ASN.1 compiled protocol handlers.
11  *
12  * Revision 1.3  1998/02/11 11:53:35  adam
13  * Changed code so that it compiles as C++.
14  *
15  * Revision 1.2  1997/09/30 11:50:04  adam
16  * Added handler data1_get_map_buf that is used by data1_nodetomarc.
17  *
18  * Revision 1.1  1997/09/17 12:28:24  adam
19  * Introduced new 'global' data1 handle.
20  *
21  */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25
26 #include <log.h>
27 #include <data1.h>
28
29 struct data1_handle_info {
30     WRBUF wrbuf;
31     char *tab_path;
32
33     char *read_buf;
34     int read_len;
35
36     data1_absyn_cache absyn_cache;
37     data1_attset_cache attset_cache;
38
39     char *map_buf;
40     int map_len;
41
42     NMEM mem;
43 };
44
45 data1_handle data1_create (void)
46 {
47     data1_handle p = (data1_handle)xmalloc (sizeof(*p));
48     if (!p)
49         return NULL;
50     p->tab_path = NULL;
51     p->wrbuf = wrbuf_alloc();
52     p->read_buf = NULL;
53     p->read_len = 0;
54     p->map_buf = NULL;
55     p->map_len = 0;
56     p->absyn_cache = NULL;
57     p->attset_cache = NULL;
58     p->mem = nmem_create ();
59     return p;
60 }
61
62 NMEM data1_nmem_get (data1_handle dh)
63 {
64     return dh->mem;
65 }
66
67 data1_absyn_cache *data1_absyn_cache_get (data1_handle dh)
68 {
69     return &dh->absyn_cache;
70 }
71
72 data1_attset_cache *data1_attset_cache_get (data1_handle dh)
73 {
74     return &dh->attset_cache;
75 }
76
77 void data1_destroy (data1_handle dh)
78 {
79     if (!dh)
80         return;
81     wrbuf_free (dh->wrbuf, 1);
82     if (dh->tab_path)
83         xfree (dh->tab_path);
84     if (dh->read_buf)
85         xfree (dh->read_buf);
86     if (dh->map_buf)
87         xfree (dh->map_buf);
88     nmem_destroy (dh->mem);
89     
90     xfree (dh);
91 }
92
93 WRBUF data1_get_wrbuf (data1_handle dp)
94 {
95     return dp->wrbuf;
96 }
97
98 char **data1_get_read_buf (data1_handle dp, int **lenp)
99 {
100     *lenp = &dp->read_len;
101     logf (LOG_DEBUG, "data1_get_read_buf lenp=%u", **lenp);
102     return &dp->read_buf;
103 }
104
105 char **data1_get_map_buf (data1_handle dp, int **lenp)
106 {
107     *lenp = &dp->map_len;
108     logf (LOG_DEBUG, "data1_get_map_buf lenp=%u", **lenp);
109     return &dp->map_buf;
110 }
111
112 void data1_set_tabpath (data1_handle dp, const char *p)
113 {
114     if (dp->tab_path)
115     {
116         xfree (dp->tab_path);
117         dp->tab_path = NULL;
118     }
119     if (p)
120     {
121         dp->tab_path = (char *)xmalloc (strlen(p)+1);
122         strcpy (dp->tab_path, p);
123     }
124 }
125
126 const char *data1_get_tabpath (data1_handle dp)
127 {
128     return dp->tab_path;
129 }
130