X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fnotification%2Fsrc%2Fprovider%2FNSProviderSubscription.c;h=3116cbb4f48da4aacaa5ad772c185f9e8741b798;hb=7f00f942c39b7bc27c7eeecf213a239c3fe4173c;hp=026fb6c7bff45efbf61ca5a6f6e456e610f123da;hpb=e68dbfb0af873791281552bc7976ee30d55c418c;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/notification/src/provider/NSProviderSubscription.c b/service/notification/src/provider/NSProviderSubscription.c index 026fb6c..3116cbb 100644 --- a/service/notification/src/provider/NSProviderSubscription.c +++ b/service/notification/src/provider/NSProviderSubscription.c @@ -19,12 +19,14 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #include "NSProviderSubscription.h" +#include "NSProviderListener.h" NSResult NSInitSubscriptionList() { NS_LOG(DEBUG, "NSInitSubscriptionList - IN"); - consumerSubList = NSStorageCreate(); + consumerSubList = NSProviderStorageCreate(); + NS_VERIFY_NOT_NULL(consumerSubList, NS_FAIL); consumerSubList->cacheType = NS_PROVIDER_CACHE_SUBSCRIBER; NS_LOG(DEBUG, "NSInitSubscriptionList - OUT"); @@ -77,11 +79,23 @@ NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest return NS_ERROR; } - NS_LOG_V(DEBUG, "NS Provider ID: %s", NSGetProviderInfo()->providerId); + NS_LOG_V(INFO_PRIVATE, "NS Provider ID: %s", NSGetProviderInfo()->providerId); + char * copyReq = OICStrdup(entityHandlerRequest->query); + char * reqInterface = NSGetValueFromQuery(copyReq, NS_QUERY_INTERFACE); + + if (reqInterface && strcmp(reqInterface, NS_INTERFACE_BASELINE) == 0) + { + OCResourcePayloadAddStringLL(&payload->interfaces, NS_INTERFACE_BASELINE); + OCResourcePayloadAddStringLL(&payload->interfaces, NS_INTERFACE_READ); + OCResourcePayloadAddStringLL(&payload->types, NS_ROOT_TYPE); + } + + NSOICFree(copyReq); OCRepPayloadSetUri(payload, NS_ROOT_URI); OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_PROVIDER_ID, NSGetProviderInfo()->providerId); - OCRepPayloadSetPropInt(payload, NS_ATTRIBUTE_POLICY, NSGetPolicy()); + OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_VERSION, VERSION); + OCRepPayloadSetPropBool(payload, NS_ATTRIBUTE_POLICY, NSGetPolicy()); OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_MESSAGE, NS_COLLECTION_MESSAGE_URI); OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_SYNC, NS_COLLECTION_SYNC_URI); OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_TOPIC, NS_COLLECTION_TOPIC_URI); @@ -96,6 +110,7 @@ NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest if (OCDoResponse(&response) != OC_STACK_OK) { NS_LOG(ERROR, "Fail to AccessPolicy send response"); + OCRepPayloadDestroy(payload); return NS_ERROR; } OCRepPayloadDestroy(payload); @@ -109,34 +124,38 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour { NS_LOG(DEBUG, "NSHandleSubscription - IN"); - char * id = NSGetValueFromQuery(OICStrdup(entityHandlerRequest->query), NS_QUERY_CONSUMER_ID); + char * copyReq = OICStrdup(entityHandlerRequest->query); + char * id = NSGetValueFromQuery(copyReq, NS_QUERY_CONSUMER_ID); - if(!id) + if (!id) { + NSOICFree(copyReq); NSFreeOCEntityHandlerRequest(entityHandlerRequest); NS_LOG(ERROR, "Invalid ConsumerID"); return; } - NS_LOG_V(DEBUG, "consumerId = %s", id); + NS_LOG_V(INFO_PRIVATE, "consumerId = %s", id); if (resourceType == NS_RESOURCE_MESSAGE) { NS_LOG(DEBUG, "resourceType == NS_RESOURCE_MESSAGE"); NSCacheElement * element = (NSCacheElement *) OICMalloc(sizeof(NSCacheElement)); + NS_VERIFY_NOT_NULL_V(element); NSCacheSubData * subData = (NSCacheSubData *) OICMalloc(sizeof(NSCacheSubData)); + NS_VERIFY_NOT_NULL_V(subData); OICStrcpy(subData->id, UUID_STRING_SIZE, id); - NS_LOG_V(DEBUG, "SubList ID = [%s]", subData->id); + NS_LOG_V(INFO_PRIVATE, "SubList ID = [%s]", subData->id); - NS_LOG_V(DEBUG, "Consumer Address: %s", entityHandlerRequest->devAddr.addr); + NS_LOG_V(INFO_PRIVATE, "Consumer Address: %s", entityHandlerRequest->devAddr.addr); subData->remote_messageObId = subData->messageObId = 0; bool iSRemoteServer = false; -#ifdef RD_CLIEND +#if(defined WITH_CLOUD) iSRemoteServer = NSIsRemoteServerAddress(entityHandlerRequest->devAddr.addr); - if(iSRemoteServer) + if (iSRemoteServer) { NS_LOG(DEBUG, "Requested by remote server"); subData->remote_messageObId = entityHandlerRequest->obsInfo.obsId; @@ -144,7 +163,7 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour } #endif - if(!iSRemoteServer) + if (!iSRemoteServer) { NS_LOG(DEBUG, "Requested by local consumer"); subData->messageObId = entityHandlerRequest->obsInfo.obsId; @@ -158,41 +177,45 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour element->data = (void*) subData; element->next = NULL; - if (NSStorageWrite(consumerSubList, element) != NS_OK) + if (NSProviderStorageWrite(consumerSubList, element) != NS_OK) { NS_LOG(DEBUG, "fail to write cache"); } bool currPolicy = NSGetPolicy(); + NSAskAcceptanceToUser(NSCopyOCEntityHandlerRequest(entityHandlerRequest)); if (currPolicy == NS_POLICY_PROVIDER) { NS_LOG(DEBUG, "NSGetSubscriptionAccepter == NS_ACCEPTER_PROVIDER"); - NSAskAcceptanceToUser(entityHandlerRequest); } else if (currPolicy == NS_POLICY_CONSUMER) { NS_LOG(DEBUG, "NSGetSubscriptionAccepter == NS_ACCEPTER_CONSUMER"); - NSSendConsumerSubResponse(entityHandlerRequest); + NSSendConsumerSubResponse(NSCopyOCEntityHandlerRequest(entityHandlerRequest)); } + + NSFreeOCEntityHandlerRequest(entityHandlerRequest); } else if (resourceType == NS_RESOURCE_SYNC) { NS_LOG(DEBUG, "resourceType == NS_RESOURCE_SYNC"); NSCacheElement * element = (NSCacheElement *) OICMalloc(sizeof(NSCacheElement)); + NS_VERIFY_NOT_NULL_V(element); NSCacheSubData * subData = (NSCacheSubData *) OICMalloc(sizeof(NSCacheSubData)); + NS_VERIFY_NOT_NULL_V(subData); OICStrcpy(subData->id, UUID_STRING_SIZE, id); - NS_LOG_V(DEBUG, "SubList ID = [%s]", subData->id); + NS_LOG_V(INFO_PRIVATE, "SubList ID = [%s]", subData->id); - NS_LOG_V(DEBUG, "Consumer Address: %s", entityHandlerRequest->devAddr.addr); + NS_LOG_V(INFO_PRIVATE, "Consumer Address: %s", entityHandlerRequest->devAddr.addr); subData->remote_syncObId = subData->syncObId = 0; bool isRemoteServer = false; -#ifdef RD_CLIENT +#if (defined WITH_CLOUD) isRemoteServer = NSIsRemoteServerAddress(entityHandlerRequest->devAddr.addr); - if(isRemoteServer) + if (isRemoteServer) { NS_LOG(DEBUG, "Requested by remote server"); subData->remote_syncObId = entityHandlerRequest->obsInfo.obsId; @@ -200,7 +223,7 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour } #endif - if(!isRemoteServer) + if (!isRemoteServer) { NS_LOG(DEBUG, "Requested by local consumer"); subData->syncObId = entityHandlerRequest->obsInfo.obsId; @@ -214,13 +237,14 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour element->data = (void*) subData; element->next = NULL; - if (NSStorageWrite(consumerSubList, element) != NS_OK) + if (NS_OK != NSProviderStorageWrite(consumerSubList, element)) { NS_LOG(ERROR, "Fail to write cache"); } NSFreeOCEntityHandlerRequest(entityHandlerRequest); } + NSOICFree(copyReq); NS_LOG(DEBUG, "NSHandleSubscription - OUT"); } @@ -231,12 +255,11 @@ void NSHandleUnsubscription(OCEntityHandlerRequest *entityHandlerRequest) consumerSubList->cacheType = NS_PROVIDER_CACHE_SUBSCRIBER_OBSERVE_ID; - while(NSStorageDelete(consumerSubList, (unsigned 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"); } @@ -272,25 +295,26 @@ NSResult NSSendResponse(const char * id, bool accepted) : OCRepPayloadSetPropInt(payload, NS_ATTRIBUTE_MESSAGE_ID, NS_DENY); OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_PROVIDER_ID, NSGetProviderInfo()->providerId); - NSCacheElement * element = NSStorageRead(consumerSubList, id); + 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, payload, OC_LOW_QOS) - != OC_STACK_OK) + if (OCNotifyListOfObservers(rHandle, (OCObservationId*)&subData->messageObId, 1, + payload, OC_LOW_QOS) != OC_STACK_OK) { NS_LOG(ERROR, "fail to send Acceptance"); OCRepPayloadDestroy(payload); return NS_ERROR; } - OCRepPayloadDestroy(payload); + OCRepPayloadDestroy(payload); NS_LOG(DEBUG, "NSSendResponse - OUT"); return NS_OK; } @@ -302,13 +326,15 @@ NSResult NSSendConsumerSubResponse(OCEntityHandlerRequest * entityHandlerRequest if (!entityHandlerRequest) { NS_LOG(ERROR, "Invalid request pointer"); - return OC_EH_ERROR; + return NS_ERROR; } - char * id = NSGetValueFromQuery(OICStrdup(entityHandlerRequest->query), NS_QUERY_CONSUMER_ID); + char * copyReq = OICStrdup(entityHandlerRequest->query); + char * id = NSGetValueFromQuery(copyReq, NS_QUERY_CONSUMER_ID); - if(!id) + if (!id) { + NSOICFree(copyReq); NSFreeOCEntityHandlerRequest(entityHandlerRequest); NS_LOG(ERROR, "Invalid ConsumerID"); return NS_ERROR; @@ -316,11 +342,44 @@ NSResult NSSendConsumerSubResponse(OCEntityHandlerRequest * entityHandlerRequest NSCacheUpdateSubScriptionState(consumerSubList, id, true); NSSendResponse(id, true); + NSOICFree(copyReq); NSFreeOCEntityHandlerRequest(entityHandlerRequest); NS_LOG(DEBUG, "NSSendSubscriptionResponse - OUT"); return NS_OK; } +#ifdef WITH_MQ +void NSProviderMQSubscription(NSMQTopicAddress * topicAddr) +{ + char * serverUri = topicAddr->serverAddr; + char * topicName = topicAddr->topicName; + + NS_LOG_V(DEBUG, "input Topic Name2 : %s", topicAddr->topicName); + + OCDevAddr * addr = NSChangeAddress(serverUri); + OCCallbackData cbdata = { NULL, NULL, NULL }; + cbdata.cb = NSProviderGetMQResponseCB; + cbdata.context = OICStrdup(topicName); + cbdata.cd = NSOICFree; + + char requestUri[100] = "coap+tcp://"; + + NS_LOG_V(DEBUG, "requestUri1 = %s", requestUri); + OICStrcat(requestUri, strlen(requestUri)+strlen(serverUri)+1, serverUri); + NS_LOG_V(DEBUG, "requestUri2 = %s", requestUri); + OICStrcat(requestUri, strlen(requestUri)+ strlen("/oic/ps") + 1, "/oic/ps"); + NS_LOG_V(DEBUG, "requestUri3 = %s", requestUri); + OCStackResult ret = OCDoResource(NULL, OC_REST_GET, requestUri, addr, + NULL, CT_DEFAULT, OC_HIGH_QOS, &cbdata, NULL, 0); + + NSOCResultToSuccess(ret); + + NSOICFree(topicAddr->serverAddr); + NSOICFree(topicAddr->topicName); + NSOICFree(topicAddr); +} +#endif + void * NSSubScriptionSchedule(void *ptr) { if (ptr == NULL) @@ -363,7 +422,7 @@ void * NSSubScriptionSchedule(void *ptr) NSCacheUpdateSubScriptionState(consumerSubList, consumerId, true); NSSendResponse(consumerId, true); - OICFree(consumerId); + NSOICFree(consumerId); break; } case TASK_SEND_DENY: @@ -373,7 +432,7 @@ void * NSSubScriptionSchedule(void *ptr) NSCacheUpdateSubScriptionState(consumerSubList, consumerId, false); NSSendResponse(consumerId, false); - NSFreeConsumer(consumerId); + NSOICFree(consumerId); break; } @@ -382,11 +441,17 @@ void * NSSubScriptionSchedule(void *ptr) NSHandleSubscription((OCEntityHandlerRequest*) node->taskData, NS_RESOURCE_SYNC); break; +#ifdef WITH_MQ + case TASK_MQ_REQ_SUBSCRIBE: + NS_LOG(DEBUG, "CASE TASK_MQ_REQ_SUBSCRIBE : "); + NSProviderMQSubscription((NSMQTopicAddress*) node->taskData); + break; +#endif default: break; } - OICFree(node); + NSOICFree(node); } pthread_mutex_unlock(&NSMutex[SUBSCRIPTION_SCHEDULER]);