//-----------------------------------------------------------------------------
#include "ocstack.h"
#include "ocstackinternal.h"
-#include "ocresource.h"
+#include "ocresourcehandler.h"
#include "occlientcb.h"
#include "ocobserve.h"
#include "ocrandom.h"
return OC_STACK_ERROR;
}
+ #ifdef WITH_PRESENCE
+ // Ensure that the TTL associated with ANY and ALL presence notifications originating from
+ // here send with the code "OC_STACK_PRESENCE_STOPPED" result.
+ presenceResource.presenceTTL = 0;
+ #endif // WITH_PRESENCE
+
// Free memory dynamically allocated for resources
deleteAllResources();
ClientCB *clientCB = NULL;
unsigned char * requestUri = NULL;
unsigned char * resourceType = NULL;
- char * newURI = (char *)requiredUri;
+ char * newUri = (char *)requiredUri;
(void) referenceUri;
OC_LOG(INFO, TAG, PCF("Entering OCDoResource"));
#ifdef WITH_PRESENCE
if(method == OC_REST_PRESENCE)
{
- result = getResourceType(requiredUri, &resourceType, &newURI);
+ result = getResourceType(requiredUri, &resourceType, &newUri);
+ if(resourceType) {
+ OC_LOG_V(DEBUG, TAG, "Got Resource Type: %s", resourceType);
+ }
+ else
+ {
+ OC_LOG(DEBUG, TAG, "Got Resource Type is NULL.");
+ }
if(result != OC_STACK_OK)
{
goto exit;
requestUri = (unsigned char *) OCMalloc(uriLen + 1);
if(requestUri)
{
- memcpy(requestUri, newURI, (uriLen + 1));
+ memcpy(requestUri, newUri, (uriLen + 1));
}
else
{
// with the request
OCGenerateCoAPToken(&token);
- if((result = AddClientCB(&clientCB, cbData, &token, *handle, method, requestUri, resourceType))
+ if((result = AddClientCB(&clientCB, cbData, &token, handle, method, requestUri, resourceType))
!= OC_STACK_OK)
{
result = OC_STACK_NO_MEMORY;
}
// Make call to OCCoAP layer
- result = OCDoCoAPResource(method, qos, &token, newURI, request, options, numOptions);
+ result = OCDoCoAPResource(method, qos, &token, newUri, request, options, numOptions);
exit:
- if(newURI != requiredUri)
+ if(newUri != requiredUri)
{
- OCFree(newURI);
+ OCFree(newUri);
}
if (result != OC_STACK_OK)
{
OCMethod method = OC_REST_NOMETHOD;
uint32_t maxAge = 0;
+ OC_LOG(INFO, TAG, PCF("Entering OCNotifyAllObservers"));
+ #ifdef WITH_PRESENCE
+ if(handle == presenceResource.handle)
+ {
+ return OC_STACK_OK;
+ }
+ #endif // WITH_PRESENCE
VERIFY_NON_NULL(handle, ERROR, OC_STACK_ERROR);
+
// Verify that the resource exists
resPtr = findResource ((OCResource *) handle);
- if (NULL == resPtr || myStackMode == OC_CLIENT)
+ if (NULL == resPtr)
{
return OC_STACK_NO_RESOURCE;
}
presenceResource.presenceTTL = OC_DEFAULT_PRESENCE_TTL;
//presenceResource.token = OCGenerateCoAPToken();
result = OCCreateResource(&presenceResource.handle,
- "core.presence",
+ OC_RSRVD_RESOURCE_TYPE_PRESENCE,
"core.r",
OC_PRESENCE_URI,
NULL,
while (pointer)
{
temp = pointer->next;
- deleteResource(pointer);
+ #ifdef WITH_PRESENCE
+ if(pointer != (OCResource *) presenceResource.handle)
+ {
+ #endif // WITH_PRESENCE
+ deleteResource(pointer);
+ #ifdef WITH_PRESENCE
+ }
+ #endif // WITH_PRESENCE
pointer = temp;
}
+
+ #ifdef WITH_PRESENCE
+ // Ensure that the last resource to be deleted is the presence resource. This allows for all
+ // presence notification attributed to their deletion to be processed.
+ deleteResource((OCResource *) presenceResource.handle);
+ #endif // WITH_PRESENCE
}
/**
if (temp == resource) {
// Invalidate all Resource Properties.
resource->resourceProperties = (OCResourceProperty) 0;
- OCNotifyAllObservers((OCResourceHandle)resource, OC_HIGH_QOS);
-
#ifdef WITH_PRESENCE
+ if(resource != (OCResource *) presenceResource.handle)
+ {
+ #endif // WITH_PRESENCE
+ OCNotifyAllObservers((OCResourceHandle)resource, OC_HIGH_QOS);
+ #ifdef WITH_PRESENCE
+ }
+
if(presenceResource.handle)
{
((OCResource *)presenceResource.handle)->sequenceNum = OCGetRandom();
- SendPresenceNotification(resource->rsrcType);
+ if(resource != (OCResource *) presenceResource.handle)
+ {
+ SendPresenceNotification(resource->rsrcType);
+ }
+ else
+ {
+ SendPresenceNotification(NULL);
+ }
}
- #endif
+ #endif
if (temp == headResource) {
headResource = temp->next;
}
/**
+ * Finds a resource type in an OCResourceType link-list.
+ *
+ * @param resourceTypeList - the link-list to be searched through
+ * @param resourceTypeName - the key to search for
+ *
+ * @return
+ * resourceType that matches the key (ie. resourceTypeName)
+ * NULL - either an invalid parameter or this function was unable to find the key.
+ */
+OCResourceType *findResourceType(OCResourceType * resourceTypeList, const char * resourceTypeName)
+{
+ if(resourceTypeList && resourceTypeName)
+ {
+ OCResourceType * rtPointer = resourceTypeList;
+ while(resourceTypeName && rtPointer)
+ {
+ if(rtPointer->resourcetypename &&
+ strcmp(resourceTypeName, (const char *)
+ (rtPointer->resourcetypename)) == 0)
+ {
+ break;
+ }
+ rtPointer = rtPointer->next;
+ }
+ return rtPointer;
+ }
+ return NULL;
+}
+/**
* Insert a resource interface into a resource's resource interface linked list.
*
* @param resource - resource where resource interface is to be inserted
{
return OC_STACK_INVALID_PARAM;
}
- char * ptr = NULL;
char * leftToken = NULL;
- char * tempURI = (char *) OCMalloc(strlen(uri));
+ char * tempURI = (char *) OCMalloc(strlen(uri) + 1);
if(!tempURI)
{
goto exit;
}
- ptr = tempURI;
strcpy(tempURI, uri);
leftToken = strtok((char *)tempURI, "?");
leftToken = strtok(NULL, "?");
}
- *newURI = ptr;
+ *newURI = tempURI;
return OC_STACK_OK;