• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef SELINUX_MAP
16 #define SELINUX_MAP
17 
18 #pragma once
19 
20 #include <stddef.h>
21 #include <stdint.h>
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif // __cplusplus
28 
29 typedef struct HashNode {
30     struct HashNode *next;
31 } HashNode;
32 
33 typedef struct {
34     HashNode *buckets[0];
35 } HashTab;
36 
37 typedef struct {
38     const char *prefixLabel;
39     const char *matchLabel;
40     uint32_t labeled;
41     int32_t index;
42     HashTab *handle;
43 } ParamContextsTrie;
44 
45 #define PREFIX_LABELED (1)
46 #define MATCH_LABELED (2)
47 #define UNLABELED (0)
48 
49 typedef struct ParamHashNode {
50     HashNode hashNode;
51     ParamContextsTrie *childPtr;
52     uint32_t nameLen;
53     char* name;
54 } ParamHashNode;
55 
56 #define HASHMAP_ENTRY(ptr, type, member) ((type *)((char *)(ptr)-offsetof(type, member)))
57 
58 int32_t HashMapCreate(HashTab **handle);
59 void HashMapDestroy(HashTab *handle);
60 int32_t HashMapAdd(HashTab *handle, HashNode *hashNode);
61 HashNode *HashMapGet(HashTab *handle, const char *key, uint32_t len);
62 #ifdef __cplusplus
63 #if __cplusplus
64 }
65 #endif
66 #endif // __cplusplus
67 #endif