Debian Codegraph @

src/OVAL/probes/SEAP/sexp-datatype.c

raw symbols SCIP
1 /*
2 * Copyright 2009 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Authors:
20 * "Daniel Kopecek" <[email protected]>
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <string.h>
28 #include <errno.h>
29
30 #include "_sexp-datatype.h"
31 #include "_sexp-rawptr.h"
32
33 #if defined(SEAP_THREAD_SAFE)
34 # include<pthread.h>
35 static pthread_once_t __SEXP_datatype_once = PTHREAD_ONCE_INIT;
36 #endif
37
38 SEXP_datatypeTbl_t g_datatypes = { NULL };
39
40 SEXP_datatypeTbl_t *SEXP_datatypeTbl_new ()
41 {
42 SEXP_datatypeTbl_t *t = malloc(sizeof(SEXP_datatypeTbl_t));
43 SEXP_datatypeTbl_init(t);
44
45 return(t);
46 }
47
48 void SEXP_datatypeTbl_free(SEXP_datatypeTbl_t *t)
49 {
50 rbt_str_free(t->tree);
51 free(t);
52 return;
53 }
54
55 int SEXP_datatypeTbl_init (SEXP_datatypeTbl_t *t)
56 {
57 if (t == NULL) {
58 return -1;
59 }
60 t->tree = rbt_str_new();
61 return(0);
62 }
63
64 void SEXP_datatype_once(void)
65 {
66 #if defined(SEAP_THREAD_SAFE)
67 if (pthread_once (&__SEXP_datatype_once, &SEXP_datatypeGlobalTbl_init) != 0)
68 abort ();
69 #else
70 SEXP_datatypeGlobalTbl_init();
71 #endif
72 return;
73 }
74
75 void SEXP_datatypeGlobalTbl_init(void)
76 {
77 if (g_datatypes.tree == NULL) {
78 SEXP_datatypeTbl_init(&g_datatypes);
79 atexit(&SEXP_datatypeGlobalTbl_free);
80 }
81 }
82
83 void SEXP_datatypeGlobalTbl_free(void)
84 {
85 if (g_datatypes.tree != NULL) {
86 rbt_str_free(g_datatypes.tree);
87 }
88 }
89
90 SEXP_datatypePtr_t *SEXP_datatype_get (SEXP_datatypeTbl_t *t, const char *k)
91 {
92 struct rbt_str_node *n = NULL;
93
94 if (t == NULL || k == NULL) {
95 return NULL;
96 }
97
98 SEXP_datatype_once();
99
100 if (rbt_str_getnode(t->tree, k, &n) != 0)
101 return(NULL);
102
103 return((SEXP_datatypePtr_t *)n);
104 }
105
106 SEXP_datatypePtr_t *SEXP_datatype_add(SEXP_datatypeTbl_t *t, char *n)
107 {
108 void *r;
109 struct rbt_str_node *node = NULL;
110
111 if (t == NULL || n == NULL) {
112 return NULL;
113 }
114
115 SEXP_datatype_once();
116
117 if (rbt_str_add(t->tree, n, NULL) != 0)
118 return(NULL);
119 /*
120 * XXX: consider adding a version of rbt_str_add that returns
121 * the node pointer, so that we don't have perform the
122 * following search operation.
123 */
124 if (rbt_str_getnode(t->tree, n, &node) != 0)
125 return(NULL);
126
127 r = node;
128
129 return((SEXP_datatypePtr_t *)r);
130 }
131
132 int SEXP_datatype_del (SEXP_datatypeTbl_t *t, const char *name)
133 {
134 errno = EOPNOTSUPP;
135 return (-1);
136 }
137
138 const char *SEXP_datatype_name(SEXP_datatypePtr_t *p)
139 {
140 char *name = NULL;
141
142 if (SEXP_rawptr_bit(p, 0)) {
143 SEXP_datatypeExtptr_t *ep = SEXP_rawptr_maskT(SEXP_datatypeExtptr_t, p, SEXP_DATATYPEPTR_MASK);
144 name = ep->n->key;
145 } else {
146 struct rbt_str_node *node = SEXP_rawptr_maskT(struct rbt_str_node, p, SEXP_DATATYPEPTR_MASK);
147 name = node->key;
148 }
149
150 return(name);
151 }
152
153 SEXP_datatype_t *SEXP_datatype_new(void)
154 {
155 SEXP_datatype_t *d = malloc(sizeof(SEXP_datatype_t));
156 d->dt_flg = 0;
157
158 return(d);
159 }
160
161 int SEXP_datatype_setflag(SEXP_datatype_t **dp, uint16_t flag, ...)
162 {
163 if (dp == NULL || *dp == NULL) {
164 errno = EFAULT;
165 return -1;
166 }
167
168 switch(flag) {
169 case SEXP_DTFLG_LOCALDATA:
170 break;
171 case SEXP_DTFLG_HAVEDTOPS:
172 break;
173 }
174
175 errno = EINVAL;
176 return(-1);
177 }
178
179 int SEXP_datatype_unsetflag(SEXP_datatype_t **dp, uint16_t flag)
180 {
181 if (dp == NULL || *dp == NULL) {
182 errno = EFAULT;
183 return -1;
184 }
185
186 switch(flag) {
187 case SEXP_DTFLG_LOCALDATA:
188 break;
189 case SEXP_DTFLG_HAVEDTOPS:
190 break;
191 }
192
193 errno = EINVAL;
194 return(-1);
195 }
196
197 int SEXP_datatype_addop(SEXP_datatype_t **dp, int opnum, SEXP_datatypeOP_t *op)
198 {
199 return(-1);
200 }
201
202 int SEXP_datatype_delop(SEXP_datatype_t **dp, int opnum)
203 {
204 return(-1);
205 }