char *allowed_appid;
};
-static sqlite3 *svc_db;
-static sqlite3 *app_info_db;
-static sqlite3 *global_app_info_db;
-
static char *__get_svc_db(uid_t uid)
{
char db_path[PATH_MAX];
/**
* db initialize
*/
-static int __init(uid_t uid, bool readonly)
+static int __init(uid_t uid, bool readonly, sqlite3 **svc_db)
{
int rc;
char *db_path;
- if (svc_db) {
+ if (*svc_db) {
_D("Already initialized");
return 0;
}
return -1;
}
- rc = sqlite3_open_v2(db_path, &svc_db,
+ rc = sqlite3_open_v2(db_path, svc_db,
readonly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE,
NULL);
free(db_path);
if (rc) {
_E("Can't open database: %d, %s, extended: %d",
- rc, sqlite3_errmsg(svc_db),
- sqlite3_extended_errcode(svc_db));
- if (svc_db) {
- sqlite3_close(svc_db);
- svc_db = NULL;
+ rc, sqlite3_errmsg(*svc_db),
+ sqlite3_extended_errcode(*svc_db));
+ if (*svc_db) {
+ sqlite3_close(*svc_db);
+ *svc_db = NULL;
}
return -1;
}
return -1;
}
-static int __init_app_info_db(uid_t uid)
+static int __init_app_info_db(uid_t uid, sqlite3 **app_info_db, sqlite3 **global_app_info_db)
{
int rc;
char *db_path;
- if (app_info_db && global_app_info_db) {
+ if (*app_info_db && *global_app_info_db) {
_D("Already initialized");
return 0;
}
return -1;
}
- rc = sqlite3_open_v2(db_path, &app_info_db, SQLITE_OPEN_READONLY, NULL);
+ rc = sqlite3_open_v2(db_path, app_info_db, SQLITE_OPEN_READONLY, NULL);
free(db_path);
if (rc) {
_E("Can't open database: %d, %s, extended: %d",
- rc, sqlite3_errmsg(app_info_db),
- sqlite3_extended_errcode(app_info_db));
+ rc, sqlite3_errmsg(*app_info_db),
+ sqlite3_extended_errcode(*app_info_db));
goto err;
}
- rc = sqlite3_exec(app_info_db, "PRAGMA journal_mode = PERSIST",
+ rc = sqlite3_exec(*app_info_db, "PRAGMA journal_mode = PERSIST",
NULL, NULL, NULL);
if (SQLITE_OK != rc) {
_D("Fail to change journal mode");
goto err;
}
- sqlite3_create_collation(app_info_db, SVC_COLLATION, SQLITE_UTF8,
+ sqlite3_create_collation(*app_info_db, SVC_COLLATION, SQLITE_UTF8,
NULL, __collate_appsvc);
- rc = sqlite3_open_v2(APP_INFO_DB_PATH, &global_app_info_db,
+ rc = sqlite3_open_v2(APP_INFO_DB_PATH, global_app_info_db,
SQLITE_OPEN_READONLY, NULL);
if (rc) {
_E("Can't open database: %d, %s, extended: %d",
- rc, sqlite3_errmsg(global_app_info_db),
- sqlite3_extended_errcode(global_app_info_db));
+ rc, sqlite3_errmsg(*global_app_info_db),
+ sqlite3_extended_errcode(*global_app_info_db));
goto err;
}
- rc = sqlite3_exec(global_app_info_db, "PRAGMA journal_mode = PERSIST",
+ rc = sqlite3_exec(*global_app_info_db, "PRAGMA journal_mode = PERSIST",
NULL, NULL, NULL);
if (SQLITE_OK != rc) {
_D("Fail to change journal mode");
goto err;
}
- sqlite3_create_collation(global_app_info_db, SVC_COLLATION, SQLITE_UTF8,
+ sqlite3_create_collation(*global_app_info_db, SVC_COLLATION, SQLITE_UTF8,
NULL, __collate_appsvc);
return 0;
err:
- if (app_info_db) {
- sqlite3_close(app_info_db);
- app_info_db = NULL;
+ if (*app_info_db) {
+ sqlite3_close(*app_info_db);
+ *app_info_db = NULL;
}
- if (global_app_info_db) {
- sqlite3_close(global_app_info_db);
- global_app_info_db = NULL;
+ if (*global_app_info_db) {
+ sqlite3_close(*global_app_info_db);
+ *global_app_info_db = NULL;
}
return -1;
}
-static void __fini_app_info_db(void)
+static void __fini_app_info_db(sqlite3 **app_info_db, sqlite3 **global_app_info_db)
{
- if (app_info_db) {
- sqlite3_close(app_info_db);
- app_info_db = NULL;
+ if (*app_info_db) {
+ sqlite3_close(*app_info_db);
+ *app_info_db = NULL;
}
- if (global_app_info_db) {
- sqlite3_close(global_app_info_db);
- global_app_info_db = NULL;
+ if (*global_app_info_db) {
+ sqlite3_close(*global_app_info_db);
+ *global_app_info_db = NULL;
}
}
-static int __fini(void)
+static int __fini(sqlite3 **svc_db)
{
- if (svc_db) {
- sqlite3_close(svc_db);
- svc_db = NULL;
+ if (*svc_db) {
+ sqlite3_close(*svc_db);
+ *svc_db = NULL;
}
return 0;
}
{
int ret = 0;
char *db;
+ sqlite3 *svc_db = NULL;
- if (__init(uid, readonly) < 0)
+ if (__init(uid, readonly, &svc_db) < 0)
return -1;
db = __get_svc_db(uid);
- if (db == NULL)
+ if (db == NULL) {
+ __fini(&svc_db);
return -1;
+ }
ret = access(db, readonly ? R_OK : (R_OK | W_OK));
free(db);
+ __fini(&svc_db);
return ret;
}
const char *pkg_name, uid_t uid)
{
int r;
+ sqlite3 *svc_db = NULL;
- if (__init(uid, false) < 0)
+ if (__init(uid, false, &svc_db) < 0)
return -1;
if (op == NULL)
return -1;
r = __insert_info(svc_db, op, mime_type, uri, pkg_name);
- __fini();
+ __fini(&svc_db);
return r;
}
int _svc_db_delete_with_pkgname(const char *pkg_name, uid_t uid)
{
int r;
+ sqlite3 *svc_db = NULL;
if (pkg_name == NULL) {
_E("Invalid argument: data to delete is NULL");
return -1;
}
- if (__init(uid, false) < 0)
+ if (__init(uid, false, &svc_db) < 0)
return -1;
r = __delete_info(svc_db, pkg_name);
- __fini();
+ __fini(&svc_db);
return r;
}
{
const char query[] = "DELETE FROM appsvc;";
int r;
+ sqlite3 *svc_db = NULL;
- if (__init(uid, false) < 0)
+ if (__init(uid, false, &svc_db) < 0)
return -1;
r = sqlite3_exec(svc_db, query, NULL, NULL, NULL);
if (r != SQLITE_OK) {
_E("Exec failed: %s", sqlite3_errmsg(svc_db));
- __fini();
+ __fini(&svc_db);
return -1;
}
- __fini();
+ __fini(&svc_db);
return 0;
}
int _svc_db_is_defapp(const char *pkg_name, uid_t uid)
{
int r;
+ sqlite3 *svc_db = NULL;
if (pkg_name == NULL) {
_E("Invalid argument: data to delete is NULL");
return 0;
}
- if (__init(uid, true) < 0)
+ if (__init(uid, true, &svc_db) < 0)
return 0;
r = __get_count(svc_db, pkg_name);
- __fini();
+ __fini(&svc_db);
if (r < 1)
return 0;
{
char *appid = NULL;
int r;
+ sqlite3 *svc_db = NULL;
if (op == NULL)
return NULL;
- if (__init(uid, true) < 0)
+ if (__init(uid, true, &svc_db) < 0)
return NULL;
r = __get_appid(svc_db, op, mime_type, uri, &appid);
if (r != 0) {
- __fini();
+ __fini(&svc_db);
return NULL;
}
- __fini();
+ __fini(&svc_db);
SECURE_LOGD("appid: %s", appid);
return appid;
return strcmp(a, b);
}
-static int __adjust_list_with_submode(sqlite3 *db, int mainapp_mode,
- const char *win_id, GSList **list)
+static int __adjust_list_with_submode(sqlite3 *db, sqlite3 *app_info_db,
+ int mainapp_mode, const char *win_id, GSList **list)
{
const char query[] =
"SELECT ac.app_id, ai.app_submode_mainid "
GSList **pkg_list, uid_t uid)
{
int r;
+ sqlite3 *app_info_db = NULL;
+ sqlite3 *global_app_info_db = NULL;
- if (__init_app_info_db(uid) < 0)
+ if (__init_app_info_db(uid, &app_info_db, &global_app_info_db) < 0)
return 0;
- r = __adjust_list_with_submode(app_info_db, mainapp_mode, win_id,
+ r = __adjust_list_with_submode(app_info_db, app_info_db, mainapp_mode, win_id,
pkg_list);
if (r < 0) {
- __fini_app_info_db();
+ __fini_app_info_db(&app_info_db, &global_app_info_db);
return -1;
}
- r = __adjust_list_with_submode(global_app_info_db, mainapp_mode, win_id,
+ r = __adjust_list_with_submode(global_app_info_db, app_info_db, mainapp_mode, win_id,
pkg_list);
if (r < 0) {
- __fini_app_info_db();
+ __fini_app_info_db(&app_info_db, &global_app_info_db);
return -1;
}
- __fini_app_info_db();
+ __fini_app_info_db(&app_info_db, &global_app_info_db);
return 0;
}
r = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
if (r != SQLITE_OK) {
- _E("Prepare failed: %s", sqlite3_errmsg(svc_db));
+ _E("Prepare failed: %s", sqlite3_errmsg(db));
return -1;
}
{
const char query[] = "SELECT pkg_name FROM appsvc;";
int r;
+ sqlite3 *svc_db = NULL;
- if (__init(uid, true) < 0)
+ if (__init(uid, true, &svc_db) < 0)
return -1;
r = __get_list_with_query(svc_db, query, pkg_list);
- __fini();
+ __fini(&svc_db);
return r;
}
int _svc_db_exec_query(const char *query, GSList **pkg_list, uid_t uid)
{
int r;
+ sqlite3 *app_info_db = NULL;
+ sqlite3 *global_app_info_db = NULL;
- if (__init_app_info_db(uid) < 0)
+ if (__init_app_info_db(uid, &app_info_db, &global_app_info_db) < 0)
return 0;
SECURE_LOGD("query : %s", query);
r = __get_list_with_query(app_info_db, query, pkg_list);
if (r < 0) {
- __fini_app_info_db();
+ __fini_app_info_db(&app_info_db, &global_app_info_db);
return -1;
}
r = __get_list_with_query(global_app_info_db, query, pkg_list);
if (r < 0) {
- __fini_app_info_db();
+ __fini_app_info_db(&app_info_db, &global_app_info_db);
return -1;
}
- __fini_app_info_db();
+ __fini_app_info_db(&app_info_db, &global_app_info_db);
return 0;
}
{
int ret;
sqlite3_stmt *stmt = NULL;
+ sqlite3 *svc_db = NULL;
const char *query =
"INSERT OR REPLACE INTO alias_info(alias_appid, appid) " \
"values(?,?);";
return -1;
}
- if (__init(uid, false) < 0)
+ if (__init(uid, false, &svc_db) < 0)
return -1;
ret = sqlite3_prepare_v2(svc_db, query, strlen(query), &stmt, NULL);
if (ret != SQLITE_OK) {
_E("sqlite3_prepare_v2() error: %d(%s)",
ret, sqlite3_errmsg(svc_db));
- __fini();
+ __fini(&svc_db);
return ret;
}
end:
sqlite3_finalize(stmt);
- __fini();
+ __fini(&svc_db);
return result;
}
sqlite3_stmt *stmt = NULL;
const char *query = "DELETE FROM alias_info WHERE alias_appid = ?;";
int result = 0;
+ sqlite3 *svc_db = NULL;
if (alias_appid == NULL) {
_E("Invalid parameter");
return -1;
}
- if (__init(uid, false) < 0)
+ if (__init(uid, false, &svc_db) < 0)
return -1;
ret = sqlite3_prepare_v2(svc_db, query, strlen(query), &stmt, NULL);
if (ret != SQLITE_OK) {
_E("sqlite3_prepare_v2() error: %d(%s)",
ret, sqlite3_errmsg(svc_db));
- __fini();
+ __fini(&svc_db);
return -1;
}
end:
sqlite3_finalize(stmt);
- __fini();
+ __fini(&svc_db);
return result;
}
sqlite3_stmt *stmt = NULL;
const char *query;
const char *real_appid;
+ sqlite3 *svc_db = NULL;
if (appid == NULL || alias_appid == NULL) {
_E("Invalid parameter");
return -1;
}
- if (__init(db_uid, true) < 0)
+ if (__init(db_uid, true, &svc_db) < 0)
return -1;
if (db_uid == GLOBAL_USER) {
if (ret != SQLITE_OK) {
_E("sqlite3_prepare_v2() error: %d(%s)",
ret, sqlite3_errmsg(svc_db));
- __fini();
+ __fini(&svc_db);
return -1;
}
end:
sqlite3_finalize(stmt);
- __fini();
+ __fini(&svc_db);
return result;
}
const char *alias_id;
const char *id;
struct alias_info_s *info;
+ sqlite3 *svc_db = NULL;
- if (__init(db_uid, true) < 0)
+ if (__init(db_uid, true, &svc_db) < 0)
return -1;
if (db_uid == GLOBAL_USER) {
if (ret != SQLITE_OK) {
_E("sqlite3_prepare_v2() error - %s(%d)",
sqlite3_errmsg(svc_db), ret);
- __fini();
+ __fini(&svc_db);
return -1;
}
_E("sqlite3_bind_int() error - %s(%d)",
sqlite3_errmsg(svc_db), ret);
sqlite3_finalize(stmt);
- __fini();
+ __fini(&svc_db);
return -1;
}
}
}
sqlite3_finalize(stmt);
- __fini();
+ __fini(&svc_db);
return 0;
}
sqlite3_stmt *stmt = NULL;
const char *query;
const char *value;
+ sqlite3 *svc_db = NULL;
if (appid == NULL) {
_E("Invalid parameter");
return -1;
}
- if (__init(db_uid, false) < 0)
+ if (__init(db_uid, false, &svc_db) < 0)
return -1;
if (enable)
if (ret != SQLITE_OK) {
_E("sqlite3_prepare_v2() error - %s(%d)",
sqlite3_errmsg(svc_db), ret);
- __fini();
+ __fini(&svc_db);
return -1;
}
end:
sqlite3_finalize(stmt);
- __fini();
+ __fini(&svc_db);
return result;
}
const char *alias_id;
const char *id;
struct alias_info_s *info;
+ sqlite3 *svc_db = NULL;
- if (__init(db_uid, true) < 0)
+ if (__init(db_uid, true, &svc_db) < 0)
return -1;
if (db_uid == GLOBAL_USER) {
if (ret != SQLITE_OK) {
_E("sqlite3_prepare_v2() error - %s(%d)",
sqlite3_errmsg(svc_db), ret);
- __fini();
+ __fini(&svc_db);
return -1;
}
_E("sqlite3_bind_text() error - %s(%d)",
sqlite3_errmsg(svc_db), ret);
sqlite3_finalize(stmt);
- __fini();
+ __fini(&svc_db);
return -1;
}
_E("sqlite3_bind_int() error - %s(%d)",
sqlite3_errmsg(svc_db), ret);
sqlite3_finalize(stmt);
- __fini();
+ __fini(&svc_db);
return -1;
}
}
}
sqlite3_finalize(stmt);
- __fini();
+ __fini(&svc_db);
return 0;
}
struct allowed_info_s *info;
GList *list;
GList *iter;
+ sqlite3 *svc_db = NULL;
- if (__init(db_uid, true) < 0)
+ if (__init(db_uid, true, &svc_db) < 0)
return -1;
if (appid) {
if (ret != SQLITE_OK) {
_E("sqlite3_prepare_v2() error - %s(%d)",
sqlite3_errmsg(svc_db), ret);
- __fini();
+ __fini(&svc_db);
return -1;
}
_E("sqlite3_bind_text() error - %s(%d)",
sqlite3_errmsg(svc_db), ret);
sqlite3_finalize(stmt);
- __fini();
+ __fini(&svc_db);
return -1;
}
}
}
sqlite3_finalize(stmt);
- __fini();
+ __fini(&svc_db);
return 0;
}