From c3f43d832d1d8260d5bf03fbbc7e1c465a59e458 Mon Sep 17 00:00:00 2001 From: fuzikun Date: Sat, 11 Sep 2021 09:07:47 +0800 Subject: [PATCH] bug fix: change softbus channle Signed-off-by: fuzikun --- frameworks/src/lite/ipc_adapt.c | 26 +++++++++++++++++++ frameworks/src/standard/ipc_adapt.cpp | 25 ++++++++++++++++++ hals/inc/common/json_utils.h | 11 ++++++-- hals/src/common/json_utils.c | 4 +-- .../soft_bus_channel/soft_bus_channel.c | 22 +++++++++------- .../src/bind_session/bind_session_server.c | 9 +++++++ 6 files changed, 84 insertions(+), 13 deletions(-) diff --git a/frameworks/src/lite/ipc_adapt.c b/frameworks/src/lite/ipc_adapt.c index 17f5f53..90abbca 100644 --- a/frameworks/src/lite/ipc_adapt.c +++ b/frameworks/src/lite/ipc_adapt.c @@ -926,8 +926,34 @@ static char *GaCbOnRequestWithType(int64_t requestId, int32_t operationCode, con return (dPtr != NULL) ? strdup(dPtr) : NULL; } +static bool CanFindCbByReqId(int64_t requestId) +{ + LockCallbackList(); + IpcCallBackNode *node = GetIpcCallBackByReqId(requestId, CB_TYPE_DEV_AUTH); + UnLockCallbackList(); + return (node != NULL) ? true : false; +} + static char *IpcGaCbOnRequest(int64_t requestId, int32_t operationCode, const char *reqParams) { + if (!CanFindCbByReqId(requestId)) { + CJson *reqParamsJson = CreateJsonFromString(reqParams); + if (reqParamsJson == NULL) { + LOGE("failed to create json from string!"); + return NULL; + } + const char *callerAppId = GetStringFromJson(reqParamsJson, FIELD_APP_ID); + if (callerAppId == NULL) { + LOGE("failed to get appId from json object!"); + FreeJson(reqParamsJson); + return NULL; + } + int32_t ret = AddReqIdByAppId(callerAppId, requestId); + FreeJson(reqParamsJson); + if (ret != HC_SUCCESS) { + return NULL; + } + } return GaCbOnRequestWithType(requestId, operationCode, reqParams, CB_TYPE_DEV_AUTH); } diff --git a/frameworks/src/standard/ipc_adapt.cpp b/frameworks/src/standard/ipc_adapt.cpp index 25d409a..e400c6a 100644 --- a/frameworks/src/standard/ipc_adapt.cpp +++ b/frameworks/src/standard/ipc_adapt.cpp @@ -880,8 +880,33 @@ static char *GaCbOnRequestWithType(int64_t requestId, int32_t operationCode, con return nullptr; } +static bool CanFindCbByReqId(int64_t requestId) +{ + std::lock_guard autoLock(g_cbListLock); + IpcCallBackNode *node = GetIpcCallBackByReqId(requestId, CB_TYPE_DEV_AUTH); + return (node != NULL) ? true : false; +} + static char *IpcGaCbOnRequest(int64_t requestId, int32_t operationCode, const char *reqParams) { + if (!CanFindCbByReqId(requestId)) { + CJson *reqParamsJson = CreateJsonFromString(reqParams); + if (reqParamsJson == NULL) { + LOGE("failed to create json from string!"); + return NULL; + } + const char *callerAppId = GetStringFromJson(reqParamsJson, FIELD_APP_ID); + if (callerAppId == NULL) { + LOGE("failed to get appId from json object!"); + FreeJson(reqParamsJson); + return NULL; + } + int32_t ret = AddReqIdByAppId(callerAppId, requestId); + FreeJson(reqParamsJson); + if (ret != HC_SUCCESS) { + return NULL; + } + } return GaCbOnRequestWithType(requestId, operationCode, reqParams, CB_TYPE_DEV_AUTH); } diff --git a/hals/inc/common/json_utils.h b/hals/inc/common/json_utils.h index b58aa79..af3d6e6 100644 --- a/hals/inc/common/json_utils.h +++ b/hals/inc/common/json_utils.h @@ -23,14 +23,18 @@ #include "cJSON.h" #include "hc_error.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef cJSON CJson; /* Need to call FreeJson to free the returned pointer when it's no longer in use. */ CJson *CreateJsonFromString(const char *jsonStr); /* Need to call FreeJson to free the returned pointer when it's no longer in use. */ -CJson *CreateJson(); +CJson *CreateJson(void); /* Need to call FreeJson to free the returned pointer when it's no longer in use. */ -CJson *CreateJsonArray(); +CJson *CreateJsonArray(void); /* Need to call FreeJson to free the returned pointer when it's no longer in use. */ CJson *DuplicateJson(const CJson *jsonObj); void FreeJson(CJson *jsonObj); @@ -97,4 +101,7 @@ void ClearSensitiveStringInJson(CJson *jsonObj, const char *key); void ClearAndFreeJsonString(char *jsonStr); int32_t GetUnsignedIntFromJson(const CJson *jsonObj, const char *key, uint32_t *value); +#ifdef __cplusplus +} +#endif #endif diff --git a/hals/src/common/json_utils.c b/hals/src/common/json_utils.c index c1247fa..9f3982e 100644 --- a/hals/src/common/json_utils.c +++ b/hals/src/common/json_utils.c @@ -31,12 +31,12 @@ CJson *CreateJsonFromString(const char *jsonStr) return cJSON_Parse(jsonStr); } -CJson *CreateJson() +CJson *CreateJson(void) { return cJSON_CreateObject(); } -CJson *CreateJsonArray() +CJson *CreateJsonArray(void) { return cJSON_CreateArray(); } diff --git a/services/common/src/channel_manager/soft_bus_channel/soft_bus_channel.c b/services/common/src/channel_manager/soft_bus_channel/soft_bus_channel.c index dfacd63..9ed4e78 100644 --- a/services/common/src/channel_manager/soft_bus_channel/soft_bus_channel.c +++ b/services/common/src/channel_manager/soft_bus_channel/soft_bus_channel.c @@ -25,13 +25,6 @@ #include "session_manager.h" #include "task_manager.h" -#define ETH_IP "ethIp" -#define ETH_PORT "ethPort" -#define WLAN_IP "wifiIp" -#define WLAN_PORT "wifiPort" -#define BR_MAC "brMac" -#define BLE_MAC "bleMac" - typedef struct { HcTaskBase base; int64_t requestId; @@ -153,9 +146,14 @@ static char *GenRecvData(int64_t channelId, const void *data, uint32_t dataLen, return recvDataStr; } +static bool IsServer(int sessionId) +{ + return (GetSessionSide(sessionId) == 0) ? true : false; +} + static int OnChannelOpenedCb(int sessionId, int result) { - if (GetSessionSide(sessionId) == 0) { + if (IsServer(sessionId)) { LOGD("Peer device open channel!"); return HC_SUCCESS; } @@ -189,7 +187,10 @@ static int OnChannelOpenedCb(int sessionId, int result) static void OnChannelClosedCb(int sessionId) { LOGI("[SoftBus][Out]: OnChannelClosed! sessionId: %d", sessionId); - return; + if (IsServer(sessionId)) { + return; + } + RemoveChannelEntry(sessionId); } static void OnBytesReceivedCb(int sessionId, const void *data, unsigned int dataLen) @@ -232,6 +233,9 @@ static int32_t OpenSoftBusChannel(const char *connectParams, int64_t requestId, static void CloseSoftBusChannel(int64_t channelId) { + if (IsServer(channelId)) { + return; + } RemoveChannelEntry(channelId); LOGD("[SoftBus][In]: CloseSession!"); CloseSession(channelId); diff --git a/services/session/src/bind_session/bind_session_server.c b/services/session/src/bind_session/bind_session_server.c index ce8ac60..0714d39 100644 --- a/services/session/src/bind_session/bind_session_server.c +++ b/services/session/src/bind_session/bind_session_server.c @@ -153,6 +153,11 @@ static int32_t GenerateRequestParams(const CJson *jsonParams, CJson *requestPara LOGE("Failed to get peerAuthId from jsonParams!"); return HC_ERR_JSON_GET; } + const char *appId = GetStringFromJson(jsonParams, FIELD_APP_ID); + if (appId == NULL) { + LOGE("Failed to get appId from jsonParams!"); + return HC_ERR_JSON_GET; + } int32_t groupType = PEER_TO_PEER_GROUP; if (GetIntFromJson(jsonParams, FIELD_GROUP_TYPE, &groupType) != HC_SUCCESS) { LOGE("Failed to get groupType from jsonParams!"); @@ -170,6 +175,10 @@ static int32_t GenerateRequestParams(const CJson *jsonParams, CJson *requestPara LOGE("Failed to add peerDeviceId to requestParams!"); return HC_ERR_JSON_FAIL; } + if (AddStringToJson(requestParams, FIELD_APP_ID, appId) != HC_SUCCESS) { + LOGE("Failed to add appId to requestParams!"); + return HC_ERR_JSON_FAIL; + } return HC_SUCCESS; }