Signed-off-by: 想不出别名 <zhengjianming1@huawei.com>
This commit is contained in:
想不出别名
2021-09-18 17:31:59 +08:00
parent 772ab4b0da
commit c4125e8fe0
10 changed files with 75 additions and 50 deletions
@@ -144,7 +144,9 @@ private:
}
if (appIcon != nullptr) {
appIconLen = appIconLen_;
(void)memcpy_s(appIcon, appIconLen, appIcon_, appIconLen_);
if (memcpy_s(appIcon, appIconLen, appIcon_, appIconLen_) != 0) {
return;
}
}
}
}
@@ -162,7 +164,9 @@ private:
}
if (appThumbnail != nullptr) {
appThumbnailLen = appThumbnailLen_;
(void)memcpy_s(appThumbnail, appThumbnailLen, appThumbnail_, appThumbnailLen_);
if (memcpy_s(appThumbnail, appThumbnailLen, appThumbnail_, appThumbnailLen_) != 0) {
return;
}
}
}
}
@@ -216,11 +216,11 @@ DeviceManagerNapi *DeviceManagerNapi::GetDeviceManagerNapi(std::string &buldleNa
void DeviceManagerNapi::OnDeviceStateChange(DmNapiDevStateChangeAction action, const DmDeviceInfo &deviceInfo)
{
napi_value result;
napi_value result = nullptr;
napi_create_object(env_, &result);
SetValueInt32(env_, "action", (int)action, result);
napi_value device;
napi_value device = nullptr;
napi_create_object(env_, &device);
SetValueUtf8String(env_, "deviceId", deviceInfo.deviceId, device);
SetValueUtf8String(env_, "deviceName", deviceInfo.deviceName, device);
@@ -233,11 +233,11 @@ void DeviceManagerNapi::OnDeviceStateChange(DmNapiDevStateChangeAction action, c
void DeviceManagerNapi::OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo)
{
DMLOG(DM_LOG_INFO, "OnDeviceFound for subscribeId %d", (int32_t)subscribeId);
napi_value result;
napi_value result = nullptr;
napi_create_object(env_, &result);
SetValueInt32(env_, "subscribeId", (int)subscribeId, result);
napi_value device;
napi_value device = nullptr;
napi_create_object(env_, &device);
SetValueUtf8String(env_, "deviceId", deviceInfo.deviceId, device);
SetValueUtf8String(env_, "deviceName", deviceInfo.deviceName, device);
@@ -250,7 +250,7 @@ void DeviceManagerNapi::OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &
void DeviceManagerNapi::OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason)
{
DMLOG(DM_LOG_INFO, "OnDiscoverFailed for subscribeId %d", (int32_t)subscribeId);
napi_value result;
napi_value result = nullptr;
napi_create_object(env_, &result);
SetValueInt32(env_, "subscribeId", (int)subscribeId, result);
SetValueInt32(env_, "reason", (int)failedReason, result);
@@ -260,7 +260,7 @@ void DeviceManagerNapi::OnDiscoverFailed(uint16_t subscribeId, int32_t failedRea
void DeviceManagerNapi::OnDmfaCall(const std::string &paramJson)
{
DMLOG(DM_LOG_INFO, "OnCall for paramJson");
napi_value result;
napi_value result = nullptr;
napi_create_object(env_, &result);
SetValueUtf8String(env_, "param", paramJson, result);
OnEvent("dmFaCallback", DM_NAPI_ARGS_ONE, &result);
@@ -333,7 +333,7 @@ void DeviceManagerNapi::OnVerifyResult(const std::string &deviceId, int32_t resu
void DeviceManagerNapi::SetValueUtf8String(const napi_env &env, const std::string &fieldStr, const std::string &str,
napi_value &result)
{
napi_value value;
napi_value value = nullptr;
napi_create_string_utf8(env, str.c_str(), NAPI_AUTO_LENGTH, &value);
napi_set_named_property(env, result, fieldStr.c_str(), value);
}
@@ -341,7 +341,7 @@ void DeviceManagerNapi::SetValueUtf8String(const napi_env &env, const std::strin
void DeviceManagerNapi::SetValueInt32(const napi_env &env, const std::string &fieldStr, const int32_t intValue,
napi_value &result)
{
napi_value value;
napi_value value = nullptr;
napi_create_int32(env, intValue, &value);
napi_set_named_property(env, result, fieldStr.c_str(), value);
}
@@ -350,7 +350,7 @@ void DeviceManagerNapi::DeviceInfoToJsArray(const napi_env &env,
const std::vector<DmDeviceInfo> &vecDevInfo,
const int32_t idx, napi_value &arrayResult)
{
napi_value result;
napi_value result = nullptr;
napi_create_object(env, &result);
SetValueUtf8String(env, "deviceId", vecDevInfo[idx].deviceId, result);
@@ -369,7 +369,7 @@ void DeviceManagerNapi::DmAuthParamToJsAuthParamy(const napi_env &env,
DMLOG(DM_LOG_INFO, "DmAuthParamToJsAuthParamy in");
SetValueInt32(env, "authType", authParam.authType, paramResult);
napi_value extraInfo;
napi_value extraInfo = nullptr;
napi_create_object(env, &extraInfo);
SetValueInt32(env, "direction", authParam.direction, extraInfo);
SetValueInt32(env, "pinToken", authParam.pinToken, extraInfo);
@@ -420,8 +420,8 @@ void DeviceManagerNapi::JsObjectToString(const napi_env &env, const napi_value &
bool hasProperty = false;
NAPI_CALL_RETURN_VOID(env, napi_has_named_property(env, object, fieldStr.c_str(), &hasProperty));
if (hasProperty) {
napi_value field;
napi_valuetype valueType;
napi_value field = nullptr;
napi_valuetype valueType = napi_undefined;
napi_get_named_property(env, object, fieldStr.c_str(), &field);
NAPI_CALL_RETURN_VOID(env, napi_typeof(env, field, &valueType));
@@ -467,8 +467,8 @@ void DeviceManagerNapi::JsObjectToInt(const napi_env &env, const napi_value &obj
bool hasProperty = false;
NAPI_CALL_RETURN_VOID(env, napi_has_named_property(env, object, fieldStr.c_str(), &hasProperty));
if (hasProperty) {
napi_value field;
napi_valuetype valueType;
napi_value field = nullptr;
napi_valuetype valueType = napi_undefined;
napi_get_named_property(env, object, fieldStr.c_str(), &field);
NAPI_CALL_RETURN_VOID(env, napi_typeof(env, field, &valueType));
@@ -485,8 +485,8 @@ void DeviceManagerNapi::JsObjectToBool(const napi_env &env, const napi_value &ob
bool hasProperty = false;
NAPI_CALL_RETURN_VOID(env, napi_has_named_property(env, object, fieldStr.c_str(), &hasProperty));
if (hasProperty) {
napi_value field;
napi_valuetype valueType;
napi_value field = nullptr;
napi_valuetype valueType = napi_undefined;
napi_get_named_property(env, object, fieldStr.c_str(), &field);
NAPI_CALL_RETURN_VOID(env, napi_typeof(env, field, &valueType));
@@ -588,9 +588,9 @@ void DeviceManagerNapi::JsToDmBuffer(const napi_env &env, const napi_value &obje
return;
}
napi_value field;
napi_value field = nullptr;
napi_get_named_property(env, object, fieldStr.c_str(), &field);
napi_typedarray_type type;
napi_typedarray_type type = napi_uint8_array;
size_t length = 0;
napi_value buffer = nullptr;
size_t offset = 0;
@@ -626,7 +626,7 @@ void DeviceManagerNapi::JsToJsonObject(const napi_env &env, const napi_value &ob
return;
}
napi_value jsonField;
napi_value jsonField = nullptr;
napi_get_named_property(env, object, fieldStr.c_str(), &jsonField);
napi_valuetype jsValueType = napi_undefined;
napi_value jsProNameList = nullptr;
@@ -794,7 +794,7 @@ napi_value DeviceManagerNapi::SetUserOperationSync(napi_env env, napi_callback_i
{
DMLOG(DM_LOG_INFO, "SetUserOperationSync in");
GET_PARAMS(env, info, DM_NAPI_ARGS_ONE);
napi_valuetype valueType;
napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType);
NAPI_ASSERT(env, valueType == napi_number, "Wrong argument type. Object expected.");
@@ -883,7 +883,7 @@ napi_value DeviceManagerNapi::StartDeviceDiscoverSync(napi_env env, napi_callbac
DMLOG(DM_LOG_INFO, "StartDeviceDiscoverSync in");
GET_PARAMS(env, info, DM_NAPI_ARGS_ONE);
napi_value result = nullptr;
napi_valuetype valueType;
napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType);
NAPI_ASSERT(env, valueType == napi_object, "Wrong argument type. Object expected.");
@@ -919,7 +919,7 @@ napi_value DeviceManagerNapi::StopDeviceDiscoverSync(napi_env env, napi_callback
DMLOG(DM_LOG_INFO, "StopDeviceDiscoverSync in");
GET_PARAMS(env, info, DM_NAPI_ARGS_ONE);
napi_value result = nullptr;
napi_valuetype valueType;
napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType);
NAPI_ASSERT(env, valueType == napi_number, "Wrong argument type. Object expected.");
@@ -948,11 +948,11 @@ napi_value DeviceManagerNapi::AuthenticateDevice(napi_env env, napi_callback_inf
DMLOG(DM_LOG_INFO, "AuthenticateDevice in");
GET_PARAMS(env, info, DM_NAPI_ARGS_THREE);
napi_value result = nullptr;
napi_valuetype deviceInfoType;
napi_valuetype deviceInfoType = napi_undefined;
napi_typeof(env, argv[0], &deviceInfoType);
NAPI_ASSERT(env, deviceInfoType == napi_object, "Wrong argument type. Object expected.");
napi_valuetype authparamType;
napi_valuetype authparamType = napi_undefined;
napi_typeof(env, argv[PARAM_INDEX_ONE], &authparamType);
NAPI_ASSERT(env, authparamType == napi_object, "Wrong argument type. Object expected.");
@@ -997,7 +997,7 @@ napi_value DeviceManagerNapi::VerifyAuthInfo(napi_env env, napi_callback_info in
DMLOG(DM_LOG_INFO, "VerifyAuthInfo in");
GET_PARAMS(env, info, DM_NAPI_ARGS_TWO);
napi_value result = nullptr;
napi_valuetype valueType;
napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType);
NAPI_ASSERT(env, valueType == napi_object, "Wrong argument type. Object expected.");
@@ -1161,8 +1161,8 @@ void DeviceManagerNapi::HandleCreateDmCallBack(const napi_env &env, AsyncCallbac
(void)status;
AsyncCallbackInfo *asCallbackInfo = (AsyncCallbackInfo *)data;
napi_value result[DM_NAPI_ARGS_TWO] = { 0 };
napi_value ctor;
napi_value argv;
napi_value ctor = nullptr;
napi_value argv = nullptr;
napi_get_reference_value(env, sConstructor_, &ctor);
napi_create_string_utf8(env, asCallbackInfo->bundleName, NAPI_AUTO_LENGTH, &argv);
napi_status ret = napi_new_instance(env, ctor, DM_NAPI_ARGS_ONE, &argv, &result[1]);
@@ -1250,7 +1250,7 @@ napi_value DeviceManagerNapi::Constructor(napi_env env, napi_callback_info info)
napi_value DeviceManagerNapi::Init(napi_env env, napi_value exports)
{
napi_value dmClass;
napi_value dmClass = nullptr;
napi_property_descriptor dmProperties[] = {
DECLARE_NAPI_FUNCTION("release", ReleaseDeviceManager),
DECLARE_NAPI_FUNCTION("getTrustedDeviceListSync", GetTrustedDeviceListSync),
@@ -359,8 +359,7 @@ void HichainAuthenCallBack::onFinish(int64_t requestId, int32_t operationCode, c
if (operationCode == GroupOperationCode::GROUP_CREATE) {
DMLOG(DM_LOG_INFO, "Create group success");
std::string returnStr = returnData;
HichainConnector::GetInstance().OnGroupCreated(requestId, returnStr);
HichainConnector::GetInstance().OnGroupCreated(requestId, data);
}
if (operationCode == GroupOperationCode::MEMBER_DELETE) {
@@ -90,21 +90,25 @@ int32_t IpcServerAdapter::GetTrustedDeviceList(std::string &pkgName, std::string
*info = nullptr;
if (*infoNum > 0) {
*info = (DmDeviceInfo *)malloc(sizeof(DmDeviceInfo) * (*infoNum));
}
for (int32_t i = 0; i < *infoNum; ++i) {
NodeBasicInfo *nodeBasicInfo = nodeInfo + i;
DmDeviceInfo *deviceInfo = *info + i;
if (memcpy_s(deviceInfo->deviceId, sizeof(deviceInfo->deviceId), nodeBasicInfo->networkId,
std::min(sizeof(deviceInfo->deviceId), sizeof(nodeBasicInfo->networkId))) != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "memcpy failed");
if (*info != nullptr) {
for (int32_t i = 0; i < *infoNum; ++i) {
NodeBasicInfo *nodeBasicInfo = nodeInfo + i;
DmDeviceInfo *deviceInfo = *info + i;
if (memcpy_s(deviceInfo->deviceId, sizeof(deviceInfo->deviceId), nodeBasicInfo->networkId,
std::min(sizeof(deviceInfo->deviceId), sizeof(nodeBasicInfo->networkId))) != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "memcpy failed");
}
if (memcpy_s(deviceInfo->deviceName, sizeof(deviceInfo->deviceName), nodeBasicInfo->deviceName,
std::min(sizeof(deviceInfo->deviceName), sizeof(nodeBasicInfo->deviceName))) != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "memcpy failed");
}
deviceInfo->deviceTypeId = (DMDeviceType)nodeBasicInfo->deviceTypeId;
}
}
if (memcpy_s(deviceInfo->deviceName, sizeof(deviceInfo->deviceName), nodeBasicInfo->deviceName,
std::min(sizeof(deviceInfo->deviceName), sizeof(nodeBasicInfo->deviceName))) != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "memcpy failed");
}
deviceInfo->deviceTypeId = (DMDeviceType)nodeBasicInfo->deviceTypeId;
}
FreeNodeInfo(nodeInfo);
if (nodeInfo != nullptr) {
FreeNodeInfo(nodeInfo);
}
DMLOG(DM_LOG_INFO, "success, pkgName:%s, deviceCount %d", pkgName.c_str(), *infoNum);
return DEVICEMANAGER_OK;
}
@@ -266,8 +266,11 @@ ON_IPC_CMD(AUTHENTICATE_DEVICE, MessageParcel &data, MessageParcel &reply)
uint8_t *appThumbnail = appThumbnailLen > 0? (uint8_t *)data.ReadRawData(appThumbnailLen) : nullptr;
DmAppImageInfo imageInfo(appIcon, appIconLen, appThumbnail, appThumbnailLen);
int32_t result = IpcServerAdapter::GetInstance().AuthenticateDevice(pkgName, *deviceInfo, imageInfo, extra);
int32_t result = DEVICEMANAGER_OK;
if (deviceInfo != nullptr) {
result = IpcServerAdapter::GetInstance().AuthenticateDevice(pkgName, *deviceInfo, imageInfo, extra);
}
if (!reply.WriteInt32(result)) {
DMLOG(DM_LOG_ERROR, "write result failed");
return DEVICEMANAGER_WRITE_FAILED;
@@ -61,6 +61,8 @@ RequestSession::RequestSession(std::string &hostPkgName, const DmDeviceInfo &dev
mTargetPkgName = targetPkgName;
mStatus_ = StatusType::STATUS_INIT;
mPinToken_ = IpcServerAdapter::GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN);
mChannelId_ = -1;
mRequestId_ = -1;
char randStr[TOKEN_LEN] = {0};
bool res = EncryptUtils::MbedtlsGenRandomStr(randStr, sizeof(randStr), false);
if (res == false) {
@@ -48,6 +48,13 @@ ResponseSession::ResponseSession()
{
mSessionStatus_ = ResponseSessionStatus::SESSION_INIT;
sem_init(&mSem_, 0, 0);
mRequestId_ = -1;
mGroupId_ = "";
mGroupName_ = "";
mReqDeviceId_ = "";
mMsgRequestAuthPtr_ = nullptr;
mChannelId_ = -1;
mPincode_ = -1;
}
int64_t ResponseSession::GetRequestId()
@@ -304,7 +304,10 @@ int32_t SoftbusAdapter::StartDiscovery(std::string &pkgName, SubscribeInfo *info
subinfo->subscribeIdOrigin = info->subscribeId;
subinfo->subscribeIdPrefix = subscribeIdPrefix++;
subinfo->info = *info;
subinfo->info.subscribeId = (subinfo->subscribeIdPrefix << SUBSCRIBE_ID_PREFIX_LEN) | info->subscribeId;
uint32_t uSubscribeId = static_cast<uint32_t>(info->subscribeId);
uSubscribeId = (subinfo->subscribeIdPrefix << SUBSCRIBE_ID_PREFIX_LEN) | uSubscribeId;
subinfo->info.subscribeId = static_cast<int32_t>(uSubscribeId);
}
if (vectorIter == subinfoVector.end()) {
subinfoVector.push_back(subinfo);
@@ -217,9 +217,9 @@ void SoftbusSession::GetPeerDeviceId(int32_t sessionId, std::string &peerDevId)
char peerDeviceId[DEVICE_UUID_LENGTH] = {0};
int32_t ret = ::GetPeerDeviceId(sessionId, &peerDeviceId[0], DEVICE_UUID_LENGTH);
if (ret == 0) {
DMLOG(DM_LOG_INFO, "GetPeerDeviceId success for session:%d, peerDeviceId:%s", sessionId,
GetAnonyString(peerDeviceId).c_str());
peerDevId = peerDeviceId;
DMLOG(DM_LOG_INFO, "GetPeerDeviceId success for session:%d, peerDeviceId:%s", sessionId,
GetAnonyString(peerDevId).c_str());
return;
}
@@ -26,6 +26,7 @@ DmTimer::DmTimer(std::string &name)
{
mStatus_ = DmTimerStatus::DM_STATUS_INIT;
mTimerName_ = name;
mEpFd_ = 0;
}
DmTimer::~DmTimer()
@@ -133,7 +134,9 @@ void DmTimer::Release()
mStatus_ = DmTimerStatus::DM_STATUS_INIT;
close(mTimeFd_[0]);
close(mTimeFd_[1]);
close(mEpFd_);
if (mEpFd_ >= 0) {
close(mEpFd_);
}
mTimeFd_[0] = 0;
mTimeFd_[1] = 0;
mEpFd_ = 0;