3 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
28 #include <account-private.h>
29 #include <account_free.h>
31 #include "account_private_client.h"
32 #include "account_internal.h"
34 #ifdef TIZEN_PROFILE_MOBILE
35 #include "mobile/account.h"
37 #include "wearable/account.h"
40 #define ACCOUNT_DB_OPEN_READONLY 0
41 #define ACCOUNT_DB_OPEN_READWRITE 1
43 typedef sqlite3_stmt* account_stmt;
45 static sqlite3* g_hAccountDB = NULL;
46 static int g_refCntDB = 0;
47 pthread_mutex_t account_mutex = PTHREAD_MUTEX_INITIALIZER;
49 static const char *_account_db_err_msg()
51 return sqlite3_errmsg(g_hAccountDB);
54 static int _account_db_err_code()
56 return sqlite3_errcode(g_hAccountDB);
59 static int _account_db_open(int mode)
63 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
65 char *client_db_path = NULL;
67 _INFO( "start to get DB path");
69 ret = vsm_canonicalize_path("/opt/usr/dbspace/.account.db", &client_db_path);
71 _ERR( "vsm_canonicalize_path fail ret = %d", ret);
72 _ACCOUNT_FREE(client_db_path);
73 return ACCOUNT_ERROR_PERMISSION_DENIED;
76 _INFO( "account_db_path canonicalized = %s", client_db_path);
78 ACCOUNT_MEMSET(query, 0x00, sizeof(query));
81 if(mode == ACCOUNT_DB_OPEN_READWRITE)
82 rc = db_util_open(client_db_path, &g_hAccountDB, DB_UTIL_REGISTER_HOOK_METHOD);
83 else if(mode == ACCOUNT_DB_OPEN_READONLY)
84 rc = db_util_open_with_options(client_db_path, &g_hAccountDB, SQLITE_OPEN_READONLY, NULL);
86 _ACCOUNT_FREE(client_db_path);
87 return ACCOUNT_ERROR_DB_NOT_OPENED;
89 _ACCOUNT_FREE(client_db_path);
91 if( _account_db_err_code() == SQLITE_PERM ){
92 ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
93 return ACCOUNT_ERROR_PERMISSION_DENIED;
96 ACCOUNT_RETURN_VAL((rc != SQLITE_PERM), {}, ACCOUNT_ERROR_PERMISSION_DENIED, ("Account permission denied rc : %d", rc));
97 ACCOUNT_RETURN_VAL((rc == SQLITE_OK), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected. rc : %d", rc));
101 _ACCOUNT_FREE(client_db_path);
104 ACCOUNT_RETURN_VAL((rc == SQLITE_OK), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("busy handler fail. rc : %d", rc));
106 return ACCOUNT_ERROR_NONE;
109 static int _account_db_close(void)
115 if (g_refCntDB > 0) {
118 if (g_refCntDB == 0) {
119 rc = db_util_close(g_hAccountDB);
120 if( rc == SQLITE_PERM ){
121 ACCOUNT_ERROR( "Access failed(SQLITE_PERM)");
122 return ACCOUNT_ERROR_PERMISSION_DENIED;
123 } else if ( rc == SQLITE_BUSY ){
124 ACCOUNT_ERROR( "database busy");
125 return ACCOUNT_ERROR_DATABASE_BUSY;
127 ACCOUNT_RETURN_VAL((rc == SQLITE_OK), {}, ACCOUNT_ERROR_DB_FAILED, ("The database isn't connected. rc : %d", rc));
130 ret = ACCOUNT_ERROR_NONE;
132 ACCOUNT_ERROR( "_account_svc_db_close: No handle(). refcnt=%d ", g_refCntDB);
133 ret = ACCOUNT_ERROR_DB_FAILED;
139 static int _account_execute_query(const char *query)
142 char* pszErrorMsg = NULL;
145 ACCOUNT_ERROR("NULL query\n");
146 return ACCOUNT_ERROR_QUERY_SYNTAX_ERROR;
150 ACCOUNT_ERROR("DB is not opened\n");
151 return ACCOUNT_ERROR_DB_NOT_OPENED;
154 rc = sqlite3_exec(g_hAccountDB, query, NULL, NULL, &pszErrorMsg);
155 if (SQLITE_OK != rc) {
156 ACCOUNT_ERROR("sqlite3_exec rc(%d) query(%s) failed(%s).", rc, query, pszErrorMsg);
157 sqlite3_free(pszErrorMsg);
163 static int _account_begin_transaction(void)
165 ACCOUNT_DEBUG("_account_begin_transaction start");
168 ret = _account_execute_query("BEGIN IMMEDIATE TRANSACTION");
170 if (ret == SQLITE_BUSY){
171 ACCOUNT_ERROR(" sqlite3 busy = %d", ret);
172 return ACCOUNT_ERROR_DATABASE_BUSY;
173 } else if(ret != SQLITE_OK) {
174 ACCOUNT_ERROR("_account_svc_begin_transaction fail :: %d", ret);
175 return ACCOUNT_ERROR_DB_FAILED;
178 ACCOUNT_DEBUG("_account_begin_transaction end");
179 return ACCOUNT_ERROR_NONE;
182 static int _account_end_transaction(bool is_success)
184 ACCOUNT_DEBUG("_account_end_transaction start");
188 if (is_success == true) {
189 ret = _account_execute_query("COMMIT TRANSACTION");
190 ACCOUNT_DEBUG("_account_end_transaction COMMIT");
192 ret = _account_execute_query("ROLLBACK TRANSACTION");
193 ACCOUNT_DEBUG("_account_end_transaction ROLLBACK");
196 if(ret == SQLITE_PERM){
197 ACCOUNT_ERROR("Account permission denied :: %d", ret);
198 return ACCOUNT_ERROR_PERMISSION_DENIED;
201 if (ret == SQLITE_BUSY){
202 ACCOUNT_DEBUG(" sqlite3 busy = %d", ret);
203 return ACCOUNT_ERROR_DATABASE_BUSY;
206 if (ret != SQLITE_OK) {
207 ACCOUNT_ERROR("_account_svc_end_transaction fail :: %d", ret);
208 return ACCOUNT_ERROR_DB_FAILED;
211 ACCOUNT_DEBUG("_account_end_transaction end");
212 return ACCOUNT_ERROR_NONE;
215 static int _account_get_record_count(char* query)
217 _INFO("_account_get_record_count");
221 account_stmt pStmt = NULL;
224 _ERR("NULL query\n");
225 return ACCOUNT_ERROR_QUERY_SYNTAX_ERROR;
229 _ERR("DB is not opened\n");
230 return ACCOUNT_ERROR_DB_NOT_OPENED;
233 rc = sqlite3_prepare_v2(g_hAccountDB, query, strlen(query), &pStmt, NULL);
235 if (SQLITE_BUSY == rc){
236 _ERR("sqlite3_prepare_v2() failed(%d, %s).", rc, _account_db_err_msg());
237 sqlite3_finalize(pStmt);
238 return ACCOUNT_ERROR_DATABASE_BUSY;
239 } else if (SQLITE_OK != rc) {
240 _ERR("sqlite3_prepare_v2() failed(%d, %s).", rc, _account_db_err_msg());
241 sqlite3_finalize(pStmt);
242 return ACCOUNT_ERROR_DB_FAILED;
245 rc = sqlite3_step(pStmt);
246 if (SQLITE_BUSY == rc) {
247 _ERR("sqlite3_step() failed(%d, %s).", rc, _account_db_err_msg());
248 sqlite3_finalize(pStmt);
249 return ACCOUNT_ERROR_DATABASE_BUSY;
250 } else if (SQLITE_ROW != rc) {
251 _ERR("sqlite3_step() failed(%d, %s).", rc, _account_db_err_msg());
252 sqlite3_finalize(pStmt);
253 return ACCOUNT_ERROR_DB_FAILED;
256 ncount = sqlite3_column_int(pStmt, 0);
258 _INFO("account record count [%d]", ncount);
259 sqlite3_finalize(pStmt);
264 static int _account_query_bind_int(account_stmt pStmt, int pos, int num)
267 ACCOUNT_ERROR("statement is null");
272 ACCOUNT_ERROR("invalid pos");
276 return sqlite3_bind_int(pStmt, pos, num);
279 static int _account_query_bind_text(account_stmt pStmt, int pos, const char *str)
281 _INFO("_account_query_bind_text");
285 _ERR("statement is null");
291 _INFO("sqlite3_bind_text");
292 return sqlite3_bind_text(pStmt, pos, (const char*)str, strlen(str), SQLITE_STATIC);
296 _INFO("sqlite3_bind_null");
297 return sqlite3_bind_null(pStmt, pos);
301 static int _account_type_convert_account_to_sql(account_type_s *account_type, account_stmt hstmt, char *sql_value)
307 /*Caution : Keep insert query orders.*/
310 _account_query_bind_text(hstmt, count++, (char*)account_type->app_id);
312 /* 2. service provider id*/
313 _account_query_bind_text(hstmt, count++, (char*)account_type->service_provider_id);
316 _account_query_bind_text(hstmt, count++, (char*)account_type->icon_path);
318 /* 4. small icon path*/
319 _account_query_bind_text(hstmt, count++, (char*)account_type->small_icon_path);
321 /* 5. multiple accont support*/
322 _account_query_bind_int(hstmt, count++, account_type->multiple_account_support);
329 static gboolean _account_type_check_duplicated(account_type_s *data)
331 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
334 ACCOUNT_MEMSET(query, 0x00, sizeof(query));
336 ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE AppId='%s'"
337 , ACCOUNT_TYPE_TABLE, data->app_id);
339 count = _account_get_record_count(query);
347 static int _account_query_finalize(account_stmt pStmt)
352 ACCOUNT_ERROR( "pStmt is NULL");
353 return ACCOUNT_ERROR_INVALID_PARAMETER;
356 rc = sqlite3_finalize(pStmt);
357 if (rc == SQLITE_BUSY){
358 ACCOUNT_ERROR(" sqlite3 busy = %d", rc);
359 return ACCOUNT_ERROR_DATABASE_BUSY;
360 } else if (rc != SQLITE_OK) {
361 ACCOUNT_ERROR( "sqlite3_finalize fail, rc : %d, db_error : %s\n", rc, _account_db_err_msg());
362 return ACCOUNT_ERROR_DB_FAILED;
365 return ACCOUNT_ERROR_NONE;
368 static int _account_query_step(account_stmt pStmt)
371 ACCOUNT_ERROR( "pStmt is NULL");
375 return sqlite3_step(pStmt);
378 static account_stmt _account_prepare_query(char *query)
381 account_stmt pStmt = NULL;
383 ACCOUNT_RETURN_VAL((query != NULL), {}, NULL, ("query is NULL"));
385 rc = sqlite3_prepare_v2(g_hAccountDB, query, strlen(query), &pStmt, NULL);
387 ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, NULL, ("sqlite3_prepare_v2(%s) failed(%s).", query, _account_db_err_msg()));
392 static int _account_get_next_sequence(const char *pszName)
395 account_stmt pStmt = NULL;
397 char szQuery[ACCOUNT_SQL_LEN_MAX] = {0,};
399 ACCOUNT_MEMSET(szQuery, 0x00, sizeof(szQuery));
400 ACCOUNT_SNPRINTF(szQuery, sizeof(szQuery), "SELECT max(seq) FROM %s where name = '%s' ", ACCOUNT_SQLITE_SEQ, pszName);
401 rc = sqlite3_prepare_v2(g_hAccountDB, szQuery, strlen(szQuery), &pStmt, NULL);
402 if (SQLITE_OK != rc) {
403 ACCOUNT_SLOGE("sqlite3_prepare_v2() failed(%d, %s).", rc, _account_db_err_msg());
404 sqlite3_finalize(pStmt);
405 return ACCOUNT_ERROR_DB_FAILED;
408 rc = sqlite3_step(pStmt);
409 max_seq = sqlite3_column_int(pStmt, 0);
412 /*Finalize Statement*/
413 rc = sqlite3_finalize(pStmt);
419 static int _account_type_insert_provider_feature(account_type_s *account_type, const char* app_id)
422 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
423 account_stmt hstmt = NULL;
425 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
426 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
428 if (g_slist_length( account_type->provider_feature_list)==0) {
429 ACCOUNT_ERROR( "no capability\n");
430 return ACCOUNT_ERROR_NONE;
433 ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where AppId='%s'", ACCOUNT_TYPE_TABLE, app_id);
435 rc = _account_get_record_count(query);
437 if( _account_db_err_code() == SQLITE_PERM ){
438 ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
439 return ACCOUNT_ERROR_PERMISSION_DENIED;
443 ACCOUNT_SLOGI( "related account type item is not existed rc=%d , %s", rc, _account_db_err_msg());
444 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
451 for (iter = account_type->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
454 ACCOUNT_MEMSET(query, 0x00, sizeof(query));
455 ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(app_id, key) VALUES "
456 "(?, ?) ", PROVIDER_FEATURE_TABLE);
458 hstmt = _account_prepare_query(query);
460 ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
462 provider_feature_s* feature_data = NULL;
463 feature_data = (provider_feature_s*)iter->data;
465 ret = _account_query_bind_text(hstmt, count++, app_id);
466 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
467 ret = _account_query_bind_text(hstmt, count++, feature_data->key);
468 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
470 rc = _account_query_step(hstmt);
472 if (rc != SQLITE_DONE) {
473 ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
477 rc = _account_query_finalize(hstmt);
478 ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
483 return ACCOUNT_ERROR_NONE;
486 static int _account_type_insert_label(account_type_s *account_type)
489 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
490 account_stmt hstmt = NULL;
492 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
494 if (g_slist_length( account_type->label_list)==0) {
495 ACCOUNT_ERROR( "_account_type_insert_label, no label\n");
496 return ACCOUNT_ERROR_NONE;
499 ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where AppId = '%s'", ACCOUNT_TYPE_TABLE, account_type->app_id);
501 rc = _account_get_record_count(query);
503 if( _account_db_err_code() == SQLITE_PERM ){
504 ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
505 return ACCOUNT_ERROR_PERMISSION_DENIED;
509 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
515 for (iter = account_type->label_list; iter != NULL; iter = g_slist_next(iter)) {
518 ACCOUNT_MEMSET(query, 0x00, sizeof(query));
519 ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(AppId, Label, Locale) VALUES "
520 "(?, ?, ?) ", LABEL_TABLE);
522 hstmt = _account_prepare_query(query);
524 ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
526 label_s* label_data = NULL;
527 label_data = (label_s*)iter->data;
529 ret = _account_query_bind_text(hstmt, count++, account_type->app_id);
530 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
531 ret = _account_query_bind_text(hstmt, count++, label_data->label);
532 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
533 ret = _account_query_bind_text(hstmt, count++, (char*)label_data->locale);
534 ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
536 rc = _account_query_step(hstmt);
538 if (rc != SQLITE_DONE) {
539 ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
543 rc = _account_query_finalize(hstmt);
544 ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
549 return ACCOUNT_ERROR_NONE;
552 static int _account_type_execute_insert_query(account_type_s *account_type)
557 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
558 int error_code = ACCOUNT_ERROR_NONE;
559 account_stmt hstmt = NULL;
561 /* check mandatory field */
562 // app id & service provider id
563 if (!account_type->app_id) {
564 return ACCOUNT_ERROR_INVALID_PARAMETER;
567 ACCOUNT_MEMSET(query, 0x00, sizeof(query));
568 ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s( AppId, ServiceProviderId , IconPath , SmallIconPath , MultipleAccountSupport ) values "
569 "(?, ?, ?, ?, ?)", ACCOUNT_TYPE_TABLE);
572 hstmt = _account_prepare_query(query);
575 if( _account_db_err_code() == SQLITE_PERM ){
576 ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
577 return ACCOUNT_ERROR_PERMISSION_DENIED;
578 } else if( _account_db_err_code() == SQLITE_BUSY ){
579 ACCOUNT_ERROR( "Database Busy(%s)", _account_db_err_msg());
580 return ACCOUNT_ERROR_DATABASE_BUSY;
583 ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
586 _account_type_convert_account_to_sql(account_type, hstmt, query);
589 rc = _account_query_step(hstmt);
590 if (rc == SQLITE_BUSY) {
591 ACCOUNT_ERROR( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg());
592 error_code = ACCOUNT_ERROR_DATABASE_BUSY;
593 } else if (rc != SQLITE_DONE) {
594 ACCOUNT_ERROR( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg());
595 error_code = ACCOUNT_ERROR_DB_FAILED;
599 rc = _account_query_finalize(hstmt);
600 ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
607 int _account_type_insert_to_db(account_type_s* account_type, int* account_type_id)
611 int error_code = ACCOUNT_ERROR_NONE, ret_transaction = 0;
613 ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
614 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE HANDLE IS NULL"));
615 ACCOUNT_RETURN_VAL((account_type_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE ID POINTER IS NULL"));
617 account_type_s *data = (account_type_s*)account_type;
619 pthread_mutex_lock(&account_mutex);
622 /* transaction control required*/
623 ret_transaction = _account_begin_transaction();
627 if( _account_db_err_code() == SQLITE_PERM ){
628 pthread_mutex_unlock(&account_mutex);
629 ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
630 return ACCOUNT_ERROR_PERMISSION_DENIED;
634 if( ret_transaction == ACCOUNT_ERROR_DATABASE_BUSY ){
635 ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg());
636 pthread_mutex_unlock(&account_mutex);
637 return ACCOUNT_ERROR_DATABASE_BUSY;
638 } else if (ret_transaction != ACCOUNT_ERROR_NONE) {
639 ACCOUNT_ERROR("_account_begin_transaction fail %d\n", ret_transaction);
640 pthread_mutex_unlock(&account_mutex);
641 return ret_transaction;
645 if (_account_type_check_duplicated(data)) {
647 ret_transaction = _account_end_transaction(FALSE);
648 ACCOUNT_ERROR("Duplicated, rollback insert query(%x)!!!!\n", ret_transaction);
649 *account_type_id = -1;
650 pthread_mutex_unlock(&account_mutex);
651 return ACCOUNT_ERROR_DUPLICATED;
654 *account_type_id = _account_get_next_sequence(ACCOUNT_TYPE_TABLE);
656 error_code = _account_type_execute_insert_query(data);
658 if (error_code != ACCOUNT_ERROR_NONE){
659 error_code = ACCOUNT_ERROR_DUPLICATED;
660 ret_transaction = _account_end_transaction(FALSE);
661 ACCOUNT_ERROR("Insert fail, rollback insert query(%x)!!!!\n", ret_transaction);
662 *account_type_id = -1;
663 pthread_mutex_unlock(&account_mutex);
669 error_code = _account_type_insert_provider_feature(data, data->app_id);
670 if(error_code != ACCOUNT_ERROR_NONE) {
672 ret_transaction = _account_end_transaction(FALSE);
673 ACCOUNT_ERROR("Insert provider feature fail(%x), rollback insert query(%x)!!!!\n", error_code, ret_transaction);
674 pthread_mutex_unlock(&account_mutex);
678 error_code = _account_type_insert_label(data);
679 if(error_code != ACCOUNT_ERROR_NONE) {
681 ret_transaction = _account_end_transaction(FALSE);
682 ACCOUNT_ERROR("Insert label fail(%x), rollback insert query(%x)!!!!\n", error_code, ret_transaction);
683 pthread_mutex_unlock(&account_mutex);
687 ret_transaction = _account_end_transaction(TRUE);
689 pthread_mutex_unlock(&account_mutex);
692 return ACCOUNT_ERROR_NONE;
695 int _account_type_delete_by_app_id(const char* app_id)
697 int error_code = ACCOUNT_ERROR_NONE;
698 account_stmt hstmt = NULL;
699 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
700 int rc = 0, count = -1;
701 int ret_transaction = 0;
702 int binding_count = 1;
703 bool is_success = FALSE;
705 ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
706 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("The database isn't connected."));
708 /* Check requested ID to delete */
709 ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE AppId = '%s'", ACCOUNT_TYPE_TABLE, app_id);
711 count = _account_get_record_count(query);
713 if( _account_db_err_code() == SQLITE_PERM ){
714 ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
715 return ACCOUNT_ERROR_PERMISSION_DENIED;
719 ACCOUNT_SLOGE("app id(%s) is not exist. count(%d)\n", app_id, count);
720 return ACCOUNT_ERROR_RECORD_NOT_FOUND;
723 /* transaction control required*/
724 ret_transaction = _account_begin_transaction();
726 if( ret_transaction == ACCOUNT_ERROR_DATABASE_BUSY ){
727 ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg());
728 pthread_mutex_unlock(&account_mutex);
729 return ACCOUNT_ERROR_DATABASE_BUSY;
730 }else if (ret_transaction != ACCOUNT_ERROR_NONE) {
731 ACCOUNT_ERROR("account_delete:_account_begin_transaction fail %d\n", ret_transaction);
732 pthread_mutex_unlock(&account_mutex);
733 return ret_transaction;
736 ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppId = ?", LABEL_TABLE);
738 hstmt = _account_prepare_query(query);
740 if( _account_db_err_code() == SQLITE_PERM ){
741 ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
742 pthread_mutex_unlock(&account_mutex);
743 return ACCOUNT_ERROR_PERMISSION_DENIED;
746 ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
747 ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
749 _account_query_bind_text(hstmt, binding_count++, app_id);
751 rc = _account_query_step(hstmt);
752 ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
754 rc = _account_query_finalize(hstmt);
755 ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
759 ACCOUNT_MEMSET(query, 0, sizeof(query));
761 ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE app_id = ? ", PROVIDER_FEATURE_TABLE);
763 hstmt = _account_prepare_query(query);
764 ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
765 ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
767 _account_query_bind_text(hstmt, binding_count++, app_id);
769 rc = _account_query_step(hstmt);
770 ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found. AppId=%s, rc=%d\n", app_id, rc));
772 rc = _account_query_finalize(hstmt);
773 ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
779 ACCOUNT_MEMSET(query, 0, sizeof(query));
781 ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppId = ? ", ACCOUNT_TYPE_TABLE);
783 hstmt = _account_prepare_query(query);
784 ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
785 ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
787 _account_query_bind_text(hstmt, binding_count++, app_id);
789 rc = _account_query_step(hstmt);
790 ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found. AppId=%s, rc=%d\n", app_id, rc));
792 rc = _account_query_finalize(hstmt);
793 ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
800 rc = _account_query_finalize(hstmt);
801 ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
805 ret_transaction = _account_end_transaction(is_success);
807 if (ret_transaction != ACCOUNT_ERROR_NONE) {
808 ACCOUNT_ERROR("account_svc_delete:_account_svc_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
811 pthread_mutex_unlock(&account_mutex);
816 ACCOUNT_INTERNAL_API int account_type_insert_to_db_offline(account_type_h account_type, int* account_type_id)
818 _INFO("account_type_insert_to_db starting");
820 ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE HANDLE IS NULL"));
821 ACCOUNT_RETURN_VAL((account_type_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE ID POINTER IS NULL"));
825 _INFO("account_manager_account_type_add start");
827 guint pid = getpid();
828 _INFO("client Id = [%u]", pid);
830 int return_code = _account_db_open(1);
831 if (return_code != ACCOUNT_ERROR_NONE)
833 _ERR("_account_db_open() error, ret = %d", return_code);
841 _ERR("current daemon is not root user, uid=%d", uid);
845 _INFO("before _account_type_insert_to_db");
846 return_code = _account_type_insert_to_db((account_type_s*)account_type, &db_id);
847 _INFO("after _account_type_insert_to_db");
848 if (return_code != ACCOUNT_ERROR_NONE)
850 _ERR("_account_type_insert_to_db error");
854 *account_type_id = db_id;
856 account_type_s* account_type_data = (account_type_s*)account_type;
857 account_type_data->id = db_id;
860 _INFO("account_manager_account_type_add end");
862 if( g_hAccountDB == NULL )
865 return_code = _account_db_close();
866 if (return_code != ACCOUNT_ERROR_NONE)
868 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
869 return_code = ACCOUNT_ERROR_DB_FAILED;
875 ACCOUNT_INTERNAL_API int account_type_delete_by_app_id_offline(const char* app_id)
877 _INFO("account_type_delete_by_app_id starting");
879 ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
881 guint pid = getpid();
883 _INFO("client Id = [%u]", pid);
885 int return_code = _account_db_open(1);
886 if (return_code != ACCOUNT_ERROR_NONE)
888 _ERR("_account_db_open() error, ret = %d", return_code);
896 _ERR("current daemon is not root user, uid=%d", uid);
900 _INFO("before _account_type_delete_by_app_id");
901 return_code = _account_type_delete_by_app_id(app_id);
902 _INFO("after _account_type_delete_by_app_id=[%d]", return_code);
904 if (return_code != ACCOUNT_ERROR_NONE)
906 _ERR("_account_type_delete_by_app_id error");
911 _INFO("account_type_delete_by_app_id_offline end");
913 if( g_hAccountDB == NULL )
916 return_code = _account_db_close();
917 if (return_code != ACCOUNT_ERROR_NONE)
919 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
920 return_code = ACCOUNT_ERROR_DB_FAILED;
926 static void _account_db_data_to_text(const char *textbuf, char **output)
928 if (textbuf && strlen(textbuf)>0) {
933 *output = strdup(textbuf);
936 static int _account_query_table_column_int(account_stmt pStmt, int pos)
939 ACCOUNT_ERROR("statement is null");
944 ACCOUNT_ERROR("invalid pos");
948 return sqlite3_column_int(pStmt, pos);
951 static const char *_account_query_table_column_text(account_stmt pStmt, int pos)
954 ACCOUNT_ERROR("statement is null");
959 ACCOUNT_ERROR("invalid pos");
963 return (const char*)sqlite3_column_text(pStmt, pos);
966 static void _account_convert_column_to_account(account_stmt hstmt, account_s *account_record)
968 const char *textbuf = NULL;
970 account_record->id = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_ID);
971 ACCOUNT_DEBUG("account_record->id =[%d]", account_record->id);
973 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_NAME);
974 _account_db_data_to_text(textbuf, &(account_record->user_name));
976 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_EMAIL_ADDRESS);
977 _account_db_data_to_text(textbuf, &(account_record->email_address));
979 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_DISPLAY_NAME);
980 _account_db_data_to_text(textbuf, &(account_record->display_name));
982 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_ICON_PATH);
983 _account_db_data_to_text(textbuf, &(account_record->icon_path));
985 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_SOURCE);
986 _account_db_data_to_text(textbuf, &(account_record->source));
988 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_PACKAGE_NAME);
989 _account_db_data_to_text(textbuf, &(account_record->package_name));
991 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_ACCESS_TOKEN);
992 _account_db_data_to_text(textbuf, &(account_record->access_token));
994 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_DOMAIN_NAME);
995 _account_db_data_to_text(textbuf, &(account_record->domain_name));
997 account_record->auth_type = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_AUTH_TYPE);
999 account_record->secret = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_SECRET);
1001 account_record->sync_support = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_SYNC_SUPPORT);
1003 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_0);
1004 _account_db_data_to_text(textbuf, &(account_record->user_data_txt[0]));
1006 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_1);
1007 _account_db_data_to_text(textbuf, &(account_record->user_data_txt[1]));
1009 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_2);
1010 _account_db_data_to_text(textbuf, &(account_record->user_data_txt[2]));
1012 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_3);
1013 _account_db_data_to_text(textbuf, &(account_record->user_data_txt[3]));
1015 textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_4);
1016 _account_db_data_to_text(textbuf, &(account_record->user_data_txt[4]));
1018 account_record->user_data_int[0] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_0);
1019 account_record->user_data_int[1] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_1);
1020 account_record->user_data_int[2] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_2);
1021 account_record->user_data_int[3] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_3);
1022 account_record->user_data_int[4] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_4);
1025 GList* _account_query_account_by_package_name(const char* package_name, int *error_code)
1027 _INFO("_account_query_account_by_package_name");
1029 *error_code = ACCOUNT_ERROR_NONE;
1030 account_stmt hstmt = NULL;
1031 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
1034 ACCOUNT_RETURN_VAL((package_name != NULL), {*error_code = ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("PACKAGE NAME IS NULL"));
1035 ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
1037 ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
1039 ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE package_name=?", ACCOUNT_TABLE);
1041 hstmt = _account_prepare_query(query);
1043 if( _account_db_err_code() == SQLITE_PERM ){
1044 ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
1045 *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
1049 int binding_count = 1;
1050 _account_query_bind_text(hstmt, binding_count++, package_name);
1052 rc = _account_query_step(hstmt);
1054 account_s* account_head = NULL;
1056 ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.(%s)\n", package_name));
1060 account_head = (account_s*) malloc(sizeof(account_s));
1061 if (account_head == NULL) {
1062 ACCOUNT_FATAL("malloc Failed");
1063 if (hstmt != NULL) {
1064 rc = _account_query_finalize(hstmt);
1065 ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
1068 *error_code = ACCOUNT_ERROR_OUT_OF_MEMORY;
1071 ACCOUNT_MEMSET(account_head, 0x00, sizeof(account_s));
1073 while (rc == SQLITE_ROW) {
1074 account_s* account_record = NULL;
1076 account_record = (account_s*) malloc(sizeof(account_s));
1078 if (account_record == NULL) {
1079 ACCOUNT_FATAL("malloc Failed");
1082 ACCOUNT_MEMSET(account_record, 0x00, sizeof(account_s));
1084 _account_convert_column_to_account(hstmt, account_record);
1086 _INFO("Adding account_list");
1087 account_head->account_list = g_list_append(account_head->account_list, account_record);
1089 rc = _account_query_step(hstmt);
1093 rc = _account_query_finalize(hstmt);
1094 ACCOUNT_CATCH_ERROR_P((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
1099 tmp = g_list_length(account_head->account_list);
1101 for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
1102 account_s* testaccount = (account_s*)iter->data;
1104 _account_query_capability_by_account_id(_account_get_capability_text_cb, testaccount->id, (void*)testaccount);
1105 _account_query_custom_by_account_id(_account_get_custom_text_cb, testaccount->id, (void*)testaccount);
1108 *error_code = ACCOUNT_ERROR_NONE;
1113 rc = _account_query_finalize(hstmt);
1114 if (rc != ACCOUNT_ERROR_NONE) {
1116 _ERR("finalize error");
1121 pthread_mutex_unlock(&account_mutex);
1123 if( (*error_code != ACCOUNT_ERROR_NONE) && account_head ) {
1124 _account_glist_account_free(account_head->account_list);
1125 _ACCOUNT_FREE(account_head);
1126 account_head = NULL;
1129 if ((*error_code == ACCOUNT_ERROR_NONE) && account_head != NULL)
1131 _INFO("Returning account_list");
1132 // _remove_sensitive_info_from_non_owning_account_list(getpid(), account_head->account_list);
1133 GList* result = account_head->account_list;
1134 _ACCOUNT_FREE(account_head);
1140 static void _account_insert_delete_update_notification_send(char *noti_name, int pid)
1143 vsm_zone_h effective_zone, real_zone;
1146 _ERR("Noti Name is NULL!!!!!!\n");
1151 ctx = vsm_create_context();
1154 _ERR( "Failed to initialize domain control vsm context.");
1158 effective_zone = vsm_lookup_zone_by_pid(ctx, pid);
1159 if(effective_zone == NULL) {
1160 _ERR( "Failed vsm_lookup_zone_by_pid.");
1164 _INFO( "before set vsm_join_zone()");
1165 real_zone = vsm_join_zone(effective_zone);
1166 _INFO( "after set vsm_join_zone()");
1169 _INFO("noti_type = %s", noti_name);
1171 if (vconf_set_str(VCONFKEY_ACCOUNT_MSG_STR, noti_name) != 0) {
1172 _ERR("Vconf MSG Str set FAILED !!!!!!\n");;
1175 _INFO( "before recover vsm_join_zone()");
1176 vsm_join_zone(real_zone);
1177 _INFO( "after recover vsm_join_zone()");
1179 _INFO( "before vsm_cleanup_context()");
1180 vsm_cleanup_context(ctx);
1181 _INFO( "after vsm_cleanup_context()");
1184 int _account_delete_from_db_by_package_name_offline(const char *package_name)
1186 int error_code = ACCOUNT_ERROR_NONE;
1187 account_stmt hstmt = NULL;
1188 char query[ACCOUNT_SQL_LEN_MAX] = {0, };
1190 int ret_transaction = 0;
1191 bool is_success = FALSE;
1192 int binding_count = 1;
1193 GSList *account_id_list = NULL;
1196 // It only needs list of ids, does not need to query sensitive info. So sending 0
1197 GList* account_list_temp = _account_query_account_by_package_name(package_name, &ret);
1198 if (account_list_temp == NULL)
1200 _ERR("_account_query_account_by_package_name returned NULL");
1201 return ACCOUNT_ERROR_DB_FAILED;
1204 if( _account_db_err_code() == SQLITE_PERM ){
1205 ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
1206 _account_glist_account_free(account_list_temp);
1207 return ACCOUNT_ERROR_PERMISSION_DENIED;
1210 if(ret != ACCOUNT_ERROR_NONE){
1211 _account_glist_account_free(account_list_temp);
1215 account_list_temp = g_list_first(account_list_temp);
1216 _INFO("account_list_temp length=[%d]",g_list_length(account_list_temp));
1219 for (iter = account_list_temp; iter != NULL; iter = g_list_next(iter))
1221 _INFO("iterating account_list_temp");
1222 account_s *account = NULL;
1223 _INFO("Before iter->data");
1224 account = (account_s*)iter->data;
1225 _INFO("After iter->data");
1226 if (account != NULL)
1228 char id[256] = {0, };
1230 ACCOUNT_MEMSET(id, 0, 256);
1232 ACCOUNT_SNPRINTF(id, 256, "%d", account->id);
1234 _INFO("Adding account id [%s]", id);
1235 account_id_list = g_slist_append(account_id_list, g_strdup(id));
1239 _account_glist_account_free(account_list_temp);
1240 /* transaction control required*/
1241 ret_transaction = _account_begin_transaction();
1243 if( _account_db_err_code() == SQLITE_PERM ){
1244 pthread_mutex_unlock(&account_mutex);
1245 ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
1246 return ACCOUNT_ERROR_PERMISSION_DENIED;
1249 if( ret_transaction == ACCOUNT_ERROR_DATABASE_BUSY ){
1250 ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg());
1251 pthread_mutex_unlock(&account_mutex);
1252 return ACCOUNT_ERROR_DATABASE_BUSY;
1253 }else if (ret_transaction != ACCOUNT_ERROR_NONE) {
1254 ACCOUNT_ERROR("account_delete:_account_begin_transaction fail %d\n", ret_transaction);
1255 pthread_mutex_unlock(&account_mutex);
1256 return ret_transaction;
1259 /* delete custom table */
1260 ACCOUNT_MEMSET(query, 0, sizeof(query));
1261 ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppId = ?", ACCOUNT_CUSTOM_TABLE);
1263 hstmt = _account_prepare_query(query);
1265 if( _account_db_err_code() == SQLITE_PERM ){
1266 _account_end_transaction(FALSE);
1267 pthread_mutex_unlock(&account_mutex);
1268 ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
1269 return ACCOUNT_ERROR_PERMISSION_DENIED;
1272 ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
1273 ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
1276 _account_query_bind_text(hstmt, binding_count++, package_name);
1278 rc = _account_query_step(hstmt);
1279 ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
1281 rc = _account_query_finalize(hstmt);
1282 ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
1285 /* delete capability table */
1286 ACCOUNT_MEMSET(query, 0, sizeof(query));
1287 ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE package_name = ?", CAPABILITY_TABLE);
1289 hstmt = _account_prepare_query(query);
1291 ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
1292 ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
1295 _account_query_bind_text(hstmt, binding_count++, package_name);
1297 rc = _account_query_step(hstmt);
1298 ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
1300 rc = _account_query_finalize(hstmt);
1301 ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
1304 /* delete account table */
1305 ACCOUNT_MEMSET(query, 0, sizeof(query));
1307 ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE package_name = ?", ACCOUNT_TABLE);
1309 hstmt = _account_prepare_query(query);
1310 ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
1311 ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
1314 _account_query_bind_text(hstmt, binding_count++, package_name);
1316 rc = _account_query_step(hstmt);
1317 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));
1319 rc = _account_query_finalize(hstmt);
1320 ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
1326 if (hstmt != NULL) {
1327 rc = _account_query_finalize(hstmt);
1328 ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
1332 ret_transaction = _account_end_transaction(is_success);
1334 if (ret_transaction != ACCOUNT_ERROR_NONE) {
1335 ACCOUNT_ERROR("account_delete:_account_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
1337 if (is_success == true) {
1338 GSList* gs_iter = NULL;
1339 for (gs_iter = account_id_list; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
1340 char* p_tmpid = NULL;
1341 p_tmpid = (char*)gs_iter->data;
1343 ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%s", ACCOUNT_NOTI_NAME_DELETE, p_tmpid);
1344 ACCOUNT_SLOGD("%s", buf);
1345 _account_insert_delete_update_notification_send(buf, getpid());
1346 _ACCOUNT_FREE(p_tmpid);
1348 g_slist_free(account_id_list);
1352 pthread_mutex_unlock(&account_mutex);
1354 _INFO("_account_delete_from_db_by_package_name_offline end");
1358 ACCOUNT_INTERNAL_API int account_delete_from_db_by_package_name_offline(const char *package_name)
1360 _INFO("_account_delete_from_db_by_package_name_offline");
1362 ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
1364 int return_code = _account_db_open(1);
1365 if (return_code != ACCOUNT_ERROR_NONE)
1367 _ERR("_account_db_open() error, ret = %d", return_code);
1375 _ERR("current process user is not root, uid=%d", uid);
1376 return_code = ACCOUNT_ERROR_PERMISSION_DENIED;
1380 _INFO("before _account_delete_from_db_by_package_name_offline");
1381 return_code = _account_delete_from_db_by_package_name_offline(package_name);
1382 _INFO("after _account_delete_from_db_by_package_name_offline=[%d]", return_code);
1384 if (return_code != ACCOUNT_ERROR_NONE)
1386 _ERR("_account_delete_from_db_by_package_name_offline error");
1391 _INFO("account_delete_from_db_by_package_name_offline end");
1393 if( g_hAccountDB == NULL )
1396 return_code = _account_db_close();
1397 if (return_code != ACCOUNT_ERROR_NONE)
1399 ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
1400 return_code = ACCOUNT_ERROR_DB_FAILED;