• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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              256  // max length of a filepath
27 
28 // follow X(carrier/network/PLMN/...) usage
29 // 1. etc/cust/followx_file_list.cfg can be in any layer, except follow x dir
30 // 2. file format:
31 //    1)line begin with '#' is comment
32 //    2)every line is a item, item begin with "follow_rule," is a follow rule
33 //    3)follow rule item has 3~4 segs, every segs split by ',', as below
34 //      follow_rule,relPath,follow_mode,follow_rule_add_path
35 //      >> if follow mode is USER_DEFINE, the next segs is a user defined follow rule
36 //      >> the follow_rule_add_path can contains param variant
37 // 3. if a relPath has multi follow rules, use the highest priority rule
38 // LIMIT: the max size of concatenated all follow rule is PARAM_CONST_VALUE_LEN_MAX(4096)
39 // example:
40 //    follow_rule,etc/xml/config.xml,10
41 //    follow_rule,etc/xml/config1.xml,100,etc/carrier2/${keyname}
42 //    follow_rule,etc/xml/config2.xml,100,etc/carrier/${keyname:-value}
43 // Follow rule in followx_file_list.cfg, which stored in param variant
44 #define FOLLOWX_MODE_DEFAULT      0
45 // Not use any follow rule, even exist followx_file_list.cfg
46 #define FOLLOWX_MODE_NO_RULE_FOLLOWED    1
47 // Follow rule by default slot
48 #define FOLLOWX_MODE_SIM_DEFAULT  10
49 // Follow rule by slot 1
50 #define FOLLOWX_MODE_SIM_1        11
51 // Follow rule by slot 2
52 #define FOLLOWX_MODE_SIM_2        12
53 // User defined follow rule, get follow_rule_add_path from @param extra
54 // Notice: Follow rule in followx_file_list.cfg will be ignored.
55 #define FOLLOWX_MODE_USER_DEFINED  100
56 
57 // Config Files
58 struct CfgFiles {
59     char *paths[MAX_CFG_POLICY_DIRS_CNT];
60 };
61 
62 // Config Directories
63 struct CfgDir {
64     char *paths[MAX_CFG_POLICY_DIRS_CNT];
65     char *realPolicyValue;
66 };
67 
68 typedef struct CfgFiles CfgFiles;
69 typedef struct CfgDir CfgDir;
70 
71 // free struct CfgFiles allocated by GetCfgFiles()
72 void FreeCfgFiles(CfgFiles *res);
73 
74 // free struct CfgDir allocated by GetCfgDirList()
75 void FreeCfgDirList(CfgDir *res);
76 
77 // get the highest priority config file
78 // pathSuffixStr: the relative path of the config file, e.g. "etc/xml/config.xml"
79 // buf: recommended buffer length is MAX_PATH_LEN
80 // followMode: 0/1/10/11/12/100, see FOLLOWX_MODE_*
81 // extra: User defined follow rule, get follow_rule_add_path
82 // return: path of the highest priority config file, return NULL when such a file is not found
83 char *GetOneCfgFileEx(const char *pathSuffix, char *buf, unsigned int bufLength, int followMode, const char *extra);
84 
85 // get the highest priority config file
86 // pathSuffixStr: the relative path of the config file, e.g. "etc/xml/config.xml"
87 // buf: recommended buffer length is MAX_PATH_LEN
88 // return: path of the highest priority config file, return NULL when such a file is not found
89 char *GetOneCfgFile(const char *pathSuffix, char *buf, unsigned int bufLength);
90 
91 // get config files, ordered by priority from low to high
92 // pathSuffixStr: the relative path of the config file, e.g. "etc/xml/config.xml"
93 // return: paths of config files
94 // CAUTION: please use FreeCfgFiles() to avoid memory leak.
95 CfgFiles *GetCfgFiles(const char *pathSuffix);
96 
97 // get config files, ordered by priority from low to high
98 // pathSuffixStr: the relative path of the config file, e.g. "etc/xml/config.xml"
99 // followMode: 0/1/10/11/12/100, see FOLLOWX_MODE_*
100 // extra: User defined follow rule, get follow_rule_add_path
101 // return: paths of config files
102 // CAUTION: please use FreeCfgFiles() to avoid memory leak.
103 CfgFiles *GetCfgFilesEx(const char *pathSuffix, int followMode, const char *extra);
104 
105 // get config directories, ordered by priority from low to high
106 // return: paths of config directories
107 // CAUTION: please use FreeCfgDirList() to avoid memory leak.
108 CfgDir *GetCfgDirList(void);
109 
110 #ifdef __cplusplus
111 #if __cplusplus
112 }
113 #endif
114 #endif // __cplusplus
115 
116 #endif // CUSTOMIZATION_CONFIG_POLICY_UTILS_H
117