From: hyuna0213.jo Date: Wed, 9 Mar 2016 05:25:23 +0000 (+0900) Subject: Removed unnecessary/duplicated code in connectivity abstraction X-Git-Tag: 1.2.0+RC1~534 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0bb49578a6094d8e08015fcb224511cd1d4f2f54;p=platform%2Fupstream%2Fiotivity.git Removed unnecessary/duplicated code in connectivity abstraction remove unnecessary/duplicated code in connectivity abstraction to increase unit tc coverage Change-Id: Ifa589642b43f1590ed492a129a0af4a2cd954358 Signed-off-by: hyuna0213.jo Reviewed-on: https://gerrit.iotivity.org/gerrit/5607 Reviewed-by: jihwan seo Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz Reviewed-on: https://gerrit.iotivity.org/gerrit/5729 Reviewed-by: Jaehong Jo --- diff --git a/resource/csdk/connectivity/inc/camessagehandler.h b/resource/csdk/connectivity/inc/camessagehandler.h index 1bd51a0..0e37c47 100644 --- a/resource/csdk/connectivity/inc/camessagehandler.h +++ b/resource/csdk/connectivity/inc/camessagehandler.h @@ -72,19 +72,6 @@ CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint, 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. diff --git a/resource/csdk/connectivity/inc/caprotocolmessage.h b/resource/csdk/connectivity/inc/caprotocolmessage.h index ef88ebe..343d600 100644 --- a/resource/csdk/connectivity/inc/caprotocolmessage.h +++ b/resource/csdk/connectivity/inc/caprotocolmessage.h @@ -217,12 +217,6 @@ CAResult_t CAGenerateTokenInternal(CAToken_t *token, uint8_t tokenLength); void CADestroyTokenInternal(CAToken_t token); /** - * destroy the ca info structure. - * @param[in] info info structure created from received packet. - */ -void CADestroyInfo(CAInfo_t *info); - -/** * gets message type from PDU binary data. * @param[in] pdu pdu data. * @param[in] size size of pdu data. diff --git a/resource/csdk/connectivity/src/camessagehandler.c b/resource/csdk/connectivity/src/camessagehandler.c index f127742..d91ef7d 100644 --- a/resource/csdk/connectivity/src/camessagehandler.c +++ b/resource/csdk/connectivity/src/camessagehandler.c @@ -399,12 +399,11 @@ static CAResult_t CAProcessMulticastData(const CAData_t *data) 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.."); @@ -422,16 +421,11 @@ static CAResult_t CAProcessMulticastData(const CAData_t *data) ) { // 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 @@ -440,7 +434,7 @@ static CAResult_t CAProcessMulticastData(const CAData_t *data) { 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) @@ -463,16 +457,11 @@ static CAResult_t CAProcessMulticastData(const CAData_t *data) // 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; } } } @@ -482,13 +471,13 @@ static CAResult_t CAProcessMulticastData(const CAData_t *data) { 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); @@ -500,15 +489,18 @@ static CAResult_t CAProcessMulticastData(const CAData_t *data) 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) @@ -935,8 +927,7 @@ static CAData_t* CAPrepareSendData(const CAEndpoint_t *endpoint, const void *sen if(!request) { OIC_LOG(ERROR, TAG, "CACloneRequestInfo failed"); - OICFree(cadata); - return NULL; + goto exit; } cadata->type = request->isMulticast ? SEND_TYPE_MULTICAST : SEND_TYPE_UNICAST; @@ -950,8 +941,7 @@ static CAData_t* CAPrepareSendData(const CAEndpoint_t *endpoint, const void *sen if(!response) { OIC_LOG(ERROR, TAG, "CACloneResponseInfo failed"); - OICFree(cadata); - return NULL; + goto exit; } cadata->type = response->isMulticast ? SEND_TYPE_MULTICAST : SEND_TYPE_UNICAST; @@ -960,8 +950,7 @@ static CAData_t* CAPrepareSendData(const CAEndpoint_t *endpoint, const void *sen else { OIC_LOG(ERROR, TAG, "CAPrepareSendData unknown data type"); - OICFree(cadata); - return NULL; + goto exit; } CAEndpoint_t* ep = CACloneEndpoint(endpoint); @@ -975,6 +964,10 @@ static CAData_t* CAPrepareSendData(const CAEndpoint_t *endpoint, const void *sen cadata->remoteEndpoint = ep; cadata->dataType = dataType; return cadata; + +exit: + OICFree(cadata); + return NULL; } CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint, const void *sendMsg, @@ -1046,18 +1039,6 @@ 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) { diff --git a/resource/csdk/connectivity/src/caprotocolmessage.c b/resource/csdk/connectivity/src/caprotocolmessage.c index e83c31e..d1975ed 100644 --- a/resource/csdk/connectivity/src/caprotocolmessage.c +++ b/resource/csdk/connectivity/src/caprotocolmessage.c @@ -1016,21 +1016,6 @@ void CADestroyTokenInternal(CAToken_t token) OICFree(token); } -void CADestroyInfo(CAInfo_t *info) -{ - if (NULL != info) - { - OIC_LOG(DEBUG, TAG, "free options"); - OICFree(info->options); - - OIC_LOG(DEBUG, TAG, "free token"); - OICFree(info->token); - - OIC_LOG(DEBUG, TAG, "free payload"); - OICFree(info->payload); - } -} - uint32_t CAGetOptionData(uint16_t key, const uint8_t *data, uint32_t len, uint8_t *option, uint32_t buflen) { diff --git a/resource/csdk/connectivity/src/ip_adapter/caipadapter.c b/resource/csdk/connectivity/src/ip_adapter/caipadapter.c index c958e0f..9fd3a4f 100644 --- a/resource/csdk/connectivity/src/ip_adapter/caipadapter.c +++ b/resource/csdk/connectivity/src/ip_adapter/caipadapter.c @@ -168,26 +168,15 @@ void CAIPPacketReceivedCB(const CASecureEndpoint_t *sep, const void *data, } } -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); } }