From: hyuna0213.jo Date: Mon, 28 Nov 2016 08:11:34 +0000 (+0900) Subject: [IOT-1608] Support PUT,POST,DELETE method type for /oic/ping X-Git-Tag: 1.3.0~1022^2~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=124dee767a034b741497a2aebbe43ae7e0b49b7e;p=platform%2Fupstream%2Fiotivity.git [IOT-1608] Support PUT,POST,DELETE method type for /oic/ping If PUT,DELETE methoed type is received for /oic/ping, HandleKeepAliveRequest() function will respond to remote device with error code. bug: https://jira.iotivity.org/browse/IOT-1608 Change-Id: I47d81222cebced3505cafec8eabfe0604c94d8a3 Signed-off-by: hyuna0213.jo Reviewed-on: https://gerrit.iotivity.org/gerrit/14835 Tested-by: jenkins-iotivity Reviewed-by: Phil Coval Reviewed-by: Ziran Sun Reviewed-on: https://gerrit.iotivity.org/gerrit/15321 Reviewed-by: jihwan seo Reviewed-by: Ashok Babu Channa --- diff --git a/resource/csdk/stack/src/ocresource.c b/resource/csdk/stack/src/ocresource.c index 3958298..9ba44ac 100755 --- a/resource/csdk/stack/src/ocresource.c +++ b/resource/csdk/stack/src/ocresource.c @@ -881,15 +881,6 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource return OC_STACK_INVALID_PARAM; } - OCStackResult discoveryResult = OC_STACK_ERROR; - if (request->method == OC_REST_PUT || request->method == OC_REST_POST || - request->method == OC_REST_DELETE) - { - OIC_LOG_V(ERROR, TAG, "Resource : %s not permitted for method: %d", - request->resourceUrl, request->method); - return OC_STACK_UNAUTHORIZED_REQ; - } - OCPayload* payload = NULL; char *interfaceQuery = NULL; char *resourceTypeQuery = NULL; @@ -899,6 +890,24 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource OCVirtualResources virtualUriInRequest = GetTypeOfVirtualURI (request->resourceUrl); +#ifdef TCP_ADAPTER + if (OC_KEEPALIVE_RESOURCE_URI == virtualUriInRequest) + { + // Received request for a keepalive + OIC_LOG(INFO, TAG, "Request is for KeepAlive Request"); + return HandleKeepAliveRequest(request, resource); + } +#endif + + OCStackResult discoveryResult = OC_STACK_ERROR; + if (request->method == OC_REST_PUT || request->method == OC_REST_POST || + request->method == OC_REST_DELETE) + { + OIC_LOG_V(ERROR, TAG, "Resource : %s not permitted for method: %d", + request->resourceUrl, request->method); + return OC_STACK_UNAUTHORIZED_REQ; + } + // Step 1: Generate the response to discovery request if (virtualUriInRequest == OC_WELL_KNOWN_URI #ifdef MQ_BROKER @@ -1019,14 +1028,7 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource discoveryResult = RMHandleGatewayRequest(request, resource); } #endif -#ifdef TCP_ADAPTER - else if (OC_KEEPALIVE_RESOURCE_URI == virtualUriInRequest) - { - // Received request for a keepalive - OIC_LOG(INFO, TAG, "Request is for KeepAlive Request"); - discoveryResult = HandleKeepAliveRequest(request, resource); - } -#endif + /** * Step 2: Send the discovery response * @@ -1065,34 +1067,28 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource if (OC_GATEWAY_URI != virtualUriInRequest) #endif { -#if TCP_ADAPTER - // KeepAlive uses the HandleKeepAliveRequest to respond to the request. - if (OC_KEEPALIVE_RESOURCE_URI != virtualUriInRequest) -#endif + OIC_LOG_PAYLOAD(DEBUG, payload); + if(discoveryResult == OC_STACK_OK) { - OIC_LOG_PAYLOAD(DEBUG, payload); - if(discoveryResult == OC_STACK_OK) - { - SendNonPersistantDiscoveryResponse(request, resource, payload, OC_EH_OK); - } - else if(((request->devAddr.flags & OC_MULTICAST) == false) && - (request->devAddr.adapter != OC_ADAPTER_RFCOMM_BTEDR) && - (request->devAddr.adapter != OC_ADAPTER_GATT_BTLE)) - { - OIC_LOG_V(ERROR, TAG, "Sending a (%d) error to (%d) discovery request", - discoveryResult, virtualUriInRequest); - SendNonPersistantDiscoveryResponse(request, resource, NULL, - (discoveryResult == OC_STACK_NO_RESOURCE) ? - OC_EH_RESOURCE_NOT_FOUND : OC_EH_ERROR); - } - else - { - // Ignoring the discovery request as per RFC 7252, Section #8.2 - OIC_LOG(INFO, TAG, "Silently ignoring the request since no useful data to send."); - // the request should be removed. - // since it never remove and causes a big memory waste. - FindAndDeleteServerRequest(request); - } + SendNonPersistantDiscoveryResponse(request, resource, payload, OC_EH_OK); + } + else if(((request->devAddr.flags & OC_MULTICAST) == false) && + (request->devAddr.adapter != OC_ADAPTER_RFCOMM_BTEDR) && + (request->devAddr.adapter != OC_ADAPTER_GATT_BTLE)) + { + OIC_LOG_V(ERROR, TAG, "Sending a (%d) error to (%d) discovery request", + discoveryResult, virtualUriInRequest); + SendNonPersistantDiscoveryResponse(request, resource, NULL, + (discoveryResult == OC_STACK_NO_RESOURCE) ? + OC_EH_RESOURCE_NOT_FOUND : OC_EH_ERROR); + } + else + { + // Ignoring the discovery request as per RFC 7252, Section #8.2 + OIC_LOG(INFO, TAG, "Silently ignoring the request since no useful data to send."); + // the request should be removed. + // since it never remove and causes a big memory waste. + FindAndDeleteServerRequest(request); } } diff --git a/resource/csdk/stack/src/ocstack.c b/resource/csdk/stack/src/ocstack.c index 25adfbf..2acb26a 100644 --- a/resource/csdk/stack/src/ocstack.c +++ b/resource/csdk/stack/src/ocstack.c @@ -1342,7 +1342,7 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp type = PAYLOAD_TYPE_REPRESENTATION; } #ifdef TCP_ADAPTER - else if (strcmp(cbNode->requestUri, KEEPALIVE_RESOURCE_URI) == 0) + else if (strcmp(cbNode->requestUri, OC_RSRVD_KEEPALIVE_URI) == 0) { type = PAYLOAD_TYPE_REPRESENTATION; } diff --git a/resource/csdk/stack/src/oickeepalive.c b/resource/csdk/stack/src/oickeepalive.c index c06bc5d..44d91ba 100644 --- a/resource/csdk/stack/src/oickeepalive.c +++ b/resource/csdk/stack/src/oickeepalive.c @@ -385,6 +385,10 @@ OCStackResult HandleKeepAliveRequest(OCServerRequest *request, } OCStackResult ret = SendKeepAliveResponse(request, result); + if (OC_STACK_OK != ret) + { + OIC_LOG_V(ERROR, TAG, "SendKeepAliveResponse failed with result %u", ret); + } OIC_LOG(DEBUG, TAG, "HandleKeepAliveRequest OUT"); return ret;