diff --git a/common/include/dinput_errcode.h b/common/include/dinput_errcode.h index 78f91f43e8f925da099e0785d785e68f09413fa7..bb93ecb25b87f6a0b030e656551300cb8a2077fe 100644 --- a/common/include/dinput_errcode.h +++ b/common/include/dinput_errcode.h @@ -44,6 +44,7 @@ namespace DistributedInput { // whilte list error code constexpr int32_t ERR_DH_INPUT_WHILTELIST_INIT_FAIL = -61001; constexpr int32_t ERR_DH_INPUT_WHILTELIST_GET_WHILTELIST_FAIL = -61002; + constexpr int32_t ERR_DH_INPUT_WHILTELIST_FILE_PATH_IS_NULL = -61003; // handler error code constexpr int32_t ERR_DH_INPUT_HANDLER_GET_DEVICE_ID_FAIL = -63000; diff --git a/common/include/white_list_util.cpp b/common/include/white_list_util.cpp index 3066906a78adc9d34943cb14c9255fbe1e2c6299..f718615d1ccf48df93288d250f62fa49f43938f6 100644 --- a/common/include/white_list_util.cpp +++ b/common/include/white_list_util.cpp @@ -65,6 +65,10 @@ int32_t WhiteListUtil::Init() { char buf[MAX_PATH_LEN] = {0}; char *whiteListFilePath = GetOneCfgFile(WHITELIST_FILE_PATH, buf, MAX_PATH_LEN); + if (whiteListFilePath == nullptr) { + DHLOGE("WhiteListFilePath is null!"); + return ERR_DH_INPUT_WHILTELIST_FILE_PATH_IS_NULL; + } std::ifstream inFile(whiteListFilePath, std::ios::in | std::ios::binary); if (!inFile.is_open()) { DHLOGE("WhiteListUtil Init error, file open fail path=%s", whiteListFilePath); @@ -83,15 +87,7 @@ int32_t WhiteListUtil::Init() } vecKeyCode.clear(); vecCombinationKey.clear(); - - std::size_t pos1 = line.find(SPLIT_COMMA); - while (pos1 != std::string::npos) { - std::string column = line.substr(0, pos1); - line = line.substr(pos1 + 1, line.size()); - pos1 = line.find(SPLIT_COMMA); - vecKeyCode.clear(); - ReadLineDataStepOne(column, vecKeyCode, vecCombinationKey); - } + SplitCombinationKey(line, vecKeyCode, vecCombinationKey); if (CheckIsNumber(line)) { int32_t keyCode = std::stoi(line); @@ -179,6 +175,19 @@ void WhiteListUtil::ReadLineDataStepOne(std::string &column, TYPE_KEY_CODE_VEC & } } +void WhiteListUtil::SplitCombinationKey(std::string &line, TYPE_KEY_CODE_VEC &vecKeyCode, + TYPE_COMBINATION_KEY_VEC &vecCombinationKey) const +{ + std::size_t pos1 = line.find(SPLIT_COMMA); + while (pos1 != std::string::npos) { + std::string column = line.substr(0, pos1); + line = line.substr(pos1 + 1, line.size()); + pos1 = line.find(SPLIT_COMMA); + vecKeyCode.clear(); + ReadLineDataStepOne(column, vecKeyCode, vecCombinationKey); + } +} + int32_t WhiteListUtil::SyncWhiteList(const std::string &deviceId, const TYPE_WHITE_LIST_VEC &vecWhiteList) { DHLOGI("deviceId=%s", GetAnonyString(deviceId).c_str()); diff --git a/common/include/white_list_util.h b/common/include/white_list_util.h index 73724e45a631624e32ad9ca70ca70b82756b2836..f184737d64d1afc68797a176cda094d00299e777 100644 --- a/common/include/white_list_util.h +++ b/common/include/white_list_util.h @@ -70,6 +70,8 @@ private: std::string GetBusinessEventHash(const BusinessEvent &event); bool IsValidLine(const std::string &line) const; bool CheckIsNumber(const std::string &str) const; + void SplitCombinationKey(std::string &line, TYPE_KEY_CODE_VEC &vecKeyCode, + TYPE_COMBINATION_KEY_VEC &vecCombinationKey) const; private: TYPE_DEVICE_WHITE_LIST_MAP mapDeviceWhiteList_; std::map> combKeysHashMap_;