1 /* 2 * Copyright (c) 2023 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 16 #ifndef BASE_STARTUP_PARAM_TRIE_H 17 #define BASE_STARTUP_PARAM_TRIE_H 18 #include <stdio.h> 19 20 #include "init_hashmap.h" 21 #include "init_param.h" 22 #include "list.h" 23 #include "param_common.h" 24 #include "param_osadp.h" 25 #include "param_security.h" 26 27 #ifdef __cplusplus 28 #if __cplusplus 29 extern "C" { 30 #endif 31 #endif 32 33 INIT_LOCAL_API int InitWorkSpace(WorkSpace *workSpace, int onlyRead, uint32_t spaceSize); 34 INIT_LOCAL_API void CloseWorkSpace(WorkSpace *workSpace); 35 36 #define GetTrieNode(workSpace, offset) (ParamTrieNode *)(((offset) == 0 || (offset) > (workSpace)->area->dataSize) ? \ 37 NULL : (workSpace)->area->data + (offset)) 38 39 #define GetTrieRoot(workSpace) \ 40 (ParamTrieNode *)(((workSpace)->area == NULL) ? NULL : (workSpace)->area->data + (workSpace)->area->firstNode) 41 42 INIT_LOCAL_API void SaveIndex(uint32_t *index, uint32_t offset); 43 44 INIT_LOCAL_API ParamTrieNode *AddTrieNode(WorkSpace *workSpace, const char *key, uint32_t keyLen); 45 INIT_LOCAL_API ParamTrieNode *FindTrieNode( 46 WorkSpace *workSpace, const char *key, uint32_t keyLen, uint32_t *matchLabel); 47 48 typedef int (*TraversalTrieNodePtr)(const WorkSpace *workSpace, const ParamTrieNode *node, const void *cookie); 49 INIT_LOCAL_API int TraversalTrieNode(const WorkSpace *workSpace, 50 const ParamTrieNode *subTrie, TraversalTrieNodePtr walkFunc, const void *cookie); 51 52 INIT_LOCAL_API uint32_t AddParamSecurityNode(WorkSpace *workSpace, const ParamAuditData *auditData); 53 INIT_LOCAL_API uint32_t AddParamNode(WorkSpace *workSpace, uint8_t type, 54 const char *key, uint32_t keyLen, const char *value, uint32_t valueLen); 55 56 INIT_LOCAL_API uint32_t GetParamMaxLen(uint8_t type); 57 INIT_LOCAL_API ParamNode *GetParamNode(uint32_t index, const char *name); 58 INIT_LOCAL_API int AddParamEntry(uint32_t index, uint8_t type, const char *name, const char *value); 59 60 #ifdef STARTUP_INIT_TEST 61 STATIC_INLINE ParamTrieNode *FindTrieNode_( 62 const WorkSpace *workSpace, const char *key, uint32_t keyLen, uint32_t *matchLabel); 63 #endif 64 #ifdef __cplusplus 65 #if __cplusplus 66 } 67 #endif 68 #endif 69 #endif // BASE_STARTUP_PARAM_TRIE_H