To get account information from .ini file 72/127472/1 accepted/tizen/unified/20170427.164153 submit/tizen/20170427.102535
authorSangkoo Kim <sangkoo.kim@samsung.com>
Thu, 27 Apr 2017 10:16:53 +0000 (19:16 +0900)
committerSangkoo Kim <sangkoo.kim@samsung.com>
Thu, 27 Apr 2017 10:16:53 +0000 (19:16 +0900)
Change-Id: I5b623756e3ff957f0556b7f1298b12b5ba0682f8
Signed-off-by: Sangkoo Kim <sangkoo.kim@samsung.com>
inc/ua_client.h
src/ua_client.cpp

index e0e2340efaaf920c804cbdfdca19a075752481c5..472fac7be0833a9809f715ba5f09869780e717e6 100644 (file)
@@ -28,6 +28,11 @@ typedef struct {
        char *ocf_server;
 } ua_device_info_s;
 
+typedef struct {
+       char *account;
+       char *auth_code;
+} ua_account_info_s;
+
 typedef enum {
        UA_HTTP_GET = 0,
        UA_HTTP_POST,
index aa453fd4d4c8c8cdcc26ebf43d4bbbf1842f1dd3..09e10c230d19ac612f60b91bb74be8ad20fd8b56 100755 (executable)
@@ -585,6 +585,60 @@ static void _get_wifi_info(ua_wifi_info_s *wifi)
 #endif
 
 
+static void _get_account_info(ua_account_info_s *account_info)
+{
+       GKeyFile *keyfile;
+       GKeyFileFlags flags = G_KEY_FILE_NONE;
+       GError *error = NULL;
+       char file_path[256] = {0,};
+
+       keyfile = g_key_file_new();
+
+       snprintf(file_path, sizeof(file_path), "%s/%s", OC_CONTROLEE_DATA_FILE_PATH, "account_info.ini");
+
+       if (!g_key_file_load_from_file(keyfile, file_path, flags, &error)) {
+               UA_LOG("error=[%s]", error->message);
+       } else {
+               account_info->account = g_key_file_get_string(keyfile, "account_info", "account", NULL);
+               account_info->auth_code = g_key_file_get_string(keyfile, "account_info", "auth_code", NULL);
+
+               g_key_file_unref(keyfile);
+       }
+
+       UA_LOG("account=[%s]", account_info->account);
+       UA_LOG("auth_code=[%s]", account_info->auth_code);
+}
+
+
+void _free_device_info(ua_device_info_s *device)
+{
+       g_free(device->manufacturer);
+       g_free(device->model_name);
+       g_free(device->firmware_ver);
+       g_free(device->firmware_update_state);
+       g_free(device->uuid);
+       g_free(device->access_token);
+       g_free(device->content_server);
+       g_free(device->ocf_server);
+       g_free(device);
+}
+
+void _free_account_info(ua_account_info_s *account_info)
+{
+       g_free(account_info->account);
+       g_free(account_info->auth_code);
+       g_free(account_info);
+}
+
+#ifdef _WIFI_AUTO_CONNECT_
+void _free_wifi_info(ua_wifi_info_s *wifi_info)
+{
+       g_free(wifi_info->ap_name);
+       g_free(wifi_info->ap_pwd);
+       g_free(wifi_info);
+}
+#endif
+
 void onPublish(const OCRepresentation &, const int &eCode)
 {
     UA_LOG("Publish resource response received, code: %d", eCode);
@@ -823,12 +877,6 @@ static const char *__test_convert_error_to_string(wifi_manager_error_e err_type)
        }
 }
 
-void _free_wifi_info(ua_wifi_info_s *wifi_info)
-{
-       g_free(wifi_info->ap_name);
-       g_free(wifi_info->ap_pwd);
-       g_free(wifi_info);
-}
 
 void _wifi_connection_state_changed_cb(wifi_manager_connection_state_e state, wifi_manager_ap_h ap, void *user_data)
 {
@@ -1151,10 +1199,25 @@ void *_start_ua_client(void *data)
        }
 #endif
 
+       // For TDC
+       ua_account_info_s *account_info = (ua_account_info_s *)calloc(1, sizeof(ua_account_info_s));
+
+       if (account_info) {
+               _get_account_info(account_info);
+               if (account_info->account == NULL || strlen(account_info->account) <= 0) {
+                       UA_LOG("There is no account information!");
+                       _free_account_info(account_info);
+                       return NULL;
+               }
+       } else {
+               UA_LOG("account_info is NULL!");
+               return NULL;
+       }
+
     try {
         if (device->uuid == NULL || (device->uuid && strlen(device->uuid) == 0)) {
             UA_LOG("Sign-up...");
-            accountMgr->signUp("tdc", "11223344", &handleSignupCB);
+            accountMgr->signUp(account_info->account, account_info->auth_code, &handleSignupCB);
             g_callbackLock.wait(lock);
             UA_LOG("Sign-In...");
             accountMgr->signIn(g_uid, g_accesstoken, &handleSigninCB);
@@ -1162,7 +1225,7 @@ void *_start_ua_client(void *data)
         } else {
 #if 1 // FOR TDC
             UA_LOG("Sign-up...");
-            accountMgr->signUp("tdc", "11223344", &handleSignupCB);
+            accountMgr->signUp(account_info->account, account_info->auth_code, &handleSignupCB);
             g_callbackLock.wait(lock);
             UA_LOG("Sign-In...");
             accountMgr->signIn(g_uid, g_accesstoken, &handleSigninCB);
@@ -1178,9 +1241,12 @@ void *_start_ua_client(void *data)
     }
     catch (exception& e){
         UA_LOG("Authentication failed");
+        _free_account_info(account_info);
         return NULL;
     }
 
+    _free_account_info(account_info);
+
     UA_LOG("Registering firmware resources to platform...");
 
        OCStackResult result = OC_STACK_ERROR;
@@ -1333,15 +1399,7 @@ int main(int argc, char *argv[])
        UA_LOG("Fail to start ua_client");
     }
 
-       g_free(device->manufacturer);
-       g_free(device->model_name);
-       g_free(device->firmware_ver);
-       g_free(device->firmware_update_state);
-       g_free(device->uuid);
-       g_free(device->access_token);
-       g_free(device->content_server);
-       g_free(device->ocf_server);
-       g_free(device);
+    _free_device_info(device);
 #ifdef _WIFI_AUTO_CONNECT_
        _free_wifi_info(wifi_info);
 #endif