!75 bug fix: change softbus channel

Merge pull request !75 from 符子坤/OpenHarmony-2.2-Beta2
This commit is contained in:
openharmony_ci
2021-09-11 03:45:49 +00:00
committed by Gitee
6 changed files with 84 additions and 13 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 *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);
}
+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 *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);
}
+9 -2
View File
@@ -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
+2 -2
View File
@@ -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();
}
@@ -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);
@@ -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;
}