1 /*
2 * Copyright (C) 2021-2023 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 NSTACK_COMMON_H
17 #define NSTACK_COMMON_H
18 #include "nstackx.h"
19 #include "nstackx_list.h"
20 #include "nstackx_epoll.h"
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #ifdef DFINDER_SAVE_DEVICE_LIST
27 typedef struct {
28 NSTACKX_DeviceInfo *deviceList;
29 uint32_t *deviceCountPtr;
30 sem_t wait;
31 } GetDeviceListMessage;
32 #endif
33
34 struct DeviceInfo;
35
36 #ifdef DFINDER_SUPPORT_COVERITY_TAINTED_SET
37 void Coverity_Tainted_Set(void *buf);
38 #else
39 #define Coverity_Tainted_Set(param)
40 #endif
41
42 bool GetIsNotifyPerDevice(void);
43 void NotifyDeviceListChanged(const NSTACKX_DeviceInfo *deviceList, uint32_t deviceCount);
44 void NotifyDeviceFound(const NSTACKX_DeviceInfo *deviceList, uint32_t deviceCount);
45 void NotificationReceived(const NSTACKX_NotificationConfig *notification);
46
47 #ifndef DFINDER_USE_MINI_NSTACKX
48 void NotifyMsgReceived(const char *moduleName, const char *deviceId, const uint8_t *data,
49 uint32_t len, const char *srcIp);
50 #endif /* END OF DFINDER_USE_MINI_NSTACKX */
51 void NotifyDFinderMsgRecver(DFinderMsgType msgType);
52 EpollDesc GetMainLoopEpollFd(void);
53 List *GetMainLoopEvendChain(void);
54 uint32_t GetDefaultDiscoverInterval(uint32_t discoverCount);
55 int32_t CheckBusinessTypeReplyUnicast(uint8_t businessType);
56 int32_t GetServiceDiscoverInfo(const uint8_t *buf, size_t size, struct DeviceInfo *deviceInfo, char **remoteUrlPtr);
57 int32_t GetServiceNotificationInfo(const uint8_t *buf, size_t size, NSTACKX_NotificationConfig *notification);
58 List *GetEventNodeChain(void);
59 EpollDesc GetEpollFD(void);
60
StringHasEOF(const char * str,size_t len)61 static inline bool StringHasEOF(const char *str, size_t len)
62 {
63 ssize_t i;
64 for (i = (ssize_t)len - 1; i >= 0; i--) {
65 if (str[i] == '\0') {
66 return true;
67 }
68 }
69
70 return false;
71 }
72
73 #ifdef __cplusplus
74 };
75 #endif
76
77 #endif /* #ifndef NSTACK_COMMON_H */
78