Modify cloud interface 17/10717/12
authorcc <ch79.cho@samsung.com>
Mon, 22 Aug 2016 07:00:12 +0000 (16:00 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 25 Aug 2016 00:38:06 +0000 (00:38 +0000)
Cloud interface and APIs are modified according to cloud module changes.
And configurations related to the interface are changed.

Conflicts:
service/notification/examples/linux/notificationconsumer.c

Change-Id: I0c7cb16dd19596cda90c0eef2a6332cc6a5532ae
Signed-off-by: cc <ch79.cho@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10717
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Hun-je Yeon <hunje.yeon@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
12 files changed:
service/notification/SConscript
service/notification/examples/linux/SConscript
service/notification/examples/linux/cloud_connector.c
service/notification/examples/linux/cloud_connector.h
service/notification/examples/linux/notificationconsumer.c
service/notification/examples/linux/notificationprovider.c
service/notification/src/common/NSCloudConnector.c [deleted file]
service/notification/src/common/NSCloudConnector.h [deleted file]
service/notification/src/consumer/NSConsumerInterface.c
service/notification/src/provider/NSProviderInterface.c
service/notification/src/provider/NSProviderListener.h
service/notification/src/provider/NSProviderResource.c

index d9fc820..774e258 100755 (executable)
@@ -77,7 +77,7 @@ if not env.get('RELEASE'):
     notification_env.AppendUnique(CCFLAGS = ['--coverage'])
 
 if 'CLIENT' in notification_env.get('RD_MODE'):
-    notification_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
+        notification_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
     
 if env.get('WITH_CLOUD') == True:      
        notification_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])    
index b55eec9..15b2f37 100644 (file)
@@ -42,27 +42,29 @@ if target_os == 'android':
                notification_sample_env.AppendUnique(LIBS = ['log'])
 
 notification_sample_consumer_src = 'notificationconsumer.c'
+notification_sample_provider_src = 'notificationprovider.c'
 
 if env.get('WITH_CLOUD') == True:
        notification_sample_env.AppendUnique(CPPPATH = ['../../src/consumer'])
+        notification_sample_env.AppendUnique(CPPPATH = ['../../src/provider'])
        notification_sample_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
+
        CONSUMER_CLOUD = File('cloud_connector.c')
        notification_sample_consumer_src = ['notificationconsumer.c', CONSUMER_CLOUD]
+        PROVIDER_CLOUD = File('cloud_connector.c')
+        notification_sample_provider_src = ['notificationprovider.c', PROVIDER_CLOUD]
 
 if env.get('WITH_TCP') == True:
        notification_sample_env.AppendUnique(CPPDEFINES = ['WITH_TCP'])
        if env.get('SECURED') == '1':
                notification_sample_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto'])
 
-
-
 ####################################################################
 # Source files and Targets
 ######################################################################
 notification_sample_provider_env = notification_sample_env.Clone()
-
 notification_sample_provider_env.AppendUnique(LIBS = 'libnotification_provider')
-notificationprovider = notification_sample_provider_env.Program('notificationprovider', 'notificationprovider.c')
+notificationprovider = notification_sample_provider_env.Program('notificationprovider', notification_sample_provider_src)
 i_notificationprovider = notification_sample_provider_env.Install(env.get('BUILD_DIR'), notificationprovider)
 
 notification_sample_consumer_env = notification_sample_env.Clone()
index 9f09bd3..c5e5f8c 100644 (file)
 // limitations under the License.
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#include "cloud_connector.h"
-
-#include <stdarg.h>
-#include <stdlib.h>
 
-#include "oic_string.h"
-#include "oic_malloc.h"
+/// This sample provides the way to create cloud sample
 
+#include "ocstack.h"
 #include "ocpayload.h"
+#include "oicresourcedirectory.h"
+#include "cloud_connector.h"
 
-#include "rdpayload.h"
+static bool isCloudLoggedin = false;
 
-#define OC_RD_PUBLISH_TTL 86400
-#define DEFAULT_CONTEXT_VALUE 0x99
+OCStackResult OCCloudSignup(const char *host, const char *deviceId,
+        const char *authprovider,
+        const char *authcode, OCClientResponseHandler response)
+{
+        char    targetUri[MAX_URI_LENGTH * 2] = { 0, };
+        snprintf(targetUri, MAX_URI_LENGTH * 2, "%s%s", host, DEFAULT_AUTH_SIGNUP);
+
+        OCCallbackData cbData;
+        memset(&cbData, 0, sizeof(OCCallbackData));
+        cbData.cb = response;
+        cbData.cd = NULL;
+        cbData.context = (void *)DEFAULT_CONTEXT_VALUE;
 
-#define DEFAULT_COAP_TCP_HOST "coap+tcp://"
-#define DEFAULT_COAP_TCP_PORT 5683
+        printf("Host: %s\n", targetUri);
+        printf("Dev id: %s\n", deviceId);
+        printf("Auth Provider: %s\n", authprovider);
+        printf("Auth Code: %s\n", authcode);
 
-#define DEFAULT_COAP_TCP_SECURE_HOST "coaps+tcp://"
-#define DEFAULT_COAP_TCP_SECURE_PORT 5864
+        OCRepPayload *registerPayload = OCRepPayloadCreate();
 
-#define DEFAULT_AUTH_REGISTER_LOGIN "/oic/auth/?reqtype=register"
-#define DEFAULT_AUTH_LOGIN "/oic/auth/?reqtype=login"
-#define DEFAULT_AUTH_LOGOUT "/oic/auth/?reqtype=logout"
+        OCRepPayloadSetPropString(registerPayload, "di", deviceId);
+        OCRepPayloadSetPropString(registerPayload, "authprovider", authprovider);
+        OCRepPayloadSetPropString(registerPayload, "authcode", authcode);
 
-static OCStackResult createStringLL(uint8_t numElements, OCResourceHandle handle,
-                                    const char *(*getValue)(OCResourceHandle handle, uint8_t i), OCStringLL **stringLL)
+        return OCDoResource(NULL, OC_REST_POST, targetUri, NULL, (OCPayload *)registerPayload,
+                CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
+}
+
+OCStackResult OCCloudSession(const char *host, const char *query, const char *uId,
+        const char *deviceId,
+        const char *accesstoken,
+        bool isLogin, OCClientResponseHandler response)
 {
-    for (uint8_t i = 0; i < numElements; ++i)
-    {
-        const char *value = getValue(handle, i);
-        if (!*stringLL)
+        char    targetUri[MAX_URI_LENGTH * 2] = { 0, };
+        snprintf(targetUri, MAX_URI_LENGTH * 2, "%s%s", host, query);
+
+        OCCallbackData cbData;
+        memset(&cbData, 0, sizeof(OCCallbackData));
+        cbData.cb = response;
+        cbData.cd = NULL;
+        cbData.context = (void *)DEFAULT_CONTEXT_VALUE;
+
+        OCRepPayload *loginoutPayload = OCRepPayloadCreate();
+
+        if (uId != NULL)
         {
-            *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
-            if (!*stringLL)
-            {
-                return OC_STACK_NO_MEMORY;
-            }
-            (*stringLL)->value = OICStrdup(value);
-            if (!(*stringLL)->value)
-            {
-                return OC_STACK_NO_MEMORY;
-            }
+                OCRepPayloadSetPropString(loginoutPayload, "uid", uId);
         }
-        else
+
+        if (deviceId != NULL)
         {
-            OCStringLL *cur = *stringLL;
-            while (cur->next)
-            {
-                cur = cur->next;
-            }
-            cur->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
-            if (!cur->next)
-            {
-                return OC_STACK_NO_MEMORY;
-            }
-            cur->next->value = OICStrdup(value);
-            if (!cur->next->value)
-            {
-                return OC_STACK_NO_MEMORY;
-            }
+                OCRepPayloadSetPropString(loginoutPayload, "di", deviceId);
         }
-    }
-    return OC_STACK_OK;
+
+        if (accesstoken != NULL)
+        {
+                OCRepPayloadSetPropString(loginoutPayload, "accesstoken", accesstoken);
+        }
+        OCRepPayloadSetPropBool(loginoutPayload, "login", isLogin);
+
+        return OCDoResource(NULL, OC_REST_POST, targetUri, NULL, (OCPayload *)loginoutPayload,
+                CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
-OCStackResult OCCloudRegisterLogin(const char *host, const char *auth_provider,
-                                   const char *auth_code, OCClientResponseHandler response)
+//Client should call refresh before expiresin or when receive 4.01 during sign-in
+OCStackResult OCCloudRefresh(const char *host, const char *query, const char *uId,
+        const char *deviceId, const char *refreshtoken, OCClientResponseHandler response)
 {
-    char    targetUri[MAX_URI_LENGTH * 2] = { 0, };
-    snprintf(targetUri, MAX_URI_LENGTH * 2, "%s%s", host, DEFAULT_AUTH_REGISTER_LOGIN);
+        char    targetUri[MAX_URI_LENGTH * 2] = { 0, };
+        snprintf(targetUri, MAX_URI_LENGTH * 2, "%s%s", host, query);
 
-    OCCallbackData cbData;
-    memset(&cbData, 0, sizeof(OCCallbackData));
-    cbData.cb = response;
-    cbData.cd = NULL;
-    cbData.context = (void *)DEFAULT_CONTEXT_VALUE;
+        OCCallbackData cbData;
+        memset(&cbData, 0, sizeof(OCCallbackData));
+        cbData.cb = response;
+        cbData.cd = NULL;
+        cbData.context = (void *)DEFAULT_CONTEXT_VALUE;
 
-    OCRepPayload *registerPayload = OCRepPayloadCreate();
-    if (!registerPayload)
-    {
-        goto no_memory;
-    }
+        OCRepPayload *refreshPayload = OCRepPayloadCreate();
 
-    OCRepPayloadSetPropString(registerPayload, "authprovider", auth_provider);
-    OCRepPayloadSetPropString(registerPayload, "authcode", auth_code);
+        OCRepPayloadSetPropString(refreshPayload, "uid", uId);
+        OCRepPayloadSetPropString(refreshPayload, "di", deviceId);
+        OCRepPayloadSetPropString(refreshPayload, "granttype", "refresh_token");
+        OCRepPayloadSetPropString(refreshPayload, "refreshtoken", refreshtoken);
 
-    return OCDoResource(NULL, OC_REST_POST, targetUri, NULL, (OCPayload *)registerPayload,
-                        CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
+        return OCDoResource(NULL, OC_REST_POST, targetUri, NULL, (OCPayload *)refreshPayload,
+                CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
+}
 
-no_memory:
-    OCRepPayloadDestroy(registerPayload);
-    return OC_STACK_NO_MEMORY;
+OCStackResult OCCloudLogin(const char *host, const char *uId, const char *deviceId,
+        const char *accesstoken, OCClientResponseHandler response)
+{
+        return OCCloudSession(host, DEFAULT_AUTH_SESSION, uId, deviceId, accesstoken, true, response);
 }
 
-OCStackResult OCCloudLoginout(const char *host, const char *query, const char *auth_session,
-                              OCClientResponseHandler response)
+OCStackResult OCCloudLogout(const char *host, OCClientResponseHandler response)
 {
-    char    targetUri[MAX_URI_LENGTH * 2] = { 0, };
-    snprintf(targetUri, MAX_URI_LENGTH * 2, "%s%s", host, query);
+        return OCCloudSession(host, DEFAULT_AUTH_SESSION, NULL, NULL, NULL, false, response);
+}
 
-    OCCallbackData cbData;
-    memset(&cbData, 0, sizeof(OCCallbackData));
-    cbData.cb = response;
-    cbData.cd = NULL;
-    cbData.context = (void *)DEFAULT_CONTEXT_VALUE;
+void printRepresentation(OCRepPayloadValue *value)
+{
+        while (value)
+        {
+                printf("Key: %s / ", value->name);
+                switch (value->type)
+                {
+                case OCREP_PROP_NULL:
+                        printf("Value: None\n");
+                        break;
+                case OCREP_PROP_INT:
+                        printf("Value: %d\n", value->i);
+                        break;
+                case OCREP_PROP_DOUBLE:
+                        printf("Value: %f\n", value->d);
+                        break;
+                case OCREP_PROP_BOOL:
+                        printf("Value: %d\n", value->b);
+                        break;
+                case OCREP_PROP_STRING:
+                        printf("Value: %s\n", value->str);
+                        break;
+                case OCREP_PROP_BYTE_STRING:
+                        printf("Value: Byte String\n");
+                        break;
+                case OCREP_PROP_OBJECT:
+                        printf("Value: Object\n");
+                        break;
+                case OCREP_PROP_ARRAY:
+                        printf("Value: Array\n");
+                        break;
+                default:
+                        break;
+                }
+                value = value->next;
+        }
+}
 
-    OCRepPayload *loginoutPayload = OCRepPayloadCreate();
-    if (!loginoutPayload)
+// callback for sign-up and sign-in
+OCStackApplicationResult CloudSignupCallback(void *ctx,
+        OCDoHandle handle, OCClientResponse *clientResponse)
+{
+    if (ctx != (void *)DEFAULT_CONTEXT_VALUE)
     {
-        goto no_memory;
+        printf("Invalid Cloud Login/out callback received\n");
     }
 
-    OCRepPayloadSetPropString(loginoutPayload, "session", auth_session);
+    printf("Signup response received: %d\n", clientResponse->result);
 
-    return OCDoResource(NULL, OC_REST_POST, targetUri, NULL, (OCPayload *)loginoutPayload,
-                        CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
+    if (clientResponse->payload != NULL &&
+            clientResponse->payload->type == PAYLOAD_TYPE_REPRESENTATION)
+    {
+        printf("PAYLOAD_TYPE_REPRESENTATION received\n");
+        printf("Sign-in using retrieved accesstoken when disconnected or reboot\n");
 
-no_memory:
-    OCRepPayloadDestroy(loginoutPayload);
-    return OC_STACK_NO_MEMORY;
-}
+        OCRepPayloadValue *val = ((OCRepPayload *)clientResponse->payload)->values;
 
+        printf("Get payload values\n");
+        printRepresentation(val);
+    }
+    return OC_STACK_KEEP_TRANSACTION;
+}
 
-OCStackResult OCCloudLogin(const char *host, const char *auth_session,
-                           OCClientResponseHandler response)
+OCStackApplicationResult CloudLoginoutCallback(void *ctx,
+        OCDoHandle handle, OCClientResponse *clientResponse)
 {
-    return OCCloudLoginout(host, DEFAULT_AUTH_LOGIN, auth_session, response);
+    if (ctx != (void *)DEFAULT_CONTEXT_VALUE)
+    {
+        printf("Invalid Cloud Login/out callback received\n");
+    }
+
+    printf("Login/out response received: %d\n", clientResponse->result);
+
+    if (clientResponse->payload != NULL &&
+            clientResponse->payload->type == PAYLOAD_TYPE_REPRESENTATION)
+    {
+        printf("PAYLOAD_TYPE_REPRESENTATION received\n");
+
+        OCRepPayloadValue *val = ((OCRepPayload *)clientResponse->payload)->values;
+
+        printf("Get payload values\n");
+        printRepresentation(val);
+
+        if(clientResponse->result < 5)
+        {
+            isCloudLoggedin = true;
+        }
+    }
+
+    return OC_STACK_KEEP_TRANSACTION;
 }
 
-OCStackResult OCCloudLogout(const char *host, const char *auth_session,
-                            OCClientResponseHandler response)
+bool IsCloudLoggedin()
 {
-    return OCCloudLoginout(host, DEFAULT_AUTH_LOGOUT, auth_session, response);
+    return isCloudLoggedin;
 }
+
index fbb8821..8f65f24 100644 (file)
@@ -1,7 +1,3 @@
-//******************************************************************
-//
-// Copyright 2016 Samsung Electronics All Rights Reserved.
-//
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-
 #include "ocstack.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif // __cplusplus
 
-OCStackResult OCCloudRegisterLogin(const char *host, const char *auth_provider,
-                                   const char *auth_code, OCClientResponseHandler response);
-OCStackResult OCCloudLogin(const char *host, const char *auth_session,
-                           OCClientResponseHandler response);
-OCStackResult OCCloudLogout(const char *host, const char *auth_session,
-                            OCClientResponseHandler response);
-OCStackResult OCCloudPublish(const char *host, const char *query,
-                             OCClientResponseHandler response, int numArg, ...);
+#define DEFAULT_CONTEXT_VALUE 0x99
+#define DEFAULT_AUTH_SIGNUP "/.well-known/ocf/account"
+#define DEFAULT_AUTH_SESSION "/.well-known/ocf/account/session"
+#define DEFAULT_AUTH_REFRESH "/.well-known/ocf/account/tokenrefresh"
+
+OCStackResult OCCloudSignup(const char *host, const char *deviceId,
+        const char *authprovider, const char *authcode,
+        OCClientResponseHandler response);
+
+OCStackResult OCCloudSession(const char *host, const char *query, const char *uId,
+        const char *deviceId, const char *accesstoken, bool isLogin,
+        OCClientResponseHandler response);
+
+OCStackResult OCCloudRefresh(const char *host, const char *query, const char *uId,
+        const char *deviceId, const char *refreshtoken, OCClientResponseHandler response);
+
+OCStackResult OCCloudLogin(const char *host, const char *uId, const char *deviceId,
+        const char *accesstoken, OCClientResponseHandler response);
+
+OCStackResult OCCloudLogout(const char *host, OCClientResponseHandler response);
+
+OCStackApplicationResult CloudLoginoutCallback(void *ctx,
+        OCDoHandle handle, OCClientResponse *clientResponse);
+
+OCStackApplicationResult CloudSignupCallback(void *ctx,
+        OCDoHandle handle, OCClientResponse *clientResponse);
+
+bool IsCloudLoggedin();
 
 #ifdef __cplusplus
 }
index d538b07..9d44402 100644 (file)
 
 #ifdef WITH_CLOUD
 #include "NSConstants.h"
-#include "NSConsumerCommon.h"
 #include "oic_malloc.h"
+#include "cloud_connector.h"
 
 #define CLOUD_CONTEXT_VALUE 0x99
-#define CLOUD_PRESENCE_SUBSCRIBE_QUERY ""          // refer to IoTivity Cloud Module Sample
 
-#define CLOUD_HOST_ADDRESS ""                      // refer to IoTivity Cloud Module Sample
-#define CLOUD_IOTIVITYNS_SESSION ""                // refer to IoTivity Cloud Module Sample
+char CLOUD_ADDRESS[50];
+char CLOUD_AUTH_PROVIDER[50];
+char CLOUD_AUTH_CODE[50];
+char CLOUD_UID[50];
+char CLOUD_ACCESS_TOKEN[50];
 #endif
 
+
 NSProvider * g_provider = NULL;
 
+FILE* server_fopen(const char *path, const char *mode)
+{
+    (void)path;
+    return fopen("oic_ns_provider_db.dat", mode);
+}
+
 void onDiscoverNotification(NSProvider * provider)
 {
     printf("notification resource discovered\n");
@@ -94,46 +103,6 @@ void onNotificationSync(NSSyncInfo * sync)
     printf("Sync STATE : %d\n", sync->state);
 }
 
-#ifdef WITH_CLOUD
-OCStackApplicationResult handleLoginoutCB(void *ctx,
-        OCDoHandle handle,
-        OCClientResponse *clientResponse)
-{
-    (void)handle;
-    if (ctx != (void *)CLOUD_CONTEXT_VALUE)
-    {
-        NS_LOG(DEBUG, "Invalid Login/out callback received");
-    }
-
-    NS_LOG(DEBUG, "Login/out response received");
-
-    if (clientResponse->payload != NULL &&
-        clientResponse->payload->type == PAYLOAD_TYPE_REPRESENTATION)
-    {
-        NS_LOG(DEBUG, "PAYLOAD_TYPE_REPRESENTATION received");
-
-        OCRepPayloadValue *val = ((OCRepPayload *)clientResponse->payload)->values;
-
-        while (val)
-        {
-            val = val->next;
-        }
-        NS_LOG(DEBUG, "Get payload values");
-
-        OCDevAddr * addr = NULL;
-        addr = (OCDevAddr *) OICMalloc(sizeof(OCDevAddr));
-        memcpy(addr, clientResponse->addr, sizeof(OCDevAddr));
-
-        NSTask * task = NSMakeTask(TASK_EVENT_CONNECTED_TCP, addr);
-
-        NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(task, OC_STACK_KEEP_TRANSACTION, NSOICFree(addr));
-        NSConsumerPushEvent(task);
-    }
-
-    return OC_STACK_KEEP_TRANSACTION;
-}
-#endif
-
 void* OCProcessThread(void * ptr)
 {
     (void) ptr;
@@ -157,7 +126,12 @@ int main(void)
     pthread_t OCThread = NULL;
 
     printf("start Iotivity\n");
-    if (OCInit1(OC_CLIENT, OC_DEFAULT_FLAGS, OC_DEFAULT_FLAGS) != OC_STACK_OK)
+
+    // open oic_db
+    static OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink};
+    OCRegisterPersistentStorageHandler(&ps);
+
+    if (OCInit1(OC_CLIENT_SERVER, OC_DEFAULT_FLAGS, OC_DEFAULT_FLAGS) != OC_STACK_OK)
     {
         printf("OCInit fail\n");
         return 0;
@@ -169,11 +143,6 @@ int main(void)
     cfg.messageCb = onNotificationPosted;
     cfg.syncInfoCb = onNotificationSync;
 
-#ifdef WITH_CLOUD
-    NS_LOG(DEBUG, "process OCCloudLogin...");
-    NS_LOG(DEBUG, "OCCloudLogin return");
-#endif
-
     pthread_create(&OCThread, NULL, OCProcessThread, NULL);
 
     printf("start notification consumer service\n");
@@ -187,6 +156,12 @@ int main(void)
         printf("3. Get Topics\n");
         printf("4. Select Topics\n");
         printf("5. Exit\n");
+#ifdef WITH_CLOUD
+        printf("21. Enable Remote Service (after login)\n");
+        printf("31. Cloud Signup\n");
+        printf("32. Cloud Login\n");
+        printf("33. Cloud Logout\n");
+#endif
 
         printf("Input: ");
 
@@ -232,6 +207,49 @@ int main(void)
                 printf("5. Exit");
                 isExit = true;
                 break;
+#ifdef WITH_CLOUD
+            case 21:
+                printf("Enable Remote Service");
+                if(!IsCloudLoggedin())
+                {
+                    printf("Cloud Login required");
+                    break;
+                }
+                NSConsumerEnableRemoteService(CLOUD_ADDRESS);
+                break;
+            case 31:
+                printf("Remote Server Address: ");
+                gets(CLOUD_ADDRESS);
+
+                printf("Auth Provider(eg. github): ");
+                gets(CLOUD_AUTH_PROVIDER);
+
+                printf("Auth Code: ");
+                gets(CLOUD_AUTH_CODE);
+
+                OCCloudSignup(CLOUD_ADDRESS, OCGetServerInstanceIDString(),
+                    CLOUD_AUTH_PROVIDER, CLOUD_AUTH_CODE, CloudSignupCallback);
+                printf("OCCloudSignup requested");
+                break;
+            case 32:
+                printf("Remote Server Address: ");
+                gets(CLOUD_ADDRESS);
+
+                printf("UID: ");
+                gets(CLOUD_UID);
+
+                printf("ACCESS_TOKEN: ");
+                gets(CLOUD_ACCESS_TOKEN);
+
+                OCCloudLogin(CLOUD_ADDRESS, CLOUD_UID, OCGetServerInstanceIDString(),
+                    CLOUD_ACCESS_TOKEN, CloudLoginoutCallback);
+                printf("OCCloudLogin requested");
+                break;
+            case 33:
+                OCCloudLogout(CLOUD_ADDRESS, CloudLoginoutCallback);
+                printf("OCCloudLogin requested");
+                break;
+#endif
             default:
                 break;
         }
index edd6937..c638d23 100644 (file)
-//******************************************************************\r
-//\r
-// Copyright 2016 Samsung Electronics All Rights Reserved.\r
-//\r
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-//\r
-// Licensed under the Apache License, Version 2.0 (the "License");\r
-// you may not use this file except in compliance with the License.\r
-// You may obtain a copy of the License at\r
-//\r
-//      http://www.apache.org/licenses/LICENSE-2.0\r
-//\r
-// Unless required by applicable law or agreed to in writing, software\r
-// distributed under the License is distributed on an "AS IS" BASIS,\r
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-// See the License for the specific language governing permissions and\r
-// limitations under the License.\r
-//\r
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-\r
-#include <stdio.h>\r
-#include <stdbool.h>\r
-#include <stdlib.h>\r
-#include <unistd.h>\r
-\r
-#include "NSProviderInterface.h"\r
-#include "NSCommon.h"\r
-#include "logger.h"\r
-#include "octypes.h"\r
-#include "pthread.h"\r
-#include "oic_string.h"\r
-#include "oic_malloc.h"\r
-\r
-#define TAG "NSProviderExample"\r
-\r
-// Input the following values to publish resource to cloud\r
-char REMOTE_SERVER_ADDRESS[50];\r
-char mainConsumer[37] = {'\0',};\r
-\r
-extern char *strdup(const char *s);\r
-\r
-bool isExit = false;\r
-\r
-int id;\r
-\r
-void* OCProcessThread(void * ptr)\r
-{\r
-    (void) ptr;\r
-    while (!isExit)\r
-    {\r
-        if (OCProcess() != OC_STACK_OK)\r
-        {\r
-            printf("OCStack process error");\r
-            return NULL;\r
-        }\r
-    }\r
-\r
-    return NULL;\r
-}\r
-\r
-void subscribeRequestCallback(NSConsumer *consumer)\r
-{\r
-    printf("consumer requested to subscribe");\r
-\r
-    printf("NS_APP Consumer Device ID: %s\n", consumer->consumerId);\r
-\r
-    if(mainConsumer[0] == '\0')\r
-    {\r
-        OICStrcpy(mainConsumer, 37, consumer->consumerId);\r
-    }\r
-\r
-    NSAcceptSubscription(consumer, true);\r
-}\r
-\r
-void syncCallback(NSSyncInfo *sync)\r
-{\r
-    printf("sync requested");\r
-\r
-    printf("NS_APP Sync State: %d\n", sync->state);\r
-}\r
-\r
-FILE* server_fopen(const char *path, const char *mode)\r
-{\r
-    (void)path;\r
-    return fopen("oic_ns_provider_db.dat", mode);\r
-}\r
-\r
-void printTopics(NSTopicLL * topics)\r
-{\r
-    if(!topics)\r
-    {\r
-        printf("topics is null\n");\r
-        return;\r
-    }\r
-\r
-    NSTopicLL * iter = topics;\r
-\r
-    while(iter)\r
-    {\r
-        printf("tName = %s, tState = %d\n", iter->topicName, (int)iter->state);\r
-        iter = iter->next;\r
-    }\r
-}\r
-\r
-void removeTopics(NSTopicLL * topics)\r
-{\r
-    if(!topics)\r
-    {\r
-        printf("topics is null\n");\r
-        return;\r
-    }\r
-\r
-    NSTopicLL * iter = topics;\r
-\r
-    while(iter)\r
-    {\r
-        NSTopicLL * del = iter;\r
-        if(del->topicName)\r
-        {\r
-            OICFree(del->topicName);\r
-        }\r
-        iter = iter->next;\r
-\r
-        OICFree(del);\r
-    }\r
-}\r
-\r
-int main()\r
-{\r
-    int num;\r
-    pthread_t processThread;\r
-\r
-    printf("NSStartProvider()\n\n");\r
-\r
-    // open oic_db\r
-    static OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink};\r
-    OCRegisterPersistentStorageHandler(&ps);\r
-\r
-    if (OCInit(NULL, 0, OC_CLIENT_SERVER) != OC_STACK_OK)\r
-    {\r
-        printf("OCStack init error");\r
-        return 0;\r
-    }\r
-\r
-    pthread_create(&processThread, NULL, OCProcessThread, unlink);\r
-\r
-    while (!isExit)\r
-    {\r
-        char dummy;\r
-\r
-        printf("==============================================\n");\r
-        printf("1.  NSStartProvider(Accepter: Provider) \n");\r
-        printf("2.  NSStartProvider(Accepter: Consumer) \n");\r
-        printf("3.  NSSendNotification() \n");\r
-        printf("4.  NSRead() \n");\r
-        printf("5.  NSProviderAddTopic(); \n");\r
-        printf("6.  NSProviderDeleteTopic(); \n");\r
-        printf("7.  NSProviderSelectTopic(); \n");\r
-        printf("8.  NSProviderUnselectTopic(); \n");\r
-        printf("9.  NSProviderGetConsumerTopics(); \n");\r
-        printf("10. NSProviderGetTopics(); \n");\r
-        printf("11. NSStopProvider() \n");\r
-        printf("12. NSProviderEnableRemoteService \n");\r
-        printf("0. Exit() \n");\r
-        printf("==============================================\n");\r
-\r
-        printf("input : ");\r
-\r
-        scanf("%d", &num);\r
-        fflush(stdin);\r
-        scanf("%c", &dummy);\r
-        fflush(stdin);\r
-\r
-        switch (num)\r
-        {\r
-            case 1:\r
-            {\r
-                printf("NSStartProvider(Accepter: Provider)");\r
-                NSProviderConfig config;\r
-                config.policy = true;\r
-                config.subRequestCallback = subscribeRequestCallback;\r
-                config.syncInfoCallback = syncCallback;\r
-                config.userInfo = OICStrdup("OCF_NOTIFICATION");\r
-                NSStartProvider(config);\r
-            }\r
-                break;\r
-\r
-            case 2:\r
-            {\r
-                printf("NSStartProvider(Accepter: Consumer)");\r
-                NSProviderConfig config;\r
-                config.policy = false;\r
-                config.subRequestCallback = subscribeRequestCallback;\r
-                config.syncInfoCallback = syncCallback;\r
-                config.userInfo = OICStrdup("OCF_NOTIFICATION");\r
-                NSStartProvider(config);\r
-            }\r
-                break;\r
-\r
-            case 3:\r
-            {\r
-                printf("NSSendNotification()");\r
-                char title[100];\r
-                char body[100];\r
-                char topic[100];\r
-\r
-                printf("id : %d\n", ++id);\r
-                printf("title : ");\r
-\r
-                gets(title);\r
-\r
-                printf("body : ");\r
-                gets(body);\r
-\r
-                printf("topic : ");\r
-                gets(topic);\r
-\r
-                printf("app - mTitle : %s \n", title);\r
-                printf("app - mContentText : %s \n", body);\r
-                printf("app - topic : %s \n", topic);\r
-\r
-                NSMessage * msg = NSCreateMessage();\r
-\r
-                msg->title = OICStrdup(title);\r
-                msg->contentText = OICStrdup(body);\r
-                msg->sourceName = OICStrdup("OCF");\r
-\r
-                if(topic[0] != '\0')\r
-                {\r
-                    msg->topic = OICStrdup(topic);\r
-                }\r
-\r
-                NSSendMessage(msg);\r
-            }\r
-                break;\r
-\r
-            case 4:\r
-                printf("NSRead\n");\r
-                break;\r
-\r
-            case 5:\r
-                printf("NSProviderAddTopic\n");\r
-                NSProviderAddTopic("OCF_TOPIC1");\r
-                NSProviderAddTopic("OCF_TOPIC2");\r
-                NSProviderAddTopic("OCF_TOPIC3");\r
-                NSProviderAddTopic("OCF_TOPIC4");\r
-                break;\r
-\r
-            case 6:\r
-                printf("NSProviderDeleteTopic\n");\r
-                NSProviderDeleteTopic("OCF_TOPIC2");\r
-                break;\r
-\r
-            case 7:\r
-                printf("NSProviderSelectTopic\n");\r
-                NSProviderSelectTopic(mainConsumer, "OCF_TOPIC1");\r
-                NSProviderSelectTopic(mainConsumer, "OCF_TOPIC2");\r
-                NSProviderSelectTopic(mainConsumer, "OCF_TOPIC3");\r
-                NSProviderSelectTopic(mainConsumer, "OCF_TOPIC4");\r
-                break;\r
-\r
-            case 8:\r
-                printf("NSProviderUnSelectTopic\n");\r
-                NSProviderUnselectTopic(mainConsumer, "OCF_TOPIC1");\r
-                break;\r
-\r
-            case 9:\r
-                printf("NSProviderGetConsumerTopics\n");\r
-                {\r
-                    NSTopicLL * topics = NSProviderGetConsumerTopics(mainConsumer);\r
-                    printTopics(topics);\r
-                    removeTopics(topics);\r
-                }\r
-                break;\r
-\r
-            case 10:\r
-                printf("NSProviderGetConsumerTopics\n");\r
-                {\r
-                    NSTopicLL * topics = NSProviderGetTopics();\r
-                    printTopics(topics);\r
-                    removeTopics(topics);\r
-                }\r
-                break;\r
-\r
-            case 11:\r
-                NSStopProvider();\r
-                break;\r
-\r
-            case 12:\r
-                printf("Remote Server Address: ");\r
-                gets(REMOTE_SERVER_ADDRESS);\r
-\r
-                NSProviderEnableRemoteService(REMOTE_SERVER_ADDRESS);\r
-                break;\r
-            case 0:\r
-                NSStopProvider();\r
-                isExit = true;\r
-                break;\r
-            default:\r
-                printf("Under Construction\n");\r
-                break;\r
-        }\r
-\r
-        printf("\n");\r
-    }\r
-\r
-    return 0;\r
-}\r
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "NSProviderInterface.h"
+#include "NSCommon.h"
+#include "logger.h"
+#include "octypes.h"
+#include "pthread.h"
+#include "oic_string.h"
+#include "oic_malloc.h"
+
+#define TAG "NSProviderExample"
+
+#ifdef WITH_CLOUD
+#include "cloud_connector.h"
+
+// Input the following values to publish resource to cloud
+char REMOTE_SERVER_ADDRESS[50];
+char AUTH_PROVIDER[50];
+char AUTH_CODE[50];
+char UID[50];
+char ACCESS_TOKEN[50];
+#endif
+
+char mainConsumer[37] = {'\0',};
+
+extern char *strdup(const char *s);
+
+bool isExit = false;
+
+int id;
+
+void* OCProcessThread(void * ptr)
+{
+    (void) ptr;
+    while (!isExit)
+    {
+        if (OCProcess() != OC_STACK_OK)
+        {
+            printf("OCStack process error");
+            return NULL;
+        }
+    }
+
+    return NULL;
+}
+
+void subscribeRequestCallback(NSConsumer *consumer)
+{
+    printf("consumer requested to subscribe");
+
+    printf("NS_APP Consumer Device ID: %s\n", consumer->consumerId);
+
+    if(mainConsumer[0] == '\0')
+    {
+        OICStrcpy(mainConsumer, 37, consumer->consumerId);
+    }
+
+    NSAcceptSubscription(consumer, true);
+}
+
+void syncCallback(NSSyncInfo *sync)
+{
+    printf("sync requested");
+
+    printf("NS_APP Sync State: %d\n", sync->state);
+}
+
+FILE* server_fopen(const char *path, const char *mode)
+{
+    (void)path;
+    return fopen("oic_ns_provider_db.dat", mode);
+}
+
+void printTopics(NSTopicLL * topics)
+{
+    if(!topics)
+    {
+        printf("topics is null\n");
+        return;
+    }
+
+    NSTopicLL * iter = topics;
+
+    while(iter)
+    {
+        printf("tName = %s, tState = %d\n", iter->topicName, (int)iter->state);
+        iter = iter->next;
+    }
+}
+
+void removeTopics(NSTopicLL * topics)
+{
+    if(!topics)
+    {
+        printf("topics is null\n");
+        return;
+    }
+
+    NSTopicLL * iter = topics;
+
+    while(iter)
+    {
+        NSTopicLL * del = iter;
+        if(del->topicName)
+        {
+            OICFree(del->topicName);
+        }
+        iter = iter->next;
+
+        OICFree(del);
+    }
+}
+
+int main()
+{
+    int num;
+    pthread_t processThread;
+
+    printf("NSStartProvider()\n\n");
+
+    // open oic_db
+    static OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink};
+    OCRegisterPersistentStorageHandler(&ps);
+
+    if (OCInit(NULL, 0, OC_CLIENT_SERVER) != OC_STACK_OK)
+    {
+        printf("OCStack init error");
+        return 0;
+    }
+
+    pthread_create(&processThread, NULL, OCProcessThread, unlink);
+
+    while (!isExit)
+    {
+        char dummy;
+
+        printf("==============================================\n");
+        printf("1.  NSStartProvider(Accepter: Provider) \n");
+        printf("2.  NSStartProvider(Accepter: Consumer) \n");
+        printf("3.  NSSendNotification() \n");
+        printf("4.  NSRead() \n");
+        printf("5.  NSProviderAddTopic(); \n");
+        printf("6.  NSProviderDeleteTopic(); \n");
+        printf("7.  NSProviderSelectTopic(); \n");
+        printf("8.  NSProviderUnselectTopic(); \n");
+        printf("9.  NSProviderGetConsumerTopics(); \n");
+        printf("10. NSProviderGetTopics(); \n");
+        printf("11. NSStopProvider() \n");
+#ifdef WITH_CLOUD
+        printf("21. NSProviderEnableRemoteService (after login) \n");
+        printf("22. NSProviderDisableRemoteService (after login) \n");
+        printf("31. Cloud Signup \n");
+        printf("32. Cloud Login \n");
+        printf("33. Cloud Logout \n");
+#endif
+        printf("0. Exit() \n");
+        printf("==============================================\n");
+
+        printf("input : ");
+
+        scanf("%d", &num);
+        fflush(stdin);
+        scanf("%c", &dummy);
+        fflush(stdin);
+
+        switch (num)
+        {
+            case 1:
+            {
+                printf("NSStartProvider(Accepter: Provider)");
+                NSProviderConfig config;
+                config.policy = true;
+                config.subRequestCallback = subscribeRequestCallback;
+                config.syncInfoCallback = syncCallback;
+                config.userInfo = OICStrdup("OCF_NOTIFICATION");
+                NSStartProvider(config);
+            }
+                break;
+
+            case 2:
+            {
+                printf("NSStartProvider(Accepter: Consumer)");
+                NSProviderConfig config;
+                config.policy = false;
+                config.subRequestCallback = subscribeRequestCallback;
+                config.syncInfoCallback = syncCallback;
+                config.userInfo = OICStrdup("OCF_NOTIFICATION");
+                NSStartProvider(config);
+            }
+                break;
+
+            case 3:
+            {
+                printf("NSSendNotification()");
+                char title[100];
+                char body[100];
+                char topic[100];
+
+                printf("id : %d\n", ++id);
+                printf("title : ");
+
+                gets(title);
+
+                printf("body : ");
+                gets(body);
+
+                printf("topic : ");
+                gets(topic);
+
+                printf("app - mTitle : %s \n", title);
+                printf("app - mContentText : %s \n", body);
+                printf("app - topic : %s \n", topic);
+
+                NSMessage * msg = NSCreateMessage();
+
+                msg->title = OICStrdup(title);
+                msg->contentText = OICStrdup(body);
+                msg->sourceName = OICStrdup("OCF");
+
+                if(topic[0] != '\0')
+                {
+                    msg->topic = OICStrdup(topic);
+                }
+
+                NSSendMessage(msg);
+            }
+                break;
+
+            case 4:
+                printf("NSRead\n");
+                break;
+
+            case 5:
+                printf("NSProviderAddTopic\n");
+                NSProviderAddTopic("OCF_TOPIC1");
+                NSProviderAddTopic("OCF_TOPIC2");
+                NSProviderAddTopic("OCF_TOPIC3");
+                NSProviderAddTopic("OCF_TOPIC4");
+                break;
+
+            case 6:
+                printf("NSProviderDeleteTopic\n");
+                NSProviderDeleteTopic("OCF_TOPIC2");
+                break;
+
+            case 7:
+                printf("NSProviderSelectTopic\n");
+                NSProviderSelectTopic(mainConsumer, "OCF_TOPIC1");
+                NSProviderSelectTopic(mainConsumer, "OCF_TOPIC2");
+                NSProviderSelectTopic(mainConsumer, "OCF_TOPIC3");
+                NSProviderSelectTopic(mainConsumer, "OCF_TOPIC4");
+                break;
+
+            case 8:
+                printf("NSProviderUnSelectTopic\n");
+                NSProviderUnselectTopic(mainConsumer, "OCF_TOPIC1");
+                break;
+
+            case 9:
+                printf("NSProviderGetConsumerTopics\n");
+                {
+                    NSTopicLL * topics = NSProviderGetConsumerTopics(mainConsumer);
+                    printTopics(topics);
+                    removeTopics(topics);
+                }
+                break;
+
+            case 10:
+                printf("NSProviderGetConsumerTopics\n");
+                {
+                    NSTopicLL * topics = NSProviderGetTopics();
+                    printTopics(topics);
+                    removeTopics(topics);
+                }
+                break;
+
+            case 11:
+                NSStopProvider();
+                break;
+#ifdef WITH_CLOUD
+            case 21:
+                printf("Enable Remote Service");
+                if(!IsCloudLoggedin())
+                {
+                    printf("Login required");
+                    break;
+                }
+                NSProviderEnableRemoteService(REMOTE_SERVER_ADDRESS);                
+                break;
+
+            case 22:
+                printf("Disable Remote Service");
+                if(!IsCloudLoggedin())
+                {
+                    printf("Login required");
+                    break;
+                }
+                NSProviderDisableRemoteService(REMOTE_SERVER_ADDRESS);
+                break;
+
+            case 31:
+                printf("Remote Server Address: ");
+                gets(REMOTE_SERVER_ADDRESS);
+
+                printf("Auth Provider(eg. github): ");
+                gets(AUTH_PROVIDER);
+
+                printf("Auth Code: ");
+                gets(AUTH_CODE);
+
+                OCCloudSignup(REMOTE_SERVER_ADDRESS, OCGetServerInstanceIDString(),
+                    AUTH_PROVIDER, AUTH_CODE, CloudSignupCallback);
+                printf("OCCloudSignup requested");
+                break;
+            case 32:
+                printf("Remote Server Address: ");
+                gets(REMOTE_SERVER_ADDRESS);
+
+                printf("UID: ");
+                gets(UID);
+
+                printf("ACCESS_TOKEN: ");
+                gets(ACCESS_TOKEN);
+
+                OCCloudLogin(REMOTE_SERVER_ADDRESS, UID, OCGetServerInstanceIDString(),
+                    ACCESS_TOKEN, CloudLoginoutCallback);
+                printf("OCCloudLogin requested");
+                break;
+            case 33:
+                OCCloudLogout(REMOTE_SERVER_ADDRESS, CloudLoginoutCallback);
+                printf("OCCloudLogin requested");
+                break;
+#endif
+            case 0:
+                NSStopProvider();
+                isExit = true;
+                break;
+            default:
+                break;
+        }
+
+        printf("\n");
+    }
+
+    return 0;
+}
diff --git a/service/notification/src/common/NSCloudConnector.c b/service/notification/src/common/NSCloudConnector.c
deleted file mode 100644 (file)
index f2db819..0000000
+++ /dev/null
@@ -1,301 +0,0 @@
-//******************************************************************
-//
-// Copyright 2016 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#include "NSCloudConnector.h"
-#include "NSUtil.h"
-
-#include <stdarg.h>
-#include <stdlib.h>
-
-#include "oic_string.h"
-#include "oic_malloc.h"
-
-#include "ocpayload.h"
-
-#include "rdpayload.h"
-/*
-#define OC_RD_PUBLISH_TTL 86400
-#define DEFAULT_CONTEXT_VALUE 0x99
-
-#define DEFAULT_COAP_TCP_HOST "coap+tcp://"
-#define DEFAULT_COAP_TCP_PORT 5683
-
-#define DEFAULT_COAP_TCP_SECURE_HOST "coaps+tcp://"
-#define DEFAULT_COAP_TCP_SECURE_PORT 5864
-
-#define DEFAULT_AUTH_REGISTER_LOGIN "/oic/auth/?reqtype=register"
-#define DEFAULT_AUTH_LOGIN "/oic/auth/?reqtype=login"
-#define DEFAULT_AUTH_LOGOUT "/oic/auth/?reqtype=logout"
-*/
-static OCStackResult createStringLL(uint8_t numElements, OCResourceHandle handle,
-                                    const char *(*getValue)(OCResourceHandle handle, uint8_t i), OCStringLL **stringLL)
-{
-    for (uint8_t i = 0; i < numElements; ++i)
-    {
-        const char *value = getValue(handle, i);
-        if (!*stringLL)
-        {
-            *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
-            if (!*stringLL)
-            {
-                return OC_STACK_NO_MEMORY;
-            }
-            (*stringLL)->value = OICStrdup(value);
-            if (!(*stringLL)->value)
-            {
-                return OC_STACK_NO_MEMORY;
-            }
-        }
-        else
-        {
-            OCStringLL *cur = *stringLL;
-            while (cur->next)
-            {
-                cur = cur->next;
-            }
-            cur->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
-            if (!cur->next)
-            {
-                return OC_STACK_NO_MEMORY;
-            }
-            cur->next->value = OICStrdup(value);
-            if (!cur->next->value)
-            {
-                return OC_STACK_NO_MEMORY;
-            }
-        }
-    }
-    return OC_STACK_OK;
-}
-
-OCStackResult NSCloudRegisterLogin(const char *host, const char *auth_provider,
-                                   const char *auth_code, OCClientResponseHandler response)
-{
-    char    targetUri[MAX_URI_LENGTH * 2] = { 0, };
-    snprintf(targetUri, MAX_URI_LENGTH * 2, "%s%s", host, DEFAULT_AUTH_REGISTER_LOGIN);
-
-    OCCallbackData cbData;
-    memset(&cbData, 0, sizeof(OCCallbackData));
-    cbData.cb = response;
-    cbData.cd = NULL;
-    cbData.context = (void *)DEFAULT_CONTEXT_VALUE;
-
-    OCRepPayload *registerPayload = OCRepPayloadCreate();
-    if (!registerPayload)
-    {
-        goto no_memory;
-    }
-
-    OCRepPayloadSetPropString(registerPayload, "authprovider", auth_provider);
-    OCRepPayloadSetPropString(registerPayload, "authcode", auth_code);
-
-    return OCDoResource(NULL, OC_REST_POST, targetUri, NULL, (OCPayload *)registerPayload,
-                        CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
-
-no_memory:
-    OCRepPayloadDestroy(registerPayload);
-    return OC_STACK_NO_MEMORY;
-}
-
-OCStackResult NSCloudLoginout(const char *host, const char *query, const char *auth_session,
-                              OCClientResponseHandler response)
-{
-    char    targetUri[MAX_URI_LENGTH * 2] = { 0, };
-    snprintf(targetUri, MAX_URI_LENGTH * 2, "%s%s", host, query);
-
-    OCCallbackData cbData;
-    memset(&cbData, 0, sizeof(OCCallbackData));
-    cbData.cb = response;
-    cbData.cd = NULL;
-    cbData.context = (void *)DEFAULT_CONTEXT_VALUE;
-
-    OCRepPayload *loginoutPayload = OCRepPayloadCreate();
-    if (!loginoutPayload)
-    {
-        goto no_memory;
-    }
-
-    OCRepPayloadSetPropString(loginoutPayload, "session", auth_session);
-
-    return OCDoResource(NULL, OC_REST_POST, targetUri, NULL, (OCPayload *)loginoutPayload,
-                        CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
-
-no_memory:
-    OCRepPayloadDestroy(loginoutPayload);
-    return OC_STACK_NO_MEMORY;
-}
-
-
-OCStackResult NSCloudLogin(const char *host, const char *auth_session,
-                           OCClientResponseHandler response)
-{
-    return NSCloudLoginout(host, DEFAULT_AUTH_LOGIN, auth_session, response);
-}
-
-OCStackResult NSCloudLogout(const char *host, const char *auth_session,
-                            OCClientResponseHandler response)
-{
-    return NSCloudLoginout(host, DEFAULT_AUTH_LOGOUT, auth_session, response);
-}
-
-
-static unsigned char gInstanceId[37] = {0, };
-OCStackResult NSCloudPublish(const char *host, const char *query,
-                             OCClientResponseHandler response, int numArg, ...)
-{
-    char    targetUri[MAX_URI_LENGTH * 2] = { 0, };
-    snprintf(targetUri, MAX_URI_LENGTH * 2, "%s%s", host, query);
-
-    // Gather all resources locally and do publish
-    OCCallbackData cbData;
-    memset(&cbData, 0, sizeof(OCCallbackData));
-    cbData.cb = response;
-    cbData.cd = NULL;
-    cbData.context = (void *)DEFAULT_CONTEXT_VALUE;
-
-    OCTagsPayload *tagsPayload = NULL;
-    OCLinksPayload *linksPayload = NULL;
-    OCStringLL *rt = NULL;
-    OCStringLL *itf = NULL;
-    OCStringLL *mt = NULL;
-
-    OCRDPayload *rdPayload = OCRDPayloadCreate();
-    if (!rdPayload)
-    {
-        goto no_memory;
-    }
-
-    const unsigned char *id = (unsigned char *)OCGetServerInstanceIDString();
-    NS_LOG_V(DEBUG, "DeviceID: %s", id);
-    tagsPayload = OCCopyTagsResources(NULL, id, OC_RD_PUBLISH_TTL);
-    if (!tagsPayload)
-    {
-        goto no_memory;
-    }
-
-    va_list arguments;
-    va_start(arguments, numArg);
-
-    for (int j = 0; j < numArg; j++)
-    {
-        OCResourceHandle handle = va_arg(arguments, OCResourceHandle);
-        if (handle)
-        {
-            rt = itf = mt = NULL;
-            const char *uri = OCGetResourceUri(handle);
-            uint8_t numElement;
-            if (OC_STACK_OK == OCGetNumberOfResourceTypes(handle, &numElement))
-            {
-                OCStackResult res = createStringLL(numElement, handle, OCGetResourceTypeName, &rt);
-                if (res != OC_STACK_OK || !rt)
-                {
-                    goto no_memory;
-                }
-            }
-
-            if (OC_STACK_OK == OCGetNumberOfResourceInterfaces(handle, &numElement))
-            {
-                OCStackResult res = createStringLL(numElement, handle, OCGetResourceInterfaceName, &itf);
-                if (res != OC_STACK_OK || !itf)
-                {
-                    goto no_memory;
-                }
-            }
-
-            mt = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
-            if (!mt)
-            {
-                goto no_memory;
-            }
-            mt->value = OICStrdup("application/cbor");
-            if (!mt->value)
-            {
-                goto no_memory;
-            }
-
-            if (!linksPayload)
-            {
-                /* Need to update with Cloud Interface Implementation.
-                 *
-               linksPayload = OCCopyLinksResources(uri, rt, itf, NULL, 0, NULL,
-                                                    NULL, j, mt);;
-                if (!linksPayload)
-                {
-                    goto no_memory;
-                }
-                */
-            }
-            else
-            {
-                OCLinksPayload *temp = linksPayload;
-                while (temp->next)
-                {
-                    temp = temp->next;
-                }
-                /* Need to update with Cloud Interface Implementation.
-                 *
-                temp->next = OCCopyLinksResources(uri, rt, itf, NULL, 0, NULL,
-                                                  NULL, j, mt);
-                if (!temp->next)
-                {
-                    goto no_memory;
-                }
-                */
-            }
-            OCFreeOCStringLL(rt);
-            OCFreeOCStringLL(itf);
-            OCFreeOCStringLL(mt);
-        }
-    }
-    va_end(arguments);
-
-    rdPayload->rdPublish = OCCopyCollectionResource(tagsPayload, linksPayload);
-    if (!rdPayload->rdPublish)
-    {
-        goto no_memory;
-    }
-
-    return OCDoResource(NULL, OC_REST_POST, targetUri, NULL, (OCPayload *)rdPayload,
-                        CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
-
-no_memory:
-    va_end(arguments);
-    if (rt)
-    {
-        OCFreeOCStringLL(rt);
-    }
-    if (itf)
-    {
-        OCFreeOCStringLL(itf);
-    }
-    if (mt)
-    {
-        OCFreeOCStringLL(mt);
-    }
-    if (tagsPayload)
-    {
-        OCFreeTagsResource(tagsPayload);
-    }
-    if (linksPayload)
-    {
-        OCFreeLinksResource(linksPayload);
-    }
-    OCRDPayloadDestroy(rdPayload);
-    return OC_STACK_NO_MEMORY;
-}
diff --git a/service/notification/src/common/NSCloudConnector.h b/service/notification/src/common/NSCloudConnector.h
deleted file mode 100644 (file)
index 8988f76..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-//******************************************************************
-//
-// Copyright 2016 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef _CLOUD_CONNECTOR_H_
-#define _CLOUD_CONNECTOR_H_
-
-#include "ocstack.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
-
-#define CLOUD_IP "52.69.149.85"
-#define CLOUD_PORT "5683"
-
-#define OC_RD_PUBLISH_TTL 86400
-#define DEFAULT_CONTEXT_VALUE 0x99
-
-#define DEFAULT_COAP_TCP_HOST "coap+tcp://"
-#define DEFAULT_COAP_TCP_PORT 5683
-
-#define DEFAULT_COAP_TCP_SECURE_HOST "coaps+tcp://"
-#define DEFAULT_COAP_TCP_SECURE_PORT 5864
-
-#define DEFAULT_AUTH_REGISTER_LOGIN "/oic/auth/?reqtype=register"
-#define DEFAULT_AUTH_LOGIN "/oic/auth/?reqtype=login"
-#define DEFAULT_AUTH_LOGOUT "/oic/auth/?reqtype=logout"
-
-OCStackResult NSCloudRegisterLogin(const char *host, const char *auth_provider,
-                                   const char *auth_code, OCClientResponseHandler response);
-OCStackResult NSCloudLogin(const char *host, const char *auth_session,
-                           OCClientResponseHandler response);
-OCStackResult NSCloudLogout(const char *host, const char *auth_session,
-                            OCClientResponseHandler response);
-OCStackResult NSCloudPublish(const char *host, const char *query,
-                             OCClientResponseHandler response, int numArg, ...);
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
-
-#endif
index 48732cd..a6d4828 100644 (file)
@@ -75,7 +75,10 @@ NSResult NSConsumerEnableRemoteService(char *serverAddress)
     bool isStartedConsumer = NSIsStartedConsumer();
     NS_VERIFY_NOT_NULL(isStartedConsumer == true ? (void *) 1 : NULL, NS_ERROR);
 
-    NSTask * discoverTask = NSMakeTask(TASK_CONSUMER_REQ_DISCOVER, (void *)serverAddress);
+    char * queryAddr = OICStrdup(serverAddress);
+    NS_VERIFY_NOT_NULL(queryAddr, NS_ERROR);
+
+    NSTask * discoverTask = NSMakeTask(TASK_CONSUMER_REQ_DISCOVER, (void *)queryAddr);
     NS_VERIFY_NOT_NULL(discoverTask, NS_ERROR);
 
     return NSConsumerPushEvent(discoverTask);
index 7648278..cddb775 100644 (file)
@@ -132,7 +132,7 @@ NSResult NSProviderEnableRemoteService(char *serverAddress)
     NS_LOG(DEBUG, "NSProviderEnableRemoteService - IN");\r
     pthread_mutex_lock(&nsInitMutex);\r
 \r
-if(!initProvider)\r
+    if(!initProvider)\r
     {\r
         NS_LOG(DEBUG, "Provider service has not been started yet");\r
         pthread_mutex_unlock(&nsInitMutex);\r
index ddf5671..0c55045 100644 (file)
@@ -34,7 +34,6 @@
 #include "oic_malloc.h"\r
 #include "NSUtil.h"\r
 #include "NSStorageAdapter.h"\r
-#include "NSCloudConnector.h"\r
 \r
 OCEntityHandlerResult NSEntityHandlerNotificationCb(OCEntityHandlerFlag flag,\r
         OCEntityHandlerRequest *entityHandlerRequest, void* callback);\r
index 9094528..fa26e0f 100644 (file)
@@ -27,11 +27,16 @@ NSSyncResource NotificationSyncResource;
 NSTopicResource NotificationTopicResource;
 
 #ifdef RD_CLIENT
+#define DEFAULT_CONTEXT_VALUE 0x99
+
 OCStackApplicationResult NSHandlePublishCb(void *ctx, OCDoHandle handle,
     OCClientResponse *clientResponse)
 {
     (void) handle;
-    (void) ctx;
+    if(ctx != (void *)DEFAULT_CONTEXT_VALUE)
+    {
+        NS_LOG(DEBUG, "Invalid Publish callback received");
+    } 
 
     NS_LOG_V(DEBUG, "Publish resource response received code: %d", clientResponse->result);
 
@@ -44,13 +49,18 @@ NSResult NSPublishResourceToCloud(char *serverAddress)
     NS_LOG(DEBUG, "NSPublishResourceToCloud - IN");
     NS_LOG_V(DEBUG, "Remote Server Address: %s", serverAddress);
 
+    OCCallbackData cbData;
+    cbData.cb = NSHandlePublishCb;
+    cbData.context = (void *)DEFAULT_CONTEXT_VALUE;
+    cbData.cd = NULL;
+
     OCResourceHandle resourceHandles[1] = {NotificationResource.handle};
     OCStackResult res = OCRDPublish(serverAddress, CT_ADAPTER_TCP, resourceHandles, 1,
-            &NSHandlePublishCb, OC_LOW_QOS);
+            &cbData, OC_LOW_QOS);
 
     if (res != OC_STACK_OK)
     {
-        NS_LOG(DEBUG, "Unable to publish resources to cloud");
+        NS_LOG_V(DEBUG, "Unable to publish resources to cloud: %d", res);
     }
 
     NS_LOG(DEBUG, "NSPublishResourceToCloud - OUT");
@@ -58,6 +68,7 @@ NSResult NSPublishResourceToCloud(char *serverAddress)
 }
 #endif
 
+
 NSResult NSCreateResource(char *uri)
 {
     NS_LOG(DEBUG, "NSCreateResource - IN");