1 /*
2  * Copyright (c) 2021-2024 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_OPERATE_H
17 #define CLIENT_TRANS_SESSION_OPERATE_H
18 
19 #include "session.h"
20 #include "socket.h"
21 #include "softbus_def.h"
22 #include "softbus_trans_def.h"
23 #include "client_trans_session_adapter.h"
24 #include "client_trans_session_manager.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 int32_t GenerateSessionId(void);
31 
32 void DestroySessionId(void);
33 
34 bool IsValidSessionParam(const SessionParam *param);
35 
36 SessionInfo *CreateNewSession(const SessionParam *param);
37 
38 NO_SANITIZE("cfi") DestroySessionInfo *CreateDestroySessionNode(SessionInfo *sessionNode,
39     const ClientSessionServer *server);
40 
41 NO_SANITIZE("cfi") void ClientDestroySession(const ListNode *destroyList, ShutdownReason reason);
42 
43 void DestroyClientSessionServer(ClientSessionServer *server, ListNode *destroyList);
44 
45 ClientSessionServer *GetNewSessionServer(SoftBusSecType type, const char *sessionName,
46     const char *pkgName, const ISessionListener *listener);
47 
48 SessionInfo *CreateNonEncryptSessionInfo(const char *sessionName);
49 
50 void DestroyClientSessionByNetworkId(const ClientSessionServer *server,
51     const char *networkId, int32_t type, ListNode *destroyList);
52 
53 SessionServerInfo *CreateSessionServerInfoNode(const ClientSessionServer *clientSessionServer);
54 
55 ClientSessionServer *GetNewSocketServer(SoftBusSecType type, const char *sessionName, const char *pkgName);
56 
57 bool IsDistributedDataSession(const char *sessionName);
58 
59 bool IsDifferentDataType(const SessionInfo *sessionInfo, int dataType, bool isEncyptedRawStream);
60 
61 SessionInfo *CreateNewSocketSession(const SessionParam *param);
62 
63 int32_t CheckBindSocketInfo(const SessionInfo *session);
64 
65 void FillSessionParam(SessionParam *param, SessionAttribute *tmpAttr,
66     ClientSessionServer *serverNode, SessionInfo *sessionNode);
67 
68 void ClientConvertRetVal(int32_t socket, int32_t *retOut);
69 
70 void ClientCleanUpIdleTimeoutSocket(const ListNode *destroyList);
71 
72 void ClientCheckWaitTimeOut(const ClientSessionServer *serverNode, SessionInfo *sessionNode,
73     int32_t waitOutSocket[], uint32_t capacity, uint32_t *num);
74 
75 void ClientCleanUpWaitTimeoutSocket(int32_t waitOutSocket[], uint32_t waitOutNum);
76 
77 void ClientUpdateIdleTimeout(const ClientSessionServer *serverNode, SessionInfo *sessionNode, ListNode *destroyList);
78 
79 int32_t ClientDeleteSocketSession(int32_t sessionId);
80 
81 int32_t ClientRemovePermission(const char *busName);
82 
83 int32_t ClientGrantPermission(int uid, int pid, const char *busName);
84 
85 int32_t GetQosValue(const QosTV *qos, uint32_t qosCount, QosType type, int32_t *value, int32_t defVal);
86 
87 int32_t ReCreateSessionServerToServer(ListNode *sessionServerInfoList);
88 
89 void FillDfsSocketParam(
90     SessionParam *param, SessionAttribute *tmpAttr, ClientSessionServer *serverNode, SessionInfo *sessionNode);
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 #endif // CLIENT_TRANS_SESSION_OPERATE_H
96