From ed9352f40b86c8d6c7e5f7732d4f68498ec69460 Mon Sep 17 00:00:00 2001 From: Ziran Sun Date: Tue, 21 Jun 2016 14:30:35 +0100 Subject: [PATCH] Change observe option header behaviour to be in line with spec at the following points: 1. If the resource can't register the client as observer, or the resource does not support observe, then the resource sends back normal GET Response with NO observe option field. 2. Upon successfully removing the client from observer list, the resource sends back a normal GET response with NO observe option field 3. This patch also reverted https://gerrit.iotivity.org/gerrit/#/c/8901/ after discussed with the author to be inline with spec. JIRA issue: https://jira.iotivity.org/browse/IOT-1122 Change-Id: I36510baa69a8ef3be9e0d9aef3fbd40d31488b0f Signed-off-by: Ziran Sun Reviewed-on: https://gerrit.iotivity.org/gerrit/8815 Tested-by: jenkins-iotivity Reviewed-by: Mushfiqul Islam --- resource/csdk/stack/include/internal/ocstackinternal.h | 4 ++-- resource/csdk/stack/src/ocresource.c | 7 +++---- resource/csdk/stack/src/ocserverrequest.c | 3 ++- resource/csdk/stack/src/ocstack.c | 2 +- resource/examples/simpleclient.cpp | 12 ++++-------- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/resource/csdk/stack/include/internal/ocstackinternal.h b/resource/csdk/stack/include/internal/ocstackinternal.h index bef3e98..538c8b5 100644 --- a/resource/csdk/stack/include/internal/ocstackinternal.h +++ b/resource/csdk/stack/include/internal/ocstackinternal.h @@ -66,8 +66,8 @@ extern void* defaultDeviceHandlerCallbackParameter; /** The coap scheme */ #define OC_COAP_SCHEME "coap://" -/** the first outgoing sequence number will be 5*/ -#define OC_OFFSET_SEQUENCE_NUMBER (4) +/** the first outgoing sequence number will be 2*/ +#define OC_OFFSET_SEQUENCE_NUMBER (1) /** * This structure will be created in occoap and passed up the stack on the server side. diff --git a/resource/csdk/stack/src/ocresource.c b/resource/csdk/stack/src/ocresource.c index c51ac9e..1e72248 100755 --- a/resource/csdk/stack/src/ocresource.c +++ b/resource/csdk/stack/src/ocresource.c @@ -1103,13 +1103,13 @@ HandleResourceWithEntityHandler (OCServerRequest *request, } else { + result = OC_STACK_OK; + // The error in observeResult for the request will be used when responding to this // request by omitting the observation option/sequence number. request->observeResult = OC_STACK_ERROR; OIC_LOG(ERROR, TAG, "Observer Addition failed"); ehFlag = OC_REQUEST_FLAG; - FindAndDeleteServerRequest(request); - goto exit; } } @@ -1139,10 +1139,9 @@ HandleResourceWithEntityHandler (OCServerRequest *request, } else { + result = OC_STACK_OK; request->observeResult = OC_STACK_ERROR; OIC_LOG(ERROR, TAG, "Observer Removal failed"); - FindAndDeleteServerRequest(request); - goto exit; } } else diff --git a/resource/csdk/stack/src/ocserverrequest.c b/resource/csdk/stack/src/ocserverrequest.c index 9ee0395..27ba09f 100644 --- a/resource/csdk/stack/src/ocserverrequest.c +++ b/resource/csdk/stack/src/ocserverrequest.c @@ -555,7 +555,8 @@ OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse) memcpy(responseInfo.info.token, serverRequest->requestToken, serverRequest->tokenLength); responseInfo.info.tokenLength = serverRequest->tokenLength; - if(serverRequest->observeResult == OC_STACK_OK) + // De-register observe option should not be included in the response header + if((serverRequest->observeResult == OC_STACK_OK) && (serverRequest->observationOption != OC_OBSERVE_DEREGISTER)) { responseInfo.info.numOptions = ehResponse->numSendVendorSpecificHeaderOptions + 1; } diff --git a/resource/csdk/stack/src/ocstack.c b/resource/csdk/stack/src/ocstack.c index 902c70b..398cad3 100644 --- a/resource/csdk/stack/src/ocstack.c +++ b/resource/csdk/stack/src/ocstack.c @@ -1151,7 +1151,7 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp OCClientResponse response = {.devAddr = {.adapter = OC_DEFAULT_ADAPTER}}; - response.sequenceNumber = OC_OBSERVE_NO_OPTION; + response.sequenceNumber = -1; CopyEndpointToDevAddr(endPoint, &response.devAddr); FixUpClientResponse(&response); response.resourceUri = responseInfo->info.resourceUri; diff --git a/resource/examples/simpleclient.cpp b/resource/examples/simpleclient.cpp index 07d55f0..42c0d6f 100644 --- a/resource/examples/simpleclient.cpp +++ b/resource/examples/simpleclient.cpp @@ -65,16 +65,12 @@ void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation& re { try { - if(eCode == OC_STACK_OK && sequenceNumber != OC_OBSERVE_NO_OPTION) + if(eCode == OC_STACK_OK && sequenceNumber != -1) { if(sequenceNumber == OC_OBSERVE_REGISTER) { std::cout << "Observe registration action is successful" << std::endl; } - else if(sequenceNumber == OC_OBSERVE_DEREGISTER) - { - std::cout << "Observe De-registration action is successful" << std::endl; - } std::cout << "OBSERVE RESULT:"<