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;
34 OCStackResult AddClientCB(ClientCB** clientCB, OCCallbackData* cbData,
35 OCCoAPToken * token, OCDoHandle handle, OCMethod method,
36 unsigned char * requestUri) {
38 cbNode = (ClientCB*) OCMalloc(sizeof(ClientCB));
40 cbNode->callBack = cbData->cb;
41 cbNode->context = cbData->context;
42 cbNode->deleteCallback = cbData->cd;
43 memcpy(&(cbNode->token), token, sizeof(OCCoAPToken));
44 cbNode->handle = handle;
45 cbNode->method = method;
46 cbNode->sequenceNumber = 0;
48 cbNode->presence = NULL;
50 cbNode->requestUri = requestUri;
51 LL_APPEND(cbList, cbNode);
56 return OC_STACK_NO_MEMORY;
59 void DeleteClientCB(ClientCB * cbNode) {
61 LL_DELETE(cbList, cbNode);
62 OC_LOG(INFO, TAG, PCF("deleting tokens"));
63 OC_LOG_BUFFER(INFO, TAG, cbNode->token.token, cbNode->token.tokenLength);
64 OCFree(cbNode->handle);
65 OCFree(cbNode->requestUri);
66 if(cbNode->deleteCallback)
68 cbNode->deleteCallback(cbNode->context);
72 if(cbNode->presence) {
73 OCFree(cbNode->presence->timeOut);
74 OCFree(cbNode->presence);
82 ClientCB* GetClientCB(OCCoAPToken * token, OCDoHandle handle, unsigned char * requestUri) {
85 LL_FOREACH(cbList, out) {
86 OC_LOG(INFO, TAG, PCF("comparing tokens"));
87 OC_LOG_BUFFER(INFO, TAG, token->token, token->tokenLength);
88 OC_LOG_BUFFER(INFO, TAG, out->token.token, out->token.tokenLength);
89 if((out->token.tokenLength == token->tokenLength) &&
90 (memcmp(out->token.token, token->token, token->tokenLength) == 0) ) {
96 LL_FOREACH(cbList, out) {
97 if(out->handle == handle) {
102 else if(requestUri) {
103 LL_FOREACH(cbList, out) {
104 if(out->requestUri && strcmp((char *)out->requestUri, (char *)requestUri) == 0) {
109 OC_LOG(INFO, TAG, PCF("Callback Not found !!"));
114 void DeleteClientCBList() {
117 LL_FOREACH_SAFE(cbList, out, tmp) {
123 void FindAndDeleteClientCB(ClientCB * cbNode) {
127 LL_FOREACH(cbList, tmp)