From 46a5bd0c0bccef89fb26b03dfb1ea03da88a17be Mon Sep 17 00:00:00 2001 From: litiangang4 Date: Wed, 10 May 2023 14:09:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=B8=89=E6=96=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=A2=9E=E5=8A=A0=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: litiangang4 --- common/include/dinput_errcode.h | 1 + common/include/white_list_util.cpp | 27 ++++++++++++++++++--------- common/include/white_list_util.h | 2 ++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/common/include/dinput_errcode.h b/common/include/dinput_errcode.h index 78f91f4..bb93ecb 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 3066906..f718615 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 73724e4..f184737 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_; -- Gitee