1 /* 2 * Copyright (c) 2021 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 STARTUP_TRIGER_CHECKER_H 17 #define STARTUP_TRIGER_CHECKER_H 18 #include <stdint.h> 19 #include <sys/types.h> 20 21 #ifdef __cplusplus 22 #if __cplusplus 23 extern "C" { 24 #endif 25 #endif 26 27 #define MAX_TRIGGER_CMD_NAME_LEN 32 28 #define MAX_TRIGGER_NAME_LEN 128 29 #define MAX_TRIGGER_TYPE_LEN 16 30 31 #define SUPPORT_DATA_BUFFER_MAX 128 32 #define MAX_DATA_BUFFER_MAX (SUPPORT_DATA_BUFFER_MAX * 5) 33 #define CONDITION_EXTEND_LEN 32 34 35 #define LOGIC_DATA_FLAGS_ORIGINAL 0x1 36 #define LOGIC_DATA_FLAGS_TRUE 0x08 37 38 #define LOGIC_DATA_TEST_FLAG(data, flag) (((data)->flags & flag) == (flag)) 39 #define LOGIC_DATA_SET_FLAG(data, flag) (data)->flags |= (flag) 40 #define LOGIC_DATA_CLEAR_FLAG(data, flag) (data)->flags &= ~(flag) 41 42 typedef struct { 43 uint32_t flags; 44 uint32_t startIndex; 45 uint32_t endIndex; 46 } LogicData; 47 48 struct tagTriggerNode_; 49 typedef int (*PARAM_CHECK_DONE)(struct tagTriggerNode_ *trigger, const char *content, uint32_t size); 50 typedef struct { 51 char triggerContent[MAX_TRIGGER_NAME_LEN]; 52 PARAM_CHECK_DONE triggerCheckDone; 53 int dataNumber; 54 int endIndex; 55 int dataUnit; 56 char *conditionName; 57 char *conditionContent; 58 char *inputName; 59 char *inputContent; 60 char *readContent; 61 char *data; 62 } LogicCalculator; 63 64 int CalculatorInit(LogicCalculator *calculator, int dataNumber, int dataUnit, int needCondition); 65 void CalculatorFree(LogicCalculator *calculator); 66 int ConvertInfixToPrefix(const char *condition, char *prefix, uint32_t prefixLen); 67 int ComputeCondition(LogicCalculator *calculator, const char *condition); 68 int GetValueFromContent(const char *content, uint32_t contentSize, uint32_t start, char *value, uint32_t valueSize); 69 int CheckMatchSubCondition(const char *condition, const char *input, int length); 70 71 #ifdef __cplusplus 72 #if __cplusplus 73 } 74 #endif 75 #endif 76 #endif // STARTUP_TRIGER_CHECKER_H