1 /*
2 * Copyright (c) 2022 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 #include <map>
17 #include <securec.h>
18 #include <session.h>
19 #include <string>
20
21 #include "socket.h"
22 #include "softbus_bus_center.h"
23
24 static std::map<std::string, std::map<std::string, const ISessionListener *>> sessionListeners;
25 static std::map<std::string, INodeStateCb *> callbacks_;
26
OpenSession(const char * mySessionName,const char * peerSessionName,const char * peerDeviceId,const char * groupId,const SessionAttribute * attr)27 int OpenSession(const char *mySessionName, const char *peerSessionName, const char *peerDeviceId, const char *groupId,
28 const SessionAttribute *attr)
29 {
30 return -1;
31 }
32
SendBytes(int sessionId,const void * data,unsigned int len)33 int SendBytes(int sessionId, const void *data, unsigned int len)
34 {
35 return -1;
36 }
37
RemoveSessionServer(const char * pkgName,const char * sessionName)38 int RemoveSessionServer(const char *pkgName, const char *sessionName)
39 {
40 const char *invalidSessionName = "INVALID_SESSION_NAME";
41 const char *closeFailedSessionName = "REMOVE_FAILED_SESSION_NAME";
42 if (!strcmp(sessionName, invalidSessionName)) {
43 return -1;
44 }
45 if (!strcmp(sessionName, closeFailedSessionName)) {
46 return -1;
47 }
48 return 0;
49 }
GetMySessionName(int sessionId,char * sessionName,unsigned int len)50 int GetMySessionName(int sessionId, char *sessionName, unsigned int len)
51 {
52 return 0;
53 }
GetPeerSessionName(int sessionId,char * sessionName,unsigned int len)54 int GetPeerSessionName(int sessionId, char *sessionName, unsigned int len)
55 {
56 return 0;
57 }
GetPeerDeviceId(int sessionId,char * devId,unsigned int len)58 int GetPeerDeviceId(int sessionId, char *devId, unsigned int len)
59 {
60 return 0;
61 }
CloseSession(int sessionId)62 void CloseSession(int sessionId){};
GetSessionSide(int sessionId)63 int GetSessionSide(int sessionId)
64 {
65 return 1;
66 };
67
GetLocalNodeDeviceInfo(const char * pkgName,NodeBasicInfo * info)68 int32_t GetLocalNodeDeviceInfo(const char *pkgName, NodeBasicInfo *info)
69 {
70 return -1;
71 }
72
GetAllNodeDeviceInfo(const char * pkgName,NodeBasicInfo ** info,int32_t * infoNum)73 int32_t GetAllNodeDeviceInfo(const char *pkgName, NodeBasicInfo **info, int32_t *infoNum)
74 {
75 (*info) = (NodeBasicInfo *)malloc(sizeof(NodeBasicInfo));
76 (*infoNum) = 1;
77 return 0;
78 }
79
GetNodeKeyInfo(const char * pkgName,const char * networkId,NodeDeviceInfoKey key,uint8_t * info,int32_t infoLen)80 int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, NodeDeviceInfoKey key, uint8_t *info,
81 int32_t infoLen)
82 {
83 return -1;
84 }
85
CreateSessionServer(const char * pkgName,const char * sessionName,const ISessionListener * listener)86 int CreateSessionServer(const char *pkgName, const char *sessionName, const ISessionListener *listener)
87 {
88 const char *invalidSessionName = "INVALID_SESSION_NAME";
89 if (!strcmp(sessionName, invalidSessionName)) {
90 return -1;
91 }
92 return 0;
93 }
94
Socket(SocketInfo info)95 int Socket(SocketInfo info)
96 {
97 const char *invalidSessionName = "INVALID_SESSION_NAME";
98 if (strstr(info.name, invalidSessionName) != nullptr) {
99 return 0;
100 }
101 return 1;
102 }
103
Listen(int32_t socket,const QosTV * qos,uint32_t qosCount,const ISocketListener * listener)104 int Listen(int32_t socket, const QosTV *qos, uint32_t qosCount, const ISocketListener *listener)
105 {
106 if (socket <= 0) {
107 return -1;
108 }
109 return 0;
110 }
111
Bind(int32_t socket,const QosTV * qos,uint32_t qosCount,const ISocketListener * listener)112 int Bind(int32_t socket, const QosTV *qos, uint32_t qosCount, const ISocketListener *listener)
113 {
114 if (socket <= 0) {
115 return -1;
116 }
117 return 0;
118 }