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