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