1 /* 2 * Copyright (c) 2021-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 16 #ifndef CUSTOMIZATION_CONFIG_POLICY_UTILS_H 17 #define CUSTOMIZATION_CONFIG_POLICY_UTILS_H 18 19 #ifdef __cplusplus 20 #if __cplusplus 21 extern "C" { 22 #endif 23 #endif // __cplusplus 24 25 #define MAX_CFG_POLICY_DIRS_CNT 32 // max number of directories 26 #define MAX_PATH_LEN 128 // max length of a filepath 27 28 // Config Files 29 struct CfgFiles { 30 char *paths[MAX_CFG_POLICY_DIRS_CNT]; 31 }; 32 33 // Config Directories 34 struct CfgDir { 35 char *paths[MAX_CFG_POLICY_DIRS_CNT]; 36 char *realPolicyValue; 37 }; 38 39 typedef struct CfgFiles CfgFiles; 40 typedef struct CfgDir CfgDir; 41 42 // free struct CfgFiles allocated by GetCfgFiles() 43 void FreeCfgFiles(CfgFiles *res); 44 45 // free struct CfgDir allocated by GetCfgDirList() 46 void FreeCfgDirList(CfgDir *res); 47 48 // get the highest priority config file 49 // pathSuffixStr: the relative path of the config file, e.g. "etc/xml/config.xml" 50 // buf: recommended buffer length is MAX_PATH_LEN 51 // return: path of the highest priority config file, return '\0' when such a file is not found 52 char *GetOneCfgFile(const char *pathSuffix, char *buf, unsigned int bufLength); 53 54 // get config files, ordered by priority from low to high 55 // pathSuffixStr: the relative path of the config file, e.g. "etc/xml/config.xml" 56 // return: paths of config files 57 // CAUTION: please use FreeCfgFiles() to avoid memory leak. 58 CfgFiles *GetCfgFiles(const char *pathSuffix); 59 60 // get config directories, ordered by priority from low to high 61 // return: paths of config directories 62 // CAUTION: please use FreeCfgDirList() to avoid memory leak. 63 CfgDir *GetCfgDirList(void); 64 65 #ifdef __cplusplus 66 #if __cplusplus 67 } 68 #endif 69 #endif // __cplusplus 70 71 #endif // CUSTOMIZATION_CONFIG_POLICY_UTILS_H 72