*/
#define _GNU_SOURCE
+#include <ctype.h>
+#include <linux/limits.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <stdbool.h>
-#include <linux/limits.h>
-#include <ctype.h>
-#include <sqlite3.h>
-#include <glib.h>
#include <bundle.h>
#include <bundle_internal.h>
+#include <glib.h>
+#include <sqlite3.h>
#include <vconf.h>
+#include "aul.h"
+#include "aul_api.h"
#include "aul_comp_info_internal.h"
-#include "aul_util.h"
+#include "aul_db.h"
#include "aul_sock.h"
-#include "aul_api.h"
-#include "aul.h"
+#include "aul_util.h"
-#define ROOT_UID 0
+#define COMPONENT_DB ".component.db"
#define DEFAULT_LOCALE "No Locale"
-#define BUSY_WAITING_USEC 50000
-#define BUSY_WAITING_MAX 40
-
#define AUL_COMPINFO_LOCALIZED_INFO_START 0
#define AUL_COMPINFO_START 0
free(info);
}
-static char *__get_db_path(uid_t uid)
-{
- char db_path[PATH_MAX];
- const char *path;
-
- path = tzplatform_getenv(TZ_SYS_DB);
- if (!path) {
- _E("Failed to get TZ_SYS_DB path");
- return NULL;
- }
-
- if (uid == ROOT_UID || uid == GLOBAL_USER) {
- snprintf(db_path, sizeof(db_path), "%s/.component.db", path);
- } else {
- snprintf(db_path, sizeof(db_path), "%s/user/%u/.component.db",
- path, uid);
- }
-
- return strdup(db_path);
-}
-
-static int __save_column_str(sqlite3_stmt *stmt, int idx, char **str)
-{
- const char *val;
-
- val = (const char *)sqlite3_column_text(stmt, idx);
- if (val) {
- *str = strdup(val);
- if (*str == NULL) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
- }
-
- return AUL_R_OK;
-}
-
static bool __get_boolean_value(const char *str)
{
if (str && !strcmp(str, "true"))
return false;
}
-static int __db_busy_handler(void *data, int count)
-{
- if (count < BUSY_WAITING_MAX) {
- usleep(BUSY_WAITING_USEC);
- return 1;
- }
-
- LOGE("Database is busy");
-
- return 0;
-}
-
-static sqlite3 *__open_db(const char *path)
+static sqlite3 *__open_component_db(uid_t uid)
{
- sqlite3 *db = NULL;
- int ret;
+ sqlite3 *db;
+ char *path;
- ret = sqlite3_open_v2(path, &db, SQLITE_OPEN_READONLY, NULL);
- if (ret != SQLITE_OK) {
- LOGE("sqlite3_open_v2() is failed. error(%d)", ret);
- if (db)
- sqlite3_close_v2(db);
+ path = aul_db_get_path(COMPONENT_DB, uid);
+ if (!path) {
+ _E("Failed to get db path");
return NULL;
}
- ret = sqlite3_busy_handler(db, __db_busy_handler, NULL);
- if (ret != SQLITE_OK) {
- LOGE("Failed to register busy handler. error(%s)",
- sqlite3_errmsg(db));
- sqlite3_close_v2(db);
- return NULL;
- }
+ db = aul_db_open(path, true);
+ free(path);
return db;
}
+static void __close_component_db(sqlite3 *db)
+{
+ aul_db_close(db);
+}
+
static void __destroy_compinfo(gpointer data)
{
struct aul_compinfo_s *info = (struct aul_compinfo_s *)data;
sqlite3_stmt *stmt = NULL;
sqlite3 *db;
char *query;
- char *db_path;
int value_idx;
int idx;
struct aul_compinfo_s *info;
int ret;
- db_path = __get_db_path(uid);
- if (!db_path) {
- _E("Failed to get db path");
- return AUL_R_ENOMEM;
- }
-
- db = __open_db(db_path);
+ db = __open_component_db(uid);
if (!db) {
- _E("Failed to open db(%s)", db_path);
- free(db_path);
+ _E("Failed to open component db. uid(%u)", uid);
return AUL_R_ERROR;
}
- free(db_path);
query = sqlite3_mprintf(query_raw, comp_id);
if (!query) {
for (idx = AUL_COMPINFO_START; idx < AUL_COMPINFO_MAX - 1; idx++) {
value_idx = (idx < AUL_COMPINFO_COMP_ID) ? idx : idx + 1;
- ret = __save_column_str(stmt, idx, &info->value[value_idx]);
+ ret = aul_db_save_column_str(stmt, idx,
+ &info->value[value_idx]);
if (ret != AUL_R_OK) {
__destroy_compinfo(info);
goto end;
end:
sqlite3_finalize(stmt);
sqlite3_free(query);
- sqlite3_close_v2(db);
+ __close_component_db(db);
return ret;
}
"FROM component_info";
sqlite3_stmt *stmt = NULL;
sqlite3 *db;
- char *db_path;
int idx;
struct aul_compinfo_s *info;
int ret;
- db_path = __get_db_path(uid);
- if (!db_path) {
- _E("Failed to get db path");
- return AUL_R_ENOMEM;
- }
-
- db = __open_db(db_path);
+ db = __open_component_db(uid);
if (!db) {
- _E("Failed to open db(%s)", db_path);
- free(db_path);
+ _E("Failed to open component db. uid(%u)", uid);
return AUL_R_ERROR;
}
- free(db_path);
ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
if (ret != SQLITE_OK) {
}
for (idx = AUL_COMPINFO_START; idx < AUL_COMPINFO_MAX; idx++) {
- ret = __save_column_str(stmt, idx, &info->value[idx]);
+ ret = aul_db_save_column_str(stmt, idx,
+ &info->value[idx]);
if (ret != AUL_R_OK) {
__destroy_compinfo(info);
g_list_free_full(*list, __destroy_compinfo);
end:
sqlite3_finalize(stmt);
- sqlite3_close_v2(db);
+ __close_component_db(db);
return ret;
}
sqlite3_stmt *stmt = NULL;
sqlite3 *db;
char *query;
- char *db_path;
int idx;
struct aul_compinfo_localized_info_s *info;
int ret;
- db_path = __get_db_path(uid);
- if (!db_path) {
- _E("Failed to get db path");
- return AUL_R_ENOMEM;
- }
-
- db = __open_db(db_path);
+ db = __open_component_db(uid);
if (!db) {
- _E("Failed to open db(%s)", db_path);
- free(db_path);
+ _E("Failed to open component db. uid(%u)", uid);
return AUL_R_ERROR;
}
- free(db_path);
query = sqlite3_mprintf(query_raw, comp_id);
if (!query) {
for (idx = AUL_COMPINFO_LOCALIZED_INFO_START;
idx < AUL_COMPINFO_LOCALIZED_INFO_MAX;
idx++) {
- ret = __save_column_str(stmt, idx, &info->value[idx]);
+ ret = aul_db_save_column_str(stmt, idx,
+ &info->value[idx]);
if (ret != AUL_R_OK) {
__destroy_compinfo_localized_info(info);
g_list_free_full(*list,
end:
sqlite3_finalize(stmt);
sqlite3_free(query);
- sqlite3_close_v2(db);
+ __close_component_db(db);
return ret;
}