#include <vconf.h>
#include <pkgmgr-info.h>
-#include <aul.h>
-#include <tzplatform_config.h>
+//#include <tzplatform_config.h>
#include <dbg.h>
#include <account_ipc_marshal.h>
#include <account_free.h>
#include <account-private.h>
-#include <account.h>
-#include <account-error.h>
+#include <account_db_helper.h>
+#include <account_crypto_service.h>
+#include <account_err.h>
+#include "account_type.h"
#include "account-server-db.h"
-#include "account-key-handler.h"
-#include "account-crypto-service.h"
-typedef sqlite3_stmt* account_stmt;
+//typedef sqlite3_stmt* account_stmt;
-#define TEST_APP_ID "org.tizen.MyAccountCoreTest"
-#define EAS_CMDLINE "/usr/bin/eas-engine"
#define EMAIL_SERVICE_CMDLINE "/usr/bin/email-service"
-#define IMS_ENGINE_CMDLINE "/usr/bin/ims-srv"
-#define IMS_AGENT_CMDLINE "/usr/bin/ims-agent"
-#define MDM_SERVER_CMDLINE "/usr/bin/mdm-server"
-#define RCS_APPID "com.samsung.rcs-im"
-#define IMS_SERVICE_APPID "ims-service"
-#define ACTIVESYNC_APPID "eas-ui"
#define EMAIL_APPID "email-setting-efl"
-#define SYNCHRONISE_APPID "setting-synchronise-efl"
-#define DS_AGENT_CMDLINE "/usr/bin/oma-ds-agent"
-
-#define FACEBOOK_SDK_APPID "com.samsung.facebook-service"
-#define FACEBOOK_APPID "com.samsung.facebook"
-
-#define EASYSIGNUP_CMDLINE "/usr/bin/esu-agent"
-#define EASYSIGNUP_APPID "com.samsung.esu-agent"
-
-#define ACCESS_TOKEN_ALIAS "access_token"
#define ACCOUNT_DB_OPEN_READONLY 0
#define ACCOUNT_DB_OPEN_READWRITE 1
pthread_mutex_t account_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t account_global_mutex = PTHREAD_MUTEX_INITIALIZER;
-int _account_db_handle_close(sqlite3* hDB);
-static char *_account_get_text(const char *text_data);
-static const char *_account_query_table_column_text(account_stmt pStmt, int pos);
+//static char *_account_dup_text(const char *text_data);
static int _account_insert_custom(account_s *account, int account_id);
static int _account_update_custom(account_s *account, int account_id);
-static int _account_query_custom_by_account_id(account_custom_cb callback, int account_id, void *user_data );
-static int _account_type_update_provider_feature(account_type_s *account_type, const char* app_id);
-
-int _account_query_capability_by_account_id(capability_cb callback, int account_id, void *user_data );
+static int _account_type_update_provider_feature(sqlite3 * account_db_handle, account_type_s *account_type, const char* app_id);
static void _account_insert_delete_update_notification_send(char *noti_name)
{
ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_appid(%d)", pkgmgr_ret);
}
- item = _account_get_text(appid);
+ item = _account_dup_text(appid);
*appid_list = g_slist_append(*appid_list, item);
return 0;
}
-static char* _account_get_current_appid(int pid, uid_t uid)
-{
- _INFO("getting caller appid with pid=[%d], uid=[%d]", pid, uid);
-
- int ret=0;
- char appid[128]={0,};
- char* appid_ret = NULL;
-
- ret = aul_app_get_appid_bypid_for_uid(pid, appid, sizeof(appid), uid);
-
- if(ret < 0){
- ACCOUNT_ERROR("fail to get current appid ret=[%d], appid=%s\n", ret, appid);
- }
-
- _INFO("");
-
- /* SLP platform core exception */
- if(strlen(appid) == 0){
- _INFO("");
- char* cmdline = NULL;
- cmdline = _account_get_proc_cmdline_bypid(pid);
- ACCOUNT_SLOGD("cmdline (%s)!!!!!!\n", cmdline);
- if(!g_strcmp0(cmdline, EAS_CMDLINE)) {
- appid_ret = _account_get_text(ACTIVESYNC_APPID);
- _ACCOUNT_FREE(cmdline);
- return appid_ret;
- } else if (!g_strcmp0(cmdline, EMAIL_SERVICE_CMDLINE) || !g_strcmp0(cmdline, MDM_SERVER_CMDLINE)) {
- appid_ret = _account_get_text(EMAIL_APPID);
- _ACCOUNT_FREE(cmdline);
- return appid_ret;
- } else if (!g_strcmp0(cmdline, IMS_ENGINE_CMDLINE) || !g_strcmp0(cmdline, IMS_AGENT_CMDLINE)) {
- if(_account_type_query_app_id_exist_from_all_db(RCS_APPID) == ACCOUNT_ERROR_NONE) {
- appid_ret = _account_get_text(RCS_APPID);
- } else if(_account_type_query_app_id_exist_from_all_db(IMS_SERVICE_APPID) == ACCOUNT_ERROR_NONE) {
- appid_ret = _account_get_text(IMS_SERVICE_APPID);
- } else {
- appid_ret = _account_get_text(RCS_APPID);
- }
- _ACCOUNT_FREE(cmdline);
- return appid_ret;
- } else if (!g_strcmp0(cmdline, DS_AGENT_CMDLINE)) {
- appid_ret = _account_get_text(SYNCHRONISE_APPID);
- _ACCOUNT_FREE(cmdline);
- return appid_ret;
- } else if (!g_strcmp0(cmdline, EASYSIGNUP_CMDLINE)) {
- appid_ret = _account_get_text(EASYSIGNUP_APPID);
- _ACCOUNT_FREE(cmdline);
- return appid_ret;
- } else {
- ACCOUNT_DEBUG("No app id\n");
- _ACCOUNT_FREE(cmdline);
- return NULL;
- }
- }
-
- _INFO("");
- /* temporary exception */
- if(!g_strcmp0(appid, "com.samsung.gallery")){
- appid_ret = _account_get_text("com.samsung.facebook");
- } else if(!g_strcmp0(appid, FACEBOOK_SDK_APPID)){
- appid_ret = _account_get_text(FACEBOOK_APPID);
- } else {
- appid_ret = _account_get_text(appid);
- }
-
- return appid_ret;
-}
-
-static const char *_account_db_err_msg_from_global_db()
-{
- return sqlite3_errmsg(g_hAccountGlobalDB);
-}
-
-static int _account_db_err_code_from_global_db()
-{
- return sqlite3_errcode(g_hAccountGlobalDB);
-}
-
-static int _account_get_record_count_from_global_db(const char *query)
-{
- _INFO("_account_get_record_count_in_global_db");
-
- int rc = -1;
- int ncount = 0;
- account_stmt pStmt = NULL;
-
- if(!query){
- _ERR("NULL query\n");
- return ACCOUNT_ERROR_QUERY_SYNTAX_ERROR;
- }
-
- if(!g_hAccountGlobalDB) {
- _ERR("DB is not opened\n");
- return ACCOUNT_ERROR_DB_NOT_OPENED;
- }
-
- rc = sqlite3_prepare_v2(g_hAccountGlobalDB, query, strlen(query), &pStmt, NULL);
-
- if (SQLITE_BUSY == rc){
- _ERR("sqlite3_prepare_v2() failed(%d, %s).", rc, _account_db_err_msg_from_global_db());
- sqlite3_finalize(pStmt);
- return ACCOUNT_ERROR_DATABASE_BUSY;
- } else if (SQLITE_OK != rc) {
- _ERR("sqlite3_prepare_v2() failed(%d, %s).", rc, _account_db_err_msg_from_global_db());
- sqlite3_finalize(pStmt);
- return ACCOUNT_ERROR_DB_FAILED;
- }
-
- rc = sqlite3_step(pStmt);
- if (SQLITE_BUSY == rc) {
- _ERR("sqlite3_step() failed(%d, %s).", rc, _account_db_err_msg_from_global_db());
- sqlite3_finalize(pStmt);
- return ACCOUNT_ERROR_DATABASE_BUSY;
- } else if (SQLITE_ROW != rc) {
- _ERR("sqlite3_step() failed(%d, %s).", rc, _account_db_err_msg_from_global_db());
- sqlite3_finalize(pStmt);
- return ACCOUNT_ERROR_DB_FAILED;
- }
-
- ncount = sqlite3_column_int(pStmt, 0);
-
- _INFO("account record count [%d]", ncount);
- sqlite3_finalize(pStmt);
-
- return ncount;
-}
/*
static int _account_execute_query_from_global_db(const char *query)
{
if(!query){
ACCOUNT_ERROR("NULL query\n");
- return ACCOUNT_ERROR_QUERY_SYNTAX_ERROR;
+ return _ACCOUNT_ERROR_QUERY_SYNTAX_ERROR;
}
if(!g_hAccountGlobalDB){
ACCOUNT_ERROR("Global DB is not opened\n");
- return ACCOUNT_ERROR_DB_NOT_OPENED;
+ return _ACCOUNT_ERROR_DB_NOT_OPENED;
}
rc = sqlite3_exec(g_hAccountGlobalDB, query, NULL, NULL, &pszErrorMsg);
if (ret == SQLITE_BUSY){
ACCOUNT_ERROR(" sqlite3 busy = %d", ret);
- return ACCOUNT_ERROR_DATABASE_BUSY;
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
} else if(ret != SQLITE_OK) {
ACCOUNT_ERROR("_account_svc_begin_transaction_in_global_db fail :: %d", ret);
- return ACCOUNT_ERROR_DB_FAILED;
+ return _ACCOUNT_ERROR_DB_FAILED;
}
ACCOUNT_DEBUG("_account_begin_transaction_in_global_db end");
- return ACCOUNT_ERROR_NONE;
+ return _ACCOUNT_ERROR_NONE;
}
static int _account_end_transaction_from_global_db(bool is_success)
if(ret == SQLITE_PERM) {
ACCOUNT_ERROR("Account permission denied :: %d", ret);
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
if (ret == SQLITE_BUSY){
ACCOUNT_DEBUG(" sqlite3 busy = %d", ret);
- return ACCOUNT_ERROR_DATABASE_BUSY;
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
}
if (ret != SQLITE_OK) {
ACCOUNT_ERROR("_account_svc_end_transaction_in_global_db fail :: %d", ret);
- return ACCOUNT_ERROR_DB_FAILED;
+ return _ACCOUNT_ERROR_DB_FAILED;
}
ACCOUNT_DEBUG("_account_end_transaction_in_global_db end");
- return ACCOUNT_ERROR_NONE;
+ return _ACCOUNT_ERROR_NONE;
}
*/
-int _account_type_query_app_id_exist_from_global_db(const char *app_id)
-{
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
-
- ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
- ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE AppId = '%s'", ACCOUNT_TYPE_TABLE, app_id);
-/*
- pthread_mutex_lock(&account_global_mutex);
-
- ret_transaction = _account_begin_transaction_from_global_db();
-
- if(_account_db_err_code() == SQLITE_PERM){
- pthread_mutex_unlock(&account_global_mutex);
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_global());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- if (ret_transaction == ACCOUNT_ERROR_DATABASE_BUSY) {
- ACCOUNT_ERROR("account insert:_account_begin_transaction fail %d\n", ret_transaction);
- pthread_mutex_unlock(&account_global_mutex);
- return ACCOUNT_ERROR_DATABASE_BUSY;
- }else if (ret_transaction != ACCOUNT_ERROR_NONE) {
- ACCOUNT_ERROR("account insert:_account_begin_transaction fail %d\n", ret_transaction);
- pthread_mutex_unlock(&account_global_mutex);
- return ret_transaction;
- }
-*/
- rc = _account_get_record_count_from_global_db(query);
-
- if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
- _ERR( "Global DB access failed(%s)", _account_db_err_msg_from_global_db());
-
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- if (rc <= 0) {
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
- }
-
- return ACCOUNT_ERROR_NONE;
-}
int _account_global_db_open(void)
{
if( g_hAccountGlobalDB ) {
_ERR( "Account database is using in another app. %x", g_hAccountDB );
- return ACCOUNT_ERROR_DATABASE_BUSY;
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
}
ret = _account_db_handle_close(g_hAccountGlobalDB2);
- if( ret != ACCOUNT_ERROR_NONE )
+ if( ret != _ACCOUNT_ERROR_NONE )
ACCOUNT_DEBUG( "db_util_close(g_hAccountGlobalDB2) fail ret = %d", ret);
ACCOUNT_DEBUG( "before db_util_open()");
// else if(mode == ACCOUNT_DB_OPEN_READONLY)
rc = db_util_open_with_options(account_db_path, &g_hAccountGlobalDB, SQLITE_OPEN_READONLY, NULL);
// else
-// return ACCOUNT_ERROR_DB_NOT_OPENED;
+// return _ACCOUNT_ERROR_DB_NOT_OPENED;
ACCOUNT_DEBUG( "after db_util_open() sqlite_rc = %d", rc);
- if( rc == SQLITE_PERM || _account_db_err_code_from_global_db() == SQLITE_PERM ) {
+ if( rc == SQLITE_PERM || _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ) {
ACCOUNT_ERROR( "Account permission denied");
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
if( rc == SQLITE_BUSY ) {
ACCOUNT_ERROR( "busy handler fail.");
- return ACCOUNT_ERROR_DATABASE_BUSY;
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
}
if( rc != SQLITE_OK ) {
ACCOUNT_ERROR( "The database isn't connected." );
- return ACCOUNT_ERROR_DB_NOT_OPENED;
+ return _ACCOUNT_ERROR_DB_NOT_OPENED;
}
_INFO( "end _account_global_db_open()");
- return ACCOUNT_ERROR_NONE;
+ return _ACCOUNT_ERROR_NONE;
}
int _account_global_db_close(void)
int ret = -1;
/*
ret = _account_db_handle_close(g_hAccountGlobalDB2);
- if( ret != ACCOUNT_ERROR_NONE )
+ if( ret != _ACCOUNT_ERROR_NONE )
ACCOUNT_DEBUG( "db_util_close(g_hAccountGlobalDB2) fail ret = %d", ret);
*/
ret = _account_db_handle_close(g_hAccountGlobalDB);
- if( ret != ACCOUNT_ERROR_NONE )
+ if( ret != _ACCOUNT_ERROR_NONE )
{
ACCOUNT_ERROR( "db_util_close(g_hAccountGlobalDB) fail ret = %d", ret);
g_hAccountGlobalDB2 = g_hAccountGlobalDB;
return ret;
}
-static int _account_check_account_type_with_appid_group(uid_t uid, const char* appid, char** verified_appid)
+static bool _account_check_add_more_account(const char* app_id)
{
- int error_code = ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER;
- pkgmgrinfo_appinfo_h ahandle=NULL;
- pkgmgrinfo_pkginfo_h phandle=NULL;
- char* package_id = NULL;
- GSList* appid_list = NULL;
- GSList* iter = NULL;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
- if(!appid){
- ACCOUNT_ERROR("input param is null\n");
- return ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER;
- }
+ ACCOUNT_RETURN_VAL((app_id != 0), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- if(!verified_appid){
- ACCOUNT_ERROR("output param is null\n");
- return ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER;
- }
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
- if(!strcmp(appid, "com.samsung.setting")){
- ACCOUNT_DEBUG("Setting exception\n");
- *verified_appid = _account_get_text("com.samsung.setting");
- return ACCOUNT_ERROR_NONE;
- }
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE AppId = '%s' and MultipleAccountSupport = 1", ACCOUNT_TYPE_TABLE, app_id);
+ rc = _account_get_record_count(g_hAccountDB, query);
- if(!strcmp(appid, "com.samsung.samsung-account-front")){
- ACCOUNT_DEBUG("Setting exception\n");
- *verified_appid = _account_get_text("com.samsung.samsung-account-front");
- return ACCOUNT_ERROR_NONE;
+ /* multiple account support case */
+ if(rc > 0) {
+ ACCOUNT_SLOGD("app id (%s) supports multiple account. rc(%d)\n", app_id, rc);
+ return TRUE;
}
- if(!strcmp(appid, IMS_SERVICE_APPID) || !strcmp(appid, RCS_APPID)){
- ACCOUNT_DEBUG("ims service exception\n");
- *verified_appid = _account_get_text(appid);
- return ACCOUNT_ERROR_NONE;
- }
+ /* multiple account not support case */
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE package_name = '%s'", ACCOUNT_TABLE, app_id);
+ rc = _account_get_record_count(g_hAccountDB, query);
- if(!strcmp(appid, EASYSIGNUP_APPID)){
- ACCOUNT_DEBUG("easysignup exception\n");
- *verified_appid = _account_get_text(appid);
- return ACCOUNT_ERROR_NONE;
+ if(rc <= 0) {
+ ACCOUNT_SLOGD("app id (%s) supports single account. and there is no account of the app id\n", app_id);
+ return TRUE;
}
- /* Get app id family which is stored in account database */
- int pkgmgr_ret = -1;
- if (uid == OWNER_ROOT || uid == GLOBAL_USER) {
- pkgmgr_ret = pkgmgrinfo_appinfo_get_appinfo(appid, &ahandle);
- } else {
- pkgmgr_ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &ahandle);
- }
- if( pkgmgr_ret != PMINFO_R_OK ){
- ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_appinfo(%d)", pkgmgr_ret);
- }
+ return FALSE;
+}
- pkgmgr_ret = pkgmgrinfo_appinfo_get_pkgid(ahandle, &package_id);
- if( pkgmgr_ret != PMINFO_R_OK ){
- ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_pkgid(%d)", pkgmgr_ret);
- }
- if (uid == OWNER_ROOT || uid == GLOBAL_USER) {
- pkgmgr_ret = pkgmgrinfo_pkginfo_get_pkginfo(package_id, &phandle);
- } else {
- pkgmgr_ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(package_id, uid, &phandle);
- }
- if( pkgmgr_ret != PMINFO_R_OK ){
- ACCOUNT_DEBUG("pkgmgrinfo_pkginfo_get_pkginfo(%d)", pkgmgr_ret);
- }
+int _account_db_open(int mode, int pid, uid_t uid)
+{
+ int rc = 0;
+ int ret = -1;
+ char account_db_dir[256] = {0, };
+ char account_db_path[256] = {0, };
- if (uid == OWNER_ROOT || uid == GLOBAL_USER) {
- pkgmgr_ret = pkgmgrinfo_appinfo_get_list(phandle, PMINFO_ALL_APP, _account_get_current_appid_cb, (void *)&appid_list);
- } else {
- pkgmgr_ret = pkgmgrinfo_appinfo_get_usr_list(phandle, PMINFO_ALL_APP, _account_get_current_appid_cb, (void *)&appid_list, uid);
- }
- if( pkgmgr_ret != PMINFO_R_OK ){
- ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_list(%d)", pkgmgr_ret);
- }
-
- /* Compare current app id with the stored app id family */
- for(iter=appid_list;iter!=NULL;iter=g_slist_next(iter)){
- char* tmp = (char*)iter->data;
- if(tmp) {
- if(_account_type_query_app_id_exist_from_all_db(tmp) == ACCOUNT_ERROR_NONE) {
- *verified_appid = _account_get_text(tmp);
- error_code = ACCOUNT_ERROR_NONE;
- _ACCOUNT_FREE(tmp);
- break;
- } else {
- ACCOUNT_SLOGD("not matched owner group app id(%s), current appid(%s)\n", tmp, appid);
- }
- }
- _ACCOUNT_FREE(tmp);
- }
+ _INFO( "start _account_db_open()");
- g_slist_free(appid_list);
- pkgmgr_ret = pkgmgrinfo_pkginfo_destroy_pkginfo(phandle);
- if( pkgmgr_ret != PMINFO_R_OK ){
- ACCOUNT_DEBUG("pkgmgrinfo_pkginfo_destroy_pkginfo(%d)", pkgmgr_ret);
- }
+ ACCOUNT_MEMSET(account_db_dir, 0x00, sizeof(account_db_dir));
+ ACCOUNT_MEMSET(account_db_path, 0x00, sizeof(account_db_path));
- pkgmgr_ret = pkgmgrinfo_appinfo_destroy_appinfo(ahandle);
- if( pkgmgr_ret != PMINFO_R_OK ){
- ACCOUNT_DEBUG("pkgmgrinfo_appinfo_destroy_appinfo(%d)", pkgmgr_ret);
- }
+ ACCOUNT_GET_USER_DB_PATH(account_db_path, sizeof(account_db_path), uid);
- return error_code;
-}
+ if( g_hAccountDB ) {
+ _ERR( "Account database is using in another app. %x", g_hAccountDB );
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
+ }
-static int _account_check_appid_group_with_package_name(uid_t uid, const char* appid, char* package_name)
-{
- int error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
- pkgmgrinfo_appinfo_h ahandle=NULL;
- pkgmgrinfo_pkginfo_h phandle=NULL;
- char* package_id = NULL;
- GSList* appid_list = NULL;
- GSList* iter = NULL;
+ ret = _account_db_handle_close(g_hAccountDB2);
+ if( ret != _ACCOUNT_ERROR_NONE )
+ ACCOUNT_DEBUG( "db_util_close(g_hAccountDB2) fail ret = %d", ret);
- if(!appid){
- ACCOUNT_ERROR("input param -appid is null\n");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
+ ACCOUNT_GET_USER_DB_DIR(account_db_dir, sizeof(account_db_dir), uid);
+ if (-1 == access (account_db_dir, F_OK)) {
+ mkdir(account_db_dir, 644);
}
- if(!package_name){
- ACCOUNT_ERROR("input param - package name is null\n");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
+ ACCOUNT_DEBUG( "before db_util_open()");
+// if(mode == ACCOUNT_DB_OPEN_READWRITE)
+ rc = db_util_open(account_db_path, &g_hAccountDB, DB_UTIL_REGISTER_HOOK_METHOD);
+// else if(mode == ACCOUNT_DB_OPEN_READONLY)
+// rc = db_util_open_with_options(account_db_path, &g_hAccountDB, SQLITE_OPEN_READONLY, NULL);
+// else
+// return _ACCOUNT_ERROR_DB_NOT_OPENED;
+ ACCOUNT_DEBUG( "after db_util_open() sqlite_rc = %d", rc);
- /* ims-service Exception */
- if ( strcmp(appid, IMS_SERVICE_APPID) == 0 && strcmp(package_name, IMS_SERVICE_APPID) == 0 ) {
- ACCOUNT_DEBUG("ims exception."); // TODO: NEED TO REMOVE, debug log.
- return ACCOUNT_ERROR_NONE;
+ if( rc == SQLITE_PERM || _account_db_err_code(g_hAccountDB) == SQLITE_PERM ) {
+ ACCOUNT_ERROR( "Account permission denied");
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- /* easysignup Exception */
- if ( strcmp(appid, EASYSIGNUP_APPID) == 0 && strcmp(package_name, EASYSIGNUP_APPID) == 0 ) {
- ACCOUNT_DEBUG("easysignup exception."); // TODO: NEED TO REMOVE, debug log.
- return ACCOUNT_ERROR_NONE;
- }
- /* Get app id family which is stored in account database */
- int pkgmgr_ret = -1;
- if (uid == OWNER_ROOT || uid == GLOBAL_USER) {
- pkgmgr_ret = pkgmgrinfo_appinfo_get_appinfo(appid, &ahandle);
- } else {
- pkgmgr_ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &ahandle);
- }
- if( pkgmgr_ret != PMINFO_R_OK ){
- ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_appinfo(%d)", pkgmgr_ret);
+ if( rc == SQLITE_BUSY ) {
+ ACCOUNT_ERROR( "busy handler fail.");
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
}
- pkgmgr_ret = pkgmgrinfo_appinfo_get_pkgid(ahandle, &package_id);
- if( pkgmgr_ret != PMINFO_R_OK ){
- ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_pkgid(%d)", pkgmgr_ret);
+ if( rc != SQLITE_OK ) {
+ ACCOUNT_ERROR( "The database isn't connected." );
+ return _ACCOUNT_ERROR_DB_NOT_OPENED;
}
- if (uid == OWNER_ROOT || uid == GLOBAL_USER) {
- pkgmgr_ret = pkgmgrinfo_pkginfo_get_pkginfo(package_id, &phandle);
- } else {
- pkgmgr_ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(package_id, uid, &phandle);
- }
- if( pkgmgr_ret != PMINFO_R_OK ){
- ACCOUNT_DEBUG("pkgmgrinfo_pkginfo_get_pkginfo(%d)", pkgmgr_ret);
- }
+ rc = _account_check_is_all_table_exists(g_hAccountDB);
- if (uid == OWNER_ROOT || uid == GLOBAL_USER) {
- pkgmgr_ret = pkgmgrinfo_appinfo_get_list(phandle, PMINFO_ALL_APP, _account_get_current_appid_cb, (void *)&appid_list);
+ if (rc < 0) {
+ _ERR("_account_check_is_all_table_exists rc=[%d]", rc);
+ return rc;
+ } else if (rc == ACCOUNT_TABLE_TOTAL_COUNT) {
+ _INFO("Tables OK");
} else {
- pkgmgr_ret = pkgmgrinfo_appinfo_get_usr_list(phandle, PMINFO_ALL_APP, _account_get_current_appid_cb, (void *)&appid_list, uid);
- }
- if( pkgmgr_ret != PMINFO_R_OK ){
- ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_list(%d)", pkgmgr_ret);
- }
-
- /* Compare current app id with the stored app id family */
- for(iter=appid_list;iter!=NULL;iter=g_slist_next(iter)){
- char* tmp = (char*)iter->data;
- if(tmp) {
- //ACCOUNT_ERROR("tmp(%s)package_name(%s)\n\n", tmp, package_name); // TODO: NEED TO REMOVE, debug log.
- if( strcmp(tmp, package_name) == 0) {
- error_code = ACCOUNT_ERROR_NONE;
- _ACCOUNT_FREE(tmp);
- break;
- } else if ( strcmp(tmp, "com.samsung.samsung-account-front") == 0 &&
- strcmp(package_name, "com.samsung.samsungaccount") == 0 ) {
- /* Samung Account Exception */
- error_code = ACCOUNT_ERROR_NONE;
- _ACCOUNT_FREE(tmp);
- break;
- } else {
- ACCOUNT_SLOGD("not matched owner group app id(%s), current appid(%s)\n", tmp, appid);
- }
+ int ret = _account_create_all_tables(g_hAccountDB);
+ if (ret != _ACCOUNT_ERROR_NONE) {
+ _ERR("_account_create_all_tables fail ret=[%d]", ret);
+ return ret;
}
- _ACCOUNT_FREE(tmp);
}
- g_slist_free(appid_list);
- pkgmgr_ret = pkgmgrinfo_pkginfo_destroy_pkginfo(phandle);
- if( pkgmgr_ret != PMINFO_R_OK ){
- ACCOUNT_DEBUG("pkgmgrinfo_pkginfo_destroy_pkginfo(%d)", pkgmgr_ret);
- }
+ _INFO( "end _account_db_open()");
+ return _ACCOUNT_ERROR_NONE;
+}
- pkgmgr_ret = pkgmgrinfo_appinfo_destroy_appinfo(ahandle);
- if( pkgmgr_ret != PMINFO_R_OK ){
- ACCOUNT_DEBUG("pkgmgrinfo_appinfo_destroy_appinfo(%d)", pkgmgr_ret);
+int _account_db_close(void)
+{
+ ACCOUNT_DEBUG( "start db_util_close()");
+ int ret = -1;
+/*
+ ret = _account_db_handle_close(g_hAccountDB2);
+ if( ret != _ACCOUNT_ERROR_NONE )
+ ACCOUNT_DEBUG( "db_util_close(g_hAccountDB2) fail ret = %d", ret);
+*/
+ ret = _account_db_handle_close(g_hAccountDB);
+ if( ret != _ACCOUNT_ERROR_NONE )
+ {
+ ACCOUNT_ERROR( "db_util_close(g_hAccountDB) fail ret = %d", ret);
+ g_hAccountDB2 = g_hAccountDB;
}
+ g_hAccountDB = NULL;
- return error_code;
+ return ret;
}
-static int __encrypt_data(unsigned char *data, const int data_len, char **pp_encrypted_data)
+static int _account_execute_insert_query(account_s *account)
{
- int ret;
- int enc_data_len = 0;
- int key_len = 0;
- const char *alias = ACCESS_TOKEN_ALIAS;
- unsigned char *key = NULL;
-
- _INFO("before account_key_handler_get_account_dek");
+ _INFO("_account_execute_insert_query start");
- ret = account_key_handler_get_account_dek(alias, &key, &key_len);
- if (ret != ACCOUNT_ERROR_NONE) {
- //To Do : fail
- _ERR("account_key_handler_get_account_dek failed");
- }
- _INFO("after account_key_handler_get_account_dek");
+ int rc = 0;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int error_code = _ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
- _INFO("before _encrypt_aes_cbc");
+ /* check whether app id exist in account type db */
- ret = encrypt_aes_cbc(key, key_len, data, data_len, pp_encrypted_data, &enc_data_len);
- if (ret != ACCOUNT_ERROR_NONE) {
- //To Do : fail
- _ERR("encrypt_aes_cbc failed");
+ if (!account->user_name && !account->display_name && !account->email_address) {
+ _INFO("");
+ ACCOUNT_ERROR("Mandetory fields is NULL. At least one field is required among username, display name, email address\n");
+ return _ACCOUNT_ERROR_INVALID_PARAMETER;
}
- _INFO("after encrypt_aes_cbc");
+ _INFO("");
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s (user_name, email_address , display_name , icon_path , source , package_name , "
+ "access_token , domain_name , auth_type , secret , sync_support , txt_custom0, txt_custom1, txt_custom2, txt_custom3, txt_custom4, "
+ "int_custom0, int_custom1, int_custom2, int_custom3, int_custom4, txt_custom0 ) values " // to do urusa
+ "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", ACCOUNT_TABLE);
- return ACCOUNT_ERROR_NONE;
-}
+ hstmt = _account_prepare_query(g_hAccountDB, query);
+ ACCOUNT_RETURN_VAL((hstmt != NULL), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query(g_hAccountDB, ) failed(%s).\n", _account_db_err_msg(g_hAccountDB)));
+ _INFO("");
+ _account_convert_account_to_sql(account, hstmt, query);
-static int _encrypt_access_token(account_s *account)
-{
- int ret = -1;
- char *encrypted_token = NULL;
-
- if (account->access_token) {
- _INFO("before __encrypt_data");
- ret = __encrypt_data((unsigned char *)(account->access_token), strlen(account->access_token), &encrypted_token);
- _INFO("after _encrypt_data, ret=[%d]", ret);
- free(account->access_token);
- account->access_token = NULL;
- if( ret == ACCOUNT_ERROR_NONE) {
- account->access_token = encrypted_token;
- _INFO("after access_token, encrypted_token size=[%d]", strlen(account->access_token));
- }
- else {
- //To Do : fail
- _ERR("_encrypt_data fail");
- return ret;
- }
+ _INFO("");
+ rc = _account_query_step(hstmt);
+ if (rc != SQLITE_DONE) {
+ _INFO("");
+ ACCOUNT_ERROR( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM )
+ error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
+ else
+ error_code = _ACCOUNT_ERROR_DB_FAILED;
}
- return ACCOUNT_ERROR_NONE;
-}
+ _INFO("");
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
+ _INFO("_account_execute_insert_query end");
+ return error_code;
+}
-static int __decrypt_data(unsigned char *data, const int data_len, char **pp_decrypted_data)
+static int _account_insert_capability(account_s *account, int account_id)
{
- int ret;
- int dec_data_len = 0;
- int key_len = 0;
- const char *alias = ACCESS_TOKEN_ALIAS;
- unsigned char *key = NULL;
+ _INFO("_account_insert_capability start");
+ int rc, count = 1;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ account_stmt hstmt = NULL;
- _INFO("before account_key_handler_get_account_dek");
- ret = account_key_handler_get_account_dek(alias, &key, &key_len);
- if (ret != ACCOUNT_ERROR_NONE) {
- //To Do : fail
- _ERR("account_key_handler_get_account_dek failed");
- }
+ ACCOUNT_RETURN_VAL((account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
- _INFO("before _decrypt_aes_cbc");
- decrypt_aes_cbc(key, key_len, data, data_len, pp_decrypted_data, &dec_data_len);
- if (ret != ACCOUNT_ERROR_NONE) {
- //To Do : fail
- _ERR("decrypt_aes_cbc failed");
+ if (g_slist_length( account->capablity_list)==0) {
+ ACCOUNT_DEBUG( "_account_insert_capability, no capability\n");
+ return _ACCOUNT_ERROR_NONE;
}
- _INFO("after decrypt_aes_cbc, dec_data = %s", *pp_decrypted_data);
- return ACCOUNT_ERROR_NONE;
-}
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where _id=%d", ACCOUNT_TABLE, account_id);
-static int _decrypt_access_token(account_s *account)
-{
- int ret = -1;
- char *decrypted_token = NULL;
-
- if (account->access_token) {
- ret = __decrypt_data((unsigned char *)account->access_token, strlen(account->access_token), &decrypted_token);
- free(account->access_token);
- account->access_token = NULL;
- if( ret == ACCOUNT_ERROR_NONE)
- account->access_token = decrypted_token;
- else {
- //To Do : fail
- _ERR("_decrypt_access_token fail");
- return ret;
- }
+ _INFO("_account_insert_capability _account_get_record_count [%s]", query);
+ rc = _account_get_record_count(g_hAccountDB, query);
+
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ _ERR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
+ if (rc <= 0) {
+ return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
}
- _INFO("_decrypt_access_token end");
- return ACCOUNT_ERROR_NONE;
-}
+ /* insert query*/
-static int _remove_sensitive_info_from_non_owning_account(int caller_pid, uid_t uid, account_s *account)
-{
- if (account == NULL)
- {
- _ERR("Null input");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
+ GSList *iter;
- if (account->package_name)
- {
- char *caller_package_name = _account_get_current_appid(caller_pid, uid);
- if (caller_package_name == NULL)
- {
- _ERR("Could not get caller app id, so removing sensitive info from account id [%d]", account->id);
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
+ for (iter = account->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
+ int ret;
+ count = 1;
- if (g_strcmp0(caller_package_name, account->package_name) != 0)
- {
- // packages dont match, so remove sensitive info
- _INFO("Removing sensitive info from account id [%d]", account->id);
- free (account->access_token);
- account->access_token = NULL;
-
- } else {
- int ret = _decrypt_access_token(account);
- if (ret != ACCOUNT_ERROR_NONE)
- {
- _ERR("_decrypt_access_token error");
- return ret;
- }
+ account_capability_s* cap_data = NULL;
+ cap_data = (account_capability_s*)iter->data;
+
+ _INFO("cap_data->type = %s, cap_data->value = %d \n", cap_data->type, cap_data->value);
+
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(key, value, package_name, user_name, account_id) VALUES "
+ "(?, ?, ?, ?, ?) ", CAPABILITY_TABLE);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
+
+ ACCOUNT_RETURN_VAL((hstmt != NULL), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query(g_hAccountDB, ) failed(%s).\n", _account_db_err_msg(g_hAccountDB)));
+
+ ret = _account_query_bind_text(hstmt, count++, cap_data->type);
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ret = _account_query_bind_int(hstmt, count++, cap_data->value);
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
+ ret = _account_query_bind_text(hstmt, count++, (char*)account->package_name);
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ret = _account_query_bind_text(hstmt, count++, (char*)account->user_name);
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ret = _account_query_bind_int(hstmt, count++, (int)account_id);
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
+
+ rc = _account_query_step(hstmt);
+ _INFO("_account_insert_capability _account_query_step[%d]", rc);
+
+ if (rc != SQLITE_DONE) {
+ _ERR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+ break;
}
- _ACCOUNT_FREE(caller_package_name);
- return ACCOUNT_ERROR_NONE;
- }
- return ACCOUNT_ERROR_INVALID_PARAMETER;
-}
-static int _remove_sensitive_info_from_non_owning_account_list(int caller_pid, uid_t uid, GList *account_list)
-{
- int return_code = ACCOUNT_ERROR_NONE;
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
- if (account_list == NULL)
- {
- _ERR("Null input");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
}
- GList *list_iter = NULL;
- for (list_iter = account_list; list_iter != NULL; list_iter = g_list_next(list_iter))
- {
- account_s *account = (account_s *) list_iter->data;
- int ret = _remove_sensitive_info_from_non_owning_account(caller_pid, uid, account);
- if( ret != ACCOUNT_ERROR_NONE)
- return_code = ret;
- }
- return return_code;
+ _INFO("_account_insert_capability end");
+ return _ACCOUNT_ERROR_NONE;
}
-static int _remove_sensitive_info_from_non_owning_account_slist(int caller_pid, uid_t uid, GSList *account_list)
+static int _account_update_capability(account_s *account, int account_id)
{
- int return_code = ACCOUNT_ERROR_NONE;
+ int rc, count = 1;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ account_stmt hstmt = NULL;
- if (account_list == NULL)
- {
- _ERR("Null input");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
+ ACCOUNT_RETURN_VAL((account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
- GSList *list_iter = NULL;
- for (list_iter = account_list; list_iter != NULL; list_iter = g_slist_next(list_iter))
- {
- account_s *account = (account_s *) list_iter->data;
- int ret = _remove_sensitive_info_from_non_owning_account(caller_pid, uid, account);
- if( ret != ACCOUNT_ERROR_NONE)
- return_code = ret;
+ if (g_slist_length( account->capablity_list)==0) {
+ ACCOUNT_ERROR( "_account_update_capability, no capability\n");
+ return _ACCOUNT_ERROR_NONE;
}
- return return_code;
-}
-static const char *_account_db_err_msg()
-{
- return sqlite3_errmsg(g_hAccountDB);
-}
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where _id=%d", ACCOUNT_TABLE, account_id);
-static int _account_db_err_code()
-{
- return sqlite3_errcode(g_hAccountDB);
-}
+ rc = _account_get_record_count(g_hAccountDB, query);
-static int _account_get_record_count(char* query)
-{
- _INFO("_account_get_record_count");
+ if (rc <= 0) {
+ ACCOUNT_SLOGI( "_account_update_capability : related account item is not existed rc=%d , %s", rc, _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ }
- int rc = -1;
- int ncount = 0;
- account_stmt pStmt = NULL;
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- if(!query){
- _ERR("NULL query\n");
- return ACCOUNT_ERROR_QUERY_SYNTAX_ERROR;
- }
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE account_id=? ", CAPABILITY_TABLE);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
+ count = 1;
+ _account_query_bind_int(hstmt, count++, (int)account_id);
+ rc = _account_query_step(hstmt);
- if(!g_hAccountDB){
- _ERR("DB is not opened\n");
- return ACCOUNT_ERROR_DB_NOT_OPENED;
+ if (rc != SQLITE_DONE) {
+ ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_DB_FAILED;
}
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
- rc = sqlite3_prepare_v2(g_hAccountDB, query, strlen(query), &pStmt, NULL);
+ GSList *iter;
- if (SQLITE_BUSY == rc){
- _ERR("sqlite3_prepare_v2() failed(%d, %s).", rc, _account_db_err_msg());
- sqlite3_finalize(pStmt);
- return ACCOUNT_ERROR_DATABASE_BUSY;
- } else if (SQLITE_OK != rc) {
- _ERR("sqlite3_prepare_v2() failed(%d, %s).", rc, _account_db_err_msg());
- sqlite3_finalize(pStmt);
- return ACCOUNT_ERROR_DB_FAILED;
- }
+ for (iter = account->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
+ int ret;
+ count = 1;
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(key, value, package_name, user_name, account_id) VALUES "
+ "(?, ?, ?, ?, ?) ", CAPABILITY_TABLE);
- rc = sqlite3_step(pStmt);
- if (SQLITE_BUSY == rc) {
- _ERR("sqlite3_step() failed(%d, %s).", rc, _account_db_err_msg());
- sqlite3_finalize(pStmt);
- return ACCOUNT_ERROR_DATABASE_BUSY;
- } else if (SQLITE_ROW != rc) {
- _ERR("sqlite3_step() failed(%d, %s).", rc, _account_db_err_msg());
- sqlite3_finalize(pStmt);
- return ACCOUNT_ERROR_DB_FAILED;
- }
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- ncount = sqlite3_column_int(pStmt, 0);
+ ACCOUNT_RETURN_VAL((hstmt != NULL), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query(g_hAccountDB, ) failed(%s).\n", _account_db_err_msg(g_hAccountDB)));
- _INFO("account record count [%d]", ncount);
- sqlite3_finalize(pStmt);
+ account_capability_s* cap_data = NULL;
+ cap_data = (account_capability_s*)iter->data;
- return ncount;
-}
+ ret = _account_query_bind_text(hstmt, count++, cap_data->type);
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ret = _account_query_bind_int(hstmt, count++, cap_data->value);
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
+ ret = _account_query_bind_text(hstmt, count++, (char*)account->package_name);
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ret = _account_query_bind_text(hstmt, count++, (char*)account->user_name);
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ret = _account_query_bind_int(hstmt, count++, (int)account_id);
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
-static int _account_execute_query(const char *query)
-{
- int rc = -1;
- char* pszErrorMsg = NULL;
+ rc = _account_query_step(hstmt);
- if(!query){
- ACCOUNT_ERROR("NULL query\n");
- return ACCOUNT_ERROR_QUERY_SYNTAX_ERROR;
- }
+ if (rc != SQLITE_DONE) {
+ ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+ break;
+ }
- if(!g_hAccountDB){
- ACCOUNT_ERROR("DB is not opened\n");
- return ACCOUNT_ERROR_DB_NOT_OPENED;
- }
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
- rc = sqlite3_exec(g_hAccountDB, query, NULL, NULL, &pszErrorMsg);
- if (SQLITE_OK != rc) {
- ACCOUNT_ERROR("sqlite3_exec rc(%d) query(%s) failed(%s).", rc, query, pszErrorMsg);
- sqlite3_free(pszErrorMsg);
}
- return rc;
+ return _ACCOUNT_ERROR_NONE;
}
-static int _account_begin_transaction(void)
+static int _account_update_capability_by_user_name(account_s *account, const char *user_name, const char *package_name )
{
- ACCOUNT_DEBUG("_account_begin_transaction start");
- int ret = -1;
+ int rc, count = 1;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ account_stmt hstmt = NULL;
- ret = _account_execute_query("BEGIN IMMEDIATE TRANSACTION");
+ ACCOUNT_RETURN_VAL((account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
- if (ret == SQLITE_BUSY){
- ACCOUNT_ERROR(" sqlite3 busy = %d", ret);
- return ACCOUNT_ERROR_DATABASE_BUSY;
- } else if(ret != SQLITE_OK) {
- ACCOUNT_ERROR("_account_svc_begin_transaction fail :: %d", ret);
- return ACCOUNT_ERROR_DB_FAILED;
+ if (g_slist_length( account->capablity_list)==0) {
+ ACCOUNT_ERROR( "_account_update_capability_by_user_name, no capability\n");
+ return _ACCOUNT_ERROR_NONE;
}
- ACCOUNT_DEBUG("_account_begin_transaction end");
- return ACCOUNT_ERROR_NONE;
-}
-
-static int _account_end_transaction(bool is_success)
-{
- ACCOUNT_DEBUG("_account_end_transaction start");
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where package_name= '%s' and user_name='%s'", ACCOUNT_TABLE, package_name, user_name);
- int ret = -1;
+ rc = _account_get_record_count(g_hAccountDB, query);
- if (is_success == true) {
- ret = _account_execute_query("COMMIT TRANSACTION");
- ACCOUNT_DEBUG("_account_end_transaction COMMIT");
- } else {
- ret = _account_execute_query("ROLLBACK TRANSACTION");
- ACCOUNT_DEBUG("_account_end_transaction ROLLBACK");
+ if (rc <= 0) {
+ ACCOUNT_SLOGI( "_account_update_capability_by_user_name : related account item is not existed rc=%d , %s ", rc, _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
}
- if(ret == SQLITE_PERM){
- ACCOUNT_ERROR("Account permission denied :: %d", ret);
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- if (ret == SQLITE_BUSY){
- ACCOUNT_DEBUG(" sqlite3 busy = %d", ret);
- return ACCOUNT_ERROR_DATABASE_BUSY;
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE package_name=? and user_name=? ", CAPABILITY_TABLE);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
+ count = 1;
+ _account_query_bind_text(hstmt, count++, (char*)account->package_name);
+ _account_query_bind_text(hstmt, count++, (char*)account->user_name);
+ rc = _account_query_step(hstmt);
+ if (rc != SQLITE_DONE) {
+ ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_DB_FAILED;
}
- if (ret != SQLITE_OK) {
- ACCOUNT_ERROR("_account_svc_end_transaction fail :: %d", ret);
- return ACCOUNT_ERROR_DB_FAILED;
- }
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
- ACCOUNT_DEBUG("_account_end_transaction end");
- return ACCOUNT_ERROR_NONE;
-}
+ GSList* iter;
-static bool _account_check_add_more_account(const char* app_id)
-{
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
+ for (iter = account->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
+ int ret;
+ count = 1;
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(key, value, package_name, user_name, account_id) VALUES "
+ "(?, ?, ?, ?, ?) ", CAPABILITY_TABLE);
- ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+ ACCOUNT_RETURN_VAL((hstmt != NULL), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query(g_hAccountDB, ) failed(%s).\n", _account_db_err_msg(g_hAccountDB)));
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE AppId = '%s' and MultipleAccountSupport = 1", ACCOUNT_TYPE_TABLE, app_id);
- rc = _account_get_record_count(query);
+ account_capability_s* cap_data = NULL;
+ cap_data = (account_capability_s*)iter->data;
- /* multiple account support case */
- if(rc > 0) {
- ACCOUNT_SLOGD("app id (%s) supports multiple account. rc(%d)\n", app_id, rc);
- return TRUE;
- }
+ ret = _account_query_bind_text(hstmt, count++, cap_data->type);
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ret = _account_query_bind_int(hstmt, count++, cap_data->value);
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
+ ret = _account_query_bind_text(hstmt, count++, (char*)account->package_name);
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ret = _account_query_bind_text(hstmt, count++, (char*)account->user_name);
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ret = _account_query_bind_int(hstmt, count++, (int)account->id);
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
- /* multiple account not support case */
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE package_name = '%s'", ACCOUNT_TABLE, app_id);
- rc = _account_get_record_count(query);
+ rc = _account_query_step(hstmt);
+
+ if (rc != SQLITE_DONE) {
+ ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+ break;
+ }
+
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
- if(rc <= 0) {
- ACCOUNT_SLOGD("app id (%s) supports single account. and there is no account of the app id\n", app_id);
- return TRUE;
}
- return FALSE;
+ return _ACCOUNT_ERROR_NONE;
}
-//TODO: Need to enable creating db on the first connect for
-//a) multi-user cases
-//b) to ensure db exist in every connect call
-static int _account_create_all_tables(void)
+bool _account_add_capability_to_account_cb(const char* capability_type, int capability_value, account_s *account)
{
- int rc = -1;
- int error_code = ACCOUNT_ERROR_NONE;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ account_capability_s *cap_data = (account_capability_s*)malloc(sizeof(account_capability_s));
- _INFO("create all table - BEGIN");
- ACCOUNT_MEMSET(query, 0, sizeof(query));
+ if (cap_data == NULL)
+ return FALSE;
+ ACCOUNT_MEMSET(cap_data, 0, sizeof(account_capability_s));
- /*Create the account table*/
- ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", ACCOUNT_TABLE);
- rc = _account_get_record_count(query);
- if (rc <= 0) {
- rc = _account_execute_query(ACCOUNT_SCHEMA);
- if(rc == SQLITE_BUSY) return ACCOUNT_ERROR_DATABASE_BUSY;
- ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", ACCOUNT_SCHEMA, rc, _account_db_err_msg()));
+ cap_data->type = _account_dup_text(capability_type);
+ cap_data->value = capability_value;
+ _INFO("cap_data->type = %s, cap_data->value = %d", cap_data->type, cap_data->value);
- }
+ account->capablity_list = g_slist_append(account->capablity_list, (gpointer)cap_data);
- /*Create capability table*/
- ACCOUNT_MEMSET(query, 0, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", CAPABILITY_TABLE);
- rc = _account_get_record_count(query);
- if (rc <= 0) {
- rc = _account_execute_query(CAPABILITY_SCHEMA);
- if(rc == SQLITE_BUSY) return ACCOUNT_ERROR_DATABASE_BUSY;
- ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", CAPABILITY_SCHEMA, rc, _account_db_err_msg()));
- }
+ return TRUE;
+}
- /* Create account custom table */
- ACCOUNT_MEMSET(query, 0, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", ACCOUNT_CUSTOM_TABLE);
- rc = _account_get_record_count(query);
- if (rc <= 0) {
- rc = _account_execute_query(ACCOUNT_CUSTOM_SCHEMA);
- if(rc == SQLITE_BUSY) return ACCOUNT_ERROR_DATABASE_BUSY;
- ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", query, rc, _account_db_err_msg()));
- }
- /* Create account type table */
- ACCOUNT_MEMSET(query, 0, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", ACCOUNT_TYPE_TABLE);
- rc = _account_get_record_count(query);
- if (rc <= 0) {
- rc = _account_execute_query(ACCOUNT_TYPE_SCHEMA);
- if(rc == SQLITE_BUSY) return ACCOUNT_ERROR_DATABASE_BUSY;
- ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", ACCOUNT_TYPE_SCHEMA, rc, _account_db_err_msg()));
- }
+bool _account_add_custom_to_account_cb(const char* key, const char* value, account_s *account)
+{
+ account_custom_s *custom_data = (account_custom_s*)malloc(sizeof(account_custom_s));
- /* Create label table */
- ACCOUNT_MEMSET(query, 0, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", LABEL_TABLE);
- rc = _account_get_record_count(query);
- if (rc <= 0) {
- rc = _account_execute_query(LABEL_SCHEMA);
- if(rc == SQLITE_BUSY) return ACCOUNT_ERROR_DATABASE_BUSY;
- ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", LABEL_SCHEMA, rc, _account_db_err_msg()));
+ if (custom_data == NULL) {
+ ACCOUNT_DEBUG("_account_add_custom_to_account_cb :: malloc fail\n");
+ return FALSE;
}
+ ACCOUNT_MEMSET(custom_data, 0, sizeof(account_custom_s));
- /* Create account feature table */
- ACCOUNT_MEMSET(query, 0, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", PROVIDER_FEATURE_TABLE);
- rc = _account_get_record_count(query);
- if (rc <= 0) {
- rc = _account_execute_query(PROVIDER_FEATURE_SCHEMA);
- if(rc == SQLITE_BUSY) return ACCOUNT_ERROR_DATABASE_BUSY;
- ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", PROVIDER_FEATURE_SCHEMA, rc, _account_db_err_msg()));
- }
+ custom_data->account_id = account->id;
+ custom_data->app_id = _account_dup_text(account->package_name);
+ custom_data->key = _account_dup_text(key);
+ custom_data->value = _account_dup_text(value);
+ _INFO("custom_data->key = %s, custom_data->value = %s", custom_data->key, custom_data->value);
- _INFO("create all table - END");
- return error_code;
+ account->custom_list = g_slist_append(account->custom_list, (gpointer)custom_data);
+
+ return TRUE;
}
-static int _account_check_is_all_table_exists()
+
+static int _account_compare_old_record_by_user_name(account_s *new_account, const char* user_name, const char* package_name)
{
- int rc = 0;
- char query[ACCOUNT_SQL_LEN_MAX] = {0,};
- ACCOUNT_MEMSET(query, 0, sizeof(query));
+ int error_code = _ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
+ account_s *old_account = NULL;
- ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s', '%s', '%s', '%s', '%s', '%s')",
- ACCOUNT_TABLE, CAPABILITY_TABLE, ACCOUNT_CUSTOM_TABLE, ACCOUNT_TYPE_TABLE, LABEL_TABLE, PROVIDER_FEATURE_TABLE);
- rc = _account_get_record_count(query);
+ ACCOUNT_RETURN_VAL((new_account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
+ ACCOUNT_RETURN_VAL((user_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
+ ACCOUNT_RETURN_VAL((package_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- if (rc != ACCOUNT_TABLE_TOTAL_COUNT) {
- ACCOUNT_ERROR("Table count is not matched rc=%d\n", rc);
+ old_account = (account_s*)calloc(1, sizeof(account_s));
+ if(!old_account) {
+ ACCOUNT_FATAL("Memory alloc fail\n");
+ return _ACCOUNT_ERROR_OUT_OF_MEMORY;
}
- return rc;
-}
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
-int _account_db_handle_close(sqlite3* hDB)
-{
- int rc = 0;
- int ret = ACCOUNT_ERROR_NONE;
- if(hDB)
- {
- rc = db_util_close(hDB);
- if( rc == SQLITE_OK )
- ret = ACCOUNT_ERROR_NONE;
- else if( rc == SQLITE_PERM )
- ret = ACCOUNT_ERROR_PERMISSION_DENIED;
- else if ( rc == SQLITE_BUSY )
- ret = ACCOUNT_ERROR_DATABASE_BUSY;
- else
- ret = ACCOUNT_ERROR_DB_FAILED;
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE user_name = '%s' and package_name='%s'", ACCOUNT_TABLE, user_name, package_name);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
+
+ rc = _account_query_step(hstmt);
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+ while (rc == SQLITE_ROW) {
+ _account_convert_column_to_account(hstmt, old_account);
+ rc = _account_query_step(hstmt);
}
- return ret;
-}
-int _account_db_open(int mode, int pid, uid_t uid)
-{
- int rc = 0;
- int ret = -1;
- char account_db_dir[256] = {0, };
- char account_db_path[256] = {0, };
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_CATCH_ERROR((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
- _INFO( "start _account_db_open()");
+ // get capability
+ error_code = _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, old_account->id, (void*)old_account);
+ ACCOUNT_CATCH_ERROR((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("account_query_capability_by_account_id error"));
- ACCOUNT_MEMSET(account_db_dir, 0x00, sizeof(account_db_dir));
- ACCOUNT_MEMSET(account_db_path, 0x00, sizeof(account_db_path));
+ // get custom text
+ error_code = _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, old_account->id, (void*)old_account);
+ ACCOUNT_CATCH_ERROR((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("_account_query_custom_by_account_id error"));
- ACCOUNT_GET_USER_DB_PATH(account_db_path, sizeof(account_db_path), uid);
+ // compare
+ new_account->id = old_account->id;
- if( g_hAccountDB ) {
- _ERR( "Account database is using in another app. %x", g_hAccountDB );
- return ACCOUNT_ERROR_DATABASE_BUSY;
+ //user name
+ if(!new_account->user_name) {
+ if(old_account->user_name)
+ new_account->user_name = _account_dup_text(old_account->user_name);
}
- ret = _account_db_handle_close(g_hAccountDB2);
- if( ret != ACCOUNT_ERROR_NONE )
- ACCOUNT_DEBUG( "db_util_close(g_hAccountDB2) fail ret = %d", ret);
-
- ACCOUNT_GET_USER_DB_DIR(account_db_dir, sizeof(account_db_dir), uid);
- if (-1 == access (account_db_dir, F_OK)) {
- mkdir(account_db_dir, 644);
+ // display name
+ if(!new_account->display_name) {
+ if(old_account->display_name)
+ new_account->display_name = _account_dup_text(old_account->display_name);
}
- ACCOUNT_DEBUG( "before db_util_open()");
-// if(mode == ACCOUNT_DB_OPEN_READWRITE)
- rc = db_util_open(account_db_path, &g_hAccountDB, DB_UTIL_REGISTER_HOOK_METHOD);
-// else if(mode == ACCOUNT_DB_OPEN_READONLY)
-// rc = db_util_open_with_options(account_db_path, &g_hAccountDB, SQLITE_OPEN_READONLY, NULL);
-// else
-// return ACCOUNT_ERROR_DB_NOT_OPENED;
- ACCOUNT_DEBUG( "after db_util_open() sqlite_rc = %d", rc);
-
- if( rc == SQLITE_PERM || _account_db_err_code() == SQLITE_PERM ) {
- ACCOUNT_ERROR( "Account permission denied");
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ // email address
+ if(!new_account->email_address) {
+ if(old_account->email_address)
+ new_account->email_address = _account_dup_text(old_account->email_address);
}
- if( rc == SQLITE_BUSY ) {
- ACCOUNT_ERROR( "busy handler fail.");
- return ACCOUNT_ERROR_DATABASE_BUSY;
+ // domain name
+ if(!new_account->domain_name) {
+ if(old_account->domain_name)
+ new_account->domain_name = _account_dup_text(old_account->domain_name);
}
- if( rc != SQLITE_OK ) {
- ACCOUNT_ERROR( "The database isn't connected." );
- return ACCOUNT_ERROR_DB_NOT_OPENED;
+ // icon path
+ if(!new_account->icon_path) {
+ if(old_account->icon_path)
+ new_account->icon_path = _account_dup_text(old_account->icon_path);
}
- rc = _account_check_is_all_table_exists();
-
- if (rc < 0) {
- _ERR("_account_check_is_all_table_exists rc=[%d]", rc);
- return rc;
- } else if (rc == ACCOUNT_TABLE_TOTAL_COUNT) {
- _INFO("Tables OK");
- } else {
- int ret = _account_create_all_tables();
- if (ret != ACCOUNT_ERROR_NONE) {
- _ERR("_account_create_all_tables fail ret=[%d]", ret);
- return ret;
- }
+ // source
+ if(!new_account->source) {
+ if(old_account->source)
+ new_account->source = _account_dup_text(old_account->source);
}
- _INFO( "end _account_db_open()");
- return ACCOUNT_ERROR_NONE;
-}
+ _ACCOUNT_FREE(new_account->package_name);
+ new_account->package_name = _account_dup_text(old_account->package_name);
-int _account_db_close(void)
-{
- ACCOUNT_DEBUG( "start db_util_close()");
- int ret = -1;
-/*
- ret = _account_db_handle_close(g_hAccountDB2);
- if( ret != ACCOUNT_ERROR_NONE )
- ACCOUNT_DEBUG( "db_util_close(g_hAccountDB2) fail ret = %d", ret);
-*/
- ret = _account_db_handle_close(g_hAccountDB);
- if( ret != ACCOUNT_ERROR_NONE )
- {
- ACCOUNT_ERROR( "db_util_close(g_hAccountDB) fail ret = %d", ret);
- g_hAccountDB2 = g_hAccountDB;
+ // access token
+ if(!new_account->access_token) {
+ if(old_account->access_token)
+ new_account->access_token = _account_dup_text(old_account->access_token);
}
- g_hAccountDB = NULL;
-
- return ret;
-}
-
-static int _account_check_duplicated(account_s *data, const char* verified_appid)
-{
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int count = 0;
- int ret = -1;
-
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from %s where package_name='%s' and (user_name='%s' or display_name='%s' or email_address='%s')"
- , ACCOUNT_TABLE, verified_appid, data->user_name, data->display_name, data->email_address);
-
- count = _account_get_record_count(query);
-
- if (count<=0) {
- return ACCOUNT_ERROR_NONE;
+ // auth type
+ if(new_account->auth_type == _ACCOUNT_AUTH_TYPE_INVALID) {
+ new_account->auth_type = old_account->auth_type;
}
- //check whether duplicated account or not.
- //1. check user_name
- //2. check display_name
- //3. check email_address
- GList* account_list_temp = _account_query_account_by_package_name(getpid(), OWNER_ROOT, verified_appid, &ret);
- if (account_list_temp == NULL)
- {
- _ERR("_account_query_account_by_package_name returned NULL");
- return ACCOUNT_ERROR_DB_FAILED;
+ //secret
+ if(new_account->secret== _ACCOUNT_SECRECY_INVALID) {
+ new_account->secret = old_account->secret;
}
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ // sync support
+ if(new_account->sync_support == _ACCOUNT_SYNC_INVALID) {
+ new_account->sync_support = old_account->sync_support;
}
- if(ret != ACCOUNT_ERROR_NONE){
- return ret;
+ // TODO user text
+ int i;
+ for(i=0;i<USER_TXT_CNT;i++) {
+ if(!new_account->user_data_txt[i]) {
+ if(old_account->user_data_txt[i])
+ new_account->user_data_txt[i] = _account_dup_text(old_account->user_data_txt[i]);
+ }
}
- account_list_temp = g_list_first(account_list_temp);
- _INFO("account_list_temp length=[%d]",g_list_length(account_list_temp));
-
- GList* iter = NULL;
- for (iter = account_list_temp; iter != NULL; iter = g_list_next(iter))
- {
- _INFO("iterating account_list_temp");
- account_s *account = NULL;
- _INFO("Before iter->data");
- account = (account_s*)iter->data;
- _INFO("After iter->data");
- if (account != NULL)
- {
- if(account->user_name!=NULL && data->user_name!=NULL && strcmp(account->user_name, data->user_name)==0)
- {
- _INFO("duplicated account(s) exist!, same user_name=%s", data->user_name);
- return ACCOUNT_ERROR_DUPLICATED;
- }
- //when user_name is not NULL and display_name is same.
- if(account->user_name==NULL && data->user_name==NULL && account->display_name!=NULL && data->display_name!=NULL && strcmp(account->display_name, data->display_name)==0)
- {
- _INFO("duplicated account(s) exist!, same display_name=%s", data->display_name);
- return ACCOUNT_ERROR_DUPLICATED;
- }
- //when user_name and display_name are not NULL and email_address is same.
- if(account->user_name==NULL && data->user_name==NULL && account->display_name==NULL && data->display_name==NULL && account->email_address!=NULL && data->email_address!=NULL && strcmp(account->email_address, data->email_address)==0)
- {
- _INFO("duplicated account(s) exist!, same email_address=%s", data->email_address);
- return ACCOUNT_ERROR_DUPLICATED;
- }
+ // TODO user int
+ for(i=0;i<USER_INT_CNT;i++) {
+ if(new_account->user_data_int[i] == 0) {
+ new_account->user_data_int[i] = old_account->user_data_int[i];
}
}
- return ACCOUNT_ERROR_NONE;
-}
+ // capability
-static int _account_get_next_sequence(const char *pszName)
-{
- int rc = 0;
- account_stmt pStmt = NULL;
- int max_seq = 0;
- char szQuery[ACCOUNT_SQL_LEN_MAX] = {0,};
+ // user custom table
- ACCOUNT_MEMSET(szQuery, 0x00, sizeof(szQuery));
- ACCOUNT_SNPRINTF(szQuery, sizeof(szQuery), "SELECT max(seq) FROM %s where name = '%s' ", ACCOUNT_SQLITE_SEQ, pszName);
- rc = sqlite3_prepare_v2(g_hAccountDB, szQuery, strlen(szQuery), &pStmt, NULL);
- if (SQLITE_OK != rc) {
- ACCOUNT_SLOGE("sqlite3_prepare_v2() failed(%d, %s).", rc, _account_db_err_msg());
- sqlite3_finalize(pStmt);
- return ACCOUNT_ERROR_DB_FAILED;
+CATCH:
+ if (old_account) {
+ _account_free_account_with_items(old_account);
}
- rc = sqlite3_step(pStmt);
- max_seq = sqlite3_column_int(pStmt, 0);
- max_seq++;
-
- /*Finalize Statement*/
- rc = sqlite3_finalize(pStmt);
- pStmt = NULL;
+ if (hstmt != NULL) {
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
+ }
- return max_seq;
+ return _ACCOUNT_ERROR_NONE;
}
-static account_stmt _account_prepare_query(char *query)
-{
- int rc = -1;
- account_stmt pStmt = NULL;
-
- ACCOUNT_RETURN_VAL((query != NULL), {}, NULL, ("query is NULL"));
- rc = sqlite3_prepare_v2(g_hAccountDB, query, strlen(query), &pStmt, NULL);
-
- ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, NULL, ("sqlite3_prepare_v2(%s) failed(%s).", query, _account_db_err_msg()));
-
- return pStmt;
-}
-static account_stmt _account_prepare_query_from_global_db(char *query)
+static int _account_update_account_by_user_name(int pid, uid_t uid, account_s *account, const char *user_name, const char *package_name)
{
- int rc = -1;
- account_stmt pStmt = NULL;
+ int rc = 0, binding_count = 0, count = 0;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int error_code = _ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
- ACCOUNT_RETURN_VAL((query != NULL), {}, NULL, ("query is NULL"));
+ ACCOUNT_RETURN_VAL((user_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is NULL.\n"));
+ ACCOUNT_RETURN_VAL((package_name!= NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is NULL.\n"));
- rc = sqlite3_prepare_v2(g_hAccountGlobalDB, query, strlen(query), &pStmt, NULL);
+ char* current_appid = NULL;
+ char* verified_appid = NULL;
- ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, NULL, ("sqlite3_prepare_v2(%s) failed(%s).", query, _account_db_err_msg_from_global_db()));
+ current_appid = _account_get_current_appid(pid, uid);
+ error_code = _account_get_represented_appid_from_db(g_hAccountDB, g_hAccountGlobalDB, current_appid, uid, &verified_appid);
- return pStmt;
-}
+ _ACCOUNT_FREE(current_appid);
+ _ACCOUNT_FREE(verified_appid);
-static int _account_query_bind_int(account_stmt pStmt, int pos, int num)
-{
- if(!pStmt){
- ACCOUNT_ERROR("statement is null");
- return -1;
+ if(error_code != _ACCOUNT_ERROR_NONE){
+ ACCOUNT_ERROR("No permission to update\n");
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- if(pos < 0){
- ACCOUNT_ERROR("invalid pos");
- return -1;
+ error_code = encrypt_access_token(account);
+ if (error_code != _ACCOUNT_ERROR_NONE)
+ {
+ _ERR("_encrypt_access_token error");
+ return error_code;
}
- return sqlite3_bind_int(pStmt, pos, num);
-}
-
-static int _account_query_bind_text(account_stmt pStmt, int pos, const char *str)
-{
- _INFO("_account_query_bind_text");
+ _account_compare_old_record_by_user_name(account, user_name, package_name);
- if(!pStmt)
- {
- _ERR("statement is null");
- return -1;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- if(str)
- {
- _INFO("sqlite3_bind_text");
- return sqlite3_bind_text(pStmt, pos, (const char*)str, strlen(str), SQLITE_STATIC);
- }
- else
- {
- _INFO("sqlite3_bind_null");
- return sqlite3_bind_null(pStmt, pos);
+ if (!account->package_name) {
+ ACCOUNT_ERROR("Package name is mandetory field, it can not be NULL!!!!\n");
+ return _ACCOUNT_ERROR_INVALID_PARAMETER;
}
-}
-
-static int _account_convert_account_to_sql(account_s *account, account_stmt hstmt, char *sql_value)
-{
- _INFO("start");
- int count = 1;
+ if (!account->user_name && !account->display_name && !account->email_address) {
+ ACCOUNT_ERROR("One field should be set among user name, display name, email address\n");
+ return _ACCOUNT_ERROR_INVALID_PARAMETER;
+ }
- /*Caution : Keep insert query orders.*/
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE user_name='%s' and package_name='%s'"
+ , ACCOUNT_TABLE, user_name, package_name);
- /* 1. user name*/
- _account_query_bind_text(hstmt, count++, (char*)account->user_name);
- _INFO("account_update_to_db_by_id_ex_p : after convert() : account_id[%d], user_name=%s", account->id, account->user_name);
+ count = _account_get_record_count(g_hAccountDB, query);
- /* 2. email address*/
- _account_query_bind_text(hstmt, count++, (char*)account->email_address);
- _INFO("account_update_to_db_by_id_ex_p : after convert() : account_id[%d], email_address=%s", account->id, account->email_address);
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
- /* 3. display name*/
- _account_query_bind_text(hstmt, count++, (char*)account->display_name);
- _INFO("account_update_to_db_by_id_ex_p : after convert() : account_id[%d], display_name=%s", account->id, account->display_name);
+ if (count <= 0) {
+ ACCOUNT_SLOGI("_account_update_account_by_user_name : The account not exist!, count = %d, user_name=%s, package_name=%s\n",
+ count, user_name, package_name);
+ return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ }
- /* 4. icon path*/
- _account_query_bind_text(hstmt, count++, (char*)account->icon_path);
- _INFO("account_update_to_db_by_id_ex_p : after convert() : account_id[%d], icon_path=%s", account->id, account->icon_path);
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- /* 5. source*/
- _account_query_bind_text(hstmt, count++, (char*)account->source);
- _INFO("account_update_to_db_by_id_ex_p : after convert() : account_id[%d], source=%s", account->id, account->source);
+ //TODO: Is it required to update id ? As of now I can only think of falied rollback cases (between account and gSSO DB)
+ ACCOUNT_SNPRINTF(query, sizeof(query), "UPDATE %s SET user_name=?, email_address =?, display_name =?, "
+ "icon_path =?, source =?, package_name =? , access_token =?, domain_name =?, auth_type =?, secret =?, sync_support =?,"
+ "txt_custom0=?, txt_custom1=?, txt_custom2=?, txt_custom3=?, txt_custom4=?, "
+ "int_custom0=?, int_custom1=?, int_custom2=?, int_custom3=?, int_custom4=? WHERE user_name=? and package_name=? ", ACCOUNT_TABLE);
- /* 6. package name*/
- _account_query_bind_text(hstmt, count++, (char*)account->package_name);
- _INFO("account_update_to_db_by_id_ex_p : after convert() : account_id[%d], package_name=%s", account->id, account->package_name);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ _account_end_transaction(g_hAccountDB, FALSE);
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
+ ACCOUNT_RETURN_VAL((hstmt != NULL), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_svc_query_prepare() failed(%s).\n", _account_db_err_msg(g_hAccountDB)));
- /* 7. access token*/
- _account_query_bind_text(hstmt, count++, (char*)account->access_token);
- _INFO("account_update_to_db_by_id_ex_p : after convert() : account_id[%d], access_token=%s", account->id, account->access_token);
+ binding_count = _account_convert_account_to_sql(account, hstmt, query);
- /* 8. domain name*/
- _account_query_bind_text(hstmt, count++, (char*)account->domain_name);
- _INFO("account_update_to_db_by_id_ex_p : after convert() : account_id[%d], domain_name=%s", account->id, account->domain_name);
+ _account_query_bind_text(hstmt, binding_count++, user_name);
+ _account_query_bind_text(hstmt, binding_count++, package_name);
+ rc = _account_query_step(hstmt);
+ if (rc != SQLITE_DONE) {
+ ACCOUNT_ERROR( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+ }
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
- /* 9. auth type*/
- _account_query_bind_int(hstmt, count++, account->auth_type);
- _INFO("account_update_to_db_by_id_ex_p : after convert() : account_id[%d], auth_type=%d", account->id, account->auth_type);
+ /*update capability*/
+ error_code = _account_update_capability_by_user_name(account, user_name, package_name);
- /* 10. secret */
- _account_query_bind_int(hstmt, count++, account->secret);
- _INFO("account_update_to_db_by_id_ex_p : after convert() : account_id[%d], secret=%d", account->id, account->secret);
+ /* update custom */
+ error_code = _account_update_custom(account, account->id);
- /* 11. sync_support */
- _account_query_bind_int(hstmt, count++, account->sync_support);
- _INFO("account_update_to_db_by_id_ex_p : after convert() : account_id[%d], sync_support=%d", account->id, account->sync_support);
+ return error_code;
+}
- int i;
+int _account_insert_to_db(account_s* account, int pid, uid_t uid, int *account_id)
+{
+ _INFO("");
+ int error_code = _ACCOUNT_ERROR_NONE;
+ int ret_transaction = 0;
- /* 12. user text*/
- for(i=0; i< USER_TXT_CNT; i++)
- _account_query_bind_text(hstmt, count++, (char*)account->user_data_txt[i]);
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
+ ACCOUNT_RETURN_VAL((account_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID POINTER IS NULL"));
- /* 13. user integer */
- for(i=0; i< USER_INT_CNT; i++)
- {
- _account_query_bind_int(hstmt, count++, account->user_data_int[i]);
- _INFO("convert user_data_int : marshal_user_int data_int[%d]=%d", i, account->user_data_int[i]);
+ if (!account->user_name && !account->display_name && !account->email_address) {
+ ACCOUNT_ERROR("One field should be set among user name, display name, email address\n");
+ return _ACCOUNT_ERROR_INVALID_PARAMETER;
}
- _INFO("end");
+ account_s *data = (account_s*)account;
+ ACCOUNT_SLOGD("(%s)-(%d) account_insert_to_db: begin_transaction.\n", __FUNCTION__, __LINE__);
- return count;
-}
+ pthread_mutex_lock(&account_mutex);
-static int _account_query_finalize(account_stmt pStmt)
-{
- int rc = -1;
+ /* transaction control required*/
+ ret_transaction = _account_begin_transaction(g_hAccountDB);
- if (!pStmt) {
- ACCOUNT_ERROR( "pStmt is NULL");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
+ if(_account_db_err_code(g_hAccountDB) == SQLITE_PERM){
+ pthread_mutex_unlock(&account_mutex);
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- rc = sqlite3_finalize(pStmt);
- if (rc == SQLITE_BUSY){
- ACCOUNT_ERROR(" sqlite3 busy = %d", rc);
- return ACCOUNT_ERROR_DATABASE_BUSY;
- } else if (rc != SQLITE_OK) {
- ACCOUNT_ERROR( "sqlite3_finalize fail, rc : %d, db_error : %s\n", rc, _account_db_err_msg());
- return ACCOUNT_ERROR_DB_FAILED;
+ if (ret_transaction == _ACCOUNT_ERROR_DATABASE_BUSY) {
+ ACCOUNT_ERROR("account insert:_account_begin_transaction fail %d\n", ret_transaction);
+ pthread_mutex_unlock(&account_mutex);
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
+ }else if (ret_transaction != _ACCOUNT_ERROR_NONE) {
+ ACCOUNT_ERROR("account insert:_account_begin_transaction fail %d\n", ret_transaction);
+ pthread_mutex_unlock(&account_mutex);
+ return ret_transaction;
}
- return ACCOUNT_ERROR_NONE;
-}
+ *account_id = _account_get_next_sequence(g_hAccountDB, ACCOUNT_TABLE);
+ data->id = *account_id;
-static int _account_query_finalize_from_global_db(account_stmt pStmt)
-{
- int rc = -1;
+ char* appid = NULL;
+ appid = _account_get_current_appid(pid, uid);
- if (!pStmt) {
- ACCOUNT_ERROR( "pStmt is NULL");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
+ if(!appid)
+ {
+ _INFO("");
+ // API caller cannot be recognized
+ ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
+ ACCOUNT_ERROR("App id is not registered in account type DB, transaction ret (%x)!!!!\n", ret_transaction);
+ pthread_mutex_unlock(&account_mutex);
+ return _ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER;
}
- rc = sqlite3_finalize(pStmt);
- if (rc == SQLITE_BUSY){
- ACCOUNT_ERROR(" sqlite3 busy = %d", rc);
- return ACCOUNT_ERROR_DATABASE_BUSY;
- } else if (rc != SQLITE_OK) {
- ACCOUNT_ERROR( "sqlite3_finalize fail, rc : %d, db_error : %s\n", rc, _account_db_err_msg_from_global_db());
- return ACCOUNT_ERROR_DB_FAILED;
+ _INFO("");
+ char* verified_appid = NULL;
+ error_code = _account_get_represented_appid_from_db(g_hAccountDB, g_hAccountGlobalDB, appid, uid, &verified_appid);//FIX
+ _ACCOUNT_FREE(appid);
+ if(error_code != _ACCOUNT_ERROR_NONE)
+ {
+ _ERR("error_code = %d", error_code);
+ ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
+ ACCOUNT_ERROR("App id is not registered in account type DB, transaction ret (%x)!!!!\n", ret_transaction);
+ _ACCOUNT_FREE(verified_appid);
+ pthread_mutex_unlock(&account_mutex);
+ return error_code;
}
- return ACCOUNT_ERROR_NONE;
-}
-
-static int _account_query_step(account_stmt pStmt)
-{
- if(!pStmt){
- ACCOUNT_ERROR( "pStmt is NULL");
- return -1;
- }
-
- return sqlite3_step(pStmt);
-}
-
-static int _account_execute_insert_query(account_s *account)
-{
- _INFO("_account_execute_insert_query start");
-
- int rc = 0;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
-
- /* check whether app id exist in account type db */
-
- if (!account->user_name && !account->display_name && !account->email_address) {
- _INFO("");
- ACCOUNT_ERROR("Mandetory fields is NULL. At least one field is required among username, display name, email address\n");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- _INFO("");
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s (user_name, email_address , display_name , icon_path , source , package_name , "
- "access_token , domain_name , auth_type , secret , sync_support , txt_custom0, txt_custom1, txt_custom2, txt_custom3, txt_custom4, "
- "int_custom0, int_custom1, int_custom2, int_custom3, int_custom4, txt_custom0 ) values " // to do urusa
- "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", ACCOUNT_TABLE);
-
- hstmt = _account_prepare_query(query);
- ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
-
- _INFO("");
- _account_convert_account_to_sql(account, hstmt, query);
-
- _INFO("");
- rc = _account_query_step(hstmt);
- if (rc != SQLITE_DONE) {
+ if(verified_appid)
+ {
_INFO("");
- ACCOUNT_ERROR( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg());
-
- if( _account_db_err_code() == SQLITE_PERM )
- error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
- else
- error_code = ACCOUNT_ERROR_DB_FAILED;
- }
-
- _INFO("");
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- _INFO("_account_execute_insert_query end");
- return error_code;
-}
-
-static int _account_insert_capability(account_s *account, int account_id)
-{
- _INFO("_account_insert_capability start");
- int rc, count = 1;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- account_stmt hstmt = NULL;
-
- ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
-
- if (g_slist_length( account->capablity_list)==0) {
- ACCOUNT_DEBUG( "_account_insert_capability, no capability\n");
- return ACCOUNT_ERROR_NONE;
- }
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where _id=%d", ACCOUNT_TABLE, account_id);
-
- _INFO("_account_insert_capability _account_get_record_count [%s]", query);
- rc = _account_get_record_count(query);
-
- if( _account_db_err_code() == SQLITE_PERM ){
- _ERR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
- if (rc <= 0) {
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
- }
-
- /* insert query*/
-
- GSList *iter;
-
- for (iter = account->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
- int ret;
- count = 1;
-
- account_capability_s* cap_data = NULL;
- cap_data = (account_capability_s*)iter->data;
-
- _INFO("cap_data->type = %s, cap_data->value = %d \n", cap_data->type, cap_data->value);
-
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(key, value, package_name, user_name, account_id) VALUES "
- "(?, ?, ?, ?, ?) ", CAPABILITY_TABLE);
- hstmt = _account_prepare_query(query);
-
- ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
-
- ret = _account_query_bind_text(hstmt, count++, cap_data->type);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
- ret = _account_query_bind_int(hstmt, count++, cap_data->value);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
- ret = _account_query_bind_text(hstmt, count++, (char*)account->package_name);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
- ret = _account_query_bind_text(hstmt, count++, (char*)account->user_name);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
- ret = _account_query_bind_int(hstmt, count++, (int)account_id);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
-
- rc = _account_query_step(hstmt);
- _INFO("_account_insert_capability _account_query_step[%d]", rc);
-
- if (rc != SQLITE_DONE) {
- _ERR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- break;
- }
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- }
-
- _INFO("_account_insert_capability end");
- return ACCOUNT_ERROR_NONE;
-}
-
-static int _account_update_capability(account_s *account, int account_id)
-{
- int rc, count = 1;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- account_stmt hstmt = NULL;
-
- ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
-
- if (g_slist_length( account->capablity_list)==0) {
- ACCOUNT_ERROR( "_account_update_capability, no capability\n");
- return ACCOUNT_ERROR_NONE;
- }
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where _id=%d", ACCOUNT_TABLE, account_id);
-
- rc = _account_get_record_count(query);
-
- if (rc <= 0) {
- ACCOUNT_SLOGI( "_account_update_capability : related account item is not existed rc=%d , %s", rc, _account_db_err_msg());
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
- }
-
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE account_id=? ", CAPABILITY_TABLE);
- hstmt = _account_prepare_query(query);
- count = 1;
- _account_query_bind_int(hstmt, count++, (int)account_id);
- rc = _account_query_step(hstmt);
-
- if (rc != SQLITE_DONE) {
- ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- return ACCOUNT_ERROR_DB_FAILED;
- }
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- GSList *iter;
-
- for (iter = account->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
- int ret;
- count = 1;
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(key, value, package_name, user_name, account_id) VALUES "
- "(?, ?, ?, ?, ?) ", CAPABILITY_TABLE);
-
- hstmt = _account_prepare_query(query);
-
- ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
-
- account_capability_s* cap_data = NULL;
- cap_data = (account_capability_s*)iter->data;
-
- ret = _account_query_bind_text(hstmt, count++, cap_data->type);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
- ret = _account_query_bind_int(hstmt, count++, cap_data->value);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
- ret = _account_query_bind_text(hstmt, count++, (char*)account->package_name);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
- ret = _account_query_bind_text(hstmt, count++, (char*)account->user_name);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
- ret = _account_query_bind_int(hstmt, count++, (int)account_id);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
-
- rc = _account_query_step(hstmt);
-
- if (rc != SQLITE_DONE) {
- ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- break;
- }
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- }
-
- return ACCOUNT_ERROR_NONE;
-}
-
-static int _account_update_capability_by_user_name(account_s *account, const char *user_name, const char *package_name )
-{
- int rc, count = 1;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- account_stmt hstmt = NULL;
-
- ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
-
- if (g_slist_length( account->capablity_list)==0) {
- ACCOUNT_ERROR( "_account_update_capability_by_user_name, no capability\n");
- return ACCOUNT_ERROR_NONE;
- }
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where package_name= '%s' and user_name='%s'", ACCOUNT_TABLE, package_name, user_name);
-
- rc = _account_get_record_count(query);
-
- if (rc <= 0) {
- ACCOUNT_SLOGI( "_account_update_capability_by_user_name : related account item is not existed rc=%d , %s ", rc, _account_db_err_msg());
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
- }
-
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE package_name=? and user_name=? ", CAPABILITY_TABLE);
- hstmt = _account_prepare_query(query);
- count = 1;
- _account_query_bind_text(hstmt, count++, (char*)account->package_name);
- _account_query_bind_text(hstmt, count++, (char*)account->user_name);
- rc = _account_query_step(hstmt);
- if (rc != SQLITE_DONE) {
- ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- return ACCOUNT_ERROR_DB_FAILED;
- }
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- GSList* iter;
-
- for (iter = account->capablity_list; iter != NULL; iter = g_slist_next(iter)) {
- int ret;
- count = 1;
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(key, value, package_name, user_name, account_id) VALUES "
- "(?, ?, ?, ?, ?) ", CAPABILITY_TABLE);
-
- hstmt = _account_prepare_query(query);
-
- ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
-
- account_capability_s* cap_data = NULL;
- cap_data = (account_capability_s*)iter->data;
-
- ret = _account_query_bind_text(hstmt, count++, cap_data->type);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
- ret = _account_query_bind_int(hstmt, count++, cap_data->value);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
- ret = _account_query_bind_text(hstmt, count++, (char*)account->package_name);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
- ret = _account_query_bind_text(hstmt, count++, (char*)account->user_name);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
- ret = _account_query_bind_int(hstmt, count++, (int)account->id);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
-
- rc = _account_query_step(hstmt);
-
- if (rc != SQLITE_DONE) {
- ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- break;
- }
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- }
-
- return ACCOUNT_ERROR_NONE;
-}
-
-static int _account_query_table_column_int(account_stmt pStmt, int pos)
-{
- if(!pStmt){
- ACCOUNT_ERROR("statement is null");
- return -1;
- }
-
- if(pos < 0){
- ACCOUNT_ERROR("invalid pos");
- return -1;
- }
-
- return sqlite3_column_int(pStmt, pos);
-}
-
-static const char *_account_query_table_column_text(account_stmt pStmt, int pos)
-{
- if(!pStmt){
- ACCOUNT_ERROR("statement is null");
- return NULL;
- }
-
- if(pos < 0){
- ACCOUNT_ERROR("invalid pos");
- return NULL;
- }
-
- return (const char*)sqlite3_column_text(pStmt, pos);
-}
-
-static void _account_db_data_to_text(const char *textbuf, char **output)
-{
- if (textbuf && strlen(textbuf)>0) {
- if (*output) {
- free(*output);
- *output = NULL;
+ error_code = _account_check_duplicated(g_hAccountDB, data, verified_appid, uid);
+ if (error_code != _ACCOUNT_ERROR_NONE) {
+ _INFO("");
+ ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
+ ACCOUNT_DEBUG("_account_check_duplicated(), rollback insert query(%x)!!!!\n", ret_transaction);
+ *account_id = -1;
+ pthread_mutex_unlock(&account_mutex);
+ return error_code;
+ }
+ if(!_account_check_add_more_account(verified_appid)) {
+ ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
+ ACCOUNT_ERROR("No more account cannot be added, transaction ret (%x)!!!!\n", ret_transaction);
+ pthread_mutex_unlock(&account_mutex);
+ _ACCOUNT_FREE(verified_appid);
+ return _ACCOUNT_ERROR_NOT_ALLOW_MULTIPLE;
}
- *output = strdup(textbuf);
- }
-}
-
-static void _account_convert_column_to_account(account_stmt hstmt, account_s *account_record)
-{
- const char *textbuf = NULL;
-
- account_record->id = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_ID);
- ACCOUNT_DEBUG("account_record->id =[%d]", account_record->id);
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_NAME);
- _account_db_data_to_text(textbuf, &(account_record->user_name));
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_EMAIL_ADDRESS);
- _account_db_data_to_text(textbuf, &(account_record->email_address));
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_DISPLAY_NAME);
- _account_db_data_to_text(textbuf, &(account_record->display_name));
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_ICON_PATH);
- _account_db_data_to_text(textbuf, &(account_record->icon_path));
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_SOURCE);
- _account_db_data_to_text(textbuf, &(account_record->source));
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_PACKAGE_NAME);
- _account_db_data_to_text(textbuf, &(account_record->package_name));
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_ACCESS_TOKEN);
- _account_db_data_to_text(textbuf, &(account_record->access_token));
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_DOMAIN_NAME);
- _account_db_data_to_text(textbuf, &(account_record->domain_name));
-
- account_record->auth_type = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_AUTH_TYPE);
-
- account_record->secret = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_SECRET);
-
- account_record->sync_support = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_SYNC_SUPPORT);
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_0);
- _account_db_data_to_text(textbuf, &(account_record->user_data_txt[0]));
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_1);
- _account_db_data_to_text(textbuf, &(account_record->user_data_txt[1]));
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_2);
- _account_db_data_to_text(textbuf, &(account_record->user_data_txt[2]));
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_3);
- _account_db_data_to_text(textbuf, &(account_record->user_data_txt[3]));
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_4);
- _account_db_data_to_text(textbuf, &(account_record->user_data_txt[4]));
-
- account_record->user_data_int[0] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_0);
- account_record->user_data_int[1] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_1);
- account_record->user_data_int[2] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_2);
- account_record->user_data_int[3] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_3);
- account_record->user_data_int[4] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_4);
-}
-
-static void _account_convert_column_to_capability(account_stmt hstmt, account_capability_s *capability_record)
-{
- const char *textbuf = NULL;
-
- _INFO("start _account_convert_column_to_capability()");
- capability_record->id = _account_query_table_column_int(hstmt, CAPABILITY_FIELD_ID);
-
- textbuf = _account_query_table_column_text(hstmt, CAPABILITY_FIELD_KEY);
- _account_db_data_to_text(textbuf, &(capability_record->type));
-
- capability_record->value = _account_query_table_column_int(hstmt, CAPABILITY_FIELD_VALUE);
-
- textbuf = _account_query_table_column_text(hstmt, CAPABILITY_FIELD_PACKAGE_NAME);
- _account_db_data_to_text(textbuf, &(capability_record->package_name));
-
- textbuf = _account_query_table_column_text(hstmt, CAPABILITY_FIELD_USER_NAME);
- _account_db_data_to_text(textbuf, &(capability_record->user_name));
-
- capability_record->account_id = _account_query_table_column_int(hstmt, CAPABILITY_FIELD_ACCOUNT_ID);
- _INFO("type = %s, value = %d", capability_record->type, capability_record->value);
- _INFO("end _account_convert_column_to_capability()");
-}
-
-static void _account_convert_column_to_custom(account_stmt hstmt, account_custom_s *custom_record)
-{
- _INFO("start _account_convert_column_to_custom()");
- const char *textbuf = NULL;
-
- custom_record->account_id = _account_query_table_column_int(hstmt, ACCOUNT_CUSTOM_FIELD_ACCOUNT_ID);
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_CUSTOM_FIELD_APP_ID);
- _account_db_data_to_text(textbuf, &(custom_record->app_id));
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_CUSTOM_FIELD_KEY);
- _account_db_data_to_text(textbuf, &(custom_record->key));
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_CUSTOM_FIELD_VALUE);
- _account_db_data_to_text(textbuf, &(custom_record->value));
- _INFO("key = %s, value = %s", custom_record->key, custom_record->value);
- _INFO("end _account_convert_column_to_custom()");
-}
-
-bool _account_get_capability_text_cb(const char* capability_type, account_capability_state_e capability_value, void *user_data)
-{
- account_s *data = (account_s*)user_data;
-
- account_capability_s *cap_data = (account_capability_s*)malloc(sizeof(account_capability_s));
-
- if (cap_data == NULL)
- return FALSE;
- ACCOUNT_MEMSET(cap_data, 0, sizeof(account_capability_s));
-
- cap_data->type = _account_get_text(capability_type);
- cap_data->value = capability_value;
- _INFO("cap_data->type = %s, cap_data->value = %d", cap_data->type, cap_data->value);
-
- data->capablity_list = g_slist_append(data->capablity_list, (gpointer)cap_data);
-
- return TRUE;
-}
-
-
-bool _account_get_custom_text_cb(char* key, char* value, void *user_data)
-{
- account_s *data = (account_s*)user_data;
-
- account_custom_s *custom_data = (account_custom_s*)malloc(sizeof(account_custom_s));
-
- if (custom_data == NULL) {
- ACCOUNT_DEBUG("_account_get_custom_text_cb :: malloc fail\n");
- return FALSE;
- }
- ACCOUNT_MEMSET(custom_data, 0, sizeof(account_custom_s));
-
- custom_data->account_id = data->id;
- custom_data->app_id = _account_get_text(data->package_name);
- custom_data->key = _account_get_text(key);
- custom_data->value = _account_get_text(value);
- _INFO("custom_data->key = %s, custom_data->value = %s", custom_data->key, custom_data->value);
-
- data->custom_list = g_slist_append(data->custom_list, (gpointer)custom_data);
-
- return TRUE;
-}
-
-
-static char *_account_get_text(const char *text_data)
-{
- char *text_value = NULL;
-
- if (text_data != NULL) {
- text_value = strdup(text_data);
- }
- return text_value;
-}
-
-static int _account_compare_old_record_by_user_name(account_s *new_account, const char* user_name, const char* package_name)
-{
- int error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
- account_s *old_account = NULL;
-
- ACCOUNT_RETURN_VAL((new_account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
- ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
- ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-
- old_account = (account_s*)calloc(1, sizeof(account_s));
- if(!old_account) {
- ACCOUNT_FATAL("Memory alloc fail\n");
- return ACCOUNT_ERROR_OUT_OF_MEMORY;
- }
-
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE user_name = '%s' and package_name='%s'", ACCOUNT_TABLE, user_name, package_name);
- hstmt = _account_prepare_query(query);
-
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
-
- while (rc == SQLITE_ROW) {
- _account_convert_column_to_account(hstmt, old_account);
- rc = _account_query_step(hstmt);
- }
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_CATCH_ERROR((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- // get capability
- error_code = _account_query_capability_by_account_id(_account_get_capability_text_cb, old_account->id, (void*)old_account);
- ACCOUNT_CATCH_ERROR((error_code == ACCOUNT_ERROR_NONE), {}, error_code, ("account_query_capability_by_account_id error"));
-
- // get custom text
- error_code = _account_query_custom_by_account_id(_account_get_custom_text_cb, old_account->id, (void*)old_account);
- ACCOUNT_CATCH_ERROR((error_code == ACCOUNT_ERROR_NONE), {}, error_code, ("_account_query_custom_by_account_id error"));
-
- // compare
- new_account->id = old_account->id;
-
- //user name
- if(!new_account->user_name) {
- if(old_account->user_name)
- new_account->user_name = _account_get_text(old_account->user_name);
- }
-
- // display name
- if(!new_account->display_name) {
- if(old_account->display_name)
- new_account->display_name = _account_get_text(old_account->display_name);
- }
-
- // email address
- if(!new_account->email_address) {
- if(old_account->email_address)
- new_account->email_address = _account_get_text(old_account->email_address);
- }
-
- // domain name
- if(!new_account->domain_name) {
- if(old_account->domain_name)
- new_account->domain_name = _account_get_text(old_account->domain_name);
- }
-
- // icon path
- if(!new_account->icon_path) {
- if(old_account->icon_path)
- new_account->icon_path = _account_get_text(old_account->icon_path);
- }
-
- // source
- if(!new_account->source) {
- if(old_account->source)
- new_account->source = _account_get_text(old_account->source);
- }
-
- _ACCOUNT_FREE(new_account->package_name);
- new_account->package_name = _account_get_text(old_account->package_name);
-
- // access token
- if(!new_account->access_token) {
- if(old_account->access_token)
- new_account->access_token = _account_get_text(old_account->access_token);
- }
-
- // auth type
- if(new_account->auth_type == ACCOUNT_AUTH_TYPE_INVALID) {
- new_account->auth_type = old_account->auth_type;
- }
-
- //secret
- if(new_account->secret== ACCOUNT_SECRECY_INVALID) {
- new_account->secret = old_account->secret;
- }
-
- // sync support
- if(new_account->sync_support == ACCOUNT_SYNC_INVALID) {
- new_account->sync_support = old_account->sync_support;
- }
-
- // TODO user text
- int i;
- for(i=0;i<USER_TXT_CNT;i++) {
- if(!new_account->user_data_txt[i]) {
- if(old_account->user_data_txt[i])
- new_account->user_data_txt[i] = _account_get_text(old_account->user_data_txt[i]);
- }
- }
-
- // TODO user int
- for(i=0;i<USER_INT_CNT;i++) {
- if(new_account->user_data_int[i] == 0) {
- new_account->user_data_int[i] = old_account->user_data_int[i];
- }
- }
-
- // capability
-
- // user custom table
-
-CATCH:
- if (old_account) {
- _account_free_account_with_items(old_account);
- }
-
- if (hstmt != NULL) {
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
- }
-
- return ACCOUNT_ERROR_NONE;
-}
-
-
-
-static int _account_update_account_by_user_name(int pid, uid_t uid, account_s *account, const char *user_name, const char *package_name)
-{
- int rc = 0, binding_count = 0, count = 0;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
-
- ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is NULL.\n"));
- ACCOUNT_RETURN_VAL((package_name!= NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is NULL.\n"));
-
- char* current_appid = NULL;
- char* verified_appid = NULL;
-
- current_appid = _account_get_current_appid(pid, uid);
- error_code = _account_check_account_type_with_appid_group(uid, current_appid, &verified_appid);
-
- _ACCOUNT_FREE(current_appid);
- _ACCOUNT_FREE(verified_appid);
-
- if(error_code != ACCOUNT_ERROR_NONE){
- ACCOUNT_ERROR("No permission to update\n");
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- error_code = _encrypt_access_token(account);
- if (error_code != ACCOUNT_ERROR_NONE)
- {
- _ERR("_encrypt_access_token error");
- return error_code;
- }
-
- _account_compare_old_record_by_user_name(account, user_name, package_name);
-
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- if (!account->package_name) {
- ACCOUNT_ERROR("Package name is mandetory field, it can not be NULL!!!!\n");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- if (!account->user_name && !account->display_name && !account->email_address) {
- ACCOUNT_ERROR("One field should be set among user name, display name, email address\n");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE user_name='%s' and package_name='%s'"
- , ACCOUNT_TABLE, user_name, package_name);
-
- count = _account_get_record_count(query);
-
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- if (count <= 0) {
- ACCOUNT_SLOGI("_account_update_account_by_user_name : The account not exist!, count = %d, user_name=%s, package_name=%s\n",
- count, user_name, package_name);
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
- }
-
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
-
- //TODO: Is it required to update id ? As of now I can only think of falied rollback cases (between account and gSSO DB)
- ACCOUNT_SNPRINTF(query, sizeof(query), "UPDATE %s SET user_name=?, email_address =?, display_name =?, "
- "icon_path =?, source =?, package_name =? , access_token =?, domain_name =?, auth_type =?, secret =?, sync_support =?,"
- "txt_custom0=?, txt_custom1=?, txt_custom2=?, txt_custom3=?, txt_custom4=?, "
- "int_custom0=?, int_custom1=?, int_custom2=?, int_custom3=?, int_custom4=? WHERE user_name=? and package_name=? ", ACCOUNT_TABLE);
-
- hstmt = _account_prepare_query(query);
- if( _account_db_err_code() == SQLITE_PERM ){
- _account_end_transaction(FALSE);
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
- ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_svc_query_prepare() failed(%s).\n", _account_db_err_msg()));
-
- binding_count = _account_convert_account_to_sql(account, hstmt, query);
-
- _account_query_bind_text(hstmt, binding_count++, user_name);
- _account_query_bind_text(hstmt, binding_count++, package_name);
- rc = _account_query_step(hstmt);
- if (rc != SQLITE_DONE) {
- ACCOUNT_ERROR( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- }
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- /*update capability*/
- error_code = _account_update_capability_by_user_name(account, user_name, package_name);
-
- /* update custom */
- error_code = _account_update_custom(account, account->id);
-
- return error_code;
-}
-
-int _account_insert_to_db(account_s* account, int pid, uid_t uid, int *account_id)
-{
- _INFO("");
- int error_code = ACCOUNT_ERROR_NONE;
- int ret_transaction = 0;
-
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
- ACCOUNT_RETURN_VAL((account_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT ID POINTER IS NULL"));
-
- if (!account->user_name && !account->display_name && !account->email_address) {
- ACCOUNT_ERROR("One field should be set among user name, display name, email address\n");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- account_s *data = (account_s*)account;
- ACCOUNT_SLOGD("(%s)-(%d) account_insert_to_db: begin_transaction.\n", __FUNCTION__, __LINE__);
-
- pthread_mutex_lock(&account_mutex);
-
- /* transaction control required*/
- ret_transaction = _account_begin_transaction();
-
- if(_account_db_err_code() == SQLITE_PERM){
- pthread_mutex_unlock(&account_mutex);
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- if (ret_transaction == ACCOUNT_ERROR_DATABASE_BUSY) {
- ACCOUNT_ERROR("account insert:_account_begin_transaction fail %d\n", ret_transaction);
- pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_DATABASE_BUSY;
- }else if (ret_transaction != ACCOUNT_ERROR_NONE) {
- ACCOUNT_ERROR("account insert:_account_begin_transaction fail %d\n", ret_transaction);
- pthread_mutex_unlock(&account_mutex);
- return ret_transaction;
- }
-
- *account_id = _account_get_next_sequence(ACCOUNT_TABLE);
- data->id = *account_id;
-
- char* appid = NULL;
- appid = _account_get_current_appid(pid, uid);
-
- if(!appid)
- {
- _INFO("");
- // API caller cannot be recognized
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR("App id is not registered in account type DB, transaction ret (%x)!!!!\n", ret_transaction);
- pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER;
- }
-
- _INFO("");
- char* verified_appid = NULL;
- error_code = _account_check_account_type_with_appid_group(uid, appid, &verified_appid);//FIX
- _ACCOUNT_FREE(appid);
- if(error_code != ACCOUNT_ERROR_NONE)
- {
- _ERR("error_code = %d", error_code);
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR("App id is not registered in account type DB, transaction ret (%x)!!!!\n", ret_transaction);
- _ACCOUNT_FREE(verified_appid);
- pthread_mutex_unlock(&account_mutex);
- return error_code;
- }
-
- if(verified_appid)
- {
- _INFO("");
- error_code = _account_check_duplicated(data, verified_appid);
- if (error_code != ACCOUNT_ERROR_NONE) {
- _INFO("");
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_DEBUG("_account_check_duplicated(), rollback insert query(%x)!!!!\n", ret_transaction);
- *account_id = -1;
- pthread_mutex_unlock(&account_mutex);
- return error_code;
- }
- if(!_account_check_add_more_account(verified_appid)) {
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR("No more account cannot be added, transaction ret (%x)!!!!\n", ret_transaction);
- pthread_mutex_unlock(&account_mutex);
- _ACCOUNT_FREE(verified_appid);
- return ACCOUNT_ERROR_NOT_ALLOW_MULTIPLE;
- }
-
- _ACCOUNT_FREE(data->package_name);
- data->package_name = _account_get_text(verified_appid);
- _ACCOUNT_FREE(verified_appid);
- }
-
- if(!_account_check_add_more_account(data->package_name))
- {
- _INFO("");
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR("No more account cannot be added, transaction ret (%x)!!!!\n", ret_transaction);
- pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_NOT_ALLOW_MULTIPLE;
- }
-
- error_code = _encrypt_access_token(data);
- if (error_code != ACCOUNT_ERROR_NONE)
- {
- _ERR("_encrypt_access_token error");
- return error_code;
- }
-
- error_code = _account_execute_insert_query(data);
-
- if (error_code != ACCOUNT_ERROR_NONE)
- {
- _INFO("");
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR("INSERT account fail, rollback insert query(%x)!!!!\n", ret_transaction);
- *account_id = -1;
- pthread_mutex_unlock(&account_mutex);
- return error_code;
- }
-
- _INFO("");
- error_code = _account_insert_capability(data, *account_id);
- if (error_code != ACCOUNT_ERROR_NONE)
- {
- _INFO("");
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR("INSERT capability fail, rollback insert capability query(%x)!!!!\n", ret_transaction);
- *account_id = -1;
- pthread_mutex_unlock(&account_mutex);
- return error_code;
- }
-
- _INFO("");
- error_code = _account_insert_custom(data, *account_id);
- if (error_code != ACCOUNT_ERROR_NONE)
- {
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR("INSERT custom fail, rollback insert capability query(%x)!!!!\n", ret_transaction);
- *account_id = -1;
- pthread_mutex_unlock(&account_mutex);
- return error_code;
- }
-
- _INFO("");
-
- pthread_mutex_unlock(&account_mutex);
- _account_end_transaction(TRUE);
- ACCOUNT_SLOGD("(%s)-(%d) account _end_transaction.\n", __FUNCTION__, __LINE__);
-
- char buf[64]={0,};
- ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", ACCOUNT_NOTI_NAME_INSERT, *account_id);
- _account_insert_delete_update_notification_send(buf);
- _INFO("account _notification_send end.");
-
- return ACCOUNT_ERROR_NONE;
-
-}
-
-int _account_query_capability_by_account_id(capability_cb callback, int account_id, void *user_data )
-{
- int error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
-
- ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
- ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE account_id = %d", CAPABILITY_TABLE, account_id);
- hstmt = _account_prepare_query(query);
-
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
-
- account_capability_s* capability_record = NULL;
-
- while (rc == SQLITE_ROW) {
- bool cb_ret = FALSE;
- capability_record = (account_capability_s*) malloc(sizeof(account_capability_s));
-
- if (capability_record == NULL) {
- ACCOUNT_FATAL("malloc Failed");
- break;
- }
-
- ACCOUNT_MEMSET(capability_record, 0x00, sizeof(account_capability_s));
-
- _account_convert_column_to_capability(hstmt, capability_record);
-
- cb_ret = callback(capability_record->type, capability_record->value, user_data);
-
- _account_free_capability_with_items(capability_record);
-
- ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, ACCOUNT_ERROR_NONE, ("Callback func returs FALSE, its iteration is stopped!!!!\n"));
-
- rc = _account_query_step(hstmt);
- }
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- error_code = ACCOUNT_ERROR_NONE;
-
-CATCH:
- if (hstmt != NULL) {
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
- }
-
- pthread_mutex_unlock(&account_mutex);
- return error_code;
-}
-
-GSList* _account_get_capability_list_by_account_id(int account_id, int *error_code)
-{
- *error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
- GSList* capability_list = NULL;
-
- ACCOUNT_RETURN_VAL((account_id > 0), {*error_code = ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("ACCOUNT INDEX IS LESS THAN 0"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
-
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE account_id = %d", CAPABILITY_TABLE, account_id);
- hstmt = _account_prepare_query(query);
-
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
- return NULL;
- }
-
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
-
- account_capability_s* capability_record = NULL;
-
- while (rc == SQLITE_ROW) {
- capability_record = (account_capability_s*) malloc(sizeof(account_capability_s));
-
- if (capability_record == NULL) {
- ACCOUNT_FATAL("malloc Failed");
- break;
- }
-
- ACCOUNT_MEMSET(capability_record, 0x00, sizeof(account_capability_s));
-
- _account_convert_column_to_capability(hstmt, capability_record);
-
- //cb_ret = callback(capability_record->type, capability_record->value, user_data);
-
- //_account_free_capability_items(capability_record);
- //_ACCOUNT_FREE(capability_record);
-
- //ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, ACCOUNT_ERROR_NONE, ("Callback func returs FALSE, its iteration is stopped!!!!\n"));
-
- capability_list = g_slist_append(capability_list, capability_record);
- rc = _account_query_step(hstmt);
- }
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
- hstmt = NULL;
-
- *error_code = ACCOUNT_ERROR_NONE;
-
-CATCH:
- if (hstmt != NULL)
- {
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
- hstmt = NULL;
- }
-
- pthread_mutex_unlock(&account_mutex);
- return capability_list;
-}
-
-static int _account_compare_old_record(account_s *new_account, int account_id)
-{
- int error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
- account_s *old_account = NULL;
-
- ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
- ACCOUNT_RETURN_VAL((new_account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-
- old_account = (account_s*)calloc(1, sizeof(account_s));
- if (old_account == NULL) {
- _ERR("Out of Memory");
- return ACCOUNT_ERROR_OUT_OF_MEMORY;
- }
-
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id = %d", ACCOUNT_TABLE, account_id);
- hstmt = _account_prepare_query(query);
-
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
-
- while (rc == SQLITE_ROW) {
- _account_convert_column_to_account(hstmt, old_account);
- rc = _account_query_step(hstmt);
- }
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_CATCH_ERROR((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- // get capability
- error_code = _account_query_capability_by_account_id(_account_get_capability_text_cb, old_account->id, (void*)old_account);
- ACCOUNT_CATCH_ERROR((error_code == ACCOUNT_ERROR_NONE), {}, error_code, ("account_query_capability_by_account_id error"));
-
- // get custom text
- error_code = _account_query_custom_by_account_id(_account_get_custom_text_cb, old_account->id, (void*)old_account);
- ACCOUNT_CATCH_ERROR((error_code == ACCOUNT_ERROR_NONE), {}, error_code, ("_account_query_custom_by_account_id error"));
-
- // compare
-
- new_account->id = old_account->id;
-
- //user name
- if(!new_account->user_name) {
- if(old_account->user_name)
- new_account->user_name = _account_get_text(old_account->user_name);
- }
-
- // display name
- if(!new_account->display_name) {
- if(old_account->display_name)
- new_account->display_name = _account_get_text(old_account->display_name);
- }
-
- // email address
- if(!new_account->email_address) {
- if(old_account->email_address)
- new_account->email_address = _account_get_text(old_account->email_address);
- }
-
- // domain name
- if(!new_account->domain_name) {
- if(old_account->domain_name)
- new_account->domain_name = _account_get_text(old_account->domain_name);
- }
-
- // icon path
- if(!new_account->icon_path) {
- if(old_account->icon_path)
- new_account->icon_path = _account_get_text(old_account->icon_path);
- }
-
- // source
- if(!new_account->source) {
- if(old_account->source)
- new_account->source = _account_get_text(old_account->source);
- }
-
- _ACCOUNT_FREE(new_account->package_name);
- new_account->package_name = _account_get_text(old_account->package_name);
-
- // access token
- if(!new_account->access_token) {
- if(old_account->access_token)
- new_account->access_token = _account_get_text(old_account->access_token);
- }
-
- // user text
- int i;
- for(i=0;i<USER_TXT_CNT;i++) {
- if(!new_account->user_data_txt[i]) {
- if(old_account->user_data_txt[i])
- new_account->user_data_txt[i] = _account_get_text(old_account->user_data_txt[i]);
- }
- }
-
- // auth type
- if(new_account->auth_type == ACCOUNT_AUTH_TYPE_INVALID) {
- new_account->auth_type = old_account->auth_type;
- }
-
- //secret
- if(new_account->secret== ACCOUNT_SECRECY_INVALID) {
- new_account->secret = old_account->secret;
- }
-
- // sync support
- if(new_account->sync_support == ACCOUNT_SYNC_INVALID) {
- new_account->sync_support = old_account->sync_support;
- }
-
- // user int
- for(i=0;i<USER_INT_CNT;i++) {
- if(new_account->user_data_int[i] == 0) {
- new_account->user_data_int[i] = old_account->user_data_int[i];
- }
- }
-
- // capability
-
- // user custom table
-
-CATCH:
- if (old_account)
- _account_free_account_with_items(old_account);
-
- if (hstmt != NULL) {
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
- }
-
- return ACCOUNT_ERROR_NONE;
-}
-
-static int _account_get_package_name_from_account_id(int account_id, char **package_name)
-{
- int error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
- account_s *old_account = NULL;
-
- ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-
- old_account = (account_s*)calloc(1, sizeof(account_s));
- if (old_account == NULL) {
- _ERR("Out Of memory");
- return ACCOUNT_ERROR_OUT_OF_MEMORY;
- }
-
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id = %d", ACCOUNT_TABLE, account_id);
- hstmt = _account_prepare_query(query);
-
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
-
- while (rc == SQLITE_ROW) {
- _account_convert_column_to_account(hstmt, old_account);
- rc = _account_query_step(hstmt);
- }
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_CATCH_ERROR((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- // get package name.
- *package_name = _account_get_text(old_account->package_name);
-
-
- CATCH:
- if (old_account) {
- _account_free_account_with_items(old_account);
- }
-
- if (hstmt != NULL) {
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
- }
-
- return error_code;
-
-}
-
-static int _account_update_account(int pid, uid_t uid, account_s *account, int account_id)
-{
- int rc = 0, binding_count =0;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int error_code = ACCOUNT_ERROR_NONE, count=0, ret_transaction = 0;
- account_stmt hstmt = NULL;
-
- if (!account->package_name) {
- ACCOUNT_ERROR("Package name is mandetory field, it can not be NULL!!!!\n");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- /* Check permission of requested appid */
- char* current_appid = NULL;
- char *package_name = NULL;
-
- current_appid = _account_get_current_appid(pid, uid);
- error_code = _account_get_package_name_from_account_id(account_id, &package_name);
-
- if(error_code != ACCOUNT_ERROR_NONE || package_name == NULL){
- ACCOUNT_ERROR("No package name with account_id\n");
- _ACCOUNT_FREE(current_appid);
- _ACCOUNT_FREE(package_name);
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
- }
-
- error_code = _account_check_appid_group_with_package_name(uid, current_appid, package_name);
- ACCOUNT_DEBUG( "UPDATE:account_id[%d],current_appid[%s]package_name[%s]", account_id, current_appid, package_name); // TODO: remove the log later.
-
- _ACCOUNT_FREE(current_appid);
- _ACCOUNT_FREE(package_name);
-
- if(error_code != ACCOUNT_ERROR_NONE){
- ACCOUNT_ERROR("No permission to update\n");
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- error_code = _encrypt_access_token(account);
- if (error_code != ACCOUNT_ERROR_NONE)
- {
- _ERR("_encrypt_access_token error");
- return error_code;
- }
-
- error_code = _account_compare_old_record(account, account_id);
- if (error_code != ACCOUNT_ERROR_NONE) {
- ACCOUNT_ERROR("_account_compare_old_record fail\n");
- return error_code;
- }
-
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- } else if( _account_db_err_code() == SQLITE_BUSY ){
- ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_DATABASE_BUSY;
- }
-
- if (!account->user_name && !account->display_name && !account->email_address) {
- ACCOUNT_ERROR("One field should be set among user name, display name, email address\n");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE _id = %d ", ACCOUNT_TABLE, account_id);
-
- count = _account_get_record_count(query);
- if (count <= 0) {
- ACCOUNT_DEBUG(" Account record not found, count = %d\n", count);
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
- }
-
- /* transaction control required*/
- ret_transaction = _account_begin_transaction();
- if( ret_transaction == ACCOUNT_ERROR_DATABASE_BUSY ){
- ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg());
- pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_DATABASE_BUSY;
- }
-
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "UPDATE %s SET user_name=?, email_address =?, display_name =?, "
- "icon_path =?, source =?, package_name =? , access_token =?, domain_name =?, auth_type =?, secret =?, sync_support =?,"
- "txt_custom0=?, txt_custom1=?, txt_custom2=?, txt_custom3=?, txt_custom4=?, "
- "int_custom0=?, int_custom1=?, int_custom2=?, int_custom3=?, int_custom4=? WHERE _id=? ", ACCOUNT_TABLE);
-
- hstmt = _account_prepare_query(query);
-
- if( _account_db_err_code() == SQLITE_PERM ){
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_svc_query_prepare() failed(%s)(%x).\n", _account_db_err_msg(), _account_end_transaction(FALSE)));
-
- binding_count = _account_convert_account_to_sql(account, hstmt, query);
- _account_query_bind_int(hstmt, binding_count++, account_id);
-
- rc = _account_query_step(hstmt);
- if (rc != SQLITE_DONE) {
- ACCOUNT_SLOGE( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- }
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- _INFO("update query=%s", query);
-
- /*update capability*/
- error_code = _account_update_capability(account, account_id);
- if(error_code != ACCOUNT_ERROR_NONE && error_code!= ACCOUNT_ERROR_RECORD_NOT_FOUND){
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR("update capability Failed, trying to roll back(%x) !!!\n", ret_transaction);
- return error_code;
- }
-
- /* update custom */
- error_code = _account_update_custom(account, account_id);
- if(error_code != ACCOUNT_ERROR_NONE && error_code!= ACCOUNT_ERROR_RECORD_NOT_FOUND){
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR("update capability Failed, trying to roll back(%x) !!!\n", ret_transaction);
- return error_code;
- }
-
- ret_transaction = _account_end_transaction(TRUE);
-
- _INFO("update end");
- return error_code;
-}
-
-
-static int _account_update_account_ex(account_s *account, int account_id)
-{
- int rc = 0, binding_count =0;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int error_code = ACCOUNT_ERROR_NONE, count=0, ret_transaction = 0;
- account_stmt hstmt = NULL;
- if (!account->package_name) {
- ACCOUNT_ERROR("Package name is mandetory field, it can not be NULL!!!!\n");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
+ _ACCOUNT_FREE(data->package_name);
+ data->package_name = _account_dup_text(verified_appid);
+ _ACCOUNT_FREE(verified_appid);
}
- error_code = _encrypt_access_token(account);
- if (error_code != ACCOUNT_ERROR_NONE)
+ if(!_account_check_add_more_account(data->package_name))
{
- _ERR("_encrypt_access_token error");
- return error_code;
+ _INFO("");
+ ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
+ ACCOUNT_ERROR("No more account cannot be added, transaction ret (%x)!!!!\n", ret_transaction);
+ pthread_mutex_unlock(&account_mutex);
+ return _ACCOUNT_ERROR_NOT_ALLOW_MULTIPLE;
}
- error_code = _account_compare_old_record(account, account_id);
- if (error_code != ACCOUNT_ERROR_NONE) {
- ACCOUNT_ERROR("_account_compare_old_record fail\n");
+ error_code = encrypt_access_token(data);
+ if (error_code != _ACCOUNT_ERROR_NONE)
+ {
+ _ERR("_encrypt_access_token error");
return error_code;
}
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- if (!account->user_name && !account->display_name && !account->email_address) {
- ACCOUNT_ERROR("One field should be set among user name, display name, email address\n");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE _id = %d ", ACCOUNT_TABLE, account_id);
-
- count = _account_get_record_count(query);
- if (count <= 0) {
- ACCOUNT_DEBUG(" Account record not found, count = %d\n", count);
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
- }
+ error_code = _account_execute_insert_query(data);
- /* transaction control required*/
- ret_transaction = _account_begin_transaction();
- if( ret_transaction == ACCOUNT_ERROR_DATABASE_BUSY ){
- ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg());
+ if (error_code != _ACCOUNT_ERROR_NONE)
+ {
+ _INFO("");
+ ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
+ ACCOUNT_ERROR("INSERT account fail, rollback insert query(%x)!!!!\n", ret_transaction);
+ *account_id = -1;
pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_DATABASE_BUSY;
- }
-
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "UPDATE %s SET user_name=?, email_address =?, display_name =?, "
- "icon_path =?, source =?, package_name =? , access_token =?, domain_name =?, auth_type =?, secret =?, sync_support =?,"
- "txt_custom0=?, txt_custom1=?, txt_custom2=?, txt_custom3=?, txt_custom4=?, "
- "int_custom0=?, int_custom1=?, int_custom2=?, int_custom3=?, int_custom4=? WHERE _id=? ", ACCOUNT_TABLE);
-
- hstmt = _account_prepare_query(query);
-
- if( _account_db_err_code() == SQLITE_PERM ){
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_svc_query_prepare() failed(%s)(%x).\n", _account_db_err_msg(), _account_end_transaction(FALSE)));
-
- _INFO("account_update_to_db_by_id_ex_p : before convert() : account_id[%d], user_name=%s", account->id, account->user_name);
- binding_count = _account_convert_account_to_sql(account, hstmt, query);
- _INFO("account_update_to_db_by_id_ex_p : after convert() : account_id[%d], user_name=%s", account->id, account->user_name);
- _INFO("account_update_to_db_by_id_ex_p : before bind()");
- rc = _account_query_bind_int(hstmt, binding_count++, account_id);
- _INFO("account_update_to_db_by_id_ex_p : after bind() : ret = %d", rc);
-
- rc = _account_query_step(hstmt);
- if (rc != SQLITE_DONE) {
- ACCOUNT_SLOGE( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- }
- _INFO("account_update_to_db_by_id_ex_p : after query_step() : ret = %d", rc);
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
- _INFO("account_update_to_db_by_id_ex_p : after query_filnalize() : ret = %d", rc);
-
- _INFO("account_update_to_db_by_id_ex_p : before update_capability()");
- /*update capability*/
- error_code = _account_update_capability(account, account_id);
- if(error_code != ACCOUNT_ERROR_NONE && error_code!= ACCOUNT_ERROR_RECORD_NOT_FOUND){
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR("update capability Failed, trying to roll back(%x) !!!\n", ret_transaction);
- return error_code;
- }
- _INFO("account_update_to_db_by_id_ex_p : after update_capability()");
-
- _INFO("account_update_to_db_by_id_ex_p : before update_custom()");
- /* update custom */
- error_code = _account_update_custom(account, account_id);
- if(error_code != ACCOUNT_ERROR_NONE && error_code!= ACCOUNT_ERROR_RECORD_NOT_FOUND){
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR("update capability Failed, trying to roll back(%x) !!!\n", ret_transaction);
return error_code;
}
- _INFO("account_update_to_db_by_id_ex_p : after update_custom()");
-
- ret_transaction = _account_end_transaction(TRUE);
- return error_code;
-}
-
-
-int _account_update_to_db_by_id(int pid, uid_t uid, account_s* account, int account_id)
-{
- ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
- ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- int error_code = ACCOUNT_ERROR_NONE;
- account_s* data = (account_s*)account;
-
- pthread_mutex_lock(&account_mutex);
-
- error_code = _account_update_account(pid, uid, data, account_id);
-
- if(error_code != ACCOUNT_ERROR_NONE) {
+ _INFO("");
+ error_code = _account_insert_capability(data, *account_id);
+ if (error_code != _ACCOUNT_ERROR_NONE)
+ {
+ _INFO("");
+ ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
+ ACCOUNT_ERROR("INSERT capability fail, rollback insert capability query(%x)!!!!\n", ret_transaction);
+ *account_id = -1;
pthread_mutex_unlock(&account_mutex);
return error_code;
}
- pthread_mutex_unlock(&account_mutex);
-
- char buf[64]={0,};
- ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", ACCOUNT_NOTI_NAME_UPDATE, account_id);
- _account_insert_delete_update_notification_send(buf);
-
- return ACCOUNT_ERROR_NONE;
-}
-
-int _account_update_to_db_by_id_ex(account_s* account, int account_id)
-{
- ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
- ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- int error_code = ACCOUNT_ERROR_NONE;
- account_s* data = account;
-
- pthread_mutex_lock(&account_mutex);
-
- _INFO("before update_account_ex() : account_id[%d], user_name=%s", account_id, data->user_name);
- error_code = _account_update_account_ex(data, account_id);
- _INFO("after update_account_ex() : account_id[%d], user_name=%s", account_id, data->user_name);
-
- if(error_code != ACCOUNT_ERROR_NONE) {
+ _INFO("");
+ error_code = _account_insert_custom(data, *account_id);
+ if (error_code != _ACCOUNT_ERROR_NONE)
+ {
+ ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
+ ACCOUNT_ERROR("INSERT custom fail, rollback insert capability query(%x)!!!!\n", ret_transaction);
+ *account_id = -1;
pthread_mutex_unlock(&account_mutex);
return error_code;
}
- pthread_mutex_unlock(&account_mutex);
-
- char buf[64]={0,};
- ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", ACCOUNT_NOTI_NAME_UPDATE, account_id);
- _account_insert_delete_update_notification_send(buf);
-
- return ACCOUNT_ERROR_NONE;
-}
-
-
-int _account_update_to_db_by_user_name(int pid, uid_t uid, account_s* account, const char *user_name, const char *package_name)
-{
- ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
- ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-
- int error_code = ACCOUNT_ERROR_NONE;
- account_s *data = (account_s*)account;
-
- pthread_mutex_lock(&account_mutex);
-
- error_code = _account_update_account_by_user_name(pid, uid, data, user_name, package_name);
+ _INFO("");
pthread_mutex_unlock(&account_mutex);
+ _account_end_transaction(g_hAccountDB, TRUE);
+ ACCOUNT_SLOGD("(%s)-(%d) account _end_transaction.\n", __FUNCTION__, __LINE__);
char buf[64]={0,};
- ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", ACCOUNT_NOTI_NAME_UPDATE, data->id);
+ ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", _ACCOUNT_NOTI_NAME_INSERT, *account_id);
_account_insert_delete_update_notification_send(buf);
+ _INFO("account _notification_send end.");
+
+ return _ACCOUNT_ERROR_NONE;
- return error_code;
}
-GSList* _account_db_query_all(int pid, uid_t uid)
+GSList* _account_get_capability_list_by_account_id(int account_id, int *error_code)
{
- //int error_code = ACCOUNT_ERROR_NONE;
+ *error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0;
- GSList *account_list = NULL;
+ GSList* capability_list = NULL;
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, NULL, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((account_id > 0), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("ACCOUNT INDEX IS LESS THAN 0"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = _ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s ", ACCOUNT_TABLE);
- hstmt = _account_prepare_query(query);
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE account_id = %d", CAPABILITY_TABLE, account_id);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
return NULL;
}
rc = _account_query_step(hstmt);
+ ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
- account_s *account_record = NULL;
-
- if (rc != SQLITE_ROW)
- {
- _ERR("The record isn't found");
- goto CATCH;
- }
+ account_capability_s* capability_record = NULL;
- while(rc == SQLITE_ROW) {
- account_record = (account_s*) malloc(sizeof(account_s));
+ while (rc == SQLITE_ROW) {
+ capability_record = (account_capability_s*) malloc(sizeof(account_capability_s));
- if (account_record == NULL) {
+ if (capability_record == NULL) {
ACCOUNT_FATAL("malloc Failed");
break;
- }
-
- ACCOUNT_MEMSET(account_record, 0x00, sizeof(account_s));
- _account_convert_column_to_account(hstmt, account_record);
- account_list = g_slist_append(account_list, account_record);
- rc = _account_query_step(hstmt);
- }
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, NULL, ("finalize error"));
- hstmt = NULL;
-
- GSList* iter;
-
- for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
- account_s *account = NULL;
- account = (account_s*)iter->data;
- _account_query_capability_by_account_id(_account_get_capability_text_cb, account->id, (void*)account);
- _account_query_custom_by_account_id(_account_get_custom_text_cb, account->id, (void*)account);
- }
-
-CATCH:
- if (hstmt != NULL) {
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {_account_gslist_account_free(account_list);}, NULL, ("finalize error"));
- hstmt = NULL;
- }
- if (account_list)
- {
- _remove_sensitive_info_from_non_owning_account_slist(pid, uid, account_list);
- }
- return account_list;
-}
-
-int _account_update_sync_status_by_id(uid_t uid, int account_db_id, const int sync_status)
-{
- int error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
- int count =1;
-
- ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- if ( (sync_status < 0) || (sync_status > ACCOUNT_SYNC_STATUS_RUNNING)) {
- ACCOUNT_SLOGE("(%s)-(%d) sync_status is less than 0 or more than enum max.\n", __FUNCTION__, __LINE__);
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- pthread_mutex_lock(&account_mutex);
-
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where _id=%d", ACCOUNT_TABLE, account_db_id);
-
- rc = _account_get_record_count(query);
-
- if( _account_db_err_code() == SQLITE_PERM ){
- pthread_mutex_unlock(&account_mutex);
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- if (rc <= 0) {
- ACCOUNT_SLOGE( "account_update_sync_status_by_id : related account item is not existed rc=%d , %s", rc, _account_db_err_msg());
- pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
- }
-
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "UPDATE %s SET sync_support=? WHERE _id = %d", ACCOUNT_TABLE, account_db_id);
- hstmt = _account_prepare_query(query);
-
- _account_query_bind_int(hstmt, count, sync_status);
-
- rc = _account_query_step(hstmt);
-
- if( _account_db_err_code() == SQLITE_PERM ){
- pthread_mutex_unlock(&account_mutex);
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_DB_FAILED,
- ("account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg()));
-
- rc = _account_query_finalize(hstmt);
- if (rc != ACCOUNT_ERROR_NONE) {
- ACCOUNT_ERROR("_account_query_finalize error");
- pthread_mutex_unlock(&account_mutex);
- return rc;
- }
- char buf[64]={0,};
- ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", ACCOUNT_NOTI_NAME_SYNC_UPDATE, account_db_id);
- _account_insert_delete_update_notification_send(buf);
-
- hstmt = NULL;
- error_code = ACCOUNT_ERROR_NONE;
-
-CATCH:
- if (hstmt != NULL) {
- rc = _account_query_finalize(hstmt);
- pthread_mutex_unlock(&account_mutex);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
- }
-
- pthread_mutex_unlock(&account_mutex);
- return error_code;
-}
-
-int _account_query_account_by_account_id(int pid, uid_t uid, int account_db_id, account_s *account_record)
-{
- _INFO("_account_query_account_by_account_id() start, account_db_id=[%d]", account_db_id);
-
- int error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
-
- ACCOUNT_RETURN_VAL((account_db_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
- ACCOUNT_RETURN_VAL(account_record != NULL, {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ }
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+ ACCOUNT_MEMSET(capability_record, 0x00, sizeof(account_capability_s));
- ACCOUNT_DEBUG("starting db operations");
+ _account_convert_column_to_capability(hstmt, capability_record);
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id = %d", ACCOUNT_TABLE, account_db_id);
- hstmt = _account_prepare_query(query);
- rc = _account_db_err_code();
- _INFO("after _account_prepare_query, rc=[%d]", rc);
+ //cb_ret = callback(capability_record->type, capability_record->value, user_data);
- if( rc == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
+ //_account_free_capability_items(capability_record);
+ //_ACCOUNT_FREE(capability_record);
- ACCOUNT_DEBUG("before _account_query_step");
- rc = _account_query_step(hstmt);
- ACCOUNT_DEBUG("after _account_query_step returned [%d]", rc);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ //ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, _ACCOUNT_ERROR_NONE, ("Callback func returs FALSE, its iteration is stopped!!!!\n"));
- while (rc == SQLITE_ROW) {
- ACCOUNT_DEBUG("before _account_convert_column_to_account");
- _account_convert_column_to_account(hstmt, account_record);
- ACCOUNT_DEBUG("after _account_convert_column_to_account");
- ACCOUNT_DEBUG("user_name = %s, user_txt[0] = %s, user_int[1] = %d", account_record->user_name, account_record->user_data_txt[0], account_record->user_data_int[1]);
+ capability_list = g_slist_append(capability_list, capability_record);
rc = _account_query_step(hstmt);
}
- ACCOUNT_DEBUG("account_record->id=[%d]", account_record->id);
-
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
-
- ACCOUNT_DEBUG("before _account_query_capability_by_account_id");
- _account_query_capability_by_account_id(_account_get_capability_text_cb, account_record->id, (void*)account_record);
- ACCOUNT_DEBUG("after _account_query_capability_by_account_id");
-
- ACCOUNT_DEBUG("before _account_query_custom_by_account_id");
- _account_query_custom_by_account_id(_account_get_custom_text_cb, account_record->id, (void*)account_record);
- ACCOUNT_DEBUG("after _account_query_custom_by_account_id");
-
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
hstmt = NULL;
- error_code = ACCOUNT_ERROR_NONE;
+
+ *error_code = _ACCOUNT_ERROR_NONE;
CATCH:
- if (hstmt != NULL) {
+ if (hstmt != NULL)
+ {
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
hstmt = NULL;
}
- if (account_record)
- {
- _remove_sensitive_info_from_non_owning_account(pid, uid, account_record);
- }
pthread_mutex_unlock(&account_mutex);
- ACCOUNT_DEBUG("_account_query_account_by_account_id end [%d]", error_code);
- return error_code;
+ return capability_list;
}
-GList* _account_query_account_by_user_name(int pid, uid_t uid, const char *user_name, int *error_code)
+static int _account_compare_old_record(account_s *new_account, int account_id)
{
- *error_code = ACCOUNT_ERROR_NONE;
+ int error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0;
- account_s *account_head = NULL;
+ account_s *old_account = NULL;
- if (user_name == NULL)
- {
- _ERR("USER NAME IS NULL");
- *error_code = ACCOUNT_ERROR_INVALID_PARAMETER;
- goto CATCH;
+ ACCOUNT_RETURN_VAL((account_id > 0), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
+ ACCOUNT_RETURN_VAL((new_account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+
+ old_account = (account_s*)calloc(1, sizeof(account_s));
+ if (old_account == NULL) {
+ _ERR("Out of Memory");
+ return _ACCOUNT_ERROR_OUT_OF_MEMORY;
}
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE user_name = ?", ACCOUNT_TABLE);
-
- hstmt = _account_prepare_query(query);
-
- if (_account_db_err_code() == SQLITE_PERM)
- {
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
- goto CATCH;
- }
-
- int binding_count = 1;
- _account_query_bind_text(hstmt, binding_count++, user_name);
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id = %d", ACCOUNT_TABLE, account_id);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
rc = _account_query_step(hstmt);
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
- if (rc != SQLITE_ROW)
- {
- _ERR("The record isn't found");
- *error_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
- goto CATCH;
+ while (rc == SQLITE_ROW) {
+ _account_convert_column_to_account(hstmt, old_account);
+ rc = _account_query_step(hstmt);
}
- int tmp = 0;
-
- account_head = (account_s*) malloc(sizeof(account_s));
- if (account_head == NULL) {
- ACCOUNT_FATAL("malloc Failed");
- if (hstmt != NULL) {
- rc = _account_query_finalize(hstmt);
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_CATCH_ERROR((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
- if (rc != ACCOUNT_ERROR_NONE)
- {
- _ERR("finalize error");
- *error_code = rc;
- goto CATCH;
- }
- hstmt = NULL;
- }
- *error_code = ACCOUNT_ERROR_OUT_OF_MEMORY;
- goto CATCH;
- }
- ACCOUNT_MEMSET(account_head, 0x00, sizeof(account_s));
+ // get capability
+ error_code = _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, old_account->id, (void*)old_account);
+ ACCOUNT_CATCH_ERROR((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("account_query_capability_by_account_id error"));
- while (rc == SQLITE_ROW) {
- account_s* account_record = NULL;
+ // get custom text
+ error_code = _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, old_account->id, (void*)old_account);
+ ACCOUNT_CATCH_ERROR((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("_account_query_custom_by_account_id error"));
- account_record = (account_s*) malloc(sizeof(account_s));
+ // compare
- if (account_record == NULL) {
- ACCOUNT_FATAL("malloc Failed");
- break;
- }
- ACCOUNT_MEMSET(account_record, 0x00, sizeof(account_s));
+ new_account->id = old_account->id;
- _account_convert_column_to_account(hstmt, account_record);
+ //user name
+ if(!new_account->user_name) {
+ if(old_account->user_name)
+ new_account->user_name = _account_dup_text(old_account->user_name);
+ }
- account_head->account_list = g_list_append(account_head->account_list, account_record);
+ // display name
+ if(!new_account->display_name) {
+ if(old_account->display_name)
+ new_account->display_name = _account_dup_text(old_account->display_name);
+ }
- rc = _account_query_step(hstmt);
- tmp++;
+ // email address
+ if(!new_account->email_address) {
+ if(old_account->email_address)
+ new_account->email_address = _account_dup_text(old_account->email_address);
}
- rc = _account_query_finalize(hstmt);
+ // domain name
+ if(!new_account->domain_name) {
+ if(old_account->domain_name)
+ new_account->domain_name = _account_dup_text(old_account->domain_name);
+ }
- if (rc != ACCOUNT_ERROR_NONE)
- {
- _ERR("finalize error");
- *error_code = rc;
- goto CATCH;
+ // icon path
+ if(!new_account->icon_path) {
+ if(old_account->icon_path)
+ new_account->icon_path = _account_dup_text(old_account->icon_path);
}
- hstmt = NULL;
+ // source
+ if(!new_account->source) {
+ if(old_account->source)
+ new_account->source = _account_dup_text(old_account->source);
+ }
- GList *iter;
+ _ACCOUNT_FREE(new_account->package_name);
+ new_account->package_name = _account_dup_text(old_account->package_name);
+ // access token
+ if(!new_account->access_token) {
+ if(old_account->access_token)
+ new_account->access_token = _account_dup_text(old_account->access_token);
+ }
- tmp = g_list_length(account_head->account_list);
+ // user text
+ int i;
+ for(i=0;i<USER_TXT_CNT;i++) {
+ if(!new_account->user_data_txt[i]) {
+ if(old_account->user_data_txt[i])
+ new_account->user_data_txt[i] = _account_dup_text(old_account->user_data_txt[i]);
+ }
+ }
- for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
- account_h account;
- account = (account_h)iter->data;
+ // auth type
+ if(new_account->auth_type == _ACCOUNT_AUTH_TYPE_INVALID) {
+ new_account->auth_type = old_account->auth_type;
+ }
- account_s *testaccount = (account_s*)account;
+ //secret
+ if(new_account->secret== _ACCOUNT_SECRECY_INVALID) {
+ new_account->secret = old_account->secret;
+ }
- _account_query_capability_by_account_id(_account_get_capability_text_cb, testaccount->id, (void*)testaccount);
- _account_query_custom_by_account_id(_account_get_custom_text_cb, testaccount->id, (void*)testaccount);
+ // sync support
+ if(new_account->sync_support == _ACCOUNT_SYNC_INVALID) {
+ new_account->sync_support = old_account->sync_support;
+ }
+ // user int
+ for(i=0;i<USER_INT_CNT;i++) {
+ if(new_account->user_data_int[i] == 0) {
+ new_account->user_data_int[i] = old_account->user_data_int[i];
+ }
}
- *error_code = ACCOUNT_ERROR_NONE;
+ // capability
+
+ // user custom table
CATCH:
- if (hstmt != NULL) {
- rc = _account_query_finalize(hstmt);
- if (rc != ACCOUNT_ERROR_NONE)
- {
- _ERR("finalize error");
- *error_code = rc;
+ if (old_account)
+ _account_free_account_with_items(old_account);
+
+ if (hstmt != NULL) {
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
}
- hstmt = NULL;
- }
- pthread_mutex_unlock(&account_mutex);
- if (account_head)
- {
- _remove_sensitive_info_from_non_owning_account_list(pid, uid, account_head->account_list);
- GList* result = account_head->account_list;
- _ACCOUNT_FREE(account_head);
- return result;
- }
- return NULL;
+ return _ACCOUNT_ERROR_NONE;
}
-GList*
-_account_query_account_by_capability(int pid, uid_t uid, const char* capability_type, const int capability_value, int *error_code)
+static int _account_get_package_name_from_account_id(int account_id, char **package_name)
{
- *error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
+ int error_code = _ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
+ int rc = 0;
+ account_s *old_account = NULL;
- ACCOUNT_RETURN_VAL((capability_type != NULL), {*error_code = ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("capability_type IS NULL"));
+ ACCOUNT_RETURN_VAL((account_id > 0), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- if ((capability_value < 0) || (capability_value > ACCOUNT_CAPABILITY_ENABLED)) {
- ACCOUNT_SLOGE("(%s)-(%d) capability_value is not equal to 0 or 1.\n", __FUNCTION__, __LINE__);
- *error_code = ACCOUNT_ERROR_INVALID_PARAMETER;
- return NULL;
+ old_account = (account_s*)calloc(1, sizeof(account_s));
+ if (old_account == NULL) {
+ _ERR("Out Of memory");
+ return _ACCOUNT_ERROR_OUT_OF_MEMORY;
}
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
-
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id IN (SELECT account_id from %s WHERE key=? AND value=?)", ACCOUNT_TABLE, CAPABILITY_TABLE);
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id = %d", ACCOUNT_TABLE, account_id);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- hstmt = _account_prepare_query(query);
+ rc = _account_query_step(hstmt);
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
- return NULL;
+ while (rc == SQLITE_ROW) {
+ _account_convert_column_to_account(hstmt, old_account);
+ rc = _account_query_step(hstmt);
}
- int binding_count = 1;
- _account_query_bind_text(hstmt, binding_count++, capability_type);
- _account_query_bind_int(hstmt, binding_count++, capability_value);
-
- rc = _account_query_step(hstmt);
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_CATCH_ERROR((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
- account_s* account_head = NULL;
+ // get package name.
+ *package_name = _account_dup_text(old_account->package_name);
- ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
- int tmp = 0;
+ CATCH:
+ if (old_account) {
+ _account_free_account_with_items(old_account);
+ }
- account_head = (account_s*) malloc(sizeof(account_s));
- if (account_head == NULL) {
- ACCOUNT_FATAL("malloc Failed");
if (hstmt != NULL) {
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
}
- *error_code = ACCOUNT_ERROR_OUT_OF_MEMORY;
- return NULL;
+
+ return error_code;
+
+}
+
+static int _account_update_account(int pid, uid_t uid, account_s *account, int account_id)
+{
+ int rc = 0, binding_count =0;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int error_code = _ACCOUNT_ERROR_NONE, count=0, ret_transaction = 0;
+ account_stmt hstmt = NULL;
+
+ if (!account->package_name) {
+ ACCOUNT_ERROR("Package name is mandetory field, it can not be NULL!!!!\n");
+ return _ACCOUNT_ERROR_INVALID_PARAMETER;
+ }
+
+ /* Check permission of requested appid */
+ char* current_appid = NULL;
+ char *package_name = NULL;
+
+ current_appid = _account_get_current_appid(pid, uid);
+ error_code = _account_get_package_name_from_account_id(account_id, &package_name);
+
+ if(error_code != _ACCOUNT_ERROR_NONE || package_name == NULL){
+ ACCOUNT_ERROR("No package name with account_id\n");
+ _ACCOUNT_FREE(current_appid);
+ _ACCOUNT_FREE(package_name);
+ return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ }
+
+ error_code = _account_check_appid_group_with_package_name(current_appid, package_name, uid);
+ ACCOUNT_DEBUG( "UPDATE:account_id[%d],current_appid[%s]package_name[%s]", account_id, current_appid, package_name); // TODO: remove the log later.
+
+ _ACCOUNT_FREE(current_appid);
+ _ACCOUNT_FREE(package_name);
+
+ if(error_code != _ACCOUNT_ERROR_NONE){
+ ACCOUNT_ERROR("No permission to update\n");
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- ACCOUNT_MEMSET(account_head, 0x00, sizeof(account_s));
- while (rc == SQLITE_ROW) {
- account_s* account_record = NULL;
+ error_code = encrypt_access_token(account);
+ if (error_code != _ACCOUNT_ERROR_NONE)
+ {
+ _ERR("_encrypt_access_token error");
+ return error_code;
+ }
- account_record = (account_s*) malloc(sizeof(account_s));
+ error_code = _account_compare_old_record(account, account_id);
+ if (error_code != _ACCOUNT_ERROR_NONE) {
+ ACCOUNT_ERROR("_account_compare_old_record fail\n");
+ return error_code;
+ }
- if (account_record == NULL) {
- ACCOUNT_FATAL("malloc Failed");
- break;
- }
- ACCOUNT_MEMSET(account_record, 0x00, sizeof(account_s));
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
+ } else if( _account_db_err_code(g_hAccountDB) == SQLITE_BUSY ){
+ ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
+ }
- _account_convert_column_to_account(hstmt, account_record);
+ if (!account->user_name && !account->display_name && !account->email_address) {
+ ACCOUNT_ERROR("One field should be set among user name, display name, email address\n");
+ return _ACCOUNT_ERROR_INVALID_PARAMETER;
+ }
- account_head->account_list = g_list_append(account_head->account_list, account_record);
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- rc = _account_query_step(hstmt);
- tmp++;
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE _id = %d ", ACCOUNT_TABLE, account_id);
+
+ count = _account_get_record_count(g_hAccountDB, query);
+ if (count <= 0) {
+ ACCOUNT_DEBUG(" Account record not found, count = %d\n", count);
+ return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
}
- rc = _account_query_finalize(hstmt);
- ACCOUNT_CATCH_ERROR_P((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
+ /* transaction control required*/
+ ret_transaction = _account_begin_transaction(g_hAccountDB);
+ if( ret_transaction == _ACCOUNT_ERROR_DATABASE_BUSY ){
+ ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg(g_hAccountDB));
+ pthread_mutex_unlock(&account_mutex);
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
+ }
- GList *iter;
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "UPDATE %s SET user_name=?, email_address =?, display_name =?, "
+ "icon_path =?, source =?, package_name =? , access_token =?, domain_name =?, auth_type =?, secret =?, sync_support =?,"
+ "txt_custom0=?, txt_custom1=?, txt_custom2=?, txt_custom3=?, txt_custom4=?, "
+ "int_custom0=?, int_custom1=?, int_custom2=?, int_custom3=?, int_custom4=? WHERE _id=? ", ACCOUNT_TABLE);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- tmp = g_list_length(account_head->account_list);
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
- for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
- account_h account = NULL;
- account = (account_h)iter->data;
- account_s* testaccount = (account_s*)account;
+ ACCOUNT_RETURN_VAL((hstmt != NULL), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_svc_query_prepare() failed(%s)(%x).\n", _account_db_err_msg(g_hAccountDB), _account_end_transaction(g_hAccountDB, FALSE)));
- _account_query_capability_by_account_id(_account_get_capability_text_cb, testaccount->id, (void*)testaccount);
- _account_query_custom_by_account_id(_account_get_custom_text_cb, testaccount->id, (void*)testaccount);
+ binding_count = _account_convert_account_to_sql(account, hstmt, query);
+ _account_query_bind_int(hstmt, binding_count++, account_id);
+ rc = _account_query_step(hstmt);
+ if (rc != SQLITE_DONE) {
+ ACCOUNT_SLOGE( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
}
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
- *error_code = ACCOUNT_ERROR_NONE;
+ _INFO("update query=%s", query);
-CATCH:
- if (hstmt != NULL) {
- rc = _account_query_finalize(hstmt);
- if ( rc != ACCOUNT_ERROR_NONE ) {
- *error_code = rc;
- _ERR("finalize error");
- }
- hstmt = NULL;
+ /*update capability*/
+ error_code = _account_update_capability(account, account_id);
+ if(error_code != _ACCOUNT_ERROR_NONE && error_code!= _ACCOUNT_ERROR_RECORD_NOT_FOUND){
+ ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
+ ACCOUNT_ERROR("update capability Failed, trying to roll back(%x) !!!\n", ret_transaction);
+ return error_code;
}
- if( *error_code != ACCOUNT_ERROR_NONE && account_head ) {
- _account_glist_account_free(account_head->account_list);
- _ACCOUNT_FREE(account_head);
- account_head = NULL;
+ /* update custom */
+ error_code = _account_update_custom(account, account_id);
+ if(error_code != _ACCOUNT_ERROR_NONE && error_code!= _ACCOUNT_ERROR_RECORD_NOT_FOUND){
+ ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
+ ACCOUNT_ERROR("update capability Failed, trying to roll back(%x) !!!\n", ret_transaction);
+ return error_code;
}
- pthread_mutex_unlock(&account_mutex);
+ ret_transaction = _account_end_transaction(g_hAccountDB, TRUE);
- if (account_head)
- {
- _remove_sensitive_info_from_non_owning_account_list(pid, uid, account_head->account_list);
- GList* result = account_head->account_list;
- _ACCOUNT_FREE(account_head);
- return result;
- }
- return NULL;
+ _INFO("update end");
+ return error_code;
}
-GList* _account_query_account_by_capability_type(int pid, uid_t uid, const char* capability_type, int *error_code)
+
+static int _account_update_account_ex(account_s *account, int account_id)
{
- *error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
+ int rc = 0, binding_count =0;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
-
- ACCOUNT_RETURN_VAL((capability_type != NULL), {*error_code = ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("capability_type IS NULL"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = ACCOUNT_ERROR_DB_NOT_OPENED;},
- NULL, ("The database isn't connected."));
-
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+ int error_code = _ACCOUNT_ERROR_NONE, count=0, ret_transaction = 0;
+ account_stmt hstmt = NULL;
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id IN (SELECT account_id from %s WHERE key=?)", ACCOUNT_TABLE, CAPABILITY_TABLE);
+ if (!account->package_name) {
+ ACCOUNT_ERROR("Package name is mandetory field, it can not be NULL!!!!\n");
+ return _ACCOUNT_ERROR_INVALID_PARAMETER;
+ }
- hstmt = _account_prepare_query(query);
+ error_code = encrypt_access_token(account);
+ if (error_code != _ACCOUNT_ERROR_NONE)
+ {
+ _ERR("_encrypt_access_token error");
+ return error_code;
+ }
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
- return NULL;
+ error_code = _account_compare_old_record(account, account_id);
+ if (error_code != _ACCOUNT_ERROR_NONE) {
+ ACCOUNT_ERROR("_account_compare_old_record fail\n");
+ return error_code;
}
- int binding_count = 1;
- _account_query_bind_text(hstmt, binding_count++, capability_type);
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
- rc = _account_query_step(hstmt);
+ if (!account->user_name && !account->display_name && !account->email_address) {
+ ACCOUNT_ERROR("One field should be set among user name, display name, email address\n");
+ return _ACCOUNT_ERROR_INVALID_PARAMETER;
+ }
- account_s* account_head = NULL;
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE _id = %d ", ACCOUNT_TABLE, account_id);
- int tmp = 0;
+ count = _account_get_record_count(g_hAccountDB, query);
+ if (count <= 0) {
+ ACCOUNT_DEBUG(" Account record not found, count = %d\n", count);
+ return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ }
- account_head = (account_s*) malloc(sizeof(account_s));
- if (account_head == NULL) {
- ACCOUNT_FATAL("malloc Failed");
- if (hstmt != NULL) {
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
- hstmt = NULL;
- }
- *error_code = ACCOUNT_ERROR_OUT_OF_MEMORY;
- return NULL;
+ /* transaction control required*/
+ ret_transaction = _account_begin_transaction(g_hAccountDB);
+ if( ret_transaction == _ACCOUNT_ERROR_DATABASE_BUSY ){
+ ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg(g_hAccountDB));
+ pthread_mutex_unlock(&account_mutex);
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
}
- ACCOUNT_MEMSET(account_head, 0x00, sizeof(account_s));
- while (rc == SQLITE_ROW) {
- account_s* account_record = NULL;
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "UPDATE %s SET user_name=?, email_address =?, display_name =?, "
+ "icon_path =?, source =?, package_name =? , access_token =?, domain_name =?, auth_type =?, secret =?, sync_support =?,"
+ "txt_custom0=?, txt_custom1=?, txt_custom2=?, txt_custom3=?, txt_custom4=?, "
+ "int_custom0=?, int_custom1=?, int_custom2=?, int_custom3=?, int_custom4=? WHERE _id=? ", ACCOUNT_TABLE);
- account_record = (account_s*) malloc(sizeof(account_s));
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- if (account_record == NULL) {
- ACCOUNT_FATAL("malloc Failed");
- break;
- }
- ACCOUNT_MEMSET(account_record, 0x00, sizeof(account_s));
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
- _account_convert_column_to_account(hstmt, account_record);
+ ACCOUNT_RETURN_VAL((hstmt != NULL), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_svc_query_prepare() failed(%s)(%x).\n", _account_db_err_msg(g_hAccountDB), _account_end_transaction(g_hAccountDB, FALSE)));
- account_head->account_list = g_list_append(account_head->account_list, account_record);
+ _INFO("account_update_to_db_by_id_ex_p : before convert() : account_id[%d], user_name=%s", account->id, account->user_name);
+ binding_count = _account_convert_account_to_sql(account, hstmt, query);
+ _INFO("account_update_to_db_by_id_ex_p : after convert() : account_id[%d], user_name=%s", account->id, account->user_name);
+ _INFO("account_update_to_db_by_id_ex_p : before bind()");
+ rc = _account_query_bind_int(hstmt, binding_count++, account_id);
+ _INFO("account_update_to_db_by_id_ex_p : after bind() : ret = %d", rc);
- rc = _account_query_step(hstmt);
- tmp++;
+ rc = _account_query_step(hstmt);
+ if (rc != SQLITE_DONE) {
+ ACCOUNT_SLOGE( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
}
+ _INFO("account_update_to_db_by_id_ex_p : after query_step() : ret = %d", rc);
rc = _account_query_finalize(hstmt);
- ACCOUNT_CATCH_ERROR_P((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
+ _INFO("account_update_to_db_by_id_ex_p : after query_filnalize() : ret = %d", rc);
- GList *iter;
+ _INFO("account_update_to_db_by_id_ex_p : before update_capability()");
+ /*update capability*/
+ error_code = _account_update_capability(account, account_id);
+ if(error_code != _ACCOUNT_ERROR_NONE && error_code!= _ACCOUNT_ERROR_RECORD_NOT_FOUND){
+ ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
+ ACCOUNT_ERROR("update capability Failed, trying to roll back(%x) !!!\n", ret_transaction);
+ return error_code;
+ }
+ _INFO("account_update_to_db_by_id_ex_p : after update_capability()");
+ _INFO("account_update_to_db_by_id_ex_p : before update_custom()");
+ /* update custom */
+ error_code = _account_update_custom(account, account_id);
+ if(error_code != _ACCOUNT_ERROR_NONE && error_code!= _ACCOUNT_ERROR_RECORD_NOT_FOUND){
+ ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
+ ACCOUNT_ERROR("update capability Failed, trying to roll back(%x) !!!\n", ret_transaction);
+ return error_code;
+ }
+ _INFO("account_update_to_db_by_id_ex_p : after update_custom()");
- tmp = g_list_length(account_head->account_list);
+ ret_transaction = _account_end_transaction(g_hAccountDB, TRUE);
- for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
- account_s* testaccount = (account_s*)iter->data;
+ return error_code;
+}
- _account_query_capability_by_account_id(_account_get_capability_text_cb, testaccount->id, (void*)testaccount);
- _account_query_custom_by_account_id(_account_get_custom_text_cb, testaccount->id, (void*)testaccount);
- }
+int _account_update_to_db_by_id(int pid, uid_t uid, account_s* account, int account_id)
+{
+ ACCOUNT_RETURN_VAL((account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
+ ACCOUNT_RETURN_VAL((account_id > 0), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ int error_code = _ACCOUNT_ERROR_NONE;
+ account_s* data = (account_s*)account;
- *error_code = ACCOUNT_ERROR_NONE;
+ pthread_mutex_lock(&account_mutex);
-CATCH:
- if (hstmt != NULL)
- {
- rc = _account_query_finalize(hstmt);
- if (rc != ACCOUNT_ERROR_NONE) {
- *error_code = rc;
- _ERR("finalize error");
- }
- hstmt = NULL;
- }
+ error_code = _account_update_account(pid, uid, data, account_id);
- if( (*error_code != ACCOUNT_ERROR_NONE) && account_head ) {
- _account_glist_account_free(account_head->account_list);
- _ACCOUNT_FREE(account_head);
- account_head = NULL;
+ if(error_code != _ACCOUNT_ERROR_NONE) {
+ pthread_mutex_unlock(&account_mutex);
+ return error_code;
}
pthread_mutex_unlock(&account_mutex);
- if (account_head)
- {
- _remove_sensitive_info_from_non_owning_account_list(pid, uid, account_head->account_list);
- GList* result = account_head->account_list;
- _ACCOUNT_FREE(account_head);
- return result;
- }
- return NULL;
+ char buf[64]={0,};
+ ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", _ACCOUNT_NOTI_NAME_UPDATE, account_id);
+ _account_insert_delete_update_notification_send(buf);
+
+ return _ACCOUNT_ERROR_NONE;
}
-GList* _account_query_account_by_package_name(int pid, uid_t uid, const char* package_name, int *error_code)
+int _account_update_to_db_by_id_ex(account_s* account, int account_id)
{
- _INFO("_account_query_account_by_package_name");
+ ACCOUNT_RETURN_VAL((account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
+ ACCOUNT_RETURN_VAL((account_id > 0), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Account id is not valid"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ int error_code = _ACCOUNT_ERROR_NONE;
+ account_s* data = account;
- *error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
+ pthread_mutex_lock(&account_mutex);
- ACCOUNT_RETURN_VAL((package_name != NULL), {*error_code = ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("PACKAGE NAME IS NULL"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
+ _INFO("before update_account_ex() : account_id[%d], user_name=%s", account_id, data->user_name);
+ error_code = _account_update_account_ex(data, account_id);
+ _INFO("after update_account_ex() : account_id[%d], user_name=%s", account_id, data->user_name);
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+ if(error_code != _ACCOUNT_ERROR_NONE) {
+ pthread_mutex_unlock(&account_mutex);
+ return error_code;
+ }
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE package_name=?", ACCOUNT_TABLE);
+ pthread_mutex_unlock(&account_mutex);
- hstmt = _account_prepare_query(query);
+ char buf[64]={0,};
+ ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", _ACCOUNT_NOTI_NAME_UPDATE, account_id);
+ _account_insert_delete_update_notification_send(buf);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
- return NULL;
- }
+ return _ACCOUNT_ERROR_NONE;
+}
- int binding_count = 1;
- _account_query_bind_text(hstmt, binding_count++, package_name);
- rc = _account_query_step(hstmt);
+int _account_update_to_db_by_user_name(int pid, uid_t uid, account_s* account, const char *user_name, const char *package_name)
+{
+ ACCOUNT_RETURN_VAL((user_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
+ ACCOUNT_RETURN_VAL((package_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- account_s* account_head = NULL;
+ int error_code = _ACCOUNT_ERROR_NONE;
+ account_s *data = (account_s*)account;
- ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.(%s)\n", package_name));
+ pthread_mutex_lock(&account_mutex);
- int tmp = 0;
+ error_code = _account_update_account_by_user_name(pid, uid, data, user_name, package_name);
+
+ pthread_mutex_unlock(&account_mutex);
+
+ char buf[64]={0,};
+ ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", _ACCOUNT_NOTI_NAME_UPDATE, data->id);
+ _account_insert_delete_update_notification_send(buf);
+
+ return error_code;
+}
+
+GSList* _account_db_query_all(int pid, uid_t uid)
+{
+ //int error_code = _ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
+ GSList *account_list = NULL;
+
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, NULL, ("The database isn't connected."));
+
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s ", ACCOUNT_TABLE);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- account_head = (account_s*) malloc(sizeof(account_s));
- if (account_head == NULL) {
- ACCOUNT_FATAL("malloc Failed");
- if (hstmt != NULL) {
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
- hstmt = NULL;
- }
- *error_code = ACCOUNT_ERROR_OUT_OF_MEMORY;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
return NULL;
}
- ACCOUNT_MEMSET(account_head, 0x00, sizeof(account_s));
- while (rc == SQLITE_ROW) {
- account_s* account_record = NULL;
+ rc = _account_query_step(hstmt);
+
+ account_s *account_record = NULL;
+
+ if (rc != SQLITE_ROW)
+ {
+ _ERR("The record isn't found");
+ goto CATCH;
+ }
+ while(rc == SQLITE_ROW) {
account_record = (account_s*) malloc(sizeof(account_s));
if (account_record == NULL) {
ACCOUNT_FATAL("malloc Failed");
break;
}
- ACCOUNT_MEMSET(account_record, 0x00, sizeof(account_s));
+ ACCOUNT_MEMSET(account_record, 0x00, sizeof(account_s));
_account_convert_column_to_account(hstmt, account_record);
-
- _INFO("Adding account_list");
- account_head->account_list = g_list_append(account_head->account_list, account_record);
-
+ account_list = g_slist_append(account_list, account_record);
rc = _account_query_step(hstmt);
- tmp++;
}
rc = _account_query_finalize(hstmt);
- ACCOUNT_CATCH_ERROR_P((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, NULL, ("finalize error"));
hstmt = NULL;
- GList *iter;
-
- tmp = g_list_length(account_head->account_list);
-
- for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
- account_s* testaccount = (account_s*)iter->data;
+ GSList* iter;
- _account_query_capability_by_account_id(_account_get_capability_text_cb, testaccount->id, (void*)testaccount);
- _account_query_custom_by_account_id(_account_get_custom_text_cb, testaccount->id, (void*)testaccount);
+ for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
+ account_s *account = NULL;
+ account = (account_s*)iter->data;
+ _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, account->id, (void*)account);
+ _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, account->id, (void*)account);
}
- *error_code = ACCOUNT_ERROR_NONE;
-
CATCH:
- if (hstmt != NULL)
- {
+ if (hstmt != NULL) {
rc = _account_query_finalize(hstmt);
- if (rc != ACCOUNT_ERROR_NONE) {
- *error_code = rc;
- _ERR("finalize error");
- }
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {_account_gslist_account_free(account_list);}, NULL, ("finalize error"));
hstmt = NULL;
}
-
- pthread_mutex_unlock(&account_mutex);
-
- if( (*error_code != ACCOUNT_ERROR_NONE) && account_head ) {
- _account_glist_account_free(account_head->account_list);
- _ACCOUNT_FREE(account_head);
- account_head = NULL;
- }
-
- if ((*error_code == ACCOUNT_ERROR_NONE) && account_head != NULL)
+ if (account_list)
{
- _INFO("Returning account_list");
- _remove_sensitive_info_from_non_owning_account_list(pid, uid, account_head->account_list);
- GList* result = account_head->account_list;
- _ACCOUNT_FREE(account_head);
- return result;
+ _remove_sensitive_info_from_non_owning_account_slist(account_list, pid, uid);
}
- return NULL;
+ return account_list;
}
-int _account_delete(int pid, uid_t uid, int account_id)
+int _account_update_sync_status_by_id(uid_t uid, int account_db_id, const int sync_status)
{
- int error_code = ACCOUNT_ERROR_NONE;
+ int error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0;
- int ret_transaction = 0;
- bool is_success = FALSE;
-
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-
- int count = -1;
- /* Check requested ID to delete */
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE _id=%d", ACCOUNT_TABLE, account_id);
-
- count = _account_get_record_count(query);
+ int count =1;
- if( _account_db_err_code() == SQLITE_PERM ){
- pthread_mutex_unlock(&account_mutex);
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ ACCOUNT_RETURN_VAL((account_db_id > 0), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ if ( (sync_status < 0) || (sync_status >= _ACCOUNT_SYNC_MAX)) {
+ ACCOUNT_SLOGE("(%s)-(%d) sync_status is less than 0 or more than enum max.\n", __FUNCTION__, __LINE__);
+ return _ACCOUNT_ERROR_INVALID_PARAMETER;
}
- if (count <= 0) {
- ACCOUNT_ERROR("account id(%d) is not exist. count(%d)\n", account_id, count);
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
- }
+ pthread_mutex_lock(&account_mutex);
- /* Check permission of requested appid */
- char* current_appid = NULL;
- char *package_name = NULL;
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
- current_appid = _account_get_current_appid(pid, uid);
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where _id=%d", ACCOUNT_TABLE, account_db_id);
- error_code = _account_get_package_name_from_account_id(account_id, &package_name);
+ rc = _account_get_record_count(g_hAccountDB, query);
- if(error_code != ACCOUNT_ERROR_NONE){
- ACCOUNT_ERROR("No package name with account_id\n");
- _ACCOUNT_FREE(current_appid);
- _ACCOUNT_FREE(package_name);
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ pthread_mutex_unlock(&account_mutex);
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- ACCOUNT_DEBUG( "DELETE:account_id[%d],current_appid[%s]package_name[%s]", account_id, current_appid, package_name);
- error_code = _account_check_appid_group_with_package_name(uid, current_appid, package_name);
+ if (rc <= 0) {
+ ACCOUNT_SLOGE( "account_update_sync_status_by_id : related account item is not existed rc=%d , %s", rc, _account_db_err_msg(g_hAccountDB));
+ pthread_mutex_unlock(&account_mutex);
+ return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ }
- _ACCOUNT_FREE(current_appid);
- _ACCOUNT_FREE(package_name);
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
- if(error_code != ACCOUNT_ERROR_NONE){
- ACCOUNT_ERROR("No permission to delete\n");
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
+ ACCOUNT_SNPRINTF(query, sizeof(query), "UPDATE %s SET sync_support=? WHERE _id = %d", ACCOUNT_TABLE, account_db_id);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- /* transaction control required*/
- ret_transaction = _account_begin_transaction();
+ _account_query_bind_int(hstmt, count, sync_status);
- if( _account_db_err_code() == SQLITE_PERM ){
- pthread_mutex_unlock(&account_mutex);
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
+ rc = _account_query_step(hstmt);
- if( ret_transaction == ACCOUNT_ERROR_DATABASE_BUSY ){
- ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg());
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_DATABASE_BUSY;
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- if (ret_transaction != ACCOUNT_ERROR_NONE) {
- ACCOUNT_ERROR("account_delete:_account_begin_transaction fail %d\n", ret_transaction);
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, _ACCOUNT_ERROR_DB_FAILED,
+ ("account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB)));
+
+ rc = _account_query_finalize(hstmt);
+ if (rc != _ACCOUNT_ERROR_NONE) {
+ ACCOUNT_ERROR("_account_query_finalize error");
pthread_mutex_unlock(&account_mutex);
- return ret_transaction;
+ return rc;
}
+ char buf[64]={0,};
+ ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", _ACCOUNT_NOTI_NAME_SYNC_UPDATE, account_db_id);
+ _account_insert_delete_update_notification_send(buf);
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE account_id = %d", CAPABILITY_TABLE, account_id);
-
- hstmt = _account_prepare_query(query);
+ hstmt = NULL;
+ error_code = _ACCOUNT_ERROR_NONE;
- if( _account_db_err_code() == SQLITE_PERM ){
+CATCH:
+ if (hstmt != NULL) {
+ rc = _account_query_finalize(hstmt);
pthread_mutex_unlock(&account_mutex);
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
}
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
+ pthread_mutex_unlock(&account_mutex);
+ return error_code;
+}
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+int _account_query_account_by_account_id(int pid, uid_t uid, int account_db_id, account_s *account_record)
+{
+ _INFO("_account_query_account_by_account_id() start, account_db_id=[%d]", account_db_id);
- rc = _account_query_finalize(hstmt);
+ int error_code = _ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
+ ACCOUNT_RETURN_VAL((account_db_id > 0), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
+ ACCOUNT_RETURN_VAL(account_record != NULL, {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- ACCOUNT_MEMSET(query, 0, sizeof(query));
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE _id = %d", ACCOUNT_TABLE, account_id);
+ ACCOUNT_DEBUG("starting db operations");
- hstmt = _account_prepare_query(query);
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id = %d", ACCOUNT_TABLE, account_db_id);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
+ rc = _account_db_err_code(g_hAccountDB);
+ _INFO("after _account_prepare_query, rc=[%d]", rc);
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found. id=%d, rc=%d\n", account_id, rc));
+ if( rc == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
+ ACCOUNT_DEBUG("before _account_query_step");
+ rc = _account_query_step(hstmt);
+ ACCOUNT_DEBUG("after _account_query_step returned [%d]", rc);
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
- /* delete custom data */
- ACCOUNT_MEMSET(query, 0, sizeof(query));
+ while (rc == SQLITE_ROW) {
+ ACCOUNT_DEBUG("before _account_convert_column_to_account");
+ _account_convert_column_to_account(hstmt, account_record);
+ ACCOUNT_DEBUG("after _account_convert_column_to_account");
+ ACCOUNT_DEBUG("user_name = %s, user_txt[0] = %s, user_int[1] = %d", account_record->user_name, account_record->user_data_txt[0], account_record->user_data_int[1]);
+ rc = _account_query_step(hstmt);
+ }
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AccountId = %d", ACCOUNT_CUSTOM_TABLE, account_id);
+ ACCOUNT_DEBUG("account_record->id=[%d]", account_record->id);
- hstmt = _account_prepare_query(query);
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
+ ACCOUNT_DEBUG("before _account_query_capability_by_account_id");
+ _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, account_record->id, (void*)account_record);
+ ACCOUNT_DEBUG("after _account_query_capability_by_account_id");
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found. id=%d, rc=%d\n", account_id, rc));
+ ACCOUNT_DEBUG("before _account_query_custom_by_account_id");
+ _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, account_record->id, (void*)account_record);
+ ACCOUNT_DEBUG("after _account_query_custom_by_account_id");
- rc = _account_query_finalize(hstmt);
- ACCOUNT_CATCH_ERROR(rc == ACCOUNT_ERROR_NONE, {}, rc, ("finalize error", account_id, rc));
hstmt = NULL;
-
- is_success = TRUE;
+ error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL) {
rc = _account_query_finalize(hstmt);
- if(rc != ACCOUNT_ERROR_NONE ){
- ACCOUNT_ERROR("rc (%d)", rc);
- is_success = FALSE;
- }
-
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
}
- ret_transaction = _account_end_transaction(is_success);
-
- if (ret_transaction != ACCOUNT_ERROR_NONE) {
- ACCOUNT_ERROR("account_delete:_account_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
- } else {
- if (is_success == true) {
- char buf[64]={0,};
- ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", ACCOUNT_NOTI_NAME_DELETE, account_id);
- _account_insert_delete_update_notification_send(buf);
- }
+ if (account_record)
+ {
+ _remove_sensitive_info_from_non_owning_account(account_record, pid, uid);
}
-
pthread_mutex_unlock(&account_mutex);
-
+ ACCOUNT_DEBUG("_account_query_account_by_account_id end [%d]", error_code);
return error_code;
-
}
-static int _account_query_account_by_username_and_package(const char* username, const char* package_name, account_h *account)
+GList* _account_query_account_by_user_name(int pid, uid_t uid, const char *user_name, int *error_code)
{
- //FIXME
- //return -1;
- int error_code = ACCOUNT_ERROR_NONE;
+ *error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0;
- int binding_count = 1;
+ account_s *account_head = NULL;
+
+ if (user_name == NULL)
+ {
+ _ERR("USER NAME IS NULL");
+ *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;
+ goto CATCH;
+ }
+
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE user_name = ?", ACCOUNT_TABLE);
+
+ hstmt = _account_prepare_query(g_hAccountDB, query);
+
+ if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM)
+ {
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
+ goto CATCH;
+ }
+
+ int binding_count = 1;
+ _account_query_bind_text(hstmt, binding_count++, user_name);
+
+ rc = _account_query_step(hstmt);
+
+ if (rc != SQLITE_ROW)
+ {
+ _ERR("The record isn't found");
+ *error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ goto CATCH;
+ }
+
+ int tmp = 0;
+
+ account_head = (account_s*) malloc(sizeof(account_s));
+ if (account_head == NULL) {
+ ACCOUNT_FATAL("malloc Failed");
+ if (hstmt != NULL) {
+ rc = _account_query_finalize(hstmt);
+
+ if (rc != _ACCOUNT_ERROR_NONE)
+ {
+ _ERR("finalize error");
+ *error_code = rc;
+ goto CATCH;
+ }
+ hstmt = NULL;
+ }
+ *error_code = _ACCOUNT_ERROR_OUT_OF_MEMORY;
+ goto CATCH;
+ }
+ ACCOUNT_MEMSET(account_head, 0x00, sizeof(account_s));
+
+ while (rc == SQLITE_ROW) {
+ account_s* account_record = NULL;
+
+ account_record = (account_s*) malloc(sizeof(account_s));
+
+ if (account_record == NULL) {
+ ACCOUNT_FATAL("malloc Failed");
+ break;
+ }
+ ACCOUNT_MEMSET(account_record, 0x00, sizeof(account_s));
+
+ _account_convert_column_to_account(hstmt, account_record);
+
+ account_head->account_list = g_list_append(account_head->account_list, account_record);
+
+ rc = _account_query_step(hstmt);
+ tmp++;
+ }
+
+ rc = _account_query_finalize(hstmt);
+
+ if (rc != _ACCOUNT_ERROR_NONE)
+ {
+ _ERR("finalize error");
+ *error_code = rc;
+ goto CATCH;
+ }
- ACCOUNT_RETURN_VAL((username != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("username IS NULL"));
- ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name IS NULL"));
- ACCOUNT_RETURN_VAL((*account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ hstmt = NULL;
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+ GList *iter;
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE user_name = ? and package_name = ?", ACCOUNT_TABLE);
- hstmt = _account_prepare_query(query);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
+ tmp = g_list_length(account_head->account_list);
- _account_query_bind_text(hstmt, binding_count++, username);
- _account_query_bind_text(hstmt, binding_count++, package_name);
+ for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
+// account_h account;
+// account = (account_h)iter->data;
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ account_s *testaccount = (account_s*)iter->data;
- account_s *account_record = (account_s *)(*account);
+ _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, testaccount->id, (void*)testaccount);
+ _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, testaccount->id, (void*)testaccount);
- while (rc == SQLITE_ROW) {
- _account_convert_column_to_account(hstmt, account_record);
- rc = _account_query_step(hstmt);
}
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- _account_query_capability_by_account_id(_account_get_capability_text_cb, account_record->id, (void*)account_record);
- _account_query_custom_by_account_id(_account_get_custom_text_cb, account_record->id, (void*)account_record);
-
- hstmt = NULL;
- error_code = ACCOUNT_ERROR_NONE;
+ *error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL) {
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ if (rc != _ACCOUNT_ERROR_NONE)
+ {
+ _ERR("finalize error");
+ *error_code = rc;
+ }
hstmt = NULL;
}
pthread_mutex_unlock(&account_mutex);
- return error_code;
+ if (account_head)
+ {
+ _remove_sensitive_info_from_non_owning_account_list(account_head->account_list, pid, uid);
+ GList* result = account_head->account_list;
+ _ACCOUNT_FREE(account_head);
+ return result;
+ }
+ return NULL;
}
-int _account_create(account_h *account)
+GList*
+_account_query_account_by_capability(int pid, uid_t uid, const char* capability_type, const int capability_value, int *error_code)
{
- if (!account) {
- ACCOUNT_SLOGE("(%s)-(%d) account is NULL.\n", __FUNCTION__, __LINE__);
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
+ *error_code = _ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
- account_s *data = (account_s*)malloc(sizeof(account_s));
+ ACCOUNT_RETURN_VAL((capability_type != NULL), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("capability_type IS NULL"));
- if (data == NULL) {
- ACCOUNT_FATAL("Memory Allocation Failed");
- return ACCOUNT_ERROR_OUT_OF_MEMORY;
+ if ((capability_value < 0) || (capability_value >= _ACCOUNT_CAPABILITY_STATE_MAX)) {
+ ACCOUNT_SLOGE("(%s)-(%d) capability_value is not equal to 0 or 1.\n", __FUNCTION__, __LINE__);
+ *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;
+ return NULL;
}
- ACCOUNT_MEMSET(data, 0, sizeof(account_s));
- /*Setting account as visible by default*/
- data->secret = ACCOUNT_SECRECY_VISIBLE;
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = _ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
- /*Setting account as not supporting sync by default*/
- data->sync_support = ACCOUNT_SYNC_NOT_SUPPORT;
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
- *account = (account_h)data;
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id IN (SELECT account_id from %s WHERE key=? AND value=?)", ACCOUNT_TABLE, CAPABILITY_TABLE);
- return ACCOUNT_ERROR_NONE;
-}
+ hstmt = _account_prepare_query(g_hAccountDB, query);
-int _account_destroy(account_h account)
-{
- account_s *data = (account_s*)account;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
+ return NULL;
+ }
- ACCOUNT_RETURN_VAL((data != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account handle is null!"));
+ int binding_count = 1;
+ _account_query_bind_text(hstmt, binding_count++, capability_type);
+ _account_query_bind_int(hstmt, binding_count++, capability_value);
- _account_free_account_with_items(data);
+ rc = _account_query_step(hstmt);
- return ACCOUNT_ERROR_NONE;
-}
+ account_s* account_head = NULL;
-int _account_get_account_id(account_s* account, int *account_id)
-{
- if (!account) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
- if (!account_id) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
+ ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+ int tmp = 0;
+
+ account_head = (account_s*) malloc(sizeof(account_s));
+ if (account_head == NULL) {
+ ACCOUNT_FATAL("malloc Failed");
+ if (hstmt != NULL) {
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
+ hstmt = NULL;
+ }
+ *error_code = _ACCOUNT_ERROR_OUT_OF_MEMORY;
+ return NULL;
}
+ ACCOUNT_MEMSET(account_head, 0x00, sizeof(account_s));
- *account_id = account->id;
+ while (rc == SQLITE_ROW) {
+ account_s* account_record = NULL;
- return ACCOUNT_ERROR_NONE;
-}
+ account_record = (account_s*) malloc(sizeof(account_s));
-int _account_delete_from_db_by_user_name(int pid, uid_t uid, const char *user_name, const char *package_name)
-{
- _INFO("[%s][%s]", user_name, package_name);
+ if (account_record == NULL) {
+ ACCOUNT_FATAL("malloc Failed");
+ break;
+ }
+ ACCOUNT_MEMSET(account_record, 0x00, sizeof(account_s));
- int error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
- int ret_transaction = 0;
- bool is_success = FALSE;
- account_h account = NULL;
- int binding_count = 1;
- int account_id = -1;
+ _account_convert_column_to_account(hstmt, account_record);
- ACCOUNT_RETURN_VAL((user_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is null!"));
- ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ account_head->account_list = g_list_append(account_head->account_list, account_record);
- /* Check permission of requested appid */
- char* current_appid = NULL;
- char* package_name_temp = NULL;
+ rc = _account_query_step(hstmt);
+ tmp++;
+ }
- current_appid = _account_get_current_appid(pid, uid);
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_CATCH_ERROR_P((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
- package_name_temp = _account_get_text(package_name);
+ GList *iter;
- ACCOUNT_DEBUG( "DELETE:user_name[%s],current_appid[%s], package_name[%s]", user_name, current_appid, package_name_temp);
- error_code = _account_check_appid_group_with_package_name(uid, current_appid, package_name_temp);
+ tmp = g_list_length(account_head->account_list);
- _ACCOUNT_FREE(current_appid);
- _ACCOUNT_FREE(package_name_temp);
+ for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
+// account_h account = NULL;
+// account = (account_h)iter->data;
+ account_s* testaccount = (account_s*)iter->data;
+
+ _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, testaccount->id, (void*)testaccount);
+ _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, testaccount->id, (void*)testaccount);
- if(error_code != ACCOUNT_ERROR_NONE){
- ACCOUNT_ERROR("No permission to delete\n");
- return ACCOUNT_ERROR_PERMISSION_DENIED;
}
- rc = _account_create(&account);
- rc = _account_query_account_by_username_and_package(user_name, package_name, &account);
- _INFO("");
+ *error_code = _ACCOUNT_ERROR_NONE;
+
+CATCH:
+ if (hstmt != NULL) {
+ rc = _account_query_finalize(hstmt);
+ if ( rc != _ACCOUNT_ERROR_NONE ) {
+ *error_code = rc;
+ _ERR("finalize error");
+ }
+ hstmt = NULL;
+ }
+
+ if( *error_code != _ACCOUNT_ERROR_NONE && account_head ) {
+ _account_glist_account_free(account_head->account_list);
+ _ACCOUNT_FREE(account_head);
+ account_head = NULL;
+ }
- if( _account_db_err_code() == SQLITE_PERM )
+ pthread_mutex_unlock(&account_mutex);
+
+ if (account_head)
{
- _account_destroy(account);
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ _remove_sensitive_info_from_non_owning_account_list(account_head->account_list, pid, uid);
+ GList* result = account_head->account_list;
+ _ACCOUNT_FREE(account_head);
+ return result;
}
+ return NULL;
+}
- _INFO("");
- account_s* account_data = (account_s*)account;
+GList* _account_query_account_by_capability_type(int pid, uid_t uid, const char* capability_type, int *error_code)
+{
+ *error_code = _ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
- rc = _account_get_account_id(account_data, &account_id);
+ ACCOUNT_RETURN_VAL((capability_type != NULL), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("capability_type IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = _ACCOUNT_ERROR_DB_NOT_OPENED;},
+ NULL, ("The database isn't connected."));
- rc = _account_destroy(account);
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
- /* transaction control required*/
- ret_transaction = _account_begin_transaction();
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id IN (SELECT account_id from %s WHERE key=?)", ACCOUNT_TABLE, CAPABILITY_TABLE);
- if( _account_db_err_code() == SQLITE_PERM )
- {
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- _INFO("");
- if( ret_transaction == ACCOUNT_ERROR_DATABASE_BUSY )
- {
- ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg());
- pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_DATABASE_BUSY;
- }
- else if (ret_transaction != ACCOUNT_ERROR_NONE) {
- ACCOUNT_ERROR("account_delete:_account_begin_transaction fail %d\n", ret_transaction);
- pthread_mutex_unlock(&account_mutex);
- return ret_transaction;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
+ return NULL;
}
- /* delete custom data */
- ACCOUNT_MEMSET(query, 0, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AccountId = ?", ACCOUNT_CUSTOM_TABLE);
+ int binding_count = 1;
+ _account_query_bind_text(hstmt, binding_count++, capability_type);
- hstmt = _account_prepare_query(query);
+ rc = _account_query_step(hstmt);
- if( _account_db_err_code() == SQLITE_PERM ){
- _account_end_transaction(FALSE);
- pthread_mutex_unlock(&account_mutex);
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
+ account_s* account_head = NULL;
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
+ ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
- _account_query_bind_int(hstmt, binding_count++, account_id);
+ int tmp = 0;
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ account_head = (account_s*) malloc(sizeof(account_s));
+ if (account_head == NULL) {
+ ACCOUNT_FATAL("malloc Failed");
+ if (hstmt != NULL) {
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
+ hstmt = NULL;
+ }
+ *error_code = _ACCOUNT_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+ ACCOUNT_MEMSET(account_head, 0x00, sizeof(account_s));
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
+ while (rc == SQLITE_ROW) {
+ account_s* account_record = NULL;
- /* delete capability */
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE user_name = ? and package_name = ?", CAPABILITY_TABLE);
+ account_record = (account_s*) malloc(sizeof(account_s));
- hstmt = _account_prepare_query(query);
+ if (account_record == NULL) {
+ ACCOUNT_FATAL("malloc Failed");
+ break;
+ }
+ ACCOUNT_MEMSET(account_record, 0x00, sizeof(account_s));
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
+ _account_convert_column_to_account(hstmt, account_record);
- binding_count = 1;
- _account_query_bind_text(hstmt, binding_count++, user_name);
- _account_query_bind_text(hstmt, binding_count++, package_name);
+ account_head->account_list = g_list_append(account_head->account_list, account_record);
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ rc = _account_query_step(hstmt);
+ tmp++;
+ }
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_CATCH_ERROR_P((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
- ACCOUNT_MEMSET(query, 0, sizeof(query));
+ GList *iter;
- _INFO("");
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE user_name = ? and package_name = ?", ACCOUNT_TABLE);
- hstmt = _account_prepare_query(query);
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
+ tmp = g_list_length(account_head->account_list);
- _INFO("");
- binding_count = 1;
- _account_query_bind_text(hstmt, binding_count++, user_name);
- _account_query_bind_text(hstmt, binding_count++, package_name);
+ for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
+ account_s* testaccount = (account_s*)iter->data;
- rc = _account_query_step(hstmt);
- 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));
+ _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, testaccount->id, (void*)testaccount);
+ _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, testaccount->id, (void*)testaccount);
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- is_success = TRUE;
+ }
- hstmt = NULL;
+ *error_code = _ACCOUNT_ERROR_NONE;
CATCH:
- if (hstmt != NULL) {
+ if (hstmt != NULL)
+ {
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ if (rc != _ACCOUNT_ERROR_NONE) {
+ *error_code = rc;
+ _ERR("finalize error");
+ }
hstmt = NULL;
}
- ret_transaction = _account_end_transaction(is_success);
+ if( (*error_code != _ACCOUNT_ERROR_NONE) && account_head ) {
+ _account_glist_account_free(account_head->account_list);
+ _ACCOUNT_FREE(account_head);
+ account_head = NULL;
+ }
+
+ pthread_mutex_unlock(&account_mutex);
+
+ if (account_head)
+ {
+ _remove_sensitive_info_from_non_owning_account_list(account_head->account_list, pid, uid);
+ GList* result = account_head->account_list;
+ _ACCOUNT_FREE(account_head);
+ return result;
+ }
+ return NULL;
+}
+
+GList* account_server_query_account_by_package_name(const char* package_name, int *error_code, int pid, uid_t uid)
+{
+ _INFO("account_server_query_account_by_package_name start");
+
+ GList * account_list = NULL;
+ *error_code = _ACCOUNT_ERROR_NONE;
+
+ ACCOUNT_RETURN_VAL((package_name != NULL), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("PACKAGE NAME IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = _ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
+
+ account_list = _account_query_account_by_package_name(g_hAccountDB, package_name, error_code, pid, uid);
+
+ _INFO("account_server_query_account_by_package_name end");
+ return account_list;
+}
+
+int account_server_delete_account_by_package_name(const char* package_name, bool permission, int pid, uid_t uid)
+{
+ _INFO("account_db_delete_account_by_package_name");
+
+ int error_code = _ACCOUNT_ERROR_NONE;
- if (ret_transaction != ACCOUNT_ERROR_NONE) {
- ACCOUNT_ERROR("account_svc_delete:_account_svc_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
- } else {
- if (is_success == true) {
- char buf[64]={0,};
- ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", ACCOUNT_NOTI_NAME_DELETE, account_id);
- _account_insert_delete_update_notification_send(buf);
- }
- }
+ ACCOUNT_RETURN_VAL((package_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- pthread_mutex_unlock(&account_mutex);
+ error_code = _account_delete_account_by_package_name(g_hAccountDB, package_name, permission, pid, uid);
+ _INFO("account_server_delete_account_by_package_name end");
return error_code;
}
-int _account_delete_from_db_by_package_name(int pid, uid_t uid, const char *package_name, gboolean permission)
+int _account_delete(int pid, uid_t uid, int account_id)
{
- _INFO("_account_delete_from_db_by_package_name");
- int error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
+ int error_code = _ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
- int ret_transaction = 0;
+ int rc = 0;
+ int ret_transaction = 0;
bool is_success = FALSE;
- int binding_count = 1;
- GSList *account_id_list = NULL;
- int ret = -1;
- ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- // It only needs list of ids, does not need to query sensitive info. So sending 0
- GList* account_list_temp = _account_query_account_by_package_name(getpid(), OWNER_ROOT, package_name, &ret);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ int count = -1;
+ /* Check requested ID to delete */
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE _id=%d", ACCOUNT_TABLE, account_id);
+
+ count = _account_get_record_count(g_hAccountDB, query);
+
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ pthread_mutex_unlock(&account_mutex);
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- if(ret != ACCOUNT_ERROR_NONE){
- _ERR("_account_query_account_by_package_name failed ret=[%d]", ret);
- return ret;
+ if (count <= 0) {
+ ACCOUNT_ERROR("account id(%d) is not exist. count(%d)\n", account_id, count);
+ return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
}
/* Check permission of requested appid */
- if(permission){
- char* current_appid = NULL;
- char* package_name_temp = NULL;
-
- current_appid = _account_get_current_appid(pid, uid);
-
- package_name_temp = _account_get_text(package_name);
+ char* current_appid = NULL;
+ char *package_name = NULL;
- ACCOUNT_DEBUG( "DELETE: current_appid[%s], package_name[%s]", current_appid, package_name_temp);
+ current_appid = _account_get_current_appid(pid, uid);
- error_code = _account_check_appid_group_with_package_name(uid, current_appid, package_name_temp);
+ error_code = _account_get_package_name_from_account_id(account_id, &package_name);
+ if(error_code != _ACCOUNT_ERROR_NONE){
+ ACCOUNT_ERROR("No package name with account_id\n");
_ACCOUNT_FREE(current_appid);
- _ACCOUNT_FREE(package_name_temp);
-
- if(error_code != ACCOUNT_ERROR_NONE){
- ACCOUNT_ERROR("No permission to delete\n");
- _account_glist_account_free(account_list_temp);
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
+ _ACCOUNT_FREE(package_name);
+ return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
}
+ ACCOUNT_DEBUG( "DELETE:account_id[%d],current_appid[%s]package_name[%s]", account_id, current_appid, package_name);
- GList *account_list = g_list_first(account_list_temp);
- _INFO("account_list_temp length=[%d]",g_list_length(account_list));
-
- GList* iter = NULL;
- for (iter = account_list; iter != NULL; iter = g_list_next(iter))
- {
- _INFO("iterating account_list");
- account_s *account = NULL;
- _INFO("Before iter->data");
- account = (account_s*)iter->data;
- _INFO("After iter->data");
- if (account != NULL)
- {
- char id[256] = {0, };
-
- ACCOUNT_MEMSET(id, 0, 256);
+ error_code = _account_check_appid_group_with_package_name(current_appid, package_name, uid);
- ACCOUNT_SNPRINTF(id, 256, "%d", account->id);
+ _ACCOUNT_FREE(current_appid);
+ _ACCOUNT_FREE(package_name);
- _INFO("Adding account id [%s]", id);
- account_id_list = g_slist_append(account_id_list, g_strdup(id));
- }
+ if(error_code != _ACCOUNT_ERROR_NONE){
+ ACCOUNT_ERROR("No permission to delete\n");
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- _account_glist_account_free(account_list_temp);
-
/* transaction control required*/
- ret_transaction = _account_begin_transaction();
+ ret_transaction = _account_begin_transaction(g_hAccountDB);
- if( _account_db_err_code() == SQLITE_PERM ){
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
pthread_mutex_unlock(&account_mutex);
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- if( ret_transaction == ACCOUNT_ERROR_DATABASE_BUSY ){
- ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg());
+ if( ret_transaction == _ACCOUNT_ERROR_DATABASE_BUSY ){
+ ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg(g_hAccountDB));
pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_DATABASE_BUSY;
- }else if (ret_transaction != ACCOUNT_ERROR_NONE) {
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
+ }
+
+ if (ret_transaction != _ACCOUNT_ERROR_NONE) {
ACCOUNT_ERROR("account_delete:_account_begin_transaction fail %d\n", ret_transaction);
pthread_mutex_unlock(&account_mutex);
return ret_transaction;
}
- /* delete custom table */
- ACCOUNT_MEMSET(query, 0, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppId = ?", ACCOUNT_CUSTOM_TABLE);
+ ACCOUNT_MEMSET(query, 0x00, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE account_id = %d", CAPABILITY_TABLE, account_id);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- if( _account_db_err_code() == SQLITE_PERM ){
- _account_end_transaction(FALSE);
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
pthread_mutex_unlock(&account_mutex);
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
-
- binding_count = 1;
- _account_query_bind_text(hstmt, binding_count++, package_name);
+ ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, _ACCOUNT_ERROR_DB_FAILED,
+ ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg(g_hAccountDB)));
rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
- /* delete capability table */
ACCOUNT_MEMSET(query, 0, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE package_name = ?", CAPABILITY_TABLE);
-
- hstmt = _account_prepare_query(query);
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE _id = %d", ACCOUNT_TABLE, account_id);
- binding_count = 1;
- _account_query_bind_text(hstmt, binding_count++, package_name);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
+ ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, _ACCOUNT_ERROR_DB_FAILED,
+ ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg(g_hAccountDB)));
rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found. id=%d, rc=%d\n", account_id, rc));
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
- /* delete account table */
+ /* delete custom data */
ACCOUNT_MEMSET(query, 0, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE package_name = ?", ACCOUNT_TABLE);
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AccountId = %d", ACCOUNT_CUSTOM_TABLE, account_id);
- hstmt = _account_prepare_query(query);
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- binding_count = 1;
- _account_query_bind_text(hstmt, binding_count++, package_name);
+ ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, _ACCOUNT_ERROR_DB_FAILED,
+ ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg(g_hAccountDB)));
rc = _account_query_step(hstmt);
- 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));
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found. id=%d, rc=%d\n", account_id, rc));
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- is_success = TRUE;
-
+ ACCOUNT_CATCH_ERROR(rc == _ACCOUNT_ERROR_NONE, {}, rc, ("finalize error", account_id, rc));
hstmt = NULL;
+ is_success = TRUE;
+
CATCH:
if (hstmt != NULL) {
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ if(rc != _ACCOUNT_ERROR_NONE ){
+ ACCOUNT_ERROR("rc (%d)", rc);
+ is_success = FALSE;
+ }
+
hstmt = NULL;
}
- ret_transaction = _account_end_transaction(is_success);
+ ret_transaction = _account_end_transaction(g_hAccountDB, is_success);
- if (ret_transaction != ACCOUNT_ERROR_NONE) {
+ if (ret_transaction != _ACCOUNT_ERROR_NONE) {
ACCOUNT_ERROR("account_delete:_account_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
} else {
if (is_success == true) {
- GSList* gs_iter = NULL;
- for (gs_iter = account_id_list; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
- char* p_tmpid = NULL;
- p_tmpid = (char*)gs_iter->data;
- char buf[64]={0,};
- ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%s", ACCOUNT_NOTI_NAME_DELETE, p_tmpid);
- ACCOUNT_SLOGD("%s", buf);
- _account_insert_delete_update_notification_send(buf);
- _ACCOUNT_FREE(p_tmpid);
- }
- g_slist_free(account_id_list);
+ char buf[64]={0,};
+ ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", _ACCOUNT_NOTI_NAME_DELETE, account_id);
+ _account_insert_delete_update_notification_send(buf);
}
}
pthread_mutex_unlock(&account_mutex);
- _INFO("_account_delete_from_db_by_package_name end");
return error_code;
+
}
-int _account_get_total_count_from_db(gboolean include_hidden, int *count)
+static int _account_query_account_by_username_and_package(const char* username, const char* package_name, account_s *account)
{
- if (!count) {
- ACCOUNT_SLOGE("(%s)-(%d) count is NULL.\n", __FUNCTION__, __LINE__);
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- if(!g_hAccountDB){
- ACCOUNT_ERROR("DB is not opened\n");
- return ACCOUNT_ERROR_DB_NOT_OPENED;
- }
-
- char query[1024] = {0, };
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
-
- if (include_hidden)
- {
- ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from %s", ACCOUNT_TABLE);
- }
- else
- {
- ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from %s where secret = %d", ACCOUNT_TABLE, ACCOUNT_SECRECY_VISIBLE);
- }
-
- *count = _account_get_record_count(query);
+ //FIXME
+ //return -1;
+ int error_code = _ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
+ int binding_count = 1;
- if( _account_db_err_code() == SQLITE_PERM ){
- pthread_mutex_unlock(&account_mutex);
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
+ ACCOUNT_RETURN_VAL((username != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("username IS NULL"));
+ ACCOUNT_RETURN_VAL((package_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name IS NULL"));
+ ACCOUNT_RETURN_VAL((account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- int rc = -1;
- int ncount = 0;
- account_stmt pStmt = NULL;
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
- rc = sqlite3_prepare_v2(g_hAccountDB, query, strlen(query), &pStmt, NULL);
- if (SQLITE_OK != rc) {
- ACCOUNT_SLOGE("sqlite3_prepare_v2() failed(%d, %s).", rc, _account_db_err_msg());
- sqlite3_finalize(pStmt);
- return ACCOUNT_ERROR_DB_FAILED;
- }
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE user_name = ? and package_name = ?", ACCOUNT_TABLE);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- rc = sqlite3_step(pStmt);
- if (SQLITE_ROW != rc) {
- ACCOUNT_ERROR("[ERROR] sqlite3_step() failed\n");
- sqlite3_finalize(pStmt);
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- ncount = sqlite3_column_int(pStmt, 0);
+ _account_query_bind_text(hstmt, binding_count++, username);
+ _account_query_bind_text(hstmt, binding_count++, package_name);
- *count = ncount;
+ rc = _account_query_step(hstmt);
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
- sqlite3_finalize(pStmt);
+ account_s *account_record = account;
- if (ncount < 0) {
- ACCOUNT_ERROR("[ERROR] Number of account : %d, End", ncount);
- return ACCOUNT_ERROR_DB_FAILED;
+ while (rc == SQLITE_ROW) {
+ _account_convert_column_to_account(hstmt, account_record);
+ rc = _account_query_step(hstmt);
}
- return ACCOUNT_ERROR_NONE;
-}
-
-int account_type_create(account_type_h *account_type)
-{
- if (!account_type) {
- ACCOUNT_SLOGE("(%s)-(%d) account type handle is NULL.\n", __FUNCTION__, __LINE__);
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, account_record->id, (void*)account_record);
+ _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, account_record->id, (void*)account_record);
- account_type_s *data = (account_type_s*)malloc(sizeof(account_type_s));
+ hstmt = NULL;
+ error_code = _ACCOUNT_ERROR_NONE;
- if (data == NULL) {
- ACCOUNT_ERROR("Memory Allocation Failed");
- return ACCOUNT_ERROR_OUT_OF_MEMORY;
+CATCH:
+ if (hstmt != NULL) {
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
}
- ACCOUNT_MEMSET(data, 0, sizeof(account_type_s));
-
- *account_type = (account_type_h)data;
-
- return ACCOUNT_ERROR_NONE;
-}
-
-int account_type_destroy(account_type_h account_type)
-{
- account_type_s *data = (account_type_s*)account_type;
-
- ACCOUNT_RETURN_VAL((data != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account type handle is null!"));
-
- _account_type_free_account_type_with_items(data);
-
- return ACCOUNT_ERROR_NONE;
+ pthread_mutex_unlock(&account_mutex);
+ return error_code;
}
-//app_id mandatory field
-int account_type_set_app_id(account_type_h account_type, const char *app_id)
+int _account_create(account_s **account)
{
- if (!account_type) {
- ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- if (!app_id) {
- ACCOUNT_SLOGE("(%s)-(%d) app_id is NULL.\n", __FUNCTION__, __LINE__);
- return ACCOUNT_ERROR_INVALID_PARAMETER;
+ if (!account) {
+ ACCOUNT_SLOGE("(%s)-(%d) account is NULL.\n", __FUNCTION__, __LINE__);
+ return _ACCOUNT_ERROR_INVALID_PARAMETER;
}
- account_type_s *data = (account_type_s*)account_type;
-
- _ACCOUNT_FREE(data->app_id);
- data->app_id = _account_get_text(app_id);
-
- return ACCOUNT_ERROR_NONE;
-}
+ account_s *data = (account_s*)malloc(sizeof(account_s));
-//service_provider_id mandatory field
-int account_type_set_service_provider_id(account_type_h account_type, const char *service_provider_id)
-{
- if (!account_type) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
+ if (data == NULL) {
+ ACCOUNT_FATAL("Memory Allocation Failed");
+ return _ACCOUNT_ERROR_OUT_OF_MEMORY;
}
+ ACCOUNT_MEMSET(data, 0, sizeof(account_s));
- if (!service_provider_id) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
+ /*Setting account as visible by default*/
+// data->secret = _ACCOUNT_SECRECY_VISIBLE;
- account_type_s *data = (account_type_s*)account_type;
+ /*Setting account as not supporting sync by default*/
+// data->sync_support = _ACCOUNT_SYNC_NOT_SUPPORT;
- _ACCOUNT_FREE(data->service_provider_id);
- data->service_provider_id = _account_get_text(service_provider_id);
+ *account = data;
- return ACCOUNT_ERROR_NONE;
+ return _ACCOUNT_ERROR_NONE;
}
-int account_type_set_icon_path(account_type_h account_type, const char *icon_path)
+int _account_destroy(account_s *account)
{
- if (!account_type) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
+ account_s *data = account;
- if (!icon_path) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- account_type_s *data = (account_type_s*)account_type;
+ ACCOUNT_RETURN_VAL((data != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Account handle is null!"));
- _ACCOUNT_FREE(data->icon_path);
- data->icon_path = _account_get_text(icon_path);
+ _account_free_account_with_items(data);
- return ACCOUNT_ERROR_NONE;
+ return _ACCOUNT_ERROR_NONE;
}
-int account_type_set_small_icon_path(account_type_h account_type, const char *small_icon_path)
+int _account_get_account_id(account_s* account, int *account_id)
{
- if (!account_type) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
+ if (!account) {
+ return _ACCOUNT_ERROR_INVALID_PARAMETER;
}
-
- if (!small_icon_path) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
+ if (!account_id) {
+ return _ACCOUNT_ERROR_INVALID_PARAMETER;
}
- account_type_s *data = (account_type_s*)account_type;
-
- _ACCOUNT_FREE(data->small_icon_path);
- data->small_icon_path = _account_get_text(small_icon_path);
-
- return ACCOUNT_ERROR_NONE;
-}
-
-int account_type_set_multiple_account_support(account_type_h account_type, const bool multiple_account_support)
-{
- ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("(%s)-(%d) account handle is NULL.\n", __FUNCTION__, __LINE__));
-
- account_type_s *data = (account_type_s*)account_type;
-
- data->multiple_account_support = multiple_account_support;
+ *account_id = account->id;
- return ACCOUNT_ERROR_NONE;
+ return _ACCOUNT_ERROR_NONE;
}
-// unset?
-int account_type_set_label(account_type_h account_type, const char* label, const char* locale)
+int _account_delete_from_db_by_user_name(int pid, uid_t uid, const char *user_name, const char *package_name)
{
- if (!account_type) {
- ACCOUNT_SLOGE("(%s)-(%d) account_type handle is NULL.\n", __FUNCTION__, __LINE__);
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- if(!label || !locale) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- account_type_s *data = (account_type_s*)account_type;
- label_s *label_data = (label_s*)malloc(sizeof(label_s));
-
- if (label_data == NULL) {
- return ACCOUNT_ERROR_OUT_OF_MEMORY;
- }
- ACCOUNT_MEMSET(label_data, 0, sizeof(label_s));
-
- label_data->label = _account_get_text(label);
- label_data->locale = _account_get_text(locale);
+ _INFO("[%s][%s]", user_name, package_name);
- data->label_list = g_slist_append(data->label_list, (gpointer)label_data);
+ int error_code = _ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
+ int ret_transaction = 0;
+ bool is_success = FALSE;
+ account_s *account = NULL;
+ int binding_count = 1;
+ int account_id = -1;
- return ACCOUNT_ERROR_NONE;
-}
+ ACCOUNT_RETURN_VAL((user_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is null!"));
+ ACCOUNT_RETURN_VAL((package_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-int account_type_get_app_id(account_type_h account_type, char **app_id)
-{
- if (!account_type) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
+ /* Check permission of requested appid */
+ char* current_appid = NULL;
+ char* package_name_temp = NULL;
- if (!app_id) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
+ current_appid = _account_get_current_appid(pid, uid);
- account_type_s *data = (account_type_s*)account_type;
+ package_name_temp = _account_dup_text(package_name);
- (*app_id) = NULL;
- *app_id = _account_get_text(data->app_id);
+ ACCOUNT_DEBUG( "DELETE:user_name[%s],current_appid[%s], package_name[%s]", user_name, current_appid, package_name_temp);
- return ACCOUNT_ERROR_NONE;
-}
+ error_code = _account_check_appid_group_with_package_name(current_appid, package_name_temp, uid);
-int account_type_get_service_provider_id(account_type_h account_type, char **service_provider_id)
-{
- if (!account_type) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
+ _ACCOUNT_FREE(current_appid);
+ _ACCOUNT_FREE(package_name_temp);
- if (!service_provider_id) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
+ if(error_code != _ACCOUNT_ERROR_NONE){
+ ACCOUNT_ERROR("No permission to delete\n");
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- account_type_s *data = (account_type_s*)account_type;
-
- (*service_provider_id) = NULL;
- *service_provider_id = _account_get_text(data->service_provider_id);
-
- return ACCOUNT_ERROR_NONE;
-}
+ rc = _account_create(&account);
+ rc = _account_query_account_by_username_and_package(user_name, package_name, account);
-int account_type_get_icon_path(account_type_h account_type, char **icon_path)
-{
- if (!account_type) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
+ _INFO("");
- if (!icon_path) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM )
+ {
+ _account_destroy(account);
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- account_type_s *data = (account_type_s*)account_type;
+ _INFO("");
+ account_s* account_data = (account_s*)account;
- (*icon_path) = NULL;
- *icon_path = _account_get_text(data->icon_path);
+ rc = _account_get_account_id(account_data, &account_id);
- return ACCOUNT_ERROR_NONE;
-}
+ rc = _account_destroy(account);
-int account_type_get_small_icon_path(account_type_h account_type, char **small_icon_path)
-{
- if (!account_type) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
+ /* transaction control required*/
+ ret_transaction = _account_begin_transaction(g_hAccountDB);
- if (!small_icon_path) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM )
+ {
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ pthread_mutex_unlock(&account_mutex);
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- account_type_s *data = (account_type_s*)account_type;
-
- (*small_icon_path) = NULL;
- *small_icon_path = _account_get_text(data->small_icon_path);
-
- return ACCOUNT_ERROR_NONE;
-}
-
-int account_type_get_multiple_account_support(account_type_h account_type, int *multiple_account_support)
-{
- if (!account_type) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
+ _INFO("");
+ if( ret_transaction == _ACCOUNT_ERROR_DATABASE_BUSY )
+ {
+ ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg(g_hAccountDB));
+ pthread_mutex_unlock(&account_mutex);
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
}
- if (!multiple_account_support) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
+ else if (ret_transaction != _ACCOUNT_ERROR_NONE) {
+ ACCOUNT_ERROR("account_delete:_account_begin_transaction fail %d\n", ret_transaction);
+ pthread_mutex_unlock(&account_mutex);
+ return ret_transaction;
}
- account_type_s *data = (account_type_s*)account_type;
-
- *multiple_account_support = data->multiple_account_support;
-
- return ACCOUNT_ERROR_NONE;
-}
-
-int account_type_get_label_by_locale(account_type_h account_type, const char* locale, char** label)
-{
- ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
- ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("INVALID PARAMETER"));
-
- GSList *iter;
- account_type_s *data = (account_type_s*)account_type;
-
- for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
- label_s *label_data = NULL;
-
- label_data = (label_s*)iter->data;
+ /* delete custom data */
+ ACCOUNT_MEMSET(query, 0, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AccountId = ?", ACCOUNT_CUSTOM_TABLE);
- *label = NULL;
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- if(!strcmp(locale, label_data->locale)) {
- *label = _account_get_text(label_data->label);
- return ACCOUNT_ERROR_NONE;
- }
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ _account_end_transaction(g_hAccountDB, FALSE);
+ pthread_mutex_unlock(&account_mutex);
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
-}
-
-int account_type_get_label(account_type_h account_type, account_label_cb callback, void *user_data)
-{
- ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
- ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
+ ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, _ACCOUNT_ERROR_DB_FAILED,
+ ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg(g_hAccountDB)));
- GSList *iter;
- account_type_s *data = (account_type_s*)account_type;
+ _account_query_bind_int(hstmt, binding_count++, account_id);
- for (iter = data->label_list; iter != NULL; iter = g_slist_next(iter)) {
- label_s *label_data = NULL;
+ rc = _account_query_step(hstmt);
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
- label_data = (label_s*)iter->data;
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
- if(callback(label_data->app_id, label_data->label, label_data->locale, user_data)!=TRUE) {
- ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
- return ACCOUNT_ERROR_NONE;
- }
- }
+ /* delete capability */
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE user_name = ? and package_name = ?", CAPABILITY_TABLE);
- return ACCOUNT_ERROR_NONE;
-}
+ hstmt = _account_prepare_query(g_hAccountDB, query);
-static gboolean _account_type_check_duplicated(account_type_s *data)
-{
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int count = 0;
+ ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, _ACCOUNT_ERROR_DB_FAILED,
+ ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg(g_hAccountDB)));
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
+ binding_count = 1;
+ _account_query_bind_text(hstmt, binding_count++, user_name);
+ _account_query_bind_text(hstmt, binding_count++, package_name);
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE AppId='%s'"
- , ACCOUNT_TYPE_TABLE, data->app_id);
+ rc = _account_query_step(hstmt);
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
- count = _account_get_record_count(query);
- if (count > 0) {
- return TRUE;
- }
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
- return FALSE;
-}
+ ACCOUNT_MEMSET(query, 0, sizeof(query));
-static int _account_type_convert_account_to_sql(account_type_s *account_type, account_stmt hstmt, char *sql_value)
-{
_INFO("");
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE user_name = ? and package_name = ?", ACCOUNT_TABLE);
- int count = 1;
+ hstmt = _account_prepare_query(g_hAccountDB, query);
+ ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, _ACCOUNT_ERROR_DB_FAILED,
+ ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg(g_hAccountDB)));
- /*Caution : Keep insert query orders.*/
+ _INFO("");
+ binding_count = 1;
+ _account_query_bind_text(hstmt, binding_count++, user_name);
+ _account_query_bind_text(hstmt, binding_count++, package_name);
- /* 1. app id*/
- _account_query_bind_text(hstmt, count++, (char*)account_type->app_id);
+ rc = _account_query_step(hstmt);
+ 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));
- /* 2. service provider id*/
- _account_query_bind_text(hstmt, count++, (char*)account_type->service_provider_id);
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ is_success = TRUE;
- /* 3. icon path*/
- _account_query_bind_text(hstmt, count++, (char*)account_type->icon_path);
+ hstmt = NULL;
- /* 4. small icon path*/
- _account_query_bind_text(hstmt, count++, (char*)account_type->small_icon_path);
+CATCH:
+ if (hstmt != NULL) {
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
+ }
- /* 5. multiple accont support*/
- _account_query_bind_int(hstmt, count++, account_type->multiple_account_support);
+ ret_transaction = _account_end_transaction(g_hAccountDB, is_success);
- _INFO("");
+ if (ret_transaction != _ACCOUNT_ERROR_NONE) {
+ ACCOUNT_ERROR("account_svc_delete:_account_svc_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
+ } else {
+ if (is_success == true) {
+ char buf[64]={0,};
+ ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", _ACCOUNT_NOTI_NAME_DELETE, account_id);
+ _account_insert_delete_update_notification_send(buf);
+ }
+ }
+
+ pthread_mutex_unlock(&account_mutex);
- return count;
+ return error_code;
}
-static int _account_type_execute_insert_query(account_type_s *account_type)
+int _account_get_total_count_from_db(gboolean include_hidden, int *count)
{
- _INFO("");
-
- int rc = 0;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
+ if (!count) {
+ ACCOUNT_SLOGE("(%s)-(%d) count is NULL.\n", __FUNCTION__, __LINE__);
+ return _ACCOUNT_ERROR_INVALID_PARAMETER;
+ }
- /* check mandatory field */
- // app id & service provider id
- if (!account_type->app_id) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
+ if(!g_hAccountDB){
+ ACCOUNT_ERROR("DB is not opened\n");
+ return _ACCOUNT_ERROR_DB_NOT_OPENED;
}
+ char query[1024] = {0, };
ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s( AppId, ServiceProviderId , IconPath , SmallIconPath , MultipleAccountSupport ) values "
- "(?, ?, ?, ?, ?)", ACCOUNT_TYPE_TABLE);
-
- _INFO("");
- hstmt = _account_prepare_query(query);
- _INFO("");
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- } else if( _account_db_err_code() == SQLITE_BUSY ){
- ACCOUNT_ERROR( "Database Busy(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_DATABASE_BUSY;
+ if (include_hidden)
+ {
+ ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from %s", ACCOUNT_TABLE);
}
-
- ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
-
- _INFO("");
- _account_type_convert_account_to_sql(account_type, hstmt, query);
- _INFO("");
-
- rc = _account_query_step(hstmt);
- if (rc == SQLITE_BUSY) {
- ACCOUNT_ERROR( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- error_code = ACCOUNT_ERROR_DATABASE_BUSY;
- } else if (rc != SQLITE_DONE) {
- ACCOUNT_ERROR( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- error_code = ACCOUNT_ERROR_DB_FAILED;
+ else
+ {
+ ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from %s where secret = %d", ACCOUNT_TABLE, _ACCOUNT_SECRECY_VISIBLE);
}
- _INFO("");
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
+ *count = _account_get_record_count(g_hAccountDB, query);
- _INFO("");
- return error_code;
-}
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ pthread_mutex_unlock(&account_mutex);
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
-static int _account_type_insert_label(account_type_s *account_type)
-{
- int rc, count = 1;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- account_stmt hstmt = NULL;
+ int rc = -1;
+ int ncount = 0;
+ account_stmt pStmt = NULL;
- ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
+ rc = sqlite3_prepare_v2(g_hAccountDB, query, strlen(query), &pStmt, NULL);
+ if (SQLITE_OK != rc) {
+ ACCOUNT_SLOGE("sqlite3_prepare_v2() failed(%d, %s).", rc, _account_db_err_msg(g_hAccountDB));
+ sqlite3_finalize(pStmt);
+ return _ACCOUNT_ERROR_DB_FAILED;
+ }
- if (g_slist_length( account_type->label_list)==0) {
- ACCOUNT_ERROR( "_account_type_insert_label, no label\n");
- return ACCOUNT_ERROR_NONE;
+ rc = sqlite3_step(pStmt);
+ if (SQLITE_ROW != rc) {
+ ACCOUNT_ERROR("[ERROR] sqlite3_step() failed\n");
+ sqlite3_finalize(pStmt);
+ return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
}
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where AppId = '%s'", ACCOUNT_TYPE_TABLE, account_type->app_id);
+ ncount = sqlite3_column_int(pStmt, 0);
- rc = _account_get_record_count(query);
+ *count = ncount;
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
+ sqlite3_finalize(pStmt);
- if (rc <= 0) {
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ if (ncount < 0) {
+ ACCOUNT_ERROR("[ERROR] Number of account : %d, End", ncount);
+ return _ACCOUNT_ERROR_DB_FAILED;
}
- /* insert query*/
- GSList *iter;
-
- for (iter = account_type->label_list; iter != NULL; iter = g_slist_next(iter)) {
- int ret;
- count = 1;
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(AppId, Label, Locale) VALUES "
- "(?, ?, ?) ", LABEL_TABLE);
-
- hstmt = _account_prepare_query(query);
+ return _ACCOUNT_ERROR_NONE;
+}
- ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
- label_s* label_data = NULL;
- label_data = (label_s*)iter->data;
+int account_server_query_app_id_exist(const char* app_id)
+{
+ _INFO("account_server_query_app_id_exist start app_id=[%s]", app_id);
+ int ret = _ACCOUNT_ERROR_NONE;
- ret = _account_query_bind_text(hstmt, count++, account_type->app_id);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
- ret = _account_query_bind_text(hstmt, count++, label_data->label);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
- ret = _account_query_bind_text(hstmt, count++, (char*)label_data->locale);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ret = _account_type_query_app_id_exist_from_all_db(g_hAccountDB, g_hAccountGlobalDB, app_id);
- rc = _account_query_step(hstmt);
+ _INFO("account_server_query_app_id_exist end error_code=[%d]", ret);
+ return ret;
+}
- if (rc != SQLITE_DONE) {
- ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- break;
- }
+int account_server_insert_account_type_to_user_db(account_type_s *account_type, int *account_type_id, uid_t uid)
+{
+ ACCOUNT_RETURN_VAL((account_type != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE HANDLE IS NULL"));
+ ACCOUNT_RETURN_VAL((account_type->app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID OF ACCOUNT TYPE IS NULL"));
+ ACCOUNT_RETURN_VAL((account_type_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE ID IS NULL"));
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
+ _INFO("account_server_insert_account_type_to_user_db start uid=[%d]", uid);
+ int ret = _ACCOUNT_ERROR_NONE;
+ if (_account_type_check_duplicated(g_hAccountDB, account_type->app_id) ||
+ _account_type_check_duplicated(g_hAccountGlobalDB, account_type->app_id)) {
+ *account_type_id = -1;
+ return _ACCOUNT_ERROR_DUPLICATED;
}
- return ACCOUNT_ERROR_NONE;
+ ret = _account_type_insert_to_db(g_hAccountDB, account_type, account_type_id);
+ _INFO("account_server_insert_account_type_to_user_db end error_code=[%d]", ret);
+ return ret;
}
-static void _account_type_convert_column_to_provider_feature(account_stmt hstmt, provider_feature_s *feature_record)
+int account_server_delete_account_type_by_app_id_from_user_db(const char * app_id)
{
- const char *textbuf = NULL;
+ ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID OF ACCOUNT TYPE IS NULL"));
- textbuf = _account_query_table_column_text(hstmt, PROVIDER_FEATURE_FIELD_APP_ID);
- _account_db_data_to_text(textbuf, &(feature_record->app_id));
-
- textbuf = _account_query_table_column_text(hstmt, PROVIDER_FEATURE_FIELD_KEY);
- _account_db_data_to_text(textbuf, &(feature_record->key));
+ _INFO("account_server_delete_account_type_by_app_id_from_user_db start");
+ int ret = _ACCOUNT_ERROR_NONE;
+ ret = _account_type_delete_by_app_id(g_hAccountDB, app_id);
+ _INFO("account_server_delete_account_type_by_app_id_from_user_db end error_code=[%d]", ret);
+ return ret;
}
GSList* _account_type_query_provider_feature_by_app_id_from_global_db(const char* app_id, int *error_code)
int rc = 0, binding_count = 1;
GSList* feature_list = NULL;
- ACCOUNT_RETURN_VAL((app_id != NULL), {*error_code = ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((app_id != NULL), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("APP ID IS NULL"));
ACCOUNT_RETURN_VAL((error_code != NULL), {_ERR("error_code pointer is NULL");}, NULL, (""));
- ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {*error_code = ACCOUNT_ERROR_INVALID_PARAMETER; _ERR("The database isn't connected.");}, NULL, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER; _ERR("The database isn't connected.");}, NULL, ("The database isn't connected."));
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE app_id = ?", PROVIDER_FEATURE_TABLE);
_INFO("account query=[%s]", query);
- hstmt = _account_prepare_query_from_global_db(query);
+ hstmt = _account_prepare_query(g_hAccountGlobalDB, query);
- if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
return NULL;
}
rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {*error_code = ACCOUNT_ERROR_RECORD_NOT_FOUND; _ERR("The record isn't found from global db. rc=[%d]", rc);}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {*error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND; _ERR("The record isn't found from global db. rc=[%d]", rc);}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
provider_feature_s* feature_record = NULL;
rc = _account_query_step(hstmt);
}
- *error_code = ACCOUNT_ERROR_NONE;
+ *error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL) {
- rc = _account_query_finalize_from_global_db(hstmt);
- if (rc != ACCOUNT_ERROR_NONE) {
+ rc = _account_query_finalize(hstmt);
+ if (rc != _ACCOUNT_ERROR_NONE) {
*error_code = rc;
_ERR("global db fianlize error");
}
}
- if (*error_code != ACCOUNT_ERROR_NONE) {
+ if (*error_code != _ACCOUNT_ERROR_NONE) {
_account_type_gslist_feature_free(feature_list);
}
int rc = 0, binding_count = 1;
GSList* feature_list = NULL;
- ACCOUNT_RETURN_VAL((app_id != NULL), {*error_code = ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((app_id != NULL), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("APP ID IS NULL"));
ACCOUNT_RETURN_VAL((error_code != NULL), {_ERR("error_code pointer is NULL");}, NULL, (""));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = _ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE app_id = ?", PROVIDER_FEATURE_TABLE);
_INFO("account query=[%s]", query);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
return NULL;
}
rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {*error_code = ACCOUNT_ERROR_RECORD_NOT_FOUND; _ERR("The record isn't found from user db. rc=[%d]", rc);}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {*error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND; _ERR("The record isn't found from user db. rc=[%d]", rc);}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
provider_feature_s* feature_record = NULL;
rc = _account_query_step(hstmt);
}
- *error_code = ACCOUNT_ERROR_NONE;
+ *error_code = _ACCOUNT_ERROR_NONE;
rc = _account_query_finalize(hstmt);
- ACCOUNT_CATCH_ERROR_P((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, rc, ("account finalize error"));
+ ACCOUNT_CATCH_ERROR_P((rc == _ACCOUNT_ERROR_NONE), {*error_code = rc;}, rc, ("account finalize error"));
hstmt = NULL;
CATCH:
if (hstmt != NULL) {
rc = _account_query_finalize(hstmt);
- if (rc != ACCOUNT_ERROR_NONE) {
+ if (rc != _ACCOUNT_ERROR_NONE) {
*error_code = rc;
_ERR("account fianlize error");
}
}
_INFO("*error_code=[%d]", *error_code);
- if (*error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+ if (*error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
feature_list = _account_type_query_provider_feature_by_app_id_from_global_db(app_id, error_code);
}
- if (*error_code != ACCOUNT_ERROR_NONE)
+ if (*error_code != _ACCOUNT_ERROR_NONE)
_account_type_gslist_feature_free(feature_list);
_INFO("Returning account feature_list");
return feature_list;
}
-int _account_type_query_provider_feature_cb_by_app_id_from_global_db(provider_feature_cb callback, const char* app_id, void *user_data )
+int _account_type_query_provider_feature_cb_by_app_id_from_global_db(account_type_provider_feature_cb callback, const char* app_id, void *user_data )
{
- int error_code = ACCOUNT_ERROR_NONE;
+ int error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0, binding_count = 1;
_INFO("_account_type_query_provider_feature_cb_by_app_id_in_global_db start app_id=%s", app_id);
- ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
- ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
- ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((callback != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
+ ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE app_id = ?", PROVIDER_FEATURE_TABLE);
- hstmt = _account_prepare_query_from_global_db(query);
+ hstmt = _account_prepare_query(g_hAccountGlobalDB, query);
- if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_from_global_db());
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_PERMISSION_DENIED, ("global db permission denied.\n"));
+ if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_PERMISSION_DENIED, ("global db permission denied.\n"));
}
_account_query_bind_text(hstmt, binding_count++, app_id);
rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {_ERR("The record isn't found. rc=[%d]", rc);}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {_ERR("The record isn't found. rc=[%d]", rc);}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
provider_feature_s* feature_record = NULL;
_account_type_free_feature_with_items(feature_record);
- ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, ACCOUNT_ERROR_NONE, ("Callback func returns FALSE, its iteration is stopped!!!!\n"));
+ ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, _ACCOUNT_ERROR_NONE, ("Callback func returns FALSE, its iteration is stopped!!!!\n"));
rc = _account_query_step(hstmt);
}
- error_code = ACCOUNT_ERROR_NONE;
+ error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL) {
- rc = _account_query_finalize_from_global_db(hstmt);
- if (rc != ACCOUNT_ERROR_NONE) {
+ rc = _account_query_finalize(hstmt);
+ if (rc != _ACCOUNT_ERROR_NONE) {
error_code = rc;
_ERR("global db finalize error[%d]", rc);
}
return error_code;
}
-int _account_type_query_provider_feature_cb_by_app_id(provider_feature_cb callback, const char* app_id, void *user_data )
+int _account_type_query_provider_feature_cb_by_app_id(account_type_provider_feature_cb callback, const char* app_id, void *user_data )
{
- int error_code = ACCOUNT_ERROR_NONE;
+ int error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0, binding_count = 1;
_INFO("_account_type_query_provider_feature_cb_by_app_id start app_id=%s", app_id);
- ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
- ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((callback != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE app_id = ?", PROVIDER_FEATURE_TABLE);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
_account_query_bind_text(hstmt, binding_count++, app_id);
rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found in user db.\n"));
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found in user db.\n"));
provider_feature_s* feature_record = NULL;
_account_type_free_feature_with_items(feature_record);
- ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, ACCOUNT_ERROR_NONE, ("Callback func returs FALSE, its iteration is stopped!!!!\n"));
+ ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, _ACCOUNT_ERROR_NONE, ("Callback func returs FALSE, its iteration is stopped!!!!\n"));
rc = _account_query_step(hstmt);
}
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
- error_code = ACCOUNT_ERROR_NONE;
+ error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL) {
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
}
/*
- if (error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+ if (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
error_code = _account_type_query_provider_feature_cb_by_app_id_from_global_db(callback, app_id, user_data);
}
*/
return error_code;
}
-int account_type_query_provider_feature_cb_by_app_id(provider_feature_cb callback, const char* app_id, void *user_data )
-{
- int error_code = ACCOUNT_ERROR_NONE;
-
- ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
- ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-
- error_code = _account_type_query_provider_feature_cb_by_app_id(callback, app_id, user_data);
-
- if (error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
- error_code = _account_type_query_provider_feature_cb_by_app_id_from_global_db(callback, app_id, user_data);
- }
-
- return error_code;
-}
-
-bool _account_type_query_supported_feature_from_global_db(const char* app_id, const char* capability, int *error_code)
-{
- _INFO("_account_type_query_supported_feature_in_global_db start");
- ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-
- *error_code = ACCOUNT_ERROR_NONE;
-
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int record_count = 0;
-
- if (app_id == NULL || capability == NULL)
- {
- *error_code = ACCOUNT_ERROR_INVALID_PARAMETER;
- return false;
- }
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s where app_id='%s' and key='%s'", PROVIDER_FEATURE_TABLE, app_id, capability);
-
- record_count = _account_get_record_count_from_global_db(query);
-
- if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_from_global_db());
- *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- if (record_count <= 0)
- {
- *error_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
- return false;
- }
-
- _INFO("_account_type_query_supported_feature_in_global_db end");
- return true;
-}
-
-bool _account_type_query_supported_feature(const char* app_id, const char* capability, int *error_code)
-{
- _INFO("_account_type_query_supported_feature start");
-
- *error_code = ACCOUNT_ERROR_NONE;
-
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int record_count = 0;
-
- if (app_id == NULL || capability == NULL)
- {
- *error_code = ACCOUNT_ERROR_INVALID_PARAMETER;
- return false;
- }
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s where app_id='%s' and key='%s'", PROVIDER_FEATURE_TABLE, app_id, capability);
-
- record_count = _account_get_record_count(query);
-
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
- return false;
- }
-
- if (record_count <= 0)
- {
- bool is_exist = false;
- is_exist = _account_type_query_supported_feature_from_global_db(app_id, capability, error_code);
- if (!is_exist)
- return false;
- }
-
- _INFO("_account_type_query_supported_feature end");
- return true;
-}
-
-static int _account_type_insert_provider_feature(account_type_s *account_type, const char* app_id)
+int account_type_query_provider_feature_cb_by_app_id(account_type_provider_feature_cb callback, const char* app_id, void *user_data )
{
- int rc, count = 1;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- account_stmt hstmt = NULL;
-
- ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
- ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
-
- if (g_slist_length( account_type->provider_feature_list)==0) {
- ACCOUNT_ERROR( "no capability\n");
- return ACCOUNT_ERROR_NONE;
- }
+ int error_code = _ACCOUNT_ERROR_NONE;
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where AppId='%s'", ACCOUNT_TYPE_TABLE, app_id);
+ ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((callback != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- rc = _account_get_record_count(query);
-
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- if (rc <= 0) {
- ACCOUNT_SLOGI( "related account type item is not existed rc=%d , %s", rc, _account_db_err_msg());
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
- }
-
- /* insert query*/
-
- GSList *iter;
-
- for (iter = account_type->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
- int ret;
- count = 1;
- ACCOUNT_MEMSET(query, 0x00, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(app_id, key) VALUES "
- "(?, ?) ", PROVIDER_FEATURE_TABLE);
-
- hstmt = _account_prepare_query(query);
-
- ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
-
- provider_feature_s* feature_data = NULL;
- feature_data = (provider_feature_s*)iter->data;
-
- ret = _account_query_bind_text(hstmt, count++, app_id);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
- ret = _account_query_bind_text(hstmt, count++, feature_data->key);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Integer binding fail"));
-
- rc = _account_query_step(hstmt);
-
- if (rc != SQLITE_DONE) {
- ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- break;
- }
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
+ error_code = _account_type_query_provider_feature_cb_by_app_id(callback, app_id, user_data);
+ if (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+ error_code = _account_type_query_provider_feature_cb_by_app_id_from_global_db(callback, app_id, user_data);
}
- return ACCOUNT_ERROR_NONE;
+ return error_code;
}
-int _account_type_insert_to_db(account_type_s* account_type, int* account_type_id)
+bool _account_type_query_supported_feature_from_global_db(const char* app_id, const char* capability, int *error_code)
{
- _INFO("");
-
- int error_code = ACCOUNT_ERROR_NONE, ret_transaction = 0;
-
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE HANDLE IS NULL"));
- ACCOUNT_RETURN_VAL((account_type_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT TYPE ID POINTER IS NULL"));
+ _INFO("_account_type_query_supported_feature_in_global_db start");
+ ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- account_type_s *data = (account_type_s*)account_type;
+ *error_code = _ACCOUNT_ERROR_NONE;
- pthread_mutex_lock(&account_mutex);
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int record_count = 0;
+ if (app_id == NULL || capability == NULL)
+ {
+ *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;
+ return false;
+ }
- /* transaction control required*/
- ret_transaction = _account_begin_transaction();
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s where app_id='%s' and key='%s'", PROVIDER_FEATURE_TABLE, app_id, capability);
- _INFO("");
+ record_count = _account_get_record_count(g_hAccountGlobalDB, query);
- if( _account_db_err_code() == SQLITE_PERM ){
- pthread_mutex_unlock(&account_mutex);
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
+ *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- _INFO("");
- if( ret_transaction == ACCOUNT_ERROR_DATABASE_BUSY ){
- ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg());
- pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_DATABASE_BUSY;
- } else if (ret_transaction != ACCOUNT_ERROR_NONE) {
- ACCOUNT_ERROR("_account_begin_transaction fail %d\n", ret_transaction);
- pthread_mutex_unlock(&account_mutex);
- return ret_transaction;
+ if (record_count <= 0)
+ {
+ *error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ return false;
}
- _INFO("");
- if (_account_type_check_duplicated(data)) {
- _INFO("");
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR("Duplicated, rollback insert query(%x)!!!!\n", ret_transaction);
- *account_type_id = -1;
- pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_DUPLICATED;
- } else {
- _INFO("");
- *account_type_id = _account_get_next_sequence(ACCOUNT_TYPE_TABLE);
+ _INFO("_account_type_query_supported_feature_in_global_db end");
+ return true;
+}
- error_code = _account_type_execute_insert_query(data);
+bool _account_type_query_supported_feature(const char* app_id, const char* capability, int *error_code)
+{
+ _INFO("_account_type_query_supported_feature start");
- if (error_code != ACCOUNT_ERROR_NONE){
- error_code = ACCOUNT_ERROR_DUPLICATED;
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR("Insert fail, rollback insert query(%x)!!!!\n", ret_transaction);
- *account_type_id = -1;
- pthread_mutex_unlock(&account_mutex);
- return error_code;
- }
- }
+ *error_code = _ACCOUNT_ERROR_NONE;
- _INFO("");
- error_code = _account_type_insert_provider_feature(data, data->app_id);
- if(error_code != ACCOUNT_ERROR_NONE) {
- _INFO("");
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR("Insert provider feature fail(%x), rollback insert query(%x)!!!!\n", error_code, ret_transaction);
- pthread_mutex_unlock(&account_mutex);
- return error_code;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int record_count = 0;
+
+ if (app_id == NULL || capability == NULL)
+ {
+ *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;
+ return false;
}
- _INFO("");
- error_code = _account_type_insert_label(data);
- if(error_code != ACCOUNT_ERROR_NONE) {
- _INFO("");
- ret_transaction = _account_end_transaction(FALSE);
- ACCOUNT_ERROR("Insert label fail(%x), rollback insert query(%x)!!!!\n", error_code, ret_transaction);
- pthread_mutex_unlock(&account_mutex);
- return error_code;
+
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s where app_id='%s' and key='%s'", PROVIDER_FEATURE_TABLE, app_id, capability);
+
+ record_count = _account_get_record_count(g_hAccountDB, query);
+
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
+ return false;
}
- ret_transaction = _account_end_transaction(TRUE);
- _INFO("");
- pthread_mutex_unlock(&account_mutex);
+ if (record_count <= 0)
+ {
+ bool is_exist = false;
+ is_exist = _account_type_query_supported_feature_from_global_db(app_id, capability, error_code);
+ if (!is_exist)
+ return false;
+ }
- _INFO("");
- return ACCOUNT_ERROR_NONE;
+ _INFO("_account_type_query_supported_feature end");
+ return true;
}
-static int _account_type_update_provider_feature(account_type_s *account_type, const char* app_id)
+
+static int _account_type_update_provider_feature(sqlite3 *account_db_handle, account_type_s *account_type, const char* app_id)
{
int rc, count = 1;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
account_stmt hstmt = NULL;
- ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
+ ACCOUNT_RETURN_VAL((account_type != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
if (g_slist_length( account_type->provider_feature_list)==0) {
ACCOUNT_ERROR( "no feature\n");
- return ACCOUNT_ERROR_NONE;
+ return _ACCOUNT_ERROR_NONE;
}
ACCOUNT_DEBUG( "app id", app_id);
ACCOUNT_MEMSET(query, 0x00, sizeof(query));
ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE app_id=? ", PROVIDER_FEATURE_TABLE);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(account_db_handle, query);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(account_db_handle) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(account_db_handle));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
count = 1;
rc = _account_query_step(hstmt);
if (rc != SQLITE_DONE) {
- ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- return ACCOUNT_ERROR_DB_FAILED;
+ ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(account_db_handle));
+ return _ACCOUNT_ERROR_DB_FAILED;
}
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
GSList *iter;
ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(app_id, key) VALUES "
"(?, ?) ", PROVIDER_FEATURE_TABLE);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(account_db_handle, query);
- ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
+ ACCOUNT_RETURN_VAL((hstmt != NULL), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg(account_db_handle)));
provider_feature_s* feature_data = NULL;
feature_data = (provider_feature_s*)iter->data;
ret = _account_query_bind_text(hstmt, count++, account_type->app_id);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
ret = _account_query_bind_text(hstmt, count++, feature_data->key);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
rc = _account_query_step(hstmt);
if (rc != SQLITE_DONE) {
- ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
+ ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(account_db_handle));
break;
}
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
}
- return ACCOUNT_ERROR_NONE;
+ return _ACCOUNT_ERROR_NONE;
}
-static int _account_type_update_label(account_type_s *account_type, const char* app_id)
+static int _account_type_update_label(sqlite3 *account_db_handle, account_type_s *account_type, const char* app_id)
{
int rc, count = 1;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
account_stmt hstmt = NULL;
- ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
+ ACCOUNT_RETURN_VAL((account_type != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
if (g_slist_length( account_type->label_list)==0) {
- return ACCOUNT_ERROR_NONE;
+ return _ACCOUNT_ERROR_NONE;
}
ACCOUNT_MEMSET(query, 0x00, sizeof(query));
ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppId=? ", LABEL_TABLE);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(account_db_handle, query);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(account_db_handle) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(account_db_handle));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
count = 1;
rc = _account_query_step(hstmt);
if (rc != SQLITE_DONE) {
- ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- return ACCOUNT_ERROR_DB_FAILED;
+ ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(account_db_handle));
+ return _ACCOUNT_ERROR_DB_FAILED;
}
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
GSList *iter;
ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(AppId, Label, Locale) VALUES "
"(?, ?, ?) ", LABEL_TABLE);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(account_db_handle, query);
- ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
+ ACCOUNT_RETURN_VAL((hstmt != NULL), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg(account_db_handle)));
label_s* label_data = NULL;
label_data = (label_s*)iter->data;
ret = _account_query_bind_text(hstmt, count++, account_type->app_id);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
ret = _account_query_bind_text(hstmt, count++, label_data->label);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
ret = _account_query_bind_text(hstmt, count++, label_data->locale);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
rc = _account_query_step(hstmt);
if (rc != SQLITE_DONE) {
- ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
+ ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(account_db_handle));
break;
}
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
}
- return ACCOUNT_ERROR_NONE;
+ return _ACCOUNT_ERROR_NONE;
}
-static int _account_type_update_account(account_type_s *account_type, const char* app_id)
+static int _account_type_update_account(sqlite3 *account_db_handle, account_type_s *account_type, const char* app_id)
{
int rc = 0, binding_count =1;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int error_code = ACCOUNT_ERROR_NONE;
+ int error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
if (!account_type->app_id) {
ACCOUNT_ERROR("app id is mandetory field, it can not be NULL!!!!\n");
- return ACCOUNT_ERROR_INVALID_PARAMETER;
+ return _ACCOUNT_ERROR_INVALID_PARAMETER;
}
ACCOUNT_MEMSET(query, 0x00, sizeof(query));
ACCOUNT_SNPRINTF(query, sizeof(query), "UPDATE %s SET AppId=?, ServiceProviderId=?, IconPath=?, "
"SmallIconPath=?, MultipleAccountSupport=? WHERE AppId=? ", ACCOUNT_TYPE_TABLE);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(account_db_handle, query);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- } else if (_account_db_err_code() == SQLITE_BUSY){
- ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_DATABASE_BUSY;
+ if( _account_db_err_code(account_db_handle) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(account_db_handle));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
+ } else if (_account_db_err_code(account_db_handle) == SQLITE_BUSY){
+ ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg(account_db_handle));
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
}
- ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_svc_query_prepare() failed(%s).\n", _account_db_err_msg()));
+ ACCOUNT_RETURN_VAL((hstmt != NULL), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_svc_query_prepare() failed(%s).\n", _account_db_err_msg(account_db_handle)));
binding_count = _account_type_convert_account_to_sql(account_type, hstmt, query);
_account_query_bind_text(hstmt, binding_count++, app_id);
rc = _account_query_step(hstmt);
if (rc != SQLITE_DONE) {
- ACCOUNT_ERROR( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg());
+ ACCOUNT_ERROR( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg(account_db_handle));
}
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
/*update label*/
- error_code = _account_type_update_label(account_type, app_id);
+ error_code = _account_type_update_label(account_db_handle, account_type, app_id);
/* update provider feature */
- error_code = _account_type_update_provider_feature(account_type, app_id);
+ error_code = _account_type_update_provider_feature(account_db_handle, account_type, app_id);
return error_code;
}
int _account_type_update_to_db_by_app_id(account_type_s* account_type, const char* app_id)
{
- ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
- ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ int error_code = _ACCOUNT_ERROR_NONE;
+
+ ACCOUNT_RETURN_VAL((account_type != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("DATA IS NULL"));
+ ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- int error_code = ACCOUNT_ERROR_NONE;
account_type_s* data = account_type;
pthread_mutex_lock(&account_mutex);
- error_code = _account_type_update_account(data, app_id);
-
- pthread_mutex_unlock(&account_mutex);
-
- return error_code;
-}
-
-int _account_type_delete_by_app_id(const char* app_id)
-{
- int error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0, count = -1;
- int ret_transaction = 0;
- int binding_count = 1;
- bool is_success = FALSE;
-
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("The database isn't connected."));
-
- /* Check requested ID to delete */
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE AppId = '%s'", ACCOUNT_TYPE_TABLE, app_id);
-
- count = _account_get_record_count(query);
-
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- if (count <= 0) {
- ACCOUNT_SLOGE("app id(%s) is not exist. count(%d)\n", app_id, count);
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
- }
-
- /* transaction control required*/
- ret_transaction = _account_begin_transaction();
-
- if( ret_transaction == ACCOUNT_ERROR_DATABASE_BUSY ){
- ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg());
- pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_DATABASE_BUSY;
- }else if (ret_transaction != ACCOUNT_ERROR_NONE) {
- ACCOUNT_ERROR("account_delete:_account_begin_transaction fail %d\n", ret_transaction);
- pthread_mutex_unlock(&account_mutex);
- return ret_transaction;
- }
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppId = ?", LABEL_TABLE);
-
- hstmt = _account_prepare_query(query);
-
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
-
- _account_query_bind_text(hstmt, binding_count++, app_id);
-
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- binding_count = 1;
- ACCOUNT_MEMSET(query, 0, sizeof(query));
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE app_id = ? ", PROVIDER_FEATURE_TABLE);
-
- hstmt = _account_prepare_query(query);
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
-
- _account_query_bind_text(hstmt, binding_count++, app_id);
-
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found. AppId=%s, rc=%d\n", app_id, rc));
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- is_success = TRUE;
-
- hstmt = NULL;
-
- binding_count = 1;
- ACCOUNT_MEMSET(query, 0, sizeof(query));
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppId = ? ", ACCOUNT_TYPE_TABLE);
-
- hstmt = _account_prepare_query(query);
- ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
- ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
-
- _account_query_bind_text(hstmt, binding_count++, app_id);
-
- rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found. AppId=%s, rc=%d\n", app_id, rc));
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- is_success = TRUE;
-
- hstmt = NULL;
-
- CATCH:
- if (hstmt != NULL) {
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
- }
-
- ret_transaction = _account_end_transaction(is_success);
-
- if (ret_transaction != ACCOUNT_ERROR_NONE) {
- ACCOUNT_ERROR("account_svc_delete:_account_svc_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
- }
+ error_code = _account_type_update_account(g_hAccountDB, data, app_id);
pthread_mutex_unlock(&account_mutex);
return error_code;
}
-static void _account_type_convert_column_to_account_type(account_stmt hstmt, account_type_s *account_type_record)
-{
- const char *textbuf = NULL;
-
- account_type_record->id = _account_query_table_column_int(hstmt, ACCOUNT_TYPE_FIELD_ID);
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_TYPE_FIELD_APP_ID);
- _account_db_data_to_text(textbuf, &(account_type_record->app_id));
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_TYPE_FIELD_SERVICE_PROVIDER_ID);
- _account_db_data_to_text(textbuf, &(account_type_record->service_provider_id));
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_TYPE_FIELD_ICON_PATH);
- _account_db_data_to_text(textbuf, &(account_type_record->icon_path));
-
- textbuf = _account_query_table_column_text(hstmt, ACCOUNT_TYPE_FIELD_SMALL_ICON_PATH);
- _account_db_data_to_text(textbuf, &(account_type_record->small_icon_path));
-
- account_type_record->multiple_account_support = _account_query_table_column_int(hstmt, ACCOUNT_TYPE_FIELD_MULTIPLE_ACCOUNT_SUPPORT);
-
-}
-
-static void _account_type_convert_column_to_label(account_stmt hstmt, label_s *label_record)
-{
- const char *textbuf = NULL;
-
- textbuf = _account_query_table_column_text(hstmt, LABEL_FIELD_APP_ID);
- _account_db_data_to_text(textbuf, &(label_record->app_id));
-
- textbuf = _account_query_table_column_text(hstmt, LABEL_FIELD_LABEL);
- _account_db_data_to_text(textbuf, &(label_record->label));
-
- textbuf = _account_query_table_column_text(hstmt, LABEL_FIELD_LOCALE);
- _account_db_data_to_text(textbuf, &(label_record->locale));
-
-}
-
GSList* _account_type_get_label_list_by_app_id_from_global_db(const char* app_id, int *error_code )
{
- *error_code = ACCOUNT_ERROR_NONE;
+ *error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0, binding_count = 1;
GSList* label_list = NULL;
- ACCOUNT_RETURN_VAL((app_id != NULL), {*error_code = ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("APP ID IS NULL"));
- ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((app_id != NULL), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", LABEL_TABLE);
- hstmt = _account_prepare_query_from_global_db(query);
+ hstmt = _account_prepare_query(g_hAccountGlobalDB, query);
- if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_from_global_db());
- *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
+ *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
goto CATCH;
}
_account_query_bind_text(hstmt, binding_count++, app_id);
rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR_P((rc == SQLITE_ROW), {_ERR("The record isn't found. rc=[%d] done", rc);}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ ACCOUNT_CATCH_ERROR_P((rc == SQLITE_ROW), {_ERR("The record isn't found. rc=[%d] done", rc);}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
label_s* label_record = NULL;
rc = _account_query_step(hstmt);
}
- *error_code = ACCOUNT_ERROR_NONE;
+ *error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL) {
- rc = _account_query_finalize_from_global_db(hstmt);
- if (rc != ACCOUNT_ERROR_NONE) {
+ rc = _account_query_finalize(hstmt);
+ if (rc != _ACCOUNT_ERROR_NONE) {
_ERR("global db finalize error[%d]", rc);
}
hstmt = NULL;
GSList* _account_type_get_label_list_by_app_id(const char* app_id, int *error_code )
{
- *error_code = ACCOUNT_ERROR_NONE;
+ *error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0, binding_count = 1;
GSList* label_list = NULL;
- ACCOUNT_RETURN_VAL((app_id != NULL), {*error_code = ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("APP ID IS NULL"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((app_id != NULL), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = _ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", LABEL_TABLE);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
return NULL;
}
_account_query_bind_text(hstmt, binding_count++, app_id);
rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
label_s* label_record = NULL;
}
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
hstmt = NULL;
- *error_code = ACCOUNT_ERROR_NONE;
+ *error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL) {
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
hstmt = NULL;
}
- if (*error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+ if (*error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
label_list = _account_type_get_label_list_by_app_id_from_global_db(app_id, error_code);
}
return label_list;
}
-int _account_type_query_label_by_app_id_from_global_db(account_label_cb callback, const char* app_id, void *user_data )
+int _account_type_query_label_by_app_id_from_global_db(account_type_label_cb callback, const char* app_id, void *user_data )
{
- int error_code = ACCOUNT_ERROR_NONE;
+ int error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0, binding_count = 1;
_INFO("account_type_query_label_by_app_id_from_global_db start");
- ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
- ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
- ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((callback != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
+ ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", LABEL_TABLE);
- hstmt = _account_prepare_query_from_global_db(query);
+ hstmt = _account_prepare_query(g_hAccountGlobalDB, query);
- if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_from_global_db());
- error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
+ error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
goto CATCH;
}
_account_query_bind_text(hstmt, binding_count++, app_id);
rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
label_s* label_record = NULL;
_account_type_free_label_with_items(label_record);
- ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, ACCOUNT_ERROR_NONE, ("Callback func returs FALSE, its iteration is stopped!!!!\n"));
+ ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, _ACCOUNT_ERROR_NONE, ("Callback func returs FALSE, its iteration is stopped!!!!\n"));
rc = _account_query_step(hstmt);
}
- error_code = ACCOUNT_ERROR_NONE;
+ error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL) {
- rc = _account_query_finalize_from_global_db(hstmt);
- if (rc != ACCOUNT_ERROR_NONE) {
+ rc = _account_query_finalize(hstmt);
+ if (rc != _ACCOUNT_ERROR_NONE) {
_ERR("global db finalize error[%d]", rc);
}
hstmt = NULL;
return error_code;
}
-int _account_type_query_label_by_app_id(account_label_cb callback, const char* app_id, void *user_data )
+int _account_type_query_label_by_app_id(account_type_label_cb callback, const char* app_id, void *user_data )
{
- int error_code = ACCOUNT_ERROR_NONE;
+ int error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0, binding_count = 1;
- ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
- ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((callback != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", LABEL_TABLE);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
_account_query_bind_text(hstmt, binding_count++, app_id);
rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
label_s* label_record = NULL;
_account_type_free_label_with_items(label_record);
-// ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, ACCOUNT_ERROR_NONE, ("Callback func returs FALSE, its iteration is stopped!!!!\n"));
+// ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, _ACCOUNT_ERROR_NONE, ("Callback func returs FALSE, its iteration is stopped!!!!\n"));
if(cb_ret == TRUE) {
_INFO("Callback func returs FALSE, its iteration is stopped!!!!\n");
break;
}
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
- error_code = ACCOUNT_ERROR_NONE;
+ error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL) {
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
}
/*
- if (error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+ if (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
error_code = account_type_query_label_by_app_id_from_global_db(callback, app_id, user_data);
}
*/
return error_code;
}
-int account_type_query_label_by_app_id(account_label_cb callback, const char* app_id, void *user_data )
+int account_type_query_label_by_app_id(account_type_label_cb callback, const char* app_id, void *user_data )
{
- int error_code = ACCOUNT_ERROR_NONE;
+ int error_code = _ACCOUNT_ERROR_NONE;
- ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
- ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((callback != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
error_code = _account_type_query_label_by_app_id(callback, app_id, user_data);
- if (error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+ if (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
error_code = _account_type_query_label_by_app_id_from_global_db(callback, app_id, user_data);
}
return error_code;
}
-int _account_type_label_get_app_id(label_h label, char **app_id)
-{
- if (!label) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- if (!app_id) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- label_s *data = (label_s*)label;
-
- (*app_id) = NULL;
-
- *app_id = _account_get_text(data->app_id);
-
- return ACCOUNT_ERROR_NONE;
-}
-
bool _account_get_label_text_cb(char* app_id, char* label, char* locale, void *user_data)
{
account_type_s *data = (account_type_s*)user_data;
}
ACCOUNT_MEMSET(label_data, 0, sizeof(label_s));
- label_data->app_id = _account_get_text(app_id);
- label_data->label = _account_get_text(label);
- label_data->locale = _account_get_text(locale);
+ label_data->app_id = _account_dup_text(app_id);
+ label_data->label = _account_dup_text(label);
+ label_data->locale = _account_dup_text(locale);
data->label_list = g_slist_append(data->label_list, (gpointer)label_data);
}
ACCOUNT_MEMSET(feature_data, 0, sizeof(provider_feature_s));
- feature_data->app_id = _account_get_text(app_id);
- feature_data->key = _account_get_text(key);
+ feature_data->app_id = _account_dup_text(app_id);
+ feature_data->key = _account_dup_text(key);
data->provider_feature_list = g_slist_append(data->provider_feature_list, (gpointer)feature_data);
{
_INFO("_account_type_query_by_app_id_from_global_db start");
- int error_code = ACCOUNT_ERROR_NONE;
+ int error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0, binding_count = 1;
- ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((app_id != 0), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", ACCOUNT_TYPE_TABLE);
- hstmt = _account_prepare_query_from_global_db(query);
+ hstmt = _account_prepare_query(g_hAccountGlobalDB, query);
- if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_from_global_db());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
_account_query_bind_text(hstmt, binding_count++, app_id);
rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
*account_type_record = create_empty_account_type_instance();
rc = _account_query_step(hstmt);
}
- rc = _account_query_finalize_from_global_db(hstmt);
- ACCOUNT_CATCH_ERROR((rc == ACCOUNT_ERROR_NONE), {_ERR("global db finalize error rc=[%d]", rc);}, rc, ("finalize error"));
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_CATCH_ERROR((rc == _ACCOUNT_ERROR_NONE), {_ERR("global db finalize error rc=[%d]", rc);}, rc, ("finalize error"));
_account_type_query_label_by_app_id_from_global_db(_account_get_label_text_cb, app_id, (void*)(*account_type_record));
_account_type_query_provider_feature_cb_by_app_id_from_global_db(_account_get_provider_feature_cb, app_id,(void*)(*account_type_record));
hstmt = NULL;
- error_code = ACCOUNT_ERROR_NONE;
+ error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL) {
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
}
{
_INFO("_account_type_query_by_app_id start");
- int error_code = ACCOUNT_ERROR_NONE;
+ int error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0, binding_count = 1;
- ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
- ACCOUNT_RETURN_VAL((account_type_record != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account type record(account_type_s**) is NULL"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((app_id != 0), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+ ACCOUNT_RETURN_VAL((account_type_record != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("account type record(account_type_s**) is NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", ACCOUNT_TYPE_TABLE);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
_account_query_bind_text(hstmt, binding_count++, app_id);
rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
*account_type_record = create_empty_account_type_instance();
if (*account_type_record == NULL) {
_ERR("Out of Memory");
- error_code = ACCOUNT_ERROR_OUT_OF_MEMORY;
+ error_code = _ACCOUNT_ERROR_OUT_OF_MEMORY;
goto CATCH;
}
}
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
_account_type_query_label_by_app_id(_account_get_label_text_cb, app_id, (void*)(*account_type_record));
_account_type_query_provider_feature_cb_by_app_id(_account_get_provider_feature_cb, app_id,(void*)(*account_type_record));
hstmt = NULL;
- error_code = ACCOUNT_ERROR_NONE;
+ error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL) {
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
}
- if (error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+ if (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
error_code = _account_type_query_by_app_id_from_global_db(app_id, account_type_record);
}
return error_code;
}
-int _account_type_query_app_id_exist(const char* app_id)
-{
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
-
- ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE AppId = '%s'", ACCOUNT_TYPE_TABLE, app_id);
- rc = _account_get_record_count(query);
-
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- if (rc <= 0) {
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
- }
-
- return ACCOUNT_ERROR_NONE;
-}
-
-int _account_type_query_app_id_exist_from_all_db(const char *app_id)
-{
- _INFO("_account_type_query_app_id_exist_from_all_db start app_id=%s", app_id);
- int return_code = ACCOUNT_ERROR_NONE;
-
- return_code = _account_type_query_app_id_exist(app_id);
-
- if (return_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
- return_code = _account_type_query_app_id_exist_from_global_db(app_id);
- } else {
- return return_code;
- }
- _INFO("_account_type_query_app_id_exist_from_all_db end");
- return return_code;
-}
-
int _account_type_query_by_provider_feature_from_global_db(const char* key, GSList **account_type_list_all)
{
- int error_code = ACCOUNT_ERROR_NONE;
+ int error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0;
if(key == NULL)
{
ACCOUNT_ERROR("capability_type IS NULL.");
- error_code = ACCOUNT_ERROR_INVALID_PARAMETER;
+ error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;
goto CATCH;
}
if(g_hAccountGlobalDB == NULL)
{
ACCOUNT_ERROR("The database isn't connected.");
- error_code = ACCOUNT_ERROR_DB_NOT_OPENED;
+ error_code = _ACCOUNT_ERROR_DB_NOT_OPENED;
goto CATCH;
}
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId IN (SELECT app_id from %s WHERE key=?)", ACCOUNT_TYPE_TABLE, PROVIDER_FEATURE_TABLE);
- hstmt = _account_prepare_query_from_global_db(query);
+ hstmt = _account_prepare_query(g_hAccountGlobalDB, query);
- if( _account_db_err_code_from_global_db() == SQLITE_PERM )
+ if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM )
{
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_from_global_db());
- error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
+ error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
goto CATCH;
}
if(rc != SQLITE_ROW)
{
ACCOUNT_ERROR("The record isn't found. rc=[%d]", rc);
- error_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
goto CATCH;
}
rc = _account_query_step(hstmt);
}
- rc = _account_query_finalize_from_global_db(hstmt);
- if (rc != ACCOUNT_ERROR_NONE )
+ rc = _account_query_finalize(hstmt);
+ if (rc != _ACCOUNT_ERROR_NONE )
{
_account_type_gslist_account_type_free(account_type_list);
ACCOUNT_ERROR("finalize error(%s)", rc);
_INFO("add account_type");
}
- error_code = ACCOUNT_ERROR_NONE;
+ error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL) {
- rc = _account_query_finalize_from_global_db(hstmt);
- if (rc != ACCOUNT_ERROR_NONE)
+ rc = _account_query_finalize(hstmt);
+ if (rc != _ACCOUNT_ERROR_NONE)
{
ACCOUNT_ERROR("finalize error(%s)", rc);
return rc;
GSList* _account_type_query_by_provider_feature(const char* key, int *error_code)
{
- *error_code = ACCOUNT_ERROR_NONE;
+ *error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0;
if(key == NULL)
{
ACCOUNT_ERROR("capability_type IS NULL.");
- *error_code = ACCOUNT_ERROR_INVALID_PARAMETER;
+ *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;
goto CATCH;
}
if(g_hAccountDB == NULL)
{
ACCOUNT_ERROR("The database isn't connected.");
- *error_code = ACCOUNT_ERROR_DB_NOT_OPENED;
+ *error_code = _ACCOUNT_ERROR_DB_NOT_OPENED;
goto CATCH;
}
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId IN (SELECT app_id from %s WHERE key=?)", ACCOUNT_TYPE_TABLE, PROVIDER_FEATURE_TABLE);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- if( _account_db_err_code() == SQLITE_PERM )
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM )
{
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
goto CATCH;
}
if(rc != SQLITE_ROW)
{
ACCOUNT_ERROR("The record isn't found. rc=[%d]", rc);
- *error_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ *error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
goto CATCH;
}
}
rc = _account_query_finalize(hstmt);
- if (rc != ACCOUNT_ERROR_NONE )
+ if (rc != _ACCOUNT_ERROR_NONE )
{
_account_type_gslist_account_type_free(account_type_list);
ACCOUNT_ERROR("finalize error(%s)", rc);
_account_type_query_provider_feature_cb_by_app_id(_account_get_provider_feature_cb, account_type->app_id,(void*)account_type);
}
- *error_code = ACCOUNT_ERROR_NONE;
+ *error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL) {
rc = _account_query_finalize(hstmt);
- if (rc != ACCOUNT_ERROR_NONE)
+ if (rc != _ACCOUNT_ERROR_NONE)
{
*error_code = rc;
return NULL;
hstmt = NULL;
}
- if (*error_code == ACCOUNT_ERROR_NONE || *error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+ if (*error_code == _ACCOUNT_ERROR_NONE || *error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
rc = _account_type_query_by_provider_feature_from_global_db(key, &account_type_list);
- if (rc != ACCOUNT_ERROR_NONE && rc != ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+ if (rc != _ACCOUNT_ERROR_NONE && rc != _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
ACCOUNT_ERROR( "_account_type_query_by_provider_feature_from_global_db fail=[%d]", rc);
_account_type_gslist_account_type_free(account_type_list);
return NULL;
}
- if (rc == ACCOUNT_ERROR_NONE)
+ if (rc == _ACCOUNT_ERROR_NONE)
*error_code = rc;
}
{
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = ACCOUNT_ERROR_NONE;
- int error_code = ACCOUNT_ERROR_NONE;
+ int rc = _ACCOUNT_ERROR_NONE;
+ int error_code = _ACCOUNT_ERROR_NONE;
GSList *account_type_list = NULL;
_INFO("_account_type_query_all_in_global_db start");
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s ", ACCOUNT_TYPE_TABLE);
- hstmt = _account_prepare_query_from_global_db(query);
+ hstmt = _account_prepare_query(g_hAccountGlobalDB, query);
rc = _account_query_step(hstmt);
- if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_from_global_db());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
account_type_s *account_type_record = NULL;
if (rc != SQLITE_ROW)
{
- _INFO("[ACCOUNT_ERROR_RECORD_NOT_FOUND]The record isn't found.");
- error_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ _INFO("[_ACCOUNT_ERROR_RECORD_NOT_FOUND]The record isn't found.");
+ error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
goto CATCH;
}
rc = _account_query_step(hstmt);
}
- rc = _account_query_finalize_from_global_db(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
GSList* iter;
*account_type_list_all = g_slist_append(*account_type_list_all, account_type);
}
- error_code = ACCOUNT_ERROR_NONE;
+ error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL)
{
- rc = _account_query_finalize_from_global_db(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {_account_type_gslist_account_type_free(account_type_list);}, rc, ("finalize error"));
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {_account_type_gslist_account_type_free(account_type_list);}, rc, ("finalize error"));
hstmt = NULL;
}
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0;
- int error_code = ACCOUNT_ERROR_NONE;
+ int error_code = _ACCOUNT_ERROR_NONE;
GSList *account_type_list = NULL;
_INFO("_account_type_query_all start");
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s ", ACCOUNT_TYPE_TABLE);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
rc = _account_query_step(hstmt);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
return NULL;
}
if (rc != SQLITE_ROW)
{
- _INFO("[ACCOUNT_ERROR_RECORD_NOT_FOUND]The record isn't found.");
- error_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ _INFO("[_ACCOUNT_ERROR_RECORD_NOT_FOUND]The record isn't found.");
+ error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
goto CATCH;
}
}
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, NULL, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, NULL, ("finalize error"));
hstmt = NULL;
GSList* iter;
_account_type_query_provider_feature_cb_by_app_id(_account_get_provider_feature_cb, account_type->app_id,(void*)account_type);
}
- error_code = ACCOUNT_ERROR_NONE;
+ error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL)
{
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {_account_type_gslist_account_type_free(account_type_list);}, NULL, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {_account_type_gslist_account_type_free(account_type_list);}, NULL, ("finalize error"));
hstmt = NULL;
}
- if (error_code == ACCOUNT_ERROR_NONE || error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+ if (error_code == _ACCOUNT_ERROR_NONE || error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
error_code = _account_type_query_all_from_global_db(&account_type_list);
- if (rc != ACCOUNT_ERROR_NONE && rc != ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+ if (rc != _ACCOUNT_ERROR_NONE && rc != _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
ACCOUNT_ERROR( "_account_type_query_all_from_global_db fail=[%d]", rc);
_account_type_gslist_account_type_free(account_type_list);
return NULL;
// output parameter label must be free
int _account_type_query_label_by_locale_from_global_db(const char* app_id, const char* locale, char **label)
{
- int error_code = ACCOUNT_ERROR_NONE;
+ int error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0, binding_count = 1;
char* converted_locale = NULL;
- ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO APP ID"));
- ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("label char is null"));
- ACCOUNT_RETURN_VAL((locale != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("locale char is null"));
+ ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("NO APP ID"));
+ ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((label != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("label char is null"));
+ ACCOUNT_RETURN_VAL((locale != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("locale char is null"));
//Making label newly created
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
- converted_locale = _account_get_text(locale);
+ converted_locale = _account_dup_text(locale);
gchar** tokens = g_strsplit(converted_locale, "-", 2);
if(tokens != NULL) {
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ? AND Locale = '%s' ", LABEL_TABLE, converted_locale);
_ACCOUNT_FREE(converted_locale);
- hstmt = _account_prepare_query_from_global_db(query);
+ hstmt = _account_prepare_query(g_hAccountGlobalDB, query);
- if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_from_global_db());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
_account_query_bind_text(hstmt, binding_count++, app_id);
rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
label_s* label_record = NULL;
_ACCOUNT_FREE(*label);
//Making label newly created
- *label = _account_get_text(label_record->label);
+ *label = _account_dup_text(label_record->label);
_account_type_free_label_with_items(label_record);
rc = _account_query_step(hstmt);
}
- rc = _account_query_finalize_from_global_db(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
- error_code = ACCOUNT_ERROR_NONE;
+ error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL) {
- rc = _account_query_finalize_from_global_db(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
}
// output parameter label must be free
int _account_type_query_label_by_locale(const char* app_id, const char* locale, char **label)
{
- int error_code = ACCOUNT_ERROR_NONE;
+ int error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0, binding_count = 1;
char* converted_locale = NULL;
- ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO APP ID"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("label char is null"));
- ACCOUNT_RETURN_VAL((locale != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("locale char is null"));
+ ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("NO APP ID"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+ ACCOUNT_RETURN_VAL((label != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("label char is null"));
+ ACCOUNT_RETURN_VAL((locale != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("locale char is null"));
//Making label newly created
ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
- converted_locale = _account_get_text(locale);
+ converted_locale = _account_dup_text(locale);
gchar** tokens = g_strsplit(converted_locale, "-", 2);
if(tokens != NULL) {
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ? AND Locale = '%s' ", LABEL_TABLE, converted_locale);
_ACCOUNT_FREE(converted_locale);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
_account_query_bind_text(hstmt, binding_count++, app_id);
rc = _account_query_step(hstmt);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
label_s* label_record = NULL;
_ACCOUNT_FREE(*label);
//Making label newly created
- *label = _account_get_text(label_record->label);
+ *label = _account_dup_text(label_record->label);
_account_type_free_label_with_items(label_record);
}
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
- error_code = ACCOUNT_ERROR_NONE;
+ error_code = _ACCOUNT_ERROR_NONE;
CATCH:
if (hstmt != NULL) {
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
}
- if (error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+ if (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
error_code = _account_type_query_label_by_locale_from_global_db(app_id, locale, label);
}
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
account_stmt hstmt = NULL;
- ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
+ ACCOUNT_RETURN_VAL((account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
if (g_slist_length( account->custom_list)==0) {
ACCOUNT_DEBUG( "_account_insert_custom, no custom data\n");
- return ACCOUNT_ERROR_NONE;
+ return _ACCOUNT_ERROR_NONE;
}
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where _id=%d", ACCOUNT_TABLE, account_id);
- rc = _account_get_record_count(query);
+ rc = _account_get_record_count(g_hAccountDB, query);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%d, %s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%d, %s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
if (rc <= 0) {
- ACCOUNT_SLOGE( "_account_insert_custom : related account item is not existed rc=%d , %s", rc, _account_db_err_msg());
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ ACCOUNT_SLOGE( "_account_insert_custom : related account item is not existed rc=%d , %s", rc, _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
}
/* insert query*/
ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s (AccountId, AppId, Key, Value) VALUES "
"(?, ?, ?, ?) ", ACCOUNT_CUSTOM_TABLE);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
+ ACCOUNT_RETURN_VAL((hstmt != NULL), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query(g_hAccountDB, ) failed(%s).\n", _account_db_err_msg(g_hAccountDB)));
account_custom_s* custom_data = NULL;
custom_data = (account_custom_s*)iter->data;
ret = _account_query_bind_int(hstmt, count++, account_id);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Int binding fail"));
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Int binding fail"));
ret = _account_query_bind_text(hstmt, count++, account->package_name);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
ret = _account_query_bind_text(hstmt, count++, (char*)custom_data->key);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
ret = _account_query_bind_text(hstmt, count++, (char*)custom_data->value);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
rc = _account_query_step(hstmt);
if (rc != SQLITE_DONE) {
- ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
+ ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
break;
}
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
}
_INFO("_account_insert_custom end");
- return ACCOUNT_ERROR_NONE;
+ return _ACCOUNT_ERROR_NONE;
}
static int _account_update_custom(account_s *account, int account_id)
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
account_stmt hstmt = NULL;
- ACCOUNT_RETURN_VAL((account != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
+ ACCOUNT_RETURN_VAL((account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
if (g_slist_length( account->custom_list)==0) {
ACCOUNT_DEBUG( "_account_update_custom, no custom data\n");
- return ACCOUNT_ERROR_NONE;
+ return _ACCOUNT_ERROR_NONE;
}
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) from %s where _id=%d", ACCOUNT_TABLE, account_id);
- rc = _account_get_record_count(query);
+ rc = _account_get_record_count(g_hAccountDB, query);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- } else if( _account_db_err_code() == SQLITE_BUSY ){
- ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg());
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
+ } else if( _account_db_err_code(g_hAccountDB) == SQLITE_BUSY ){
+ ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg(g_hAccountDB));
pthread_mutex_unlock(&account_mutex);
- return ACCOUNT_ERROR_DATABASE_BUSY;
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
}
if (rc <= 0) {
- ACCOUNT_SLOGE( "_account_update_custom : related account item is not existed rc=%d , %s", rc, _account_db_err_msg());
- return ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ ACCOUNT_SLOGE( "_account_update_custom : related account item is not existed rc=%d , %s", rc, _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
}
ACCOUNT_MEMSET(query, 0x00, sizeof(query));
ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AccountId=? ", ACCOUNT_CUSTOM_TABLE);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
count = 1;
_account_query_bind_int(hstmt, count++, (int)account_id);
rc = _account_query_step(hstmt);
if (rc == SQLITE_BUSY) {
- ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- return ACCOUNT_ERROR_DATABASE_BUSY;
+ ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
} else if (rc != SQLITE_DONE) {
- ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
- return ACCOUNT_ERROR_DB_FAILED;
+ ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_DB_FAILED;
}
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
GSList *iter;
ACCOUNT_SNPRINTF(query, sizeof(query), "INSERT INTO %s(AccountId, AppId, Key, Value) VALUES "
"(?, ?, ?, ?) ", ACCOUNT_CUSTOM_TABLE);
- hstmt = _account_prepare_query(query);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
+ if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
- ACCOUNT_RETURN_VAL((hstmt != NULL), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query() failed(%s).\n", _account_db_err_msg()));
+ ACCOUNT_RETURN_VAL((hstmt != NULL), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_prepare_query(g_hAccountDB, ) failed(%s).\n", _account_db_err_msg(g_hAccountDB)));
account_custom_s* custom_data = NULL;
custom_data = (account_custom_s*)iter->data;
ret = _account_query_bind_int(hstmt, count++, (int)account_id);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Int binding fail"));
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Int binding fail"));
ret = _account_query_bind_text(hstmt, count++, (char*)account->package_name);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
ret = _account_query_bind_text(hstmt, count++, (char*)custom_data->key);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
ret = _account_query_bind_text(hstmt, count++, (char*)custom_data->value);
- ACCOUNT_RETURN_VAL((ret == ACCOUNT_ERROR_NONE), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
+ ACCOUNT_RETURN_VAL((ret == _ACCOUNT_ERROR_NONE), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("Text binding fail"));
rc = _account_query_step(hstmt);
if (rc != SQLITE_DONE) {
- ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg());
+ ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
break;
}
rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
}
- return ACCOUNT_ERROR_NONE;
+ return _ACCOUNT_ERROR_NONE;
}
-static int _account_query_custom_by_account_id(account_custom_cb callback, int account_id, void *user_data )
-{
- int error_code = ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
-
- ACCOUNT_RETURN_VAL((account_id > 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
- ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
- ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
-
- ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AccountId = %d", ACCOUNT_CUSTOM_TABLE, account_id);
- hstmt = _account_prepare_query(query);
-
- if( _account_db_err_code() == SQLITE_PERM ){
- ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
- return ACCOUNT_ERROR_PERMISSION_DENIED;
- }
-
- rc = _account_query_step(hstmt);
-
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
-
- account_custom_s* custom_record = NULL;
-
- while (rc == SQLITE_ROW) {
- bool cb_ret = FALSE;
- custom_record = (account_custom_s*) malloc(sizeof(account_custom_s));
-
- if (custom_record == NULL) {
- ACCOUNT_FATAL("malloc Failed");
- break;
- }
-
- ACCOUNT_MEMSET(custom_record, 0x00, sizeof(account_custom_s));
-
- _account_convert_column_to_custom(hstmt, custom_record);
-
- cb_ret = callback(custom_record->key, custom_record->value, user_data);
-
- _account_free_custom_with_items(custom_record);
-
- ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, ACCOUNT_ERROR_NONE, ("Callback func returs FALSE, its iteration is stopped!!!!\n"));
-
- rc = _account_query_step(hstmt);
- }
-
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- error_code = ACCOUNT_ERROR_NONE;
-
-CATCH:
- if (hstmt != NULL) {
- rc = _account_query_finalize(hstmt);
- ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
- }
-
- pthread_mutex_unlock(&account_mutex);
- return error_code;
-}