[IOT-1608] Support PUT,POST,DELETE method type for /oic/ping
authorhyuna0213.jo <hyuna0213.jo@samsung.com>
Mon, 28 Nov 2016 08:11:34 +0000 (17:11 +0900)
committerZiran Sun <ziran.sun@samsung.com>
Mon, 28 Nov 2016 10:16:21 +0000 (10:16 +0000)
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 <hyuna0213.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14835
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
Reviewed-by: Ziran Sun <ziran.sun@samsung.com>
resource/csdk/stack/src/ocresource.c
resource/csdk/stack/src/ocstack.c
resource/csdk/stack/src/oickeepalive.c

index 3405556acda51b2eb5aee665b5f34cc54a9cf788..55523944bfa1ca93cb79f07ae0c614728965da04 100755 (executable)
@@ -834,15 +834,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;
@@ -852,6 +843,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
@@ -938,14 +947,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
      *
@@ -984,34 +986,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);
         }
     }
 
index 74b4e7daf2f612c4126fec6fb5e0a59a1cac27e0..bde9b0ebd7871a99839fde5a95b2e3c6c4a6d861 100644 (file)
@@ -1313,7 +1313,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;
                     }
index ecd0f19109d23f6dbeba74b1e673d2aeb0288a83..af6cb6421285ad7b1957f408ae1bba1c2b9c6917 100644 (file)
@@ -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;