Added message format error logic for EMPTY message.
authorhyuna0213.jo <hyuna0213.jo@samsung.com>
Fri, 4 Dec 2015 05:37:14 +0000 (05:37 +0000)
committerJon A. Cruz <jonc@osg.samsung.com>
Wed, 9 Dec 2015 20:34:13 +0000 (20:34 +0000)
According to CoAP spec(RFC 7252), Empty message has
the token length field set to Zero.
and bytes of data MUST NOT be present after the MessageID field.
If there are any bytes, they MUST be preocessed as a message
format error.

Change-Id: I1709143c9aa1851c428bbcce08d28c2d0534b89c
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3797
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
Signed-off-by: hyuna0213.jo <hyuna0213.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4403
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/ResourceModel.c
resource/csdk/connectivity/samples/linux/sample_main.c
resource/csdk/connectivity/src/caprotocolmessage.c

index 9e032ee..8296951 100644 (file)
@@ -597,7 +597,13 @@ Java_org_iotivity_ca_service_RMInterface_RMSendResponse(JNIEnv *env, jobject obj
 
     CAResponseInfo_t responseInfo = { 0 };
 
-    if (msgType != CA_MSG_RESET)
+    if (CA_MSG_RESET == msgType ||
+        (CA_MSG_ACKNOWLEDGE == msgType && CA_EMPTY == responseValue))
+    {
+        printf("RESET or ACK/EMPTY. there will be not payload/option\n");
+        responseInfo.result = CA_EMPTY;
+    }
+    else
     {
         responseData.token = g_clientToken;
         responseData.tokenLength = g_clientTokenLength;
@@ -619,11 +625,6 @@ Java_org_iotivity_ca_service_RMInterface_RMSendResponse(JNIEnv *env, jobject obj
             responseData.payloadSize = length;
         }
     }
-    //msgType is RESET
-    else
-    {
-        responseInfo.result = CA_EMPTY;
-    }
 
     responseInfo.info = responseData;
 
index 8d23a98..d717f0f 100644 (file)
@@ -1206,7 +1206,13 @@ void send_response(const CAEndpoint_t *endpoint, const CAInfo_t *info)
                               .payloadSize = 0,
                               .resourceUri = resourceUri };
 
-    if(CA_MSG_RESET != messageType)
+    if (CA_MSG_RESET == messageType ||
+        (CA_MSG_ACKNOWLEDGE == messageType && CA_EMPTY == responseCode))
+    {
+        printf("RESET or ACK/EMPTY. there will be not payload/option\n");
+
+    }
+    else
     {
         responseData.token = (info != NULL) ? info->token : NULL;
         responseData.tokenLength = (info != NULL) ? info->tokenLength : 0;
index 42a382e..f39c124 100644 (file)
@@ -127,6 +127,13 @@ coap_pdu_t *CAGeneratePDU(uint32_t code, const CAInfo_t *info, const CAEndpoint_
     // and ACKNOWLEDGE can use empty message when code is empty.
     if (CA_MSG_RESET == info->type || (CA_EMPTY == code && CA_MSG_ACKNOWLEDGE == info->type))
     {
+        if ((CA_EMPTY == code) && (info->payloadSize > 0 || info->payload
+            || info->token || info->tokenLength > 0))
+        {
+            OIC_LOG(ERROR, TAG, "Empty message has unnecessary data after messageID");
+            return NULL;
+        }
+
         OIC_LOG(DEBUG, TAG, "code is empty");
         if (!(pdu = CAGeneratePDUImpl((code_t) code, info, endpoint, NULL, transport)))
         {