From 954a3da8b97dda0f992b1ab52b06da3ff702864e Mon Sep 17 00:00:00 2001 From: "jaesick.shin" Date: Tue, 18 Oct 2016 09:44:48 +0900 Subject: [PATCH] modify about rule of coding. this patch include, 1. modify if statement and while statement about rule of coding. 2. remove unused function. Change-Id: I73117fcc15581dfaff435cd5922f14c91356c358 Signed-off-by: jaesick.shin Reviewed-on: https://gerrit.iotivity.org/gerrit/13357 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- service/notification/include/NSCommon.h | 1 + service/notification/src/common/NSConstants.h | 4 ++ service/notification/src/common/NSStructs.h | 10 ++++ service/notification/src/common/NSUtil.c | 56 +++++++++------------- .../src/provider/NSProviderCallbackResponse.c | 3 +- .../src/provider/NSProviderDiscovery.c | 2 +- .../src/provider/NSProviderInterface.c | 15 +++--- .../notification/src/provider/NSProviderListener.c | 24 +++++----- .../src/provider/NSProviderMemoryCache.c | 53 +++++++++++--------- .../src/provider/NSProviderNotification.c | 22 ++++----- .../notification/src/provider/NSProviderResource.c | 14 +++--- .../src/provider/NSProviderScheduler.c | 7 +-- .../src/provider/NSProviderSubscription.c | 25 +++++----- .../notification/src/provider/NSProviderSystem.c | 16 ++++--- .../notification/src/provider/NSProviderTopic.c | 20 +++++--- 15 files changed, 151 insertions(+), 121 deletions(-) diff --git a/service/notification/include/NSCommon.h b/service/notification/include/NSCommon.h index be47df4..9f6e35c 100644 --- a/service/notification/include/NSCommon.h +++ b/service/notification/include/NSCommon.h @@ -54,6 +54,7 @@ typedef enum NS_TOPIC = 3, NS_DISCOVERED = 11, NS_STOPPED = 12 + } NSProviderState; /** diff --git a/service/notification/src/common/NSConstants.h b/service/notification/src/common/NSConstants.h index cbfca9a..983f2a3 100644 --- a/service/notification/src/common/NSConstants.h +++ b/service/notification/src/common/NSConstants.h @@ -220,6 +220,7 @@ typedef enum eSchedulerType SUBSCRIPTION_SCHEDULER = 2, NOTIFICATION_SCHEDULER = 3, TOPIC_SCHEDULER = 4, + } NSSchedulerType; typedef enum eTaskType @@ -300,6 +301,7 @@ typedef enum eCacheType NS_CONSUMER_CACHE_PROVIDER = 2000, NS_CONSUMER_CACHE_MESSAGE = 2001, + } NSCacheType; typedef enum eResourceType @@ -307,12 +309,14 @@ typedef enum eResourceType NS_RESOURCE_MESSAGE = 1000, NS_RESOURCE_SYNC = 1001, NS_RESOURCE_TOPIC = 1002, + } NSResourceType; typedef enum eInterfaceType { NS_INTERFACE_TYPE_READ = 1, NS_INTERFACE_TYPE_READWRITE = 2, + } NSInterfaceType; #endif /* _NS_CONSTANTS_H_ */ diff --git a/service/notification/src/common/NSStructs.h b/service/notification/src/common/NSStructs.h index bb9a15f..ceb84a3 100644 --- a/service/notification/src/common/NSStructs.h +++ b/service/notification/src/common/NSStructs.h @@ -35,6 +35,7 @@ typedef struct _nsTask NSTaskType taskType; void * taskData; struct _nsTask * nextTask; + } NSTask; typedef struct @@ -52,6 +53,7 @@ typedef struct _NSCacheElement { NSCacheData * data; struct _NSCacheElement * next; + } NSCacheElement; typedef struct @@ -59,6 +61,7 @@ typedef struct NSCacheType cacheType; NSCacheElement * head; NSCacheElement * tail; + } NSCacheList; typedef struct @@ -69,6 +72,7 @@ typedef struct int remote_syncObId; //sync observer ID subscribed through remote server int remote_messageObId; //message observer ID subscribed through remote server bool isWhite; // access state -> True: allowed / False: blocked + } NSCacheSubData; typedef struct @@ -76,6 +80,7 @@ typedef struct char * id; int messageType; // noti = 1, read = 2, dismiss = 3 NSMessage * nsMessage; + } NSCacheMsgData; typedef struct @@ -103,6 +108,7 @@ typedef struct //optional char * topic_uri; + } NSNotificationResource; typedef struct @@ -121,6 +127,7 @@ typedef struct char * sourceName; char * topicName; NSMediaContents * mediaContents; + } NSMessageResource; typedef struct @@ -129,6 +136,7 @@ typedef struct char * id; char providerId[NS_UUID_STRING_SIZE]; char * state; + } NSSyncResource; typedef struct @@ -137,6 +145,7 @@ typedef struct char providerId[NS_UUID_STRING_SIZE]; char consumerId[NS_UUID_STRING_SIZE]; NSTopicList ** TopicList; + } NSTopicResource; typedef struct @@ -144,6 +153,7 @@ typedef struct char providerId[NS_UUID_STRING_SIZE]; char * providerName; char * userInfo; + } NSProviderInfo; #endif /* _NS_STRUCTS_H_ */ diff --git a/service/notification/src/common/NSUtil.c b/service/notification/src/common/NSUtil.c index 14ca14b..2789366 100755 --- a/service/notification/src/common/NSUtil.c +++ b/service/notification/src/common/NSUtil.c @@ -35,7 +35,7 @@ OCEntityHandlerRequest *NSCopyOCEntityHandlerRequest(OCEntityHandlerRequest *ent if (copyOfRequest->query) { copyOfRequest->query = OICStrdup(entityHandlerRequest->query); - if(!copyOfRequest->query) + if (!copyOfRequest->query) { NS_LOG(ERROR, "Copy failed due to allocation failure"); OICFree(copyOfRequest); @@ -107,7 +107,7 @@ NSMessage * NSDuplicateMessage(NSMessage * copyMsg) { NSMessage * newMsg = NULL; - if(copyMsg == NULL) + if (copyMsg == NULL) { NS_LOG(ERROR, "Copy Msg is NULL"); return NULL; @@ -119,7 +119,7 @@ NSMessage * NSDuplicateMessage(NSMessage * copyMsg) newMsg->messageId = copyMsg->messageId; OICStrcpy(newMsg->providerId, UUID_STRING_SIZE, copyMsg->providerId); - if(copyMsg->dateTime) + if (copyMsg->dateTime) { newMsg->dateTime = OICStrdup(copyMsg->dateTime); } @@ -175,7 +175,7 @@ NSSyncInfo* NSDuplicateSync(NSSyncInfo * copyMsg) { NSSyncInfo * newMsg = NULL; - if(!copyMsg) + if (!copyMsg) { NS_LOG(ERROR, "Copy Msg is NULL"); return NULL; @@ -183,7 +183,7 @@ NSSyncInfo* NSDuplicateSync(NSSyncInfo * copyMsg) newMsg = (NSSyncInfo *)OICMalloc(sizeof(NSSyncInfo)); - if(!newMsg) + if (!newMsg) { NS_LOG(ERROR, "newMsg is NULL"); return NULL; @@ -215,7 +215,7 @@ NSConsumer* NSDuplicateConsumer(NSConsumer * copyMsg) { NSConsumer * newMsg = NULL; - if(copyMsg == NULL) + if (copyMsg == NULL) { NS_LOG(ERROR, "Copy Msg is NULL"); return NULL; @@ -223,7 +223,7 @@ NSConsumer* NSDuplicateConsumer(NSConsumer * copyMsg) newMsg = (NSConsumer *)OICMalloc(sizeof(NSConsumer)); - if(!newMsg) + if (!newMsg) { NS_LOG(ERROR, "newMsg is NULL"); return NULL; @@ -239,7 +239,7 @@ NSConsumer* NSDuplicateConsumer(NSConsumer * copyMsg) void NSDuplicateSetPropertyString(OCRepPayload** msgPayload, const char * name, const char * copyString) { - if(copyString) + if (copyString) { OCRepPayloadSetPropString(*msgPayload, name, copyString); } @@ -248,7 +248,7 @@ void NSDuplicateSetPropertyString(OCRepPayload** msgPayload, const char * name, void NSDuplicateSetPropertyInt(OCRepPayload** msgPayload, const char * name, int64_t value) { - if(value) + if (value) { OCRepPayloadSetPropInt(*msgPayload, name, value); } @@ -260,11 +260,13 @@ NSSyncInfo * NSGetSyncInfo(OCPayload * payload) char * providerId = NULL; int64_t state = 0; - if(!payload) + if (!payload) { return NULL; } + NSSyncInfo * retSync = (NSSyncInfo *)OICMalloc(sizeof(NSSyncInfo)); + if (!retSync) { return NULL; @@ -272,8 +274,8 @@ NSSyncInfo * NSGetSyncInfo(OCPayload * payload) retSync->messageId = 0; retSync->state = NS_SYNC_READ; - OCRepPayload * repPayload = (OCRepPayload *)payload; + if (!OCRepPayloadGetPropInt(repPayload, NS_ATTRIBUTE_MESSAGE_ID, (int64_t *)&retSync->messageId)) { @@ -329,7 +331,7 @@ char * NSGetValueFromQuery(char *query, char * compareKey) NS_LOG_V(INFO, "NS Query Params = %s", query); - if(!query || query[0] == '\0' || !strlen(query)) + if (!query || query[0] == '\0' || !strlen(query)) { NS_LOG(ERROR, "query is null or \\0 or size is 0"); return NULL; @@ -369,7 +371,7 @@ char * NSGetValueFromQuery(char *query, char * compareKey) NSResult NSFreeMalloc(char ** obj) { - if(*obj) + if (*obj) { OICFree(*obj); *obj = NULL; @@ -381,20 +383,20 @@ NSResult NSFreeMalloc(char ** obj) NSMediaContents * NSDuplicateMediaContents(NSMediaContents * copyObj) { - if(!copyObj) + if (!copyObj) { return NULL; } NSMediaContents * newObj = (NSMediaContents *)OICMalloc(sizeof(NSMediaContents)); - if(!newObj) + if (!newObj) { NS_LOG(ERROR, "contents newObj is NULL"); return NULL; } - if(copyObj->iconImage) + if (copyObj->iconImage) { newObj->iconImage = OICStrdup(copyObj->iconImage); } @@ -404,7 +406,7 @@ NSMediaContents * NSDuplicateMediaContents(NSMediaContents * copyObj) NSResult NSFreeMediaContents(NSMediaContents * obj) { - if(!obj) + if (!obj) { return NS_FAIL; } @@ -419,7 +421,7 @@ NSMessage * NSInitializeMessage() { NSMessage * msg = (NSMessage *)OICMalloc(sizeof(NSMessage)); - if(!msg) + if (!msg) { NS_LOG(ERROR, "Msg is NULL"); return NULL; @@ -449,7 +451,8 @@ OCRepPayloadValue* NSPayloadFindValue(const OCRepPayload* payload, const char* n } OCRepPayloadValue* val = payload->values; - while(val) + + while (val) { if (0 == strcmp(val->name, name)) { @@ -465,7 +468,7 @@ NSTopicList * NSInitializeTopicList() { NSTopicList * topicList = (NSTopicList *)OICMalloc(sizeof(NSTopicList)); - if(!topicList) + if (!topicList) { NS_LOG(ERROR, "topicList is NULL"); return NULL; @@ -478,16 +481,3 @@ NSTopicList * NSInitializeTopicList() return topicList; } -NSResult NSFreeTopicList(NSTopicList * topicList) -{ - if (!topicList) - { - return NS_ERROR; - } - - //TODO:Free Topic List - - - return NS_OK; -} - diff --git a/service/notification/src/provider/NSProviderCallbackResponse.c b/service/notification/src/provider/NSProviderCallbackResponse.c index e079f8c..6c60c04 100644 --- a/service/notification/src/provider/NSProviderCallbackResponse.c +++ b/service/notification/src/provider/NSProviderCallbackResponse.c @@ -93,11 +93,12 @@ void * NSCallbackResponseSchedule(void * ptr) char * copyQuery = OICStrdup(request->query); char * consumerId = NSGetValueFromQuery(copyQuery, NS_QUERY_CONSUMER_ID); - if(consumerId) + if (consumerId) { OICStrcpy(consumer->consumerId, UUID_STRING_SIZE, consumerId); NSSubscribeRequestCb(consumer); } + OICFree(copyQuery); NSFreeConsumer(consumer); NSFreeOCEntityHandlerRequest(request); diff --git a/service/notification/src/provider/NSProviderDiscovery.c b/service/notification/src/provider/NSProviderDiscovery.c index 81b5903..2ff973b 100644 --- a/service/notification/src/provider/NSProviderDiscovery.c +++ b/service/notification/src/provider/NSProviderDiscovery.c @@ -79,7 +79,7 @@ void * NSDiscoverySchedule(void * ptr) NS_LOG(DEBUG, "CASE TASK_REGISTER_RESOURCE : "); NSRegisterResource(); break; -#if(defined WITH_CLOUD && defined RD_CLIENT) +#if (defined WITH_CLOUD && defined RD_CLIENT) case TASK_PUBLISH_RESOURCE: NS_LOG(DEBUG, "CASE TASK_PUBLISH_PESOURCE : "); NSPublishResourceToCloud((char*)node->taskData); diff --git a/service/notification/src/provider/NSProviderInterface.c b/service/notification/src/provider/NSProviderInterface.c index 84c3809..7adad28 100644 --- a/service/notification/src/provider/NSProviderInterface.c +++ b/service/notification/src/provider/NSProviderInterface.c @@ -92,10 +92,11 @@ NSResult NSStartProvider(NSProviderConfig config) #ifdef SECURED NS_LOG(DEBUG, "Built with SECURED"); - if(!config.resourceSecurity) + if (!config.resourceSecurity) { NS_LOG(DEBUG, "Resource Security Off"); } + NSSetResourceSecurity(config.resourceSecurity); #endif @@ -121,7 +122,7 @@ NSResult NSStopProvider() NS_LOG(DEBUG, "NSStopProvider - IN"); pthread_mutex_lock(&nsInitMutex); - if(initProvider) + if (initProvider) { NSPushQueue(DISCOVERY_SCHEDULER, TASK_STOP_PRESENCE, NULL); NSDeinitProviderInfo(); @@ -141,16 +142,17 @@ NSResult NSStopProvider() NSResult NSProviderEnableRemoteService(char *serverAddress) { -#if(defined WITH_CLOUD && defined RD_CLIENT) +#if (defined WITH_CLOUD && defined RD_CLIENT) NS_LOG(DEBUG, "NSProviderEnableRemoteService - IN"); pthread_mutex_lock(&nsInitMutex); - if(!initProvider || !serverAddress) + if (!initProvider || !serverAddress) { NS_LOG(DEBUG, "Provider service has not been started yet"); pthread_mutex_unlock(&nsInitMutex); return NS_FAIL; } + NS_LOG_V(DEBUG, "Remote server address: %s", serverAddress); NS_LOG(DEBUG, "Request to publish resource"); NSPushQueue(DISCOVERY_SCHEDULER, TASK_PUBLISH_RESOURCE, serverAddress); @@ -167,15 +169,16 @@ NSResult NSProviderEnableRemoteService(char *serverAddress) NSResult NSProviderDisableRemoteService(char *serverAddress) { -#if(defined WITH_CLOUD && defined RD_CLIENT) +#if (defined WITH_CLOUD && defined RD_CLIENT) NS_LOG(DEBUG, "NSProviderDisableRemoteService - IN"); pthread_mutex_lock(&nsInitMutex); - if(!initProvider || !serverAddress) + if (!initProvider || !serverAddress) { NS_LOG(DEBUG, "Provider service has not been started yet"); return NS_FAIL; } + NS_LOG_V(DEBUG, "Remote server address: %s", serverAddress); NS_LOG(DEBUG, "Delete remote server info"); diff --git a/service/notification/src/provider/NSProviderListener.c b/service/notification/src/provider/NSProviderListener.c index dfd28e7..1f3723f 100644 --- a/service/notification/src/provider/NSProviderListener.c +++ b/service/notification/src/provider/NSProviderListener.c @@ -141,7 +141,7 @@ OCEntityHandlerResult NSEntityHandlerMessageCb(OCEntityHandlerFlag flag, return ehResult; } } - else if(ocObAction == OC_OBSERVE_DEREGISTER) + else if (ocObAction == OC_OBSERVE_DEREGISTER) { NS_LOG(DEBUG, "NSEntityHandlerMessageCb - OC_OBSERVE_DEREGISTER"); NS_LOG_V(DEBUG, "NSEntityHandlerMessageCb\n - " @@ -203,7 +203,7 @@ OCEntityHandlerResult NSEntityHandlerSyncCb(OCEntityHandlerFlag flag, NS_LOG(DEBUG, "NSEntityHandlerSyncCb - OC_REST_POST"); - if(NSProviderIsSyncAttributes((OCRepPayload *)entityHandlerRequest->payload)) + if (NSProviderIsSyncAttributes((OCRepPayload *)entityHandlerRequest->payload)) { NSPushQueue(NOTIFICATION_SCHEDULER, TASK_RECV_READ, NSGetSyncInfo(entityHandlerRequest->payload)); @@ -233,7 +233,7 @@ OCEntityHandlerResult NSEntityHandlerSyncCb(OCEntityHandlerFlag flag, NSPushQueue(SUBSCRIPTION_SCHEDULER, TASK_SYNC_SUBSCRIPTION, NSCopyOCEntityHandlerRequest(entityHandlerRequest)); } - else if(ocObAction == OC_OBSERVE_DEREGISTER) + else if (ocObAction == OC_OBSERVE_DEREGISTER) { NS_LOG(DEBUG, "NSEntityHandlerSyncCb - OC_OBSERVE_DEREGISTER"); NS_LOG_V(DEBUG, "NSEntityHandlerSyncCb\n - " @@ -301,7 +301,7 @@ OCEntityHandlerResult NSEntityHandlerTopicCb(OCEntityHandlerFlag flag, NS_LOG(DEBUG, "NSEntityHandlerTopicCb - OC_REST_POST"); // Accepter is provider. our service is not support sendtopiclist from OC_REST_POST // Accepter is consumer. our service is support sendtopiclist from OC_REST_POST - if(NSGetPolicy() == false && + if (NSGetPolicy() == false && NSProviderIsTopicAttributes(OCRepPayloadClone((OCRepPayload *) entityHandlerRequest->payload))) { @@ -339,7 +339,7 @@ void NSProviderConnectionStateListener(const CAEndpoint_t * info, bool connected // Start Presence NSPushQueue(DISCOVERY_SCHEDULER, TASK_START_PRESENCE, NULL); - if(info->adapter == CA_ADAPTER_TCP) + if (info->adapter == CA_ADAPTER_TCP) { NS_LOG_V(DEBUG, "TCP Connected remote address: %s:%d", info->addr, info->port); } @@ -351,7 +351,7 @@ void NSProviderConnectionStateListener(const CAEndpoint_t * info, bool connected // Set Connection State NSSetProviderConnectionState(DISCONNECTED); - if(info->adapter == CA_ADAPTER_TCP) + if (info->adapter == CA_ADAPTER_TCP) { NS_LOG_V(DEBUG, "TCP Disconnected remote address: %s:%d", info->addr, info->port); } @@ -403,14 +403,15 @@ bool NSProviderCompareSyncAttributes(const char * name) bool NSProviderIsSyncAttributes(OCRepPayload * payload) { NS_LOG(DEBUG, "get extra info"); - OCRepPayloadValue * curr = payload->values; - while(curr) + + while (curr) { if (!NSProviderCompareSyncAttributes(curr->name)) { return false; } + curr = curr->next; } @@ -442,9 +443,9 @@ bool NSProviderCompareSubTopicAttributes(const char * name) bool NSProviderIsTopicAttributes(OCRepPayload * payload) { NS_LOG(DEBUG, "get extra info"); - OCRepPayloadValue * curr = payload->values; - while(curr) + + while (curr) { if (!NSProviderCompareTopicAttributes(curr->name)) { @@ -470,7 +471,8 @@ bool NSProviderIsTopicAttributes(OCRepPayload * payload) for (int i = 0; i < (int) dimensionSize; i++) { OCRepPayloadValue * subCurr = topicListPayload[i]->values; - while(subCurr) + + while (subCurr) { if (!NSProviderCompareSubTopicAttributes(subCurr->name)) { diff --git a/service/notification/src/provider/NSProviderMemoryCache.c b/service/notification/src/provider/NSProviderMemoryCache.c index bcc0bfb..90da361 100644 --- a/service/notification/src/provider/NSProviderMemoryCache.c +++ b/service/notification/src/provider/NSProviderMemoryCache.c @@ -25,6 +25,7 @@ NSCacheList * NSProviderStorageCreate() { pthread_mutex_lock(&NSCacheMutex); NSCacheList * newList = (NSCacheList *) OICMalloc(sizeof(NSCacheList)); + if (!newList) { pthread_mutex_unlock(&NSCacheMutex); @@ -194,7 +195,7 @@ NSResult NSProviderStorageWrite(NSCacheList * list, NSCacheElement * newObj) } } - else if(type == NS_PROVIDER_CACHE_REGISTER_TOPIC) + else if (type == NS_PROVIDER_CACHE_REGISTER_TOPIC) { NS_LOG(DEBUG, "Type is REGITSTER TOPIC"); @@ -211,7 +212,7 @@ NSResult NSProviderStorageWrite(NSCacheList * list, NSCacheElement * newObj) return NS_FAIL; } } - else if(type == NS_PROVIDER_CACHE_CONSUMER_TOPIC_NAME) + else if (type == NS_PROVIDER_CACHE_CONSUMER_TOPIC_NAME) { NS_LOG(DEBUG, "Type is REGITSTER TOPIC"); @@ -228,7 +229,7 @@ NSResult NSProviderStorageWrite(NSCacheList * list, NSCacheElement * newObj) return NS_FAIL; } } - else if(type == NS_PROVIDER_CACHE_CONSUMER_TOPIC_CID) + else if (type == NS_PROVIDER_CACHE_CONSUMER_TOPIC_CID) { NS_LOG(DEBUG, "Type is REGITSTER TOPIC"); @@ -399,7 +400,7 @@ NSResult NSProviderDeleteCacheData(NSCacheType type, void * data) OICFree(subData); return NS_OK; } - else if(type == NS_PROVIDER_CACHE_REGISTER_TOPIC) + else if (type == NS_PROVIDER_CACHE_REGISTER_TOPIC) { NSCacheTopicData * topicData = (NSCacheTopicData *) data; @@ -409,7 +410,7 @@ NSResult NSProviderDeleteCacheData(NSCacheType type, void * data) OICFree(topicData->topicName); OICFree(topicData); } - else if(type == NS_PROVIDER_CACHE_CONSUMER_TOPIC_NAME || + else if (type == NS_PROVIDER_CACHE_CONSUMER_TOPIC_NAME || type == NS_PROVIDER_CACHE_CONSUMER_TOPIC_CID) { NSCacheTopicSubData * topicData = (NSCacheTopicSubData *) data; @@ -428,7 +429,7 @@ NSResult NSProviderStorageDelete(NSCacheList * list, const char * delId) NSCacheType type = list->cacheType; - if(!del) + if (!del) { NS_LOG(DEBUG, "list head is NULL"); pthread_mutex_unlock(&NSCacheMutex); @@ -453,6 +454,7 @@ NSResult NSProviderStorageDelete(NSCacheList * list, const char * delId) } del = del->next; + while (del) { if (NSProviderCompareIdCacheData(type, del->data, delId)) @@ -472,6 +474,7 @@ NSResult NSProviderStorageDelete(NSCacheList * list, const char * delId) prev = del; del = del->next; } + pthread_mutex_unlock(&NSCacheMutex); return NS_FAIL; } @@ -483,7 +486,7 @@ NSTopicLL * NSProviderGetTopicsCacheData(NSCacheList * regTopicList) NSCacheElement * iter = regTopicList->head; - if(!iter) + if (!iter) { pthread_mutex_unlock(&NSCacheMutex); return NULL; @@ -497,7 +500,8 @@ NSTopicLL * NSProviderGetTopicsCacheData(NSCacheList * regTopicList) { NSCacheTopicData * curr = (NSCacheTopicData *) iter->data; newTopic = (NSTopicLL *) OICMalloc(sizeof(NSTopicLL)); - if(!newTopic) + + if (!newTopic) { pthread_mutex_unlock(&NSCacheMutex); return NULL; @@ -507,7 +511,7 @@ NSTopicLL * NSProviderGetTopicsCacheData(NSCacheList * regTopicList) newTopic->next = NULL; newTopic->topicName = OICStrdup(curr->topicName); - if(!topics) + if (!topics) { iterTopic = topics = newTopic; } @@ -534,7 +538,7 @@ NSTopicLL * NSProviderGetConsumerTopicsCacheData(NSCacheList * regTopicList, pthread_mutex_lock(&NSCacheMutex); NSTopicLL * topics = NSProviderGetTopicsCacheData(regTopicList); - if(!topics) + if (!topics) { pthread_mutex_unlock(&NSCacheMutex); return NULL; @@ -543,23 +547,24 @@ NSTopicLL * NSProviderGetConsumerTopicsCacheData(NSCacheList * regTopicList, NSCacheElement * iter = conTopicList->head; conTopicList->cacheType = NS_PROVIDER_CACHE_CONSUMER_TOPIC_CID; - while(iter) + while (iter) { NSCacheTopicSubData * curr = (NSCacheTopicSubData *)iter->data; - if(curr && strcmp(curr->id, consumerId) == 0) + if (curr && strcmp(curr->id, consumerId) == 0) { NS_LOG_V(DEBUG, "curr->id = %s", curr->id); NS_LOG_V(DEBUG, "curr->topicName = %s", curr->topicName); - NSTopicLL * topicIter = topics; - while(topicIter) + + while (topicIter) { - if(strcmp(topicIter->topicName, curr->topicName) == 0) + if (strcmp(topicIter->topicName, curr->topicName) == 0) { topicIter->state = NS_TOPIC_SUBSCRIBED; break; } + topicIter = topicIter->next; } } @@ -578,22 +583,24 @@ bool NSProviderIsTopicSubScribed(NSCacheElement * conTopicList, char * cId, char { pthread_mutex_lock(&NSCacheMutex); - if(!conTopicList || !cId || !topicName) + if (!conTopicList || !cId || !topicName) { pthread_mutex_unlock(&NSCacheMutex); return false; } NSCacheElement * iter = conTopicList; - while(iter) + + while (iter) { NSCacheTopicSubData * curr = (NSCacheTopicSubData *) iter->data; - if( (strcmp(curr->id, cId) == 0) && (strcmp(curr->topicName, topicName) == 0) ) + if ( (strcmp(curr->id, cId) == 0) && (strcmp(curr->topicName, topicName) == 0) ) { pthread_mutex_unlock(&NSCacheMutex); return true; } + iter = iter->next; } @@ -609,7 +616,7 @@ NSResult NSProviderDeleteConsumerTopic(NSCacheList * conTopicList, char * cId = topicSubData->id; char * topicName = topicSubData->topicName; - if(!conTopicList || !cId || !topicName) + if (!conTopicList || !cId || !topicName) { pthread_mutex_unlock(&NSCacheMutex); return NS_ERROR; @@ -620,7 +627,7 @@ NSResult NSProviderDeleteConsumerTopic(NSCacheList * conTopicList, NSCacheType type = conTopicList->cacheType; - if(!del) + if (!del) { NS_LOG(DEBUG, "list head is NULL"); pthread_mutex_unlock(&NSCacheMutex); @@ -633,7 +640,7 @@ NSResult NSProviderDeleteConsumerTopic(NSCacheList * conTopicList, NS_LOG_V(DEBUG, "curr->id = %s", curr->id); NS_LOG_V(DEBUG, "curr->topicName = %s", curr->topicName); - if( (strncmp(curr->id, cId, NS_UUID_STRING_SIZE) == 0) && + if ( (strncmp(curr->id, cId, NS_UUID_STRING_SIZE) == 0) && (strcmp(curr->topicName, topicName) == 0) ) { if (del == conTopicList->head) // first object @@ -653,10 +660,11 @@ NSResult NSProviderDeleteConsumerTopic(NSCacheList * conTopicList, curr = NULL; del = del->next; + while (del) { curr = (NSCacheTopicSubData *) del->data; - if( (strncmp(curr->id, cId, NS_UUID_STRING_SIZE) == 0) && + if ( (strncmp(curr->id, cId, NS_UUID_STRING_SIZE) == 0) && (strcmp(curr->topicName, topicName) == 0) ) { if (del == conTopicList->tail) // delete object same to last object @@ -674,6 +682,7 @@ NSResult NSProviderDeleteConsumerTopic(NSCacheList * conTopicList, prev = del; del = del->next; } + pthread_mutex_unlock(&NSCacheMutex); return NS_FAIL; } diff --git a/service/notification/src/provider/NSProviderNotification.c b/service/notification/src/provider/NSProviderNotification.c index 269fe20..e84bebd 100644 --- a/service/notification/src/provider/NSProviderNotification.c +++ b/service/notification/src/provider/NSProviderNotification.c @@ -120,11 +120,11 @@ NSResult NSSendNotification(NSMessage *msg) { if(subData->messageObId != 0) { - if(msg->topic && (msg->topic)[0] != '\0') + if (msg->topic && (msg->topic)[0] != '\0') { NS_LOG_V(DEBUG, "this is topic message: %s", msg->topic); - if(NSProviderIsTopicSubScribed(consumerTopicList->head, subData->id, msg->topic)) + if (NSProviderIsTopicSubScribed(consumerTopicList->head, subData->id, msg->topic)) { obArray[obCount++] = subData->messageObId; } @@ -135,13 +135,13 @@ NSResult NSSendNotification(NSMessage *msg) } } -#if(defined WITH_CLOUD && defined RD_CLIENT) - if(subData->remote_messageObId != 0) +#if (defined WITH_CLOUD && defined RD_CLIENT) + if (subData->remote_messageObId != 0) { - if(msg->topic && (msg->topic)[0] != '\0') + if (msg->topic && (msg->topic)[0] != '\0') { NS_LOG_V(DEBUG, "this is topic message via remote server: %s", msg->topic); - if(NSProviderIsTopicSubScribed(consumerTopicList->head, subData->id, msg->topic)) + if (NSProviderIsTopicSubScribed(consumerTopicList->head, subData->id, msg->topic)) { obArray[obCount++] = subData->remote_messageObId; } @@ -152,8 +152,8 @@ NSResult NSSendNotification(NSMessage *msg) } } #endif - } + it = it->next; } @@ -164,7 +164,7 @@ NSResult NSSendNotification(NSMessage *msg) NS_LOG(DEBUG, "-------------------------------------------------------message\n"); } - if(!obCount) + if (!obCount) { NS_LOG(ERROR, "observer count is zero"); return NS_ERROR; @@ -219,13 +219,13 @@ NSResult NSSendSync(NSSyncInfo *sync) if (subData->isWhite) { - if(subData->syncObId != 0) + if (subData->syncObId != 0) { obArray[obCount++] = subData->syncObId; } -#if(defined WITH_CLOUD && defined RD_CLIENT) - if(subData->remote_syncObId != 0) +#if (defined WITH_CLOUD && defined RD_CLIENT) + if (subData->remote_syncObId != 0) { obArray[obCount++] = subData->remote_syncObId; } diff --git a/service/notification/src/provider/NSProviderResource.c b/service/notification/src/provider/NSProviderResource.c index 2520c01..7d0c979 100644 --- a/service/notification/src/provider/NSProviderResource.c +++ b/service/notification/src/provider/NSProviderResource.c @@ -27,14 +27,14 @@ NSMessageResource NotificationMessageResource; NSSyncResource NotificationSyncResource; NSTopicResource NotificationTopicResource; -#if(defined WITH_CLOUD && defined RD_CLIENT) +#if (defined WITH_CLOUD && defined RD_CLIENT) #define DEFAULT_CONTEXT_VALUE 0x99 OCStackApplicationResult NSHandlePublishCb(void *ctx, OCDoHandle handle, OCClientResponse *clientResponse) { (void) handle; - if(ctx != (void *)DEFAULT_CONTEXT_VALUE) + if (ctx != (void *)DEFAULT_CONTEXT_VALUE) { NS_LOG(DEBUG, "Invalid Publish callback received"); } @@ -55,7 +55,7 @@ NSResult NSPublishResourceToCloud(char *serverAddress) cbData.context = (void *)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - OCResourceHandle resourceHandles[1] = {NotificationResource.handle}; + OCResourceHandle resourceHandles[1] = { NotificationResource.handle }; OCStackResult res = OCRDPublish(serverAddress, CT_ADAPTER_TCP, resourceHandles, 1, &cbData, OC_LOW_QOS); @@ -91,7 +91,7 @@ NSResult NSCreateResource(char *uri) NotificationResource.version = VERSION; NotificationResource.handle = NULL; - if(NSGetResourceSecurity()) + if (NSGetResourceSecurity()) { NS_LOG(DEBUG, "Create secured resource"); resourceProperties = OC_DISCOVERABLE | OC_SECURE; @@ -131,7 +131,7 @@ NSResult NSCreateResource(char *uri) NotificationMessageResource.topicName = NULL; NotificationMessageResource.mediaContents = NULL; - if(NSGetResourceSecurity()) + if (NSGetResourceSecurity()) { NS_LOG(DEBUG, "Create secured resource"); resourceProperties = OC_OBSERVABLE | OC_SECURE; @@ -163,7 +163,7 @@ NSResult NSCreateResource(char *uri) NotificationSyncResource.state = NULL; NotificationSyncResource.handle = NULL; - if(NSGetResourceSecurity()) + if (NSGetResourceSecurity()) { NS_LOG(DEBUG, "Create secured resource"); resourceProperties = OC_OBSERVABLE | OC_SECURE; @@ -196,7 +196,7 @@ NSResult NSCreateResource(char *uri) NotificationTopicResource.TopicList = NULL; NotificationTopicResource.handle = NULL; - if(NSGetResourceSecurity()) + if (NSGetResourceSecurity()) { NS_LOG(DEBUG, "Create secured resource"); resourceProperties = OC_RES_PROP_NONE | OC_SECURE; diff --git a/service/notification/src/provider/NSProviderScheduler.c b/service/notification/src/provider/NSProviderScheduler.c index fb49337..7803938 100755 --- a/service/notification/src/provider/NSProviderScheduler.c +++ b/service/notification/src/provider/NSProviderScheduler.c @@ -150,7 +150,7 @@ bool NSStopScheduler() void NSPushQueue(NSSchedulerType schedulerType, NSTaskType taskType, void* data) { - if(!NSIsRunning[schedulerType]) + if (!NSIsRunning[schedulerType]) { return; } @@ -164,7 +164,8 @@ void NSPushQueue(NSSchedulerType schedulerType, NSTaskType taskType, void* data) if (NSHeadMsg[schedulerType] == NULL) { NSHeadMsg[schedulerType] = (NSTask*) OICMalloc(sizeof(NSTask)); - if(NSHeadMsg[schedulerType]) + + if (NSHeadMsg[schedulerType]) { NSHeadMsg[schedulerType]->taskType = taskType; NSHeadMsg[schedulerType]->taskData = data; @@ -175,7 +176,7 @@ void NSPushQueue(NSSchedulerType schedulerType, NSTaskType taskType, void* data) else { NSTask* newNode = (NSTask*) OICMalloc(sizeof(NSTask)); - if(newNode) + if (newNode) { newNode->taskType = taskType; newNode->taskData = data; diff --git a/service/notification/src/provider/NSProviderSubscription.c b/service/notification/src/provider/NSProviderSubscription.c index 321109d..6bfe3cd 100644 --- a/service/notification/src/provider/NSProviderSubscription.c +++ b/service/notification/src/provider/NSProviderSubscription.c @@ -89,6 +89,7 @@ NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest OCResourcePayloadAddStringLL(&payload->interfaces, NS_INTERFACE_READ); OCResourcePayloadAddStringLL(&payload->types, NS_ROOT_TYPE); } + OICFree(copyReq); OCRepPayloadSetUri(payload, NS_ROOT_URI); OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_PROVIDER_ID, NSGetProviderInfo()->providerId); @@ -125,7 +126,7 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour char * copyReq = OICStrdup(entityHandlerRequest->query); char * id = NSGetValueFromQuery(copyReq, NS_QUERY_CONSUMER_ID); - if(!id) + if (!id) { OICFree(copyReq); NSFreeOCEntityHandlerRequest(entityHandlerRequest); @@ -153,7 +154,7 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour #if(defined WITH_CLOUD && defined RD_CLIENT) iSRemoteServer = NSIsRemoteServerAddress(entityHandlerRequest->devAddr.addr); - if(iSRemoteServer) + if (iSRemoteServer) { NS_LOG(DEBUG, "Requested by remote server"); subData->remote_messageObId = entityHandlerRequest->obsInfo.obsId; @@ -161,7 +162,7 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour } #endif - if(!iSRemoteServer) + if (!iSRemoteServer) { NS_LOG(DEBUG, "Requested by local consumer"); subData->messageObId = entityHandlerRequest->obsInfo.obsId; @@ -209,9 +210,9 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour subData->remote_syncObId = subData->syncObId = 0; bool isRemoteServer = false; -#if(defined WITH_CLOUD && defined RD_CLIENT) +#if (defined WITH_CLOUD && defined RD_CLIENT) isRemoteServer = NSIsRemoteServerAddress(entityHandlerRequest->devAddr.addr); - if(isRemoteServer) + if (isRemoteServer) { NS_LOG(DEBUG, "Requested by remote server"); subData->remote_syncObId = entityHandlerRequest->obsInfo.obsId; @@ -219,7 +220,7 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour } #endif - if(!isRemoteServer) + if (!isRemoteServer) { NS_LOG(DEBUG, "Requested by local consumer"); subData->syncObId = entityHandlerRequest->obsInfo.obsId; @@ -251,12 +252,11 @@ void NSHandleUnsubscription(OCEntityHandlerRequest *entityHandlerRequest) consumerSubList->cacheType = NS_PROVIDER_CACHE_SUBSCRIBER_OBSERVE_ID; - while(NSProviderStorageDelete(consumerSubList, (char *) + while (NSProviderStorageDelete(consumerSubList, (char *) &(entityHandlerRequest->obsInfo.obsId)) != NS_FAIL); - consumerSubList->cacheType = NS_PROVIDER_CACHE_SUBSCRIBER; + consumerSubList->cacheType = NS_PROVIDER_CACHE_SUBSCRIBER; NSFreeOCEntityHandlerRequest(entityHandlerRequest); - NS_LOG(DEBUG, "NSHandleUnsubscription - OUT"); } @@ -294,11 +294,12 @@ NSResult NSSendResponse(const char * id, bool accepted) NSCacheElement * element = NSProviderStorageRead(consumerSubList, id); - if(element == NULL) + if (element == NULL) { NS_LOG(ERROR, "element is NULL"); return NS_ERROR; } + NSCacheSubData * subData = (NSCacheSubData*) element->data; if (OCNotifyListOfObservers(rHandle, (OCObservationId*)&subData->messageObId, 1, @@ -309,8 +310,8 @@ NSResult NSSendResponse(const char * id, bool accepted) return NS_ERROR; } - OCRepPayloadDestroy(payload); + OCRepPayloadDestroy(payload); NS_LOG(DEBUG, "NSSendResponse - OUT"); return NS_OK; } @@ -328,7 +329,7 @@ NSResult NSSendConsumerSubResponse(OCEntityHandlerRequest * entityHandlerRequest char * copyReq = OICStrdup(entityHandlerRequest->query); char * id = NSGetValueFromQuery(copyReq, NS_QUERY_CONSUMER_ID); - if(!id) + if (!id) { OICFree(copyReq); NSFreeOCEntityHandlerRequest(entityHandlerRequest); diff --git a/service/notification/src/provider/NSProviderSystem.c b/service/notification/src/provider/NSProviderSystem.c index b8181bc..5949350 100644 --- a/service/notification/src/provider/NSProviderSystem.c +++ b/service/notification/src/provider/NSProviderSystem.c @@ -19,7 +19,7 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #include "NSProviderSystem.h" -#if(defined WITH_CLOUD && defined RD_CLIENT) +#if (defined WITH_CLOUD && defined RD_CLIENT) #define MAX_SERVER_ADDRESS 32 static char NSRemoteServerAddress[MAX_SERVER_ADDRESS] = {0,}; #endif @@ -44,7 +44,7 @@ NSConnectionState NSGetProviderConnectionState() return NSProviderConnectionState; } -#if(defined WITH_CLOUD && defined RD_CLIENT) +#if (defined WITH_CLOUD && defined RD_CLIENT) void NSSetRemoteServerAddress(char *serverAddress) { @@ -62,7 +62,7 @@ bool NSIsRemoteServerAddress(char *serverAddress) { NS_LOG_V(DEBUG, "Check server address: %s", serverAddress); - if(serverAddress != NULL) + if (serverAddress != NULL) { return strstr(NSRemoteServerAddress, serverAddress); } @@ -83,27 +83,29 @@ void NSInitProviderInfo(const char * userInfo) providerInfo->providerName = NULL; providerInfo->userInfo = NULL; - if(userInfo) + if (userInfo) + { providerInfo->userInfo = OICStrdup(userInfo); + } } void NSDeinitProviderInfo() { NS_LOG(DEBUG, "NSDeinitProviderInfo"); - if(!providerInfo) + if (!providerInfo) { NS_LOG(DEBUG, "providerInfo is NULL"); return; } - if(providerInfo->providerName) + if (providerInfo->providerName) { OICFree(providerInfo->providerName); providerInfo->providerName = NULL; } - if(providerInfo->userInfo) + if (providerInfo->userInfo) { OICFree(providerInfo->userInfo); providerInfo->userInfo = NULL; diff --git a/service/notification/src/provider/NSProviderTopic.c b/service/notification/src/provider/NSProviderTopic.c index bd23e91..389ef25 100644 --- a/service/notification/src/provider/NSProviderTopic.c +++ b/service/notification/src/provider/NSProviderTopic.c @@ -77,16 +77,17 @@ NSResult NSRegisterTopic(const char * topicName) OICFree(data); return NS_FAIL; } + element->data = (void *) data; element->next = NULL; - if(NSProviderStorageWrite(registeredTopicList, element) != NS_OK) + if (NSProviderStorageWrite(registeredTopicList, element) != NS_OK) { NS_LOG(DEBUG, "fail to write cache"); return NS_FAIL; } - NSSendTopicUpdation(); + NSSendTopicUpdation(); NS_LOG(DEBUG, "NSWriteTopicsToStorage() NS_OK"); return NS_OK; } @@ -103,6 +104,7 @@ NSResult NSUnregisterTopic(const char * topicName) } result = NSProviderStorageDelete(registeredTopicList, topicName); + while (NSProviderStorageDelete(consumerTopicList, topicName) != NS_FAIL) { } @@ -155,13 +157,14 @@ NSResult NSSendTopicUpdation() obArray[obCount++] = subData->messageObId; } -#if(defined WITH_CLOUD && defined RD_CLIENT) - if(subData->remote_messageObId != 0) +#if (defined WITH_CLOUD && defined RD_CLIENT) + if (subData->remote_messageObId != 0) { obArray[obCount++] = subData->remote_messageObId; } #endif } + it = it->next; } @@ -337,8 +340,8 @@ NSResult NSSendTopicList(OCEntityHandlerRequest * entityHandlerRequest) OCResourcePayloadAddStringLL(&payload->interfaces, NS_INTERFACE_READ); OCResourcePayloadAddStringLL(&payload->types, NS_ROOT_TYPE); } - OICFree(copyReq); + OICFree(copyReq); response.requestHandle = entityHandlerRequest->requestHandle; response.resourceHandle = entityHandlerRequest->resource; response.persistentBufferFlag = 0; @@ -378,8 +381,8 @@ NSResult NSPostConsumerTopics(OCEntityHandlerRequest * entityHandlerRequest) while (NSProviderStorageDelete(consumerTopicList, consumerId) != NS_FAIL) { } - consumerTopicList->cacheType = NS_PROVIDER_CACHE_CONSUMER_TOPIC_NAME; + consumerTopicList->cacheType = NS_PROVIDER_CACHE_CONSUMER_TOPIC_NAME; OCRepPayload ** topicListPayload = NULL; OCRepPayloadValue * payloadValue = NULL; payloadValue = NSPayloadFindValue(payload, NS_ATTRIBUTE_TOPIC_LIST); @@ -472,7 +475,8 @@ void * NSTopicSchedule(void * ptr) { newObj->data = topicSyncResult->topicData; newObj->next = NULL; - if(NSProviderStorageWrite(consumerTopicList, newObj) == NS_OK) + + if (NSProviderStorageWrite(consumerTopicList, newObj) == NS_OK) { NSSendTopicUpdationToConsumer(subData->id); topicSyncResult->result = NS_OK; @@ -496,11 +500,13 @@ void * NSTopicSchedule(void * ptr) pthread_mutex_lock(topicSyncResult->mutex); NSCacheTopicSubData * topicSubData = (NSCacheTopicSubData *) topicSyncResult->topicData; + if (NSProviderDeleteConsumerTopic(consumerTopicList, topicSubData) == NS_OK) { NSSendTopicUpdationToConsumer(topicSubData->id); topicSyncResult->result = NS_OK; } + OICFree(topicSubData->topicName); OICFree(topicSubData); pthread_cond_signal(topicSyncResult->condition); -- 2.7.4