//#define DB_PATH tzplatform_mkpath(TZ_USER_DB, ".vc_info.db")
static sqlite3* g_db_handle = NULL;
static sqlite3* g_db_backup_handle = NULL;
-static char* g_path = NULL;
-static char* g_backup_path = NULL;
+static char g_path[256] = {0, };
+static char g_backup_path[256] = {0, };
static int g_ref_cnt = 0;
int g_fpid = -1;
return VC_DB_ERROR_NONE;
}
-int __vc_db_open_db_for_daemon(char** path, sqlite3** db_handle)
+static int __vc_db_open_db_for_daemon(const char* path, sqlite3** db_handle)
{
struct stat stat;
- int ret = db_util_open(*path, db_handle, DB_UTIL_REGISTER_HOOK_METHOD);
+ int ret = db_util_open(path, db_handle, DB_UTIL_REGISTER_HOOK_METHOD);
if (ret != SQLITE_OK) {
- SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open db, path = %s, ret(%d)", *path, ret);
+ SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open db, path = %s, ret(%d)", path, ret);
if (db_handle && *db_handle) {
SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Error msg (%s)", sqlite3_errmsg(*db_handle));
db_util_close(*db_handle);
*db_handle = NULL;
}
- free(*path);
- *path = NULL;
return VC_DB_ERROR_OPERATION_FAILED;
}
- if (lstat(*path, &stat) < 0) {
+ if (lstat(path, &stat) < 0) {
char buf_err[256];
SLOG(LOG_ERROR, vc_db_tag(), "%d", strerror_r(errno, buf_err, sizeof(buf_err)));
if (*db_handle)
db_util_close(*db_handle);
*db_handle = NULL;
- free(*path);
- *path = NULL;
return VC_DB_ERROR_OPERATION_FAILED;
}
db_util_close(*db_handle);
*db_handle = NULL;
- free(*path);
- *path = NULL;
return VC_DB_ERROR_OPERATION_FAILED;
}
return VC_DB_ERROR_NONE;
}
-bool __vc_db_connect_db_for_daemon(char** path, sqlite3** db_handle)
+static bool __vc_db_connect_db_for_daemon(const char* path, sqlite3** db_handle)
{
bool is_connect = false;
int ret = __vc_db_open_db_for_daemon(path, db_handle);
g_db_cnt = (g_db_cnt + 1) % 1000;
snprintf(g_path, 256, "%s/.vc_info_%d.db", VC_RUNTIME_INFO_ROOT, g_db_cnt);
}
- bool is_connect = __vc_db_connect_db_for_daemon(&g_path, &g_db_handle);
+ bool is_connect = __vc_db_connect_db_for_daemon(g_path, &g_db_handle);
if (true == is_connect) {
SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect main DB for daemon");
ret = __vc_db_restore_table(g_db_handle, VC_INFO_TABLE);
if (0 != ret) {
SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to create table (%s)", VC_RESULT_TABLE);
}
- is_connect = __vc_db_connect_db_for_daemon(&g_backup_path, &g_db_backup_handle);
+ is_connect = __vc_db_connect_db_for_daemon(g_backup_path, &g_db_backup_handle);
if (true == is_connect) {
SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect backup DB for daemon");
if (0 != vc_db_restore_command()) {
}
/* For voice control DB */
- g_path = (char*)calloc(256, sizeof(char));
- if (NULL == g_path) {
- SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to allocate memory");
- return VC_DB_ERROR_OUT_OF_MEMORY;
- }
/* This should be changed to general DB space - TZ_USER_DB */
snprintf(g_path, 256, "%s/.vc_info.db", VC_RUNTIME_INFO_ROOT);
/* For Backup DB */
- g_backup_path = (char*)calloc(256, sizeof(char));
- if (NULL == g_backup_path) {
- SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to allocate memory");
- return VC_DB_ERROR_OUT_OF_MEMORY;
- }
snprintf(g_backup_path, 256, "%s/.vc_backup.db", VC_RUNTIME_INFO_ROOT);
- bool is_connect = __vc_db_connect_db_for_daemon(&g_path, &g_db_handle);
+ bool is_connect = __vc_db_connect_db_for_daemon(g_path, &g_db_handle);
if (false == is_connect) {
SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to connect main DB, retry to connect after removing");
if (0 != remove(g_path)) {
g_db_cnt = (g_db_cnt + 1) % 1000;
snprintf(g_path, 256, "%s/.vc_info_%d.db", VC_RUNTIME_INFO_ROOT, g_db_cnt);
}
- is_connect = __vc_db_connect_db_for_daemon(&g_path, &g_db_handle);
+ is_connect = __vc_db_connect_db_for_daemon(g_path, &g_db_handle);
if (true == is_connect) {
SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect main DB for daemon");
- is_connect = __vc_db_connect_db_for_daemon(&g_backup_path, &g_db_backup_handle);
+ is_connect = __vc_db_connect_db_for_daemon(g_backup_path, &g_db_backup_handle);
if (true == is_connect) {
SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect backup DB for daemon");
if (0 != vc_db_restore_command()) {
g_db_cnt = (g_db_cnt + 1) % 1000;
snprintf(g_path, 256, "%s/.vc_info_%d.db", VC_RUNTIME_INFO_ROOT, g_db_cnt);
}
- is_connect = __vc_db_connect_db_for_daemon(&g_path, &g_db_handle);
+ is_connect = __vc_db_connect_db_for_daemon(g_path, &g_db_handle);
if (true == is_connect) {
SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect main DB for daemon");
- is_connect = __vc_db_connect_db_for_daemon(&g_backup_path, &g_db_backup_handle);
+ is_connect = __vc_db_connect_db_for_daemon(g_backup_path, &g_db_backup_handle);
if (true == is_connect) {
SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect backup DB for daemon");
if (0 != vc_db_restore_command()) {
return VC_DB_ERROR_NONE;
}
- is_connect = __vc_db_connect_db_for_daemon(&g_backup_path, &g_db_backup_handle);
+ is_connect = __vc_db_connect_db_for_daemon(g_backup_path, &g_db_backup_handle);
if (false == is_connect) {
SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open backup DB, retry to connect after removing file for daemon");
if (0 != remove(g_backup_path)) {
SLOG(LOG_ERROR, vc_db_tag(), "[Error] remove file(%s) is failed", g_backup_path);
snprintf(g_backup_path, 256, "%s/.vc_backup_%d.db", VC_RUNTIME_INFO_ROOT, g_backup_db_cnt);
}
- is_connect = __vc_db_connect_db_for_daemon(&g_path, &g_db_backup_handle);
+ is_connect = __vc_db_connect_db_for_daemon(g_path, &g_db_backup_handle);
if (true == is_connect) {
SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect backup DB for daemon");
if (0 != vc_db_restore_command()) {
return VC_DB_ERROR_NONE;
}
-int __vc_db_open_db(char** path, sqlite3** db_handle)
+static int __vc_db_open_db(const char* path, sqlite3** db_handle)
{
- int ret = db_util_open(*path, db_handle, DB_UTIL_REGISTER_HOOK_METHOD);
+ int ret = db_util_open(path, db_handle, DB_UTIL_REGISTER_HOOK_METHOD);
if (ret != SQLITE_OK) {
- SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open db for daemon, path = %s, ret(%d)", *path, ret);
+ SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open db for daemon, path = %s, ret(%d)", path, ret);
if (db_handle && *db_handle) {
SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Error msg (%s)", sqlite3_errmsg(*db_handle));
db_util_close(*db_handle);
*db_handle = NULL;
}
- free(*path);
- *path = NULL;
return VC_DB_ERROR_OPERATION_FAILED;
}
return VC_DB_ERROR_NONE;
}
-bool __vc_db_connect_db(char** path, sqlite3** db_handle)
+static bool __vc_db_connect_db(const char* path, sqlite3** db_handle)
{
bool is_connect = false;
int ret = __vc_db_open_db(path, db_handle);
}
/* For voice control DB */
- g_path = (char*)calloc(256, sizeof(char));
- if (NULL == g_path) {
- SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to allocate memory");
- return VC_DB_ERROR_OUT_OF_MEMORY;
- }
/* This should be changed to general DB space - TZ_USER_DB */
snprintf(g_path, 256, "%s/.vc_info.db", VC_RUNTIME_INFO_ROOT);
/* For Backup DB */
- g_backup_path = (char*)calloc(256, sizeof(char));
- if (NULL == g_backup_path) {
- SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to allocate memory");
- return VC_DB_ERROR_OUT_OF_MEMORY;
- }
snprintf(g_backup_path, 256, "%s/.vc_backup.db", VC_RUNTIME_INFO_ROOT);
- bool is_connect = __vc_db_connect_db(&g_path, &g_db_handle);
+ bool is_connect = __vc_db_connect_db(g_path, &g_db_handle);
if (false == is_connect) {
SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to connect main DB, retry to connect after removing");
if (0 != remove(g_path)) {
g_db_cnt = (g_db_cnt + 1) % 1000;
snprintf(g_path, 256, "%s/.vc_info_%d.db", VC_RUNTIME_INFO_ROOT, g_db_cnt);
}
- is_connect = __vc_db_connect_db(&g_path, &g_db_handle);
+ is_connect = __vc_db_connect_db(g_path, &g_db_handle);
if (true == is_connect) {
SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect main DB");
- is_connect = __vc_db_connect_db(&g_backup_path, &g_db_backup_handle);
+ is_connect = __vc_db_connect_db(g_backup_path, &g_db_backup_handle);
if (true == is_connect) {
SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect backup DB");
if (0 != vc_db_restore_command()) {
}
}
- is_connect = __vc_db_connect_db(&g_backup_path, &g_db_backup_handle);
+ is_connect = __vc_db_connect_db(g_backup_path, &g_db_backup_handle);
if (false == is_connect) {
SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open backup DB, retry to connect after removing file");
if (0 != remove(g_backup_path)) {
SLOG(LOG_ERROR, vc_db_tag(), "[Error] remove file(%s) is failed", g_backup_path);
snprintf(g_backup_path, 256, "%s/.vc_backup_%d.db", VC_RUNTIME_INFO_ROOT, g_backup_db_cnt);
}
- is_connect = __vc_db_connect_db(&g_path, &g_db_backup_handle);
+ is_connect = __vc_db_connect_db(g_path, &g_db_backup_handle);
if (true == is_connect) {
SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect backup");
if (0 != vc_db_restore_command()) {
if (0 != --g_ref_cnt)
return VC_DB_ERROR_NONE;
- if (NULL != g_path) {
- free(g_path);
- g_path = NULL;
- }
+ memset(g_path, 0, 256);
- if (NULL != g_backup_path) {
- free(g_backup_path);
- g_backup_path = NULL;
- }
+ memset(g_backup_path, 0, 256);
if (!g_db_handle)
return VC_DB_ERROR_NONE;