1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 #include "occlientcb.h"
30 #define TAG PCF("occlientcb")
32 struct ClientCB *cbList = NULL;
33 OCMulticastNode * mcPresenceNodes = NULL;
35 OCStackResult AddClientCB(ClientCB** clientCB, OCCallbackData* cbData,
36 OCCoAPToken * token, OCDoHandle handle, OCMethod method,
37 unsigned char * requestUri) {
39 cbNode = (ClientCB*) OCMalloc(sizeof(ClientCB));
41 cbNode->callBack = cbData->cb;
42 cbNode->context = cbData->context;
43 cbNode->deleteCallback = cbData->cd;
44 memcpy(&(cbNode->token), token, sizeof(OCCoAPToken));
45 cbNode->handle = handle;
46 cbNode->method = method;
47 cbNode->sequenceNumber = 0;
49 cbNode->presence = NULL;
51 cbNode->requestUri = requestUri;
52 LL_APPEND(cbList, cbNode);
57 return OC_STACK_NO_MEMORY;
60 void DeleteClientCB(ClientCB * cbNode) {
62 LL_DELETE(cbList, cbNode);
63 OC_LOG(INFO, TAG, PCF("deleting tokens"));
64 OC_LOG_BUFFER(INFO, TAG, cbNode->token.token, cbNode->token.tokenLength);
65 OCFree(cbNode->handle);
66 OCFree(cbNode->requestUri);
67 if(cbNode->deleteCallback)
69 cbNode->deleteCallback(cbNode->context);
73 if(cbNode->presence) {
74 OCFree(cbNode->presence->timeOut);
75 OCFree(cbNode->presence);
83 ClientCB* GetClientCB(OCCoAPToken * token, OCDoHandle handle, unsigned char * requestUri) {
86 LL_FOREACH(cbList, out) {
87 OC_LOG(INFO, TAG, PCF("comparing tokens"));
88 OC_LOG_BUFFER(INFO, TAG, token->token, token->tokenLength);
89 OC_LOG_BUFFER(INFO, TAG, out->token.token, out->token.tokenLength);
90 if((out->token.tokenLength == token->tokenLength) &&
91 (memcmp(out->token.token, token->token, token->tokenLength) == 0) ) {
97 LL_FOREACH(cbList, out) {
98 if(out->handle == handle) {
103 else if(requestUri) {
104 LL_FOREACH(cbList, out) {
105 if(out->requestUri && strcmp((char *)out->requestUri, (char *)requestUri) == 0) {
110 OC_LOG(INFO, TAG, PCF("Callback Not found !!"));
115 void DeleteClientCBList() {
118 LL_FOREACH_SAFE(cbList, out, tmp) {
124 void FindAndDeleteClientCB(ClientCB * cbNode) {
128 LL_FOREACH(cbList, tmp)
139 OCStackResult AddMCPresenceNode(OCMulticastNode** outnode, unsigned char* uri, uint32_t nonce)
141 OCMulticastNode *node;
143 node = (OCMulticastNode*) OCMalloc(sizeof(OCMulticastNode));
148 LL_APPEND(mcPresenceNodes, node);
153 return OC_STACK_NO_MEMORY;
156 OCMulticastNode* GetMCPresenceNode(unsigned char * uri) {
157 OCMulticastNode* out = NULL;
160 LL_FOREACH(mcPresenceNodes, out) {
161 if(out->uri && strcmp((char *)out->uri, (char *)uri) == 0) {
166 OC_LOG(INFO, TAG, PCF("MulticastNode Not found !!"));