Debian Codegraph @

cil/src/cil_symtab.h

raw
1 /*
2 * Copyright 2011 Tresys Technology, LLC. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
15 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17 * EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
22 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * The views and conclusions contained in the software and documentation are those
26 * of the authors and should not be interpreted as representing official policies,
27 * either expressed or implied, of Tresys Technology, LLC.
28 */
29
30 #ifndef __CIL_SYMTAB_H_
31 #define __CIL_SYMTAB_H_
32
33 #include <sepol/policydb/symtab.h>
34 #include <sepol/policydb/hashtab.h>
35
36 #include "cil_tree.h"
37
38 struct cil_symtab_datum {
39 struct cil_list *nodes;
40 char *name;
41 char *fqn;
42 symtab_t *symtab;
43 };
44
45 #define DATUM(d) ((struct cil_symtab_datum *)(d))
46 #define NODE(n) ((struct cil_tree_node *)(DATUM(n)->nodes->head->data))
47 #define FLAVOR(f) (NODE(f)->flavor)
48
49 struct cil_complex_symtab_key {
50 intptr_t key1;
51 intptr_t key2;
52 intptr_t key3;
53 intptr_t key4;
54 };
55
56 struct cil_complex_symtab_datum {
57 void *data;
58 };
59
60 struct cil_complex_symtab_node {
61 struct cil_complex_symtab_key *ckey;
62 struct cil_complex_symtab_datum *datum;
63 struct cil_complex_symtab_node *next;
64 };
65
66 struct cil_complex_symtab {
67 struct cil_complex_symtab_node **htable;
68 uint32_t nelems;
69 uint32_t nslots;
70 uint32_t mask;
71 };
72
73 void cil_symtab_init(symtab_t *symtab, unsigned int size);
74 void cil_symtab_datum_init(struct cil_symtab_datum *datum);
75 void cil_symtab_datum_destroy(struct cil_symtab_datum *datum);
76 void cil_symtab_datum_remove_node(struct cil_symtab_datum *datum, struct cil_tree_node *node);
77 int cil_symtab_insert(symtab_t *symtab, hashtab_key_t key, struct cil_symtab_datum *datum, struct cil_tree_node *node);
78 void cil_symtab_remove_datum(struct cil_symtab_datum *datum);
79 int cil_symtab_get_datum(symtab_t *symtab, char *key, struct cil_symtab_datum **datum);
80 int cil_symtab_map(symtab_t *symtab,
81 int (*apply) (hashtab_key_t k, hashtab_datum_t d, void *args),
82 void *args);
83 void cil_symtab_destroy(symtab_t *symtab);
84 void cil_complex_symtab_init(struct cil_complex_symtab *symtab, unsigned int size);
85 int cil_complex_symtab_insert(struct cil_complex_symtab *symtab, struct cil_complex_symtab_key *ckey, struct cil_complex_symtab_datum *datum);
86 void cil_complex_symtab_search(struct cil_complex_symtab *symtab, struct cil_complex_symtab_key *ckey, struct cil_complex_symtab_datum **out);
87 void cil_complex_symtab_destroy(struct cil_complex_symtab *symtab);
88
89 #endif