!7153 fix: set rename callback

Merge pull request !7153 from xuxiaoqing/master
This commit is contained in:
openharmony_ci 2024-08-08 02:17:31 +00:00 committed by Gitee
commit 6db3d124bc
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 58 additions and 1 deletions

View File

@ -20,7 +20,8 @@
extern "C" {
#endif
#define MAX_MAC_LEN 18
#define MAX_MAC_LEN 18
#define MAX_PATH_LEN 4096
/**
* @brief Enumerates the data types.
@ -288,6 +289,14 @@ typedef struct {
} FrameEvtCbInfo;
typedef int (*OnFrameEvt)(int fd, const FrameEvtCbInfo *info);
typedef struct {
int32_t socket; /**< Socket fd */
const char *initFileName; /**< Init file name */
char newFileName[MAX_PATH_LEN]; /**< New file name */
} RenameParam;
typedef void (*OnRenameFileCallback)(RenameParam *renameParam);
#ifdef __cplusplus
}
#endif

View File

@ -528,6 +528,7 @@
"OpenAuthSessionWithPara";
"ResourceConflictCheck";
"ClientTransTdcIfChannelForSocket";
"SetFileRenameHook";
extern "C++" {
OHOS::StreamAdaptor*;
Communication::SoftBus*;

View File

@ -59,6 +59,7 @@ typedef struct {
sessionNeed info;
int32_t routeType;
int32_t sessionId;
OnRenameFileCallback onRenameFile;
} UdpChannel;
int32_t ClientTransUdpMgrInit(IClientSessionCallBack *callback);
@ -92,6 +93,8 @@ int32_t TransLimitChange(int32_t channelId, uint8_t tos);
int32_t TransSetUdpChanelSessionId(int32_t channelId, int32_t sessionId);
int32_t TransUdpChannelSetStreamMultiLayer(int32_t channelId, const void *optValue);
int32_t TransSetUdpChannelRenameHook(int32_t channelId, OnRenameFileCallback onRenameFile);
#ifdef __cplusplus
}
#endif

View File

@ -796,4 +796,34 @@ int32_t TransSetUdpChanelSessionId(int32_t channelId, int32_t sessionId)
(void)SoftBusMutexUnlock(&(g_udpChannelMgr->lock));
TRANS_LOGE(TRANS_SDK, "udp channel not found, channelId=%{public}d.", channelId);
return SOFTBUS_TRANS_UDP_CHANNEL_NOT_FOUND;
}
int32_t TransSetUdpChannelRenameHook(int32_t channelId, OnRenameFileCallback onRenameFile)
{
if (onRenameFile == NULL) {
TRANS_LOGE(TRANS_SDK, "onRenameFile is null");
return SOFTBUS_INVALID_PARAM;
}
if (g_udpChannelMgr == NULL) {
TRANS_LOGE(TRANS_SDK, "udp channel manager hasn't init.");
return SOFTBUS_NO_INIT;
}
if (SoftBusMutexLock(&(g_udpChannelMgr->lock)) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SDK, "lock failed");
return SOFTBUS_LOCK_ERR;
}
UdpChannel *channelNode = NULL;
LIST_FOR_EACH_ENTRY(channelNode, &(g_udpChannelMgr->list), UdpChannel, node) {
if (channelNode->channelId == channelId && channelNode->businessType == BUSINESS_TYPE_FILE) {
channelNode->onRenameFile = onRenameFile;
(void)SoftBusMutexUnlock(&(g_udpChannelMgr->lock));
return SOFTBUS_OK;
}
}
(void)SoftBusMutexUnlock(&(g_udpChannelMgr->lock));
TRANS_LOGE(TRANS_SDK, "udp channel not found, channelId=%{public}d.", channelId);
return SOFTBUS_TRANS_UDP_CHANNEL_NOT_FOUND;
}

View File

@ -456,6 +456,16 @@ static int32_t UpdateFileRecvPath(int32_t channelId, FileListener *fileListener,
return SOFTBUS_OK;
}
static void RenameHook(DFileRenamePara *renamePara)
{
if (renamePara == NULL) {
TRANS_LOGE(TRANS_SDK, "invalid param renamePara.");
return;
}
(void)strcpy_s(renamePara->newFileName, NSTACKX_MAX_REMOTE_PATH_LEN, renamePara->initFileName);
TRANS_LOGD(TRANS_FILE, "default rename hook.");
}
int32_t TransOnFileChannelOpened(const char *sessionName, const ChannelInfo *channel, int32_t *filePort)
{
if (channel == NULL || filePort == NULL) {
@ -491,6 +501,10 @@ int32_t TransOnFileChannelOpened(const char *sessionName, const ChannelInfo *cha
*filePort = 0;
return SOFTBUS_FILE_ERR;
}
if (NSTACKX_DFileSetRenameHook(fileSession, RenameHook) != NSTACKX_EOK) {
TRANS_LOGE(TRANS_FILE, "set rename hook failed, fileSession=%{public}d, channelId=%{public}d", fileSession,
channel->channelId);
}
} else {
fileSession = StartNStackXDFileClient(channel->peerIp, channel->peerPort,
(uint8_t *)channel->sessionKey, DEFAULT_KEY_LENGTH, FileSendListener);