* functions to write to the pipe and read from the pipe.
*/
+#include <cinttypes>
#include <string.h>
#include <errno.h>
#include "messageHandler.h"
#include "platform_features.h"
#include "oic_malloc.h"
#include "logger.h"
-#include <cinttypes>
#define TAG "PIPE_HANDLER"
# Set common flags
if env['CC'] == 'cl':
- # Enable warnings as errors.
# - warning C4133: incompatible type conversion
env.AppendUnique(CCFLAGS=['/we4133'])
# Disable the following warnings:
# - warning C4127: conditional expression is constant
# - Disabled due to the widespread usage in IoTivity
- env.AppendUnique(CCFLAGS=['/wd4127'])
+ # - warning C4200: zero-sized array in struct/union.
+ # - It is an acceptable approach for variable size structs.
+ env.AppendUnique(CCFLAGS=['/wd4127', '/wd4200'])
env.AppendUnique(CCFLAGS=['/EHsc'])
#include "iotivity_config.h"
+#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
* @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_NOT_INITIALIZED or
* ::CA_STATUS_INVALID_PARAM or ::CA_MEMORY_ALLOC_FAILED
*/
-CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size);
+CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, size_t *size);
/**
* Get supported network adapter.
/**
* Macro to verify the validity of input argument.
*
+ * @param expr Expression to verify.
+ * @param log_tag Log tag.
+ * @param log_message Log message.
+ */
+#define VERIFY_TRUE(expr, log_tag, log_message) \
+ VERIFY_TRUE_RET((expr), (log_tag), (log_message), CA_STATUS_INVALID_PARAM)
+
+/**
+ * Macro to verify the validity of input argument.
+ *
+ * @param expr Expression to verify.
+ * @param log_tag Log tag.
+ * @param log_message Log message.
+ * @param ret Return value.
+ */
+#define VERIFY_TRUE_RET(expr, log_tag, log_message, ret) \
+ if (!(expr)) \
+ { \
+ OIC_LOG_V(ERROR, (log_tag), "Invalid input: %s", (log_message)); \
+ return (ret); \
+ } \
+
+/**
+ * Macro to verify the validity of input argument.
+ *
* @param arg log level
* @param log_tag log tag
* @param log_message log message
* @param ret return value
*/
#define VERIFY_NON_NULL_RET(arg, log_tag, log_message, ret) \
- if (NULL == (arg)) \
- { \
- OIC_LOG_V(ERROR, (log_tag), "Invalid input:%s", (log_message)); \
- return (ret); \
- } \
+ VERIFY_TRUE_RET(NULL != (arg), (log_tag), (log_message), (ret))
/**
* Macro to verify the validity of input argument.
typedef struct u_arraylist_t
{
void **data;
- uint32_t length;
- uint32_t capacity;
+ size_t length;
+ size_t capacity;
} u_arraylist_t;
/**
* @param[in] index index of array list.
* @return void pointer of data if success or NULL pointer otherwise.
*/
-void *u_arraylist_get(const u_arraylist_t *list, uint32_t index);
+void *u_arraylist_get(const u_arraylist_t *list, size_t index);
/**
* Returns the index of the data from the array list.
* @param[out]index index of array list.
* @return true if success, false otherwise.
*/
-bool u_arraylist_get_index(const u_arraylist_t *list, const void *data, uint32_t *index);
+bool u_arraylist_get_index(const u_arraylist_t *list, const void *data, size_t *index);
/**
* Add data in the array list.
* @param[in] index index of array list.
* @return void pointer of the data if success or NULL pointer otherwise.
*/
-void *u_arraylist_remove(u_arraylist_t *list, uint32_t index);
+void *u_arraylist_remove(u_arraylist_t *list, size_t index);
/**
* Returns the length of the array list.
* @param[in] list pointer of array list.
* @return length of the array list.
*/
-uint32_t u_arraylist_length(const u_arraylist_t *list);
+size_t u_arraylist_length(const u_arraylist_t *list);
/**
* Returns whether the data exists or not.
int thrRet = oc_thread_new(&threadInfo->thread, ca_thread_pool_pthreads_delegate, info);
if (thrRet != 0)
{
- uint32_t index = 0;
+ size_t index = 0;
if (u_arraylist_get_index(thread_pool->details->threads_list, threadInfo, &index))
{
u_arraylist_remove(thread_pool->details->threads_list, index);
oc_mutex_lock(thread_pool->details->list_lock);
- for (uint32_t i = 0; i < u_arraylist_length(thread_pool->details->threads_list); ++i)
+ for (size_t i = 0; i < u_arraylist_length(thread_pool->details->threads_list); ++i)
{
ca_thread_pool_thread_info_t *threadInfo = (ca_thread_pool_thread_info_t *)
u_arraylist_get(thread_pool->details->threads_list, i);
}
}
-void *u_arraylist_get(const u_arraylist_t *list, uint32_t index)
+void *u_arraylist_get(const u_arraylist_t *list, size_t index)
{
if (!list )
{
return NULL;
}
-bool u_arraylist_get_index(const u_arraylist_t *list, const void *data, uint32_t *index)
+bool u_arraylist_get_index(const u_arraylist_t *list, const void *data, size_t *index)
{
if (!list || !data)
{
return false;
}
- for (uint32_t i = 0; i < list->length; i++)
+ for (size_t i = 0; i < list->length; i++)
{
if (data == list->data[i])
{
list->data = (void **) tmp;
memset(list->data + list->capacity, 0,
(new_capacity - list->capacity) * sizeof(list->data[0]));
- list->capacity = (uint32_t)new_capacity;
+ list->capacity = new_capacity;
}
list->data[list->length] = data;
return true;
}
-void *u_arraylist_remove(u_arraylist_t *list, uint32_t index)
+void *u_arraylist_remove(u_arraylist_t *list, size_t index)
{
void *removed = NULL;
return removed;
}
-uint32_t u_arraylist_length(const u_arraylist_t *list)
+size_t u_arraylist_length(const u_arraylist_t *list)
{
if (!list)
{
return false;
}
- for (uint32_t i = 0; i < list->length; i++)
+ for (size_t i = 0; i < list->length; i++)
{
if (data == list->data[i])
{
{
return;
}
- for (uint32_t i = 0; i < list->length; i++)
+ for (size_t i = 0; i < list->length; i++)
{
OICFree(list->data[i]);
}
*
*/
-CAResult_t CAencryptSsl(const CAEndpoint_t *endpoint, void *data, uint32_t dataLen);
+CAResult_t CAencryptSsl(const CAEndpoint_t *endpoint, void *data, size_t dataLen);
/**
* Performs TLS decryption of the data.
* @retval ::CA_STATUS_FAILED Operation failed.
*
*/
-CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t dataLen);
+CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, size_t dataLen);
/**
* Initiate TLS handshake with selected cipher suite.
* @param[out] size Number of local connectivity structures.
* @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h)
*/
-typedef CAResult_t (*CAAdapterGetNetworkInfo)(CAEndpoint_t **info, uint32_t *size);
+typedef CAResult_t (*CAAdapterGetNetworkInfo)(CAEndpoint_t **info, size_t *size);
/**
* Read Synchronous API callback.
* @return ::CASTATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
CAResult_t CAUpdateBlockOptionType(const CABlockDataID_t *blockID,
- uint8_t blockType);
+ uint16_t blockType);
/**
* Get the block option type from block-wise transfer list.
* @param[in] blockID ID set of CABlockData.
* @return block option type.
*/
-uint8_t CAGetBlockOptionType(const CABlockDataID_t *blockID);
+uint16_t CAGetBlockOptionType(const CABlockDataID_t *blockID);
/**
* Get the block data from block-wise transfer list.
* @param[out] size number of connectivity information structures.
* @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
-CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, uint32_t *size);
+CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, size_t *size);
/**
* Sends unicast data to the remote endpoint.
* @param[out] size No Of Array objects.
* @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
-CAResult_t CAGetNetworkInformationInternal(CAEndpoint_t **info, uint32_t *size);
+CAResult_t CAGetNetworkInformationInternal(CAEndpoint_t **info, size_t *size);
/**
* Terminate network type from selected configuration.
errorInfo.result = (status); \
g_sslCallback(&(peer)->sep.endpoint, &errorInfo); \
}
-/**@def SSL_CHECK_FAIL(peer, ret, str, mutex, error, msg)
- *
- * Checks handshake result and send alert if needed.
- *
- * @param[in] peer remote peer
- * @param[in] ret error code
- * @param[in] str debug string
- * @param[in] mutex ca mutex
- * @param[in] if code does not equal to -1 returns error code
- * @param[in] msg allert message
- */
-#define SSL_CHECK_FAIL(peer, ret, str, mutex, error, msg) \
-if (0 != (ret) && MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY != (int) (ret) && \
- MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED != (int) (ret) && \
- MBEDTLS_ERR_SSL_WANT_READ != (int) (ret) && \
- MBEDTLS_ERR_SSL_WANT_WRITE != (int) (ret) && \
- MBEDTLS_ERR_SSL_NON_FATAL != (int) (ret) && \
- MBEDTLS_SSL_ALERT_MSG_USER_CANCELED != (int) (ret) && \
- MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION != (int) (ret) && \
- MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT != (int) (ret) && \
- MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY != (int) (ret) && \
- MBEDTLS_SSL_ALERT_MSG_NO_CERT != (int) (ret) && \
- MBEDTLS_SSL_ALERT_MSG_BAD_CERT != (int) (ret) && \
- MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT != (int) (ret) && \
- MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED != (int) (ret) && \
- MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED != (int) (ret) && \
- MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN != (int) (ret) && \
- MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK != (int) (ret) && \
- MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME != (int) (ret) && \
- MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY != (int) (ret) && \
- MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL != (int) (ret)) \
-{ \
- OIC_LOG_V(ERROR, NET_SSL_TAG, "%s: -0x%x", (str), -(ret)); \
- if ((int) MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE != (int) (ret) && \
- (int) MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO != (int) (ret)) \
- { \
- mbedtls_ssl_send_alert_message(&(peer)->ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, (msg)); \
- } \
- RemovePeerFromList(&(peer)->sep.endpoint); \
- if (mutex) \
- { \
- oc_mutex_unlock(g_sslContextMutex); \
- } \
- if ((int) MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO != (int)(ret)) \
- { \
- SSL_RES((peer), CA_DTLS_AUTHENTICATION_FAILURE); \
- } \
- OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__); \
- if (-1 != error) \
- { \
- return (error); \
- } \
-}
+
/**@def CONF_SSL(clientConf, serverConf, fn, ...)
*
* Calls \a fn for \a clientConf and \a serverConf.
VERIFY_NON_NULL_RET(tep, NET_SSL_TAG, "secure endpoint is NULL", -1);
VERIFY_NON_NULL_RET(data, NET_SSL_TAG, "data is NULL", -1);
VERIFY_NON_NULL_RET(g_caSslContext, NET_SSL_TAG, "SSL Context is NULL", -1);
- OIC_LOG_V(DEBUG, NET_SSL_TAG, "Data len: %zu", dataLen);
+ OIC_LOG_V(DEBUG, NET_SSL_TAG, "Data len: %" PRIuPTR, dataLen);
OIC_LOG_V(DEBUG, NET_SSL_TAG, "Adapter: %u", ((SslEndPoint_t * )tep)->sep.endpoint.adapter);
ssize_t sentLen = 0;
int adapterIndex = GetAdapterIndex(((SslEndPoint_t * )tep)->sep.endpoint.adapter);
if (0 <= adapterIndex && MAX_SUPPORTED_ADAPTERS > adapterIndex)
{
+ size_t dataToSend = (dataLen > INT_MAX) ? INT_MAX : dataLen;
CAPacketSendCallback sendCallback = g_caSslContext->adapterCallbacks[adapterIndex].sendCallback;
- sentLen = sendCallback(&(((SslEndPoint_t * )tep)->sep.endpoint), (const void *) data, dataLen);
+ sentLen = sendCallback(&(((SslEndPoint_t * )tep)->sep.endpoint), (const void *) data, dataToSend);
if (sentLen != dataLen)
{
OIC_LOG_V(DEBUG, NET_SSL_TAG,
- "Packet was partially sent - total/sent/remained bytes : %d/%d/%d",
+ "Packet was partially sent - sent/total/remained bytes : %d/%" PRIuPTR "/%" PRIuPTR,
sentLen, dataLen, (dataLen - sentLen));
}
}
}
OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);
- return sentLen;
+ return (int)sentLen;
}
/**
* Read callback.
VERIFY_NON_NULL_RET(data, NET_SSL_TAG, "data is NULL", 0);
SslRecBuf_t *recBuf = &((SslEndPoint_t *)tep)->recBuf;
- size_t retLen = (recBuf->len > recBuf->loaded ? recBuf->len - recBuf->loaded : 0);
- retLen = (retLen < dataLen ? retLen : dataLen);
+ size_t retLen = ((recBuf->len > recBuf->loaded) ? (recBuf->len - recBuf->loaded) : 0);
+ retLen = (retLen < dataLen) ? retLen : dataLen;
if (retLen > INT_MAX)
{
*
* @return number of successfully parsed certificates or -1 on error
*/
-static int ParseChain(mbedtls_x509_crt * crt, unsigned char * buf, int bufLen, int * errNum)
+static size_t ParseChain(mbedtls_x509_crt * crt, unsigned char * buf, size_t bufLen, int * errNum)
{
OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__);
VERIFY_NON_NULL_RET(crt, NET_SSL_TAG, "Param crt is NULL" , -1);
size_t len = 0;
unsigned char * tmp = NULL;
- int count = 0;
+ size_t count = 0;
int ret = 0;
- int pos = 0;
+ size_t pos = 0;
*errNum = 0;
while (pos < bufLen)
// optional
int ret;
int errNum;
- int count = ParseChain(&g_caSslContext->crt, g_pkiInfo.crt.data, g_pkiInfo.crt.len, &errNum);
+ size_t count = ParseChain(&g_caSslContext->crt, g_pkiInfo.crt.data, g_pkiInfo.crt.len, &errNum);
if (0 >= count)
{
OIC_LOG(WARNING, NET_SSL_TAG, "Own certificate chain parsing error");
VERIFY_NON_NULL_RET(g_getCredentialsCallback, NET_SSL_TAG, "Credential callback s NULL", -1);
VERIFY_NON_NULL_RET(ssl, NET_SSL_TAG, "ssl pointer is NULL", -1);
VERIFY_NON_NULL_RET(desc, NET_SSL_TAG, "desc pointer is NULL", -1);
- if (descLen > CA_MAX_ENDPOINT_IDENTITY_LEN)
- {
- OIC_LOG(ERROR, NET_SSL_TAG, "desc too long!");
- return -1;
- }
+ VERIFY_TRUE_RET((descLen <= CA_MAX_ENDPOINT_IDENTITY_LEN), NET_SSL_TAG,
+ "desc too long!", -1);
+
(void) notUsed;
uint8_t keyBuf[PSK_LENGTH] = {0};
if (ret > 0)
{
memcpy(((SslEndPoint_t *) ssl)->sep.identity.id, desc, descLen);
- ((SslEndPoint_t *) ssl)->sep.identity.id_length = descLen;
+ ((SslEndPoint_t *) ssl)->sep.identity.id_length = (uint16_t)descLen;
OIC_LOG(DEBUG, NET_SSL_TAG, "PSK:");
OIC_LOG_BUFFER(DEBUG, NET_SSL_TAG, keyBuf, ret);
*/
static SslEndPoint_t *GetSslPeer(const CAEndpoint_t *peer)
{
- uint32_t listIndex = 0;
- uint32_t listLength = 0;
+ size_t listIndex = 0;
+ size_t listLength = 0;
OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__);
VERIFY_NON_NULL_RET(peer, NET_SSL_TAG, "TLS peer is NULL", NULL);
VERIFY_NON_NULL_RET(g_caSslContext, NET_SSL_TAG, "SSL Context is NULL", NULL);
{
OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__);
VERIFY_NON_NULL_VOID(cacheList, NET_SSL_TAG, "cacheList");
- uint32_t listIndex = 0;
- uint32_t listLength = 0;
+ size_t listIndex = 0;
+ size_t listLength = 0;
listLength = u_arraylist_length(cacheList);
for (listIndex = 0; listIndex < listLength; listIndex++)
{
VERIFY_NON_NULL_VOID(g_caSslContext, NET_SSL_TAG, "SSL Context is NULL");
VERIFY_NON_NULL_VOID(endpoint, NET_SSL_TAG, "endpoint");
- uint32_t listLength = u_arraylist_length(g_caSslContext->peerList);
- for (uint32_t listIndex = 0; listIndex < listLength; listIndex++)
+ size_t listLength = u_arraylist_length(g_caSslContext->peerList);
+ for (size_t listIndex = 0; listIndex < listLength; listIndex++)
{
- SslEndPoint_t * tep = (SslEndPoint_t *)u_arraylist_get(g_caSslContext->peerList,listIndex);
+ SslEndPoint_t * tep = (SslEndPoint_t *)u_arraylist_get(g_caSslContext->peerList, listIndex);
if (NULL == tep)
{
continue;
}
}
}
+
+ /**
+ * Checks handshake result. Removes peer from list and sends alert
+ * if handshake failed.
+ *
+ * @param[in] peer Remote peer's endpoint.
+ * @param[in] ret Error code.
+ * @param[in] str Debug string.
+ * @param[in] msg Alert message.
+ *
+ * @return - "true" if the SSL handshake was successful.
+ * - "false" otherwise.
+ */
+static bool checkSslOperation(SslEndPoint_t* peer,
+ int ret,
+ const char* str,
+ unsigned char msg)
+{
+ if ((0 != ret) &&
+ (MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY != ret) &&
+ (MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED != ret) &&
+ (MBEDTLS_ERR_SSL_WANT_READ != ret) &&
+ (MBEDTLS_ERR_SSL_WANT_WRITE != ret) &&
+ (MBEDTLS_ERR_SSL_NON_FATAL != ret) &&
+ (MBEDTLS_SSL_ALERT_MSG_USER_CANCELED != ret) &&
+ (MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION != ret) &&
+ (MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT != ret) &&
+ (MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY != ret) &&
+ (MBEDTLS_SSL_ALERT_MSG_NO_CERT != ret) &&
+ (MBEDTLS_SSL_ALERT_MSG_BAD_CERT != ret) &&
+ (MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT != ret) &&
+ (MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED != ret) &&
+ (MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED != ret) &&
+ (MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN != ret) &&
+ (MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK != ret) &&
+ (MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME != ret) &&
+ (MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY != ret) &&
+ (MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL != ret))
+ {
+ OIC_LOG_V(ERROR, NET_SSL_TAG, "%s: -0x%x", (str), -ret);
+ if ((MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE != ret) &&
+ (MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO != ret))
+ {
+ mbedtls_ssl_send_alert_message(&(peer)->ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, (msg));
+ }
+
+ if (MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO != ret)
+ {
+ SSL_RES((peer), CA_DTLS_AUTHENTICATION_FAILURE);
+ }
+
+ RemovePeerFromList(&(peer)->sep.endpoint);
+ return false;
+ }
+
+ return true;
+}
+
/**
* Deletes session list.
*/
{
VERIFY_NON_NULL_VOID(g_caSslContext, NET_SSL_TAG, "SSL Context is NULL");
- uint32_t listLength = u_arraylist_length(g_caSslContext->peerList);
- for (uint32_t listIndex = 0; listIndex < listLength; listIndex++)
+ size_t listLength = u_arraylist_length(g_caSslContext->peerList);
+ for (size_t listIndex = 0; listIndex < listLength; listIndex++)
{
- SslEndPoint_t * tep = (SslEndPoint_t *)u_arraylist_get(g_caSslContext->peerList,listIndex);
+ SslEndPoint_t * tep = (SslEndPoint_t *)u_arraylist_get(g_caSslContext->peerList, listIndex);
if (NULL == tep)
{
continue;
return;
}
- uint32_t listLength = u_arraylist_length(g_caSslContext->peerList);
+ size_t listLength = u_arraylist_length(g_caSslContext->peerList);
OIC_LOG_V(DEBUG, NET_SSL_TAG,
- "Required transport [%d], peer count [%u]", transportType, listLength);
- for (uint32_t i = listLength; i > 0; i--)
+ "Required transport [%d], peer count [%" PRIuPTR "]", transportType, listLength);
+ for (size_t i = listLength; i > 0; i--)
{
SslEndPoint_t *tep = (SslEndPoint_t *)u_arraylist_get(g_caSslContext->peerList, i - 1);
if (NULL == tep)
RemovePeerFromList(&tep->sep.endpoint);
return NULL;
}
- SSL_CHECK_FAIL(tep, ret, "Handshake error", 0, NULL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE);
+ if (!checkSslOperation(tep,
+ ret,
+ "Handshake error",
+ MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE))
+ {
+ OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);
+ DeleteSslEndPoint(tep);
+ return NULL;
+ }
}
OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);
return tep;
*/
static int StartRetransmit()
{
- uint32_t listIndex = 0;
- uint32_t listLength = 0;
+ size_t listIndex = 0;
+ size_t listLength = 0;
SslEndPoint_t *tep = NULL;
oc_mutex_lock(g_sslContextMutex);
//start new timer
registerTimer(RETRANSMISSION_TIME, &g_caSslContext->timerId, (void *) StartRetransmit);
//unlock & return
- SSL_CHECK_FAIL(tep, ret, "Retransmission", 1, CA_STATUS_FAILED,
- MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE);
+ if (!checkSslOperation(tep,
+ ret,
+ "Retransmission",
+ MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE))
+ {
+ oc_mutex_unlock(g_sslContextMutex);
+ return CA_STATUS_FAILED;
+ }
}
}
}
/* Send data via TLS connection.
*/
CAResult_t CAencryptSsl(const CAEndpoint_t *endpoint,
- void *data, uint32_t dataLen)
+ void *data, size_t dataLen)
{
int ret = 0;
if (0 == dataLen)
{
- OIC_LOG_V(ERROR, NET_SSL_TAG, "dataLen is zero [%d]", dataLen);
+ OIC_LOG_V(ERROR, NET_SSL_TAG, "dataLen is zero [%" PRIuPTR "]", dataLen);
return CA_STATUS_FAILED;
}
- OIC_LOG_V(DEBUG, NET_SSL_TAG, "Data to be encrypted dataLen [%d]", dataLen);
+ OIC_LOG_V(DEBUG, NET_SSL_TAG, "Data to be encrypted dataLen [%" PRIuPTR "]", dataLen);
oc_mutex_lock(g_sslContextMutex);
if(NULL == g_caSslContext)
OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__);
VERIFY_NON_NULL_VOID(tep, NET_SSL_TAG, "Param tep is NULL");
- uint32_t listIndex = 0;
- uint32_t listLength = 0;
+ size_t listIndex = 0;
+ size_t listLength = 0;
listLength = u_arraylist_length(tep->cacheList);
for (listIndex = 0; listIndex < listLength;)
{
/* Read data from TLS connection
*/
-CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t dataLen)
+CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, size_t dataLen)
{
int ret = 0;
OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__);
if (!ret)
{
OIC_LOG(ERROR, NET_SSL_TAG, "u_arraylist_add failed!");
- OICFree(peer);
+ DeleteSslEndPoint(peer);
oc_mutex_unlock(g_sslContextMutex);
return CA_STATUS_FAILED;
}
if (0 != flags)
{
OIC_LOG_BUFFER(ERROR, NET_SSL_TAG, (const uint8_t *) &flags, sizeof(flags));
- SSL_CHECK_FAIL(peer, flags, "Cert verification failed", 1,
- CA_STATUS_FAILED, GetAlertCode(flags));
+ if (!checkSslOperation(peer,
+ (int)flags,
+ "Cert verification failed",
+ GetAlertCode(flags)))
+ {
+ oc_mutex_unlock(g_sslContextMutex);
+ OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);
+ return CA_STATUS_FAILED;
+ }
+ }
+ if (!checkSslOperation(peer,
+ ret,
+ "Handshake error",
+ MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE))
+ {
+ oc_mutex_unlock(g_sslContextMutex);
+ OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);
+ return CA_STATUS_FAILED;
}
- SSL_CHECK_FAIL(peer, ret, "Handshake error", 1, CA_STATUS_FAILED, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE);
if (MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC == peer->ssl.state)
{
memcpy(peer->master, peer->ssl.session_negotiate->master, sizeof(peer->master));
void * userIdPos = NULL;
const mbedtls_x509_crt * peerCert = mbedtls_ssl_get_peer_cert(&peer->ssl);
ret = (NULL == peerCert ? -1 : 0);
- SSL_CHECK_FAIL(peer, ret, "Failed to retrieve cert", 1,
- CA_STATUS_FAILED, MBEDTLS_SSL_ALERT_MSG_NO_CERT);
+ if (!checkSslOperation(peer,
+ ret,
+ "Failed to retrieve cert",
+ MBEDTLS_SSL_ALERT_MSG_NO_CERT))
+ {
+ oc_mutex_unlock(g_sslContextMutex);
+ OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);
+ return CA_STATUS_FAILED;
+ }
uuidPos = memmem(peerCert->subject_raw.p, peerCert->subject_raw.len,
UUID_PREFIX, sizeof(UUID_PREFIX) - 1);
memcpy(uuid, (char*) uuidPos + sizeof(UUID_PREFIX) - 1, UUID_LENGTH * 2 + 4);
OIC_LOG_V(DEBUG, NET_SSL_TAG, "certificate uuid string: %s" , uuid);
ret = (OCConvertStringToUuid(uuid, peer->sep.identity.id)) ? 0 : -1;
- SSL_CHECK_FAIL(peer, ret, "Failed to convert subject", 1,
- CA_STATUS_FAILED, MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT);
+ if (!checkSslOperation(peer,
+ ret,
+ "Failed to convert subject",
+ MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT))
+ {
+ oc_mutex_unlock(g_sslContextMutex);
+ OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);
+ return CA_STATUS_FAILED;
+ }
}
else
{
{
memcpy(uuid, (char*) userIdPos + sizeof(USERID_PREFIX) - 1, UUID_LENGTH * 2 + 4);
ret = (OCConvertStringToUuid(uuid, peer->sep.userId.id)) ? 0 : -1;
- SSL_CHECK_FAIL(peer, ret, "Failed to convert subject alt name", 1,
- CA_STATUS_FAILED, MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT);
+ if (!checkSslOperation(peer,
+ ret,
+ "Failed to convert subject alt name",
+ MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT))
+ {
+ oc_mutex_unlock(g_sslContextMutex);
+ OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);
+ return CA_STATUS_FAILED;
+ }
}
else
{
* @param random2 Random seed.
* @param random2Len Actual length of @p random2 (may be zero).
* @param buf Output buffer for generated random data.
- * @param bufLen Maximum size of @p buf.
+ * @param bufLen Maximum size of @p buf. Must not be larger than INT_MAX.
*
* @return The actual number of bytes written to @p buf or @c -1 on error.
*/
size_t dLen; /* digest length */
size_t len = 0; /* result length */
+ VERIFY_TRUE_RET(bufLen <= INT_MAX, NET_SSL_TAG, "buffer too large", -1);
VERIFY_NON_NULL_RET(key, NET_SSL_TAG, "key is NULL", -1);
VERIFY_NON_NULL_RET(label, NET_SSL_TAG, "label is NULL", -1);
VERIFY_NON_NULL_RET(random1, NET_SSL_TAG, "random1 is NULL", -1);
mbedtls_md_free(&hmacA);
mbedtls_md_free(&hmacP);
- return bufLen;
+ return (int)bufLen;
// exit label required for CHECK_MBEDTLS_RET macro
exit:
mbedtls_md_free(&hmacA);
size_t *totalLength,
uint16_t mtuSize)
{
- OIC_LOG_V(DEBUG, TAG, "IN, dataLength = %zu, mtu = %zu", dataLength, mtuSize);
+ OIC_LOG_V(DEBUG, TAG, "IN, dataLength = %" PRIuPTR ", mtu = %u",
+ dataLength, (uint32_t)mtuSize);
size_t remainDataSize = 0;
size_t dataOnlyLen =
#define _DEFAULT_SOURCE
#define _BSD_SOURCE
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// check if message has to be transfered to a block
size_t maxBlockSize = BLOCK_SIZE(CA_DEFAULT_BLOCK_SIZE);
- OIC_LOG_V(DEBUG, TAG, "payloadLen=%zu, maxBlockSize=%zu", payloadLen, maxBlockSize);
+ OIC_LOG_V(DEBUG, TAG, "payloadLen=%" PRIuPTR ", maxBlockSize=%" PRIuPTR, payloadLen, maxBlockSize);
if (payloadLen <= maxBlockSize)
{
VERIFY_NON_NULL(pdu->transport_hdr, TAG, "pdu->transport_hdr");
VERIFY_NON_NULL(endpoint, TAG, "endpoint");
VERIFY_NON_NULL(receivedData, TAG, "receivedData");
+ VERIFY_TRUE((pdu->transport_hdr->udp.token_length <= UINT8_MAX), TAG,
+ "pdu->transport_hdr->udp.token_length");
// check if received message type is CA_MSG_RESET
if (CA_EMPTY == pdu->transport_hdr->udp.code)
{
CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
(CAToken_t)pdu->transport_hdr->udp.token,
- pdu->transport_hdr->udp.token_length,
+ (uint8_t)pdu->transport_hdr->udp.token_length,
endpoint->addr, endpoint->port);
if (NULL == blockDataID || blockDataID->idLength < 1)
{
if (receivedData->responseInfo)
{
CARemoveBlockDataFromListWithSeed((CAToken_t)pdu->transport_hdr->udp.token,
- pdu->transport_hdr->udp.token_length,
+ (uint8_t)pdu->transport_hdr->udp.token_length,
endpoint->addr, endpoint->port);
}
return CA_NOT_SUPPORTED;
VERIFY_NON_NULL(pdu, TAG, "pdu");
VERIFY_NON_NULL(pdu->transport_hdr, TAG, "pdu->transport_hdr");
VERIFY_NON_NULL(blockID, TAG, "blockID");
+ VERIFY_TRUE((pdu->transport_hdr->udp.token_length <= UINT8_MAX), TAG,
+ "pdu->transport_hdr->udp.token_length");
// create error responseInfo
CABlockData_t *data = CAGetBlockDataFromBlockDataList(blockID);
}
else
{
- CAInfo_t responseData = { .tokenLength = pdu->transport_hdr->udp.token_length };
+ CAInfo_t responseData = { .tokenLength = (uint8_t)pdu->transport_hdr->udp.token_length };
responseData.token = (CAToken_t) OICMalloc(responseData.tokenLength);
if (!responseData.token)
{
static CABlockData_t* CACheckTheExistOfBlockData(const CABlockDataID_t* blockDataID,
coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
- uint8_t blockType)
+ uint16_t blockType)
{
// Get BlockData data. If does not exist, create a new data
CABlockData_t *data = CAGetBlockDataFromBlockDataList(blockDataID);
VERIFY_NON_NULL(pdu->transport_hdr, TAG, "pdu->transport_hdr");
VERIFY_NON_NULL(endpoint, TAG, "endpoint");
VERIFY_NON_NULL(receivedData, TAG, "receivedData");
+ VERIFY_TRUE((pdu->transport_hdr->udp.token_length <= UINT8_MAX), TAG,
+ "pdu->transport_hdr->udp.token_length");
OIC_LOG_V(INFO, TAG, "num:%d, M:%d, sze:%d", block.num, block.m, block.szx);
CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
(CAToken_t)pdu->transport_hdr->udp.token,
- pdu->transport_hdr->udp.token_length,
+ (uint8_t)pdu->transport_hdr->udp.token_length,
endpoint->addr, endpoint->port);
if (NULL == blockDataID || blockDataID->idLength < 1)
{
VERIFY_NON_NULL(pdu->transport_hdr, TAG, "pdu->transport_hdr");
VERIFY_NON_NULL(endpoint, TAG, "endpoint");
VERIFY_NON_NULL(receivedData, TAG, "receivedData");
+ VERIFY_TRUE((pdu->transport_hdr->udp.token_length <= UINT8_MAX), TAG,
+ "pdu->transport_hdr->udp.token_length");
CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
(CAToken_t)pdu->transport_hdr->udp.token,
- pdu->transport_hdr->udp.token_length,
+ (uint8_t)pdu->transport_hdr->udp.token_length,
endpoint->addr, endpoint->port);
if (NULL == blockDataID || blockDataID->idLength < 1)
{
VERIFY_NON_NULL(info, TAG, "info");
VERIFY_NON_NULL(endpoint, TAG, "endpoint");
VERIFY_NON_NULL(options, TAG, "options");
+ VERIFY_TRUE(((*pdu)->transport_hdr->udp.token_length <= UINT8_MAX), TAG,
+ "pdu->transport_hdr->udp.token_length");
+ VERIFY_TRUE((info->payloadSize <= COAP_MAX_PDU_SIZE), TAG,
+ "info->payloadSize");
CAResult_t res = CA_STATUS_OK;
- size_t dataLength = 0;
+ unsigned int dataLength = 0;
if (info->payload)
{
- dataLength = info->payloadSize;
- OIC_LOG_V(DEBUG, TAG, "dataLength - %zu", dataLength);
+ dataLength = (unsigned int)info->payloadSize;
+ OIC_LOG_V(DEBUG, TAG, "dataLength - %" PRIuPTR, dataLength);
}
CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
(CAToken_t)(*pdu)->transport_hdr->udp.token,
- (*pdu)->transport_hdr->udp.token_length,
+ (uint8_t)(*pdu)->transport_hdr->udp.token_length,
endpoint->addr, endpoint->port);
if (NULL == blockDataID || blockDataID->idLength < 1)
{
goto exit;
}
- uint8_t blockType = CAGetBlockOptionType(blockDataID);
+ uint16_t blockType = CAGetBlockOptionType(blockDataID);
if (COAP_OPTION_BLOCK2 == blockType)
{
res = CAAddBlockOption2(pdu, info, dataLength, blockDataID, options);
OIC_LOG_V(DEBUG, TAG, "[%d] pdu length after option", (*pdu)->length);
// if response data is so large. it have to send as block transfer
- if (!coap_add_data(*pdu, dataLength, (const unsigned char *) info->payload))
+ if (!coap_add_data(*pdu, dataLength, (const unsigned char*)info->payload))
{
OIC_LOG(INFO, TAG, "it has to use block");
res = CA_STATUS_FAILED;
VERIFY_NON_NULL(info, TAG, "info");
VERIFY_NON_NULL(blockID, TAG, "blockID");
VERIFY_NON_NULL(options, TAG, "options");
+ VERIFY_TRUE((dataLength <= COAP_MAX_PDU_SIZE), TAG, "dataLength");
// get set block data from CABlock list-set.
coap_block_t *block1 = CAGetBlockOption(blockID, COAP_OPTION_BLOCK1);
goto exit;
}
- if (!coap_add_block(*pdu, dataLength, (const unsigned char *) info->payload,
+ if (!coap_add_block(*pdu, (unsigned int)dataLength,
+ (const unsigned char *) info->payload,
block2->num, block2->szx))
{
OIC_LOG(ERROR, TAG, "Data length is smaller than the start index");
VERIFY_NON_NULL(info, TAG, "info");
VERIFY_NON_NULL(blockID, TAG, "blockID");
VERIFY_NON_NULL(options, TAG, "options");
+ VERIFY_TRUE((dataLength <= COAP_MAX_PDU_SIZE), TAG, "dataLength");
// get set block data from CABlock list-set.
coap_block_t *block1 = CAGetBlockOption(blockID, COAP_OPTION_BLOCK1);
}
// add the payload data as the block size.
- if (!coap_add_block(*pdu, dataLength, (const unsigned char *) info->payload, block1->num,
+ if (!coap_add_block(*pdu, (unsigned int)dataLength,
+ (const unsigned char *) info->payload, block1->num,
block1->szx))
{
OIC_LOG(ERROR, TAG, "Data length is smaller than the start index");
}
// add the payload data as the block size.
- if (!coap_add_data(*pdu, dataLength, (const unsigned char *) info->payload))
+ if (!coap_add_data(*pdu, (unsigned int)dataLength,
+ (const unsigned char*)info->payload))
{
OIC_LOG(ERROR, TAG, "failed to add payload");
return CA_STATUS_FAILED;
COAP_OPTION_DATA(*(coap_option *) opt->data));
OIC_LOG_V(DEBUG, TAG, "[%d] pdu length", pdu->length);
- int ret = coap_add_option(pdu, COAP_OPTION_KEY(*(coap_option *) opt->data),
- COAP_OPTION_LENGTH(*(coap_option *) opt->data),
- COAP_OPTION_DATA(*(coap_option *) opt->data));
+ size_t ret = coap_add_option(pdu, COAP_OPTION_KEY(*(coap_option *) opt->data),
+ COAP_OPTION_LENGTH(*(coap_option *) opt->data),
+ COAP_OPTION_DATA(*(coap_option *) opt->data));
if (!ret)
{
return CA_STATUS_FAILED;
OIC_LOG(DEBUG, TAG, "IN-CAAddBlockSizeOption");
VERIFY_NON_NULL(pdu, TAG, "pdu");
VERIFY_NON_NULL(options, TAG, "options");
+ VERIFY_TRUE((dataLength <= UINT_MAX), TAG, "dataLength");
if (sizeType != COAP_OPTION_SIZE1 && sizeType != COAP_OPTION_SIZE2)
{
}
unsigned char value[BLOCKWISE_OPTION_BUFFER] = { 0 };
- unsigned int optionLength = coap_encode_var_bytes(value, dataLength);
+ unsigned int optionLength = coap_encode_var_bytes(value,
+ (unsigned int)dataLength);
int ret = coap_insert(options,
CACreateNewOptionNode(sizeType, optionLength, (char *) value),
*totalPayloadLen = coap_decode_var_bytes(COAP_OPT_VALUE(option),
COAP_OPT_LENGTH(option));
- OIC_LOG_V(DEBUG, TAG, "the total payload length to be received is [%zu]bytes",
+ OIC_LOG_V(DEBUG, TAG, "the total payload length to be received is [%" PRIuPTR "]bytes",
*totalPayloadLen);
return true;
if (receivedBlock->m && blockPayloadLen != (size_t) BLOCK_SIZE(receivedBlock->szx))
{
// 413 Error handling of too large entity
- if (COAP_MAX_PDU_SIZE < BLOCK_SIZE(receivedBlock->szx) + optionLen)
+ if (COAP_MAX_PDU_SIZE < ((size_t)BLOCK_SIZE(receivedBlock->szx)) + optionLen)
{
// buffer size is smaller than received block size
OIC_LOG(ERROR, TAG, "error type 4.13");
OIC_LOG(ERROR, TAG, "too large size");
// set the block size to be smaller than COAP_MAX_PDU_SIZE
- for (int32_t size = CA_DEFAULT_BLOCK_SIZE; size >= 0; size--)
+ for (unsigned int size = CA_DEFAULT_BLOCK_SIZE; size >= 0; size--)
{
- if (COAP_MAX_PDU_SIZE >= BLOCK_SIZE(size) + optionLen)
+ if (COAP_MAX_PDU_SIZE >= (size_t)BLOCK_SIZE(size) + optionLen)
{
OIC_LOG_V(ERROR, TAG, "replace sze with %d", size);
currData->block2.szx = size;
VERIFY_NON_NULL_RET(pdu, TAG, "pdu", NULL);
VERIFY_NON_NULL_RET(pdu->transport_hdr, TAG, "pdu->transport_hdr", NULL);
VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint", NULL);
+ VERIFY_TRUE_RET((pdu->transport_hdr->udp.token_length <= UINT8_MAX), TAG,
+ "pdu->transport_hdr->udp.token_length", NULL);
CARequestInfo_t* requestInfo = NULL;
CAResponseInfo_t* responseInfo = NULL;
uint32_t code = pdu->transport_hdr->udp.code;
if (CA_GET == code || CA_POST == code || CA_PUT == code || CA_DELETE == code)
{
- CAInfo_t responseData = { .tokenLength = pdu->transport_hdr->udp.token_length };
+ CAInfo_t responseData = { .tokenLength = (uint8_t)pdu->transport_hdr->udp.token_length };
responseData.token = (CAToken_t) OICMalloc(responseData.tokenLength);
if (!responseData.token)
{
}
else
{
- CAInfo_t requestData = { .tokenLength = pdu->transport_hdr->udp.token_length };
+ CAInfo_t requestData = { .tokenLength = (uint8_t)pdu->transport_hdr->udp.token_length };
requestData.token = (CAToken_t) OICMalloc(requestData.tokenLength);
if (!requestData.token)
{
return CA_STATUS_OK;
}
-CAResult_t CAUpdateBlockOptionType(const CABlockDataID_t *blockID, uint8_t blockType)
+CAResult_t CAUpdateBlockOptionType(const CABlockDataID_t *blockID, uint16_t blockType)
{
OIC_LOG(DEBUG, TAG, "IN-UpdateBlockOptionType");
VERIFY_NON_NULL(blockID, TAG, "blockID");
return CA_STATUS_FAILED;
}
-uint8_t CAGetBlockOptionType(const CABlockDataID_t *blockID)
+uint16_t CAGetBlockOptionType(const CABlockDataID_t *blockID)
{
OIC_LOG(DEBUG, TAG, "IN-GetBlockOptionType");
VERIFY_NON_NULL_RET(blockID, TAG, "blockID", 0);
OIC_LOG(DEBUG, TAG, "OUT");
}
-CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size)
+CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, size_t *size)
{
OIC_LOG(DEBUG, TAG, "CAGetNetworkInformation");
static CAConnectivityHandler_t *g_adapterHandler = NULL;
-static uint32_t g_numberOfAdapters = 0;
+static size_t g_numberOfAdapters = 0;
static CANetworkPacketReceivedCallback g_networkPacketReceivedCallback = NULL;
} CANetworkCallback_t;
-static int CAGetAdapterIndex(CATransportAdapter_t cType)
+static size_t CAGetAdapterIndex(CATransportAdapter_t cType)
{
- for (uint32_t index=0 ; index < g_numberOfAdapters ; index++)
+ for (size_t index = 0 ; index < g_numberOfAdapters ; index++)
{
if (cType == g_adapterHandler[index].cType )
{
OIC_LOG(ERROR, TAG, "connectivity handler is not enough to be used!");
return;
}
- uint32_t numberofAdapters = g_numberOfAdapters + 1;
+ size_t numberofAdapters = g_numberOfAdapters + 1;
CAConnectivityHandler_t *adapterHandler = OICRealloc(g_adapterHandler,
(numberofAdapters) * sizeof(*adapterHandler));
if (NULL == adapterHandler)
{
OIC_LOG_V(DEBUG, TAG, "Start the adapter of CAConnectivityType[%d]", transportType);
- int index = CAGetAdapterIndex(transportType);
+ size_t index = CAGetAdapterIndex(transportType);
if (0 > index)
{
OIC_LOG(ERROR, TAG, "unknown connectivity type!");
{
OIC_LOG_V(DEBUG, TAG, "Stop the adapter of CATransportType[%d]", transportType);
- int index = CAGetAdapterIndex(transportType);
+ size_t index = CAGetAdapterIndex(transportType);
if (0 > index)
{
OIC_LOG(ERROR, TAG, "unknown transport type!");
}
}
-CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, uint32_t *size)
+CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, size_t *size)
{
VERIFY_NON_NULL(info, TAG, "info is null");
VERIFY_NON_NULL(size, TAG, "size is null");
OIC_LOG(ERROR, TAG, "Out of memory!");
return CA_MEMORY_ALLOC_FAILED;
}
- uint32_t *tempSize =(uint32_t*) OICCalloc(g_numberOfAdapters, sizeof(*tempSize));
+ size_t *tempSize = (size_t*)OICCalloc(g_numberOfAdapters, sizeof(*tempSize));
if (!tempSize)
{
OIC_LOG(ERROR, TAG, "Out of memory!");
CAResult_t res = CA_STATUS_FAILED;
size_t resSize = 0;
- for (uint32_t index = 0; index < g_numberOfAdapters; index++)
+ for (size_t index = 0; index < g_numberOfAdapters; index++)
{
if (g_adapterHandler[index].GetnetInfo != NULL)
{
}
}
- OIC_LOG_V(DEBUG, TAG, "network info total size is %zu!", resSize);
+ OIC_LOG_V(DEBUG, TAG, "network info total size is %" PRIuPTR "!", resSize);
if (resSize == 0)
{
*info = resInfo;
*size = resSize;
- for (uint32_t index = 0; index < g_numberOfAdapters; index++)
+ for (size_t index = 0; index < g_numberOfAdapters; index++)
{
// check information
if (tempSize[index] == 0)
// memory error label.
memory_error_exit:
- for (uint32_t index = 0; index < g_numberOfAdapters; index++)
+ for (size_t index = 0; index < g_numberOfAdapters; index++)
{
OICFree(tempInfo[index]);
tempInfo[index] = NULL;
}
CATransportAdapter_t requestedAdapter = endpoint->adapter ? endpoint->adapter : CA_ALL_ADAPTERS;
- for (uint32_t i = 0; i < u_arraylist_length(list); i++)
+ for (size_t i = 0; i < u_arraylist_length(list); i++)
{
void* ptrType = u_arraylist_get(list, i);
continue;
}
- int index = CAGetAdapterIndex(connType);
+ size_t index = CAGetAdapterIndex(connType);
if (-1 == index)
{
sentDataLen = g_adapterHandler[index].sendData(endpoint, data, length, dataType);
}
- if (sentDataLen != (int32_t)length)
+ if (sentDataLen != length)
{
OIC_LOG(ERROR, TAG, "error in sending data. Error will be reported in adapter");
#ifdef SINGLE_THREAD
continue;
}
- int index = CAGetAdapterIndex(connType);
+ size_t index = CAGetAdapterIndex(connType);
if (0 > index)
{
OIC_LOG(ERROR, TAG, "unknown connectivity type!");
CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
- int index = CAGetAdapterIndex(connType);
+ size_t index = CAGetAdapterIndex(connType);
if (0 > index)
{
OIC_LOG(ERROR, TAG, "unknown connectivity type!");
CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
- int index = CAGetAdapterIndex(connType);
+ size_t index = CAGetAdapterIndex(connType);
if (0 > index)
{
OIC_LOG(ERROR, TAG, "unknown connectivity type!");
CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
- int index = CAGetAdapterIndex(connType);
+ size_t index = CAGetAdapterIndex(connType);
if (0 > index)
{
OIC_LOG(DEBUG, TAG, "unknown connectivity type!");
void CATerminateAdapters()
{
- for (uint32_t index = 0; index < g_numberOfAdapters; index++)
+ for (size_t index = 0; index < g_numberOfAdapters; index++)
{
if (g_adapterHandler[index].terminate != NULL)
{
return CA_STATUS_FAILED;
}
- uint8_t i = 0;
+ size_t i = 0;
for (i = 0; i < u_arraylist_length(list); i++)
{
void *ptrType = u_arraylist_get(list, i);
CATransportAdapter_t connType = *(CATransportAdapter_t *) ptrType;
- int index = CAGetAdapterIndex(connType);
+ size_t index = CAGetAdapterIndex(connType);
if (0 > index)
{
OIC_LOG(DEBUG, TAG, "unknown connectivity type!");
#ifndef SINGLE_THREAD
CATransportAdapter_t connType;
u_arraylist_t *list = CAGetSelectedNetworkList();
- uint32_t length = u_arraylist_length(list);
+ size_t length = u_arraylist_length(list);
- uint32_t i = 0;
- for (i = 0; i < length; i++)
+ for (size_t i = 0; i < length; i++)
{
void* ptrType = u_arraylist_get(list, i);
if (info->payload)
{
- OIC_LOG_V(DEBUG, TAG, "payload: %p(%zu)", info->payload,
+ OIC_LOG_V(DEBUG, TAG, "payload: %p(%" PRIuPTR ")", info->payload,
info->payloadSize);
}
return CA_STATUS_FAILED;
}
- uint32_t selectedNetworkLength = u_arraylist_length(g_selectedNetworkList);
- for (uint32_t index = 0; index < selectedNetworkLength; index++)
+ size_t selectedNetworkLength = u_arraylist_length(g_selectedNetworkList);
+ for (size_t index = 0; index < selectedNetworkLength; index++)
{
void* ptrType = u_arraylist_get(g_selectedNetworkList, index);
if (NULL == ptrType)
return CASelectedNetwork;
}
-CAResult_t CAGetNetworkInformationInternal(CAEndpoint_t **info, uint32_t *size)
+CAResult_t CAGetNetworkInformationInternal(CAEndpoint_t **info, size_t *size)
{
OIC_LOG(DEBUG, TAG, "get network information.");
{
OIC_LOG_V(DEBUG, TAG, "uri : %s", info->resourceUri);
- uint32_t length = strlen(info->resourceUri);
+ size_t length = strlen(info->resourceUri);
if (CA_MAX_URI_LENGTH < length)
{
OIC_LOG(ERROR, TAG, "URI len err");
return NULL;
}
- uint32_t uriLength = length + sizeof(COAP_URI_HEADER);
+ size_t uriLength = length + sizeof(COAP_URI_HEADER);
char *coapUri = (char *) OICCalloc(1, uriLength);
if (NULL == coapUri)
{
VERIFY_NON_NULL_RET(info, TAG, "info", NULL);
VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint", NULL);
VERIFY_NON_NULL_RET(transport, TAG, "transport", NULL);
+ VERIFY_TRUE_RET((info->payloadSize <= COAP_MAX_PDU_SIZE), TAG,
+ "info->payloadSize", NULL);
- unsigned int length = COAP_MAX_PDU_SIZE;
+ size_t length = COAP_MAX_PDU_SIZE;
#ifdef WITH_TCP
- unsigned int msgLength = 0;
+ size_t msgLength = 0;
if (CAIsSupportedCoAPOverTCP(endpoint->adapter))
{
if (options)
}
msgLength += optLength;
prevOptNumber = curOptNumber;
- OIC_LOG_V(DEBUG, TAG, "curOptNumber[%d], prevOptNumber[%d], optValueLen[%zu], "
- "optLength[%zu], msgLength[%d]",
+ OIC_LOG_V(DEBUG, TAG, "curOptNumber[%d], prevOptNumber[%d], optValueLen[%" PRIuPTR "], "
+ "optLength[%" PRIuPTR "], msgLength[%" PRIuPTR "]",
curOptNumber, prevOptNumber, optValueLen, optLength, msgLength);
}
}
{
msgLength = msgLength + info->payloadSize + PAYLOAD_MARKER;
}
- *transport = coap_get_tcp_header_type_from_size(msgLength);
+
+ if (msgLength > UINT_MAX)
+ {
+ OIC_LOG(ERROR, TAG, "Message length too large.");
+ return NULL;
+ }
+
+ *transport = coap_get_tcp_header_type_from_size((unsigned int)msgLength);
length = msgLength + coap_get_tcp_header_length_for_transport(*transport)
+ info->tokenLength;
}
*transport = COAP_UDP;
}
- coap_pdu_t *pdu = coap_new_pdu2(*transport, length);
+ coap_pdu_t *pdu = coap_pdu_init2(0, 0,
+ ntohs(COAP_INVALID_TID),
+ length, *transport);
if (NULL == pdu)
{
return NULL;
}
- OIC_LOG_V(DEBUG, TAG, "transport type: %d, payload size: %zu",
+ OIC_LOG_V(DEBUG, TAG, "transport type: %d, payload size: %" PRIuPTR,
*transport, info->payloadSize);
#ifdef WITH_TCP
if (CAIsSupportedCoAPOverTCP(endpoint->adapter))
{
- coap_add_length(pdu, *transport, msgLength);
+ coap_add_length(pdu, *transport, (unsigned int)msgLength);
}
else
#endif
OIC_LOG_V(DEBUG, TAG, "[%d] pdu length after option", pdu->length);
- if (NULL != info->payload && 0 < info->payloadSize)
+ if ((NULL != info->payload) && (0 < info->payloadSize))
{
OIC_LOG(DEBUG, TAG, "payload is added");
- coap_add_data(pdu, info->payloadSize, (const unsigned char *) info->payload);
+ coap_add_data(pdu, (unsigned int)info->payloadSize,
+ (const unsigned char*)info->payload);
}
return pdu;
if (optionResult[0] != '\0')
{
- OIC_LOG_V(DEBUG, TAG, "URL length:%zu", strlen(optionResult));
+ OIC_LOG_V(DEBUG, TAG, "URL length:%" PRIuPTR, strlen(optionResult));
outInfo->resourceUri = OICStrdup(optionResult);
if (!outInfo->resourceUri)
{
} CARetransmissionData_t;
static const uint64_t USECS_PER_SEC = 1000000;
+static const uint64_t USECS_PER_MSEC = 1000;
static const uint64_t MSECS_PER_SEC = 1000;
#ifndef SINGLE_THREAD
{
#ifndef SINGLE_THREAD
// #1. calculate timeout
- uint32_t milliTimeoutValue = retData->timeout * 0.001;
- uint64_t timeout = ((uint64_t) milliTimeoutValue << retData->triedCount) * MSECS_PER_SEC;
+ uint64_t milliTimeoutValue = retData->timeout / USECS_PER_MSEC;
+ uint64_t timeout = (milliTimeoutValue << retData->triedCount) * USECS_PER_MSEC;
if (currentTime >= retData->timeStamp + timeout)
{
// mutex lock
oc_mutex_lock(context->threadMutex);
- uint32_t i = 0;
- uint32_t len = u_arraylist_length(context->dataList);
+ size_t len = u_arraylist_length(context->dataList);
- for (i = 0; i < len; i++)
+ for (size_t i = 0; i < len; i++)
{
CARetransmissionData_t *retData = u_arraylist_get(context->dataList, i);
// mutex lock
oc_mutex_lock(context->threadMutex);
- uint32_t i = 0;
- uint32_t len = u_arraylist_length(context->dataList);
+ size_t len = u_arraylist_length(context->dataList);
// #3. add data into list
- for (i = 0; i < len; i++)
+ for (size_t i = 0; i < len; i++)
{
CARetransmissionData_t *currData = u_arraylist_get(context->dataList, i);
// mutex lock
oc_mutex_lock(context->threadMutex);
- uint32_t len = u_arraylist_length(context->dataList);
+ size_t len = u_arraylist_length(context->dataList);
- // find index
- uint32_t i;
- for (i = 0; i < len; i++)
+ for (size_t i = 0; i < len; i++)
{
CARetransmissionData_t *retData = (CARetransmissionData_t *) u_arraylist_get(
context->dataList, i);
OIC_LOG(DEBUG, TAG, "retransmission context destroy..");
oc_mutex_lock(context->threadMutex);
- uint32_t len = u_arraylist_length(context->dataList);
- for (uint32_t i = 0; i < len; i++)
+ size_t len = u_arraylist_length(context->dataList);
+ for (size_t i = 0; i < len; i++)
{
CARetransmissionData_t *data = u_arraylist_get(context->dataList, i);
if (NULL == data)
// CAGetNetworkInformation TC
TEST_F (CATests, GetNetworkInformationTest)
{
- uint32_t tempSize = 0;
+ size_t tempSize = 0;
CAEndpoint_t *tempInfo = NULL;
EXPECT_EQ(CA_STATUS_OK, CASelectNetwork(CA_ADAPTER_IP));
// @todo: if this api is supported on windows platform, it should be changed.
#if !defined(_WIN32)
- for (uint32_t index = 0; index < tempSize; index++)
+ for (size_t index = 0; index < tempSize; index++)
{
EXPECT_TRUE(tempInfo[index].adapter != 0);
EXPECT_TRUE(strlen(tempInfo[index].addr) != 0);
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#include <cinttypes>
#include "gtest/gtest.h"
#include "time.h"
#define dummyHandler 0xF123
#define SERVER_PORT 4433
+#define SERVER_PORT_STRING "4433"
#define SERVER_NAME "localhost"
#define GET_REQUEST "GET / HTTP/1.0\r\n\r\n"
exit(0);
}
-static int sockfd, newsockfd;
+static CASocketFd_t sockfd, newsockfd;
static void socketConnect()
{
- int portno;
- struct sockaddr_in serv_addr;
- struct hostent *server;
+ struct addrinfo* addressInfo = NULL;
+ struct addrinfo hints;
+
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_family = AF_INET;
- portno = SERVER_PORT;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
error("ERROR opening socket");
- server = gethostbyname(SERVER_NAME);
- if (server == NULL) {
+
+ int result = getaddrinfo(SERVER_NAME, SERVER_PORT_STRING, &hints, &addressInfo);
+ if (0 != result)
+ {
fprintf(stderr,"ERROR, no such host\n");
exit(0);
}
- //memset((char *) &serv_addr, sizeof(serv_addr));
- memset((void*)&serv_addr, 0, sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- memcpy((char *)server->h_addr,
- (char *)&serv_addr.sin_addr.s_addr,
- server->h_length);
- serv_addr.sin_port = htons(portno);
- if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
+
+ if (connect(sockfd, addressInfo->ai_addr, (int)addressInfo->ai_addrlen) < 0)
+ {
error("ERROR connecting");
+ }
+
+ freeaddrinfo(addressInfo);
}
static ssize_t CATCPPacketSendCB(CAEndpoint_t *, const void *buf, size_t buflen)
{
- int n;
- n = write(sockfd, buf, buflen);
+ int n = send(sockfd, (const char*)buf, (int)buflen, 0);
if (n < 0)
- error("ERROR writing to socket");
+ {
+ error("ERROR writing to socket");
+ }
return n;
}
{
int n;
char buffer[2048] = {'\0'};
- n = read(sockfd, buffer, 5);
+ n = recv(sockfd, buffer, 5, 0);
if ((buffer[0] == 0x16 || buffer[0] == 0x14 || buffer[0] == 0x17 || buffer[0] == 0x15)
&& buffer[1] == 0x03 && buffer[2] == 0x03)
{
int tlslen = (unsigned char)buffer[3] * 0x100 + (unsigned char)buffer[4];
- n = read(sockfd, buffer + 5, tlslen);
+ n = recv(sockfd, buffer + 5, tlslen, 0);
}
if (n < 0)
static void socketClose()
{
- close(sockfd);
+ OC_CLOSE_SOCKET(sockfd);
}
static void infoCallback_that_loads_x509(PkiInfo_t * inf)
static ssize_t CATCPPacketSendCB_server(CAEndpoint_t *, const void *buf, size_t buflen)
{
int n;
- n = write(newsockfd,buf,buflen);
+ n = send(newsockfd, (const char*)buf, (int)buflen, 0);
if (n < 0)
error("ERROR writing to socket");
return n;
{
int n;
char buffer[2048] = {'\0'};
- n = read(newsockfd, buffer, 5);
+ n = recv(newsockfd, buffer, 5, 0);
if (buffer[0] == 0x16 || buffer[0] == 0x14 || buffer[0] == 0x17 || buffer[0] == 0x15)
{
int tlslen = (unsigned char)buffer[3] * 0x100 + (unsigned char)buffer[4];
- n = read(newsockfd, buffer + 5, tlslen);
+ n = recv(newsockfd, buffer + 5, tlslen, 0);
}
if (n < 0)
static void socketClose_server()
{
- close(newsockfd);
- close(sockfd);
+ OC_CLOSE_SOCKET(newsockfd);
+ OC_CLOSE_SOCKET(sockfd);
}
static void clutch(bool * list)
0x00, 0x00, 0x00, 0x17, 0x00, 0x00
};
static unsigned char controlBuf[sizeof(predictedClientHello)];
-static char controlBufLen = 0;
+static size_t controlBufLen = 0;
static ssize_t CATCPPacketSendCB_forInitHsTest(CAEndpoint_t *, const void * buf, size_t buflen)
{
int n;
- n = write(sockfd, buf, buflen);
+ n = send(sockfd, (const char*)buf, (int)buflen, 0);
if (n < 0)
error("ERROR writing to socket");
int errNum;
mbedtls_x509_crt crt;
mbedtls_x509_crt_init(&crt);
- int ret = ParseChain(&crt, certChain, certChainLen, &errNum);
+ size_t ret = ParseChain(&crt, certChain, certChainLen, &errNum);
mbedtls_x509_crt_free(&crt);
EXPECT_EQ(10, ret + errNum);
#define IOTIVITY_VERSION "1.3.0"
+#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
*/
void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload *payload, const OCResource *res,
uint16_t securePort, bool isVirtual,
- void *networkInfo, uint32_t infoSize,
+ void *networkInfo, size_t infoSize,
const OCDevAddr *devAddr);
#else
/**
*/
void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload *payload, const OCResource *res,
uint16_t securePort, bool isVirtual,
- void *networkInfo, uint32_t infoSize,
+ void *networkInfo, size_t infoSize,
const OCDevAddr *devAddr, uint16_t tcpPort);
#endif
#ifdef __cplusplus
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "iotivity_config.h"
+#include <cinttypes>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
\r
#include "iotivity_config.h"\r
+#include <cinttypes>\r
#include <stdio.h>\r
#include <stdlib.h>\r
#include <string.h>\r
static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t securePort,
bool isVirtual, CAEndpoint_t *networkInfo,
- uint32_t infoSize, const OCDevAddr *devAddr
+ size_t infoSize, const OCDevAddr *devAddr
#ifndef TCP_ADAPTER
)
#else
OCEndpointPayload *lastNode = pl->eps;
if ((OC_ADAPTER_IP | OC_ADAPTER_TCP) & (devAddr->adapter))
{
- for (uint32_t i = 0; i < infoSize; i++)
+ for (size_t i = 0; i < infoSize; i++)
{
CAEndpoint_t *info = networkInfo + i;
#ifndef TCP_ADAPTER
void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload* payload, const OCResource* res,
uint16_t securePort, bool isVirtual,
- void *networkInfo, uint32_t infoSize,
+ void *networkInfo, size_t infoSize,
const OCDevAddr *devAddr)
{
OCDiscoveryPayloadAddNewResource(payload,
#else
void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload* payload, const OCResource* res,
uint16_t securePort, bool isVirtual,
- void *networkInfo, uint32_t infoSize,
+ void *networkInfo, size_t infoSize,
const OCDevAddr *devAddr, uint16_t tcpPort)
{
OCDiscoveryPayloadAddNewResource(payload,
OCDiscoveryPayload *payload,
OCDevAddr *endpoint,
CAEndpoint_t *networkInfo,
- uint32_t infoSize);
+ size_t infoSize);
//-----------------------------------------------------------------------------
// Default resource entity handler function
OCDiscoveryPayload *payload,
OCDevAddr *devAddr,
CAEndpoint_t *networkInfo,
- uint32_t infoSize)
+ size_t infoSize)
{
if (!resourcePtr || !payload)
{
char *resourceTypeQuery = NULL;
CAEndpoint_t *networkInfo = NULL;
- uint32_t infoSize = 0;
+ size_t infoSize = 0;
CAResult_t caResult = CAGetNetworkInformation(&networkInfo, &infoSize);
if (CA_STATUS_FAILED == caResult)
* @param[out] index index of array list.
* @return KeepAlive entry to send ping message.
*/
-static KeepAliveEntry_t *GetEntryFromEndpoint(const CAEndpoint_t *endpoint, uint32_t *index);
+static KeepAliveEntry_t *GetEntryFromEndpoint(const CAEndpoint_t *endpoint, size_t *index);
/**
* Add keepalive entry.
CAEndpoint_t endpoint = {.adapter = CA_DEFAULT_ADAPTER};
CopyDevAddrToEndpoint(&request->devAddr, &endpoint);
- uint32_t index = 0;
+ size_t index = 0;
KeepAliveEntry_t *entry = GetEntryFromEndpoint(&endpoint, &index);
int64_t interval = (entry) ? entry->interval : 0;
CAEndpoint_t endpoint = { .adapter = CA_DEFAULT_ADAPTER };
CopyDevAddrToEndpoint(&request->devAddr, &endpoint);
- uint32_t index = 0;
+ size_t index = 0;
KeepAliveEntry_t *entry = GetEntryFromEndpoint(&endpoint, &index);
if (!entry)
{
OIC_LOG(DEBUG, TAG, "HandleKeepAliveResponse IN");
// Get entry from KeepAlive table.
- uint32_t index = 0;
+ size_t index = 0;
KeepAliveEntry_t *entry = GetEntryFromEndpoint(endPoint, &index);
if (!entry)
{
return;
}
- uint32_t len = u_arraylist_length(g_keepAliveConnectionTable);
+ size_t len = u_arraylist_length(g_keepAliveConnectionTable);
- for (uint32_t i = 0; i < len; i++)
+ for (size_t i = 0; i < len; i++)
{
KeepAliveEntry_t *entry = (KeepAliveEntry_t *)u_arraylist_get(g_keepAliveConnectionTable,
i);
{
VERIFY_NON_NULL_NR(entry, FATAL);
- OIC_LOG_V(DEBUG, TAG, "Total interval counts: %zu", entry->intervalSize);
+ OIC_LOG_V(DEBUG, TAG, "Total interval counts: %" PRIuPTR, entry->intervalSize);
if (entry->intervalSize > (size_t)entry->currIndex + 1)
{
entry->currIndex++;
return OC_STACK_DELETE_TRANSACTION;
}
-KeepAliveEntry_t *GetEntryFromEndpoint(const CAEndpoint_t *endpoint, uint32_t *index)
+KeepAliveEntry_t *GetEntryFromEndpoint(const CAEndpoint_t *endpoint, size_t *index)
{
if (!g_keepAliveConnectionTable)
{
return NULL;
}
- uint32_t len = u_arraylist_length(g_keepAliveConnectionTable);
+ size_t len = u_arraylist_length(g_keepAliveConnectionTable);
- for (uint32_t i = 0; i < len; i++)
+ for (size_t i = 0; i < len; i++)
{
KeepAliveEntry_t *entry = (KeepAliveEntry_t *)u_arraylist_get(g_keepAliveConnectionTable,
i);
{
VERIFY_NON_NULL(endpoint, FATAL, OC_STACK_INVALID_PARAM);
- uint32_t index = 0;
+ size_t index = 0;
KeepAliveEntry_t *entry = GetEntryFromEndpoint(endpoint, &index);
if (!entry)
{
TEST(StackZoneId, getZoneId)
{
- uint32_t tempSize = 0;
+ size_t tempSize = 0;
CAEndpoint_t *tempInfo = NULL;
CAGetNetworkInformation(&tempInfo, &tempSize);
- for (uint32_t i = 0; i < tempSize; i++)
+ for (size_t i = 0; i < tempSize; i++)
{
char *zoneId = NULL;
EXPECT_EQ(OC_STACK_OK, OCGetLinkLocalZoneId(tempInfo[i].ifindex, &zoneId));
}
CAEndpoint_t *tempInfo = NULL;
- uint32_t tempSize = 0;
+ size_t tempSize = 0;
CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize);
- if (CA_STATUS_OK != res || NULL == tempInfo || 0 >= tempSize)
+ if (CA_STATUS_OK != res || NULL == tempInfo || 0 == tempSize)
{
free(tempInfo);
return false;
}
- for (uint32_t index = 0; index < tempSize; index++)
+ for (size_t index = 0; index < tempSize; index++)
{
if (CA_ADAPTER_IP == tempInfo[index].adapter)
{
}
CAEndpoint_t *tempInfo = NULL;
- uint32_t tempSize = 0;
+ size_t tempSize = 0;
CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize);
- if (CA_STATUS_OK != res || NULL == tempInfo || 0 >= tempSize)
+ if (CA_STATUS_OK != res || NULL == tempInfo || 0 == tempSize)
{
free(tempInfo);
return false;
}
- for (uint32_t index = 0; index < tempSize; index++)
+ for (size_t index = 0; index < tempSize; index++)
{
if (CA_ADAPTER_IP == tempInfo[index].adapter)
{
std::string SceneUtils::getNetAddress()
{
CAEndpoint_t * netInfo = nullptr;
- uint32_t size = 0;
+ size_t size = 0;
CAGetNetworkInformation(&netInfo, &size);
if (size == 0)
}
std::string address_ipv4 = "", address_ipv6 = "";
- for (uint32_t i = 0; i < size; ++i)
+ for (size_t i = 0; i < size; ++i)
{
if (netInfo[i].adapter == CATransportAdapter_t::CA_ADAPTER_IP)
{