From: Mandeep Shetty Date: Thu, 10 Sep 2015 21:35:05 +0000 (-0700) Subject: Enable error responses to be sent back to the client. X-Git-Tag: 1.0.0-RC1^2~44 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=289ff6d919059fb5655ba19122eb05cb7b5000a8;p=contrib%2Fiotivity.git Enable error responses to be sent back to the client. The resource uri was moved from the endpoint to the uri response info struct in IPv6. The function sendDirectStackResponses responsible for sending out ACKs, RESETs and error codes back to the client was not updated to take in the resource uri. As a result, the CA layer ate this error with a uri is NULL log and the client did not receive any response. Added resource Uri to the responseInfo struct to fix the problem. Change-Id: Ic3b964c646244698c1621860922fc06b40842bc3 Signed-off-by: Mandeep Shetty Reviewed-on: https://gerrit.iotivity.org/gerrit/2454 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz --- diff --git a/resource/csdk/stack/include/internal/ocstackinternal.h b/resource/csdk/stack/include/internal/ocstackinternal.h index a44654d..a77aed6 100644 --- a/resource/csdk/stack/include/internal/ocstackinternal.h +++ b/resource/csdk/stack/include/internal/ocstackinternal.h @@ -200,7 +200,7 @@ OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest); OCStackResult SendDirectStackResponse(const CAEndpoint_t* endPoint, const uint16_t coapID, const CAResponseResult_t responseResult, const CAMessageType_t type, const uint8_t numOptions, const CAHeaderOption_t *options, - CAToken_t token, uint8_t tokenLength); + CAToken_t token, uint8_t tokenLength, const char *resourceUri); #ifdef WITH_PRESENCE diff --git a/resource/csdk/stack/src/ocstack.c b/resource/csdk/stack/src/ocstack.c index 87acda6..93a9398 100644 --- a/resource/csdk/stack/src/ocstack.c +++ b/resource/csdk/stack/src/ocstack.c @@ -1127,7 +1127,7 @@ void HandleCAResponses(const CAEndpoint_t* endPoint, const CAResponseInfo_t* res if(responseInfo->info.type == CA_MSG_CONFIRM) { SendDirectStackResponse(endPoint, responseInfo->info.messageId, CA_EMPTY, - CA_MSG_ACKNOWLEDGE, 0, NULL, NULL, 0); + CA_MSG_ACKNOWLEDGE, 0, NULL, NULL, 0, NULL); } OCPayloadDestroy(response.payload); @@ -1176,7 +1176,7 @@ void HandleCAResponses(const CAEndpoint_t* endPoint, const CAResponseInfo_t* res { OC_LOG(INFO, TAG, "Received a message without callbacks. Sending RESET"); SendDirectStackResponse(endPoint, responseInfo->info.messageId, CA_EMPTY, - CA_MSG_RESET, 0, NULL, NULL, 0); + CA_MSG_RESET, 0, NULL, NULL, 0, NULL); } } @@ -1231,7 +1231,7 @@ void HandleCAErrorResponse(const CAEndpoint_t *endPoint, const CAErrorInfo_t *er OCStackResult SendDirectStackResponse(const CAEndpoint_t* endPoint, const uint16_t coapID, const CAResponseResult_t responseResult, const CAMessageType_t type, const uint8_t numOptions, const CAHeaderOption_t *options, - CAToken_t token, uint8_t tokenLength) + CAToken_t token, uint8_t tokenLength, const char *resourceUri) { CAResponseInfo_t respInfo = { .result = responseResult @@ -1243,8 +1243,14 @@ OCStackResult SendDirectStackResponse(const CAEndpoint_t* endPoint, const uint16 respInfo.info.token = token; respInfo.info.tokenLength = tokenLength; respInfo.info.type = type; + respInfo.info.resourceUri = OICStrdup (resourceUri); CAResult_t caResult = CASendResponse(endPoint, &respInfo); + + // resourceUri in the info field is cloned in the CA layer and + // thus ownership is still here. + OICFree (respInfo.info.resourceUri); + if(caResult != CA_STATUS_OK) { OC_LOG(ERROR, TAG, "CASendResponse error"); @@ -1353,7 +1359,7 @@ void HandleCARequests(const CAEndpoint_t* endPoint, const CARequestInfo_t* reque SendDirectStackResponse(endPoint, requestInfo->info.messageId, CA_BAD_REQ, requestInfo->info.type, requestInfo->info.numOptions, requestInfo->info.options, requestInfo->info.token, - requestInfo->info.tokenLength); + requestInfo->info.tokenLength, requestInfo->info.resourceUri); OICFree(serverRequest.payload); return; } @@ -1369,7 +1375,7 @@ void HandleCARequests(const CAEndpoint_t* endPoint, const CARequestInfo_t* reque SendDirectStackResponse(endPoint, requestInfo->info.messageId, CA_INTERNAL_SERVER_ERROR, requestInfo->info.type, requestInfo->info.numOptions, requestInfo->info.options, requestInfo->info.token, - requestInfo->info.tokenLength); + requestInfo->info.tokenLength, requestInfo->info.resourceUri); OICFree(serverRequest.payload); return; } @@ -1401,7 +1407,7 @@ void HandleCARequests(const CAEndpoint_t* endPoint, const CARequestInfo_t* reque SendDirectStackResponse(endPoint, requestInfo->info.messageId, CA_BAD_OPT, requestInfo->info.type, requestInfo->info.numOptions, requestInfo->info.options, requestInfo->info.token, - requestInfo->info.tokenLength); + requestInfo->info.tokenLength, requestInfo->info.resourceUri); OICFree(serverRequest.payload); OICFree(serverRequest.requestToken); return; @@ -1419,7 +1425,7 @@ void HandleCARequests(const CAEndpoint_t* endPoint, const CARequestInfo_t* reque if(requestResult == OC_STACK_SLOW_RESOURCE) { SendDirectStackResponse(endPoint, requestInfo->info.messageId, CA_EMPTY, - CA_MSG_ACKNOWLEDGE,0, NULL, NULL, 0); + CA_MSG_ACKNOWLEDGE,0, NULL, NULL, 0, NULL); } else if(requestResult != OC_STACK_OK) { @@ -1430,7 +1436,7 @@ void HandleCARequests(const CAEndpoint_t* endPoint, const CARequestInfo_t* reque SendDirectStackResponse(endPoint, requestInfo->info.messageId, stackResponse, requestInfo->info.type, requestInfo->info.numOptions, requestInfo->info.options, requestInfo->info.token, - requestInfo->info.tokenLength); + requestInfo->info.tokenLength, requestInfo->info.resourceUri); } // requestToken is fed to HandleStackRequests, which then goes to AddServerRequest. // The token is copied in there, and is thus still owned by this function.