bug fix: softbus channel

Signed-off-by: fuzikun <fuzikun@huawei.com>
This commit is contained in:
fuzikun
2021-09-09 22:44:45 +08:00
parent 03e2804269
commit 47949e3213
4 changed files with 67 additions and 0 deletions
+26
View File
@@ -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 *appId = GetStringFromJson(reqParamsJson, FIELD_APP_ID);
if (appId == NULL) {
LOGE("failed to get appId from json object!");
FreeJson(reqParamsJson);
return NULL;
}
int32_t ret = AddReqIdByAppId(appId, requestId);
FreeJson(reqParamsJson);
if (ret != HC_SUCCESS) {
return NULL;
}
}
return GaCbOnRequestWithType(requestId, operationCode, reqParams, CB_TYPE_DEV_AUTH);
}
+25
View File
@@ -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<std::mutex> 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 *appId = GetStringFromJson(reqParamsJson, FIELD_APP_ID);
if (appId == NULL) {
LOGE("failed to get appId from json object!");
FreeJson(reqParamsJson);
return NULL;
}
int32_t ret = AddReqIdByAppId(appId, requestId);
FreeJson(reqParamsJson);
if (ret != HC_SUCCESS) {
return NULL;
}
}
return GaCbOnRequestWithType(requestId, operationCode, reqParams, CB_TYPE_DEV_AUTH);
}
+7
View File
@@ -23,6 +23,10 @@
#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. */
@@ -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
@@ -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;
}