[IOT-1570] fixed a crash issue related to block-wise transfer
authorJaewook Jung <jw0213.jung@samsung.com>
Thu, 17 Nov 2016 04:14:43 +0000 (13:14 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Fri, 18 Nov 2016 08:33:37 +0000 (08:33 +0000)
When a resource server receives 4.08 error response from a resource
client, the server will try to send the response from the first
block again.
But now, the server assumes the message type that has to be sent
for receiving 4.08 error is only request message.
So I modified to handle it up to the message type.

Change-Id: I555b5dd5c44b73647c2543de551aba6f5113f909
Signed-off-by: Jaewook Jung <jw0213.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14433
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
(cherry picked from commit 4667f8b18e45b67022a0dc0966ad85c572d52f53)
Reviewed-on: https://gerrit.iotivity.org/gerrit/14439
Reviewed-by: Uze Choi <uzchoi@samsung.com>
resource/csdk/connectivity/src/cablockwisetransfer.c

index 1cd1864..f2c0e2a 100644 (file)
@@ -642,21 +642,26 @@ CAResult_t CASendBlockMessage(const coap_pdu_t *pdu, CAMessageType_t msgType,
     }
     else
     {
-        // if the received response message type is CON, send empty message.
-        // and then, send next block request message with new messagId.
-        if (msgType == CA_MSG_CONFIRM)
-        {
-            CASendDirectEmptyResponse(data->remoteEndpoint,
-                                      data->requestInfo->info.messageId);
-            sentMsgType = CA_MSG_CONFIRM;
-        }
-
         if (data->requestInfo)
         {
+            // if the received response message type is CON, send empty message.
+            // and then, send next block request message with new messagId.
+            if (msgType == CA_MSG_CONFIRM)
+            {
+                CASendDirectEmptyResponse(data->remoteEndpoint,
+                                          data->requestInfo->info.messageId);
+                sentMsgType = CA_MSG_CONFIRM;
+            }
+
             OIC_LOG(DEBUG, TAG, "need new msgID");
             data->requestInfo->info.messageId = 0;
             data->requestInfo->info.type = sentMsgType;
         }
+        else if (data->responseInfo)
+        {
+            data->responseInfo->info.messageId = pdu->transport_hdr->udp.id;
+            data->responseInfo->info.type = sentMsgType;
+        }
     }
 
     // add data to send thread
@@ -1863,7 +1868,11 @@ uint8_t CACheckBlockErrorType(CABlockData_t *currData, coap_block_t *receivedBlo
                 OIC_LOG(ERROR, TAG, "it didn't order");
                 return CA_BLOCK_INCOMPLETE;
             }
-            return CA_BLOCK_RECEIVED_ALREADY;
+            else
+            {
+                OIC_LOG(ERROR, TAG, "already received this block");
+                return CA_BLOCK_RECEIVED_ALREADY;
+            }
         }
     }
 
@@ -2606,8 +2615,14 @@ void CADestroyDataSet(CAData_t* data)
     VERIFY_NON_NULL_VOID(data, TAG, "data");
 
     CAFreeEndpoint(data->remoteEndpoint);
-    CADestroyRequestInfoInternal(data->requestInfo);
-    CADestroyResponseInfoInternal(data->responseInfo);
+    if (data->requestInfo)
+    {
+        CADestroyRequestInfoInternal(data->requestInfo);
+    }
+    if (data->responseInfo)
+    {
+        CADestroyResponseInfoInternal(data->responseInfo);
+    }
     OICFree(data);
 }