Commit ffad5c66 authored by Jaewook Jung's avatar Jaewook Jung Committed by Ashok Babu Channa

Modify the location of HandleVirtualObserveRequest()

Since HandleVirtualObserveRequest() is called by only ocresource.c,
it is not needed to be in ocobserve.
So I moved it to ocresource.c as a static function.

Change-Id: Iadc6fc7587b10b1250c4325653a63464162836f2
Signed-off-by: default avatarJaewook Jung <jw0213.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20383Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarDan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-by: default avatarHyuna Jo <hyuna0213.jo@samsung.com>
Reviewed-by: default avatarAshok Babu Channa <ashok.channa@samsung.com>
parent 5fb0d343
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#ifndef OC_OBSERVE_H #ifndef OC_OBSERVE_H
#define OC_OBSERVE_H #define OC_OBSERVE_H
#include "ocserverrequest.h"
/** Maximum number of observers to reach */ /** Maximum number of observers to reach */
...@@ -263,18 +262,5 @@ GetObserveHeaderOption (uint32_t * observationOption, ...@@ -263,18 +262,5 @@ GetObserveHeaderOption (uint32_t * observationOption,
CAHeaderOption_t *options, CAHeaderOption_t *options,
uint8_t * numOptions); uint8_t * numOptions);
/**
* Handle registering/deregistering of observers of virtual resources. Currently only the
* well-known virtual resource (/oic/res) may be observable.
*
* @param request a virtual resource server request
*
* @return ::OC_STACK_OK on success, ::OC_STACK_DUPLICATE_REQUEST when registering a duplicate
* observer, some other value upon failure.
*/
OCStackResult
HandleVirtualObserveRequest(OCServerRequest *request);
#endif //OC_OBSERVE_H #endif //OC_OBSERVE_H
...@@ -663,95 +663,3 @@ GetObserveHeaderOption (uint32_t * observationOption, ...@@ -663,95 +663,3 @@ GetObserveHeaderOption (uint32_t * observationOption,
} }
return OC_STACK_OK; return OC_STACK_OK;
} }
OCStackResult
HandleVirtualObserveRequest(OCServerRequest *request)
{
OCStackResult result = OC_STACK_OK;
if (request->notificationFlag)
{
// The request is to send an observe payload, not register/deregister an observer
goto exit;
}
OCVirtualResources virtualUriInRequest;
virtualUriInRequest = GetTypeOfVirtualURI(request->resourceUrl);
if (virtualUriInRequest != OC_WELL_KNOWN_URI)
{
// OC_WELL_KNOWN_URI is currently the only virtual resource that may be observed
goto exit;
}
OCResource *resourcePtr;
resourcePtr = FindResourceByUri(OC_RSRVD_WELL_KNOWN_URI);
if (NULL == resourcePtr)
{
OIC_LOG(FATAL, TAG, "Well-known URI not found.");
result = OC_STACK_ERROR;
goto exit;
}
if (request->observationOption == OC_OBSERVE_REGISTER)
{
OIC_LOG(INFO, TAG, "Observation registration requested");
ResourceObserver *obs = GetObserverUsingToken (request->requestToken,
request->tokenLength);
if (obs)
{
OIC_LOG (INFO, TAG, "Observer with this token already present");
OIC_LOG (INFO, TAG, "Possibly re-transmitted CON OBS request");
OIC_LOG (INFO, TAG, "Not adding observer. Not responding to client");
OIC_LOG (INFO, TAG, "The first request for this token is already ACKED.");
result = OC_STACK_DUPLICATE_REQUEST;
goto exit;
}
OCObservationId obsId;
result = GenerateObserverId(&obsId);
if (result == OC_STACK_OK)
{
result = AddObserver ((const char*)(request->resourceUrl),
(const char *)(request->query),
obsId, request->requestToken, request->tokenLength,
resourcePtr, request->qos, request->acceptFormat,
request->acceptVersion, &request->devAddr);
}
if (result == OC_STACK_OK)
{
OIC_LOG(INFO, TAG, "Added observer successfully");
request->observeResult = OC_STACK_OK;
}
else if (result == OC_STACK_RESOURCE_ERROR)
{
OIC_LOG(INFO, TAG, "The Resource is not active, discoverable or observable");
request->observeResult = OC_STACK_ERROR;
}
else
{
// 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");
}
}
else if (request->observationOption == OC_OBSERVE_DEREGISTER)
{
OIC_LOG(INFO, TAG, "Deregistering observation requested");
result = DeleteObserverUsingToken (request->requestToken, request->tokenLength);
if (result == OC_STACK_OK)
{
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
{
request->observeResult = OC_STACK_ERROR;
OIC_LOG(ERROR, TAG, "Observer Removal failed");
}
}
// Whether the observe request succeeded or failed, the request is processed as normal
// and excludes/includes the OBSERVE option depending on request->observeResult
result = OC_STACK_OK;
exit:
return result;
}
...@@ -1746,6 +1746,106 @@ static bool isUnicast(OCServerRequest *request) ...@@ -1746,6 +1746,106 @@ static bool isUnicast(OCServerRequest *request)
(request->devAddr.adapter != OC_ADAPTER_GATT_BTLE)); (request->devAddr.adapter != OC_ADAPTER_GATT_BTLE));
} }
/**
* Handle registering/deregistering of observers of virtual resources. Currently only the
* well-known virtual resource (/oic/res) may be observable.
*
* @param request a virtual resource server request
*
* @return ::OC_STACK_OK on success, ::OC_STACK_DUPLICATE_REQUEST when registering a duplicate
* observer, some other value upon failure.
*/
static OCStackResult HandleVirtualObserveRequest(OCServerRequest *request)
{
OCStackResult result = OC_STACK_OK;
if (request->notificationFlag)
{
// The request is to send an observe payload, not register/deregister an observer
goto exit;
}
OCVirtualResources virtualUriInRequest;
virtualUriInRequest = GetTypeOfVirtualURI(request->resourceUrl);
if (virtualUriInRequest != OC_WELL_KNOWN_URI)
{
// OC_WELL_KNOWN_URI is currently the only virtual resource that may be observed
goto exit;
}
OCResource *resourcePtr;
resourcePtr = FindResourceByUri(OC_RSRVD_WELL_KNOWN_URI);
if (NULL == resourcePtr)
{
OIC_LOG(FATAL, TAG, "Well-known URI not found.");
result = OC_STACK_ERROR;
goto exit;
}
if (request->observationOption == OC_OBSERVE_REGISTER)
{
OIC_LOG(INFO, TAG, "Observation registration requested");
ResourceObserver *obs = GetObserverUsingToken (request->requestToken,
request->tokenLength);
if (obs)
{
OIC_LOG (INFO, TAG, "Observer with this token already present");
OIC_LOG (INFO, TAG, "Possibly re-transmitted CON OBS request");
OIC_LOG (INFO, TAG, "Not adding observer. Not responding to client");
OIC_LOG (INFO, TAG, "The first request for this token is already ACKED.");
result = OC_STACK_DUPLICATE_REQUEST;
goto exit;
}
OCObservationId obsId;
result = GenerateObserverId(&obsId);
if (result == OC_STACK_OK)
{
result = AddObserver ((const char*)(request->resourceUrl),
(const char *)(request->query),
obsId, request->requestToken, request->tokenLength,
resourcePtr, request->qos, request->acceptFormat,
request->acceptVersion, &request->devAddr);
}
if (result == OC_STACK_OK)
{
OIC_LOG(INFO, TAG, "Added observer successfully");
request->observeResult = OC_STACK_OK;
}
else if (result == OC_STACK_RESOURCE_ERROR)
{
OIC_LOG(INFO, TAG, "The Resource is not active, discoverable or observable");
request->observeResult = OC_STACK_ERROR;
}
else
{
// 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");
}
}
else if (request->observationOption == OC_OBSERVE_DEREGISTER)
{
OIC_LOG(INFO, TAG, "Deregistering observation requested");
result = DeleteObserverUsingToken (request->requestToken, request->tokenLength);
if (result == OC_STACK_OK)
{
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
{
request->observeResult = OC_STACK_ERROR;
OIC_LOG(ERROR, TAG, "Observer Removal failed");
}
}
// Whether the observe request succeeded or failed, the request is processed as normal
// and excludes/includes the OBSERVE option depending on request->observeResult
result = OC_STACK_OK;
exit:
return result;
}
static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource* resource) static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource* resource)
{ {
if (!request || !resource) if (!request || !resource)
......
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