4 * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Tarun Kumar <tarun.kr@samsung.com>, Sukumar Moharana <msukumar@samsung.com>, Wonyoung Lee <wy1115.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
30 #include <account-private.h>
37 #define LOG_TAG "ACCOUNT"
39 #define ACCOUNT_DLOG_USE
40 #ifdef ACCOUNT_DLOG_USE
41 #define ACCOUNT_DEBUG(fmt, arg...) \
42 LOGD(": " fmt "\n", ##arg);
44 #define ACCOUNT_DEBUG(fmt, arg...) \
45 printf(": " fmt "\n", ##arg);
48 #define ACCOUNT_RETURN_VAL(eval, expr, ret_val, X)\
57 #define ACCOUNT_SNPRINTF(dest,size,format,arg...) \
59 snprintf(dest,size-1,format,##arg); \
61 /* If the same pointer is passed to free twice, known as a double free. To avoid this, set pointers to
62 NULL after passing them to free: free(NULL) is safe (it does nothing).
65 #define ACCOUNT_MEMSET(dest,value,size) \
67 memset(dest,value,size); \
70 #define ACCOUNT_CATCH_ERROR(eval, expr, error_val, X) \
74 error_code = (error_val);\
81 static sqlite3* g_hAccountDB = NULL;
82 static int g_refCntDB = 0;
83 pthread_mutex_t account_mutex = PTHREAD_MUTEX_INITIALIZER;
85 static int _account_gslist_free(GSList* list);
86 static int _account_glist_free(GList* list);
88 static const char *_account_db_err_msg()
90 assert(NULL != g_hAccountDB);
91 return sqlite3_errmsg(g_hAccountDB);
94 static int _account_get_record_count(char* query)
98 account_stmt pStmt = NULL;
100 assert(NULL != query);
101 assert(NULL != g_hAccountDB);
102 rc = sqlite3_prepare_v2(g_hAccountDB, query, strlen(query), &pStmt, NULL);
104 rc = sqlite3_step(pStmt);
105 if (SQLITE_ROW != rc) {
106 ACCOUNT_DEBUG("sqlite3_step() failed(%d, %s).", rc, _account_db_err_msg());
107 sqlite3_finalize(pStmt);
108 return ACCOUNT_ERROR_DB_FAILED;
111 ncount = sqlite3_column_int(pStmt, 0);
113 ACCOUNT_DEBUG("count : %d, End", ncount);
114 sqlite3_finalize(pStmt);
119 static int _account_execute_query(char *query)
122 char* pszErrorMsg = NULL;
124 assert(NULL != query);
125 assert(NULL != g_hAccountDB);
127 ACCOUNT_DEBUG("query : %s", query);
129 rc = sqlite3_exec(g_hAccountDB, query, NULL, NULL, &pszErrorMsg);
130 if (SQLITE_OK != rc) {
131 ACCOUNT_DEBUG("sqlite3_exec(%s) failed(%s).", query, pszErrorMsg);
132 sqlite3_free(pszErrorMsg);
138 static int _account_begin_transaction(void)
142 ret = _account_execute_query("BEGIN IMMEDIATE TRANSACTION");
144 if (ret != SQLITE_OK) {
145 ACCOUNT_DEBUG("_account_svc_begin_transaction fail :: %d", ret);
146 return ACCOUNT_ERROR_DB_FAILED;
149 return ACCOUNT_ERROR_NONE;
152 static int _account_end_transaction(bool is_success)
156 if (is_success == true) {
157 ret = _account_execute_query("COMMIT TRANSACTION");
159 ret = _account_execute_query("ROLLBACK TRANSACTION");
162 if (ret != SQLITE_OK) {
163 ACCOUNT_DEBUG("_account_svc_end_transaction fail :: %d", ret);
164 return ACCOUNT_ERROR_DB_FAILED;
167 return ACCOUNT_ERROR_NONE;
170 static int _account_create_all_tables(void)
173 int error_code = ACCOUNT_ERROR_NONE;
174 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
177 ACCOUNT_MEMSET(query, 0, sizeof(query));
179 ACCOUNT_DEBUG("_account_create_all_tables begin");
181 /*Create the account table*/
182 ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", ACCOUNT_TABLE);
183 rc = _account_get_record_count(query);
184 ACCOUNT_DEBUG("rc = %d \n", rc);
187 ACCOUNT_MEMSET(query, 0, sizeof(query));
188 ACCOUNT_SNPRINTF(query, sizeof(query), ACCOUNT_SCHEMA, ACCOUNT_TABLE);
189 rc = _account_execute_query(query);
190 ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", query, rc, _account_db_err_msg()));
193 ACCOUNT_MEMSET(query, 0, sizeof(query));
194 /*Create capability table*/
195 ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", CAPABILITY_TABLE);
196 rc = _account_get_record_count(query);
197 ACCOUNT_DEBUG("rc = %d \n", rc);
200 ACCOUNT_MEMSET(query, 0, sizeof(query));
201 ACCOUNT_SNPRINTF(query, sizeof(query), CAPABILITY_SCHEMA, CAPABILITY_TABLE);
202 rc = _account_execute_query(query);
204 ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", query, rc, _account_db_err_msg()));
211 static bool _account_check_is_all_table_exists()
214 char query[ACCOUNT_SQL_LEN_MAX] = {0,};
215 ACCOUNT_MEMSET(query, 0, sizeof(query));
217 ACCOUNT_DEBUG("_account_check_is_all_table_exists");
219 ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s', '%s')",
220 ACCOUNT_TABLE, CAPABILITY_TABLE);
221 rc = _account_get_record_count(query);
222 ACCOUNT_DEBUG("rc = %d \n", rc);
224 if (rc != ACCOUNT_TABLE_TOTAL_COUNT) {
225 ACCOUNT_DEBUG("Table count is not matched rc=%d\n", rc);
229 ACCOUNT_DEBUG("END of _account_check_is_all_table_exists\n");
234 static int _account_db_open(void)
237 bool is_success = false;
238 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
240 ACCOUNT_MEMSET(query, 0x00, sizeof(query));
243 rc = db_util_open(ACCOUNT_DB_NAME, &g_hAccountDB, DB_UTIL_REGISTER_HOOK_METHOD);
244 ACCOUNT_RETURN_VAL((rc == SQLITE_OK), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected. rc : %d", rc));
248 ACCOUNT_DEBUG("_account_db_open: The database connected. refcnt=%d ", g_refCntDB);
252 ACCOUNT_DEBUG("The database already connected. refcnt=%d ", g_refCntDB);
255 return ACCOUNT_ERROR_NONE;
258 static int _account_db_close(void)
263 if (g_refCntDB > 0) {
265 ACCOUNT_DEBUG("_account_svc_db_close: The database disconnected. refcnt=%d ", g_refCntDB);
268 if (g_refCntDB == 0) {
269 rc = db_util_close(g_hAccountDB);
270 ACCOUNT_RETURN_VAL((rc == SQLITE_OK), {}, ACCOUNT_ERROR_DB_FAILED, ("The database isn't connected. rc : %d", rc));
273 ACCOUNT_DEBUG( "_account_svc_db_close: The database disconnected really. ");
276 ACCOUNT_DEBUG( "_account_svc_db_close: No handle(). refcnt=%d ", g_refCntDB);
279 return ACCOUNT_ERROR_NONE;
282 static int _account_connect(void)
284 int error_code = ACCOUNT_ERROR_NONE;
286 pthread_mutex_lock(&account_mutex);
288 ACCOUNT_DEBUG("db path = %s\n", ACCOUNT_DB_NAME);
290 error_code = _account_db_open();
291 if (ACCOUNT_ERROR_NONE != error_code) {
292 ACCOUNT_DEBUG("The database isn't connected.\n");
293 pthread_mutex_unlock(&account_mutex);
294 return ACCOUNT_ERROR_DB_NOT_OPENED;
297 if (FALSE == _account_check_is_all_table_exists())
298 error_code = _account_create_all_tables();
300 pthread_mutex_unlock(&account_mutex);
301 return ACCOUNT_ERROR_NONE;
304 int account_connect (void)
306 return _account_connect();
309 static int _account_disconnect(void)
311 int error_code = ACCOUNT_ERROR_NONE;
313 pthread_mutex_lock(&account_mutex);
314 ACCOUNT_DEBUG("db path = %s have been closed!!!\n", ACCOUNT_DB_NAME);
316 error_code = _account_db_close();
317 pthread_mutex_unlock(&account_mutex);
322 int account_disconnect (void)
324 return _account_disconnect();
327 static int _account_free_capability_items(account_capability_s *data)
329 _ACCOUNT_FREE(data->package_name);
330 _ACCOUNT_FREE(data->user_name);
332 return ACCOUNT_ERROR_NONE;
335 static int _account_free_account_items(account_s *data)
337 _ACCOUNT_FREE(data->user_name);
338 _ACCOUNT_FREE(data->email_address);
339 _ACCOUNT_FREE(data->display_name);
340 _ACCOUNT_FREE(data->icon_path);
341 _ACCOUNT_FREE(data->source);
342 _ACCOUNT_FREE(data->package_name);
343 _ACCOUNT_FREE(data->domain_name);
346 for(i=0;i<USER_TXT_CNT;i++)
347 _ACCOUNT_FREE(data->user_data_txt[i]);
349 _account_gslist_free(data->capablity_list);
350 _account_glist_free(data->account_list);
352 return ACCOUNT_ERROR_NONE;
355 static int _account_gslist_free(GSList* list)
357 ACCOUNT_RETURN_VAL((list != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("GSlist is NULL"));
361 for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
362 account_capability_s *cap_data = (account_capability_s*)iter->data;
363 _account_free_capability_items(cap_data);
369 return ACCOUNT_ERROR_NONE;
372 static int _account_glist_free(GList* list)
374 ACCOUNT_RETURN_VAL((list != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Glist is NULL"));
378 for (iter = list; iter != NULL; iter = g_list_next(iter)) {
379 account_s *account_record = (account_s*)iter->data;
380 _account_free_account_items(account_record);
386 return ACCOUNT_ERROR_NONE;
389 static gboolean _account_check_duplicated(account_s *data)
391 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
394 ACCOUNT_MEMSET(query, 0x00, sizeof(query));
396 ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from %s where user_name='%s' and domain_name='%s'"
397 , ACCOUNT_TABLE, data->user_name, data->domain_name);
399 count = _account_get_record_count(query);
401 ACCOUNT_DEBUG("_account_check_duplicated : duplicated %d account(s) exist!, user_name=%s, domain_name=%s\n",
402 count, data->user_name, data->domain_name );
409 static int _account_get_next_sequence(char *pszName)
412 account_stmt pStmt = NULL;
414 char szQuery[ACCOUNT_SQL_LEN_MAX] = {0,};
416 ACCOUNT_DEBUG( "[Enter] pszName:%s\n", pszName);
418 ACCOUNT_MEMSET(szQuery, 0x00, sizeof(szQuery));
419 ACCOUNT_SNPRINTF(szQuery, sizeof(szQuery), "SELECT max(seq) FROM %s where name = '%s' ", ACCOUNT_SQLITE_SEQ, pszName);
420 rc = sqlite3_prepare_v2(g_hAccountDB, szQuery, strlen(szQuery), &pStmt, NULL);
422 rc = sqlite3_step(pStmt);
423 max_seq = sqlite3_column_int(pStmt, 0);
426 ACCOUNT_DEBUG( "sqlite3_column_int, rc=%d, max_seq=%d\n", rc, max_seq);
428 /*Finalize Statement*/
429 rc = sqlite3_finalize(pStmt);
435 static account_stmt _account_prepare_query(char *query)
438 account_stmt pStmt = NULL;
440 ACCOUNT_RETURN_VAL((query != NULL), {}, NULL, ("query is NULL"));
442 ACCOUNT_DEBUG( "prepare query : %s", query);
444 rc = sqlite3_prepare_v2(g_hAccountDB, query, strlen(query), &pStmt, NULL);
445 ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, NULL, ("sqlite3_prepare_v2(%s) failed(%s).", query, _account_db_err_msg()));
450 static int _account_query_bind_int(account_stmt pStmt, int pos, int num)
452 assert(NULL != pStmt);
454 return sqlite3_bind_int(pStmt, pos, num);
457 static int _account_query_bind_text(account_stmt pStmt, int pos, const char *str)
459 assert(NULL != pStmt);
462 return sqlite3_bind_text(pStmt, pos, (const char*)str, strlen(str), SQLITE_STATIC);
464 return sqlite3_bind_null(pStmt, pos);
467 static int _account_convert_account_to_sql(account_s *account, account_stmt hstmt, char *sql_value)
469 ACCOUNT_DEBUG( "_account_convert_account_to_sql");
472 /*Caution : Keep insert query orders.*/
475 _account_query_bind_text(hstmt, count++, (char*)account->user_name);
477 /* 2. email address*/
478 _account_query_bind_text(hstmt, count++, (char*)account->email_address);
481 _account_query_bind_text(hstmt, count++, (char*)account->display_name);
484 _account_query_bind_text(hstmt, count++, (char*)account->icon_path);
487 _account_query_bind_text(hstmt, count++, (char*)account->source);
490 _account_query_bind_text(hstmt, count++, (char*)account->package_name);
493 _account_query_bind_text(hstmt, count++, (char*)account->access_token);
496 _account_query_bind_text(hstmt, count++, (char*)account->domain_name);
499 _account_query_bind_int(hstmt, count++, account->auth_type);
502 _account_query_bind_int(hstmt, count++, account->secret);
507 for(i=0; i< USER_TXT_CNT; i++)
508 _account_query_bind_text(hstmt, count++, (char*)account->user_data_txt[i]);
510 /* 12. user integer */
511 for(i=0; i< USER_INT_CNT; i++)
512 _account_query_bind_int(hstmt, count++, account->user_data_int[i]);
518 static void _account_query_finalize(account_stmt pStmt)
523 ACCOUNT_DEBUG( "pStmt is NULL");
527 rc = sqlite3_finalize(pStmt);
528 if (rc != SQLITE_OK) {
529 ACCOUNT_DEBUG( "sqlite3_finalize fail, rc : %d, db_error : %s\n", rc, _account_db_err_msg());
532 ACCOUNT_DEBUG( "sqlite3_finalize finish");
536 static int _account_query_step(account_stmt pStmt)
538 assert(NULL != pStmt);
539 return sqlite3_step(pStmt);
543 static int _account_execute_insert_query(account_s *account)
546 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
547 int error_code = ACCOUNT_ERROR_NONE;
548 account_stmt hstmt = NULL;
550 if (!account->user_name && !account->display_name && !account->email_address) {
551 ACCOUNT_DEBUG("Mandetory fields is NULL. At least one field is required among username, display name, email address\n");
552 return ACCOUNT_ERROR_INVALID_PARAMETER;
555 ACCOUNT_MEMSET(query, 0x00, sizeof(query));
556 ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s( user_name, email_address , display_name , icon_path , source , package_name , "
557 "access_token , domain_name , auth_type , secret , txt_custom0, txt_custom1, txt_custom2, txt_custom3, txt_custom4, "
558 "int_custom0, int_custom1, int_custom2, int_custom3, int_custom4, txt_custom0 ) values "
559 "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? , ?)", ACCOUNT_TABLE);
561 hstmt = _account_prepare_query(query);
562 ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
564 _account_convert_account_to_sql(account, hstmt, query);
566 rc = _account_query_step(hstmt);
567 if (rc != SQLITE_DONE) {
568 ACCOUNT_DEBUG( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg());
569 error_code = ACCOUNT_ERROR_DB_FAILED;
572 _account_query_finalize(hstmt);
578 static int _account_insert_capability(account_s *account, int account_id)
581 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
582 account_stmt hstmt = NULL;
584 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
586 if (g_slist_length( account->capablity_list)==0) {
587 ACCOUNT_DEBUG( "_account_insert_capability, no capability\n");
588 return ACCOUNT_ERROR_NONE;
591 ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where _id=%d", ACCOUNT_TABLE, account_id);
593 rc = _account_get_record_count(query);
596 ACCOUNT_DEBUG( "_account_insert_capability : related account item is not existed rc=%d , %s", rc, _account_db_err_msg());
597 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
604 for (iter = account->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
607 ACCOUNT_MEMSET(query, 0x00, sizeof(query));
608 ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(key, value, package_name, user_name, account_id) VALUES "
609 "(?, ?, ?, ?, ?) ", CAPABILITY_TABLE);
611 hstmt = _account_prepare_query(query);
613 ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
615 account_capability_s* cap_data = NULL;
616 cap_data = (account_capability_s*)iter->data;
617 ACCOUNT_DEBUG( "@@@@@@@@@@@@@cap_data->type = %d, cap_data->value = %d \n @@@@@@@@@@", cap_data->type, cap_data->value);
619 ret = _account_query_bind_int(hstmt, count++, cap_data->type);
620 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
621 ret = _account_query_bind_int(hstmt, count++, cap_data->value);
622 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
623 ret = _account_query_bind_text(hstmt, count++, (char*)account->package_name);
624 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
625 ret = _account_query_bind_text(hstmt, count++, (char*)account->user_name);
626 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
627 ret = _account_query_bind_int(hstmt, count++, (int)account_id);
628 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
630 rc = _account_query_step(hstmt);
632 if (rc != SQLITE_DONE) {
633 ACCOUNT_DEBUG( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
637 _account_query_finalize(hstmt);
642 ACCOUNT_DEBUG( "_account_insert_capability() DONE\n");
644 return ACCOUNT_ERROR_NONE;
648 static int _account_update_capability(account_s *account, int account_id)
651 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
652 account_stmt hstmt = NULL;
654 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
656 if (g_slist_length( account->capablity_list)==0) {
657 ACCOUNT_DEBUG( "_account_insert_capability, no capability\n");
658 return ACCOUNT_ERROR_NONE;
661 ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where _id=%d", ACCOUNT_TABLE, account_id);
663 rc = _account_get_record_count(query);
666 ACCOUNT_DEBUG( "_account_insert_capability : related account item is not existed rc=%d , %s", rc, _account_db_err_msg());
667 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
670 ACCOUNT_MEMSET(query, 0x00, sizeof(query));
672 ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE account_id=? ", CAPABILITY_TABLE);
673 hstmt = _account_prepare_query(query);
675 _account_query_bind_int(hstmt, count++, (int)account_id);
676 _account_query_step(hstmt);
677 _account_query_finalize(hstmt);
682 for (iter = account->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
685 ACCOUNT_MEMSET(query, 0x00, sizeof(query));
686 ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(key, value, package_name, user_name, account_id) VALUES "
687 "(?, ?, ?, ?, ?) ", CAPABILITY_TABLE);
689 hstmt = _account_prepare_query(query);
691 ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
693 account_capability_s* cap_data = NULL;
694 cap_data = (account_capability_s*)iter->data;
696 ret = _account_query_bind_int(hstmt, count++, cap_data->type);
697 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
698 ret = _account_query_bind_int(hstmt, count++, cap_data->value);
699 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
700 ret = _account_query_bind_text(hstmt, count++, (char*)account->package_name);
701 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
702 ret = _account_query_bind_text(hstmt, count++, (char*)account->user_name);
703 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
704 ret = _account_query_bind_int(hstmt, count++, (int)account_id);
705 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
707 rc = _account_query_step(hstmt);
709 if (rc != SQLITE_DONE) {
710 ACCOUNT_DEBUG( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
714 _account_query_finalize(hstmt);
719 ACCOUNT_DEBUG( "_account_insert_capability() DONE\n");
721 return ACCOUNT_ERROR_NONE;
724 static int _account_update_capability_by_user_name(account_s *account, char *user_name, char *package_name )
727 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
728 account_stmt hstmt = NULL;
730 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
732 if (g_slist_length( account->capablity_list)==0) {
733 ACCOUNT_DEBUG( "_account_insert_capability, no capability\n");
734 return ACCOUNT_ERROR_NONE;
737 ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where package_name=%s and user_name=%s", ACCOUNT_TABLE, package_name, user_name);
739 rc = _account_get_record_count(query);
742 ACCOUNT_DEBUG( "_account_insert_capability : related account item is not existed rc=%d , %s ", rc, _account_db_err_msg());
743 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
746 ACCOUNT_MEMSET(query, 0x00, sizeof(query));
748 ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE package_name=? and user_name=? ", CAPABILITY_TABLE);
749 hstmt = _account_prepare_query(query);
751 _account_query_bind_text(hstmt, count++, (char*)account->package_name);
752 _account_query_bind_text(hstmt, count++, (char*)account->user_name);
753 _account_query_step(hstmt);
754 _account_query_finalize(hstmt);
759 for (iter = account->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
762 ACCOUNT_MEMSET(query, 0x00, sizeof(query));
763 ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(key, value, package_name, user_name, account_id) VALUES "
764 "(?, ?, ?, ?, ?) ", CAPABILITY_TABLE);
766 hstmt = _account_prepare_query(query);
768 ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
770 account_capability_s* cap_data = NULL;
771 cap_data = (account_capability_s*)iter->data;
773 ret = _account_query_bind_int(hstmt, count++, cap_data->type);
774 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
775 ret = _account_query_bind_int(hstmt, count++, cap_data->value);
776 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
777 ret = _account_query_bind_text(hstmt, count++, (char*)account->package_name);
778 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
779 ret = _account_query_bind_text(hstmt, count++, (char*)account->user_name);
780 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
781 /*ret = _account_query_bind_int(hstmt, count++, (int)account_id);
782 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));*/
784 rc = _account_query_step(hstmt);
786 if (rc != SQLITE_DONE) {
787 ACCOUNT_DEBUG( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
791 _account_query_finalize(hstmt);
796 ACCOUNT_DEBUG( "_account_insert_capability() DONE\n");
798 return ACCOUNT_ERROR_NONE;
801 static int _account_query_table_column_int(account_stmt pStmt, int pos)
803 assert(NULL != pStmt);
805 return sqlite3_column_int(pStmt, pos);
808 static char *_account_query_table_column_text(account_stmt pStmt, int pos)
810 assert(NULL != pStmt);
812 return (char *)sqlite3_column_text(pStmt, pos);
815 static void _account_db_data_to_text(char *textbuf, char **output)
817 if (textbuf && strlen(textbuf)>0) {
822 *output = strdup(textbuf);
824 ACCOUNT_DEBUG("_account_db_data_to_text : no text");
828 static void _account_convert_column_to_account(account_stmt hstmt, account_s *account_record)
830 char *textbuf = NULL;
832 account_record->id = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_ID);
834 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_NAME);
835 _account_db_data_to_text(textbuf, &(account_record->user_name));
837 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_EMAIL_ADDRESS);
838 _account_db_data_to_text(textbuf, &(account_record->email_address));
840 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_DISPLAY_NAME);
841 _account_db_data_to_text(textbuf, &(account_record->display_name));
843 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_ICON_PATH);
844 _account_db_data_to_text(textbuf, &(account_record->icon_path));
846 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_SOURCE);
847 _account_db_data_to_text(textbuf, &(account_record->source));
849 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_PACKAGE_NAME);
850 _account_db_data_to_text(textbuf, &(account_record->package_name));
852 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_ACCESS_TOKEN);
853 _account_db_data_to_text(textbuf, &(account_record->access_token));
855 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_DOMAIN_NAME);
856 _account_db_data_to_text(textbuf, &(account_record->domain_name));
858 account_record->auth_type = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_AUTH_TYPE);
860 account_record->secret = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_SECRET);
862 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_0);
863 _account_db_data_to_text(textbuf, &(account_record->user_data_txt[0]));
865 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_1);
866 _account_db_data_to_text(textbuf, &(account_record->user_data_txt[1]));
868 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_2);
869 _account_db_data_to_text(textbuf, &(account_record->user_data_txt[2]));
871 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_3);
872 _account_db_data_to_text(textbuf, &(account_record->user_data_txt[3]));
874 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_4);
875 _account_db_data_to_text(textbuf, &(account_record->user_data_txt[4]));
877 account_record->user_data_int[0] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_0);
878 account_record->user_data_int[1] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_1);
879 account_record->user_data_int[2] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_2);
880 account_record->user_data_int[3] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_3);
881 account_record->user_data_int[4] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_4);
883 ACCOUNT_DEBUG("END _account_convert_column_to_account");
887 static void _account_convert_column_to_capability(account_stmt hstmt, account_capability_s *capability_record)
889 char *textbuf = NULL;
891 capability_record->id = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_ID);
893 capability_record->type = _account_query_table_column_int(hstmt, CAPABILITY_FIELD_KEY);
895 capability_record->value = _account_query_table_column_int(hstmt, CAPABILITY_FIELD_VALUE);
897 textbuf = _account_query_table_column_text(hstmt, CAPABILITY_FIELD_PACKAGE_NAME);
898 _account_db_data_to_text(textbuf, &(capability_record->package_name));
900 textbuf = _account_query_table_column_text(hstmt, CAPABILITY_FIELD_USER_NAME);
901 _account_db_data_to_text(textbuf, &(capability_record->user_name));
903 capability_record->account_id = _account_query_table_column_int(hstmt, CAPABILITY_FIELD_ACCOUNT_ID);
905 ACCOUNT_DEBUG("END _account_convert_column_to_capability");
908 bool _account_get_capability_text_cb(account_capability_type_e capability_type, account_capability_state_e capability_value, void *user_data)
910 account_s *data = (account_s*)user_data;
912 account_capability_s *cap_data = (account_capability_s*)malloc(sizeof(account_capability_s));
914 if (cap_data == NULL)
916 ACCOUNT_MEMSET(cap_data, 0, sizeof(account_capability_s));
918 cap_data->type = capability_type;
919 cap_data->value = capability_value;
921 data->capablity_list = g_slist_append(data->capablity_list, (gpointer)cap_data);
923 ACCOUNT_DEBUG("_account_get_capability_text_cb :: %d\n", capability_type);
928 static char *_account_get_text(char *text_data)
930 char *text_value = NULL;
932 if (text_data != NULL) {
933 text_value = strdup(text_data);
934 ACCOUNT_DEBUG("text_value = %s", text_value);
939 static int _account_update_account_by_user_name(account_s *account, char *user_name, char *package_name)
941 int rc = 0, binding_count =0;
942 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
943 int error_code = ACCOUNT_ERROR_NONE;
944 account_stmt hstmt = NULL;
946 ACCOUNT_RETURN_VAL((account->user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is NULL.\n"));
947 ACCOUNT_RETURN_VAL((account->email_address != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("email_address is NULL.\n"));
949 if (!account->user_name && !account->display_name && !account->email_address) {
950 ACCOUNT_DEBUG("One field should be set among user name, display name, email address\n");
951 return ACCOUNT_ERROR_INVALID_PARAMETER;
954 ACCOUNT_MEMSET(query, 0x00, sizeof(query));
955 ACCOUNT_SNPRINTF(query, sizeof(query), "UPDATE %s SET user_name=?, email_address =?, display_name =?, "
956 "icon_path =?, source =?, package_name =? , access_token =?, domain_name =?, auth_type =?, secret =?,"
957 "txt_custom0=?, txt_custom1=?, txt_custom2=?, txt_custom3=?, txt_custom4=?, "
958 "int_custom0=?, int_custom1=?, int_custom2=?, int_custom3=?, int_custom4=? WHERE user_name=? and package_name=? ", ACCOUNT_TABLE);
960 hstmt = _account_prepare_query(query);
961 ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_svc_query_prepare() failed(%s).\n", _account_db_err_msg()));
963 binding_count = _account_convert_account_to_sql(account, hstmt, query);
965 _account_query_bind_text(hstmt, binding_count++, user_name);
966 _account_query_bind_text(hstmt, binding_count++, package_name);
967 ACCOUNT_DEBUG("_account_query_step : user_name = %s, package_name=%s\n", user_name, package_name);
968 rc = _account_query_step(hstmt);
969 ACCOUNT_DEBUG("_account_query_step return rc=%d\n", rc);
970 if (rc != SQLITE_DONE) {
971 ACCOUNT_DEBUG( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg());
974 _account_query_finalize(hstmt);
977 /*update capability*/
978 _account_update_capability_by_user_name(account, user_name, package_name);
983 int account_insert_to_db(account_h account, int *account_id)
985 int ret = ACCOUNT_ERROR_NONE;
986 int error_code = ACCOUNT_ERROR_NONE;
989 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected. rc : %d", ret));
992 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
994 account_s *data = (account_s*)account;
996 pthread_mutex_lock(&account_mutex);
998 if (_account_check_duplicated(data)) {
999 error_code = ACCOUNT_ERROR_DUPLICATED;
1001 *account_id = _account_get_next_sequence(ACCOUNT_TABLE);
1003 error_code = _account_execute_insert_query(data);
1005 if (error_code != ACCOUNT_ERROR_NONE)
1009 ACCOUNT_DEBUG( "_account_execute_insert_query, insert error_code : %d", error_code);
1011 _account_insert_capability(data, *account_id);
1013 pthread_mutex_unlock(&account_mutex);
1015 return ACCOUNT_ERROR_NONE;
1019 int account_create(account_h *account)
1022 ACCOUNT_DEBUG("(%s)-(%d) account is NULL.\n", __FUNCTION__, __LINE__);
1023 return ACCOUNT_ERROR_INVALID_PARAMETER;
1026 account_s *data = (account_s*)malloc(sizeof(account_s));
1029 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1030 ACCOUNT_MEMSET(data, 0, sizeof(account_s));
1032 ACCOUNT_DEBUG("create handle=%p\n", *account);
1034 *account = (account_h)data;
1036 return ACCOUNT_ERROR_NONE;
1039 int account_set_user_name(account_h account, const char *user_name)
1042 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1043 return ACCOUNT_ERROR_INVALID_PARAMETER;
1047 ACCOUNT_DEBUG("(%s)-(%d) user_name is NULL.\n", __FUNCTION__, __LINE__);
1048 return ACCOUNT_ERROR_INVALID_PARAMETER;
1051 account_s *data = (account_s*)account;
1053 ACCOUNT_DEBUG("account=%p\n", account);
1055 _ACCOUNT_FREE(data->user_name);
1056 data->user_name = strdup(user_name);
1058 ACCOUNT_DEBUG("(%s)-(%d) %s, %s\n", __FUNCTION__, __LINE__ , data->user_name, user_name);
1060 return ACCOUNT_ERROR_NONE;
1064 int account_set_display_name(account_h account, const char *display_name)
1067 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1068 return ACCOUNT_ERROR_INVALID_PARAMETER;
1071 if (!display_name) {
1072 ACCOUNT_DEBUG("(%s)-(%d) display_name is NULL.\n", __FUNCTION__, __LINE__);
1073 return ACCOUNT_ERROR_INVALID_PARAMETER;
1076 account_s *data = (account_s*)account;
1078 _ACCOUNT_FREE(data->display_name);
1079 data->display_name = strdup(display_name);
1081 ACCOUNT_DEBUG("(%s)-(%d) %s, %s\n", __FUNCTION__, __LINE__ , data->display_name, display_name);
1083 return ACCOUNT_ERROR_NONE;
1086 int account_set_email_address(account_h account, const char *email_address)
1089 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1090 return ACCOUNT_ERROR_INVALID_PARAMETER;
1093 if (!email_address) {
1094 ACCOUNT_DEBUG("(%s)-(%d) email_address is NULL.\n", __FUNCTION__, __LINE__);
1095 return ACCOUNT_ERROR_INVALID_PARAMETER;
1098 account_s *data = (account_s*)account;
1100 _ACCOUNT_FREE(data->email_address);
1101 data->email_address = strdup(email_address);
1103 ACCOUNT_DEBUG("(%s)-(%d) %s, %s\n", __FUNCTION__, __LINE__ , data->email_address, email_address);
1105 return ACCOUNT_ERROR_NONE;
1108 int account_set_icon_path(account_h account, const char *icon_path)
1111 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1112 return ACCOUNT_ERROR_INVALID_PARAMETER;
1116 ACCOUNT_DEBUG("(%s)-(%d) icon_path is NULL.\n", __FUNCTION__, __LINE__);
1117 return ACCOUNT_ERROR_INVALID_PARAMETER;
1120 account_s *data = (account_s*)account;
1122 _ACCOUNT_FREE(data->icon_path);
1123 data->icon_path = strdup(icon_path);
1125 ACCOUNT_DEBUG("(%s)-(%d) %s, %s\n", __FUNCTION__, __LINE__ , data->icon_path, icon_path);
1127 return ACCOUNT_ERROR_NONE;
1131 int account_set_source(account_h account, const char *source)
1134 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1135 return ACCOUNT_ERROR_INVALID_PARAMETER;
1139 ACCOUNT_DEBUG("(%s)-(%d) source is NULL.\n", __FUNCTION__, __LINE__);
1140 return ACCOUNT_ERROR_INVALID_PARAMETER;
1142 account_s *data = (account_s*)account;
1144 _ACCOUNT_FREE(data->source);
1145 data->source = strdup(source);
1147 ACCOUNT_DEBUG("(%s)-(%d) %s, %s\n", __FUNCTION__, __LINE__ , data->source, source);
1149 return ACCOUNT_ERROR_NONE;
1152 int account_set_package_name(account_h account, const char *package_name)
1155 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1156 return ACCOUNT_ERROR_INVALID_PARAMETER;
1159 if (!package_name) {
1160 ACCOUNT_DEBUG("(%s)-(%d) package_name is NULL.\n", __FUNCTION__, __LINE__);
1161 return ACCOUNT_ERROR_INVALID_PARAMETER;
1164 account_s *data = (account_s*)account;
1166 _ACCOUNT_FREE(data->package_name);
1167 data->package_name = strdup(package_name);
1169 ACCOUNT_DEBUG("(%s)-(%d) %s, %s\n", __FUNCTION__, __LINE__ , data->package_name, package_name);
1171 return ACCOUNT_ERROR_NONE;
1175 int account_set_domain_name(account_h account, const char *domain_name)
1178 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1179 return ACCOUNT_ERROR_INVALID_PARAMETER;
1183 ACCOUNT_DEBUG("(%s)-(%d) domain_name is NULL.\n", __FUNCTION__, __LINE__);
1184 return ACCOUNT_ERROR_INVALID_PARAMETER;
1186 account_s *data = (account_s*)account;
1188 _ACCOUNT_FREE(data->domain_name);
1189 data->domain_name = strdup(domain_name);
1191 ACCOUNT_DEBUG("(%s)-(%d) %s, %s\n", __FUNCTION__, __LINE__ , data->domain_name, domain_name);
1193 return ACCOUNT_ERROR_NONE;
1197 int account_set_access_token(account_h account, const char *access_token)
1200 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1201 return ACCOUNT_ERROR_INVALID_PARAMETER;
1204 if (!access_token) {
1205 ACCOUNT_DEBUG("(%s)-(%d) access_token is NULL.\n", __FUNCTION__, __LINE__);
1206 return ACCOUNT_ERROR_INVALID_PARAMETER;
1209 account_s *data = (account_s*)account;
1211 _ACCOUNT_FREE(data->access_token);
1212 data->access_token = strdup(access_token);
1214 ACCOUNT_DEBUG("(%s)-(%d) %s, %s\n", __FUNCTION__, __LINE__ , data->access_token, access_token);
1216 return ACCOUNT_ERROR_NONE;
1219 int account_set_user_text(account_h account, int index, const char *user_txt)
1222 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1223 return ACCOUNT_ERROR_INVALID_PARAMETER;
1227 ACCOUNT_DEBUG("(%s)-(%d) user_txt is NULL.\n", __FUNCTION__, __LINE__);
1228 return ACCOUNT_ERROR_INVALID_PARAMETER;
1230 if (index >= USER_TXT_CNT) {
1231 ACCOUNT_DEBUG("(%s)-(%d) index rage should be between 0-4.\n", __FUNCTION__, __LINE__);
1232 return ACCOUNT_ERROR_INVALID_PARAMETER;
1235 account_s *data = (account_s*)account;
1237 _ACCOUNT_FREE(data->user_data_txt[index]);
1238 data->user_data_txt[index] = strdup(user_txt);
1240 ACCOUNT_DEBUG("(%s)-(%d) %s, %s\n", __FUNCTION__, __LINE__ , data->user_data_txt[index], user_txt);
1242 return ACCOUNT_ERROR_NONE;
1245 int account_set_auth_type(account_h account, const account_auth_type_e auth_type)
1247 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
1249 if ( (auth_type < 0) || (auth_type > ACCOUNT_AUTH_TYPE_CLIENT_LOGIN)) {
1250 ACCOUNT_DEBUG("(%s)-(%d) auth_type is less than 1 or more than enum max.\n", __FUNCTION__, __LINE__);
1251 return ACCOUNT_ERROR_INVALID_PARAMETER;
1254 account_s *data = (account_s*)account;
1256 data->auth_type = (int)auth_type;
1258 return ACCOUNT_ERROR_NONE;
1261 int account_set_secret(account_h account, const account_secrecy_state_e secret)
1263 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
1265 if ( (secret < 0) || (secret > ACCOUNT_SECRECY_VISIBLE)) {
1266 ACCOUNT_DEBUG("(%s)-(%d) auth_type is less than 1 or more than enum max.\n", __FUNCTION__, __LINE__);
1267 return ACCOUNT_ERROR_INVALID_PARAMETER;
1270 account_s *data = (account_s*)account;
1272 data->secret = (int)secret;
1274 return ACCOUNT_ERROR_NONE;
1277 int account_set_user_int(account_h account, int index, const int user_int)
1280 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1281 return ACCOUNT_ERROR_INVALID_PARAMETER;
1284 if (index >= USER_INT_CNT) {
1285 ACCOUNT_DEBUG("(%s)-(%d) index rage should be between 0-4.\n", __FUNCTION__, __LINE__);
1286 return ACCOUNT_ERROR_INVALID_PARAMETER;
1289 account_s *data = (account_s*)account;
1291 data->user_data_int[index] = user_int;
1293 return ACCOUNT_ERROR_NONE;
1297 int account_set_capability(account_h account, account_capability_type_e capability_type, account_capability_state_e capability_value)
1300 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1301 return ACCOUNT_ERROR_INVALID_PARAMETER;
1304 if ( (capability_type < 0) || (capability_type > ACCOUNT_CAPABILITY_MOBILE_TRACKER)) {
1305 ACCOUNT_DEBUG("(%s)-(%d) capability_type is less than 1 or more than enum max.\n", __FUNCTION__, __LINE__);
1306 return ACCOUNT_ERROR_INVALID_PARAMETER;
1309 if ((capability_value != ACCOUNT_CAPABILITY_DISABLED) && (capability_value != ACCOUNT_CAPABILITY_ENABLED)) {
1310 ACCOUNT_DEBUG("(%s)-(%d) capability_value is not equal to 0 or 1.\n", __FUNCTION__, __LINE__);
1311 return ACCOUNT_ERROR_INVALID_PARAMETER;
1314 account_s *data = (account_s*)account;
1316 account_capability_s* cap_data = (account_capability_s*)malloc(sizeof(account_capability_s));
1318 if (cap_data == NULL)
1319 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1320 ACCOUNT_MEMSET(cap_data, 0, sizeof(account_capability_s));
1322 cap_data->type = capability_type;
1323 cap_data->value = capability_value;
1324 data->capablity_list = g_slist_append(data->capablity_list, (gpointer)cap_data);
1326 return ACCOUNT_ERROR_NONE;
1329 int account_get_user_name(account_h account, char **user_name)
1332 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1333 return ACCOUNT_ERROR_INVALID_PARAMETER;
1337 ACCOUNT_DEBUG("(%s)-(%d) user name is NULL.\n", __FUNCTION__, __LINE__);
1338 return ACCOUNT_ERROR_INVALID_PARAMETER;
1341 account_s *data = (account_s*)account;
1343 (*user_name) = NULL;
1344 *user_name = _account_get_text(data->user_name);
1346 return ACCOUNT_ERROR_NONE;
1349 int account_get_display_name(account_h account, char **display_name)
1352 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1353 return ACCOUNT_ERROR_INVALID_PARAMETER;
1356 if (!display_name) {
1357 ACCOUNT_DEBUG("(%s)-(%d) display name is NULL.\n", __FUNCTION__, __LINE__);
1358 return ACCOUNT_ERROR_INVALID_PARAMETER;
1361 account_s *data = (account_s*)account;
1363 (*display_name) = NULL;
1365 *display_name = _account_get_text(data->display_name);
1367 return ACCOUNT_ERROR_NONE;
1370 int account_get_email_address(account_h account,char **email_address)
1373 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1374 return ACCOUNT_ERROR_INVALID_PARAMETER;
1377 if (!email_address) {
1378 ACCOUNT_DEBUG("(%s)-(%d) email address is NULL.\n", __FUNCTION__, __LINE__);
1379 return ACCOUNT_ERROR_INVALID_PARAMETER;
1382 account_s *data = (account_s*)account;
1384 (*email_address) = NULL;
1386 *email_address = _account_get_text(data->email_address);
1388 return ACCOUNT_ERROR_NONE;
1391 int account_get_icon_path(account_h account, char **icon_path)
1394 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1395 return ACCOUNT_ERROR_INVALID_PARAMETER;
1399 ACCOUNT_DEBUG("(%s)-(%d) icon path is NULL.\n", __FUNCTION__, __LINE__);
1400 return ACCOUNT_ERROR_INVALID_PARAMETER;
1403 account_s *data = (account_s*)account;
1405 (*icon_path) = NULL;
1407 *icon_path = _account_get_text(data->icon_path);
1409 return ACCOUNT_ERROR_NONE;
1412 int account_get_source(account_h account, char **source)
1415 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1416 return ACCOUNT_ERROR_INVALID_PARAMETER;
1420 ACCOUNT_DEBUG("(%s)-(%d) source is NULL.\n", __FUNCTION__, __LINE__);
1421 return ACCOUNT_ERROR_INVALID_PARAMETER;
1424 account_s *data = (account_s*)account;
1428 *source = _account_get_text(data->source);
1430 return ACCOUNT_ERROR_NONE;
1433 int account_get_package_name(account_h account, char **package_name)
1436 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1437 return ACCOUNT_ERROR_INVALID_PARAMETER;
1440 if (!package_name) {
1441 ACCOUNT_DEBUG("(%s)-(%d) package name is NULL.\n", __FUNCTION__, __LINE__);
1442 return ACCOUNT_ERROR_INVALID_PARAMETER;
1445 account_s *data = (account_s*)account;
1447 (*package_name) = NULL;
1449 *package_name = _account_get_text(data->package_name);
1451 return ACCOUNT_ERROR_NONE;
1454 int account_get_domain_name(account_h account, char **domain_name)
1457 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1458 return ACCOUNT_ERROR_INVALID_PARAMETER;
1462 ACCOUNT_DEBUG("(%s)-(%d) domain name is NULL.\n", __FUNCTION__, __LINE__);
1463 return ACCOUNT_ERROR_INVALID_PARAMETER;
1466 account_s *data = (account_s*)account;
1468 (*domain_name) = NULL;
1470 *domain_name = _account_get_text(data->domain_name);
1472 return ACCOUNT_ERROR_NONE;
1475 int account_get_access_token(account_h account, char **access_token)
1478 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1479 return ACCOUNT_ERROR_INVALID_PARAMETER;
1482 if (!access_token) {
1483 ACCOUNT_DEBUG("(%s)-(%d) access token is NULL.\n", __FUNCTION__, __LINE__);
1484 return ACCOUNT_ERROR_INVALID_PARAMETER;
1487 account_s *data = (account_s*)account;
1489 (*access_token) = NULL;
1491 *access_token = _account_get_text(data->access_token);
1493 return ACCOUNT_ERROR_NONE;
1496 int account_get_user_text(account_h account, int user_text_index, char **text)
1499 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1500 return ACCOUNT_ERROR_INVALID_PARAMETER;
1504 ACCOUNT_DEBUG("(%s)-(%d) text is NULL.\n", __FUNCTION__, __LINE__);
1505 return ACCOUNT_ERROR_INVALID_PARAMETER;
1507 ACCOUNT_RETURN_VAL((user_text_index >=0 && user_text_index < USER_TXT_CNT ), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1509 account_s *data = (account_s*)account;
1513 *text = _account_get_text(data->user_data_txt[user_text_index]);
1515 return ACCOUNT_ERROR_NONE;
1518 int account_get_auth_type(account_h account, account_auth_type_e *auth_type)
1521 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1522 return ACCOUNT_ERROR_INVALID_PARAMETER;
1525 ACCOUNT_DEBUG("(%s)-(%d) auth_type is NULL.\n", __FUNCTION__, __LINE__);
1526 return ACCOUNT_ERROR_INVALID_PARAMETER;
1529 account_s* data = (account_s*)account;
1531 *auth_type = data->auth_type;
1533 return ACCOUNT_ERROR_NONE;
1536 int account_get_secret(account_h account, account_secrecy_state_e *secret)
1539 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1540 return ACCOUNT_ERROR_INVALID_PARAMETER;
1543 ACCOUNT_DEBUG("(%s)-(%d) secret is NULL.\n", __FUNCTION__, __LINE__);
1544 return ACCOUNT_ERROR_INVALID_PARAMETER;
1547 account_s* data = (account_s*)account;
1549 *secret = data->secret;
1551 return ACCOUNT_ERROR_NONE;
1554 int account_get_account_id(account_h account, int *account_id)
1557 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1558 return ACCOUNT_ERROR_INVALID_PARAMETER;
1561 ACCOUNT_DEBUG("(%s)-(%d) account_id is NULL.\n", __FUNCTION__, __LINE__);
1562 return ACCOUNT_ERROR_INVALID_PARAMETER;
1565 account_s *data = (account_s*)account;
1567 *account_id = data->id;
1569 return ACCOUNT_ERROR_NONE;
1572 int account_get_user_int(account_h account, int user_int_index, int *integer)
1575 ACCOUNT_DEBUG("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__);
1576 return ACCOUNT_ERROR_INVALID_PARAMETER;
1579 ACCOUNT_RETURN_VAL((user_int_index >=0 && user_int_index < USER_TXT_CNT ), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID USER TEXT INDEX"));
1582 ACCOUNT_DEBUG("(%s)-(%d) integer is NULL.\n", __FUNCTION__, __LINE__);
1583 return ACCOUNT_ERROR_INVALID_PARAMETER;
1586 account_s *data = (account_s*)account;
1588 *integer = data->user_data_int[user_int_index];
1590 return ACCOUNT_ERROR_NONE;
1593 int account_get_capability(account_h account, capability_cb cb_func, void *user_data)
1595 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
1596 ACCOUNT_RETURN_VAL((cb_func != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
1599 account_s *data = (account_s*)account;
1601 for (iter = data->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
1602 account_capability_s *cap_data = NULL;
1604 cap_data = (account_capability_s*)iter->data;
1606 ACCOUNT_DEBUG("account_get_capability :: type = %d, value = %d", cap_data->type, cap_data->value);
1608 cb_func(cap_data->type, cap_data->value, user_data);
1611 return ACCOUNT_ERROR_NONE;
1614 int account_query_capability_by_account_id(capability_cb cb_func, int account_id, void *user_data )
1616 int error_code = ACCOUNT_ERROR_NONE;
1617 account_stmt hstmt = NULL;
1618 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
1621 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1623 int ret = ACCOUNT_ERROR_NONE;
1625 if (!g_hAccountDB) {
1626 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected. rc : %d", ret));
1629 ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
1631 ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE account_id = %d", CAPABILITY_TABLE, account_id);
1632 hstmt = _account_prepare_query(query);
1634 rc = _account_query_step(hstmt);
1635 ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
1637 account_capability_s* capability_record = NULL;
1639 while (rc == SQLITE_ROW) {
1640 capability_record = (account_capability_s*) malloc(sizeof(account_capability_s));
1642 if (capability_record == NULL) {
1643 ACCOUNT_DEBUG("malloc Failed");
1647 ACCOUNT_MEMSET(capability_record, 0x00, sizeof(account_capability_s));
1649 _account_convert_column_to_capability(hstmt, capability_record);
1651 cb_func(capability_record->type, capability_record->value, user_data);
1653 _account_free_capability_items(capability_record);
1654 _ACCOUNT_FREE(capability_record);
1656 rc = _account_query_step(hstmt);
1659 _account_query_finalize(hstmt);
1662 error_code = ACCOUNT_ERROR_NONE;
1665 if (hstmt != NULL) {
1666 _account_query_finalize(hstmt);
1670 pthread_mutex_unlock(&account_mutex);
1674 static int _account_update_account(account_s *account, int account_id)
1676 int rc = 0, binding_count =0;
1677 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
1678 int error_code = ACCOUNT_ERROR_NONE;
1679 account_stmt hstmt = NULL;
1681 ACCOUNT_RETURN_VAL((account->user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is NULL.\n"));
1682 ACCOUNT_RETURN_VAL((account->email_address != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("email_address is NULL.\n"));
1684 if (!account->user_name && !account->display_name && !account->email_address) {
1685 ACCOUNT_DEBUG("One field should be set among user name, display name, email address\n");
1686 return ACCOUNT_ERROR_INVALID_PARAMETER;
1689 ACCOUNT_MEMSET(query, 0x00, sizeof(query));
1690 ACCOUNT_SNPRINTF(query, sizeof(query), "UPDATE %s SET user_name=?, email_address =?, display_name =?, "
1691 "icon_path =?, source =?, package_name =? , access_token =?, domain_name =?, auth_type =?, secret =?,"
1692 "txt_custom0=?, txt_custom1=?, txt_custom2=?, txt_custom3=?, txt_custom4=?, "
1693 "int_custom0=?, int_custom1=?, int_custom2=?, int_custom3=?, int_custom4=? WHERE _id=? ", ACCOUNT_TABLE);
1695 hstmt = _account_prepare_query(query);
1696 ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_svc_query_prepare() failed(%s).\n", _account_db_err_msg()));
1698 binding_count = _account_convert_account_to_sql(account, hstmt, query);
1699 _account_query_bind_int(hstmt, binding_count++, account_id);
1701 rc = _account_query_step(hstmt);
1702 ACCOUNT_DEBUG("_account_query_step return rc=%d\n", rc);
1703 if (rc != SQLITE_DONE) {
1704 ACCOUNT_DEBUG( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg());
1707 _account_query_finalize(hstmt);
1710 /*update capability*/
1711 _account_update_capability(account, account_id);
1716 int account_update_to_db_by_id(const account_h account, int account_id)
1718 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
1719 ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
1720 int error_code = ACCOUNT_ERROR_NONE;
1721 account_s* data = (account_s*)account;
1723 int ret = ACCOUNT_ERROR_NONE;
1725 if (!g_hAccountDB) {
1726 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected. rc : %d", ret));
1729 pthread_mutex_lock(&account_mutex);
1731 error_code = _account_update_account(data, account_id);
1733 pthread_mutex_unlock(&account_mutex);
1735 return ACCOUNT_ERROR_NONE;
1738 int account_update_to_db_by_user_name(account_h account, const char *user_name, const char *package_name)
1740 ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
1741 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
1742 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
1744 int error_code = ACCOUNT_ERROR_NONE;
1745 account_s *data = (account_s*)account;
1747 int ret = ACCOUNT_ERROR_NONE;
1749 if (!g_hAccountDB) {
1750 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected. rc : %d", ret));
1752 pthread_mutex_lock(&account_mutex);
1754 error_code = _account_update_account_by_user_name(data, (char*)user_name, (char*)package_name);
1756 pthread_mutex_unlock(&account_mutex);
1758 return ACCOUNT_ERROR_NONE;
1761 int account_foreach_account_from_db(account_cb callback, void *user_data)
1763 int error_code = ACCOUNT_ERROR_NONE;
1764 account_stmt hstmt = NULL;
1765 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
1767 GList *account_list = NULL;
1769 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INFO IS NULL"));
1771 int ret = ACCOUNT_ERROR_NONE;
1773 if (!g_hAccountDB) {
1774 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected. rc : %d", ret));
1777 ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
1779 ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s ", ACCOUNT_TABLE);
1780 hstmt = _account_prepare_query(query);
1782 rc = _account_query_step(hstmt);
1784 account_s *account_record = NULL;
1786 ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
1789 while(rc == SQLITE_ROW) {
1790 account_record = (account_s*) malloc(sizeof(account_s));
1792 if (account_record == NULL) {
1793 ACCOUNT_DEBUG("malloc Failed");
1796 ACCOUNT_MEMSET(account_record, 0x00, sizeof(account_s));
1798 _account_convert_column_to_account(hstmt, account_record);
1800 account_list = g_list_append(account_list, account_record);
1802 ACCOUNT_DEBUG("##### URUSA account_record(%d) = %p\n", k, account_record);
1804 rc = _account_query_step(hstmt);
1808 _account_query_finalize(hstmt);
1813 for (iter = account_list; iter != NULL; iter = g_list_next(iter)) {
1814 account_s *account = NULL;
1815 account = (account_s*)iter->data;
1816 account_query_capability_by_account_id(_account_get_capability_text_cb, account->id, (void*)account);
1817 callback((account_h)account, user_data);
1821 error_code = ACCOUNT_ERROR_NONE;
1824 if (hstmt != NULL) {
1825 _account_query_finalize(hstmt);
1829 _account_glist_free(account_list);
1830 account_list = NULL;
1837 int account_query_account_by_account_id(int account_db_id, account_h *account)
1839 int error_code = ACCOUNT_ERROR_NONE;
1840 account_stmt hstmt = NULL;
1841 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
1844 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
1846 int ret = ACCOUNT_ERROR_NONE;
1848 if (!g_hAccountDB) {
1849 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected. rc : %d", ret));
1852 ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
1854 ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id = %d", ACCOUNT_TABLE, account_db_id);
1855 hstmt = _account_prepare_query(query);
1857 rc = _account_query_step(hstmt);
1858 ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
1860 account_s *account_record = (account_s *)(*account);
1862 while (rc == SQLITE_ROW) {
1863 _account_convert_column_to_account(hstmt, account_record);
1864 ACCOUNT_DEBUG("get account info by id %p\n", account_record);
1865 rc = _account_query_step(hstmt);
1868 _account_query_finalize(hstmt);
1869 account_query_capability_by_account_id(_account_get_capability_text_cb, account_record->id, (void*)account_record);
1872 error_code = ACCOUNT_ERROR_NONE;
1875 if (hstmt != NULL) {
1876 _account_query_finalize(hstmt);
1880 pthread_mutex_unlock(&account_mutex);
1884 int account_query_account_by_user_name(account_cb cb_func, const char *user_name, void *user_data)
1886 int error_code = ACCOUNT_ERROR_NONE;
1887 account_stmt hstmt = NULL;
1888 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
1891 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
1894 int ret = ACCOUNT_ERROR_NONE;
1896 if (!g_hAccountDB) {
1897 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected. rc : %d", ret));
1900 ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
1902 ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE user_name = ?", ACCOUNT_TABLE);
1904 hstmt = _account_prepare_query(query);
1906 int binding_count = 1;
1907 _account_query_bind_text(hstmt, binding_count++, user_name);
1909 rc = _account_query_step(hstmt);
1911 account_s *account_head = NULL;
1913 ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
1917 account_head = (account_s*) malloc(sizeof(account_s));
1918 if (account_head == NULL) {
1919 ACCOUNT_DEBUG("malloc Failed");
1920 if (hstmt != NULL) {
1921 _account_query_finalize(hstmt);
1924 return ACCOUNT_ERROR_OUT_OF_MEMORY;
1926 ACCOUNT_MEMSET(account_head, 0x00, sizeof(account_s));
1928 while (rc == SQLITE_ROW) {
1929 account_s* account_record = NULL;
1931 account_record = (account_s*) malloc(sizeof(account_s));
1933 if (account_record == NULL) {
1934 ACCOUNT_DEBUG("malloc Failed");
1937 ACCOUNT_MEMSET(account_record, 0x00, sizeof(account_s));
1939 _account_convert_column_to_account(hstmt, account_record);
1941 account_head->account_list = g_list_append(account_head->account_list, account_record);
1943 rc = _account_query_step(hstmt);
1945 ACCOUNT_DEBUG("DETECTED COUNT %d\n", tmp);
1948 _account_query_finalize(hstmt);
1954 tmp = g_list_length(account_head->account_list);
1955 ACCOUNT_DEBUG("GLIST LEN %d\n", tmp);
1957 for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
1959 account = (account_h)iter->data;
1961 account_s *testaccount = (account_s*)account;
1963 ACCOUNT_DEBUG("id = %d", testaccount->id);
1964 ACCOUNT_DEBUG("user_name = %s", testaccount->user_name);
1965 ACCOUNT_DEBUG("email_address = %s", testaccount->email_address);
1966 ACCOUNT_DEBUG("display_name = %s", testaccount->display_name);
1967 ACCOUNT_DEBUG("icon_path = %s", testaccount->icon_path);
1968 ACCOUNT_DEBUG("source = %s", testaccount->source);
1969 ACCOUNT_DEBUG("package_name = %s", testaccount->package_name);
1970 ACCOUNT_DEBUG("access_token = %s", testaccount->access_token);
1971 ACCOUNT_DEBUG("domain_name = %s", testaccount->domain_name);
1972 ACCOUNT_DEBUG("auth_type = %d", testaccount->auth_type);
1973 ACCOUNT_DEBUG("secret = %d", testaccount->secret);
1974 ACCOUNT_DEBUG("user text = %s", testaccount->user_data_txt[0]);
1975 ACCOUNT_DEBUG("user text = %s", testaccount->user_data_txt[1]);
1976 ACCOUNT_DEBUG("user text = %s", testaccount->user_data_txt[2]);
1977 ACCOUNT_DEBUG("user text = %s", testaccount->user_data_txt[3]);
1978 ACCOUNT_DEBUG("user text = %s", testaccount->user_data_txt[4]);
1979 ACCOUNT_DEBUG("user int = %d", testaccount->user_data_int[0]);
1980 ACCOUNT_DEBUG("user int = %d", testaccount->user_data_int[1]);
1981 ACCOUNT_DEBUG("user int = %d", testaccount->user_data_int[2]);
1982 ACCOUNT_DEBUG("user int = %d", testaccount->user_data_int[3]);
1983 ACCOUNT_DEBUG("user int = %d", testaccount->user_data_int[4]);
1985 account_query_capability_by_account_id(_account_get_capability_text_cb, testaccount->id, (void*)testaccount);
1987 ACCOUNT_DEBUG("capability_list address = %p", testaccount->capablity_list);
1989 cb_func(account, user_data);
1993 error_code = ACCOUNT_ERROR_NONE;
1996 if (hstmt != NULL) {
1997 _account_query_finalize(hstmt);
2001 if (account_head->account_list) {
2002 _account_glist_free(account_head->account_list);
2003 account_head->account_list = NULL;
2004 _account_free_account_items(account_head);
2005 _ACCOUNT_FREE(account_head);
2009 pthread_mutex_unlock(&account_mutex);
2013 int account_query_account_by_capability(account_cb cb_func, account_capability_type_e capability_type, account_capability_state_e capability_value, void* user_data)
2015 int error_code = ACCOUNT_ERROR_NONE;
2016 account_stmt hstmt = NULL;
2017 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
2020 if ( (capability_type < 0) || (capability_type > ACCOUNT_CAPABILITY_MOBILE_TRACKER)) {
2021 ACCOUNT_DEBUG("(%s)-(%d) capability_type is less than 1 or more than enum max.\n", __FUNCTION__, __LINE__);
2022 return ACCOUNT_ERROR_INVALID_PARAMETER;
2025 if ((capability_value < 0) || (capability_value > ACCOUNT_CAPABILITY_ENABLED)) {
2026 ACCOUNT_DEBUG("(%s)-(%d) capability_value is not equal to 0 or 1.\n", __FUNCTION__, __LINE__);
2027 return ACCOUNT_ERROR_INVALID_PARAMETER;
2030 ACCOUNT_RETURN_VAL((cb_func != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
2032 int ret = ACCOUNT_ERROR_NONE;
2034 if (!g_hAccountDB) {
2035 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected. rc : %d", ret));
2038 ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
2040 ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id IN (SELECT account_id from %s WHERE key=? AND value=?)", ACCOUNT_TABLE, CAPABILITY_TABLE);
2042 hstmt = _account_prepare_query(query);
2044 int binding_count = 1;
2045 _account_query_bind_int(hstmt, binding_count++, (int)capability_type);
2046 _account_query_bind_int(hstmt, binding_count++, (int)capability_value);
2048 rc = _account_query_step(hstmt);
2050 account_s* account_head = NULL;
2052 ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
2056 account_head = (account_s*) malloc(sizeof(account_s));
2057 if (account_head == NULL) {
2058 ACCOUNT_DEBUG("malloc Failed");
2059 if (hstmt != NULL) {
2060 _account_query_finalize(hstmt);
2063 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2065 ACCOUNT_MEMSET(account_head, 0x00, sizeof(account_s));
2067 while (rc == SQLITE_ROW) {
2068 account_s* account_record = NULL;
2070 account_record = (account_s*) malloc(sizeof(account_s));
2072 if (account_record == NULL) {
2073 ACCOUNT_DEBUG("malloc Failed");
2076 ACCOUNT_MEMSET(account_record, 0x00, sizeof(account_s));
2078 _account_convert_column_to_account(hstmt, account_record);
2080 account_head->account_list = g_list_append(account_head->account_list, account_record);
2082 rc = _account_query_step(hstmt);
2084 ACCOUNT_DEBUG("DETECTED COUNT %d\n", tmp);
2087 _account_query_finalize(hstmt);
2093 tmp = g_list_length(account_head->account_list);
2094 ACCOUNT_DEBUG("GLIST LEN %d\n", tmp);
2096 for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
2097 account_h account = NULL;
2098 account = (account_h)iter->data;
2101 account_s* testaccount = (account_s*)account;
2103 ACCOUNT_DEBUG("id = %d", testaccount->id);
2104 ACCOUNT_DEBUG("user_name = %s", testaccount->user_name);
2105 ACCOUNT_DEBUG("email_address = %s", testaccount->email_address);
2106 ACCOUNT_DEBUG("display_name = %s", testaccount->display_name);
2107 ACCOUNT_DEBUG("icon_path = %s", testaccount->icon_path);
2108 ACCOUNT_DEBUG("source = %s", testaccount->source);
2109 ACCOUNT_DEBUG("package_name = %s", testaccount->package_name);
2110 ACCOUNT_DEBUG("access_token = %s", testaccount->access_token);
2111 ACCOUNT_DEBUG("domain_name = %s", testaccount->domain_name);
2112 ACCOUNT_DEBUG("auth_type = %d", testaccount->auth_type);
2113 ACCOUNT_DEBUG("secret = %d", testaccount->secret);
2114 ACCOUNT_DEBUG("user text = %s", testaccount->user_data_txt[0]);
2115 ACCOUNT_DEBUG("user text = %s", testaccount->user_data_txt[1]);
2116 ACCOUNT_DEBUG("user text = %s", testaccount->user_data_txt[2]);
2117 ACCOUNT_DEBUG("user text = %s", testaccount->user_data_txt[3]);
2118 ACCOUNT_DEBUG("user text = %s", testaccount->user_data_txt[4]);
2119 ACCOUNT_DEBUG("user int = %d", testaccount->user_data_int[0]);
2120 ACCOUNT_DEBUG("user int = %d", testaccount->user_data_int[1]);
2121 ACCOUNT_DEBUG("user int = %d", testaccount->user_data_int[2]);
2122 ACCOUNT_DEBUG("user int = %d", testaccount->user_data_int[3]);
2123 ACCOUNT_DEBUG("user int = %d", testaccount->user_data_int[4]);
2125 account_query_capability_by_account_id(_account_get_capability_text_cb, testaccount->id, (void*)testaccount);
2127 ACCOUNT_DEBUG("capability_list address = %p", testaccount->capablity_list);
2129 cb_func(account, user_data);
2134 error_code = ACCOUNT_ERROR_NONE;
2137 if (hstmt != NULL) {
2138 _account_query_finalize(hstmt);
2142 if (account_head->account_list) {
2143 _account_glist_free(account_head->account_list);
2144 account_head->account_list = NULL;
2145 _account_free_account_items(account_head);
2146 _ACCOUNT_FREE(account_head);
2150 pthread_mutex_unlock(&account_mutex);
2155 int account_query_account_by_package_name(account_cb cb_func, const char* package_name, void* user_data)
2157 int error_code = ACCOUNT_ERROR_NONE;
2158 account_stmt hstmt = NULL;
2159 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
2162 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
2163 ACCOUNT_RETURN_VAL((cb_func != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
2165 int ret = ACCOUNT_ERROR_NONE;
2167 if (!g_hAccountDB) {
2168 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected. rc : %d", ret));
2171 ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
2173 ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE package_name=?", ACCOUNT_TABLE);
2175 hstmt = _account_prepare_query(query);
2177 int binding_count = 1;
2178 _account_query_bind_text(hstmt, binding_count++, package_name);
2180 rc = _account_query_step(hstmt);
2182 account_s* account_head = NULL;
2184 ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
2188 account_head = (account_s*) malloc(sizeof(account_s));
2189 if (account_head == NULL) {
2190 ACCOUNT_DEBUG("malloc Failed");
2191 if (hstmt != NULL) {
2192 _account_query_finalize(hstmt);
2195 return ACCOUNT_ERROR_OUT_OF_MEMORY;
2197 ACCOUNT_MEMSET(account_head, 0x00, sizeof(account_s));
2199 while (rc == SQLITE_ROW) {
2200 account_s* account_record = NULL;
2202 account_record = (account_s*) malloc(sizeof(account_s));
2204 if (account_record == NULL) {
2205 ACCOUNT_DEBUG("malloc Failed");
2208 ACCOUNT_MEMSET(account_record, 0x00, sizeof(account_s));
2210 _account_convert_column_to_account(hstmt, account_record);
2212 account_head->account_list = g_list_append(account_head->account_list, account_record);
2214 rc = _account_query_step(hstmt);
2216 ACCOUNT_DEBUG("DETECTED COUNT %d\n", tmp);
2219 _account_query_finalize(hstmt);
2225 tmp = g_list_length(account_head->account_list);
2226 ACCOUNT_DEBUG("GLIST LEN %d\n", tmp);
2228 for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
2229 account_h account = NULL;
2230 account = (account_h)iter->data;
2233 account_s* testaccount = (account_s*)account;
2235 ACCOUNT_DEBUG("id = %d", testaccount->id);
2236 ACCOUNT_DEBUG("user_name = %s", testaccount->user_name);
2237 ACCOUNT_DEBUG("email_address = %s", testaccount->email_address);
2238 ACCOUNT_DEBUG("display_name = %s", testaccount->display_name);
2239 ACCOUNT_DEBUG("icon_path = %s", testaccount->icon_path);
2240 ACCOUNT_DEBUG("source = %s", testaccount->source);
2241 ACCOUNT_DEBUG("package_name = %s", testaccount->package_name);
2242 ACCOUNT_DEBUG("access_token = %s", testaccount->access_token);
2243 ACCOUNT_DEBUG("domain_name = %s", testaccount->domain_name);
2244 ACCOUNT_DEBUG("auth_type = %d", testaccount->auth_type);
2245 ACCOUNT_DEBUG("secret = %d", testaccount->secret);
2246 ACCOUNT_DEBUG("user text = %s", testaccount->user_data_txt[0]);
2247 ACCOUNT_DEBUG("user text = %s", testaccount->user_data_txt[1]);
2248 ACCOUNT_DEBUG("user text = %s", testaccount->user_data_txt[2]);
2249 ACCOUNT_DEBUG("user text = %s", testaccount->user_data_txt[3]);
2250 ACCOUNT_DEBUG("user text = %s", testaccount->user_data_txt[4]);
2251 ACCOUNT_DEBUG("user int = %d", testaccount->user_data_int[0]);
2252 ACCOUNT_DEBUG("user int = %d", testaccount->user_data_int[1]);
2253 ACCOUNT_DEBUG("user int = %d", testaccount->user_data_int[2]);
2254 ACCOUNT_DEBUG("user int = %d", testaccount->user_data_int[3]);
2255 ACCOUNT_DEBUG("user int = %d", testaccount->user_data_int[4]);
2257 account_query_capability_by_account_id(_account_get_capability_text_cb, testaccount->id, (void*)testaccount);
2259 ACCOUNT_DEBUG("capability_list address = %p", testaccount->capablity_list);
2261 cb_func(account, user_data);
2265 error_code = ACCOUNT_ERROR_NONE;
2268 if (hstmt != NULL) {
2269 _account_query_finalize(hstmt);
2273 if (account_head->account_list) {
2274 _account_glist_free(account_head->account_list);
2275 account_head->account_list = NULL;
2276 _account_free_account_items(account_head);
2277 _ACCOUNT_FREE(account_head);
2281 pthread_mutex_unlock(&account_mutex);
2285 int account_delete(int account_id)
2287 int error_code = ACCOUNT_ERROR_NONE;
2288 account_stmt hstmt = NULL;
2289 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
2291 int ret_transaction = 0, ret =0;
2292 bool is_success = FALSE;
2294 if (!g_hAccountDB) {
2295 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected. rc : %d", ret));
2298 /* transaction control required*/
2299 ret_transaction = _account_begin_transaction();
2301 if (ret_transaction != ACCOUNT_ERROR_NONE) {
2302 ACCOUNT_DEBUG("account_delete:_account_begin_transaction fail %d\n", ret_transaction);
2303 pthread_mutex_unlock(&account_mutex);
2304 return ret_transaction;
2307 ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE account_id = %d", CAPABILITY_TABLE, account_id);
2309 hstmt = _account_prepare_query(query);
2310 ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
2311 ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
2313 rc = _account_query_step(hstmt);
2314 ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
2316 _account_query_finalize(hstmt);
2319 ACCOUNT_MEMSET(query, 0, sizeof(query));
2321 ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE _id = %d", ACCOUNT_TABLE, account_id);
2323 hstmt = _account_prepare_query(query);
2324 ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
2325 ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
2327 rc = _account_query_step(hstmt);
2328 ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found. id=%d, rc=%d\n", account_id, rc));
2330 _account_query_finalize(hstmt);
2336 if (hstmt != NULL) {
2337 _account_query_finalize(hstmt);
2341 ret_transaction = _account_end_transaction(is_success);
2343 if (ret_transaction != ACCOUNT_ERROR_NONE) {
2344 ACCOUNT_DEBUG("account_svc_delete:_account_svc_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
2347 pthread_mutex_unlock(&account_mutex);
2353 int account_delete_from_db_by_id(int account_db_id)
2355 ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID IS LESS THAN ZERO."));
2357 account_delete(account_db_id);
2360 int account_delete_from_db_by_user_name(char *user_name, char *package_name)
2362 int error_code = ACCOUNT_ERROR_NONE;
2363 account_stmt hstmt = NULL;
2364 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
2366 int ret_transaction = 0, ret =0;
2367 bool is_success = FALSE;
2369 ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is null!"));
2370 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
2372 if (!g_hAccountDB) {
2373 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected. rc : %d", ret));
2376 /* transaction control required*/
2377 ret_transaction = _account_begin_transaction();
2379 if (ret_transaction != ACCOUNT_ERROR_NONE) {
2380 ACCOUNT_DEBUG("account_delete:_account_begin_transaction fail %d\n", ret_transaction);
2381 pthread_mutex_unlock(&account_mutex);
2382 return ret_transaction;
2385 ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE user_name = ? and package_name = ?", CAPABILITY_TABLE);
2387 hstmt = _account_prepare_query(query);
2389 ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
2390 ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
2392 int binding_count = 1;
2393 _account_query_bind_text(hstmt, binding_count++, user_name);
2394 _account_query_bind_text(hstmt, binding_count++, package_name);
2396 rc = _account_query_step(hstmt);
2397 ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
2399 _account_query_finalize(hstmt);
2402 ACCOUNT_MEMSET(query, 0, sizeof(query));
2404 ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE user_name = ? and package_name = ?", ACCOUNT_TABLE);
2406 hstmt = _account_prepare_query(query);
2407 ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
2408 ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
2411 _account_query_bind_text(hstmt, binding_count++, user_name);
2412 _account_query_bind_text(hstmt, binding_count++, package_name);
2414 rc = _account_query_step(hstmt);
2415 ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found. user_name=%s, package_name=%s, rc=%d\n", user_name, package_name, rc));
2417 _account_query_finalize(hstmt);
2423 if (hstmt != NULL) {
2424 _account_query_finalize(hstmt);
2428 ret_transaction = _account_end_transaction(is_success);
2430 if (ret_transaction != ACCOUNT_ERROR_NONE) {
2431 ACCOUNT_DEBUG("account_svc_delete:_account_svc_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
2434 pthread_mutex_unlock(&account_mutex);
2439 int account_delete_from_db_by_package_name(char *package_name)
2441 int error_code = ACCOUNT_ERROR_NONE;
2442 account_stmt hstmt = NULL;
2443 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
2445 int ret_transaction = 0, ret =0;
2446 bool is_success = FALSE;
2448 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
2450 if (!g_hAccountDB) {
2451 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected. rc : %d", ret));
2454 /* transaction control required*/
2455 ret_transaction = _account_begin_transaction();
2457 if (ret_transaction != ACCOUNT_ERROR_NONE) {
2458 ACCOUNT_DEBUG("account_delete:_account_begin_transaction fail %d\n", ret_transaction);
2459 pthread_mutex_unlock(&account_mutex);
2460 return ret_transaction;
2463 ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE package_name = ?", CAPABILITY_TABLE);
2465 hstmt = _account_prepare_query(query);
2467 ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
2468 ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
2470 int binding_count = 1;
2471 _account_query_bind_text(hstmt, binding_count++, package_name);
2473 rc = _account_query_step(hstmt);
2474 ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
2476 _account_query_finalize(hstmt);
2479 ACCOUNT_MEMSET(query, 0, sizeof(query));
2481 ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE package_name = ?", ACCOUNT_TABLE);
2483 hstmt = _account_prepare_query(query);
2484 ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
2485 ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
2488 _account_query_bind_text(hstmt, binding_count++, package_name);
2490 rc = _account_query_step(hstmt);
2491 ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found. package_name=%s, rc=%d\n", package_name, rc));
2493 _account_query_finalize(hstmt);
2499 if (hstmt != NULL) {
2500 _account_query_finalize(hstmt);
2504 ret_transaction = _account_end_transaction(is_success);
2506 if (ret_transaction != ACCOUNT_ERROR_NONE) {
2507 ACCOUNT_DEBUG("account_svc_delete:_account_svc_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
2510 pthread_mutex_unlock(&account_mutex);
2515 int account_get_total_count_from_db(int *count)
2518 ACCOUNT_DEBUG("(%s)-(%d) count is NULL.\n", __FUNCTION__, __LINE__);
2519 return ACCOUNT_ERROR_INVALID_PARAMETER;
2522 char query[1024] = {0, };
2523 ACCOUNT_MEMSET(query, 0x00, sizeof(query));
2524 ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from %s", ACCOUNT_TABLE);
2526 *count = _account_get_record_count(query);
2529 account_stmt pStmt = NULL;
2531 assert(NULL != g_hAccountDB);
2532 rc = sqlite3_prepare_v2(g_hAccountDB, query, strlen(query), &pStmt, NULL);
2534 rc = sqlite3_step(pStmt);
2535 if (SQLITE_ROW != rc) {
2536 ACCOUNT_DEBUG("[ERROR] sqlite3_step() failed\n");
2537 sqlite3_finalize(pStmt);
2538 return ACCOUNT_ERROR_DB_FAILED;
2541 ncount = sqlite3_column_int(pStmt, 0);
2545 ACCOUNT_DEBUG("Number of account : %d", ncount);
2546 sqlite3_finalize(pStmt);
2549 ACCOUNT_DEBUG("[ERROR] Number of account : %d, End", ncount);
2550 return ACCOUNT_ERROR_DB_FAILED;
2553 return ACCOUNT_ERROR_NONE;
2556 int account_destroy(account_h account)
2558 account_s *data = (account_s*)account;
2560 ACCOUNT_RETURN_VAL((data != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account handle is null!"));
2562 ACCOUNT_DEBUG("destroy handle=%p\n", data);
2564 _account_free_account_items(data);
2565 _ACCOUNT_FREE(data);
2567 return ACCOUNT_ERROR_NONE;