diff options
-rw-r--r-- | inc/ua_client.h | 5 | ||||
-rwxr-xr-x | src/ua_client.cpp | 92 |
2 files changed, 80 insertions, 17 deletions
diff --git a/inc/ua_client.h b/inc/ua_client.h index e0e2340..472fac7 100644 --- a/inc/ua_client.h +++ b/inc/ua_client.h @@ -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, diff --git a/src/ua_client.cpp b/src/ua_client.cpp index aa453fd..09e10c2 100755 --- a/src/ua_client.cpp +++ b/src/ua_client.cpp @@ -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 |