1 /*
2  * Copyright (C) 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 OHOS_OPERATOR_FILE_PARSER_H
17 #define OHOS_OPERATOR_FILE_PARSER_H
18 #include <mutex>
19 
20 #include "cJSON.h"
21 #include "core_service_errors.h"
22 #include "operator_config_types.h"
23 #include "sim_state_type.h"
24 #include "telephony_log_wrapper.h"
25 
26 namespace OHOS {
27 namespace Telephony {
28 class OperatorFileParser {
29 public:
30     bool ParseFromCustomSystem(int32_t slotId, OperatorConfig &opc, cJSON *root);
31     bool ParseOperatorConfigFromFile(
32         OperatorConfig &poc, const std::string &path, cJSON *root, bool needSaveTempOpc = false);
33     bool WriteOperatorConfigJson(std::string filename, const cJSON *root);
34     std::string GetOperatorConfigFilePath(std::string filename);
35     static void ClearFilesCache();
36     static bool isCachePathExit();
37     virtual ~OperatorFileParser();
38 
39 private:
40     void ParseOperatorConfigFromJson(const cJSON *root, OperatorConfig &poc, bool needSaveTempOpc);
41     int32_t LoaderJsonFile(char *&content, const std::string &path);
42     void CreateJsonFromOperatorConfig(cJSON *root);
43     void ParseArray(const std::string key, const cJSON *value, OperatorConfig &poc);
44     bool CloseFile(FILE *f);
45     static void DeleteFiles();
46     std::map<std::string, std::string> tempConfig_;
47     inline static const char *DEFAULT_OPERATE_CONFIG_PATH = "etc/telephony/operator_config.json";
48     inline static const char *DEFAULT_OPERATE_CONFIG_DIR = "/data/service/el1/public/telephony/operatorconfig";
49     inline static const int MODE_SLOT_0 = 11;
50     inline static const int MODE_SLOT_1 = 12;
51     inline static const int SUCCESS = 0;
52     inline static const int MAX_BYTE_LEN = 10 * 1024 * 1024;
53     inline static const int LOADER_JSON_ERROR = -1;
54     std::mutex mutex_;
55 };
56 } // namespace Telephony
57 } // namespace OHOS
58 #endif // OHOS_OPERATOR_FILE_PARSER_H
59