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, unsigned char * resourceType) {
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;
50 cbNode->filterResourceType = resourceType;
52 cbNode->requestUri = requestUri;
53 LL_APPEND(cbList, cbNode);
58 return OC_STACK_NO_MEMORY;
61 void DeleteClientCB(ClientCB * cbNode) {
63 LL_DELETE(cbList, cbNode);
64 OC_LOG(INFO, TAG, PCF("deleting tokens"));
65 OC_LOG_BUFFER(INFO, TAG, cbNode->token.token, cbNode->token.tokenLength);
66 OCFree(cbNode->handle);
67 OCFree(cbNode->requestUri);
68 if(cbNode->deleteCallback)
70 cbNode->deleteCallback(cbNode->context);
74 if(cbNode->presence) {
75 OCFree(cbNode->presence->timeOut);
76 OCFree(cbNode->presence);
77 OCFree(cbNode->filterResourceType);
85 ClientCB* GetClientCB(OCCoAPToken * token, OCDoHandle handle, unsigned char * requestUri) {
88 LL_FOREACH(cbList, out) {
89 OC_LOG(INFO, TAG, PCF("comparing tokens"));
90 OC_LOG_BUFFER(INFO, TAG, token->token, token->tokenLength);
91 OC_LOG_BUFFER(INFO, TAG, out->token.token, out->token.tokenLength);
92 if((out->token.tokenLength == token->tokenLength) &&
93 (memcmp(out->token.token, token->token, token->tokenLength) == 0) ) {
99 LL_FOREACH(cbList, out) {
100 if(out->handle == handle) {
105 else if(requestUri) {
106 LL_FOREACH(cbList, out) {
107 if(out->requestUri && strcmp((char *)out->requestUri, (char *)requestUri) == 0) {
112 OC_LOG(INFO, TAG, PCF("Callback Not found !!"));
117 void DeleteClientCBList() {
120 LL_FOREACH_SAFE(cbList, out, tmp) {
126 void FindAndDeleteClientCB(ClientCB * cbNode) {
130 LL_FOREACH(cbList, tmp)
141 OCStackResult AddMCPresenceNode(OCMulticastNode** outnode, unsigned char* uri, uint32_t nonce)
143 OCMulticastNode *node;
145 node = (OCMulticastNode*) OCMalloc(sizeof(OCMulticastNode));
150 LL_APPEND(mcPresenceNodes, node);
155 return OC_STACK_NO_MEMORY;
158 OCMulticastNode* GetMCPresenceNode(unsigned char * uri) {
159 OCMulticastNode* out = NULL;
162 LL_FOREACH(mcPresenceNodes, out) {
163 if(out->uri && strcmp((char *)out->uri, (char *)uri) == 0) {
168 OC_LOG(INFO, TAG, PCF("MulticastNode Not found !!"));