• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 DATA_STORAGE_PDP_OPERATOR_PARSER_UTIL_H
17 #define DATA_STORAGE_PDP_OPERATOR_PARSER_UTIL_H
18 
19 #include "cJSON.h"
20 #include "iosfwd"
21 #include "rdb_store.h"
22 #include "string"
23 
24 namespace OHOS {
25 namespace NativeRdb {
26 class ValuesBucket;
27 }
28 namespace Telephony {
29 struct OpKey;
30 struct PdpProfile;
31 struct NumMatch;
32 struct EccNum;
33 const std::string ECC_DATA_HASH = "ecc_data_hash";
34 const std::string NUM_MATCH_HASH = "num_match_hash";
35 class ParserUtil {
36 public:
37     int GetPdpProfilePath(int slotId, std::string &path);
38     int GetFileChecksum(const char *path, std::string &checkSum);
39     int ParserPdpProfileJson(std::vector<PdpProfile> &vec);
40     int ParserPdpProfileJson(std::vector<PdpProfile> &vec, const char *filePath);
41     void ParserPdpProfileInfos(std::vector<PdpProfile> &vec, cJSON *itemRoots);
42     void ParserPdpProfileToValuesBucket(NativeRdb::ValuesBucket &value, const PdpProfile &bean);
43     int GetOpKeyFilePath(std::string &path);
44     int ParserOpKeyJson(std::vector<OpKey> &vec, const char *path);
45     void ParserOpKeyInfos(std::vector<OpKey> &vec, cJSON *itemRoots);
46     void ParserOpKeyToValuesBucket(NativeRdb::ValuesBucket &value, const OpKey &bean);
47     int ParserNumMatchJson(std::vector<NumMatch> &vec, const bool hashCheck);
48     void ParserNumMatchInfos(std::vector<NumMatch> &vec, cJSON *itemRoots);
49     void ParserNumMatchToValuesBucket(NativeRdb::ValuesBucket &value, const NumMatch &bean);
50     int ParserEccDataJson(std::vector<EccNum> &vec, const bool hashCheck);
51     void ParserEccDataInfos(std::vector<EccNum> &vec, cJSON *itemRoots);
52     void ParserEccDataToValuesBucket(NativeRdb::ValuesBucket &value, const EccNum &bean);
53     void RefreshDigest(const std::string &key);
54     void ClearTempDigest(const std::string &key);
55     bool GetJsonItemStringVaule(const std::string &path, const std::string &rootName, const std::string &key,
56         std::string &resultValue);
57 
58 public:
59     inline static const int MODE_SLOT_0 = 11;
60     inline static const int MODE_SLOT_1 = 12;
61     enum class RuleID {
62         RULE_EMPTY = 0x0,
63         RULE_MCCMNC = 0x1,
64         RULE_ICCID = 0x2,
65         RULE_IMSI = 0x4,
66         RULE_SPN = 0x8,
67         RULE_GID1 = 0x10,
68         RULE_GID2 = 0x20,
69     };
70 
71 private:
72     int32_t ParseInt(const cJSON *value);
73     std::string ParseString(const cJSON *value);
74     std::string ParseAsString(const cJSON *value);
75     int LoaderJsonFile(char *&content, const char *path) const;
76     int CloseFile(FILE *f) const;
77     int GetRuleId(OpKey &bean);
78     std::string GetCustFile(const char *&file, const char *key);
79     bool IsNeedInsertToTable(cJSON *value);
80     bool IsDigestChanged(const char *path, const std::string &key);
81 };
82 } // namespace Telephony
83 } // namespace OHOS
84 #endif // DATA_STORAGE_PDP_OPERATOR_PARSER_UTIL_H
85