CADataType_t dataType);
/**
- * Detaches control from the caller for sending request.
- * @param[in] resourceUri resource uri that needs to be sent in the request.
- * @param[in] token token information of the request.
- * @param[in] tokenLength length of the token.
- * @param[in] options header options that need to be append in the request.
- * @param[in] numOptions number of options be appended.
- * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
- */
-CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t token,
- uint8_t tokenLength, const CAHeaderOption_t *options,
- uint8_t numOptions);
-
-/**
* Setting the request and response callbacks for network packets.
* @param[in] ReqHandler callback for receiving the requests.
* @param[in] RespHandler callback for receiving the response.
VERIFY_NON_NULL(data, TAG, "data");
VERIFY_NON_NULL(data->remoteEndpoint, TAG, "remoteEndpoint");
- CAResult_t res = CA_STATUS_FAILED;
-
coap_pdu_t *pdu = NULL;
CAInfo_t *info = NULL;
coap_list_t *options = NULL;
coap_transport_type transport;
+ CAResult_t res = CA_SEND_FAILED;
if (NULL != data->requestInfo)
{
OIC_LOG(DEBUG, TAG, "requestInfo is available..");
)
{
// Blockwise transfer
- CAResult_t res = CAAddBlockOption(&pdu, info,
- data->remoteEndpoint,
- &options);
+ res = CAAddBlockOption(&pdu, info, data->remoteEndpoint, &options);
if (CA_STATUS_OK != res)
{
OIC_LOG(DEBUG, TAG, "CAAddBlockOption has failed");
- CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
- coap_delete_list(options);
- coap_delete_pdu(pdu);
- return res;
+ goto exit;
}
}
#endif // WITH_BWT
{
OIC_LOG(ERROR,TAG,"Failed to generate multicast PDU");
CASendErrorInfo(data->remoteEndpoint, info, CA_SEND_FAILED);
- return CA_SEND_FAILED;
+ return res;
}
}
else if (NULL != data->responseInfo)
// Blockwise transfer
if (NULL != info)
{
- CAResult_t res = CAAddBlockOption(&pdu, info,
- data->remoteEndpoint,
- &options);
+ res = CAAddBlockOption(&pdu, info, data->remoteEndpoint, &options);
if (CA_STATUS_OK != res)
{
OIC_LOG(INFO, TAG, "to write block option has failed");
- CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
- coap_delete_list(options);
- coap_delete_pdu(pdu);
- return res;
+ goto exit;
}
}
}
{
OIC_LOG(ERROR,TAG,"Failed to generate multicast PDU");
CASendErrorInfo(data->remoteEndpoint, info, CA_SEND_FAILED);
- return CA_SEND_FAILED;
+ return res;
}
}
else
{
OIC_LOG(ERROR, TAG, "request or response info is empty");
- return CA_SEND_FAILED;
+ return res;
}
CALogPDUInfo(pdu, data->remoteEndpoint);
if (CA_STATUS_OK != res)
{
OIC_LOG_V(ERROR, TAG, "send failed:%d", res);
- CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
- coap_delete_list(options);
- coap_delete_pdu(pdu);
- return res;
+ goto exit;
}
coap_delete_list(options);
coap_delete_pdu(pdu);
- return CA_STATUS_OK;
+ return res;
+
+exit:
+ CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
+ coap_delete_list(options);
+ coap_delete_pdu(pdu);
+ return res;
}
static CAResult_t CAProcessSendData(const CAData_t *data)
if(!request)
{
OIC_LOG(ERROR, TAG, "CACloneRequestInfo failed");
- OICFree(cadata);
- return NULL;
+ goto exit;
}
cadata->type = request->isMulticast ? SEND_TYPE_MULTICAST : SEND_TYPE_UNICAST;
if(!response)
{
OIC_LOG(ERROR, TAG, "CACloneResponseInfo failed");
- OICFree(cadata);
- return NULL;
+ goto exit;
}
cadata->type = response->isMulticast ? SEND_TYPE_MULTICAST : SEND_TYPE_UNICAST;
else
{
OIC_LOG(ERROR, TAG, "CAPrepareSendData unknown data type");
- OICFree(cadata);
- return NULL;
+ goto exit;
}
CAEndpoint_t* ep = CACloneEndpoint(endpoint);
cadata->remoteEndpoint = ep;
cadata->dataType = dataType;
return cadata;
+
+exit:
+ OICFree(cadata);
+ return NULL;
}
CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint, const void *sendMsg,
return CA_STATUS_OK;
}
-CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t token,
- uint8_t tokenLength, const CAHeaderOption_t *options,
- uint8_t numOptions)
-{
- (void)resourceUri;
- (void)token;
- (void)tokenLength;
- (void)options;
- (void)numOptions;
- return CA_NOT_SUPPORTED;
-}
-
void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
CAErrorCallback errorHandler)
{
}
}
-void CAIPErrorHandler (const CAEndpoint_t *endpoint, const void *data,
- uint32_t dataLength, CAResult_t result)
+void CAIPErrorHandler(const CAEndpoint_t *endpoint, const void *data,
+ uint32_t dataLength, CAResult_t result)
{
VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint is NULL");
VERIFY_NON_NULL_VOID(data, TAG, "data is NULL");
- void *buf = (void*)OICMalloc(sizeof(char) * dataLength);
- if (!buf)
- {
- OIC_LOG(ERROR, TAG, "Memory Allocation failed!");
- return;
- }
- memcpy(buf, data, dataLength);
if (g_errorCallback)
{
- g_errorCallback(endpoint, buf, dataLength, result);
- }
- else
- {
- OICFree(buf);
+ g_errorCallback(endpoint, data, dataLength, result);
}
}