Commit 04bdbb76 authored by Ziran Sun's avatar Ziran Sun

Fix client crash caused by observe cancellation with sequence No 1.

1. Added support for sequence number starting from 1.
2. When sequence number is 1, client treats it as a normal response
rather than de-registration response.
3. Correct default sequence number value to be valid.

JIRA Issue: https://jira.iotivity.org/browse/IOT-1195

Change-Id: I2ce68d70ff5f8f0cce98234a7dbda566b8085a61
Signed-off-by: default avatarZiran Sun <ziran.sun@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9541Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarPhil Coval <philippe.coval@osg.samsung.com>
Reviewed-by: default avatarMarkus Jung <markus.jung85@gmail.com>
Reviewed-by: default avatarMushfiqul Islam <i.mushfiq@samsung.com>
parent c5ec8565
......@@ -66,8 +66,8 @@ extern void* defaultDeviceHandlerCallbackParameter;
/** The coap scheme */
#define OC_COAP_SCHEME "coap://"
/** the first outgoing sequence number will be 2*/
#define OC_OFFSET_SEQUENCE_NUMBER (1)
/** the first outgoing sequence number will be 1*/
#define OC_OFFSET_SEQUENCE_NUMBER (0)
/**
* This structure will be created in occoap and passed up the stack on the server side.
......
......@@ -1140,6 +1140,9 @@ HandleResourceWithEntityHandler (OCServerRequest *request,
{
OIC_LOG(INFO, TAG, "Removed observer successfully");
request->observeResult = OC_STACK_OK;
// There should be no observe option header for de-registration response.
// Set as an invalid value here so we can detect it later and remove the field in response.
request->observationOption = MAX_SEQUENCE_NUMBER + 1;
}
else
{
......
......@@ -22,6 +22,7 @@
#include "ocstack.h"
#include "ocserverrequest.h"
#include "ocresourcehandler.h"
#include "ocobserve.h"
#include "oic_malloc.h"
#include "oic_string.h"
#include "ocpayload.h"
......@@ -552,8 +553,8 @@ OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse)
memcpy(responseInfo.info.token, serverRequest->requestToken, serverRequest->tokenLength);
responseInfo.info.tokenLength = serverRequest->tokenLength;
// De-register observe option should not be included in the response header
if((serverRequest->observeResult == OC_STACK_OK) && (serverRequest->observationOption != OC_OBSERVE_DEREGISTER))
if((serverRequest->observeResult == OC_STACK_OK)&&
(serverRequest->observationOption != MAX_SEQUENCE_NUMBER + 1))
{
responseInfo.info.numOptions = ehResponse->numSendVendorSpecificHeaderOptions + 1;
}
......
......@@ -1129,7 +1129,7 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp
OCClientResponse response =
{.devAddr = {.adapter = OC_DEFAULT_ADAPTER}};
response.sequenceNumber = -1;
response.sequenceNumber = MAX_SEQUENCE_NUMBER + 1;
CopyEndpointToDevAddr(endPoint, &response.devAddr);
FixUpClientResponse(&response);
response.resourceUri = responseInfo->info.resourceUri;
......@@ -1276,6 +1276,7 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp
if (cbNode->method == OC_REST_OBSERVE &&
response.sequenceNumber > OC_OFFSET_SEQUENCE_NUMBER &&
cbNode->sequenceNumber <= MAX_SEQUENCE_NUMBER &&
response.sequenceNumber <= cbNode->sequenceNumber)
{
OIC_LOG_V(INFO, TAG, "Received stale notification. Number :%d",
......
......@@ -29,6 +29,8 @@
#include "OCPlatform.h"
#include "OCApi.h"
#define maxSequenceNumber 0xFFFFFF
using namespace OC;
static const char* SVR_DB_FILE_NAME = "./oic_svr_db_client.dat";
......@@ -65,7 +67,7 @@ void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation& re
{
try
{
if(eCode == OC_STACK_OK && sequenceNumber != -1)
if(eCode == OC_STACK_OK && sequenceNumber != maxSequenceNumber + 1)
{
if(sequenceNumber == OC_OBSERVE_REGISTER)
{
......
......@@ -644,10 +644,7 @@ namespace OC
std::thread exec(context->callback, serverHeaderOptions, attrs,
result, sequenceNumber);
exec.detach();
if (sequenceNumber == OC_OBSERVE_DEREGISTER)
{
return OC_STACK_DELETE_TRANSACTION;
}
return OC_STACK_KEEP_TRANSACTION;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment