return data->requestInfo->info.payload;
}
}
- else
+ else if (data->responseInfo)
{
if (data->responseInfo->info.payload)
{
return NULL;
}
+CABlockData_t *CAUpdateDataSetFromBlockDataList(const CABlockDataID_t *blockID,
+ const CAData_t *sendData)
+{
+ VERIFY_NON_NULL_RET(blockID, TAG, "blockID", NULL);
+ VERIFY_NON_NULL_RET(sendData, TAG, "sendData", NULL);
+
+ oc_mutex_lock(g_context.blockDataListMutex);
+
+ size_t len = u_arraylist_length(g_context.dataList);
+ for (size_t i = 0; i < len; i++)
+ {
+ CABlockData_t *currData = (CABlockData_t *) u_arraylist_get(g_context.dataList, i);
+ if (CABlockidMatches(currData, blockID))
+ {
+ CADestroyDataSet(currData->sentData);
+ currData->sentData = CACloneCAData(sendData);
+ oc_mutex_unlock(g_context.blockDataListMutex);
+ return currData;
+ }
+ }
+ oc_mutex_unlock(g_context.blockDataListMutex);
+
+ return NULL;
+}
+
CAResult_t CAGetTokenFromBlockDataList(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
CAResponseInfo_t *responseInfo)
{
return CA_STATUS_FAILED;
}
- CABlockData_t *storedData = CAGetBlockDataFromBlockDataList(blockDataID);
- if (storedData)
+ CABlockData_t *updatedData = CAUpdateDataSetFromBlockDataList(blockDataID, sendData);
+ if (updatedData)
{
OIC_LOG(DEBUG, TAG, "Send response about the received block request.");
- if (storedData->sentData)
- {
- OIC_LOG(DEBUG, TAG, "init block number");
- CADestroyDataSet(storedData->sentData);
- }
- storedData->sentData = CACloneCAData(sendData);
- *blockData = storedData;
+ *blockData = updatedData;
CADestroyBlockID(blockDataID);
return CA_STATUS_OK;
}
}
// destroy memory
- CADestroyDataSet(currData->sentData);
- CADestroyBlockID(currData->blockDataId);
- OICFree(currData->payload);
- OICFree(currData);
+ CADestroyDataSet(removedData->sentData);
+ CADestroyBlockID(removedData->blockDataId);
+ OICFree(removedData->payload);
+ OICFree(removedData);
oc_mutex_unlock(g_context.blockDataListMutex);
return CA_STATUS_OK;
}
{
VERIFY_NON_NULL_VOID(data, TAG, "data");
- CAFreeEndpoint(data->remoteEndpoint);
+ if (data->remoteEndpoint)
+ {
+ CAFreeEndpoint(data->remoteEndpoint);
+ data->remoteEndpoint = NULL;
+ }
if (data->requestInfo)
{
CADestroyRequestInfoInternal(data->requestInfo);
+ data->requestInfo = NULL;
}
if (data->responseInfo)
{
CADestroyResponseInfoInternal(data->responseInfo);
+ data->responseInfo = NULL;
}
OICFree(data);
}
return CA_STATUS_FAILED;
}
- CAResult_t res = CA_STATUS_OK;
-
- if (NULL != CAGetBlockDataFromBlockDataList(blockDataID))
+ CAResult_t res = CARemoveBlockDataFromList(blockDataID);
+ if (CA_STATUS_OK != res)
{
- res = CARemoveBlockDataFromList(blockDataID);
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CARemoveBlockDataFromList failed");
- }
+ OIC_LOG(ERROR, TAG, "CARemoveBlockDataFromList failed");
}
CADestroyBlockID(blockDataID);
-
return res;
}