• 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_SESSION_MANAGER_H
17 #define CLIENT_TRANS_SESSION_MANAGER_H
18 
19 #include "session.h"
20 #include "softbus_def.h"
21 #include "softbus_trans_def.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #define IS_SERVER 0
28 #define IS_CLIENT 1
29 
30 typedef struct {
31     char peerSessionName[SESSION_NAME_SIZE_MAX];
32     char peerDeviceId[DEVICE_ID_SIZE_MAX];
33     char groupId[GROUP_ID_SIZE_MAX];
34     int flag; // TYPE_MESSAGE & TYPE_BYTES & TYPE_FILE
35 } SessionTag;
36 
37 typedef struct {
38     ListNode node;
39     uint16_t timeout;
40     int32_t sessionId;
41     int32_t channelId;
42     ChannelType channelType;
43     SessionTag info;
44     bool isServer;
45     bool isEnable;
46     int32_t peerUid;
47     int32_t peerPid;
48     bool isEncrypt;
49     int32_t routeType;
50 } SessionInfo;
51 
52 typedef struct {
53     ListNode node;
54     SoftBusSecType type;
55     char sessionName[SESSION_NAME_SIZE_MAX];
56     char pkgName[PKG_NAME_SIZE_MAX];
57     union {
58         ISessionListener session;
59     } listener;
60     ListNode sessionList;
61 } ClientSessionServer;
62 
63 typedef enum {
64     KEY_SESSION_NAME = 1,
65     KEY_PEER_SESSION_NAME,
66     KEY_PEER_DEVICE_ID,
67     KEY_IS_SERVER,
68     KEY_PEER_PID,
69     KEY_PEER_UID,
70     KEY_PKG_NAME,
71 } SessionKey;
72 
73 int32_t ClientAddNewSession(const char* sessionName, SessionInfo* session);
74 
75 /**
76  * @brief Add session.
77  * @return  if session already added, return SOFTBUS_TRANS_SESSION_REPEATED, else return SOFTBUS_OK or SOFTBUS_ERR.
78  */
79 int32_t ClientAddSession(const SessionParam *param, int32_t *sessionId, bool *isEnabled);
80 
81 int32_t ClientAddAuthSession(const char *sessionName, int32_t *sessionId);
82 
83 int32_t ClientDeleteSessionServer(SoftBusSecType type, const char *sessionName);
84 
85 int32_t ClientDeleteSession(int32_t sessionId);
86 
87 int32_t ClientGetSessionDataById(int32_t sessionId, char *data, uint16_t len, SessionKey key);
88 
89 int32_t ClientGetSessionIntegerDataById(int32_t sessionId, int *data, SessionKey key);
90 
91 int32_t ClientGetChannelBySessionId(int32_t sessionId, int32_t *channelId, int32_t *type, bool *isEnable);
92 
93 int32_t ClientSetChannelBySessionId(int32_t sessionId, TransInfo *transInfo);
94 
95 int32_t GetEncryptByChannelId(int32_t channelId, int32_t channelType, int32_t *data);
96 
97 int32_t ClientGetSessionIdByChannelId(int32_t channelId, int32_t channelType, int32_t *sessionId);
98 
99 int32_t ClientEnableSessionByChannelId(const ChannelInfo *channel, int32_t *sessionId);
100 
101 int32_t ClientGetSessionCallbackById(int32_t sessionId, ISessionListener *callback);
102 
103 int32_t ClientGetSessionCallbackByName(const char *sessionName, ISessionListener *callback);
104 
105 int32_t ClientAddSessionServer(SoftBusSecType type, const char *pkgName, const char *sessionName,
106     const ISessionListener *listener);
107 
108 int32_t ClientGetSessionSide(int32_t sessionId);
109 
110 int TransClientInit(void);
111 void TransClientDeinit(void);
112 
113 int32_t ReCreateSessionServerToServer(void);
114 void ClientTransRegLnnOffline(void);
115 
116 void ClientTransOnLinkDown(const char *networkId, int32_t routeType);
117 #ifdef __cplusplus
118 }
119 #endif
120 #endif // CLIENT_TRANS_SESSION_MANAGER_H