mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-27 10:50:41 +00:00
!7153 fix: set rename callback
Merge pull request !7153 from xuxiaoqing/master
This commit is contained in:
commit
6db3d124bc
@ -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
|
||||
|
@ -528,6 +528,7 @@
|
||||
"OpenAuthSessionWithPara";
|
||||
"ResourceConflictCheck";
|
||||
"ClientTransTdcIfChannelForSocket";
|
||||
"SetFileRenameHook";
|
||||
extern "C++" {
|
||||
OHOS::StreamAdaptor*;
|
||||
Communication::SoftBus*;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user