• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef CLIENT_TRANS_PROXY_CHANNEL_H
17 #define CLIENT_TRANS_PROXY_CHANNEL_H
18 
19 #include "client_trans_file_listener.h"
20 #include "client_trans_session_callback.h"
21 #include "softbus_def.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #ifdef __linux__
28 #define MAX_FILE_NUM 1
29 #else
30 #define MAX_FILE_NUM 1
31 #endif
32 #define MAX_RECV_FILE_NUM 50
33 #define MAX_FILE_PATH_NAME_LEN 512
34 
35 #define FRAME_DATA_SEQ_OFFSET (4)
36 #define PROXY_MAX_PACKET_SIZE (1024 - 48)
37 #define MAX_FILE_SIZE (0x500000) /* 5M */
38 
39 #define PATH_SEPARATOR '/'
40 #define DEFAULT_NEW_PATH_AUTHORITY (0750)
41 
42 #define INVALID_NODE_INDEX (-1)
43 #define INVALID_FD (-1)
44 
45 typedef struct {
46     int32_t channelId;
47     int32_t sessionId;
48     FileListener fileListener;
49 } SendListenerInfo;
50 
51 typedef struct {
52     uint32_t seqCount;
53     SoftBusMutex lock;
54     uint32_t seqLockInitFlag;
55 } SendFileInfo;
56 
57 typedef struct {
58     uint8_t *buffer;
59     uint32_t bufferSize;
60 } FileListBuffer;
61 
62 typedef struct {
63     int32_t frameType;
64     uint32_t frameLength;
65     uint8_t *data;
66 } FileFrame;
67 
68 typedef enum {
69     NODE_IDLE,
70     NODE_BUSY,
71     NODE_ERR,
72 } RecvFileNodeStatus;
73 
74 typedef struct {
75     int32_t index;
76     uint32_t seq;
77     int32_t fileFd;
78     int32_t fileStatus; /* 0: idle 1:busy */
79     uint64_t fileOffset;
80     int32_t timeOut;
81     char filePath[MAX_FILE_PATH_NAME_LEN];
82 } SingleFileInfo;
83 
84 typedef struct {
85     SoftBusMutex lock;
86     int32_t sessionId;
87     FileListener fileListener;
88     SingleFileInfo recvFileInfo[MAX_RECV_FILE_NUM];
89 } RecvFileInfo;
90 
91 int32_t ClinetTransProxyInit(const IClientSessionCallBack *cb);
92 
93 void ClientTransProxyDeinit(void);
94 
95 int32_t ClientTransProxyOnChannelOpened(const char *sessionName, const ChannelInfo *channel);
96 
97 int32_t ClientTransProxyOnChannelClosed(int32_t channelId);
98 
99 int32_t ClientTransProxyOnChannelOpenFailed(int32_t channelId);
100 
101 int32_t ClientTransProxyOnDataReceived(int32_t channelId,
102     const void *data, uint32_t len, SessionPktType type);
103 
104 void ClientTransProxyCloseChannel(int32_t channelId);
105 
106 int32_t TransProxyChannelSendBytes(int32_t channelId, const void *data, uint32_t len);
107 
108 int32_t TransProxyChannelSendMessage(int32_t channelId, const void *data, uint32_t len);
109 
110 int32_t TransProxyChannelSendFile(int32_t channelId, const char *sFileList[], const char *dFileList[],
111     uint32_t fileCnt);
112 
113 int32_t ProcessFileFrameData(int32_t sessionId, FileListener fileListener, const char *data, uint32_t len,
114     int32_t type);
115 
116 int32_t ProcessFileListData(int32_t sessionId, FileListener fileListener, const char *data, uint32_t len);
117 
118 #ifdef __cplusplus
119 }
120 #endif
121 #endif
122