#include "caadapterutils.h"
#include "cainterfacecontroller.h"
#include "caretransmission.h"
+#include "oic_string.h"
#ifdef WITH_BWT
#include "cablockwisetransfer.h"
if (!ep)
{
OIC_LOG(ERROR, TAG, "endpoint clone failed");
- OICFree(cadata);
- return NULL;
+ goto exit;
}
OIC_LOG_V(DEBUG, TAG, "address : %s", ep->addr);
- CAResult_t result;
- if(CA_RESPONSE_DATA == dataType)
+ if (CA_RESPONSE_DATA == dataType)
{
CAResponseInfo_t* resInfo = (CAResponseInfo_t*)OICCalloc(1, sizeof(CAResponseInfo_t));
if (!resInfo)
{
OIC_LOG(ERROR, TAG, "memory allocation failed");
- OICFree(cadata);
- CAFreeEndpoint(ep);
- return NULL;
+ goto exit;
}
- result = CAGetResponseInfoFromPDU(data, resInfo, endpoint);
+ CAResult_t result = CAGetResponseInfoFromPDU(data, resInfo, endpoint);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, TAG, "CAGetResponseInfoFromPDU Failed");
- CAFreeEndpoint(ep);
CADestroyResponseInfoInternal(resInfo);
- OICFree(cadata);
- return NULL;
+ goto exit;
}
cadata->responseInfo = resInfo;
info = &resInfo->info;
if (!reqInfo)
{
OIC_LOG(ERROR, TAG, "memory allocation failed");
- OICFree(cadata);
- CAFreeEndpoint(ep);
- return NULL;
+ goto exit;
}
- result = CAGetRequestInfoFromPDU(data, endpoint, reqInfo);
+ CAResult_t result = CAGetRequestInfoFromPDU(data, endpoint, reqInfo);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, TAG, "CAGetRequestInfoFromPDU failed");
- CAFreeEndpoint(ep);
CADestroyRequestInfoInternal(reqInfo);
- OICFree(cadata);
- return NULL;
+ goto exit;
}
if (CADropSecondMessage(&caglobals.ca.requestHistory, endpoint, reqInfo->info.messageId,
reqInfo->info.token, reqInfo->info.tokenLength))
{
OIC_LOG(ERROR, TAG, "Second Request with same Token, Drop it");
- CAFreeEndpoint(ep);
CADestroyRequestInfoInternal(reqInfo);
- OICFree(cadata);
- return NULL;
+ goto exit;
}
cadata->requestInfo = reqInfo;
if (!errorInfo)
{
OIC_LOG(ERROR, TAG, "Memory allocation failed!");
- OICFree(cadata);
- CAFreeEndpoint(ep);
- return NULL;
+ goto exit;
}
CAResult_t result = CAGetErrorInfoFromPDU(data, endpoint, errorInfo);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, TAG, "CAGetErrorInfoFromPDU failed");
- CAFreeEndpoint(ep);
OICFree(errorInfo);
- OICFree(cadata);
- return NULL;
+ goto exit;
}
cadata->errorInfo = errorInfo;
OIC_LOG(DEBUG, TAG, "CAGenerateHandlerData OUT");
return cadata;
+
+exit:
+ OICFree(cadata);
+ CAFreeEndpoint(ep);
+ return NULL;
}
static void CATimeoutCallback(const CAEndpoint_t *endpoint, const void *pdu, uint32_t size)
coap_pdu_t *pdu = NULL;
CAInfo_t *info = NULL;
coap_list_t *options = NULL;
- coap_transport_type transport;
+ coap_transport_type transport = coap_udp;
CAResult_t res = CA_SEND_FAILED;
if (NULL != data->requestInfo)
{
return res;
}
}
- else if (NULL != data->responseInfo)
- {
- OIC_LOG(DEBUG, TAG, "responseInfo is available..");
-
- info = &data->responseInfo->info;
- pdu = CAGeneratePDU(data->responseInfo->result, info, data->remoteEndpoint,
- &options, &transport);
-
- if (NULL != pdu)
- {
-#ifdef WITH_BWT
- if (CAIsSupportedBlockwiseTransfer(data->remoteEndpoint->adapter))
- {
- // Blockwise transfer
- if (NULL != info)
- {
- res = CAAddBlockOption(&pdu, info, data->remoteEndpoint, &options);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(INFO, TAG, "to write block option has failed");
- goto exit;
- }
- }
- }
-#endif // WITH_BWT
- }
- else
- {
- OIC_LOG(ERROR,TAG,"Failed to generate multicast PDU");
- CASendErrorInfo(data->remoteEndpoint, info, CA_SEND_FAILED);
- return res;
- }
- }
else
{
- OIC_LOG(ERROR, TAG, "request or response info is empty");
+ OIC_LOG(ERROR, TAG, "not supported message type for multicast.");
return res;
}
coap_pdu_t *pdu = NULL;
CAInfo_t *info = NULL;
coap_list_t *options = NULL;
- coap_transport_type transport;
+ coap_transport_type transport = coap_udp;
if (SEND_TYPE_UNICAST == type)
{
OIC_LOG(DEBUG,TAG,"Unicast message");
+
#ifdef ROUTING_GATEWAY
/*
* When forwarding a packet, do not attempt retransmission as its the responsibility of
CAResult_t res = CAReceiveBlockWiseData(pdu, &(sep->endpoint), cadata, dataLen);
if (CA_NOT_SUPPORTED == res || CA_REQUEST_TIMEOUT == res)
{
- OIC_LOG(ERROR, TAG, "this message does not have block option");
+ OIC_LOG(DEBUG, TAG, "this message does not have block option");
CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
}
else
return NULL;
}
- if(CA_REQUEST_DATA == dataType)
+ if (CA_REQUEST_DATA == dataType)
{
// clone request info
CARequestInfo_t *request = CACloneRequestInfo((CARequestInfo_t *)sendData);
- if(!request)
+ if (!request)
{
OIC_LOG(ERROR, TAG, "CACloneRequestInfo failed");
goto exit;
cadata->type = request->isMulticast ? SEND_TYPE_MULTICAST : SEND_TYPE_UNICAST;
cadata->requestInfo = request;
}
- else if(CA_RESPONSE_DATA == dataType)
+ else if (CA_RESPONSE_DATA == dataType)
{
// clone response info
CAResponseInfo_t *response = CACloneResponseInfo((CAResponseInfo_t *)sendData);
if (!ep)
{
OIC_LOG(ERROR, TAG, "endpoint clone failed");
- CADestroyData(cadata, sizeof(CAData_t));
- return NULL;
+ goto exit;
}
cadata->remoteEndpoint = ep;
return cadata;
exit:
- OICFree(cadata);
+ CADestroyData(cadata, sizeof(CAData_t));
return NULL;
}
#ifdef SINGLE_THREAD
CAResult_t result = CAProcessSendData(data);
- if(CA_STATUS_OK != result)
+ if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, TAG, "CAProcessSendData failed");
CADestroyData(data, sizeof(CAData_t));
{
// send block data
CAResult_t res = CASendBlockWiseData(data);
- if(CA_NOT_SUPPORTED == res)
+ if (CA_NOT_SUPPORTED == res)
{
OIC_LOG(DEBUG, TAG, "normal msg will be sent");
CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t));
static void CALogPayloadInfo(CAInfo_t *info)
{
- if(info)
+ if (info)
{
if (info->options)
{
}
CAData_t *cadata = CAGenerateHandlerData(endpoint, NULL, pdu, CA_ERROR_DATA);
- if(!cadata)
+ if (!cadata)
{
OIC_LOG(ERROR, TAG, "CAErrorHandler, CAGenerateHandlerData failed!");
coap_delete_pdu(pdu);