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 56 public: 57 inline static const int MODE_SLOT_0 = 11; 58 inline static const int MODE_SLOT_1 = 12; 59 enum class RuleID { 60 RULE_EMPTY = 0x0, 61 RULE_MCCMNC = 0x1, 62 RULE_ICCID = 0x2, 63 RULE_IMSI = 0x4, 64 RULE_SPN = 0x8, 65 RULE_GID1 = 0x10, 66 RULE_GID2 = 0x20, 67 }; 68 69 private: 70 int32_t ParseInt(const cJSON *value); 71 std::string ParseString(const cJSON *value); 72 std::string ParseAsString(const cJSON *value); 73 int LoaderJsonFile(char *&content, const char *path) const; 74 int CloseFile(FILE *f) const; 75 int GetRuleId(OpKey &bean); 76 std::string GetCustFile(const char *&file, const char *key); 77 bool IsNeedInsertToTable(cJSON *value); 78 bool IsDigestChanged(const char *path, const std::string &key); 79 }; 80 } // namespace Telephony 81 } // namespace OHOS 82 #endif // DATA_STORAGE_PDP_OPERATOR_PARSER_UTIL_H 83