mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-24 17:29:54 +00:00
codex fix for coap disc
Signed-off-by: wanghan985406 <wanghan76@huawei.com>
This commit is contained in:
parent
061cf8ade0
commit
31b083dcac
@ -55,22 +55,20 @@ int32_t CoapResolveAddress(const coap_str_const_t *server, struct sockaddr *dst)
|
||||
struct addrinfo *ainfo = NULL;
|
||||
struct addrinfo hints;
|
||||
char addrstr[DEFAULT_COAP_BUFFER_LENGTH]; /* Get a char array with length 256 to save host name. */
|
||||
int error;
|
||||
int32_t len = -1;
|
||||
|
||||
if (server == NULL || server->s == NULL || dst == NULL) {
|
||||
return len;
|
||||
return NSTACKX_EINVAL;
|
||||
}
|
||||
(void)memset_s(addrstr, sizeof(addrstr), 0, sizeof(addrstr));
|
||||
if (server->length) {
|
||||
if (memcpy_s(addrstr, sizeof(addrstr), server->s, server->length) != EOK) {
|
||||
DFINDER_LOGD(TAG, "addrstr copy error");
|
||||
return len;
|
||||
return NSTACKX_EFAILED;
|
||||
}
|
||||
} else {
|
||||
if (memcpy_s(addrstr, sizeof(addrstr), "localhost", strlen("localhost")) != EOK) {
|
||||
DFINDER_LOGD(TAG, "addrstr copy error");
|
||||
return len;
|
||||
return NSTACKX_EFAILED;
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,24 +76,25 @@ int32_t CoapResolveAddress(const coap_str_const_t *server, struct sockaddr *dst)
|
||||
hints.ai_socktype = SOCK_DGRAM;
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
|
||||
error = getaddrinfo(addrstr, NULL, &hints, &res);
|
||||
int32_t error = getaddrinfo(addrstr, NULL, &hints, &res);
|
||||
if (error != 0) {
|
||||
DFINDER_LOGE(TAG, "getaddrinfo error");
|
||||
return error;
|
||||
}
|
||||
|
||||
socklen_t len = 0;
|
||||
for (ainfo = res; ainfo != NULL; ainfo = ainfo->ai_next) {
|
||||
switch (ainfo->ai_family) {
|
||||
case AF_INET6:
|
||||
/* fall-through */
|
||||
case AF_INET:
|
||||
len = ainfo->ai_addrlen;
|
||||
if (memcpy_s(dst, sizeof(struct sockaddr), ainfo->ai_addr, len) != EOK) {
|
||||
if (memcpy_s(dst, sizeof(struct sockaddr), ainfo->ai_addr, (size_t)len) != EOK) {
|
||||
DFINDER_LOGE(TAG, "ai_addr copy error");
|
||||
len = -1;
|
||||
break;
|
||||
error = NSTACKX_EFAILED;
|
||||
goto finish;
|
||||
}
|
||||
goto finish;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -103,7 +102,7 @@ int32_t CoapResolveAddress(const coap_str_const_t *server, struct sockaddr *dst)
|
||||
|
||||
finish:
|
||||
freeaddrinfo(res);
|
||||
return len;
|
||||
return (error == NSTACKX_EFAILED) ? error : (int32_t)len;
|
||||
}
|
||||
|
||||
coap_response_t CoapMessageHandler(coap_session_t *session,
|
||||
|
@ -1402,8 +1402,7 @@ static int32_t NSTACKX_SendMsgParamCheck(const char *moduleName, const char *dev
|
||||
return NSTACKX_EOK;
|
||||
}
|
||||
|
||||
static int MsgCtxInit(MsgCtx *msg, const char *moduleName, const char *deviceId,
|
||||
const uint8_t *data, uint32_t len, uint8_t type)
|
||||
static int MsgCtxInit(MsgCtx *msg, const char *moduleName, const char *deviceId, const uint8_t *data, uint32_t len)
|
||||
{
|
||||
if (SemInit(&msg->wait, 0, 0)) {
|
||||
DFINDER_LOGE(TAG, "sem init fail");
|
||||
@ -1414,7 +1413,6 @@ static int MsgCtxInit(MsgCtx *msg, const char *moduleName, const char *deviceId,
|
||||
msg->moduleName = moduleName;
|
||||
msg->data = data;
|
||||
msg->len = len;
|
||||
msg->type = type;
|
||||
msg->err = NSTACKX_EOK;
|
||||
|
||||
return NSTACKX_EOK;
|
||||
@ -1451,8 +1449,8 @@ int32_t NSTACKX_SendMsgDirect(const char *moduleName, const char *deviceId, cons
|
||||
return NSTACKX_EINVAL;
|
||||
}
|
||||
directMsg.ipStr = ipaddr;
|
||||
|
||||
if (MsgCtxInit(&directMsg.msg, moduleName, deviceId, data, len, type) != NSTACKX_EOK) {
|
||||
directMsg.msg.type = type;
|
||||
if (MsgCtxInit(&directMsg.msg, moduleName, deviceId, data, len) != NSTACKX_EOK) {
|
||||
return NSTACKX_EFAILED;
|
||||
}
|
||||
|
||||
@ -1516,7 +1514,8 @@ int32_t NSTACKX_SendMsg(const char *moduleName, const char *deviceId, const uint
|
||||
}
|
||||
|
||||
MsgCtx msg;
|
||||
if (MsgCtxInit(&msg, moduleName, deviceId, data, len, INVALID_TYPE) != NSTACKX_EOK) {
|
||||
msg.type = INVALID_TYPE;
|
||||
if (MsgCtxInit(&msg, moduleName, deviceId, data, len) != NSTACKX_EOK) {
|
||||
return NSTACKX_EFAILED;
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ static int32_t UpdateDeviceDbInDeviceList(const CoapCtxType *coapCtx, const Devi
|
||||
return NSTACKX_EFAILED;
|
||||
}
|
||||
const struct in_addr *remoteIp = &(deviceInfo->netChannelInfo.wifiApInfo.ip);
|
||||
uint8_t updated = NSTACKX_FALSE;
|
||||
int8_t updated = NSTACKX_FALSE;
|
||||
if (UpdateRemoteNodeByDeviceInfo(deviceId, &info, remoteIp, deviceInfo, &updated) != NSTACKX_EOK) {
|
||||
DFINDER_LOGE(TAG, "update remote node by deviceinfo failed");
|
||||
return NSTACKX_EFAILED;
|
||||
@ -431,7 +431,7 @@ uint16_t GetSequenceNumber(uint8_t sendBcast)
|
||||
return (sendBcast) ? g_seqAll.seqBcast : g_seqAll.seqUcast;
|
||||
}
|
||||
|
||||
void ResetSequenceNumber()
|
||||
void ResetSequenceNumber(void)
|
||||
{
|
||||
(void)memset_s(&g_seqAll, sizeof(g_seqAll), 0, sizeof(g_seqAll));
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ static RxIface *CreateRxIface(RemoteDevice *device, const NSTACKX_InterfaceInfo
|
||||
return rxIface;
|
||||
}
|
||||
|
||||
static uint32_t CheckAndUpdateBusinessAll(BusinessDataAll *curInfo, const BusinessDataAll *newInfo, uint8_t *updated)
|
||||
static uint32_t CheckAndUpdateBusinessAll(BusinessDataAll *curInfo, const BusinessDataAll *newInfo, int8_t *updated)
|
||||
{
|
||||
if (newInfo->isBroadcast == NSTACKX_TRUE) {
|
||||
if (strcmp(curInfo->businessDataBroadcast, newInfo->businessDataBroadcast) != 0) {
|
||||
@ -294,13 +294,13 @@ static RemoteNode *CreateRemoteNode(RxIface *rxIface, const struct in_addr *remo
|
||||
return remoteNode;
|
||||
}
|
||||
|
||||
static int32_t UpdateDeviceInfoBusinessData(DeviceInfo *curInfo, const DeviceInfo *newInfo, uint8_t *updated)
|
||||
static int32_t UpdateDeviceInfoBusinessData(DeviceInfo *curInfo, const DeviceInfo *newInfo, int8_t *updated)
|
||||
{
|
||||
return CheckAndUpdateBusinessAll(&curInfo->businessData, &newInfo->businessData, updated);
|
||||
}
|
||||
|
||||
static int32_t UpdateCapabilityBitmap(DeviceInfo *curInfo, const DeviceInfo *newInfo,
|
||||
uint8_t *updated)
|
||||
int8_t *updated)
|
||||
{
|
||||
/* judge capabilityBitmap is or not different with new deviceInfo */
|
||||
if ((curInfo->capabilityBitmapNum != newInfo->capabilityBitmapNum) ||
|
||||
@ -324,7 +324,7 @@ static int32_t UpdateCapabilityBitmap(DeviceInfo *curInfo, const DeviceInfo *new
|
||||
return NSTACKX_EOK;
|
||||
}
|
||||
|
||||
static int32_t UpdateDeviceInfoInner(DeviceInfo *curInfo, const DeviceInfo *newInfo, uint8_t *updated)
|
||||
static int32_t UpdateDeviceInfoInner(DeviceInfo *curInfo, const DeviceInfo *newInfo, int8_t *updated)
|
||||
{
|
||||
if (curInfo->deviceType != newInfo->deviceType) {
|
||||
DFINDER_LOGE(TAG, "deviceType is different");
|
||||
@ -365,9 +365,9 @@ static int32_t UpdateDeviceInfoInner(DeviceInfo *curInfo, const DeviceInfo *newI
|
||||
}
|
||||
|
||||
static int32_t UpdateDeviceInfo(DeviceInfo *curInfo, const RxIface *rxIface, const DeviceInfo *newInfo,
|
||||
uint8_t *updatedPtr)
|
||||
int8_t *updatedPtr)
|
||||
{
|
||||
uint8_t updated = NSTACKX_FALSE;
|
||||
int8_t updated = NSTACKX_FALSE;
|
||||
if (UpdateDeviceInfoInner(curInfo, newInfo, &updated) != NSTACKX_EOK) {
|
||||
DFINDER_LOGE(TAG, "UpdateDeviceInfoInner error");
|
||||
return NSTACKX_EFAILED;
|
||||
@ -421,7 +421,7 @@ static int32_t UpdateDeviceInfo(DeviceInfo *curInfo, const RxIface *rxIface, con
|
||||
return NSTACKX_EOK;
|
||||
}
|
||||
|
||||
static void UpdatedByTimeout(RxIface *rxIface, uint8_t *updated)
|
||||
static void UpdatedByTimeout(RxIface *rxIface, int8_t *updated)
|
||||
{
|
||||
struct timespec cur;
|
||||
ClockGetTime(CLOCK_MONOTONIC, &cur);
|
||||
@ -433,7 +433,7 @@ static void UpdatedByTimeout(RxIface *rxIface, uint8_t *updated)
|
||||
}
|
||||
|
||||
static int32_t UpdateRemoteNode(RemoteNode *remoteNode, RxIface *rxIface, const DeviceInfo *deviceInfo,
|
||||
uint8_t *updated)
|
||||
int8_t *updated)
|
||||
{
|
||||
int32_t ret = UpdateDeviceInfo(&remoteNode->deviceInfo, rxIface, deviceInfo, updated);
|
||||
if (ret == NSTACKX_EOK && (*updated == NSTACKX_FALSE)) {
|
||||
@ -443,7 +443,7 @@ static int32_t UpdateRemoteNode(RemoteNode *remoteNode, RxIface *rxIface, const
|
||||
}
|
||||
|
||||
#ifdef DFINDER_DISTINGUISH_ACTIVE_PASSIVE_DISCOVERY
|
||||
static void UpdateRemoteNodeChangeStateActive(UpdateState *curState, uint8_t *updated)
|
||||
static void UpdateRemoteNodeChangeStateActive(UpdateState *curState, int8_t *updated)
|
||||
{
|
||||
switch (*curState) {
|
||||
case DFINDER_UPDATE_STATE_NULL:
|
||||
@ -470,7 +470,7 @@ static void UpdateRemoteNodeChangeStateActive(UpdateState *curState, uint8_t *up
|
||||
}
|
||||
}
|
||||
|
||||
static void UpdateRemoteNodeChangeStatePassive(UpdateState *curState, uint8_t *updated)
|
||||
static void UpdateRemoteNodeChangeStatePassive(UpdateState *curState, int8_t *updated)
|
||||
{
|
||||
switch (*curState) {
|
||||
case DFINDER_UPDATE_STATE_NULL:
|
||||
@ -498,7 +498,7 @@ static void UpdateRemoteNodeChangeStatePassive(UpdateState *curState, uint8_t *u
|
||||
}
|
||||
|
||||
static void CheckAndUpdateRemoteNodeChangeState(RemoteNode *remoteNode,
|
||||
const DeviceInfo *deviceInfo, uint8_t *updated)
|
||||
const DeviceInfo *deviceInfo, int8_t *updated)
|
||||
{
|
||||
UpdateState *curState = &(remoteNode->updateState);
|
||||
if (deviceInfo->discoveryType == NSTACKX_DISCOVERY_TYPE_PASSIVE) {
|
||||
@ -621,7 +621,7 @@ static RemoteNode *CheckAndCreateRemoteNode(RxIface *rxIface,
|
||||
}
|
||||
|
||||
int32_t UpdateRemoteNodeByDeviceInfo(const char *deviceId, const NSTACKX_InterfaceInfo *interfaceInfo,
|
||||
const struct in_addr *remoteIp, const DeviceInfo *deviceInfo, uint8_t *updated)
|
||||
const struct in_addr *remoteIp, const DeviceInfo *deviceInfo, int8_t *updated)
|
||||
{
|
||||
RemoteDevice *device = FindRemoteDevice(g_remoteDeviceList, deviceId);
|
||||
if (device == NULL) {
|
||||
|
@ -190,7 +190,7 @@ static int DumpStatistics(char *buf, uint32_t size)
|
||||
|
||||
int DFinderDumpIface(char *buf, int size, const char *ifname, const struct in_addr *ip, uint8_t state)
|
||||
{
|
||||
int index = 0;
|
||||
uint32_t index = 0;
|
||||
int ret;
|
||||
DUMP_MSG_ADD_CHECK(ret, buf, index, size, "network name:%s"CRLF, ifname);
|
||||
DUMP_MSG_ADD_CHECK(ret, buf, index, size, "if state:%hhu"CRLF, state);
|
||||
@ -213,9 +213,9 @@ int DFinderDumpIface(char *buf, int size, const char *ifname, const struct in_ad
|
||||
#define DFINDER_DEVICE_ID_ANONY_REMOTE_LEN 15
|
||||
int DumpDeviceInfo(const DeviceInfo *info, char *buf, int size, uint8_t remote)
|
||||
{
|
||||
int index = 0;
|
||||
int ret;
|
||||
int i;
|
||||
uint32_t index = 0;
|
||||
size_t len;
|
||||
char deviceid[DFINDER_DEVICE_ID_ANONY_REMOTE_LEN + 1] = {0};
|
||||
DUMP_MSG_ADD_CHECK(ret, buf, index, size, "device name:%s"CRLF, info->deviceName);
|
||||
@ -295,8 +295,8 @@ static int DumpRemoteDeviceInfo(char *buf, uint32_t size)
|
||||
static int DumpCapFilterInfoImp(char *buf, uint32_t size)
|
||||
{
|
||||
int i;
|
||||
int index = 0;
|
||||
int ret;
|
||||
uint32_t index = 0;
|
||||
uint32_t bitmapNum;
|
||||
uint32_t *bitmap = GetFilterCapability(&bitmapNum);
|
||||
|
||||
@ -323,7 +323,7 @@ static int DumpCapFilterInfo(char *buf, uint32_t size)
|
||||
static int DumpHelp(char *buf, uint32_t size)
|
||||
{
|
||||
int ret;
|
||||
int index = 0;
|
||||
uint32_t index = 0;
|
||||
DUMP_MSG_ADD_CHECK(ret, buf, index, size, CRLF"Usage: dfinder <opt>"CRLF);
|
||||
DUMP_MSG_ADD_CHECK(ret, buf, index, size, " -h show this help"CRLF);
|
||||
DUMP_MSG_ADD_CHECK(ret, buf, index, size, " -l show local device info"CRLF);
|
||||
|
@ -119,7 +119,7 @@ typedef struct DeviceInfo {
|
||||
char deviceId[NSTACKX_MAX_DEVICE_ID_LEN];
|
||||
char deviceName[NSTACKX_MAX_DEVICE_NAME_LEN];
|
||||
#ifdef DFINDER_SAVE_DEVICE_LIST
|
||||
uint8_t update : 1;
|
||||
int8_t update : 1;
|
||||
uint8_t reserved : 7;
|
||||
#endif
|
||||
uint32_t deviceType;
|
||||
@ -171,7 +171,7 @@ uint32_t GetMaxDeviceNum(void);
|
||||
uint32_t *GetFilterCapability(uint32_t *capabilityBitmapNum);
|
||||
void IncreaseSequenceNumber(uint8_t sendBcast);
|
||||
uint16_t GetSequenceNumber(uint8_t sendBcast);
|
||||
void ResetSequenceNumber();
|
||||
void ResetSequenceNumber(void);
|
||||
|
||||
int32_t RegisterCapability(uint32_t capabilityBitmapNum, uint32_t capabilityBitmap[]);
|
||||
int32_t SetFilterCapability(uint32_t capabilityBitmapNum, uint32_t capabilityBitmap[]);
|
||||
|
@ -30,7 +30,7 @@ void BackupRemoteDeviceList(void);
|
||||
void DestroyRxIfaceByIfname(const char *ifName);
|
||||
const struct in_addr *GetRemoteDeviceIp(const char *deviceId);
|
||||
int32_t UpdateRemoteNodeByDeviceInfo(const char *deviceId, const NSTACKX_InterfaceInfo *interfaceInfo,
|
||||
const struct in_addr *remoteIp, const DeviceInfo *deviceInfo, uint8_t *updated);
|
||||
const struct in_addr *remoteIp, const DeviceInfo *deviceInfo, int8_t *updated);
|
||||
|
||||
void GetDeviceList(NSTACKX_DeviceInfo *deviceList, uint32_t *deviceCountPtr, bool doFilter);
|
||||
void SetDeviceListAgingTime(uint32_t agingTime);
|
||||
|
Loading…
Reference in New Issue
Block a user