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 #define PARAM_TRIE_STACK_SIZE 25 34 35 INIT_LOCAL_API int InitWorkSpace(WorkSpace *workSpace, int onlyRead, uint32_t spaceSize); 36 INIT_LOCAL_API void CloseWorkSpace(WorkSpace *workSpace); 37 38 #define GetTrieNode(workSpace, offset) (ParamTrieNode *)(((offset) == 0 || (offset) > (workSpace)->area->dataSize) ? \ 39 NULL : (workSpace)->area->data + (offset)) 40 41 #define GetTrieRoot(workSpace) \ 42 (ParamTrieNode *)(((workSpace)->area == NULL) ? NULL : (workSpace)->area->data + (workSpace)->area->firstNode) 43 44 INIT_LOCAL_API void SaveIndex(uint32_t *index, uint32_t offset); 45 46 INIT_LOCAL_API ParamTrieNode *AddTrieNode(WorkSpace *workSpace, const char *key, uint32_t keyLen); 47 INIT_LOCAL_API ParamTrieNode *FindTrieNode( 48 WorkSpace *workSpace, const char *key, uint32_t keyLen, uint32_t *matchLabel); 49 50 typedef int (*TraversalTrieNodePtr)(const WorkSpace *workSpace, const ParamTrieNode *node, const void *cookie); 51 INIT_LOCAL_API int TraversalTrieNode(const WorkSpace *workSpace, 52 const ParamTrieNode *subTrie, TraversalTrieNodePtr walkFunc, const void *cookie); 53 54 INIT_LOCAL_API uint32_t AddParamSecurityNode(WorkSpace *workSpace, const ParamAuditData *auditData); 55 INIT_LOCAL_API uint32_t AddParamNode(WorkSpace *workSpace, uint8_t type, 56 const char *key, uint32_t keyLen, const char *value, uint32_t valueLen); 57 58 INIT_LOCAL_API uint32_t GetParamMaxLen(uint8_t type); 59 INIT_LOCAL_API ParamNode *GetParamNode(uint32_t index, const char *name); 60 INIT_LOCAL_API int AddParamEntry(uint32_t index, uint8_t type, const char *name, const char *value); 61 62 #ifdef STARTUP_INIT_TEST 63 STATIC_INLINE ParamTrieNode *FindTrieNode_( 64 const WorkSpace *workSpace, const char *key, uint32_t keyLen, uint32_t *matchLabel); 65 #endif 66 67 #define GetWorkSpaceSize(workSpace) \ 68 ((workSpace == NULL) || (workSpace->area == NULL) || \ 69 (workSpace->area->spaceSizeOffset == 0) || \ 70 (workSpace->area->spaceSizeOffset >= workSpace->area->dataSize)) ? NULL : \ 71 (WorkSpaceSize*)(workSpace->area->data + workSpace->area->spaceSizeOffset) 72 73 #ifdef __cplusplus 74 #if __cplusplus 75 } 76 #endif 77 #endif 78 #endif // BASE_STARTUP_PARAM_TRIE_H