From: Ziran Sun Date: Tue, 21 Jun 2016 13:30:35 +0000 (+0100) Subject: Change observe option header behaviour to be in line with spec X-Git-Tag: 1.2.0+RC1~267 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ed9352f40b86c8d6c7e5f7732d4f68498ec69460;p=platform%2Fupstream%2Fiotivity.git 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 --- diff --git a/resource/csdk/stack/include/internal/ocstackinternal.h b/resource/csdk/stack/include/internal/ocstackinternal.h index bef3e9829..538c8b502 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 c51ac9e93..1e722488f 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 9ee039536..27ba09f29 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 902c70b86..398cad301 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 07d55f0db..42c0d6f34 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:"<