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 "inner_socket.h" 20 21 #include "client_trans_session_manager.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 typedef struct { 28 ListNode node; 29 int32_t socketId; 30 int32_t channelId; 31 int32_t seq; 32 int32_t channelType; 33 uint32_t timeout; 34 } DataSeqInfo; 35 36 int32_t GenerateSessionId(void); 37 38 void DestroySessionId(void); 39 40 bool IsValidSessionParam(const SessionParam *param); 41 42 SessionInfo *CreateNewSession(const SessionParam *param); 43 44 NO_SANITIZE("cfi") DestroySessionInfo *CreateDestroySessionNode(SessionInfo *sessionNode, 45 const ClientSessionServer *server); 46 47 NO_SANITIZE("cfi") void ClientDestroySession(const ListNode *destroyList, ShutdownReason reason); 48 49 void DestroyClientSessionServer(ClientSessionServer *server, ListNode *destroyList); 50 51 ClientSessionServer *GetNewSessionServer(SoftBusSecType type, const char *sessionName, 52 const char *pkgName, const ISessionListener *listener); 53 54 SessionInfo *CreateNonEncryptSessionInfo(const char *sessionName); 55 56 void DestroyAllClientSession(const ClientSessionServer *server, ListNode *destroyList); 57 58 void DestroyClientSessionByNetworkId(const ClientSessionServer *server, 59 const char *networkId, int32_t type, ListNode *destroyList); 60 61 SessionServerInfo *CreateSessionServerInfoNode(const ClientSessionServer *clientSessionServer); 62 63 ClientSessionServer *GetNewSocketServer(SoftBusSecType type, const char *sessionName, const char *pkgName); 64 65 bool IsDistributedDataSession(const char *sessionName); 66 67 bool IsDifferentDataType(const SessionInfo *sessionInfo, int dataType, bool isEncyptedRawStream); 68 69 SessionInfo *CreateNewSocketSession(const SessionParam *param); 70 71 int32_t CheckBindSocketInfo(const SessionInfo *session); 72 73 void FillSessionParam(SessionParam *param, SessionAttribute *tmpAttr, 74 ClientSessionServer *serverNode, SessionInfo *sessionNode); 75 76 void ClientConvertRetVal(int32_t socket, int32_t *retOut); 77 78 void ClientCleanUpIdleTimeoutSocket(const ListNode *destroyList); 79 80 void ClientCheckWaitTimeOut(const ClientSessionServer *serverNode, SessionInfo *sessionNode, 81 int32_t waitOutSocket[], uint32_t capacity, uint32_t *num); 82 83 void ClientCleanUpWaitTimeoutSocket(int32_t waitOutSocket[], uint32_t waitOutNum); 84 85 void ClientUpdateIdleTimeout(const ClientSessionServer *serverNode, SessionInfo *sessionNode, ListNode *destroyList); 86 87 int32_t ClientDeleteSocketSession(int32_t sessionId); 88 89 int32_t ClientRemovePermission(const char *busName); 90 91 int32_t ClientGrantPermission(int uid, int pid, const char *busName); 92 93 int32_t GetQosValue(const QosTV *qos, uint32_t qosCount, QosType type, int32_t *value, int32_t defVal); 94 95 int32_t ReCreateSessionServerToServer(ListNode *sessionServerInfoList); 96 97 void FillDfsSocketParam( 98 SessionParam *param, SessionAttribute *tmpAttr, ClientSessionServer *serverNode, SessionInfo *sessionNode); 99 100 void PrivilegeDestroyAllClientSession( 101 const ClientSessionServer *server, ListNode *destroyList, const char *peerNetworkId); 102 103 int32_t ClientRegisterRelationChecker(IFeatureAbilityRelationChecker *relationChecker); 104 105 int32_t ClientTransCheckCollabRelation( 106 const CollabInfo *sourceInfo, const CollabInfo *sinkInfo, int32_t channelId, int32_t channelType); 107 108 void DestroyRelationChecker(void); 109 110 int32_t LockClientDataSeqInfoList(void); 111 112 void UnlockClientDataSeqInfoList(void); 113 114 int32_t TransDataSeqInfoListInit(void); 115 116 void TransDataSeqInfoListDeinit(void); 117 118 int32_t DataSeqInfoListAddItem(uint32_t dataSeq, int32_t channelId, int32_t socketId, int32_t channelType); 119 120 int32_t DeleteDataSeqInfoList(uint32_t dataSeq, int32_t channelId); 121 122 void TransAsyncSendBytesTimeoutProc(void); 123 #ifdef __cplusplus 124 } 125 #endif 126 #endif // CLIENT_TRANS_SESSION_OPERATE_H 127