#include "occlientcb.h"
#include "utlist.h"
#include "logger.h"
-#include "ocmalloc.h"
+#include "oic_malloc.h"
#include <string.h>
#ifdef WITH_ARDUINO
#include "cainterface.h"
/// Module Name
-#define TAG PCF("occlientcb")
+#define TAG "occlientcb"
struct ClientCB *cbList = NULL;
static OCMulticastNode * mcPresenceNodes = NULL;
AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
CAToken_t token, uint8_t tokenLength,
OCDoHandle *handle, OCMethod method,
- char * requestUri, char * resourceTypeName, OCConnectivityType conType, uint32_t ttl)
+ OCDevAddr *devAddr, char * requestUri,
+ char * resourceTypeName, uint32_t ttl)
{
if(!clientCB || !cbData || !handle || !requestUri || tokenLength > CA_MAX_TOKEN_LEN)
{
ClientCB *cbNode = NULL;
- #ifdef WITH_PRESENCE
+#ifdef WITH_PRESENCE
if(method == OC_REST_PRESENCE)
{ // Retrieve the presence callback structure for this specific requestUri.
cbNode = GetClientCB(NULL, 0, NULL, requestUri);
}
- #endif // WITH_PRESENCE
+#endif // WITH_PRESENCE
if(!cbNode)// If it does not already exist, create new node.
{
- cbNode = (ClientCB*) OCMalloc(sizeof(ClientCB));
+ cbNode = (ClientCB*) OICMalloc(sizeof(ClientCB));
if(!cbNode)
{
*clientCB = NULL;
}
else
{
+ OC_LOG(INFO, TAG, "Adding client callback with token");
+ OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)token, tokenLength);
cbNode->callBack = cbData->cb;
cbNode->context = cbData->context;
cbNode->deleteCallback = cbData->cd;
{
cbNode->TTL = ttl;
}
- cbNode->requestUri = requestUri;
- cbNode->conType = conType;
+ cbNode->requestUri = requestUri; // I own it now
+ cbNode->devAddr = devAddr; // I own it now
+ OC_LOG_V(INFO, TAG, "Added Callback for uri : %s", requestUri);
LL_APPEND(cbList, cbNode);
*clientCB = cbNode;
}
cbData->cd(cbData->context);
}
- OCFree(token);
- OCFree(*handle);
- OCFree(requestUri);
+ OICFree(token);
+ OICFree(*handle);
+ OICFree(requestUri);
+ OICFree(devAddr);
*handle = cbNode->handle;
}
- #ifdef WITH_PRESENCE
+#ifdef WITH_PRESENCE
if(method == OC_REST_PRESENCE && resourceTypeName)
{
// Amend the found or created node by adding a new resourceType to it.
return InsertResourceTypeFilter(cbNode,(char *)resourceTypeName);
+ // I own resourceTypName now.
}
else
{
- OCFree(resourceTypeName);
+ OICFree(resourceTypeName);
}
- #else
- OCFree(resourceTypeName);
- #endif
+#else
+ OICFree(resourceTypeName);
+#endif
return OC_STACK_OK;
- exit:
- return OC_STACK_NO_MEMORY;
+exit:
+ return OC_STACK_NO_MEMORY;
}
void DeleteClientCB(ClientCB * cbNode)
if(cbNode)
{
LL_DELETE(cbList, cbNode);
- OC_LOG(INFO, TAG, PCF("deleting tokens"));
+ OC_LOG (INFO, TAG, "Deleting token");
OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)cbNode->token, cbNode->tokenLength);
CADestroyToken (cbNode->token);
- OCFree(cbNode->handle);
- OCFree(cbNode->requestUri);
+ OICFree(cbNode->devAddr);
+ OICFree(cbNode->handle);
+ OC_LOG_V (INFO, TAG, "Deleting callback with uri %s", cbNode->requestUri);
+ OICFree(cbNode->requestUri);
if(cbNode->deleteCallback)
{
cbNode->deleteCallback(cbNode->context);
}
- #ifdef WITH_PRESENCE
+#ifdef WITH_PRESENCE
if(cbNode->presence)
{
- OCFree(cbNode->presence->timeOut);
- OCFree(cbNode->presence);
+ OICFree(cbNode->presence->timeOut);
+ OICFree(cbNode->presence);
}
if(cbNode->method == OC_REST_PRESENCE)
{
while(pointer)
{
next = pointer->next;
- OCFree(pointer->resourcetypename);
- OCFree(pointer);
+ OICFree(pointer->resourcetypename);
+ OICFree(pointer);
pointer = next;
}
}
- #endif // WITH_PRESENCE
- OCFree(cbNode);
+#endif // WITH_PRESENCE
+ OICFree(cbNode);
cbNode = NULL;
}
}
if (cbNode->TTL < now)
{
- OC_LOG(INFO, TAG, PCF("Deleting timed-out callback"));
+ OC_LOG(INFO, TAG, "Deleting timed-out callback");
DeleteClientCB(cbNode);
}
}
if(token && *token && tokenLength <= CA_MAX_TOKEN_LEN && tokenLength > 0)
{
+ OC_LOG (INFO, TAG, "Looking for token");
+ OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)token, tokenLength);
+ OC_LOG(INFO, TAG, "\tFound in callback list");
LL_FOREACH(cbList, out)
{
- OC_LOG(INFO, TAG, PCF("comparing tokens"));
- OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)token, tokenLength);
OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)out->token, tokenLength);
if(memcmp(out->token, token, tokenLength) == 0)
}
else if(requestUri)
{
+ OC_LOG_V(INFO, TAG, "Looking for uri %s", requestUri);
LL_FOREACH(cbList, out)
{
+ OC_LOG_V(INFO, TAG, "\tFound %s", out->requestUri);
if(out->requestUri && strcmp(out->requestUri, requestUri ) == 0)
{
return out;
CheckAndDeleteTimedOutCB(out);
}
}
- OC_LOG(INFO, TAG, PCF("Callback Not found !!"));
+ OC_LOG(INFO, TAG, "Callback Not found !!");
return NULL;
}
if(cbNode && resourceTypeName)
{
// Form a new resourceType member.
- newResourceType = (OCResourceType *) OCMalloc(sizeof(OCResourceType));
+ newResourceType = (OCResourceType *) OICMalloc(sizeof(OCResourceType));
if(!newResourceType)
{
return OC_STACK_NO_MEMORY;
OCMulticastNode *node;
- node = (OCMulticastNode*) OCMalloc(sizeof(OCMulticastNode));
+ node = (OCMulticastNode*) OICMalloc(sizeof(OCMulticastNode));
if (node)
{
}
}
}
- OC_LOG(INFO, TAG, PCF("MulticastNode Not found !!"));
+ OC_LOG(INFO, TAG, "MulticastNode Not found !!");
return NULL;
}