static sqlite3* g_hAccountDB2 = NULL;
static sqlite3* g_hAccountGlobalDB = NULL;
static sqlite3* g_hAccountGlobalDB2 = NULL;
-pthread_mutex_t account_mutex = PTHREAD_MUTEX_INITIALIZER;
-pthread_mutex_t account_global_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t account_mutex = PTHREAD_MUTEX_INITIALIZER;
//static char *_account_dup_text(const char *text_data);
static int _account_insert_custom(account_s *account, int account_id);
return TRUE;
}
-
-static int _account_compare_old_record_by_user_name(account_s *new_account, const char* user_name, const char* package_name)
+static void _account_compare_new_and_old_account_properties(account_s** new_account, account_s* old_account)
{
- int error_code = _ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
- account_s *old_account = NULL;
-
- ACCOUNT_RETURN_VAL((new_account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
- ACCOUNT_RETURN_VAL((user_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
- ACCOUNT_RETURN_VAL((package_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-
- old_account = (account_s*)calloc(1, sizeof(account_s));
- if (!old_account) {
- ACCOUNT_FATAL("Memory alloc fail\n");
- return _ACCOUNT_ERROR_OUT_OF_MEMORY;
- }
-
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE user_name = '%s' and package_name='%s'", ACCOUNT_TABLE, user_name, package_name);
- hstmt = _account_prepare_query(g_hAccountDB, query);
-
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
-
- while (rc == SQLITE_ROW) {
- _account_convert_column_to_account(hstmt, old_account);
- rc = _account_query_step(hstmt);
+ if ((*new_account) == NULL || old_account == NULL) {
+ _ERR("invalid input params");
+ return;
}
- rc = _account_query_finalize(hstmt);
- ACCOUNT_CATCH_ERROR((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- // get capability
- error_code = _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, old_account->id, (void*)old_account, false);
- ACCOUNT_CATCH_ERROR((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("account_query_capability_by_account_id error"));
-
- // get custom text
- error_code = _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, old_account->id, (void*)old_account, false);
- ACCOUNT_CATCH_ERROR((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("_account_query_custom_by_account_id error"));
-
// compare
- new_account->id = old_account->id;
+ (*new_account)->id = old_account->id;
//user name
- if (!new_account->user_name) {
+ if (!(*new_account)->user_name) {
if (old_account->user_name)
- new_account->user_name = _account_dup_text(old_account->user_name);
+ (*new_account)->user_name = _account_dup_text(old_account->user_name);
}
// display name
- if (!new_account->display_name) {
+ if (!(*new_account)->display_name) {
if (old_account->display_name)
- new_account->display_name = _account_dup_text(old_account->display_name);
+ (*new_account)->display_name = _account_dup_text(old_account->display_name);
}
// email address
- if (!new_account->email_address) {
+ if (!(*new_account)->email_address) {
if (old_account->email_address)
- new_account->email_address = _account_dup_text(old_account->email_address);
+ (*new_account)->email_address = _account_dup_text(old_account->email_address);
}
// domain name
- if (!new_account->domain_name) {
+ if (!(*new_account)->domain_name) {
if (old_account->domain_name)
- new_account->domain_name = _account_dup_text(old_account->domain_name);
+ (*new_account)->domain_name = _account_dup_text(old_account->domain_name);
}
// icon path
- if (!new_account->icon_path) {
+ if (!(*new_account)->icon_path) {
if (old_account->icon_path)
- new_account->icon_path = _account_dup_text(old_account->icon_path);
+ (*new_account)->icon_path = _account_dup_text(old_account->icon_path);
}
// source
- if (!new_account->source) {
+ if (!(*new_account)->source) {
if (old_account->source)
- new_account->source = _account_dup_text(old_account->source);
+ (*new_account)->source = _account_dup_text(old_account->source);
}
- _ACCOUNT_FREE(new_account->package_name);
- new_account->package_name = _account_dup_text(old_account->package_name);
+ _ACCOUNT_FREE((*new_account)->package_name);
+ (*new_account)->package_name = _account_dup_text(old_account->package_name);
// access token
- if (!new_account->access_token) {
+ if (!(*new_account)->access_token) {
if (old_account->access_token)
- new_account->access_token = _account_dup_text(old_account->access_token);
+ (*new_account)->access_token = _account_dup_text(old_account->access_token);
}
// auth type
- if (new_account->auth_type == _ACCOUNT_AUTH_TYPE_INVALID)
- new_account->auth_type = old_account->auth_type;
+ if ((*new_account)->auth_type == _ACCOUNT_AUTH_TYPE_INVALID)
+ (*new_account)->auth_type = old_account->auth_type;
//secret
- if (new_account->secret == _ACCOUNT_SECRECY_INVALID)
- new_account->secret = old_account->secret;
+ if ((*new_account)->secret == _ACCOUNT_SECRECY_INVALID)
+ (*new_account)->secret = old_account->secret;
// sync support
- if (new_account->sync_support == _ACCOUNT_SYNC_INVALID)
- new_account->sync_support = old_account->sync_support;
+ if ((*new_account)->sync_support == _ACCOUNT_SYNC_INVALID)
+ (*new_account)->sync_support = old_account->sync_support;
// TODO user text
int i;
for (i = 0; i < USER_TXT_CNT; i++) {
- if (!new_account->user_data_txt[i]) {
+ if (!(*new_account)->user_data_txt[i]) {
if (old_account->user_data_txt[i])
- new_account->user_data_txt[i] = _account_dup_text(old_account->user_data_txt[i]);
+ (*new_account)->user_data_txt[i] = _account_dup_text(old_account->user_data_txt[i]);
}
}
// TODO user int
for (i = 0; i < USER_INT_CNT; i++) {
- if (new_account->user_data_int[i] == 0)
- new_account->user_data_int[i] = old_account->user_data_int[i];
+ if ((*new_account)->user_data_int[i] == 0)
+ (*new_account)->user_data_int[i] = old_account->user_data_int[i];
+ }
+
+ return;
+}
+
+
+static int _account_compare_old_record_by_user_name(account_s *new_account, const char* user_name, const char* package_name)
+{
+ int error_code = _ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
+ account_s *old_account = NULL;
+
+ ACCOUNT_RETURN_VAL((new_account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
+ ACCOUNT_RETURN_VAL((user_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
+ ACCOUNT_RETURN_VAL((package_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+
+ old_account = (account_s*)calloc(1, sizeof(account_s));
+ if (!old_account) {
+ ACCOUNT_FATAL("Memory alloc fail\n");
+ return _ACCOUNT_ERROR_OUT_OF_MEMORY;
+ }
+
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE user_name = '%s' and package_name='%s'", ACCOUNT_TABLE, user_name, package_name);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
+
+ rc = _account_query_step(hstmt);
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+ while (rc == SQLITE_ROW) {
+ _account_convert_column_to_account(hstmt, old_account);
+ rc = _account_query_step(hstmt);
}
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_CATCH_ERROR((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
+
+ // get capability
+ error_code = _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, old_account->id, (void*)old_account, false);
+ ACCOUNT_CATCH_ERROR((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("account_query_capability_by_account_id error"));
+
+ // get custom text
+ error_code = _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, old_account->id, (void*)old_account, false);
+ ACCOUNT_CATCH_ERROR((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("_account_query_custom_by_account_id error"));
+
+ _account_compare_new_and_old_account_properties(&new_account, old_account);
+
CATCH:
if (old_account)
_account_free_account_with_items(old_account);
error_code = _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, old_account->id, (void*)old_account, false);
ACCOUNT_CATCH_ERROR((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("_account_query_custom_by_account_id error"));
- // compare
-
- new_account->id = old_account->id;
-
- //user name
- if (!new_account->user_name) {
- if (old_account->user_name)
- new_account->user_name = _account_dup_text(old_account->user_name);
- }
-
- // display name
- if (!new_account->display_name) {
- if (old_account->display_name)
- new_account->display_name = _account_dup_text(old_account->display_name);
- }
-
- // email address
- if (!new_account->email_address) {
- if (old_account->email_address)
- new_account->email_address = _account_dup_text(old_account->email_address);
- }
-
- // domain name
- if (!new_account->domain_name) {
- if (old_account->domain_name)
- new_account->domain_name = _account_dup_text(old_account->domain_name);
- }
-
- // icon path
- if (!new_account->icon_path) {
- if (old_account->icon_path)
- new_account->icon_path = _account_dup_text(old_account->icon_path);
- }
-
- // source
- if (!new_account->source) {
- if (old_account->source)
- new_account->source = _account_dup_text(old_account->source);
- }
-
- _ACCOUNT_FREE(new_account->package_name);
- new_account->package_name = _account_dup_text(old_account->package_name);
-
- // access token
- if (!new_account->access_token) {
- if (old_account->access_token)
- new_account->access_token = _account_dup_text(old_account->access_token);
- }
-
- // user text
- int i;
- for (i = 0; i < USER_TXT_CNT; i++) {
- if (!new_account->user_data_txt[i]) {
- if (old_account->user_data_txt[i])
- new_account->user_data_txt[i] = _account_dup_text(old_account->user_data_txt[i]);
- }
- }
-
- // auth type
- if (new_account->auth_type == _ACCOUNT_AUTH_TYPE_INVALID)
- new_account->auth_type = old_account->auth_type;
-
- // secret
- if (new_account->secret == _ACCOUNT_SECRECY_INVALID)
- new_account->secret = old_account->secret;
-
- // sync support
- if (new_account->sync_support == _ACCOUNT_SYNC_INVALID)
- new_account->sync_support = old_account->sync_support;
-
- // user int
- for (i = 0; i < USER_INT_CNT; i++) {
- if (new_account->user_data_int[i] == 0)
- new_account->user_data_int[i] = old_account->user_data_int[i];
- }
+ _account_compare_new_and_old_account_properties(&new_account, old_account);
CATCH:
if (old_account)