mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2025-02-23 20:53:09 +00:00
fix: modify super file
Signed-off-by: liangjunhao <liangjunhao10@huawei.com>
This commit is contained in:
parent
0f2f64fe36
commit
c20dbdc2e2
@ -50,6 +50,7 @@
|
||||
#define MIN_META_LEN 6
|
||||
#define META_SESSION "IShare"
|
||||
#define MAX_DATA_BUF 4096
|
||||
#define MAX_ERRDESC_LEN 128
|
||||
|
||||
typedef struct {
|
||||
ListNode node;
|
||||
@ -798,109 +799,107 @@ static void ReleaseSessionConn(SessionConn *chan)
|
||||
SoftBusFree(chan);
|
||||
}
|
||||
|
||||
static int32_t OpenDataBusRequest(int32_t channelId, uint32_t flags, uint64_t seq, const cJSON *request)
|
||||
static void ReportTransEventExtra(
|
||||
TransEventExtra *extra, int32_t channelId, SessionConn *conn, NodeInfo *nodeInfo, char *peerUuid)
|
||||
{
|
||||
TRANS_LOGI(TRANS_CTRL, "channelId=%{public}d, seq=%{public}" PRIu64, channelId, seq);
|
||||
SessionConn *conn = GetSessionConnFromDataBusRequest(channelId, request);
|
||||
if (conn == NULL) {
|
||||
TRANS_LOGE(TRANS_CTRL, "conn is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
TransEventExtra extra = {
|
||||
.socketName = conn->appInfo.myData.sessionName,
|
||||
.calleePkg = NULL,
|
||||
.callerPkg = NULL,
|
||||
.channelId = channelId,
|
||||
.peerChannelId = conn->appInfo.peerData.channelId,
|
||||
.socketFd = conn->appInfo.fd,
|
||||
.result = EVENT_STAGE_RESULT_OK
|
||||
};
|
||||
char peerUuid[DEVICE_ID_SIZE_MAX] = {0};
|
||||
NodeInfo nodeInfo;
|
||||
(void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
|
||||
extra->socketName = conn->appInfo.myData.sessionName;
|
||||
extra->calleePkg = NULL;
|
||||
extra->callerPkg = NULL;
|
||||
extra->channelId = channelId;
|
||||
extra->peerChannelId = conn->appInfo.peerData.channelId;
|
||||
extra->socketFd = conn->appInfo.fd;
|
||||
extra->result = EVENT_STAGE_RESULT_OK;
|
||||
bool peerRet = GetUuidByChanId(channelId, peerUuid, DEVICE_ID_SIZE_MAX) == SOFTBUS_OK &&
|
||||
LnnGetRemoteNodeInfoById(peerUuid, CATEGORY_UUID, &nodeInfo) == SOFTBUS_OK;
|
||||
LnnGetRemoteNodeInfoById(peerUuid, CATEGORY_UUID, nodeInfo) == SOFTBUS_OK;
|
||||
if (peerRet) {
|
||||
extra.peerUdid = nodeInfo.deviceInfo.deviceUdid;
|
||||
extra.peerDevVer = nodeInfo.deviceInfo.deviceVersion;
|
||||
extra->peerUdid = nodeInfo->deviceInfo.deviceUdid;
|
||||
extra->peerDevVer = nodeInfo->deviceInfo.deviceVersion;
|
||||
}
|
||||
if (LnnGetLocalStrInfo(STRING_KEY_DEV_UDID, nodeInfo.masterUdid, UDID_BUF_LEN) == SOFTBUS_OK) {
|
||||
extra.localUdid = nodeInfo.masterUdid;
|
||||
if (LnnGetLocalStrInfo(STRING_KEY_DEV_UDID, nodeInfo->masterUdid, UDID_BUF_LEN) == SOFTBUS_OK) {
|
||||
extra->localUdid = nodeInfo->masterUdid;
|
||||
}
|
||||
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_START, extra);
|
||||
if ((flags & FLAG_AUTH_META) != 0 && !IsMetaSession(conn->appInfo.myData.sessionName)) {
|
||||
char *tmpName = NULL;
|
||||
Anonymize(conn->appInfo.myData.sessionName, &tmpName);
|
||||
TRANS_LOGI(TRANS_CTRL,
|
||||
"Request denied: session is not a meta session. sessionName=%{public}s", tmpName);
|
||||
AnonymizeFree(tmpName);
|
||||
ReleaseSessionConn(conn);
|
||||
return SOFTBUS_TRANS_NOT_META_SESSION;
|
||||
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_START, *extra);
|
||||
}
|
||||
|
||||
static void CheckStrcpy(char *dest, const int32_t destSize, const char *src)
|
||||
{
|
||||
if (strcpy_s(dest, destSize, src) != EOK) {
|
||||
TRANS_LOGW(TRANS_CTRL, "strcpy failed");
|
||||
}
|
||||
char *errDesc = NULL;
|
||||
int32_t errCode;
|
||||
int myHandleId;
|
||||
int32_t ret = SOFTBUS_ERR;
|
||||
return;
|
||||
}
|
||||
|
||||
static int32_t CheckAndFillAppinfo(SessionConn *conn, int32_t channelId, char *errDesc)
|
||||
{
|
||||
char *ret = NULL;
|
||||
int32_t errCode = SOFTBUS_OK;
|
||||
if (conn->appInfo.callingTokenId != TOKENID_NOT_SET &&
|
||||
TransCheckServerAccessControl(conn->appInfo.callingTokenId) != SOFTBUS_OK) {
|
||||
errCode = SOFTBUS_TRANS_CHECK_ACL_FAILED;
|
||||
errDesc = (char *)"Server check acl failed";
|
||||
goto ERR_EXIT;
|
||||
ret = (char *)"Server check acl failed";
|
||||
CheckStrcpy(errDesc, MAX_ERRDESC_LEN, ret);
|
||||
return errCode;
|
||||
}
|
||||
if (TransTdcGetUidAndPid(conn->appInfo.myData.sessionName,
|
||||
&conn->appInfo.myData.uid, &conn->appInfo.myData.pid) != SOFTBUS_OK) {
|
||||
errCode = SOFTBUS_TRANS_PEER_SESSION_NOT_CREATED;
|
||||
errDesc = (char *)"Peer Device Session Not Create";
|
||||
goto ERR_EXIT;
|
||||
ret = (char *)"Peer Device Session Not Create";
|
||||
CheckStrcpy(errDesc, MAX_ERRDESC_LEN, ret);
|
||||
return errCode;
|
||||
}
|
||||
if (GetUuidByChanId(channelId, conn->appInfo.peerData.deviceId, DEVICE_ID_SIZE_MAX) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "Get Uuid By ChanId failed.");
|
||||
errCode = SOFTBUS_TRANS_TDC_CHANNEL_NOT_FOUND;
|
||||
errDesc = (char *)"Get Uuid By ChanId failed";
|
||||
goto ERR_EXIT;
|
||||
ret = (char *)"Get Uuid By ChanId failed";
|
||||
CheckStrcpy(errDesc, MAX_ERRDESC_LEN, ret);
|
||||
return errCode;
|
||||
}
|
||||
if (TransTdcFillDataConfig(&conn->appInfo) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "fill data config failed.");
|
||||
errCode = SOFTBUS_INVALID_PARAM;
|
||||
errDesc = (char *)"fill data config failed";
|
||||
goto ERR_EXIT;
|
||||
ret = (char *)"fill data config failed";
|
||||
CheckStrcpy(errDesc, MAX_ERRDESC_LEN, ret);
|
||||
return errCode;
|
||||
}
|
||||
if (SetAppInfoById(channelId, &conn->appInfo) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "set app info by id failed.");
|
||||
errCode = SOFTBUS_TRANS_SESSION_INFO_NOT_FOUND;
|
||||
errDesc = (char *)"Set App Info By Id Failed";
|
||||
goto ERR_EXIT;
|
||||
ret = (char *)"Set App Info By Id Failed";
|
||||
CheckStrcpy(errDesc, MAX_ERRDESC_LEN, ret);
|
||||
return errCode;
|
||||
}
|
||||
|
||||
OpenDataBusRequestOutSessionName(conn->appInfo.myData.sessionName,
|
||||
conn->appInfo.peerData.sessionName);
|
||||
OpenDataBusRequestOutSessionName(conn->appInfo.myData.sessionName, conn->appInfo.peerData.sessionName);
|
||||
TRANS_LOGI(TRANS_CTRL, "OpenDataBusRequest: myPid=%{public}d, peerPid=%{public}d",
|
||||
conn->appInfo.myData.pid, conn->appInfo.peerData.pid);
|
||||
if (NotifyChannelOpened(channelId) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "Notify App Channel Opened Failed");
|
||||
errCode = SOFTBUS_TRANS_UDP_SERVER_NOTIFY_APP_OPEN_FAILED;
|
||||
errDesc = (char *)"Notify App Channel Opened Failed";
|
||||
goto ERR_EXIT;
|
||||
}
|
||||
if (conn->appInfo.fastTransDataSize > 0 && conn->appInfo.fastTransData != NULL) {
|
||||
NotifyFastDataRecv(conn, channelId);
|
||||
ret = (char *)"Notify App Channel Opened Failed";
|
||||
CheckStrcpy(errDesc, MAX_ERRDESC_LEN, ret);
|
||||
return errCode;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t HandleDataBusReply(
|
||||
SessionConn *conn, int32_t channelId, TransEventExtra *extra, uint32_t flags, uint64_t seq)
|
||||
{
|
||||
int myHandleId;
|
||||
myHandleId = NotifyNearByUpdateHandleId(channelId);
|
||||
if (myHandleId != SOFTBUS_ERR) {
|
||||
TRANS_LOGE(TRANS_CTRL, "update handId notify failed");
|
||||
conn->appInfo.myHandleId = myHandleId;
|
||||
}
|
||||
(void)SetAppInfoById(channelId, &conn->appInfo);
|
||||
ret = OpenDataBusRequestReply(&conn->appInfo, channelId, seq, flags);
|
||||
int32_t ret = OpenDataBusRequestReply(&conn->appInfo, channelId, seq, flags);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "OpenDataBusRequest reply err");
|
||||
(void)NotifyChannelClosed(&conn->appInfo, channelId);
|
||||
ReleaseSessionConn(conn);
|
||||
return ret;
|
||||
} else {
|
||||
extra.result = EVENT_STAGE_RESULT_OK;
|
||||
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_REPLY, extra);
|
||||
extra->result = EVENT_STAGE_RESULT_OK;
|
||||
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_REPLY, *extra);
|
||||
}
|
||||
|
||||
if (conn->appInfo.routeType == WIFI_P2P) {
|
||||
@ -910,18 +909,55 @@ static int32_t OpenDataBusRequest(int32_t channelId, uint32_t flags, uint64_t se
|
||||
LaneUpdateP2pAddressByIp(conn->appInfo.peerData.addr, conn->appInfo.peerNetWorkId);
|
||||
}
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t OpenDataBusRequest(int32_t channelId, uint32_t flags, uint64_t seq, const cJSON *request)
|
||||
{
|
||||
TRANS_LOGI(TRANS_CTRL, "channelId=%{public}d, seq=%{public}" PRIu64, channelId, seq);
|
||||
SessionConn *conn = GetSessionConnFromDataBusRequest(channelId, request);
|
||||
TRANS_CHECK_AND_RETURN_RET_LOGE(conn != NULL, SOFTBUS_INVALID_PARAM, TRANS_CTRL, "conn is null");
|
||||
|
||||
TransEventExtra extra;
|
||||
char peerUuid[DEVICE_ID_SIZE_MAX] = { 0 };
|
||||
NodeInfo nodeInfo;
|
||||
(void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
|
||||
ReportTransEventExtra(&extra, channelId, conn, &nodeInfo, peerUuid);
|
||||
|
||||
if ((flags & FLAG_AUTH_META) != 0 && !IsMetaSession(conn->appInfo.myData.sessionName)) {
|
||||
char *tmpName = NULL;
|
||||
Anonymize(conn->appInfo.myData.sessionName, &tmpName);
|
||||
TRANS_LOGI(TRANS_CTRL,
|
||||
"Request denied: session is not a meta session. sessionName=%{public}s", tmpName);
|
||||
AnonymizeFree(tmpName);
|
||||
ReleaseSessionConn(conn);
|
||||
return SOFTBUS_TRANS_NOT_META_SESSION;
|
||||
}
|
||||
char errDesc[MAX_ERRDESC_LEN] = { 0 };
|
||||
int32_t errCode = CheckAndFillAppinfo(conn, channelId, errDesc);
|
||||
if (errCode != SOFTBUS_OK) {
|
||||
if (OpenDataBusRequestError(channelId, seq, errDesc, errCode, flags) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "OpenDataBusRequestError error");
|
||||
}
|
||||
ReleaseSessionConn(conn);
|
||||
return errCode;
|
||||
}
|
||||
|
||||
if (conn->appInfo.fastTransDataSize > 0 && conn->appInfo.fastTransData != NULL) {
|
||||
NotifyFastDataRecv(conn, channelId);
|
||||
}
|
||||
|
||||
errCode = HandleDataBusReply(conn, channelId, &extra, flags, seq);
|
||||
if (errCode != SOFTBUS_OK) {
|
||||
ReleaseSessionConn(conn);
|
||||
return errCode;
|
||||
}
|
||||
|
||||
ReleaseSessionConn(conn);
|
||||
TRANS_LOGD(TRANS_CTRL, "ok");
|
||||
return SOFTBUS_OK;
|
||||
|
||||
ERR_EXIT:
|
||||
if (OpenDataBusRequestError(channelId, seq, errDesc, errCode, flags) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "OpenDataBusRequestError error");
|
||||
}
|
||||
ReleaseSessionConn(conn);
|
||||
return errCode;
|
||||
}
|
||||
|
||||
|
||||
static int32_t ProcessMessage(int32_t channelId, uint32_t flags, uint64_t seq, const char *msg)
|
||||
{
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "client_bus_center_manager.h"
|
||||
#include "client_disc_manager.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "comm_log.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_adapter_thread.h"
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "client_disc_manager.h"
|
||||
#include "client_trans_channel_callback.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "comm_log.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "ipc_types.h"
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <thread>
|
||||
#include "client_bus_center_manager.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "bus_center_server_proxy.h"
|
||||
#include "comm_log.h"
|
||||
#include "disc_server_proxy.h"
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_session_service.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "session.h"
|
||||
#include "session_callback_mock.h"
|
||||
|
||||
|
@ -136,6 +136,17 @@ typedef struct {
|
||||
char sessionName[SESSION_NAME_SIZE_MAX];
|
||||
} SessionServerInfo;
|
||||
|
||||
typedef struct {
|
||||
ListNode node;
|
||||
int32_t sessionId;
|
||||
int32_t channelId;
|
||||
ChannelType channelType;
|
||||
void (*OnSessionClosed)(int sessionId);
|
||||
void (*OnShutdown)(int32_t socket, ShutdownReason reason);
|
||||
char sessionName[SESSION_NAME_SIZE_MAX];
|
||||
char pkgName[PKG_NAME_SIZE_MAX];
|
||||
} DestroySessionInfo;
|
||||
|
||||
int32_t ClientAddNewSession(const char *sessionName, SessionInfo *session);
|
||||
|
||||
/**
|
||||
@ -182,16 +193,11 @@ int32_t ClientAddSessionServer(SoftBusSecType type, const char *pkgName, const c
|
||||
|
||||
int32_t ClientGetSessionSide(int32_t sessionId);
|
||||
|
||||
int32_t ClientGrantPermission(int uid, int pid, const char *busName);
|
||||
|
||||
int32_t ClientRemovePermission(const char *busName);
|
||||
|
||||
int32_t ClientGetFileConfigInfoById(int32_t sessionId, int32_t *fileEncrypt, int32_t *algorithm, int32_t *crc);
|
||||
|
||||
int TransClientInit(void);
|
||||
void TransClientDeinit(void);
|
||||
|
||||
int32_t ReCreateSessionServerToServer(ListNode *sessionServerInfoList);
|
||||
void ClientTransRegLnnOffline(void);
|
||||
|
||||
void ClientTransOnLinkDown(const char *networkId, int32_t routeType);
|
||||
@ -204,8 +210,6 @@ void PermissionStateChange(const char *pkgName, int32_t state);
|
||||
|
||||
int32_t ClientAddSocketServer(SoftBusSecType type, const char *pkgName, const char *sessionName);
|
||||
|
||||
int32_t ClientDeleteSocketSession(int32_t sessionId);
|
||||
|
||||
int32_t ClientAddSocketSession(
|
||||
const SessionParam *param, bool isEncyptedRawStream, int32_t *sessionId, SessionEnableStatus *isEnabled);
|
||||
|
||||
@ -238,23 +242,35 @@ int32_t SetSessionIsAsyncById(int32_t sessionId, bool isAsync);
|
||||
|
||||
int32_t ClientTransSetChannelInfo(const char *sessionName, int32_t sessionId, int32_t channelId, int32_t channelType);
|
||||
|
||||
int32_t ClientDfsIpcOpenSession(int32_t sessionId, TransInfo *transInfo);
|
||||
|
||||
void DelSessionStateClosing(void);
|
||||
int32_t GetSocketLifecycleAndSessionNameBySessionId(
|
||||
int32_t sessionId, char *sessionName, SocketLifecycleData *lifecycle);
|
||||
int32_t SetSessionStateBySessionId(int32_t sessionId, SessionState sessionState, int32_t optional);
|
||||
|
||||
int32_t ClientHandleBindWaitTimer(int32_t socket, uint32_t maxWaitTime, TimerAction action);
|
||||
int32_t GetQosValue(const QosTV *qos, uint32_t qosCount, QosType type, int32_t *value, int32_t defVal);
|
||||
|
||||
inline bool IsValidQosInfo(const QosTV qos[], uint32_t qosCount)
|
||||
{
|
||||
return (qos == NULL) ? (qosCount == 0) : (qosCount <= QOS_TYPE_BUTT);
|
||||
}
|
||||
int32_t ClientWaitSyncBind(int32_t socket);
|
||||
int32_t ClientSignalSyncBind(int32_t socket, int32_t errCode);
|
||||
|
||||
void AddSessionStateClosing(void);
|
||||
|
||||
int32_t SetSessionInitInfoById(int32_t sessionId);
|
||||
|
||||
int32_t ClientSetEnableStatusBySocket(int32_t socket, SessionEnableStatus enableStatus);
|
||||
|
||||
int32_t TryDeleteEmptySessionServer(const char *pkgName, const char *sessionName);
|
||||
|
||||
int32_t DeleteSocketSession(int32_t sessionId, char *pkgName, char *sessionName);
|
||||
|
||||
int32_t SetSessionStateBySessionId(int32_t sessionId, SessionState sessionState, int32_t optional);
|
||||
|
||||
int32_t GetSocketLifecycleAndSessionNameBySessionId(
|
||||
int32_t sessionId, char *sessionName, SocketLifecycleData *lifecycle);
|
||||
|
||||
int32_t ClientWaitSyncBind(int32_t socket);
|
||||
|
||||
int32_t ClientSignalSyncBind(int32_t socket, int32_t errCode);
|
||||
|
||||
int32_t ClientDfsIpcOpenSession(int32_t sessionId, TransInfo *transInfo);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CLIENT_TRANS_SESSION_OPERATE_H
|
||||
#define CLIENT_TRANS_SESSION_OPERATE_H
|
||||
|
||||
#include "session.h"
|
||||
#include "socket.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_trans_def.h"
|
||||
#include "client_trans_session_adapter.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t GenerateSessionId(void);
|
||||
|
||||
void DestroySessionId(void);
|
||||
|
||||
bool IsValidSessionParam(const SessionParam *param);
|
||||
|
||||
SessionInfo *CreateNewSession(const SessionParam *param);
|
||||
|
||||
NO_SANITIZE("cfi") DestroySessionInfo *CreateDestroySessionNode(SessionInfo *sessionNode,
|
||||
const ClientSessionServer *server);
|
||||
|
||||
NO_SANITIZE("cfi") void ClientDestroySession(const ListNode *destroyList, ShutdownReason reason);
|
||||
|
||||
void DestroyClientSessionServer(ClientSessionServer *server, ListNode *destroyList);
|
||||
|
||||
ClientSessionServer *GetNewSessionServer(SoftBusSecType type, const char *sessionName,
|
||||
const char *pkgName, const ISessionListener *listener);
|
||||
|
||||
SessionInfo *CreateNonEncryptSessionInfo(const char *sessionName);
|
||||
|
||||
void DestroyClientSessionByNetworkId(const ClientSessionServer *server,
|
||||
const char *networkId, int32_t type, ListNode *destroyList);
|
||||
|
||||
SessionServerInfo *CreateSessionServerInfoNode(const ClientSessionServer *clientSessionServer);
|
||||
|
||||
ClientSessionServer *GetNewSocketServer(SoftBusSecType type, const char *sessionName, const char *pkgName);
|
||||
|
||||
bool IsDistributedDataSession(const char *sessionName);
|
||||
|
||||
bool IsDifferentDataType(const SessionInfo *sessionInfo, int dataType, bool isEncyptedRawStream);
|
||||
|
||||
SessionInfo *CreateNewSocketSession(const SessionParam *param);
|
||||
|
||||
int32_t CheckBindSocketInfo(const SessionInfo *session);
|
||||
|
||||
void FillSessionParam(SessionParam *param, SessionAttribute *tmpAttr,
|
||||
ClientSessionServer *serverNode, SessionInfo *sessionNode);
|
||||
|
||||
void ClientConvertRetVal(int32_t socket, int32_t *retOut);
|
||||
|
||||
void ClientCleanUpIdleTimeoutSocket(const ListNode *destroyList);
|
||||
|
||||
void ClientCheckWaitTimeOut(SessionInfo *sessionNode, int32_t waitOutSocket[], uint32_t capacity, uint32_t *num);
|
||||
|
||||
void ClientCleanUpWaitTimeoutSocket(int32_t waitOutSocket[], uint32_t waitOutNum);
|
||||
|
||||
void ClientUpdateIdleTimeout(const ClientSessionServer *serverNode, SessionInfo *sessionNode, ListNode *destroyList);
|
||||
|
||||
int32_t ClientDeleteSocketSession(int32_t sessionId);
|
||||
|
||||
int32_t ClientRemovePermission(const char *busName);
|
||||
|
||||
int32_t ClientGrantPermission(int uid, int pid, const char *busName);
|
||||
|
||||
int32_t GetQosValue(const QosTV *qos, uint32_t qosCount, QosType type, int32_t *value, int32_t defVal);
|
||||
|
||||
int32_t ReCreateSessionServerToServer(ListNode *sessionServerInfoList);
|
||||
|
||||
void FillDfsSocketParam(
|
||||
SessionParam *param, SessionAttribute *tmpAttr, ClientSessionServer *serverNode, SessionInfo *sessionNode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // CLIENT_TRANS_SESSION_OPERATE_H
|
@ -20,6 +20,7 @@
|
||||
#include "client_trans_file_listener.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_session_service.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_statistics.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "anonymizer.h"
|
||||
#include "client_trans_proxy_manager.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_udp_manager.h"
|
||||
#include "session_set_timer.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -27,6 +27,7 @@
|
||||
#include "client_trans_file_listener.h"
|
||||
#include "client_trans_session_adapter.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "dfs_session.h"
|
||||
#include "inner_session.h"
|
||||
#include "securec.h"
|
||||
|
815
sdk/transmission/session/src/client_trans_socket_manager.c
Normal file
815
sdk/transmission/session/src/client_trans_socket_manager.c
Normal file
@ -0,0 +1,815 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "client_trans_socket_manager.h"
|
||||
|
||||
#include <securec.h>
|
||||
|
||||
#include "anonymizer.h"
|
||||
#include "client_bus_center_manager.h"
|
||||
#include "client_trans_channel_manager.h"
|
||||
#include "client_trans_file_listener.h"
|
||||
#include "client_trans_proxy_file_manager.h"
|
||||
#include "client_trans_tcp_direct_manager.h"
|
||||
#include "client_trans_udp_manager.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_app_info.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_socket.h"
|
||||
#include "softbus_utils.h"
|
||||
#include "trans_log.h"
|
||||
#include "trans_server_proxy.h"
|
||||
|
||||
#define NETWORK_ID_LEN 7
|
||||
#define HML_IP_PREFIX "172.30."
|
||||
#define GET_ROUTE_TYPE(type) ((type) & 0xff)
|
||||
#define GET_CONN_TYPE(type) (((type) >> 8) & 0xff)
|
||||
|
||||
#define DISTRIBUTED_DATA_SESSION "distributeddata-default"
|
||||
|
||||
bool IsValidSessionParam(const SessionParam *param)
|
||||
{
|
||||
if ((param == NULL) ||
|
||||
(param->sessionName == NULL) ||
|
||||
(param->peerSessionName == NULL) ||
|
||||
(param->peerDeviceId == NULL) ||
|
||||
(param->groupId == NULL) ||
|
||||
(param->attr == NULL)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
SessionInfo *CreateNewSession(const SessionParam *param)
|
||||
{
|
||||
if (param == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "param is null");
|
||||
return NULL;
|
||||
}
|
||||
SessionInfo *session = (SessionInfo*)SoftBusCalloc(sizeof(SessionInfo));
|
||||
if (session == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "calloc failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strcpy_s(session->info.peerSessionName, SESSION_NAME_SIZE_MAX, param->peerSessionName) != EOK ||
|
||||
strcpy_s(session->info.peerDeviceId, DEVICE_ID_SIZE_MAX, param->peerDeviceId) != EOK ||
|
||||
strcpy_s(session->info.groupId, GROUP_ID_SIZE_MAX, param->groupId) != EOK ||
|
||||
memcpy_s(session->linkType, sizeof(param->attr->linkType), param->attr->linkType,
|
||||
sizeof(param->attr->linkType)) != EOK) {
|
||||
TRANS_LOGE(TRANS_SDK, "strcpy failed");
|
||||
SoftBusFree(session);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
session->sessionId = INVALID_SESSION_ID;
|
||||
session->channelId = INVALID_CHANNEL_ID;
|
||||
session->channelType = CHANNEL_TYPE_BUTT;
|
||||
session->isServer = false;
|
||||
session->role = SESSION_ROLE_INIT;
|
||||
session->enableStatus = ENABLE_STATUS_INIT;
|
||||
session->info.flag = param->attr->dataType;
|
||||
session->isEncrypt = true;
|
||||
session->isAsync = false;
|
||||
session->lifecycle.sessionState = SESSION_STATE_INIT;
|
||||
return session;
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi") DestroySessionInfo *CreateDestroySessionNode(SessionInfo *sessionNode,
|
||||
const ClientSessionServer *server)
|
||||
{
|
||||
if (sessionNode == NULL || server == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param.");
|
||||
return NULL;
|
||||
}
|
||||
DestroySessionInfo *destroyNode = (DestroySessionInfo *)SoftBusCalloc(sizeof(DestroySessionInfo));
|
||||
if (destroyNode == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "destroyList malloc fail.");
|
||||
return NULL;
|
||||
}
|
||||
destroyNode->sessionId = sessionNode->sessionId;
|
||||
destroyNode->channelId = sessionNode->channelId;
|
||||
destroyNode->channelType = sessionNode->channelType;
|
||||
if (memcpy_s(destroyNode->sessionName, SESSION_NAME_SIZE_MAX, server->sessionName, SESSION_NAME_SIZE_MAX) != EOK) {
|
||||
TRANS_LOGE(TRANS_SDK, "memcpy_s sessionName fail.");
|
||||
SoftBusFree(destroyNode);
|
||||
return NULL;
|
||||
}
|
||||
if (memcpy_s(destroyNode->pkgName, PKG_NAME_SIZE_MAX, server->pkgName, PKG_NAME_SIZE_MAX) != EOK) {
|
||||
TRANS_LOGE(TRANS_SDK, "memcpy_s pkgName fail.");
|
||||
SoftBusFree(destroyNode);
|
||||
return NULL;
|
||||
}
|
||||
destroyNode->OnSessionClosed = server->listener.session.OnSessionClosed;
|
||||
destroyNode->OnShutdown = sessionNode->isServer ? server->listener.socketServer.OnShutdown :
|
||||
server->listener.socketClient.OnShutdown;
|
||||
return destroyNode;
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi") void ClientDestroySession(const ListNode *destroyList, ShutdownReason reason)
|
||||
{
|
||||
if (destroyList == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param.");
|
||||
return;
|
||||
}
|
||||
if (IsListEmpty(destroyList)) {
|
||||
TRANS_LOGD(TRANS_SDK, "destroyList is empty fail.");
|
||||
return;
|
||||
}
|
||||
DestroySessionInfo *destroyNode = NULL;
|
||||
DestroySessionInfo *destroyNodeNext = NULL;
|
||||
TRANS_LOGD(TRANS_SDK, "enter.");
|
||||
LIST_FOR_EACH_ENTRY_SAFE(destroyNode, destroyNodeNext, destroyList, DestroySessionInfo, node) {
|
||||
int32_t id = destroyNode->sessionId;
|
||||
(void)ClientDeleteRecvFileList(id);
|
||||
(void)ClientTransCloseChannel(destroyNode->channelId, destroyNode->channelType);
|
||||
if (destroyNode->OnSessionClosed != NULL) {
|
||||
destroyNode->OnSessionClosed(id);
|
||||
} else if (destroyNode->OnShutdown != NULL) {
|
||||
destroyNode->OnShutdown(id, reason);
|
||||
(void)TryDeleteEmptySessionServer(destroyNode->pkgName, destroyNode->sessionName);
|
||||
}
|
||||
ListDelete(&(destroyNode->node));
|
||||
SoftBusFree(destroyNode);
|
||||
}
|
||||
TRANS_LOGD(TRANS_SDK, "ok");
|
||||
}
|
||||
|
||||
void DestroyClientSessionServer(ClientSessionServer *server, ListNode *destroyList)
|
||||
{
|
||||
if (server == NULL || destroyList == NULL) {
|
||||
TRANS_LOGW(TRANS_SDK, "invalid param");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsListEmpty(&(server->sessionList))) {
|
||||
SessionInfo *sessionNode = NULL;
|
||||
SessionInfo *sessionNodeNext = NULL;
|
||||
LIST_FOR_EACH_ENTRY_SAFE(sessionNode, sessionNodeNext, &(server->sessionList), SessionInfo, node) {
|
||||
DestroySessionInfo *destroyNode = CreateDestroySessionNode(sessionNode, server);
|
||||
if (destroyNode == NULL) {
|
||||
continue;
|
||||
}
|
||||
DestroySessionId();
|
||||
ListDelete(&sessionNode->node);
|
||||
ListAdd(destroyList, &(destroyNode->node));
|
||||
SoftBusFree(sessionNode);
|
||||
}
|
||||
}
|
||||
|
||||
ListDelete(&(server->node));
|
||||
char *tmpName = NULL;
|
||||
Anonymize(server->sessionName, &tmpName);
|
||||
TRANS_LOGI(TRANS_SDK, "destroy session server sessionName=%{public}s", tmpName);
|
||||
AnonymizeFree(tmpName);
|
||||
SoftBusFree(server);
|
||||
}
|
||||
|
||||
ClientSessionServer *GetNewSessionServer(SoftBusSecType type, const char *sessionName,
|
||||
const char *pkgName, const ISessionListener *listener)
|
||||
{
|
||||
if (sessionName == NULL || pkgName == NULL || listener == NULL) {
|
||||
TRANS_LOGW(TRANS_SDK, "invalid param");
|
||||
return NULL;
|
||||
}
|
||||
ClientSessionServer *server = (ClientSessionServer *)SoftBusCalloc(sizeof(ClientSessionServer));
|
||||
if (server == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
server->type = type;
|
||||
if (strcpy_s(server->pkgName, sizeof(server->pkgName), pkgName) != EOK) {
|
||||
goto EXIT_ERR;
|
||||
}
|
||||
if (strcpy_s(server->sessionName, sizeof(server->sessionName), sessionName) != EOK) {
|
||||
goto EXIT_ERR;
|
||||
}
|
||||
if (memcpy_s(&server->listener.session, sizeof(ISessionListener), listener, sizeof(ISessionListener)) != EOK) {
|
||||
goto EXIT_ERR;
|
||||
}
|
||||
server->listener.isSocketListener = false;
|
||||
server->isSrvEncryptedRawStream = false;
|
||||
|
||||
ListInit(&server->node);
|
||||
ListInit(&server->sessionList);
|
||||
return server;
|
||||
|
||||
EXIT_ERR:
|
||||
if (server != NULL) {
|
||||
SoftBusFree(server);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SessionInfo *CreateNonEncryptSessionInfo(const char *sessionName)
|
||||
{
|
||||
if (sessionName == NULL) {
|
||||
TRANS_LOGW(TRANS_SDK, "Invalid param");
|
||||
return NULL;
|
||||
}
|
||||
if (!IsValidString(sessionName, SESSION_NAME_SIZE_MAX - 1)) {
|
||||
TRANS_LOGW(TRANS_SDK, "Invalid param");
|
||||
return NULL;
|
||||
}
|
||||
SessionInfo *session = (SessionInfo *)SoftBusCalloc(sizeof(SessionInfo));
|
||||
if (session == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
session->channelType = CHANNEL_TYPE_AUTH;
|
||||
session->isEncrypt = false;
|
||||
if (strcpy_s(session->info.peerSessionName, SESSION_NAME_SIZE_MAX, sessionName) != EOK) {
|
||||
SoftBusFree(session);
|
||||
return NULL;
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
static int32_t ClientTransGetTdcIp(int32_t channelId, char *myIp, int32_t ipLen)
|
||||
{
|
||||
TcpDirectChannelInfo channel;
|
||||
if (TransTdcGetInfoById(channelId, &channel) == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "not found Tdc channel by channelId=%{public}d", channelId);
|
||||
return SOFTBUS_TRANS_TDC_CHANNEL_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (strcpy_s(myIp, ipLen, channel.detail.myIp) != EOK) {
|
||||
TRANS_LOGE(TRANS_SDK, "strcpy_s ip failed, len=%{public}zu", strlen(channel.detail.myIp));
|
||||
return SOFTBUS_STRCPY_ERR;
|
||||
}
|
||||
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t ClientTransGetUdpIp(int32_t channelId, char *myIp, int32_t ipLen)
|
||||
{
|
||||
UdpChannel channel;
|
||||
if (TransGetUdpChannel(channelId, &channel) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SDK, "not found Udp channel by channelId=%{public}d", channelId);
|
||||
return SOFTBUS_TRANS_UDP_CHANNEL_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (strcpy_s(myIp, ipLen, channel.info.myIp) != EOK) {
|
||||
TRANS_LOGE(TRANS_SDK, "strcpy_s ip failed, len=%{public}zu", strlen(channel.info.myIp));
|
||||
return SOFTBUS_STRCPY_ERR;
|
||||
}
|
||||
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
// determine connection type based on IP
|
||||
static bool ClientTransCheckHmlIp(const char *ip)
|
||||
{
|
||||
if (strncmp(ip, HML_IP_PREFIX, NETWORK_ID_LEN) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// determine connection type based on IP, delete session when connection type and parameter connType are consistent
|
||||
static bool ClientTransCheckNeedDel(SessionInfo *sessionNode, int32_t routeType, int32_t connType)
|
||||
{
|
||||
if (connType == TRANS_CONN_ALL) {
|
||||
if (routeType != ROUTE_TYPE_ALL && sessionNode->routeType != routeType) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
* only when the function OnWifiDirectDeviceOffLine is called can reach this else branch,
|
||||
* and routeType is WIFI_P2P, the connType is hml or p2p
|
||||
*/
|
||||
if (sessionNode->routeType != routeType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char myIp[IP_LEN] = {0};
|
||||
if (sessionNode->channelType == CHANNEL_TYPE_UDP) {
|
||||
if (ClientTransGetUdpIp(sessionNode->channelId, myIp, sizeof(myIp)) != SOFTBUS_OK) {
|
||||
return false;
|
||||
}
|
||||
} else if (sessionNode->channelType == CHANNEL_TYPE_TCP_DIRECT) {
|
||||
if (ClientTransGetTdcIp(sessionNode->channelId, myIp, sizeof(myIp)) != SOFTBUS_OK) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
TRANS_LOGW(TRANS_SDK, "check channelType=%{public}d", sessionNode->channelType);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isHml = ClientTransCheckHmlIp(myIp);
|
||||
if (connType == TRANS_CONN_HML && isHml) {
|
||||
return true;
|
||||
} else if (connType == TRANS_CONN_P2P && !isHml) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void DestroyClientSessionByNetworkId(const ClientSessionServer *server,
|
||||
const char *networkId, int32_t type, ListNode *destroyList)
|
||||
{
|
||||
if (server == NULL || networkId == NULL || destroyList == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param.");
|
||||
return;
|
||||
}
|
||||
SessionInfo *sessionNode = NULL;
|
||||
SessionInfo *sessionNodeNext = NULL;
|
||||
// connType is set only in function OnWifiDirectDeviceOffLine, others is TRANS_CONN_ALL, and routeType is WIFI_P2P
|
||||
int32_t routeType = GET_ROUTE_TYPE(type);
|
||||
int32_t connType = GET_CONN_TYPE(type);
|
||||
|
||||
LIST_FOR_EACH_ENTRY_SAFE(sessionNode, sessionNodeNext, &(server->sessionList), SessionInfo, node) {
|
||||
if (strcmp(sessionNode->info.peerDeviceId, networkId) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ClientTransCheckNeedDel(sessionNode, routeType, connType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TRANS_LOGI(TRANS_SDK, "channelId=%{public}d, channelType=%{public}d, routeType=%{public}d, type=%{public}d",
|
||||
sessionNode->channelId, sessionNode->channelType, sessionNode->routeType, type);
|
||||
DestroySessionInfo *destroyNode = CreateDestroySessionNode(sessionNode, server);
|
||||
if (destroyNode == NULL) {
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
* When the channel type is UDP and the business type is file, trigger DFILE_ON_CLEAR_POLICY_FILE_LIST event
|
||||
* before cleaning up sessionNode.
|
||||
*/
|
||||
if (sessionNode->channelType == CHANNEL_TYPE_UDP && sessionNode->businessType == BUSINESS_TYPE_FILE) {
|
||||
ClientEmitFileEvent(sessionNode->channelId);
|
||||
}
|
||||
DestroySessionId();
|
||||
ListDelete(&sessionNode->node);
|
||||
ListAdd(destroyList, &(destroyNode->node));
|
||||
SoftBusFree(sessionNode);
|
||||
}
|
||||
}
|
||||
|
||||
SessionServerInfo *CreateSessionServerInfoNode(const ClientSessionServer *clientSessionServer)
|
||||
{
|
||||
if (clientSessionServer == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SessionServerInfo *infoNode = (SessionServerInfo *)SoftBusCalloc(sizeof(SessionServerInfo));
|
||||
if (infoNode == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "failed to malloc SessionServerInfo.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strcpy_s(infoNode->pkgName, SESSION_NAME_SIZE_MAX, clientSessionServer->pkgName) != EOK) {
|
||||
SoftBusFree(infoNode);
|
||||
TRANS_LOGE(TRANS_SDK, "failed to strcpy pkgName.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strcpy_s(infoNode->sessionName, SESSION_NAME_SIZE_MAX, clientSessionServer->sessionName) != EOK) {
|
||||
SoftBusFree(infoNode);
|
||||
TRANS_LOGE(TRANS_SDK, "failed to strcpy sessionName.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return infoNode;
|
||||
}
|
||||
|
||||
ClientSessionServer *GetNewSocketServer(SoftBusSecType type, const char *sessionName, const char *pkgName)
|
||||
{
|
||||
if (sessionName == NULL || pkgName == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param.");
|
||||
return NULL;
|
||||
}
|
||||
ClientSessionServer *server = (ClientSessionServer *)SoftBusCalloc(sizeof(ClientSessionServer));
|
||||
if (server == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
server->type = type;
|
||||
if (strcpy_s(server->pkgName, sizeof(server->pkgName), pkgName) != EOK) {
|
||||
goto EXIT_ERR;
|
||||
}
|
||||
if (strcpy_s(server->sessionName, sizeof(server->sessionName), sessionName) != EOK) {
|
||||
goto EXIT_ERR;
|
||||
}
|
||||
server->isSrvEncryptedRawStream = false;
|
||||
ListInit(&server->node);
|
||||
ListInit(&server->sessionList);
|
||||
return server;
|
||||
|
||||
EXIT_ERR:
|
||||
if (server != NULL) {
|
||||
SoftBusFree(server);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool IsDistributedDataSession(const char *sessionName)
|
||||
{
|
||||
if (sessionName == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param.");
|
||||
return false;
|
||||
}
|
||||
uint32_t distributedDataSessionLen = strlen(DISTRIBUTED_DATA_SESSION);
|
||||
if (strlen(sessionName) < distributedDataSessionLen ||
|
||||
strncmp(sessionName, DISTRIBUTED_DATA_SESSION, distributedDataSessionLen) != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsDifferentDataType(const SessionInfo *sessionInfo, int dataType, bool isEncyptedRawStream)
|
||||
{
|
||||
if (sessionInfo == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param.");
|
||||
return false;
|
||||
}
|
||||
if (sessionInfo->info.flag != dataType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (dataType != RAW_STREAM) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return sessionInfo->isEncyptedRawStream != isEncyptedRawStream;
|
||||
}
|
||||
|
||||
static void ClientInitSession(SessionInfo *session, const SessionParam *param)
|
||||
{
|
||||
session->sessionId = INVALID_SESSION_ID;
|
||||
session->channelId = INVALID_CHANNEL_ID;
|
||||
session->channelType = CHANNEL_TYPE_BUTT;
|
||||
session->isServer = false;
|
||||
session->role = SESSION_ROLE_INIT;
|
||||
session->enableStatus = ENABLE_STATUS_INIT;
|
||||
session->info.flag = param->attr->dataType;
|
||||
session->info.streamType = param->attr->attr.streamAttr.streamType;
|
||||
session->isEncrypt = true;
|
||||
session->isAsync = false;
|
||||
session->lifecycle.sessionState = SESSION_STATE_INIT;
|
||||
}
|
||||
|
||||
SessionInfo *CreateNewSocketSession(const SessionParam *param)
|
||||
{
|
||||
if (param == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param.");
|
||||
return NULL;
|
||||
}
|
||||
SessionInfo *session = (SessionInfo *)SoftBusCalloc(sizeof(SessionInfo));
|
||||
if (session == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "calloc failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (param->peerSessionName != NULL &&
|
||||
strcpy_s(session->info.peerSessionName, SESSION_NAME_SIZE_MAX, param->peerSessionName) != EOK) {
|
||||
char *anonySessionName = NULL;
|
||||
Anonymize(param->peerSessionName, &anonySessionName);
|
||||
TRANS_LOGI(TRANS_SDK, "strcpy peerName failed, peerName=%{public}s, peerNameLen=%{public}zu",
|
||||
anonySessionName, strlen(param->peerSessionName));
|
||||
AnonymizeFree(anonySessionName);
|
||||
SoftBusFree(session);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (param->peerDeviceId != NULL &&
|
||||
strcpy_s(session->info.peerDeviceId, DEVICE_ID_SIZE_MAX, param->peerDeviceId) != EOK) {
|
||||
char *anonyNetworkId = NULL;
|
||||
Anonymize(param->peerDeviceId, &anonyNetworkId);
|
||||
TRANS_LOGI(TRANS_SDK, "strcpy peerDeviceId failed, peerDeviceId=%{public}s, peerDeviceIdLen=%{public}zu",
|
||||
anonyNetworkId, strlen(param->peerDeviceId));
|
||||
AnonymizeFree(anonyNetworkId);
|
||||
SoftBusFree(session);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strcpy_s(session->info.groupId, GROUP_ID_SIZE_MAX, param->groupId) != EOK ||
|
||||
memcpy_s(session->linkType, sizeof(param->attr->linkType), param->attr->linkType,
|
||||
sizeof(param->attr->linkType)) != EOK) {
|
||||
TRANS_LOGE(TRANS_SDK, "strcpy failed");
|
||||
SoftBusFree(session);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (SoftBusCondInit(&session->lifecycle.callbackCond) != SOFTBUS_OK) {
|
||||
SoftBusFree(session);
|
||||
TRANS_LOGE(TRANS_SDK, "callbackCond Init failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ClientInitSession(session, param);
|
||||
return session;
|
||||
}
|
||||
|
||||
int32_t CheckBindSocketInfo(const SessionInfo *session)
|
||||
{
|
||||
if (session == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param.");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (!IsValidString(session->info.peerSessionName, SESSION_NAME_SIZE_MAX - 1) ||
|
||||
!IsValidString(session->info.peerDeviceId, DEVICE_ID_SIZE_MAX - 1)) {
|
||||
char *anonySessionName = NULL;
|
||||
char *anonyNetworkId = NULL;
|
||||
Anonymize(session->info.peerSessionName, &anonySessionName);
|
||||
Anonymize(session->info.peerDeviceId, &anonyNetworkId);
|
||||
TRANS_LOGI(TRANS_SDK, "invalid peerName=%{public}s, peerNameLen=%{public}zu, peerNetworkId=%{public}s, "
|
||||
"peerNetworkIdLen=%{public}zu", anonySessionName,
|
||||
strlen(session->info.peerSessionName), anonyNetworkId, strlen(session->info.peerDeviceId));
|
||||
AnonymizeFree(anonyNetworkId);
|
||||
AnonymizeFree(anonySessionName);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (session->info.flag < TYPE_MESSAGE || session->info.flag >= TYPE_BUTT) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid dataType");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
void FillSessionParam(SessionParam *param, SessionAttribute *tmpAttr,
|
||||
ClientSessionServer *serverNode, SessionInfo *sessionNode)
|
||||
{
|
||||
if (param == NULL || tmpAttr == NULL || serverNode == NULL || sessionNode == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param.");
|
||||
return;
|
||||
}
|
||||
tmpAttr->fastTransData = NULL;
|
||||
tmpAttr->fastTransDataSize = 0;
|
||||
tmpAttr->dataType = sessionNode->info.flag;
|
||||
tmpAttr->attr.streamAttr.streamType = sessionNode->info.streamType;
|
||||
tmpAttr->linkTypeNum = 0;
|
||||
param->sessionName = serverNode->sessionName;
|
||||
param->peerSessionName = sessionNode->info.peerSessionName;
|
||||
param->peerDeviceId = sessionNode->info.peerDeviceId;
|
||||
param->groupId = "reserved";
|
||||
param->attr = tmpAttr;
|
||||
param->isQosLane = true;
|
||||
}
|
||||
|
||||
void ClientConvertRetVal(int32_t socket, int32_t *retOut)
|
||||
{
|
||||
if (retOut == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param.");
|
||||
return;
|
||||
}
|
||||
SocketLifecycleData lifecycle;
|
||||
(void)memset_s(&lifecycle, sizeof(SocketLifecycleData), 0, sizeof(SocketLifecycleData));
|
||||
int32_t ret = GetSocketLifecycleAndSessionNameBySessionId(socket, NULL, &lifecycle);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SDK, "get info fail, socket=%{public}d", socket);
|
||||
return;
|
||||
}
|
||||
|
||||
if (lifecycle.bindErrCode == SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SDK, "bindErrCode is SOFTBUS_OK, socket=%{public}d", socket);
|
||||
return;
|
||||
}
|
||||
*retOut = lifecycle.bindErrCode;
|
||||
}
|
||||
|
||||
void ClientCleanUpIdleTimeoutSocket(const ListNode *destroyList)
|
||||
{
|
||||
if (destroyList == NULL || IsListEmpty(destroyList)) {
|
||||
TRANS_LOGD(TRANS_SDK, "destroyList is empty.");
|
||||
return;
|
||||
}
|
||||
DestroySessionInfo *destroyNode = NULL;
|
||||
DestroySessionInfo *destroyNodeNext = NULL;
|
||||
LIST_FOR_EACH_ENTRY_SAFE(destroyNode, destroyNodeNext, destroyList, DestroySessionInfo, node) {
|
||||
int32_t id = destroyNode->sessionId;
|
||||
(void)ClientDeleteRecvFileList(id);
|
||||
(void)ClientTransCloseChannel(destroyNode->channelId, destroyNode->channelType);
|
||||
TRANS_LOGI(TRANS_SDK, "session is idle, sessionId=%{public}d", id);
|
||||
if (destroyNode->OnShutdown != NULL) {
|
||||
destroyNode->OnShutdown(id, SHUTDOWN_REASON_TIMEOUT);
|
||||
(void)TryDeleteEmptySessionServer(destroyNode->pkgName, destroyNode->sessionName);
|
||||
}
|
||||
ListDelete(&(destroyNode->node));
|
||||
SoftBusFree(destroyNode);
|
||||
}
|
||||
TRANS_LOGD(TRANS_SDK, "ok");
|
||||
}
|
||||
|
||||
void ClientCheckWaitTimeOut(SessionInfo *sessionNode, int32_t waitOutSocket[], uint32_t capacity, uint32_t *num)
|
||||
{
|
||||
if (sessionNode == NULL || waitOutSocket == NULL || num == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param.");
|
||||
return;
|
||||
}
|
||||
if (sessionNode->enableStatus == ENABLE_STATUS_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
|
||||
sessionNode->lifecycle.waitTime += TIMER_TIMEOUT;
|
||||
if (sessionNode->lifecycle.maxWaitTime == 0 ||
|
||||
sessionNode->lifecycle.waitTime <= sessionNode->lifecycle.maxWaitTime) {
|
||||
TRANS_LOGD(TRANS_SDK, "no wait timeout, socket=%{public}d", sessionNode->sessionId);
|
||||
return;
|
||||
}
|
||||
|
||||
TRANS_LOGW(TRANS_SDK, "bind time out socket=%{public}d", sessionNode->sessionId);
|
||||
// stop check time out
|
||||
sessionNode->lifecycle.maxWaitTime = 0;
|
||||
|
||||
uint32_t tmpNum = *num;
|
||||
if (tmpNum + 1 > capacity) {
|
||||
TRANS_LOGE(TRANS_SDK, "socket num invalid tmpNum=%{public}u, capacity=%{public}u", tmpNum, capacity);
|
||||
return;
|
||||
}
|
||||
waitOutSocket[tmpNum] = sessionNode->sessionId;
|
||||
*num = tmpNum + 1;
|
||||
}
|
||||
|
||||
void ClientCleanUpWaitTimeoutSocket(int32_t waitOutSocket[], uint32_t waitOutNum)
|
||||
{
|
||||
if (waitOutSocket == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param.");
|
||||
return;
|
||||
}
|
||||
bool tmpIsServer = false;
|
||||
SessionListenerAdapter callback = { 0 };
|
||||
for (uint32_t i = 0; i < waitOutNum; ++i) {
|
||||
TRANS_LOGI(TRANS_SDK, "time out shutdown socket=%{public}d", waitOutSocket[i]);
|
||||
ClientGetSessionCallbackAdapterById(waitOutSocket[i], &callback, &tmpIsServer);
|
||||
if (callback.socketClient.OnError != NULL) {
|
||||
(void)callback.socketClient.OnError(waitOutSocket[i], SOFTBUS_TRANS_STOP_BIND_BY_TIMEOUT);
|
||||
}
|
||||
ClientShutdown(waitOutSocket[i], SOFTBUS_TRANS_STOP_BIND_BY_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
void ClientUpdateIdleTimeout(const ClientSessionServer *serverNode, SessionInfo *sessionNode, ListNode *destroyList)
|
||||
{
|
||||
if (serverNode == NULL || sessionNode == NULL || destroyList == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param.");
|
||||
return;
|
||||
}
|
||||
if (sessionNode->role != SESSION_ROLE_CLIENT || sessionNode->enableStatus != ENABLE_STATUS_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
|
||||
sessionNode->timeout += TIMER_TIMEOUT;
|
||||
if (sessionNode->maxIdleTime == 0 || sessionNode->timeout <= sessionNode->maxIdleTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
DestroySessionInfo *destroyNode = CreateDestroySessionNode(sessionNode, serverNode);
|
||||
if (destroyNode == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "failed to create destory session Node, sessionId=%{public}d", sessionNode->sessionId);
|
||||
return;
|
||||
}
|
||||
ListAdd(destroyList, &(destroyNode->node));
|
||||
DestroySessionId();
|
||||
ListDelete(&sessionNode->node);
|
||||
SoftBusFree(sessionNode);
|
||||
}
|
||||
|
||||
int32_t ReCreateSessionServerToServer(ListNode *sessionServerInfoList)
|
||||
{
|
||||
TRANS_LOGD(TRANS_SDK, "enter.");
|
||||
if (sessionServerInfoList == NULL) {
|
||||
TRANS_LOGE(TRANS_INIT, "session server list not init");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
SessionServerInfo *infoNode = NULL;
|
||||
SessionServerInfo *infoNodeNext = NULL;
|
||||
char *tmpName = NULL;
|
||||
LIST_FOR_EACH_ENTRY_SAFE(infoNode, infoNodeNext, sessionServerInfoList, SessionServerInfo, node) {
|
||||
int32_t ret = ServerIpcCreateSessionServer(infoNode->pkgName, infoNode->sessionName);
|
||||
Anonymize(infoNode->sessionName, &tmpName);
|
||||
TRANS_LOGI(TRANS_SDK, "sessionName=%{public}s, pkgName=%{public}s, ret=%{public}d",
|
||||
tmpName, infoNode->pkgName, ret);
|
||||
AnonymizeFree(tmpName);
|
||||
ListDelete(&infoNode->node);
|
||||
SoftBusFree(infoNode);
|
||||
}
|
||||
|
||||
TRANS_LOGI(TRANS_SDK, "ok");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
void FillDfsSocketParam(
|
||||
SessionParam *param, SessionAttribute *tmpAttr, ClientSessionServer *serverNode, SessionInfo *sessionNode)
|
||||
{
|
||||
if (param == NULL || tmpAttr == NULL || serverNode == NULL || sessionNode == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param.");
|
||||
return;
|
||||
}
|
||||
tmpAttr->fastTransData = NULL;
|
||||
tmpAttr->fastTransDataSize = 0;
|
||||
tmpAttr->dataType = sessionNode->info.flag;
|
||||
tmpAttr->attr.streamAttr.streamType = sessionNode->info.streamType;
|
||||
// 2 means has two linkType
|
||||
tmpAttr->linkTypeNum = 2;
|
||||
tmpAttr->linkType[0] = LINK_TYPE_WIFI_WLAN_5G;
|
||||
tmpAttr->linkType[1] = LINK_TYPE_WIFI_WLAN_2G;
|
||||
param->sessionName = serverNode->sessionName;
|
||||
param->peerSessionName = sessionNode->info.peerSessionName;
|
||||
param->peerDeviceId = sessionNode->info.peerDeviceId;
|
||||
param->groupId = "reserved";
|
||||
param->attr = tmpAttr;
|
||||
param->isQosLane = false;
|
||||
param->qosCount = 0;
|
||||
(void)memset_s(param->qos, sizeof(param->qos), 0, sizeof(param->qos));
|
||||
param->isAsync = false;
|
||||
}
|
||||
|
||||
int32_t GetQosValue(const QosTV *qos, uint32_t qosCount, QosType type, int32_t *value, int32_t defVal)
|
||||
{
|
||||
if (!IsValidQosInfo(qos, qosCount) || value == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (qos == NULL || qosCount == 0) {
|
||||
TRANS_LOGW(TRANS_SDK, "no qos info, use defVal");
|
||||
*value = defVal;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < qosCount; i++) {
|
||||
if (qos[i].qos != type) {
|
||||
continue;
|
||||
}
|
||||
*value = qos[i].value;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
*value = defVal;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ClientGrantPermission(int uid, int pid, const char *busName)
|
||||
{
|
||||
if (uid < 0 || pid < 0 || busName == NULL) {
|
||||
TRANS_LOGW(TRANS_SDK, "invalid parameter");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
char *tmpName = NULL;
|
||||
Anonymize(busName, &tmpName);
|
||||
TRANS_LOGI(TRANS_SDK, "sessionName=%{public}s", tmpName);
|
||||
AnonymizeFree(tmpName);
|
||||
int32_t ret = ServerIpcGrantPermission(uid, pid, busName);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SDK, "server grant permission failed, ret=%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t ClientRemovePermission(const char *busName)
|
||||
{
|
||||
if (busName == NULL) {
|
||||
TRANS_LOGW(TRANS_SDK, "invalid parameter");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
char *tmpName = NULL;
|
||||
Anonymize(busName, &tmpName);
|
||||
TRANS_LOGI(TRANS_SDK, "sessionName=%{public}s", tmpName);
|
||||
AnonymizeFree(tmpName);
|
||||
int32_t ret = ServerIpcRemovePermission(busName);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SDK, "server remove permission failed, ret=%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t ClientDeleteSocketSession(int32_t sessionId)
|
||||
{
|
||||
if (sessionId <= 0) {
|
||||
TRANS_LOGE(TRANS_SDK, "Invalid sessionId=%{public}d", sessionId);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
char pkgName[PKG_NAME_SIZE_MAX] = { 0 };
|
||||
char sessionName[SESSION_NAME_SIZE_MAX] = { 0 };
|
||||
int32_t ret = DeleteSocketSession(sessionId, pkgName, sessionName);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SDK, "failed delete session");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = TryDeleteEmptySessionServer(pkgName, sessionName);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SDK, "delete empty session server failed, ret=%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
#include "anonymizer.h"
|
||||
#include "client_trans_session_adapter.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_socket_option.h"
|
||||
#include "inner_socket.h"
|
||||
#include "socket.h"
|
||||
|
@ -20,6 +20,7 @@ trans_session_sdk_src = [
|
||||
"$dsoftbus_sdk_path/transmission/session/src/client_trans_message_service.c",
|
||||
"$dsoftbus_sdk_path/transmission/session/src/client_trans_session_service.c",
|
||||
"$dsoftbus_sdk_path/transmission/session/src/client_trans_socket_service.c",
|
||||
"$dsoftbus_sdk_path/transmission/session/src/client_trans_socket_manager.c",
|
||||
]
|
||||
|
||||
broadcast_dep_dir = "dsoftbus_enhance/interfaces/kits/broadcast"
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "client_trans_auth_manager.h"
|
||||
#include "client_trans_proxy_manager.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_statistics.h"
|
||||
#include "client_trans_tcp_direct_manager.h"
|
||||
#include "client_trans_tcp_direct_callback.h"
|
||||
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CLIENT_TRANS_PROXY_FILE_HELPER_H
|
||||
#define CLIENT_TRANS_PROXY_FILE_HELPER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "client_trans_file_listener.h"
|
||||
#include "client_trans_proxy_file_common.h"
|
||||
#include "client_trans_proxy_file_manager.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t ProxyChannelSendFileStream(int32_t channelId, const char *data, uint32_t len, int32_t type);
|
||||
|
||||
int32_t SendFileTransResult(int32_t channelId, uint32_t seq, int32_t result, uint32_t side);
|
||||
|
||||
int32_t UnpackFileTransResultFrame(
|
||||
const uint8_t *data, uint32_t len, uint32_t *seq, int32_t *result, uint32_t *side);
|
||||
|
||||
int32_t SendFileAckReqAndResData(int32_t channelId, uint32_t startSeq, uint32_t value, int32_t type);
|
||||
|
||||
int32_t UnpackAckReqAndResData(FileFrame *frame, uint32_t *startSeq, uint32_t *value);
|
||||
|
||||
int64_t PackReadFileData(FileFrame *fileFrame, uint64_t readLength, uint64_t fileOffset, SendListenerInfo *info);
|
||||
|
||||
int32_t UnpackFileDataFrame(FileRecipientInfo *info, FileFrame *fileFrame, uint32_t *fileDataLen);
|
||||
|
||||
int32_t AckResponseDataHandle(const SendListenerInfo *info, const char *data, uint32_t len);
|
||||
|
||||
char *GetFullRecvPath(const char *filePath, const char *recvRootDir);
|
||||
|
||||
int32_t CreateDirAndGetAbsPath(const char *filePath, char *recvAbsPath, int32_t pathSize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // CLIENT_TRANS_PROXY_FILE_HELPER_H
|
@ -0,0 +1,463 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "client_trans_proxy_file_helper.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <securec.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "client_trans_proxy_file_manager.h"
|
||||
#include "client_trans_proxy_manager.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "softbus_adapter_errcode.h"
|
||||
#include "softbus_adapter_file.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_app_info.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_utils.h"
|
||||
#include "trans_log.h"
|
||||
|
||||
int32_t ProxyChannelSendFileStream(int32_t channelId, const char *data, uint32_t len, int32_t type)
|
||||
{
|
||||
if (data == NULL) {
|
||||
TRANS_LOGI(TRANS_FILE, "data is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
ProxyChannelInfoDetail info;
|
||||
(void)memset_s(&info, sizeof(ProxyChannelInfoDetail), 0, sizeof(ProxyChannelInfoDetail));
|
||||
int32_t ret = ClientTransProxyGetInfoByChannelId(channelId, &info);
|
||||
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret,
|
||||
TRANS_FILE, "client trans proxy get info by ChannelId fail");
|
||||
return TransProxyPackAndSendData(channelId, data, len, &info, (SessionPktType)type);
|
||||
}
|
||||
|
||||
int32_t SendFileTransResult(int32_t channelId, uint32_t seq, int32_t result, uint32_t side)
|
||||
{
|
||||
TRANS_LOGI(TRANS_FILE, "send file result seq=%{public}u, side=%{public}u, result=%{public}d", seq, side, result);
|
||||
uint32_t len = FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET + sizeof(uint32_t) + sizeof(int32_t);
|
||||
char *data = (char *)SoftBusCalloc(len);
|
||||
if (data == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "malloc failedLen=%{public}d.", len);
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
*(uint32_t *)data = FILE_MAGIC_NUMBER;
|
||||
*(uint64_t *)(data + FRAME_MAGIC_OFFSET) = (FRAME_DATA_SEQ_OFFSET + sizeof(uint32_t) + sizeof(int32_t));
|
||||
*(uint32_t *)(data + FRAME_HEAD_LEN) = seq;
|
||||
*(uint32_t *)(data + FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET) = side;
|
||||
*(int32_t *)(data + FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET + sizeof(uint32_t)) = result;
|
||||
|
||||
int32_t ret = ProxyChannelSendFileStream(channelId, data, len, TRANS_SESSION_FILE_RESULT_FRAME);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_FILE, "conn send file fail ret=%{public}d", ret);
|
||||
}
|
||||
SoftBusFree(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UnpackFileTransResultFrame(
|
||||
const uint8_t *data, uint32_t len, uint32_t *seq, int32_t *result, uint32_t *side)
|
||||
{
|
||||
if (seq == NULL || result == NULL || side == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "param invalid");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (data == NULL || len < FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET + FRAME_DATA_SEQ_OFFSET) {
|
||||
TRANS_LOGE(TRANS_FILE, "recv ack fail. responseLen=%{public}u", len);
|
||||
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
|
||||
}
|
||||
uint32_t magic = *(uint32_t *)data;
|
||||
uint64_t dataLen = *(uint64_t *)(data + FRAME_MAGIC_OFFSET);
|
||||
if (magic != FILE_MAGIC_NUMBER || dataLen != (FRAME_DATA_SEQ_OFFSET + sizeof(uint32_t) + sizeof(int32_t))) {
|
||||
TRANS_LOGE(
|
||||
TRANS_FILE, "recv ack response head fail. magic=%{public}u, dataLen=%{public}" PRIu64, magic, dataLen);
|
||||
return SOFTBUS_INVALID_DATA_HEAD;
|
||||
}
|
||||
(*seq) = (*(uint32_t *)(data + FRAME_HEAD_LEN));
|
||||
(*side) = (*(uint32_t *)(data + FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET));
|
||||
(*result) = (*(int32_t *)(data + FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET + sizeof(uint32_t)));
|
||||
TRANS_LOGI(TRANS_FILE, "seq=%{public}u, side=%{public}u, result=%{public}d", *seq, *side, *result);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SendFileAckReqAndResData(int32_t channelId, uint32_t startSeq, uint32_t value, int32_t type)
|
||||
{
|
||||
uint32_t len = FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET + FRAME_DATA_SEQ_OFFSET;
|
||||
char *data = (char *)SoftBusCalloc(len);
|
||||
if (data == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "calloc fail! len=%{public}d.", len);
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
*(uint32_t *)data = FILE_MAGIC_NUMBER;
|
||||
*(int64_t *)(data + FRAME_MAGIC_OFFSET) = (FRAME_DATA_SEQ_OFFSET + FRAME_DATA_SEQ_OFFSET);
|
||||
*(uint32_t *)(data + FRAME_HEAD_LEN) = startSeq;
|
||||
*(uint32_t *)(data + FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET) = value;
|
||||
int32_t ret = ProxyChannelSendFileStream(channelId, data, len, type);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_FILE, "conn send ack buf fail ret=%{public}d.", ret);
|
||||
}
|
||||
SoftBusFree(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UnpackAckReqAndResData(FileFrame *frame, uint32_t *startSeq, uint32_t *value)
|
||||
{
|
||||
if (frame == NULL || startSeq == NULL || value == NULL || frame->data == NULL) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (frame->frameLength < FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET + FRAME_DATA_SEQ_OFFSET) {
|
||||
TRANS_LOGE(TRANS_FILE, "unpack ack data fail. frameLen=%{public}d", frame->frameLength);
|
||||
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
|
||||
}
|
||||
frame->magic = (*(uint32_t *)(frame->data));
|
||||
uint64_t dataLen = (*(uint64_t *)(frame->data + FRAME_MAGIC_OFFSET));
|
||||
if (frame->magic != FILE_MAGIC_NUMBER || dataLen < FRAME_DATA_SEQ_OFFSET + FRAME_DATA_SEQ_OFFSET) {
|
||||
TRANS_LOGE(
|
||||
TRANS_FILE, "unpack ack head fail. magic=%{public}u, dataLen=%{public}" PRIu64, frame->magic, dataLen);
|
||||
return SOFTBUS_INVALID_DATA_HEAD;
|
||||
}
|
||||
frame->fileData = frame->data + FRAME_HEAD_LEN;
|
||||
(*startSeq) = (*(uint32_t *)(frame->fileData));
|
||||
(*value) = (*(uint32_t *)(frame->fileData + FRAME_DATA_SEQ_OFFSET));
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int64_t PackReadFileData(FileFrame *fileFrame, uint64_t readLength, uint64_t fileOffset, SendListenerInfo *info)
|
||||
{
|
||||
if (fileFrame == NULL || info == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "param invalid");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
int64_t len = SoftBusPreadFile(info->fd, fileFrame->fileData + FRAME_DATA_SEQ_OFFSET, readLength, fileOffset);
|
||||
if (len <= 0) {
|
||||
TRANS_LOGE(TRANS_FILE, "pread src file failed. ret=%{public}" PRId64, len);
|
||||
return len;
|
||||
}
|
||||
if (info->crc == APP_INFO_FILE_FEATURES_SUPPORT) {
|
||||
uint64_t dataLen = (uint64_t)len + FRAME_DATA_SEQ_OFFSET;
|
||||
fileFrame->frameLength = FRAME_HEAD_LEN + dataLen + FRAME_CRC_LEN;
|
||||
if (fileFrame->frameLength > info->packetSize) {
|
||||
TRANS_LOGE(TRANS_FILE, "frameLength invalid. frameLength=%{public}u", fileFrame->frameLength);
|
||||
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
|
||||
}
|
||||
uint16_t crc = RTU_CRC(fileFrame->fileData + FRAME_DATA_SEQ_OFFSET, len);
|
||||
(*(uint32_t *)(fileFrame->data)) = fileFrame->magic;
|
||||
(*(uint64_t *)(fileFrame->data + FRAME_MAGIC_OFFSET)) = dataLen;
|
||||
info->seq++;
|
||||
(*(uint32_t *)(fileFrame->fileData)) = info->seq;
|
||||
(*(uint16_t *)(fileFrame->fileData + dataLen)) = crc;
|
||||
info->checkSumCRC += crc;
|
||||
} else {
|
||||
uint64_t tmp = FRAME_DATA_SEQ_OFFSET + (uint64_t)len;
|
||||
if (tmp > UINT32_MAX) {
|
||||
TRANS_LOGE(TRANS_FILE, "Overflow error");
|
||||
return SOFTBUS_INVALID_NUM;
|
||||
}
|
||||
fileFrame->frameLength = (uint32_t)tmp;
|
||||
if (fileFrame->frameLength > info->packetSize) {
|
||||
TRANS_LOGE(TRANS_FILE, "frameLength invalid. frameLength=%{public}u", fileFrame->frameLength);
|
||||
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
|
||||
}
|
||||
(*(int32_t *)(fileFrame->fileData)) = info->channelId;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static int64_t PackReadFileRetransData(
|
||||
FileFrame *fileFrame, uint32_t seq, uint64_t readLength, uint64_t fileOffset, const SendListenerInfo *info)
|
||||
{
|
||||
if (fileFrame == NULL || info == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "param invalid");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
int64_t len = SoftBusPreadFile(info->fd, fileFrame->fileData + FRAME_DATA_SEQ_OFFSET, readLength, fileOffset);
|
||||
if (len <= 0) {
|
||||
TRANS_LOGE(TRANS_FILE, "pread src file failed. ret=%{public}" PRId64, len);
|
||||
return len;
|
||||
}
|
||||
uint64_t dataLen = (uint64_t)len + FRAME_DATA_SEQ_OFFSET;
|
||||
fileFrame->frameLength = FRAME_HEAD_LEN + dataLen + FRAME_CRC_LEN;
|
||||
if (fileFrame->frameLength > info->packetSize) {
|
||||
TRANS_LOGE(TRANS_FILE, "frameLength invalid. frameLength=%{public}u", fileFrame->frameLength);
|
||||
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
|
||||
}
|
||||
uint16_t crc = RTU_CRC(fileFrame->fileData + FRAME_DATA_SEQ_OFFSET, len);
|
||||
(*(uint32_t *)(fileFrame->data)) = fileFrame->magic;
|
||||
(*(uint64_t *)(fileFrame->data + FRAME_MAGIC_OFFSET)) = dataLen;
|
||||
(*(uint32_t *)(fileFrame->fileData)) = seq;
|
||||
(*(uint16_t *)(fileFrame->fileData + dataLen)) = crc;
|
||||
|
||||
int32_t ret = ProxyChannelSendFileStream(info->channelId, (char *)fileFrame->data, fileFrame->frameLength,
|
||||
FrameIndexToType((uint64_t)seq, info->frameNum));
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_FILE, "conn send buf fail ret=%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int32_t UnpackFileDataFrame(FileRecipientInfo *info, FileFrame *fileFrame, uint32_t *fileDataLen)
|
||||
{
|
||||
if (info == NULL || fileFrame == NULL || fileDataLen == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "param invalid");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (info->crc == APP_INFO_FILE_FEATURES_SUPPORT) {
|
||||
if (fileFrame->frameLength <= FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET + FRAME_CRC_LEN) {
|
||||
TRANS_LOGE(TRANS_FILE, "frameLength invalid. frameLength=%{public}u", fileFrame->frameLength);
|
||||
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
|
||||
}
|
||||
fileFrame->magic = (*(uint32_t *)(fileFrame->data));
|
||||
uint64_t dataLen = (*(uint64_t *)(fileFrame->data + FRAME_MAGIC_OFFSET));
|
||||
if (fileFrame->magic != FILE_MAGIC_NUMBER ||
|
||||
(dataLen + FRAME_HEAD_LEN + FRAME_CRC_LEN) != fileFrame->frameLength) {
|
||||
TRANS_LOGE(TRANS_FILE, "unpack data frame failed. magic=%{public}u, dataLen=%{public}" PRIu64,
|
||||
fileFrame->magic, dataLen);
|
||||
return SOFTBUS_INVALID_DATA_HEAD;
|
||||
}
|
||||
fileFrame->fileData = fileFrame->data + FRAME_HEAD_LEN;
|
||||
fileFrame->seq = (*(uint32_t *)(fileFrame->fileData));
|
||||
uint16_t recvCRC = (*(uint16_t *)(fileFrame->fileData + dataLen));
|
||||
uint16_t crc = RTU_CRC(fileFrame->fileData + FRAME_DATA_SEQ_OFFSET, dataLen - FRAME_DATA_SEQ_OFFSET);
|
||||
if (crc != recvCRC) {
|
||||
TRANS_LOGE(
|
||||
TRANS_FILE, "crc check fail recvCrc=%{public}u, crc=%{public}u", (uint32_t)recvCRC, (uint32_t)crc);
|
||||
return SOFTBUS_FILE_ERR;
|
||||
}
|
||||
*fileDataLen = dataLen;
|
||||
fileFrame->crc = crc;
|
||||
} else {
|
||||
fileFrame->fileData = fileFrame->data;
|
||||
if (fileFrame->frameLength <= FRAME_DATA_SEQ_OFFSET) {
|
||||
TRANS_LOGE(TRANS_FILE, "frameLength invalid. frameLength=%{public}u", fileFrame->frameLength);
|
||||
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
|
||||
}
|
||||
fileFrame->seq = (*(uint32_t *)(fileFrame->fileData));
|
||||
*fileDataLen = fileFrame->frameLength;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t RetransFileFrameBySeq(const SendListenerInfo *info, int32_t seq)
|
||||
{
|
||||
if ((info != NULL) && (info->crc != APP_INFO_FILE_FEATURES_SUPPORT)) {
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
if ((info == NULL) || (seq <= 0)) {
|
||||
TRANS_LOGE(TRANS_FILE, "param invalid");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
FileFrame fileFrame = { 0 };
|
||||
fileFrame.data = (uint8_t *)SoftBusCalloc(info->packetSize);
|
||||
if (fileFrame.data == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "data calloc fail");
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
fileFrame.magic = FILE_MAGIC_NUMBER;
|
||||
fileFrame.fileData = fileFrame.data + FRAME_HEAD_LEN;
|
||||
uint64_t frameDataSize = info->packetSize - FRAME_HEAD_LEN - FRAME_DATA_SEQ_OFFSET - FRAME_CRC_LEN;
|
||||
uint64_t fileOffset = frameDataSize * ((uint32_t)seq - 1);
|
||||
if (fileOffset >= info->fileSize) {
|
||||
TRANS_LOGE(TRANS_FILE, "retrans file frame failed, seq=%{public}d", seq);
|
||||
SoftBusFree(fileFrame.data);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
uint64_t remainedSize = info->fileSize - fileOffset;
|
||||
uint64_t readLength = (remainedSize < frameDataSize) ? remainedSize : frameDataSize;
|
||||
int64_t len = PackReadFileRetransData(&fileFrame, seq, readLength, fileOffset, info);
|
||||
if (len <= 0) {
|
||||
TRANS_LOGE(TRANS_FILE, "retrans file frame failed");
|
||||
SoftBusFree(fileFrame.data);
|
||||
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
|
||||
}
|
||||
SoftBusFree(fileFrame.data);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t AckResponseDataHandle(const SendListenerInfo *info, const char *data, uint32_t len)
|
||||
{
|
||||
if (info == NULL || data == NULL || len != sizeof(AckResponseData)) {
|
||||
TRANS_LOGE(TRANS_FILE, "data or len invalid");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
AckResponseData *resData = (AckResponseData *)data;
|
||||
uint32_t startSeq = resData->startSeq;
|
||||
uint32_t seqResult = resData->seqResult;
|
||||
if (seqResult != FILE_SEND_ACK_RESULT_SUCCESS) {
|
||||
for (int32_t i = 0; i < FILE_SEND_ACK_INTERVAL; i++) {
|
||||
if (((seqResult >> i) & 0x01) == 0x01) {
|
||||
continue;
|
||||
}
|
||||
uint32_t failSeq = startSeq + (uint32_t)i;
|
||||
int32_t ret = RetransFileFrameBySeq(info, (int32_t)failSeq);
|
||||
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_FILE, "retrans file fail!");
|
||||
}
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
char *GetFullRecvPath(const char *filePath, const char *recvRootDir)
|
||||
{
|
||||
if ((filePath == NULL) || (recvRootDir == NULL)) {
|
||||
TRANS_LOGE(TRANS_FILE, "filePath or rootDir is null");
|
||||
return NULL;
|
||||
}
|
||||
int32_t rootDirLength = (int32_t)strlen(recvRootDir);
|
||||
int32_t filePathLength = (int32_t)strlen(filePath);
|
||||
bool isNeedAddSep = true;
|
||||
if (((filePathLength > 0) && (filePath[0] == PATH_SEPARATOR)) ||
|
||||
((rootDirLength > 0) && (recvRootDir[rootDirLength - 1] == PATH_SEPARATOR))) {
|
||||
isNeedAddSep = false;
|
||||
}
|
||||
int32_t destFullPathLength =
|
||||
(int32_t)((isNeedAddSep) ? (rootDirLength + sizeof('/') + filePathLength) : (rootDirLength + filePathLength));
|
||||
char *recvFullPath = (char *)SoftBusCalloc(destFullPathLength + 1);
|
||||
if (recvFullPath == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "recvFullPath is null");
|
||||
return NULL;
|
||||
}
|
||||
int32_t ret;
|
||||
if (isNeedAddSep) {
|
||||
ret = sprintf_s(recvFullPath, destFullPathLength + 1, "%s/%s", recvRootDir, filePath);
|
||||
} else {
|
||||
ret = sprintf_s(recvFullPath, destFullPathLength + 1, "%s%s", recvRootDir, filePath);
|
||||
}
|
||||
if (ret < 0) {
|
||||
TRANS_LOGE(TRANS_FILE, "create fullPath fail");
|
||||
SoftBusFree(recvFullPath);
|
||||
return NULL;
|
||||
}
|
||||
return recvFullPath;
|
||||
}
|
||||
|
||||
static int32_t GetDirPath(const char *fullPath, char *dirPath, int32_t dirPathLen)
|
||||
{
|
||||
if ((fullPath == NULL) || (strlen(fullPath) < 1) || (fullPath[strlen(fullPath) - 1] == PATH_SEPARATOR)) {
|
||||
TRANS_LOGE(TRANS_FILE, "invalid input param");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
int32_t i = 0;
|
||||
int32_t dirFullLen = (int32_t)strlen(fullPath);
|
||||
for (i = dirFullLen - 1; i >= 0; i--) {
|
||||
if (fullPath[i] == PATH_SEPARATOR) {
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
if (i == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
int32_t dirLen = i;
|
||||
if (dirLen >= dirPathLen) {
|
||||
TRANS_LOGE(TRANS_FILE, "dirLen >= dirPathLen. dirLen=%{public}d, dirPathLen=%{public}d", dirLen, dirPathLen);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (strncpy_s(dirPath, dirPathLen, fullPath, dirLen) != EOK) {
|
||||
TRANS_LOGE(TRANS_FILE, "strcpy_s dir path error, dirLen=%{public}d", dirLen);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t GetAbsFullPath(const char *fullPath, char *recvAbsPath, int32_t pathSize)
|
||||
{
|
||||
char *dirPath = (char *)SoftBusCalloc(MAX_FILE_PATH_NAME_LEN);
|
||||
if (dirPath == NULL) {
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
if (GetDirPath(fullPath, dirPath, MAX_FILE_PATH_NAME_LEN) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_FILE, "get dir path failed");
|
||||
SoftBusFree(dirPath);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
char *absFullDir = (char *)SoftBusCalloc(PATH_MAX + 1);
|
||||
if (absFullDir == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "calloc absFullDir failed");
|
||||
SoftBusFree(dirPath);
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
int32_t fileNameLength = -1;
|
||||
int32_t dirPathLength = -1;
|
||||
const char *fileName = TransGetFileName(fullPath);
|
||||
if (fileName == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "get file name failed");
|
||||
goto EXIT_ERR;
|
||||
}
|
||||
if (GetAndCheckRealPath(dirPath, absFullDir) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_FILE, "get full abs file failed");
|
||||
goto EXIT_ERR;
|
||||
}
|
||||
TRANS_LOGI(TRANS_FILE, "dirPath=%{public}s, absFullDir=%{public}s", dirPath, absFullDir);
|
||||
fileNameLength = (int32_t)strlen(fileName);
|
||||
dirPathLength = (int32_t)strlen(absFullDir);
|
||||
if (pathSize < (fileNameLength + dirPathLength + 1)) {
|
||||
TRANS_LOGE(TRANS_FILE, "copy name is too large, dirLen=%{public}d, fileNameLen=%{public}d",
|
||||
dirPathLength, fileNameLength);
|
||||
goto EXIT_ERR;
|
||||
}
|
||||
TRANS_LOGI(TRANS_FILE, "fileName=%{public}s, fileNameLen=%{public}d", fileName, fileNameLength);
|
||||
if (sprintf_s(recvAbsPath, pathSize, "%s/%s", absFullDir, fileName) < 0) {
|
||||
TRANS_LOGE(TRANS_FILE, "sprintf_s filename error");
|
||||
goto EXIT_ERR;
|
||||
}
|
||||
TRANS_LOGI(TRANS_FILE, "recvAbsPath=%{public}s", recvAbsPath);
|
||||
SoftBusFree(absFullDir);
|
||||
SoftBusFree(dirPath);
|
||||
return SOFTBUS_OK;
|
||||
|
||||
EXIT_ERR:
|
||||
SoftBusFree(dirPath);
|
||||
SoftBusFree(absFullDir);
|
||||
return SOFTBUS_FILE_ERR;
|
||||
}
|
||||
|
||||
int32_t CreateDirAndGetAbsPath(const char *filePath, char *recvAbsPath, int32_t pathSize)
|
||||
{
|
||||
if ((filePath == NULL) || (recvAbsPath == NULL)) {
|
||||
TRANS_LOGE(TRANS_FILE, "invalid input");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
uint32_t len = (uint32_t)strlen(filePath);
|
||||
int32_t ret;
|
||||
char *tempPath = (char *)SoftBusCalloc(len + 1);
|
||||
if (tempPath == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "calloc tempPath failed");
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
tempPath[i] = filePath[i];
|
||||
if (tempPath[i] != PATH_SEPARATOR) {
|
||||
continue;
|
||||
}
|
||||
if (SoftBusAccessFile(tempPath, SOFTBUS_F_OK) != SOFTBUS_OK) {
|
||||
ret = SoftBusMakeDir(tempPath, DEFAULT_NEW_PATH_AUTHORITY);
|
||||
if (ret == SOFTBUS_ADAPTER_ERR) {
|
||||
TRANS_LOGE(TRANS_FILE, "mkdir failed errno=%{public}d", errno);
|
||||
SoftBusFree(tempPath);
|
||||
return SOFTBUS_FILE_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SoftBusFree(tempPath);
|
||||
ret = GetAbsFullPath(filePath, recvAbsPath, pathSize);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGI(TRANS_FILE, "dest dir is invalid");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
@ -24,8 +24,10 @@
|
||||
#include <stdatomic.h>
|
||||
|
||||
#include "client_trans_pending.h"
|
||||
#include "client_trans_proxy_file_helper.h"
|
||||
#include "client_trans_proxy_manager.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "lnn_lane_interface.h"
|
||||
#include "softbus_adapter_errcode.h"
|
||||
#include "softbus_adapter_file.h"
|
||||
@ -48,63 +50,6 @@ static LIST_HEAD(g_sessionFileLockList);
|
||||
static LIST_HEAD(g_sendListenerInfoList);
|
||||
static LIST_HEAD(g_recvRecipientInfoList);
|
||||
|
||||
static int32_t ProxyChannelSendFileStream(int32_t channelId, const char *data, uint32_t len, int32_t type)
|
||||
{
|
||||
ProxyChannelInfoDetail info;
|
||||
int32_t ret = ClientTransProxyGetInfoByChannelId(channelId, &info);
|
||||
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret,
|
||||
TRANS_FILE, "client trans proxy get info by ChannelId fail");
|
||||
return TransProxyPackAndSendData(channelId, data, len, &info, (SessionPktType)type);
|
||||
}
|
||||
|
||||
static int32_t SendFileTransResult(int32_t channelId, uint32_t seq, int32_t result, uint32_t side)
|
||||
{
|
||||
TRANS_LOGI(TRANS_FILE, "send file result seq=%{public}u, side=%{public}u, result=%{public}d", seq, side, result);
|
||||
uint32_t len = FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET + sizeof(uint32_t) + sizeof(int32_t);
|
||||
char *data = (char *)SoftBusCalloc(len);
|
||||
if (data == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "malloc failedLen=%{public}d.", len);
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
*(uint32_t *)data = FILE_MAGIC_NUMBER;
|
||||
*(uint64_t *)(data + FRAME_MAGIC_OFFSET) = (FRAME_DATA_SEQ_OFFSET + sizeof(uint32_t) + sizeof(int32_t));
|
||||
*(uint32_t *)(data + FRAME_HEAD_LEN) = seq;
|
||||
*(uint32_t *)(data + FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET) = side;
|
||||
*(int32_t *)(data + FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET + sizeof(uint32_t)) = result;
|
||||
|
||||
int32_t ret = ProxyChannelSendFileStream(channelId, data, len, TRANS_SESSION_FILE_RESULT_FRAME);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_FILE, "conn send file fail ret=%{public}d", ret);
|
||||
}
|
||||
SoftBusFree(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t UnpackFileTransResultFrame(
|
||||
const uint8_t *data, uint32_t len, uint32_t *seq, int32_t *result, uint32_t *side)
|
||||
{
|
||||
if (seq == NULL || result == NULL || side == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "param invalid");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (data == NULL || len < FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET + FRAME_DATA_SEQ_OFFSET) {
|
||||
TRANS_LOGE(TRANS_FILE, "recv ack fail. responseLen=%{public}u", len);
|
||||
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
|
||||
}
|
||||
uint32_t magic = *(uint32_t *)data;
|
||||
uint64_t dataLen = *(uint64_t *)(data + FRAME_MAGIC_OFFSET);
|
||||
if (magic != FILE_MAGIC_NUMBER || dataLen != (FRAME_DATA_SEQ_OFFSET + sizeof(uint32_t) + sizeof(int32_t))) {
|
||||
TRANS_LOGE(
|
||||
TRANS_FILE, "recv ack response head fail. magic=%{public}u, dataLen=%{public}" PRIu64, magic, dataLen);
|
||||
return SOFTBUS_INVALID_DATA_HEAD;
|
||||
}
|
||||
(*seq) = (*(uint32_t *)(data + FRAME_HEAD_LEN));
|
||||
(*side) = (*(uint32_t *)(data + FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET));
|
||||
(*result) = (*(int32_t *)(data + FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET + sizeof(uint32_t)));
|
||||
TRANS_LOGI(TRANS_FILE, "seq=%{public}u, side=%{public}u, result=%{public}d", *seq, *side, *result);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void ClearRecipientResources(FileRecipientInfo *info)
|
||||
{
|
||||
if (info->recvFileInfo.fileFd != INVALID_FD) {
|
||||
@ -207,361 +152,6 @@ void ClinetTransProxyFileManagerDeinit(void)
|
||||
atomic_store_explicit(&(g_recvFileInfoLock.lockInitFlag), false, memory_order_release);
|
||||
}
|
||||
|
||||
static int32_t SendFileAckReqAndResData(int32_t channelId, uint32_t startSeq, uint32_t value, int32_t type)
|
||||
{
|
||||
uint32_t len = FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET + FRAME_DATA_SEQ_OFFSET;
|
||||
char *data = (char *)SoftBusCalloc(len);
|
||||
if (data == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "calloc fail! len=%{public}d.", len);
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
*(uint32_t *)data = FILE_MAGIC_NUMBER;
|
||||
*(int64_t *)(data + FRAME_MAGIC_OFFSET) = (FRAME_DATA_SEQ_OFFSET + FRAME_DATA_SEQ_OFFSET);
|
||||
*(uint32_t *)(data + FRAME_HEAD_LEN) = startSeq;
|
||||
*(uint32_t *)(data + FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET) = value;
|
||||
int32_t ret = ProxyChannelSendFileStream(channelId, data, len, type);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_FILE, "conn send ack buf fail ret=%{public}d.", ret);
|
||||
}
|
||||
SoftBusFree(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t UnpackAckReqAndResData(FileFrame *frame, uint32_t *startSeq, uint32_t *value)
|
||||
{
|
||||
if (frame == NULL || startSeq == NULL || value == NULL || frame->data == NULL) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (frame->frameLength < FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET + FRAME_DATA_SEQ_OFFSET) {
|
||||
TRANS_LOGE(TRANS_FILE, "unpack ack data fail. frameLen=%{public}d", frame->frameLength);
|
||||
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
|
||||
}
|
||||
frame->magic = (*(uint32_t *)(frame->data));
|
||||
uint64_t dataLen = (*(uint64_t *)(frame->data + FRAME_MAGIC_OFFSET));
|
||||
if (frame->magic != FILE_MAGIC_NUMBER || dataLen < FRAME_DATA_SEQ_OFFSET + FRAME_DATA_SEQ_OFFSET) {
|
||||
TRANS_LOGE(
|
||||
TRANS_FILE, "unpack ack head fail. magic=%{public}u, dataLen=%{public}" PRIu64, frame->magic, dataLen);
|
||||
return SOFTBUS_INVALID_DATA_HEAD;
|
||||
}
|
||||
frame->fileData = frame->data + FRAME_HEAD_LEN;
|
||||
(*startSeq) = (*(uint32_t *)(frame->fileData));
|
||||
(*value) = (*(uint32_t *)(frame->fileData + FRAME_DATA_SEQ_OFFSET));
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int64_t PackReadFileData(FileFrame *fileFrame, uint64_t readLength, uint64_t fileOffset, SendListenerInfo *info)
|
||||
{
|
||||
int64_t len = SoftBusPreadFile(info->fd, fileFrame->fileData + FRAME_DATA_SEQ_OFFSET, readLength, fileOffset);
|
||||
if (len <= 0) {
|
||||
TRANS_LOGE(TRANS_FILE, "pread src file failed. ret=%{public}" PRId64, len);
|
||||
return len;
|
||||
}
|
||||
if (info->crc == APP_INFO_FILE_FEATURES_SUPPORT) {
|
||||
uint64_t dataLen = (uint64_t)len + FRAME_DATA_SEQ_OFFSET;
|
||||
fileFrame->frameLength = FRAME_HEAD_LEN + dataLen + FRAME_CRC_LEN;
|
||||
if (fileFrame->frameLength > info->packetSize) {
|
||||
TRANS_LOGE(TRANS_FILE, "frameLength invalid. frameLength=%{public}u", fileFrame->frameLength);
|
||||
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
|
||||
}
|
||||
uint16_t crc = RTU_CRC(fileFrame->fileData + FRAME_DATA_SEQ_OFFSET, len);
|
||||
(*(uint32_t *)(fileFrame->data)) = fileFrame->magic;
|
||||
(*(uint64_t *)(fileFrame->data + FRAME_MAGIC_OFFSET)) = dataLen;
|
||||
info->seq++;
|
||||
(*(uint32_t *)(fileFrame->fileData)) = info->seq;
|
||||
(*(uint16_t *)(fileFrame->fileData + dataLen)) = crc;
|
||||
info->checkSumCRC += crc;
|
||||
} else {
|
||||
uint64_t tmp = FRAME_DATA_SEQ_OFFSET + (uint64_t)len;
|
||||
if (tmp > UINT32_MAX) {
|
||||
TRANS_LOGE(TRANS_FILE, "Overflow error");
|
||||
return SOFTBUS_INVALID_NUM;
|
||||
}
|
||||
fileFrame->frameLength = (uint32_t)tmp;
|
||||
if (fileFrame->frameLength > info->packetSize) {
|
||||
TRANS_LOGE(TRANS_FILE, "frameLength invalid. frameLength=%{public}u", fileFrame->frameLength);
|
||||
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
|
||||
}
|
||||
(*(int32_t *)(fileFrame->fileData)) = info->channelId;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static int64_t PackReadFileRetransData(
|
||||
FileFrame *fileFrame, uint32_t seq, uint64_t readLength, uint64_t fileOffset, const SendListenerInfo *info)
|
||||
{
|
||||
int64_t len = SoftBusPreadFile(info->fd, fileFrame->fileData + FRAME_DATA_SEQ_OFFSET, readLength, fileOffset);
|
||||
if (len <= 0) {
|
||||
TRANS_LOGE(TRANS_FILE, "pread src file failed. ret=%{public}" PRId64, len);
|
||||
return len;
|
||||
}
|
||||
uint64_t dataLen = (uint64_t)len + FRAME_DATA_SEQ_OFFSET;
|
||||
fileFrame->frameLength = FRAME_HEAD_LEN + dataLen + FRAME_CRC_LEN;
|
||||
if (fileFrame->frameLength > info->packetSize) {
|
||||
TRANS_LOGE(TRANS_FILE, "frameLength invalid. frameLength=%{public}u", fileFrame->frameLength);
|
||||
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
|
||||
}
|
||||
uint16_t crc = RTU_CRC(fileFrame->fileData + FRAME_DATA_SEQ_OFFSET, len);
|
||||
(*(uint32_t *)(fileFrame->data)) = fileFrame->magic;
|
||||
(*(uint64_t *)(fileFrame->data + FRAME_MAGIC_OFFSET)) = dataLen;
|
||||
(*(uint32_t *)(fileFrame->fileData)) = seq;
|
||||
(*(uint16_t *)(fileFrame->fileData + dataLen)) = crc;
|
||||
|
||||
int32_t ret = ProxyChannelSendFileStream(info->channelId, (char *)fileFrame->data, fileFrame->frameLength,
|
||||
FrameIndexToType((uint64_t)seq, info->frameNum));
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_FILE, "conn send buf fail ret=%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static int32_t UnpackFileDataFrame(FileRecipientInfo *info, FileFrame *fileFrame, uint32_t *fileDataLen)
|
||||
{
|
||||
if (info->crc == APP_INFO_FILE_FEATURES_SUPPORT) {
|
||||
if (fileFrame->frameLength <= FRAME_HEAD_LEN + FRAME_DATA_SEQ_OFFSET + FRAME_CRC_LEN) {
|
||||
TRANS_LOGE(TRANS_FILE, "frameLength invalid. frameLength=%{public}u", fileFrame->frameLength);
|
||||
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
|
||||
}
|
||||
fileFrame->magic = (*(uint32_t *)(fileFrame->data));
|
||||
uint64_t dataLen = (*(uint64_t *)(fileFrame->data + FRAME_MAGIC_OFFSET));
|
||||
if (fileFrame->magic != FILE_MAGIC_NUMBER ||
|
||||
(dataLen + FRAME_HEAD_LEN + FRAME_CRC_LEN) != fileFrame->frameLength) {
|
||||
TRANS_LOGE(TRANS_FILE, "unpack data frame failed. magic=%{public}u, dataLen=%{public}" PRIu64,
|
||||
fileFrame->magic, dataLen);
|
||||
return SOFTBUS_INVALID_DATA_HEAD;
|
||||
}
|
||||
fileFrame->fileData = fileFrame->data + FRAME_HEAD_LEN;
|
||||
fileFrame->seq = (*(uint32_t *)(fileFrame->fileData));
|
||||
uint16_t recvCRC = (*(uint16_t *)(fileFrame->fileData + dataLen));
|
||||
uint16_t crc = RTU_CRC(fileFrame->fileData + FRAME_DATA_SEQ_OFFSET, dataLen - FRAME_DATA_SEQ_OFFSET);
|
||||
if (crc != recvCRC) {
|
||||
TRANS_LOGE(
|
||||
TRANS_FILE, "crc check fail recvCrc=%{public}u, crc=%{public}u", (uint32_t)recvCRC, (uint32_t)crc);
|
||||
return SOFTBUS_FILE_ERR;
|
||||
}
|
||||
*fileDataLen = dataLen;
|
||||
fileFrame->crc = crc;
|
||||
} else {
|
||||
fileFrame->fileData = fileFrame->data;
|
||||
if (fileFrame->frameLength <= FRAME_DATA_SEQ_OFFSET) {
|
||||
TRANS_LOGE(TRANS_FILE, "frameLength invalid. frameLength=%{public}u", fileFrame->frameLength);
|
||||
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
|
||||
}
|
||||
fileFrame->seq = (*(uint32_t *)(fileFrame->fileData));
|
||||
*fileDataLen = fileFrame->frameLength;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t RetransFileFrameBySeq(const SendListenerInfo *info, int32_t seq)
|
||||
{
|
||||
if ((info != NULL) && (info->crc != APP_INFO_FILE_FEATURES_SUPPORT)) {
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
if ((info == NULL) || (seq <= 0)) {
|
||||
TRANS_LOGE(TRANS_FILE, "param invalid");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
FileFrame fileFrame = { 0 };
|
||||
fileFrame.data = (uint8_t *)SoftBusCalloc(info->packetSize);
|
||||
if (fileFrame.data == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "data calloc fail");
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
fileFrame.magic = FILE_MAGIC_NUMBER;
|
||||
fileFrame.fileData = fileFrame.data + FRAME_HEAD_LEN;
|
||||
uint64_t frameDataSize = info->packetSize - FRAME_HEAD_LEN - FRAME_DATA_SEQ_OFFSET - FRAME_CRC_LEN;
|
||||
uint64_t fileOffset = frameDataSize * ((uint32_t)seq - 1);
|
||||
if (fileOffset >= info->fileSize) {
|
||||
TRANS_LOGE(TRANS_FILE, "retrans file frame failed, seq=%{public}d", seq);
|
||||
SoftBusFree(fileFrame.data);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
uint64_t remainedSize = info->fileSize - fileOffset;
|
||||
uint64_t readLength = (remainedSize < frameDataSize) ? remainedSize : frameDataSize;
|
||||
int64_t len = PackReadFileRetransData(&fileFrame, seq, readLength, fileOffset, info);
|
||||
if (len <= 0) {
|
||||
TRANS_LOGE(TRANS_FILE, "retrans file frame failed");
|
||||
SoftBusFree(fileFrame.data);
|
||||
return SOFTBUS_TRANS_INVALID_DATA_LENGTH;
|
||||
}
|
||||
SoftBusFree(fileFrame.data);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t AckResponseDataHandle(const SendListenerInfo *info, const char *data, uint32_t len)
|
||||
{
|
||||
if (data == NULL || len != sizeof(AckResponseData)) {
|
||||
TRANS_LOGE(TRANS_FILE, "data or len invalid");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
AckResponseData *resData = (AckResponseData *)data;
|
||||
uint32_t startSeq = resData->startSeq;
|
||||
uint32_t seqResult = resData->seqResult;
|
||||
if (seqResult != FILE_SEND_ACK_RESULT_SUCCESS) {
|
||||
for (int32_t i = 0; i < FILE_SEND_ACK_INTERVAL; i++) {
|
||||
if (((seqResult >> i) & 0x01) == 0x01) {
|
||||
continue;
|
||||
}
|
||||
uint32_t failSeq = startSeq + (uint32_t)i;
|
||||
int32_t ret = RetransFileFrameBySeq(info, (int32_t)failSeq);
|
||||
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_FILE, "retrans file fail!");
|
||||
}
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static char *GetFullRecvPath(const char *filePath, const char *recvRootDir)
|
||||
{
|
||||
if ((filePath == NULL) || (recvRootDir == NULL)) {
|
||||
TRANS_LOGE(TRANS_FILE, "filePath or rootDir is null");
|
||||
return NULL;
|
||||
}
|
||||
int32_t rootDirLength = (int32_t)strlen(recvRootDir);
|
||||
int32_t filePathLength = (int32_t)strlen(filePath);
|
||||
bool isNeedAddSep = true;
|
||||
if (((filePathLength > 0) && (filePath[0] == PATH_SEPARATOR)) ||
|
||||
((rootDirLength > 0) && (recvRootDir[rootDirLength - 1] == PATH_SEPARATOR))) {
|
||||
isNeedAddSep = false;
|
||||
}
|
||||
int32_t destFullPathLength =
|
||||
(int32_t)((isNeedAddSep) ? (rootDirLength + sizeof('/') + filePathLength) : (rootDirLength + filePathLength));
|
||||
char *recvFullPath = (char *)SoftBusCalloc(destFullPathLength + 1);
|
||||
if (recvFullPath == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "recvFullPath is null");
|
||||
return NULL;
|
||||
}
|
||||
int32_t ret;
|
||||
if (isNeedAddSep) {
|
||||
ret = sprintf_s(recvFullPath, destFullPathLength + 1, "%s/%s", recvRootDir, filePath);
|
||||
} else {
|
||||
ret = sprintf_s(recvFullPath, destFullPathLength + 1, "%s%s", recvRootDir, filePath);
|
||||
}
|
||||
if (ret < 0) {
|
||||
TRANS_LOGE(TRANS_FILE, "create fullPath fail");
|
||||
SoftBusFree(recvFullPath);
|
||||
return NULL;
|
||||
}
|
||||
return recvFullPath;
|
||||
}
|
||||
|
||||
static int32_t GetDirPath(const char *fullPath, char *dirPath, int32_t dirPathLen)
|
||||
{
|
||||
if ((fullPath == NULL) || (strlen(fullPath) < 1) || (fullPath[strlen(fullPath) - 1] == PATH_SEPARATOR)) {
|
||||
TRANS_LOGE(TRANS_FILE, "invalid input param");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
int32_t i = 0;
|
||||
int32_t dirFullLen = (int32_t)strlen(fullPath);
|
||||
for (i = dirFullLen - 1; i >= 0; i--) {
|
||||
if (fullPath[i] == PATH_SEPARATOR) {
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
if (i == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
int32_t dirLen = i;
|
||||
if (dirLen >= dirPathLen) {
|
||||
TRANS_LOGE(TRANS_FILE, "dirLen >= dirPathLen. dirLen=%{public}d, dirPathLen=%{public}d", dirLen, dirPathLen);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (strncpy_s(dirPath, dirPathLen, fullPath, dirLen) != EOK) {
|
||||
TRANS_LOGE(TRANS_FILE, "strcpy_s dir path error, dirLen=%{public}d", dirLen);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t GetAbsFullPath(const char *fullPath, char *recvAbsPath, int32_t pathSize)
|
||||
{
|
||||
char *dirPath = (char *)SoftBusCalloc(MAX_FILE_PATH_NAME_LEN);
|
||||
if (dirPath == NULL) {
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
if (GetDirPath(fullPath, dirPath, MAX_FILE_PATH_NAME_LEN) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_FILE, "get dir path failed");
|
||||
SoftBusFree(dirPath);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
char *absFullDir = (char *)SoftBusCalloc(PATH_MAX + 1);
|
||||
if (absFullDir == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "calloc absFullDir failed");
|
||||
SoftBusFree(dirPath);
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
int32_t fileNameLength = -1;
|
||||
int32_t dirPathLength = -1;
|
||||
const char *fileName = TransGetFileName(fullPath);
|
||||
if (fileName == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "get file name failed");
|
||||
goto EXIT_ERR;
|
||||
}
|
||||
if (GetAndCheckRealPath(dirPath, absFullDir) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_FILE, "get full abs file failed");
|
||||
goto EXIT_ERR;
|
||||
}
|
||||
TRANS_LOGI(TRANS_FILE, "dirPath=%{public}s, absFullDir=%{public}s", dirPath, absFullDir);
|
||||
fileNameLength = (int32_t)strlen(fileName);
|
||||
dirPathLength = (int32_t)strlen(absFullDir);
|
||||
if (pathSize < (fileNameLength + dirPathLength + 1)) {
|
||||
TRANS_LOGE(TRANS_FILE, "copy name is too large, dirLen=%{public}d, fileNameLen=%{public}d",
|
||||
dirPathLength, fileNameLength);
|
||||
goto EXIT_ERR;
|
||||
}
|
||||
TRANS_LOGI(TRANS_FILE, "fileName=%{public}s, fileNameLen=%{public}d", fileName, fileNameLength);
|
||||
if (sprintf_s(recvAbsPath, pathSize, "%s/%s", absFullDir, fileName) < 0) {
|
||||
TRANS_LOGE(TRANS_FILE, "sprintf_s filename error");
|
||||
goto EXIT_ERR;
|
||||
}
|
||||
TRANS_LOGI(TRANS_FILE, "recvAbsPath=%{public}s", recvAbsPath);
|
||||
SoftBusFree(absFullDir);
|
||||
SoftBusFree(dirPath);
|
||||
return SOFTBUS_OK;
|
||||
EXIT_ERR:
|
||||
SoftBusFree(dirPath);
|
||||
SoftBusFree(absFullDir);
|
||||
return SOFTBUS_FILE_ERR;
|
||||
}
|
||||
|
||||
static int32_t CreateDirAndGetAbsPath(const char *filePath, char *recvAbsPath, int32_t pathSize)
|
||||
{
|
||||
if ((filePath == NULL) || (recvAbsPath == NULL)) {
|
||||
TRANS_LOGE(TRANS_FILE, "invalid input");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
uint32_t len = (uint32_t)strlen(filePath);
|
||||
int32_t ret;
|
||||
char *tempPath = (char *)SoftBusCalloc(len + 1);
|
||||
if (tempPath == NULL) {
|
||||
TRANS_LOGE(TRANS_FILE, "calloc tempPath failed");
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
tempPath[i] = filePath[i];
|
||||
if (tempPath[i] != PATH_SEPARATOR) {
|
||||
continue;
|
||||
}
|
||||
if (SoftBusAccessFile(tempPath, SOFTBUS_F_OK) != SOFTBUS_OK) {
|
||||
ret = SoftBusMakeDir(tempPath, DEFAULT_NEW_PATH_AUTHORITY);
|
||||
if (ret == SOFTBUS_ADAPTER_ERR) {
|
||||
TRANS_LOGE(TRANS_FILE, "mkdir failed errno=%{public}d", errno);
|
||||
SoftBusFree(tempPath);
|
||||
return SOFTBUS_FILE_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SoftBusFree(tempPath);
|
||||
ret = GetAbsFullPath(filePath, recvAbsPath, pathSize);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGI(TRANS_FILE, "dest dir is invalid");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static ProxyFileMutexLock *GetSessionFileLock(int32_t channelId)
|
||||
{
|
||||
if (SoftBusMutexLock(&g_sendFileInfoLock.lock) != 0) {
|
||||
|
@ -821,26 +821,6 @@ void ClientTransProxyCloseChannel(int32_t channelId)
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t ClientTransProxyEncryptWithSeq(const char *sessionKey, int32_t seqNum, const char *in,
|
||||
uint32_t inLen, char *out, uint32_t *outLen)
|
||||
{
|
||||
AesGcmCipherKey cipherKey = {0};
|
||||
cipherKey.keyLen = SESSION_KEY_LENGTH;
|
||||
if (memcpy_s(cipherKey.key, SESSION_KEY_LENGTH, sessionKey, SESSION_KEY_LENGTH) != EOK) {
|
||||
TRANS_LOGE(TRANS_SDK, "memcpy key error.");
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
|
||||
int ret = SoftBusEncryptDataWithSeq(&cipherKey, (unsigned char*)in, inLen, (unsigned char*)out, outLen, seqNum);
|
||||
(void)memset_s(cipherKey.key, SESSION_KEY_LENGTH, 0, SESSION_KEY_LENGTH);
|
||||
|
||||
if (ret != SOFTBUS_OK || *outLen != inLen + OVERHEAD_LEN) {
|
||||
TRANS_LOGE(TRANS_SDK, "encrypt error, ret=%{public}d", ret);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t ClientTransProxyPackBytes(
|
||||
int32_t channelId, ClientProxyDataInfo *dataInfo, int seq, char *sessionKey, SessionPktType flag)
|
||||
{
|
||||
@ -856,8 +836,21 @@ static int32_t ClientTransProxyPackBytes(
|
||||
}
|
||||
|
||||
uint32_t outLen = 0;
|
||||
if (ClientTransProxyEncryptWithSeq(sessionKey, seq, (const char *)dataInfo->inData, dataInfo->inLen,
|
||||
(char *)dataInfo->outData + sizeof(PacketHead), &outLen) != SOFTBUS_OK) {
|
||||
AesGcmCipherKey cipherKey = { 0 };
|
||||
cipherKey.keyLen = SESSION_KEY_LENGTH;
|
||||
if (memcpy_s(cipherKey.key, SESSION_KEY_LENGTH, sessionKey, SESSION_KEY_LENGTH) != EOK) {
|
||||
TRANS_LOGE(TRANS_SDK, "memcpy key error.");
|
||||
SoftBusFree(dataInfo->outData);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
char *outData = (char *)dataInfo->outData + sizeof(PacketHead);
|
||||
int32_t ret = SoftBusEncryptDataWithSeq(&cipherKey, (const unsigned char *)dataInfo->inData,
|
||||
dataInfo->inLen, (unsigned char *)outData, &outLen, seq);
|
||||
(void)memset_s(cipherKey.key, SESSION_KEY_LENGTH, 0, SESSION_KEY_LENGTH);
|
||||
|
||||
if (ret != SOFTBUS_OK || outLen != dataInfo->inLen + OVERHEAD_LEN) {
|
||||
TRANS_LOGE(TRANS_SDK, "encrypt error, ret=%{public}d", ret);
|
||||
outData = NULL;
|
||||
SoftBusFree(dataInfo->outData);
|
||||
TRANS_LOGE(TRANS_SDK, "ClientTransProxyEncryptWithSeq channelId=%{public}d", channelId);
|
||||
return SOFTBUS_TRANS_PROXY_SESS_ENCRYPT_ERR;
|
||||
|
@ -22,6 +22,7 @@ if (dsoftbus_feature_proxy_file == true) {
|
||||
trans_proxy_channel_sdk_src += [
|
||||
"$dsoftbus_sdk_path/transmission/trans_channel/proxy/src/client_trans_proxy_file_common.c",
|
||||
"$dsoftbus_sdk_path/transmission/trans_channel/proxy/src/client_trans_proxy_file_manager.c",
|
||||
"$dsoftbus_sdk_path/transmission/trans_channel/proxy/src/client_trans_proxy_file_helper.c",
|
||||
]
|
||||
} else {
|
||||
trans_proxy_channel_sdk_src += [ "$dsoftbus_sdk_path/transmission/trans_channel/proxy/src/client_trans_proxy_file_manager_virtual.c" ]
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "common_list.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_conn_interface.h"
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "client_trans_tcp_direct_callback.h"
|
||||
#include "client_trans_tcp_direct_manager.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "common_list.h"
|
||||
#include "softbus_adapter_crypto.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "client_trans_file.h"
|
||||
#include "client_trans_file_listener.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_stream.h"
|
||||
#include "nstackx_dfile.h"
|
||||
#include "securec.h"
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "client_trans_stream.h"
|
||||
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_udp_stream_interface.h"
|
||||
#include "session.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "client_trans_proxy_manager.h"
|
||||
#include "client_trans_session_callback.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_tcp_direct_manager.h"
|
||||
#include "client_trans_udp_manager.h"
|
||||
#include "softbus_error_code.h"
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "client_trans_pending.h"
|
||||
#include "client_trans_proxy_file_common.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_tcp_direct_message.h"
|
||||
#include "securec.h"
|
||||
#include "softbus_adapter_errcode.h"
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "client_trans_proxy_file_common.h"
|
||||
#include "client_trans_proxy_file_manager.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_tcp_direct_message.h"
|
||||
#include "softbus_adapter_errcode.h"
|
||||
#include "softbus_adapter_file.h"
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "clienttranssessionmanager_fuzzer.h"
|
||||
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "session.h"
|
||||
#include "softbus_trans_def.h"
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "client_trans_proxy_manager.h"
|
||||
#include "client_trans_session_callback.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_tcp_direct_manager.h"
|
||||
#include "client_trans_udp_manager.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "trans_server_proxy_standard.h"
|
||||
#include "trans_server_proxy_standard.cpp"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_session_service.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "client_trans_message_service.h"
|
||||
#include "client_trans_message_service.c"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "softbus_common.h"
|
||||
#include "trans_log.h"
|
||||
#include "softbus_feature_config.h"
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "softbus_server_frame.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_session_service.h"
|
||||
#include "client_trans_session_callback.h"
|
||||
#include "client_trans_session_callback.c"
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "softbus_server_frame.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "trans_log.h"
|
||||
#include "softbus_feature_config.h"
|
||||
#include "softbus_conn_interface.h"
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "softbus_server_frame.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_session_service.h"
|
||||
#include "softbus_config_type.h"
|
||||
#include "trans_log.h"
|
||||
|
@ -25,9 +25,11 @@
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_config_type.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_session_service.h"
|
||||
#include "client_trans_session_service.c"
|
||||
#include "client_trans_session_manager.c"
|
||||
#include "client_trans_socket_manager.c"
|
||||
#include "softbus_access_token_test.h"
|
||||
#include "softbus_common.h"
|
||||
#include "token_setproc.h"
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "securec.h"
|
||||
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "session_impl.h"
|
||||
#include "session_service_impl.h"
|
||||
#include "ISessionListener.h"
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_def.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "softbus_feature_config.h"
|
||||
#include "client_trans_session_service.h"
|
||||
#include <string>
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "client_trans_pending.h"
|
||||
#include "client_trans_proxy_file_manager.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
|
@ -20,8 +20,10 @@
|
||||
#include "securec.h"
|
||||
|
||||
#include "client_trans_proxy_file_manager.c"
|
||||
#include "client_trans_proxy_file_helper.c"
|
||||
#include "client_trans_proxy_manager.c"
|
||||
#include "client_trans_session_manager.c"
|
||||
#include "client_trans_socket_manager.c"
|
||||
#include "client_trans_file_listener.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
@ -519,7 +521,7 @@ HWTEST_F(ClientTransProxyFileManagerTest, ClinetTransProxySendOneFrameTest001, T
|
||||
EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
|
||||
|
||||
ret = SendOneFrame(&info, &fileFrame);
|
||||
EXPECT_EQ(SOFTBUS_TRANS_PROXY_CHANNEL_NOT_FOUND, ret);
|
||||
EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
|
||||
|
||||
info.crc = APP_INFO_FILE_FEATURES_NO_SUPPORT;
|
||||
uint32_t dataTest = TEST_DATA_LENGTH;
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "client_trans_proxy_manager.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "session.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "client_trans_tcp_direct_callback.h"
|
||||
#include "client_trans_session_callback.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_tcp_direct_listener.h"
|
||||
#include "session.h"
|
||||
#include "softbus_def.h"
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_session_service.h"
|
||||
#include "trans_log.h"
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "client_trans_tcp_direct_listener.c"
|
||||
#include "client_trans_tcp_direct_message.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_session_callback.h"
|
||||
#include "session.h"
|
||||
#include "softbus_def.h"
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "client_trans_session_callback.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_udp_manager.h"
|
||||
#include "session.h"
|
||||
#include "softbus_def.h"
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <securec.h>
|
||||
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "client_trans_socket_manager.h"
|
||||
#include "client_trans_stream.c"
|
||||
#include "client_trans_stream.h"
|
||||
#include "client_trans_udp_manager.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user