From 55fce59f349e740a3686b7579aa7d46e0f061dfd Mon Sep 17 00:00:00 2001 From: hw-zhangliang Date: Sun, 24 Apr 2022 18:09:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E6=AE=B5=E6=B6=88=E6=81=AF=E6=8E=A5?= =?UTF-8?q?=E6=94=B6=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hw-zhangliang --- common/include/dm_constants.h | 1 + .../authentication/auth_message_processor.h | 2 +- .../authentication/auth_message_processor.cpp | 72 +++++++++---------- .../UTTest_auth_message_processor.cpp | 30 +++----- 4 files changed, 45 insertions(+), 60 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index a2124ae2..1ad9e4cd 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -85,6 +85,7 @@ enum { DM_AUTH_NOT_AUTH, DM_AUTH_DONT_AUTH, DM_AUTH_NOT_START, + DM_MESSAGE_NOT_COMPLETE, DM_SOFTBUS_FAILED = 3000, DM_SOFTBUS_CREATE_SESSION_SERVER_FAILED, DM_HICHAIN_FAILED = 4000, diff --git a/services/devicemanagerservice/include/authentication/auth_message_processor.h b/services/devicemanagerservice/include/authentication/auth_message_processor.h index ec545b81..28026904 100644 --- a/services/devicemanagerservice/include/authentication/auth_message_processor.h +++ b/services/devicemanagerservice/include/authentication/auth_message_processor.h @@ -47,7 +47,7 @@ private: void CreateSyncGroupMessage(nlohmann::json &json); void CreateResponseAuthMessage(nlohmann::json &json); void ParseAuthResponseMessage(nlohmann::json &json); - int32_t ParseAuthRequestMessage(); + int32_t ParseAuthRequestMessage(nlohmann::json &json); void ParseNegotiateMessage(const nlohmann::json &json); void CreateResponseFinishMessage(nlohmann::json &json); void ParseResponseFinishMessage(nlohmann::json &json); diff --git a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp index 486aa989..b8f538e8 100644 --- a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp +++ b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp @@ -164,33 +164,15 @@ int32_t AuthMessageProcessor::ParseMessage(const std::string &message) LOGE("err json string, first time"); return DM_FAILED; } - int32_t sliceNum = 0; int32_t msgType = jsonObject[TAG_TYPE]; authResponseContext_->msgType = msgType; - LOGI("AuthMessageProcessor::ParseAuthRequestMessage======== %d", authResponseContext_->msgType); + LOGI("AuthMessageProcessor::ParseMessage message type %d", authResponseContext_->msgType); switch (msgType) { case MSG_TYPE_NEGOTIATE: ParseNegotiateMessage(jsonObject); break; case MSG_TYPE_REQ_AUTH: - if (!jsonObject.contains(TAG_INDEX) || !jsonObject.contains(TAG_DEVICE_ID) || - !jsonObject.contains(TAG_SLICE_NUM)) { - LOGE("err json string, first time"); - return DM_FAILED; - } - authResponseContext_->deviceId = jsonObject[TAG_DEVICE_ID]; - authResponseContext_->authType = jsonObject[TAG_AUTH_TYPE]; - authResponseContext_->appDesc = jsonObject[TAG_APP_DESCRIPTION]; - authResponseContext_->token = jsonObject[TAG_TOKEN]; - authResponseContext_->targetPkgName = jsonObject[TAG_TARGET]; - authResponseContext_->appName = jsonObject[TAG_APP_NAME]; - LOGI("AuthMessageProcessor::ParseAuthResponseMessage %s", authResponseContext_->deviceId.c_str()); - sliceNum = jsonObject[TAG_SLICE_NUM]; - if ((int32_t)authSplitJsonList_.size() < sliceNum) { - authSplitJsonList_.push_back(message); - } else { - ParseAuthRequestMessage(); - } + return ParseAuthRequestMessage(jsonObject); break; case MSG_TYPE_RESP_AUTH: ParseAuthResponseMessage(jsonObject); @@ -209,6 +191,37 @@ void AuthMessageProcessor::ParseResponseFinishMessage(nlohmann::json &json) authResponseContext_->reply = json[TAG_REPLY]; } +int32_t AuthMessageProcessor::ParseAuthRequestMessage(nlohmann::json &json) +{ + LOGE("start ParseAuthRequestMessage"); + int32_t sliceNum = 0; + int32_t idx = 0; + if (!json.contains(TAG_INDEX) || !json.contains(TAG_DEVICE_ID) || + !json.contains(TAG_SLICE_NUM)) { + LOGE("err json string, first time"); + return DM_FAILED; + } + + idx = json[TAG_INDEX]; + sliceNum = json[TAG_SLICE_NUM]; + if (idx == 0) { + authResponseContext_->deviceId = json[TAG_DEVICE_ID]; + authResponseContext_->authType = json[TAG_AUTH_TYPE]; + authResponseContext_->appDesc = json[TAG_APP_DESCRIPTION]; + authResponseContext_->token = json[TAG_TOKEN]; + authResponseContext_->targetPkgName = json[TAG_TARGET]; + authResponseContext_->appName = json[TAG_APP_NAME]; + authResponseContext_->appThumbnail = ""; + } + + if (idx < sliceNum && json.contains(TAG_APP_THUMBNAIL)) { + std::string appSliceThumbnail = json[TAG_APP_THUMBNAIL]; + authResponseContext_->appThumbnail = authResponseContext_->appThumbnail + appSliceThumbnail; + return DM_MESSAGE_NOT_COMPLETE; + } + return DM_OK; +} + void AuthMessageProcessor::ParseAuthResponseMessage(nlohmann::json &json) { LOGI("AuthMessageProcessor::ParseAuthResponseMessage "); @@ -227,25 +240,6 @@ void AuthMessageProcessor::ParseAuthResponseMessage(nlohmann::json &json) LOGI("AuthMessageProcessor::ParseAuthResponseMessage "); } -int32_t AuthMessageProcessor::ParseAuthRequestMessage() -{ - nlohmann::json jsonObject = authSplitJsonList_.front(); - authResponseContext_->deviceId = jsonObject[TAG_DEVICE_ID]; - authResponseContext_->reply = jsonObject[TAG_REPLY]; - authResponseContext_->authType = jsonObject[TAG_AUTH_TYPE]; - LOGI("AuthMessageProcessor::ParseAuthResponseMessage %d", authResponseContext_->reply); - LOGI("AuthMessageProcessor::ParseAuthResponseMessage %s", authResponseContext_->deviceId.c_str()); - if (authResponseContext_->reply == AUTH_REPLY_ACCEPT) { - authResponseContext_->networkId = jsonObject[TAG_NET_ID]; - authResponseContext_->groupId = jsonObject[TAG_GROUP_ID]; - authResponseContext_->groupName = jsonObject[TAG_GROUP_NAME]; - authResponseContext_->requestId = jsonObject[TAG_REQUEST_ID]; - return DM_FAILED; - } - authSplitJsonList_.clear(); - return DM_OK; -} - void AuthMessageProcessor::ParseNegotiateMessage(const nlohmann::json &json) { if (json.contains(TAG_CRYPTO_SUPPORT)) { diff --git a/test/unittest/UTTest_auth_message_processor.cpp b/test/unittest/UTTest_auth_message_processor.cpp index df185bac..c484f6a3 100644 --- a/test/unittest/UTTest_auth_message_processor.cpp +++ b/test/unittest/UTTest_auth_message_processor.cpp @@ -267,7 +267,6 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_001, testing::ext::Te std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->SetResponseContext(authResponseContext); - nlohmann::json json; nlohmann::json jsonThumbnail; authResponseContext->deviceId = "123"; authResponseContext->reply = 0; @@ -283,8 +282,7 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_001, testing::ext::Te jsonThumbnail[TAG_GROUP_ID] = authResponseContext->groupId; jsonThumbnail[TAG_GROUP_NAME] = authResponseContext->groupName; jsonThumbnail[TAG_REQUEST_ID] = authResponseContext->requestId; - authMessageProcessor->authSplitJsonList_.push_back(jsonThumbnail); - int32_t ret = authMessageProcessor->ParseAuthRequestMessage(); + int32_t ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail); ASSERT_EQ(ret, DM_FAILED); } @@ -302,24 +300,16 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_002, testing::ext::Te std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->SetResponseContext(authResponseContext); - nlohmann::json json; nlohmann::json jsonThumbnail; - authResponseContext->deviceId = "123"; - authResponseContext->reply = 1; - authResponseContext->authType = 222; - authResponseContext->networkId = "234"; - authResponseContext->groupId = "345"; - authResponseContext->groupName = "456"; - authResponseContext->requestId = 2333; - jsonThumbnail[TAG_DEVICE_ID] = authResponseContext->deviceId; - jsonThumbnail[TAG_REPLY] = authResponseContext->reply; - jsonThumbnail[TAG_AUTH_TYPE] = authResponseContext->authType; - jsonThumbnail[TAG_NET_ID] = authResponseContext->networkId; - jsonThumbnail[TAG_GROUP_ID] = authResponseContext->groupId; - jsonThumbnail[TAG_GROUP_NAME] = authResponseContext->groupName; - jsonThumbnail[TAG_REQUEST_ID] = authResponseContext->requestId; - authMessageProcessor->authSplitJsonList_.push_back(jsonThumbnail); - int32_t ret = authMessageProcessor->ParseAuthRequestMessage(); + jsonThumbnail[TAG_SLICE_NUM] = 1; + jsonThumbnail[TAG_INDEX] = 0; + jsonThumbnail[TAG_DEVICE_ID] = "123"; + jsonThumbnail[TAG_AUTH_TYPE] = 1; + jsonThumbnail[TAG_APP_DESCRIPTION] = "123"; + jsonThumbnail[TAG_TOKEN] = "1234"; + jsonThumbnail[TAG_TARGET] = "12345"; + jsonThumbnail[TAG_APP_NAME] = "123456"; + int32_t ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail); ASSERT_EQ(ret, DM_OK); }