From: saerome.kim Date: Tue, 30 Jul 2019 01:29:12 +0000 (+0900) Subject: Removed redundant codes related to DB management. X-Git-Tag: accepted/tizen/unified/20190730.224309~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0094e87e262f7af16ccbdc3527f1c94a9cce7c72;p=platform%2Fcore%2Fconnectivity%2Fua-manager.git Removed redundant codes related to DB management. Change-Id: Id8bc6dc853c9e20559f8b5bbfd172e2e829149f5 Signed-off-by: saerome.kim --- diff --git a/ua-daemon/include/ua-manager-database.h b/ua-daemon/include/ua-manager-database.h index d3760d1..bb81032 100644 --- a/ua-daemon/include/ua-manager-database.h +++ b/ua-daemon/include/ua-manager-database.h @@ -32,6 +32,73 @@ extern "C" { #define DATABASE_FULL_PATH "/opt/usr/dbspace/.ua-manager-data.db" #endif +/* Helper macros */ +#define EXEC(error_code, command, handle_error) do { \ + if (error_code != command) { \ + FUNC_EXIT; \ + goto handle_error; \ + } \ +} while (0) + +#define PREPARE_DELETE(rc, db, stm, query, finalize) do { \ + rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ + if (rc != SQLITE_OK) { \ + stm = NULL; \ + finalize(); \ + UAM_ERR("Failed to prepare \"%s\" query" \ + , query); \ + return rc; \ + } \ +} while (0) + +#define PREPARE_SELECT(rc, db, stm, query, finalize) do { \ + rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ + if (rc != SQLITE_OK) { \ + stm = NULL; \ + finalize(); \ + UAM_ERR("Failed to prepare \"%s\" query" \ + , query); \ + return rc; \ + } \ +} while (0) + +#define PREPARE_UPDATE(rc, db, stm, query, finalize) do { \ + rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ + if (rc != SQLITE_OK) { \ + stm = NULL; \ + finalize(); \ + UAM_ERR("Failed to prepare \"%s\" query" \ + , query); \ + return rc; \ + } \ +} while (0) + +#define PREPARE_INSERT(rc, db, stm, query, finalize) do { \ + rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ + if (rc != SQLITE_OK) { \ + stm = NULL; \ + finalize(); \ + UAM_ERR("Failed to prepare \"%s\" query" \ + , query); \ + return rc; \ + } \ +} while (0) + +#define FINALIZE(stm) do { \ + if (stm) { \ + sqlite3_finalize(stm); \ + stm = NULL; \ + } \ +} while (0) + +#define DB_ACTION(command, error_code, handle_error) do { \ + if ((command) != SQLITE_OK) { \ + error_code = UAM_ERROR_DB_FAILED; \ + FUNC_EXIT; \ + goto handle_error; \ + } \ +} while (0) + /* Helper Functions */ int _ua_db_initialize_once(void); @@ -73,27 +140,29 @@ int _ua_device_db_deinitialize(void); /* select operations */ GSList *_ua_device_db_get_all_devices(void); -int _ua_device_db_get_device(char *device_id, int tech_type, char *address, - db_device_info_t *info); -int _uam_db_get_device_number(const char *device_id, int tech_type, const char *address, int *device_number); +int _ua_device_db_get_device( + char *device_id, int tech_type, char *address, db_device_info_t *info); +int _uam_db_get_device_number( + const char *device_id, int tech_type, const char *address, int *device_number); /* delete operations */ int _ua_device_db_clear(void); -int _ua_device_db_delete_device_info(const char *device_id, int tech_type, const char *address); +int _ua_device_db_delete_device_info( + const char *device_id, int tech_type, const char *address); /* insert */ -int _ua_device_db_insert_device_info(int user_id, const uam_device_info_s *dev_info, - int presence_state, long timestamp); +int _ua_device_db_insert_device_info( + int user_id, const uam_device_info_s *dev_info, int presence_state, long timestamp); /* update */ -int _ua_device_db_update_device_timestamp(char *device_id, int tech_type, - char *address, long timestamp); -int _ua_device_db_update_device_presence(char *device_id, int tech_type, char *address, - int presence_state); -int _ua_device_db_update_device_ip_address(char *device_id, int tech_type, char *address, - char *ip_address); -int _ua_device_db_update_device_discriminant(char *device_id, int tech_type, - char *address, char discriminant); +int _ua_device_db_update_device_timestamp( + char *device_id, int tech_type, char *address, long timestamp); +int _ua_device_db_update_device_presence( + char *device_id, int tech_type, char *address, int presence_state); +int _ua_device_db_update_device_ip_address( + char *device_id, int tech_type, char *address, char *ip_address); +int _ua_device_db_update_device_discriminant( + char *device_id, int tech_type, char *address, char discriminant); /* SERVICE QUERIES */ typedef struct { @@ -115,7 +184,8 @@ int _uam_db_delete_service_info(const char *service_name); int _ua_service_db_clear(void); /* insert */ -int _uam_db_insert_service_info(int *service_number, const char *service_name, int cycle); +int _uam_db_insert_service_info( + int *service_number, const char *service_name, int cycle); /* update */ int _uam_db_update_service_cycle(const char *service_name, int cycle); @@ -129,12 +199,14 @@ int _ua_device_service_db_deinitialize(void); /* select operations */ GSList *_uam_db_get_service(int device_number); -GSList *_uam_db_get_device_services(const char *device_id, int tech_type, const char *address); +GSList *_uam_db_get_device_services( + const char *device_id, int tech_type, const char *address); /* delete operations */ int _ua_device_service_db_clear(void); int _uam_db_delete_service_number(int service_number); -int _uam_db_delete_device_service_number(int device_number, int service_number); +int _uam_db_delete_device_service_number( + int device_number, int service_number); int _uam_db_delete_device_service(const char *service_name); int _uam_db_delete_device_service_info(const char *device_id, int tech_type, const char *address, const char *service_name); @@ -142,8 +214,7 @@ int _uam_db_delete_device_service_info(const char *device_id, int tech_type, /* insert */ int _uam_db_insert_service(int device_number, int service_number); int _uam_db_insert_device_service_info(const char *device_id, int tech_type, - const char *address, const char *service_name, int cycle); - + const char *address, const char *service_name, int cycle); #ifdef __cplusplus } diff --git a/ua-daemon/src/ua-manager-db.c b/ua-daemon/src/ua-manager-db.c index a39f6c3..20b5ca1 100644 --- a/ua-daemon/src/ua-manager-db.c +++ b/ua-daemon/src/ua-manager-db.c @@ -78,26 +78,30 @@ static int __ua_db_busy(void *user, int attempts) return 1; } -static int __uam_db_check_integrity_cb(void *err, int count, char **data, char **columns) +static int __uam_db_check_integrity_cb( + void *err, int count, char **data, char **columns) { FUNC_ENTRY; int i; for (i = 0; i < count; i++) { UAM_DBG("%s = %s\n", columns[i], data[i] ? data[i] : "NULL"); - if (!g_strcmp0(columns[i], "integrity_check") && !g_strcmp0(data[i], "ok")) return 0; + if (!g_strcmp0(columns[i], "integrity_check") && !g_strcmp0(data[i], "ok")) + return 0; } return 1; } -static int __uam_db_check_table_cb(void *err, int count, char **data, char **columns) +static int __uam_db_check_table_cb( + void *err, int count, char **data, char **columns) { FUNC_ENTRY; int i; for (i = 0; i < count; i++) { UAM_DBG("%s = %s\n", columns[i], data[i] ? data[i] : "NULL"); - if (!g_strcmp0(columns[i], "count") && !g_strcmp0(data[i], "1")) return 0; + if (!g_strcmp0(columns[i], "count") && !g_strcmp0(data[i], "1")) + return 0; } return 1; } @@ -110,7 +114,8 @@ static int __check_integrity(void) res = sqlite3_open(DATABASE_FULL_PATH, &database); if (res != SQLITE_OK) { - UAM_ERR("Error in opening database %s: %s", DATABASE_FULL_PATH, sqlite3_errmsg(database)); + UAM_ERR("Error in opening database %s: %s", + DATABASE_FULL_PATH, sqlite3_errmsg(database)); FUNC_EXIT; return UAM_ERROR_DB_FAILED; } @@ -307,7 +312,7 @@ int _ua_db_initialize_once(void) char *error = NULL; sql_ret = sqlite3_open_v2(DATABASE_FULL_PATH, &(database), - SQLITE_OPEN_FULLMUTEX | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); + SQLITE_OPEN_FULLMUTEX | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); if (SQLITE_OK != sql_ret) { UAM_ERR("sqlite3_open_v2 failed, (%d)", sql_ret); return UAM_ERROR_DB_FAILED; diff --git a/ua-daemon/src/ua-manager-device-db.c b/ua-daemon/src/ua-manager-device-db.c index d256e55..8fe6490 100644 --- a/ua-daemon/src/ua-manager-device-db.c +++ b/ua-daemon/src/ua-manager-device-db.c @@ -27,11 +27,15 @@ #define SELECT_ALL_DEVICES "SELECT device_id, tech_type, address, " \ "ip_address, timestamp, presence_state, os_type, " \ "user_id, discriminant FROM devices" + #define SELECT_DEVICE "SELECT device_id, tech_type, address, " \ "ip_address, timestamp, presence_state, os_type, " \ - "user_id, discriminant FROM devices WHERE device_id = ? AND tech_type = ? AND address = ?" + "user_id, discriminant FROM devices WHERE device_id = ? AND tech_type = ? " \ + "AND address = ?" + #define SELECT_DEVICE_NUMBER "SELECT device_number FROM devices " \ "WHERE device_id = ? AND tech_type = ? AND address = ?" + #define SELECT_MAX_DEVICE_NUMBER "SELECT MAX(device_number) FROM devices" #define INSERT_DEVICE "insert into devices " \ @@ -41,10 +45,13 @@ #define UPDATE_TIMESTAMP "UPDATE devices " \ "SET timestamp = ? WHERE device_id = ? AND tech_type = ? AND address = ?" + #define UPDATE_PRESENCE "UPDATE devices " \ "SET presence_state = ? WHERE device_id = ? AND tech_type = ? AND address = ?" + #define UPDATE_IP_ADDRESS "UPDATE devices " \ "SET ip_address = ? WHERE device_id = ? AND tech_type = ? AND address = ?" + #define UPDATE_DISCRIMINANT "UPDATE devices " \ "SET discriminant = ? WHERE device_id = ? AND tech_type = ? AND address = ?" @@ -53,86 +60,8 @@ #define DELETE_DEVICE_INFO "delete from devices " \ "WHERE device_id = ? AND tech_type = ? AND address = ?" -#ifndef DATABASE_FULL_PATH -#define DATABASE_FULL_PATH "/opt/usr/dbspace/.ua-manager-data.db" -#endif - -#define SQLITE_BUSY_TIMEOUT 500000 - static void __ua_device_finalize_delete(void); -#define EXEC(error_code, command) do { \ - if (error_code != command) { \ - FUNC_EXIT; \ - goto handle_error; \ - } \ -} while (0) - -#define PREPARE_DELETE(stm, query) do { \ - rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ - if (rc != SQLITE_OK) { \ - stm = NULL; \ - __ua_device_finalize_delete(); \ - UAM_ERR("Failed to prepare \"%s\" query" \ - , query); \ - return rc; \ - } \ -} while (0) - -static void __ua_device_finalize_select(void); - -#define PREPARE_SELECT(stm, query) do { \ - rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ - if (rc != SQLITE_OK) { \ - stm = NULL; \ - __ua_device_finalize_select(); \ - UAM_ERR("Failed to prepare \"%s\" query" \ - , query); \ - return rc; \ - } \ -} while (0) - -static void _ua_device_finalize_update(void); - -#define PREPARE_UPDATE(stm, query) do { \ - rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ - if (rc != SQLITE_OK) { \ - stm = NULL; \ - _ua_device_finalize_update(); \ - UAM_ERR("Failed to prepare \"%s\" query" \ - , query); \ - return rc; \ - } \ -} while (0) - -static void __ua_device_finalize_insert(void); - -#define PREPARE_INSERT(stm, query) do { \ - rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ - if (rc != SQLITE_OK) { \ - stm = NULL; \ - __ua_device_finalize_insert(); \ - UAM_ERR("Failed to prepare \"%s\" query" \ - , query); \ - return rc; \ - } \ -} while (0) - -#define FINALIZE(stm) do { \ - if (stm) { \ - sqlite3_finalize(stm); \ - stm = NULL; \ - } \ -} while (0) - -#define DB_ACTION(command) do { \ - if ((command) != SQLITE_OK) { \ - error_code = UAM_ERROR_DB_FAILED; \ - FUNC_EXIT; \ - goto handle_error; \ - } \ -} while (0) - /* DELETE statements */ static sqlite3_stmt *delete_all_devices; static sqlite3_stmt *delete_device_info; @@ -155,6 +84,49 @@ static sqlite3_stmt *insert_device_info; extern sqlite3 *database; static int max_device_number; +static void __ua_device_finalize_delete(void) +{ + FUNC_ENTRY; + + FINALIZE(delete_all_devices); + FINALIZE(delete_device_info); + + FUNC_EXIT; +} + +static void __ua_device_finalize_select(void) +{ + FUNC_ENTRY; + + FINALIZE(select_all_devices); + FINALIZE(select_device); + FINALIZE(select_device_number); + FINALIZE(select_max_device_number); + + FUNC_EXIT; +} + +static void __ua_device_finalize_insert(void) +{ + FUNC_ENTRY; + + FINALIZE(insert_device_info); + + FUNC_EXIT; +} + +static void __ua_device_finalize_update(void) +{ + FUNC_ENTRY; + + FINALIZE(update_timestamp); + FINALIZE(update_presence); + FINALIZE(update_ip_address); + FINALIZE(update_discriminant); + + FUNC_EXIT; +} + static int __ua_device_prepare_delete(sqlite3 *db) { FUNC_ENTRY; @@ -166,8 +138,10 @@ static int __ua_device_prepare_delete(sqlite3 *db) return SQLITE_OK; } - PREPARE_DELETE(delete_all_devices, DELETE_ALL_DEVICES); - PREPARE_DELETE(delete_device_info, DELETE_DEVICE_INFO); + PREPARE_DELETE(rc, db, delete_all_devices, + DELETE_ALL_DEVICES, __ua_device_finalize_delete); + PREPARE_DELETE(rc, db, delete_device_info, + DELETE_DEVICE_INFO, __ua_device_finalize_delete); initialized = 1; FUNC_EXIT; @@ -185,10 +159,14 @@ static int __ua_device_prepare_select(sqlite3 *db) return SQLITE_OK; } - PREPARE_SELECT(select_all_devices, SELECT_ALL_DEVICES); - PREPARE_SELECT(select_device, SELECT_DEVICE); - PREPARE_SELECT(select_device_number, SELECT_DEVICE_NUMBER); - PREPARE_SELECT(select_max_device_number, SELECT_MAX_DEVICE_NUMBER); + PREPARE_SELECT(rc, db, select_all_devices, + SELECT_ALL_DEVICES, __ua_device_finalize_select); + PREPARE_SELECT(rc, db, select_device, + SELECT_DEVICE, __ua_device_finalize_select); + PREPARE_SELECT(rc, db, select_device_number, + SELECT_DEVICE_NUMBER, __ua_device_finalize_select); + PREPARE_SELECT(rc, db, select_max_device_number, + SELECT_MAX_DEVICE_NUMBER, __ua_device_finalize_select); initialized = 1; FUNC_EXIT; @@ -206,10 +184,14 @@ static int __ua_device_prepare_update(sqlite3 *db) return SQLITE_OK; } - PREPARE_UPDATE(update_timestamp, UPDATE_TIMESTAMP); - PREPARE_UPDATE(update_presence, UPDATE_PRESENCE); - PREPARE_UPDATE(update_ip_address, UPDATE_IP_ADDRESS); - PREPARE_UPDATE(update_discriminant, UPDATE_DISCRIMINANT); + PREPARE_UPDATE(rc, db, update_timestamp, + UPDATE_TIMESTAMP, __ua_device_finalize_update); + PREPARE_UPDATE(rc, db, update_presence, + UPDATE_PRESENCE, __ua_device_finalize_update); + PREPARE_UPDATE(rc, db, update_ip_address, + UPDATE_IP_ADDRESS, __ua_device_finalize_update); + PREPARE_UPDATE(rc, db, update_discriminant, + UPDATE_DISCRIMINANT, __ua_device_finalize_update); initialized = 1; FUNC_EXIT; @@ -227,7 +209,8 @@ static int __ua_device_prepare_insert(sqlite3 *db) return SQLITE_OK; } - PREPARE_INSERT(insert_device_info, INSERT_DEVICE); + PREPARE_INSERT(rc, db, insert_device_info, + INSERT_DEVICE, __ua_device_finalize_insert); initialized = 1; FUNC_EXIT; @@ -245,10 +228,10 @@ static int __ua_device_table_devicesinfo_prepare(sqlite3 *db) return UAM_ERROR_DB_FAILED; } - DB_ACTION(__ua_device_prepare_delete(db)); - DB_ACTION(__ua_device_prepare_select(db)); - DB_ACTION(__ua_device_prepare_update(db)); - DB_ACTION(__ua_device_prepare_insert(db)); + DB_ACTION(__ua_device_prepare_delete(db), error_code, handle_error); + DB_ACTION(__ua_device_prepare_select(db), error_code, handle_error); + DB_ACTION(__ua_device_prepare_update(db), error_code, handle_error); + DB_ACTION(__ua_device_prepare_insert(db), error_code, handle_error); handle_error: @@ -256,49 +239,6 @@ handle_error: return error_code; } -static void __ua_device_finalize_delete(void) -{ - FUNC_ENTRY; - - FINALIZE(delete_all_devices); - FINALIZE(delete_device_info); - - FUNC_EXIT; -} - -static void __ua_device_finalize_select(void) -{ - FUNC_ENTRY; - - FINALIZE(select_all_devices); - FINALIZE(select_device); - FINALIZE(select_device_number); - FINALIZE(select_max_device_number); - - FUNC_EXIT; -} - -static void __ua_device_finalize_insert(void) -{ - FUNC_ENTRY; - - FINALIZE(insert_device_info); - - FUNC_EXIT; -} - -static void _ua_device_finalize_update(void) -{ - FUNC_ENTRY; - - FINALIZE(update_timestamp); - FINALIZE(update_presence); - FINALIZE(update_ip_address); - FINALIZE(update_discriminant); - - FUNC_EXIT; -} - static void __ua_device_table_devicesinfo_finalize(void) { FUNC_ENTRY; @@ -362,7 +302,7 @@ int _ua_device_db_initialize(void) { FUNC_ENTRY; - EXEC(UAM_ERROR_NONE, __ua_device_table_devicesinfo_prepare(database)); + EXEC(UAM_ERROR_NONE, __ua_device_table_devicesinfo_prepare(database), handle_error); if (_uam_db_get_max_device_number() != UAM_ERROR_NONE) goto handle_error; @@ -375,7 +315,8 @@ handle_error: return UAM_ERROR_DB_FAILED; } -int _ua_device_db_update_device_ip_address(char *device_id, int tech_type, char *address, +int _ua_device_db_update_device_ip_address(char *device_id, int tech_type, + char *address, char *ip_address) { int error_code = UAM_ERROR_NONE; @@ -385,10 +326,14 @@ int _ua_device_db_update_device_ip_address(char *device_id, int tech_type, char retv_if(NULL == address, UAM_ERROR_INVALID_PARAMETER); retv_if(NULL == ip_address, UAM_ERROR_INVALID_PARAMETER); - DB_ACTION(sqlite3_bind_text(stmt, 1, ip_address, -1, SQLITE_TRANSIENT)); - DB_ACTION(sqlite3_bind_text(stmt, 2, device_id, -1, SQLITE_TRANSIENT)); - DB_ACTION(sqlite3_bind_int(stmt, 3, tech_type)); - DB_ACTION(sqlite3_bind_text(stmt, 4, address, -1, SQLITE_TRANSIENT)); + DB_ACTION(sqlite3_bind_text(stmt, 1, ip_address, -1, SQLITE_TRANSIENT), + error_code, handle_error); + DB_ACTION(sqlite3_bind_text(stmt, 2, device_id, -1, SQLITE_TRANSIENT), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 3, tech_type), + error_code, handle_error); + DB_ACTION(sqlite3_bind_text(stmt, 4, address, -1, SQLITE_TRANSIENT), + error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to update ip address: %s", @@ -405,8 +350,8 @@ handle_error: return error_code; } -int _ua_device_db_update_device_presence(char *device_id, int tech_type, char *address, - int presence_state) +int _ua_device_db_update_device_presence(char *device_id, int tech_type, + char *address, int presence_state) { int error_code = UAM_ERROR_NONE; sqlite3_stmt *stmt = update_presence; @@ -414,10 +359,14 @@ int _ua_device_db_update_device_presence(char *device_id, int tech_type, char *a retv_if(NULL == device_id, UAM_ERROR_INVALID_PARAMETER); retv_if(NULL == address, UAM_ERROR_INVALID_PARAMETER); - DB_ACTION(sqlite3_bind_int(stmt, 1, presence_state)); - DB_ACTION(sqlite3_bind_text(stmt, 2, device_id, -1, SQLITE_TRANSIENT)); - DB_ACTION(sqlite3_bind_int(stmt, 3, tech_type)); - DB_ACTION(sqlite3_bind_text(stmt, 4, address, -1, SQLITE_TRANSIENT)); + DB_ACTION(sqlite3_bind_int(stmt, 1, presence_state), + error_code, handle_error); + DB_ACTION(sqlite3_bind_text(stmt, 2, device_id, -1, SQLITE_TRANSIENT), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 3, tech_type), + error_code, handle_error); + DB_ACTION(sqlite3_bind_text(stmt, 4, address, -1, SQLITE_TRANSIENT), + error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to update presence: %s", @@ -443,10 +392,14 @@ int _ua_device_db_update_device_timestamp(char *device_id, int tech_type, retv_if(NULL == device_id, UAM_ERROR_INVALID_PARAMETER); retv_if(NULL == address, UAM_ERROR_INVALID_PARAMETER); - DB_ACTION(sqlite3_bind_int64(stmt, 1, timestamp)); - DB_ACTION(sqlite3_bind_text(stmt, 2, device_id, -1, SQLITE_TRANSIENT)); - DB_ACTION(sqlite3_bind_int(stmt, 3, tech_type)); - DB_ACTION(sqlite3_bind_text(stmt, 4, address, -1, SQLITE_TRANSIENT)); + DB_ACTION(sqlite3_bind_int64(stmt, 1, timestamp), + error_code, handle_error); + DB_ACTION(sqlite3_bind_text(stmt, 2, device_id, -1, SQLITE_TRANSIENT), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 3, tech_type), + error_code, handle_error); + DB_ACTION(sqlite3_bind_text(stmt, 4, address, -1, SQLITE_TRANSIENT), + error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to update device timestamp: %s", @@ -472,10 +425,14 @@ int _ua_device_db_update_device_discriminant(char *device_id, int tech_type, retv_if(NULL == device_id, UAM_ERROR_INVALID_PARAMETER); retv_if(NULL == address, UAM_ERROR_INVALID_PARAMETER); - DB_ACTION(sqlite3_bind_int(stmt, 1, discriminant)); - DB_ACTION(sqlite3_bind_text(stmt, 2, device_id, -1, SQLITE_TRANSIENT)); - DB_ACTION(sqlite3_bind_int(stmt, 3, tech_type)); - DB_ACTION(sqlite3_bind_text(stmt, 4, address, -1, SQLITE_TRANSIENT)); + DB_ACTION(sqlite3_bind_int(stmt, 1, discriminant), + error_code, handle_error); + DB_ACTION(sqlite3_bind_text(stmt, 2, device_id, -1, SQLITE_TRANSIENT), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 3, tech_type), + error_code, handle_error); + DB_ACTION(sqlite3_bind_text(stmt, 4, address, -1, SQLITE_TRANSIENT), + error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to update device discriminant: %s", @@ -492,8 +449,8 @@ handle_error: return error_code; } -int _ua_device_db_insert_device_info(int user_id, const uam_device_info_s *dev_info, - int presence_state, long timestamp) +int _ua_device_db_insert_device_info(int user_id, + const uam_device_info_s *dev_info, int presence_state, long timestamp) { FUNC_ENTRY; int error_code = UAM_ERROR_NONE; @@ -506,16 +463,26 @@ int _ua_device_db_insert_device_info(int user_id, const uam_device_info_s *dev_i timestamp, presence_state, dev_info->operating_system, dev_info->discriminant, user_id); - DB_ACTION(sqlite3_bind_text(stmt, 1, dev_info->device_id, -1, SQLITE_TRANSIENT)); - DB_ACTION(sqlite3_bind_int(stmt, 2, dev_info->type)); - DB_ACTION(sqlite3_bind_text(stmt, 3, dev_info->mac, -1, SQLITE_TRANSIENT)); - DB_ACTION(sqlite3_bind_text(stmt, 4, dev_info->ipv4_addr, -1, SQLITE_TRANSIENT)); - DB_ACTION(sqlite3_bind_int64(stmt, 5, timestamp)); - DB_ACTION(sqlite3_bind_int(stmt, 6, presence_state)); - DB_ACTION(sqlite3_bind_int(stmt, 7, dev_info->operating_system)); - DB_ACTION(sqlite3_bind_int(stmt, 8, user_id)); - DB_ACTION(sqlite3_bind_int(stmt, 9, dev_info->discriminant)); - DB_ACTION(sqlite3_bind_int(stmt, 10, max_device_number + 1)); + DB_ACTION(sqlite3_bind_text(stmt, 1, dev_info->device_id, -1, SQLITE_TRANSIENT), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 2, dev_info->type), + error_code, handle_error); + DB_ACTION(sqlite3_bind_text(stmt, 3, dev_info->mac, -1, SQLITE_TRANSIENT), + error_code, handle_error); + DB_ACTION(sqlite3_bind_text(stmt, 4, dev_info->ipv4_addr, -1, SQLITE_TRANSIENT), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int64(stmt, 5, timestamp), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 6, presence_state), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 7, dev_info->operating_system), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 8, user_id), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 9, dev_info->discriminant), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 10, max_device_number + 1), + error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to insert device info: %s", @@ -524,7 +491,8 @@ int _ua_device_db_insert_device_info(int user_id, const uam_device_info_s *dev_i goto handle_error; } - UAM_DBG("Device info inserted device_id [%s] user id [%d]", dev_info->device_id, user_id); + UAM_DBG("Device info inserted device_id [%s] user id [%d]", + dev_info->device_id, user_id); max_device_number = max_device_number + 1; handle_error: @@ -533,7 +501,8 @@ handle_error: return error_code; } -int _ua_device_db_delete_device_info(const char *device_id, int tech_type, const char *address) +int _ua_device_db_delete_device_info(const char *device_id, int tech_type, + const char *address) { FUNC_ENTRY; int error_code = UAM_ERROR_NONE; @@ -541,9 +510,12 @@ int _ua_device_db_delete_device_info(const char *device_id, int tech_type, const UAM_INFO("DeviceId: %s", device_id); - DB_ACTION(sqlite3_bind_text(stmt, 1, device_id, -1, SQLITE_STATIC)); - DB_ACTION(sqlite3_bind_int(stmt, 2, tech_type)); - DB_ACTION(sqlite3_bind_text(stmt, 3, address, -1, SQLITE_STATIC)); + DB_ACTION(sqlite3_bind_text(stmt, 1, device_id, -1, SQLITE_STATIC), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 2, tech_type), + error_code, handle_error); + DB_ACTION(sqlite3_bind_text(stmt, 3, address, -1, SQLITE_STATIC), + error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to delete device info %s", @@ -569,9 +541,12 @@ int _ua_device_db_get_device(char *device_id, int tech_type, char *address, UAM_INFO("UserId: %s", device_id); - DB_ACTION(sqlite3_bind_text(stmt, 1, device_id, -1, SQLITE_STATIC)); - DB_ACTION(sqlite3_bind_int(stmt, 2, tech_type)); - DB_ACTION(sqlite3_bind_text(stmt, 3, address, -1, SQLITE_STATIC)); + DB_ACTION(sqlite3_bind_text(stmt, 1, device_id, -1, SQLITE_STATIC), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 2, tech_type), + error_code, handle_error); + DB_ACTION(sqlite3_bind_text(stmt, 3, address, -1, SQLITE_STATIC), + error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to select device info %s", @@ -580,20 +555,29 @@ int _ua_device_db_get_device(char *device_id, int tech_type, char *address, } else { UAM_DBG("User info found"); info = g_new0(db_device_info_t, 1); - g_strlcpy(info->dev_info.device_id, (char *)sqlite3_column_text(stmt, 0), UAM_DEVICE_ID_MAX_STRING_LEN); + g_strlcpy(info->dev_info.device_id, (char *)sqlite3_column_text(stmt, 0), + UAM_DEVICE_ID_MAX_STRING_LEN); info->dev_info.type = sqlite3_column_int(stmt, 1); - g_strlcpy(info->dev_info.mac, (char *)sqlite3_column_text(stmt, 2), UAM_MAC_ADDRESS_STRING_LEN); - g_strlcpy(info->dev_info.ipv4_addr, (char *)sqlite3_column_text(stmt, 3), UAM_IP_ADDRESS_MAX_STRING_LEN); + g_strlcpy(info->dev_info.mac, (char *)sqlite3_column_text(stmt, 2), + UAM_MAC_ADDRESS_STRING_LEN); + g_strlcpy(info->dev_info.ipv4_addr, (char *)sqlite3_column_text(stmt, 3), + UAM_IP_ADDRESS_MAX_STRING_LEN); info->timestamp = sqlite3_column_int64(stmt, 4); info->presence_state = sqlite3_column_int(stmt, 5); info->dev_info.operating_system = sqlite3_column_int(stmt, 6); info->user_id = sqlite3_column_int(stmt, 7); info->discriminant = sqlite3_column_int(stmt, 8); - UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d-%d", info->dev_info.device_id, info->dev_info.type, info->dev_info.mac, - info->dev_info.ipv4_addr, info->timestamp, info->presence_state, - info->dev_info.operating_system, info->user_id, - info->discriminant); + UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d-%d", + info->dev_info.device_id, + info->dev_info.type, + info->dev_info.mac, + info->dev_info.ipv4_addr, + info->timestamp, + info->presence_state, + info->dev_info.operating_system, + info->user_id, + info->discriminant); } handle_error: @@ -602,7 +586,8 @@ handle_error: return error_code; } -int _uam_db_get_device_number(const char *device_id, int tech_type, const char *address, int *device_number) +int _uam_db_get_device_number(const char *device_id, int tech_type, + const char *address, int *device_number) { FUNC_ENTRY; int rc; @@ -614,9 +599,12 @@ int _uam_db_get_device_number(const char *device_id, int tech_type, const char * UAM_INFO("UserId: %s", device_id); - DB_ACTION(sqlite3_bind_text(stmt, 1, device_id, -1, SQLITE_STATIC)); - DB_ACTION(sqlite3_bind_int(stmt, 2, tech_type)); - DB_ACTION(sqlite3_bind_text(stmt, 3, address, -1, SQLITE_STATIC)); + DB_ACTION(sqlite3_bind_text(stmt, 1, device_id, -1, SQLITE_STATIC), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 2, tech_type), + error_code, handle_error); + DB_ACTION(sqlite3_bind_text(stmt, 3, address, -1, SQLITE_STATIC), + error_code, handle_error); do { rc = sqlite3_step(stmt); @@ -658,20 +646,29 @@ GSList *_ua_device_db_get_all_devices(void) break; case SQLITE_ROW: info = g_new0(db_device_info_t, 1); - g_strlcpy(info->dev_info.device_id, (char *)sqlite3_column_text(stmt, 0), UAM_DEVICE_ID_MAX_STRING_LEN); + g_strlcpy(info->dev_info.device_id, (char *)sqlite3_column_text(stmt, 0), + UAM_DEVICE_ID_MAX_STRING_LEN); info->dev_info.type = sqlite3_column_int(stmt, 1); - g_strlcpy(info->dev_info.mac, (char *)sqlite3_column_text(stmt, 2), UAM_MAC_ADDRESS_STRING_LEN); - g_strlcpy(info->dev_info.ipv4_addr, (char *)sqlite3_column_text(stmt, 3), UAM_IP_ADDRESS_MAX_STRING_LEN); + g_strlcpy(info->dev_info.mac, (char *)sqlite3_column_text(stmt, 2), + UAM_MAC_ADDRESS_STRING_LEN); + g_strlcpy(info->dev_info.ipv4_addr, (char *)sqlite3_column_text(stmt, 3), + UAM_IP_ADDRESS_MAX_STRING_LEN); info->timestamp = sqlite3_column_int64(stmt, 4); info->presence_state = sqlite3_column_int(stmt, 5); info->dev_info.operating_system = sqlite3_column_int(stmt, 6); info->user_id = sqlite3_column_int(stmt, 7); info->discriminant = sqlite3_column_int(stmt, 8); - UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d-%d", info->dev_info.device_id, info->dev_info.type, info->dev_info.mac, - info->dev_info.ipv4_addr, info->timestamp, info->presence_state, - info->dev_info.operating_system, - info->user_id, info->discriminant); + UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d-%d", + info->dev_info.device_id, + info->dev_info.type, + info->dev_info.mac, + info->dev_info.ipv4_addr, + info->timestamp, + info->presence_state, + info->dev_info.operating_system, + info->user_id, + info->discriminant); device_list = g_slist_append(device_list, info); break; diff --git a/ua-daemon/src/ua-manager-device-service-db.c b/ua-daemon/src/ua-manager-device-service-db.c index 69b5a21..0f22936 100644 --- a/ua-daemon/src/ua-manager-device-service-db.c +++ b/ua-daemon/src/ua-manager-device-service-db.c @@ -25,97 +25,20 @@ #include "ua-manager-database.h" #define SELECT_SERVICE "SELECT S.service_number, S.service_name, S.cycle " \ - "FROM device_services as D JOIN services as S USING(service_number) where D.device_number = ?" + "FROM device_services as D JOIN services as S USING(service_number) " \ + "where D.device_number = ?" #define INSERT_DEVICE_SERVICE "insert into device_services " \ "(device_number, service_number) values (?, ?)" #define DELETE_ALL_DEVICE_SERVICES "delete from device_services " + #define DELETE_DEVICE_SERVICE "delete from device_services " \ "WHERE device_number = ? and service_number = ?" + #define DELETE_SERVICE "delete from device_services " \ "WHERE service_number = ?" -#ifndef DATABASE_FULL_PATH -#define DATABASE_FULL_PATH "/opt/usr/dbspace/.ua-manager-data.db" -#endif - -#define SQLITE_BUSY_TIMEOUT 500000 - -static void __ua_device_service_finalize_delete(void); - -#define EXEC(error_code, command) do { \ - if (error_code != command) { \ - FUNC_EXIT; \ - goto handle_error; \ - } \ -} while (0) - -#define PREPARE_DELETE(stm, query) do { \ - rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ - if (rc != SQLITE_OK) { \ - stm = NULL; \ - __ua_device_service_finalize_delete(); \ - UAM_ERR("Failed to prepare \"%s\" query" \ - , query); \ - return rc; \ - } \ -} while (0) - -static void __ua_device_service_finalize_select(void); - -#define PREPARE_SELECT(stm, query) do { \ - rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ - if (rc != SQLITE_OK) { \ - stm = NULL; \ - __ua_device_service_finalize_select(); \ - UAM_ERR("Failed to prepare \"%s\" query" \ - , query); \ - return rc; \ - } \ -} while (0) - -static void __ua_device_service_finalize_update(void); - -#define PREPARE_UPDATE(stm, query) do { \ - rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ - if (rc != SQLITE_OK) { \ - stm = NULL; \ - __ua_device_service_finalize_update(); \ - UAM_ERR("Failed to prepare \"%s\" query" \ - , query); \ - return rc; \ - } \ -} while (0) - -static void __ua_device_service_finalize_insert(void); - -#define PREPARE_INSERT(stm, query) do { \ - rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ - if (rc != SQLITE_OK) { \ - stm = NULL; \ - __ua_device_service_finalize_insert(); \ - UAM_ERR("Failed to prepare \"%s\" query" \ - , query); \ - return rc; \ - } \ -} while (0) - -#define FINALIZE(stm) do { \ - if (stm) { \ - sqlite3_finalize(stm); \ - stm = NULL; \ - } \ -} while (0) - -#define DB_ACTION(command) do { \ - if ((command) != SQLITE_OK) { \ - error_code = UAM_ERROR_DB_FAILED; \ - FUNC_EXIT; \ - goto handle_error; \ - } \ -} while (0) - /* DELETE statements */ static sqlite3_stmt *delete_all_device_services; static sqlite3_stmt *delete_service; @@ -131,6 +54,45 @@ static sqlite3_stmt *select_service; static sqlite3_stmt *insert_device_service; extern sqlite3 *database; +static void __ua_device_service_finalize_delete(void) +{ + FUNC_ENTRY; + + FINALIZE(delete_all_device_services); + FINALIZE(delete_service); + FINALIZE(delete_device_service); + + FUNC_EXIT; +} + +static void __ua_device_service_finalize_select(void) +{ + FUNC_ENTRY; + + FINALIZE(select_service); + + FUNC_EXIT; +} + +static void __ua_device_service_finalize_insert(void) +{ + FUNC_ENTRY; + + FINALIZE(insert_device_service); + + FUNC_EXIT; +} + +static void __ua_device_service_finalize_update(void) +{ + FUNC_ENTRY; + +// TO-DO + + FUNC_EXIT; +} + + static int __ua_device_service_prepare_delete(sqlite3 *db) { FUNC_ENTRY; @@ -142,9 +104,12 @@ static int __ua_device_service_prepare_delete(sqlite3 *db) return SQLITE_OK; } - PREPARE_DELETE(delete_all_device_services, DELETE_ALL_DEVICE_SERVICES); - PREPARE_DELETE(delete_service, DELETE_SERVICE); - PREPARE_DELETE(delete_device_service, DELETE_DEVICE_SERVICE); + PREPARE_DELETE(rc, db, delete_all_device_services, + DELETE_ALL_DEVICE_SERVICES, __ua_device_service_finalize_delete); + PREPARE_DELETE(rc, db, delete_service, + DELETE_SERVICE, __ua_device_service_finalize_delete); + PREPARE_DELETE(rc, db, delete_device_service, + DELETE_DEVICE_SERVICE, __ua_device_service_finalize_delete); initialized = 1; FUNC_EXIT; @@ -162,7 +127,8 @@ static int __ua_device_service_prepare_select(sqlite3 *db) return SQLITE_OK; } - PREPARE_SELECT(select_service, SELECT_SERVICE); + PREPARE_SELECT(rc, db, select_service, + SELECT_SERVICE, __ua_device_service_finalize_select); initialized = 1; FUNC_EXIT; @@ -188,7 +154,8 @@ static int __ua_device_service_prepare_insert(sqlite3 *db) return SQLITE_OK; } - PREPARE_INSERT(insert_device_service, INSERT_DEVICE_SERVICE); + PREPARE_INSERT(rc, db, insert_device_service, + INSERT_DEVICE_SERVICE, __ua_device_service_finalize_insert); initialized = 1; FUNC_EXIT; @@ -206,10 +173,10 @@ static int __ua_device_service_table_deviceservicesinfo_prepare(sqlite3 *db) return UAM_ERROR_DB_FAILED; } - DB_ACTION(__ua_device_service_prepare_delete(db)); - DB_ACTION(__ua_device_service_prepare_select(db)); - DB_ACTION(__ua_device_service_prepare_update(db)); - DB_ACTION(__ua_device_service_prepare_insert(db)); + DB_ACTION(__ua_device_service_prepare_delete(db), error_code, handle_error); + DB_ACTION(__ua_device_service_prepare_select(db), error_code, handle_error); + DB_ACTION(__ua_device_service_prepare_update(db), error_code, handle_error); + DB_ACTION(__ua_device_service_prepare_insert(db), error_code, handle_error); handle_error: @@ -217,44 +184,6 @@ handle_error: return error_code; } -static void __ua_device_service_finalize_delete(void) -{ - FUNC_ENTRY; - - FINALIZE(delete_all_device_services); - FINALIZE(delete_service); - FINALIZE(delete_device_service); - - FUNC_EXIT; -} - -static void __ua_device_service_finalize_select(void) -{ - FUNC_ENTRY; - - FINALIZE(select_service); - - FUNC_EXIT; -} - -static void __ua_device_service_finalize_insert(void) -{ - FUNC_ENTRY; - - FINALIZE(insert_device_service); - - FUNC_EXIT; -} - -static void __ua_device_service_finalize_update(void) -{ - FUNC_ENTRY; - -// TO-DO - - FUNC_EXIT; -} - static void __ua_device_service_table_devicesinfo_finalize(void) { FUNC_ENTRY; @@ -282,7 +211,8 @@ int _ua_device_service_db_initialize(void) { FUNC_ENTRY; - EXEC(UAM_ERROR_NONE, __ua_device_service_table_deviceservicesinfo_prepare(database)); + EXEC(UAM_ERROR_NONE, __ua_device_service_table_deviceservicesinfo_prepare(database), + handle_error); FUNC_EXIT; return UAM_ERROR_NONE; @@ -309,8 +239,8 @@ int _uam_db_insert_service(int device_number, int service_number) UAM_INFO("%d-%d", device_number, service_number); - DB_ACTION(sqlite3_bind_int(stmt, 1, device_number)); - DB_ACTION(sqlite3_bind_int(stmt, 2, service_number)); + DB_ACTION(sqlite3_bind_int(stmt, 1, device_number), error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 2, service_number), error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to insert device-service info: %s", @@ -331,6 +261,7 @@ int _uam_db_insert_device_service_info(const char *device_id, int tech_type, const char *address, const char *service_name, int cycle) { FUNC_ENTRY; + int ret = UAM_ERROR_NONE; db_service_info_t info; int service_number = 0; int error_code = UAM_ERROR_NONE; @@ -338,18 +269,22 @@ int _uam_db_insert_device_service_info(const char *device_id, int tech_type, UAM_INFO("%s-%d-%s-%s-%d", device_id, tech_type, address, service_name, cycle); int device_number = 0; - if (_uam_db_get_device_number(device_id, tech_type, address, &device_number) != UAM_ERROR_NONE) + ret = _uam_db_get_device_number(device_id, tech_type, address, &device_number); + if (UAM_ERROR_NONE != ret) goto handle_error; - if (_uam_db_get_service_info(service_name, &info) != UAM_ERROR_NONE) { - if (_uam_db_insert_service_info(&service_number, service_name, cycle) != UAM_ERROR_NONE) + ret = _uam_db_get_service_info(service_name, &info); + if (UAM_ERROR_NONE != ret) { + ret = _uam_db_insert_service_info(&service_number, service_name, cycle); + if (UAM_ERROR_NONE != ret) goto handle_error; } else service_number = info.service_number; UAM_INFO("%d-%d", device_number, service_number); - if (_uam_db_insert_service(device_number, service_number) != UAM_ERROR_NONE) + ret = _uam_db_insert_service(device_number, service_number); + if (UAM_ERROR_NONE != ret) goto handle_error; UAM_DBG("Device-service info inserted [%d] [%d]", device_number, service_number); @@ -387,7 +322,7 @@ int _uam_db_delete_service_number(int service_number) UAM_INFO("Service Number: %d", service_number); - DB_ACTION(sqlite3_bind_int(stmt, 1, service_number)); + DB_ACTION(sqlite3_bind_int(stmt, 1, service_number), error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to delete device-service info %s", @@ -410,8 +345,8 @@ int _uam_db_delete_device_service_number(int device_number, int service_number) UAM_INFO("Device Number: %d Service Number: %d", device_number, service_number); - DB_ACTION(sqlite3_bind_int(stmt, 1, device_number)); - DB_ACTION(sqlite3_bind_int(stmt, 2, service_number)); + DB_ACTION(sqlite3_bind_int(stmt, 1, device_number), error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 2, service_number), error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to delete device-service info %s", @@ -430,17 +365,20 @@ int _uam_db_delete_device_service(const char *service_name) { FUNC_ENTRY; db_service_info_t info; + int ret = UAM_ERROR_NONE; int service_number = 0; int error_code = UAM_ERROR_NONE; UAM_INFO("%s", service_name); - if (_uam_db_get_service_info(service_name, &info) != UAM_ERROR_NONE) - goto handle_error; + ret = _uam_db_get_service_info(service_name, &info); + if (UAM_ERROR_NONE != ret) + goto handle_error; service_number = info.service_number; UAM_INFO("%d", service_number); - if (_uam_db_delete_service_number(service_number) != UAM_ERROR_NONE) + ret = _uam_db_delete_service_number(service_number); + if (UAM_ERROR_NONE != ret) goto handle_error; UAM_DBG("Service info deleted [%d]", service_number); @@ -455,22 +393,26 @@ int _uam_db_delete_device_service_info(const char *device_id, int tech_type, { FUNC_ENTRY; db_service_info_t info; + int ret = UAM_ERROR_NONE; int service_number = 0; int device_number = 0; int error_code = UAM_ERROR_NONE; UAM_INFO("%s-%d-%s-%s", device_id, tech_type, address, service_name); - if (_uam_db_get_device_number(device_id, tech_type, address, &device_number) != UAM_ERROR_NONE) + ret = _uam_db_get_device_number(device_id, tech_type, address, &device_number); + if (UAM_ERROR_NONE != ret) goto handle_error; - if (_uam_db_get_service_info(service_name, &info) != UAM_ERROR_NONE) + ret = _uam_db_get_service_info(service_name, &info); + if (UAM_ERROR_NONE != ret) goto handle_error; service_number = info.service_number; UAM_INFO("%d-%d", device_number, service_number); - if (_uam_db_delete_device_service_number(device_number, service_number) != UAM_ERROR_NONE) + ret = _uam_db_delete_device_service_number(device_number, service_number); + if (UAM_ERROR_NONE != ret) goto handle_error; UAM_DBG("Device-service info deleted [%d] [%d]", device_number, service_number); @@ -500,7 +442,8 @@ GSList *_uam_db_get_service(int device_number) case SQLITE_ROW: info = g_new0(db_service_info_t, 1); info->service_number = sqlite3_column_int(stmt, 0); - g_strlcpy(info->service_name, (char *)sqlite3_column_text(stmt, 1), UAM_SERVICE_MAX_STRING_LEN); + g_strlcpy(info->service_name, (char *)sqlite3_column_text(stmt, 1), + UAM_SERVICE_MAX_STRING_LEN); info->cycle = sqlite3_column_int(stmt, 2); UAM_INFO("%d-%s-%d", info->service_number, info->service_name, info->cycle); @@ -519,14 +462,17 @@ handle_error: return service_list; } -GSList *_uam_db_get_device_services(const char *device_id, int tech_type, const char *address) +GSList *_uam_db_get_device_services(const char *device_id, int tech_type, + const char *address) { FUNC_ENTRY; + int ret = UAM_ERROR_NONE; + int device_number = 0; UAM_INFO("%s-%d-%s", device_id, tech_type, address); GSList *service_list = NULL; - int device_number = 0; - if (_uam_db_get_device_number(device_id, tech_type, address, &device_number) != UAM_ERROR_NONE) + ret = _uam_db_get_device_number(device_id, tech_type, address, &device_number); + if (UAM_ERROR_NONE != ret) goto handle_error; service_list = _uam_db_get_service(device_number); diff --git a/ua-daemon/src/ua-manager-service-db.c b/ua-daemon/src/ua-manager-service-db.c index 7823cb9..c6d6eec 100644 --- a/ua-daemon/src/ua-manager-service-db.c +++ b/ua-daemon/src/ua-manager-service-db.c @@ -26,96 +26,20 @@ #define SELECT_ALL_SERVICES "SELECT service_number, service_name, " \ "cycle FROM services" + #define SELECT_SERVICE "SELECT service_number, service_name, cycle " \ "FROM services where service_name = ?" + #define SELECT_MAX_SERVICE_NUMBER "SELECT MAX(service_number) FROM services" -#define INSERT_SERVICE "insert into services (service_number, service_name, cycle) values (?, ?, ?)" +#define INSERT_SERVICE "insert into services (service_number, service_name, cycle) " \ + "values (?, ?, ?)" #define UPDATE_CYCLE "UPDATE services SET cycle = ? WHERE service_name = ?" #define DELETE_ALL_SERVICES "delete from services" -#define DELETE_SERVICE_INFO "delete from services WHERE service_name = ?" -#ifndef DATABASE_FULL_PATH -#define DATABASE_FULL_PATH "/opt/usr/dbspace/.ua-manager-data.db" -#endif - -#define SQLITE_BUSY_TIMEOUT 500000 - -static void __ua_service_finalize_delete(void); - -#define EXEC(error_code, command) do { \ - if (error_code != command) { \ - FUNC_EXIT; \ - goto handle_error; \ - } \ -} while (0) - -#define PREPARE_DELETE(stm, query) do { \ - rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ - if (rc != SQLITE_OK) { \ - stm = NULL; \ - __ua_service_finalize_delete(); \ - UAM_ERR("Failed to prepare \"%s\" query" \ - , query); \ - return rc; \ - } \ -} while (0) - -static void __ua_service_finalize_select(void); - -#define PREPARE_SELECT(stm, query) do { \ - rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ - if (rc != SQLITE_OK) { \ - stm = NULL; \ - __ua_service_finalize_select(); \ - UAM_ERR("Failed to prepare \"%s\" query" \ - , query); \ - return rc; \ - } \ -} while (0) - -static void _ua_service_finalize_update(void); - -#define PREPARE_UPDATE(stm, query) do { \ - rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ - if (rc != SQLITE_OK) { \ - stm = NULL; \ - _ua_service_finalize_update(); \ - UAM_ERR("Failed to prepare \"%s\" query" \ - , query); \ - return rc; \ - } \ -} while (0) - -static void __ua_service_finalize_insert(void); - -#define PREPARE_INSERT(stm, query) do { \ - rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ - if (rc != SQLITE_OK) { \ - stm = NULL; \ - __ua_service_finalize_insert(); \ - UAM_ERR("Failed to prepare \"%s\" query" \ - , query); \ - return rc; \ - } \ -} while (0) - -#define FINALIZE(stm) do { \ - if (stm) { \ - sqlite3_finalize(stm); \ - stm = NULL; \ - } \ -} while (0) - -#define DB_ACTION(command) do { \ - if ((command) != SQLITE_OK) { \ - error_code = UAM_ERROR_DB_FAILED; \ - FUNC_EXIT; \ - goto handle_error; \ - } \ -} while (0) +#define DELETE_SERVICE_INFO "delete from services WHERE service_name = ?" /* DELETE statements */ static sqlite3_stmt *delete_all_services; @@ -135,6 +59,45 @@ static sqlite3_stmt *insert_service_info; extern sqlite3 *database; static int max_service_number; +static void __ua_service_finalize_delete(void) +{ + FUNC_ENTRY; + + FINALIZE(delete_all_services); + FINALIZE(delete_service_info); + + FUNC_EXIT; +} + +static void __ua_service_finalize_select(void) +{ + FUNC_ENTRY; + + FINALIZE(select_all_services); + FINALIZE(select_service); + FINALIZE(select_max_service_number); + + FUNC_EXIT; +} + +static void __ua_service_finalize_insert(void) +{ + FUNC_ENTRY; + + FINALIZE(insert_service_info); + + FUNC_EXIT; +} + +static void __ua_service_finalize_update(void) +{ + FUNC_ENTRY; + + FINALIZE(update_cycle); + + FUNC_EXIT; +} + static int __ua_service_prepare_delete(sqlite3 *db) { FUNC_ENTRY; @@ -146,8 +109,10 @@ static int __ua_service_prepare_delete(sqlite3 *db) return SQLITE_OK; } - PREPARE_DELETE(delete_all_services, DELETE_ALL_SERVICES); - PREPARE_DELETE(delete_service_info, DELETE_SERVICE_INFO); + PREPARE_DELETE(rc, db, delete_all_services, + DELETE_ALL_SERVICES, __ua_service_finalize_delete); + PREPARE_DELETE(rc, db, delete_service_info, + DELETE_SERVICE_INFO, __ua_service_finalize_delete); initialized = 1; FUNC_EXIT; @@ -165,9 +130,12 @@ static int __ua_service_prepare_select(sqlite3 *db) return SQLITE_OK; } - PREPARE_SELECT(select_all_services, SELECT_ALL_SERVICES); - PREPARE_SELECT(select_service, SELECT_SERVICE); - PREPARE_SELECT(select_max_service_number, SELECT_MAX_SERVICE_NUMBER); + PREPARE_SELECT(rc, db, select_all_services, + SELECT_ALL_SERVICES, __ua_service_finalize_select); + PREPARE_SELECT(rc, db, select_service, + SELECT_SERVICE, __ua_service_finalize_select); + PREPARE_SELECT(rc, db, select_max_service_number, + SELECT_MAX_SERVICE_NUMBER, __ua_service_finalize_select); initialized = 1; FUNC_EXIT; @@ -185,7 +153,8 @@ static int __ua_service_prepare_update(sqlite3 *db) return SQLITE_OK; } - PREPARE_UPDATE(update_cycle, UPDATE_CYCLE); + PREPARE_UPDATE(rc, db, update_cycle, + UPDATE_CYCLE, __ua_service_finalize_update); initialized = 1; FUNC_EXIT; @@ -203,7 +172,8 @@ static int __ua_service_prepare_insert(sqlite3 *db) return SQLITE_OK; } - PREPARE_INSERT(insert_service_info, INSERT_SERVICE); + PREPARE_INSERT(rc, db, insert_service_info, + INSERT_SERVICE, __ua_service_finalize_insert); initialized = 1; FUNC_EXIT; @@ -221,10 +191,10 @@ static int __ua_service_table_servicesinfo_prepare(sqlite3 *db) return UAM_ERROR_DB_FAILED; } - DB_ACTION(__ua_service_prepare_delete(db)); - DB_ACTION(__ua_service_prepare_select(db)); - DB_ACTION(__ua_service_prepare_update(db)); - DB_ACTION(__ua_service_prepare_insert(db)); + DB_ACTION(__ua_service_prepare_delete(db), error_code, handle_error); + DB_ACTION(__ua_service_prepare_select(db), error_code, handle_error); + DB_ACTION(__ua_service_prepare_update(db), error_code, handle_error); + DB_ACTION(__ua_service_prepare_insert(db), error_code, handle_error); handle_error: @@ -232,45 +202,6 @@ handle_error: return error_code; } -static void __ua_service_finalize_delete(void) -{ - FUNC_ENTRY; - - FINALIZE(delete_all_services); - FINALIZE(delete_service_info); - - FUNC_EXIT; -} - -static void __ua_service_finalize_select(void) -{ - FUNC_ENTRY; - - FINALIZE(select_all_services); - FINALIZE(select_service); - FINALIZE(select_max_service_number); - - FUNC_EXIT; -} - -static void __ua_service_finalize_insert(void) -{ - FUNC_ENTRY; - - FINALIZE(insert_service_info); - - FUNC_EXIT; -} - -static void _ua_service_finalize_update(void) -{ - FUNC_ENTRY; - - FINALIZE(update_cycle); - - FUNC_EXIT; -} - static void __ua_service_table_servicesinfo_finalize(void) { FUNC_ENTRY; @@ -334,7 +265,7 @@ int _ua_service_db_initialize(void) { FUNC_ENTRY; - EXEC(UAM_ERROR_NONE, __ua_service_table_servicesinfo_prepare(database)); + EXEC(UAM_ERROR_NONE, __ua_service_table_servicesinfo_prepare(database), handle_error); if (_uam_db_get_max_service_number() != UAM_ERROR_NONE) goto handle_error; @@ -347,7 +278,8 @@ handle_error: return UAM_ERROR_DB_FAILED; } -int _uam_db_insert_service_info(int *service_number, const char *service_name, int cycle) +int _uam_db_insert_service_info( + int *service_number, const char *service_name, int cycle) { FUNC_ENTRY; int error_code = UAM_ERROR_NONE; @@ -357,9 +289,12 @@ int _uam_db_insert_service_info(int *service_number, const char *service_name, i UAM_INFO("%s-%d", service_name, cycle); - DB_ACTION(sqlite3_bind_int(stmt, 1, max_service_number + 1)); - DB_ACTION(sqlite3_bind_text(stmt, 2, service_name, -1, SQLITE_TRANSIENT)); - DB_ACTION(sqlite3_bind_int(stmt, 3, cycle)); + DB_ACTION(sqlite3_bind_int(stmt, 1, max_service_number + 1), + error_code, handle_error); + DB_ACTION(sqlite3_bind_text(stmt, 2, service_name, -1, SQLITE_TRANSIENT), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 3, cycle), + error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to insert service info: %s", @@ -386,7 +321,8 @@ int _uam_db_delete_service_info(const char *service_name) UAM_INFO("Service name: %s", service_name); - DB_ACTION(sqlite3_bind_text(stmt, 1, service_name, -1, SQLITE_STATIC)); + DB_ACTION(sqlite3_bind_text(stmt, 1, service_name, -1, SQLITE_STATIC), + error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to delete service info %s", @@ -428,8 +364,10 @@ int _uam_db_update_service_cycle(const char *service_name, int cycle) retv_if(NULL == service_name, UAM_ERROR_INVALID_PARAMETER); - DB_ACTION(sqlite3_bind_int64(stmt, 1, cycle)); - DB_ACTION(sqlite3_bind_text(stmt, 2, service_name, -1, SQLITE_TRANSIENT)); + DB_ACTION(sqlite3_bind_int64(stmt, 1, cycle), + error_code, handle_error); + DB_ACTION(sqlite3_bind_text(stmt, 2, service_name, -1, SQLITE_TRANSIENT), + error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to update service timestamp: %s", @@ -458,7 +396,8 @@ int _uam_db_get_service_info(const char *service_name, db_service_info_t *info) UAM_INFO("Service Name: %s", service_name); - DB_ACTION(sqlite3_bind_text(stmt, 1, service_name, -1, SQLITE_STATIC)); + DB_ACTION(sqlite3_bind_text(stmt, 1, service_name, -1, SQLITE_STATIC), + error_code, handle_error); do { rc = sqlite3_step(stmt); @@ -469,7 +408,8 @@ int _uam_db_get_service_info(const char *service_name, db_service_info_t *info) case SQLITE_ROW: UAM_DBG("Service info found"); info->service_number = sqlite3_column_int(stmt, 0); - g_strlcpy(info->service_name, (char *)sqlite3_column_text(stmt, 1), UAM_SERVICE_MAX_STRING_LEN); + g_strlcpy(info->service_name, (char *)sqlite3_column_text(stmt, 1), + UAM_SERVICE_MAX_STRING_LEN); info->cycle = sqlite3_column_int(stmt, 2); UAM_INFO("%d-%s-%d", info->service_number, info->service_name, info->cycle); @@ -506,7 +446,8 @@ GSList *_ua_service_db_get_all_services(void) case SQLITE_ROW: info = g_new0(db_service_info_t, 1); info->service_number = sqlite3_column_int(stmt, 0); - g_strlcpy(info->service_name, (char *)sqlite3_column_text(stmt, 1), UAM_SERVICE_MAX_STRING_LEN); + g_strlcpy(info->service_name, (char *)sqlite3_column_text(stmt, 1), + UAM_SERVICE_MAX_STRING_LEN); info->cycle = sqlite3_column_int(stmt, 2); UAM_INFO("%d-%s-%d", info->service_number, info->service_name, info->cycle); diff --git a/ua-daemon/src/ua-manager-user-db.c b/ua-daemon/src/ua-manager-user-db.c index fbc2ac6..15ae9f1 100644 --- a/ua-daemon/src/ua-manager-user-db.c +++ b/ua-daemon/src/ua-manager-user-db.c @@ -42,89 +42,6 @@ #define DELETE_USER_INFO "delete from userdata " \ "WHERE user_id = ? " -#ifndef DATABASE_FULL_PATH -#define DATABASE_FULL_PATH "/opt/usr/dbspace/.ua-manager-data.db" -#endif - -#define SQLITE_BUSY_TIMEOUT 500000 - -static void __ua_finalize_delete(void); - -#define EXEC(error_code, command) do { \ - if (error_code != command) { \ - FUNC_EXIT; \ - goto handle_error; \ - } \ -} while (0) - -#define PREPARE_DELETE(stm, query) do { \ - rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ - if (rc != SQLITE_OK) { \ - stm = NULL; \ - __ua_finalize_delete(); \ - UAM_ERR("Failed to prepare \"%s\" query" \ - , query); \ - return rc; \ - } \ -} while (0) - -static void __ua_finalize_select(void); - -#define PREPARE_SELECT(stm, query) do { \ - rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ - if (rc != SQLITE_OK) { \ - stm = NULL; \ - __ua_finalize_select(); \ - UAM_ERR("Failed to prepare \"%s\" query" \ - , query); \ - return rc; \ - } \ -} while (0) - -#if 0 -/* TODO: */ -static void _ua_finalize_update(void); - -#define PREPARE_UPDATE(stm, query) do { \ - rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ - if (rc != SQLITE_OK) { \ - stm = NULL; \ - _ua_finalize_update(); \ - UAM_ERR("Failed to prepare \"%s\" query" \ - , query); \ - return rc; \ - } \ -} while (0) -#endif - -static void __ua_finalize_insert(void); - -#define PREPARE_INSERT(stm, query) do { \ - rc = sqlite3_prepare_v2(db, query, -1, &stm, NULL); \ - if (rc != SQLITE_OK) { \ - stm = NULL; \ - __ua_finalize_insert(); \ - UAM_ERR("Failed to prepare \"%s\" query" \ - , query); \ - return rc; \ - } \ -} while (0) - -#define FINALIZE(stm) do { \ - if (stm) { \ - sqlite3_finalize(stm); \ - stm = NULL; \ - } \ -} while (0) - -#define DB_ACTION(command) do { \ - if ((command) != SQLITE_OK) { \ - error_code = UAM_ERROR_DB_FAILED; \ - FUNC_EXIT; \ - goto handle_error; \ - } \ -} while (0) - /* DELETE statements */ static sqlite3_stmt *delete_all_users_data; static sqlite3_stmt *delete_user_info; @@ -140,9 +57,50 @@ static sqlite3_stmt *select_max_user_id; /* INSERT statements */ static sqlite3_stmt *insert_user_info; -sqlite3 *database; +extern sqlite3 *database; static int max_user_id; +static void __ua_finalize_delete(void) +{ + FUNC_ENTRY; + + FINALIZE(delete_all_users_data); + FINALIZE(delete_user_info); + + FUNC_EXIT; +} + +static void __ua_finalize_select(void) +{ + FUNC_ENTRY; + + FINALIZE(select_all_users_data); + FINALIZE(select_user_data); + FINALIZE(select_max_user_id); + + FUNC_EXIT; +} + +static void __ua_finalize_insert(void) +{ + FUNC_ENTRY; + + FINALIZE(insert_user_info); + + FUNC_EXIT; +} + +#if 0 +/* TODO */ +static void _ua_finalize_update(void) +{ + FUNC_ENTRY; + + + FUNC_EXIT; +} +#endif + static int __ua_prepare_delete(sqlite3 *db) { FUNC_ENTRY; @@ -154,8 +112,10 @@ static int __ua_prepare_delete(sqlite3 *db) return SQLITE_OK; } - PREPARE_DELETE(delete_all_users_data, DELETE_ALL_USERS_DATA); - PREPARE_DELETE(delete_user_info, DELETE_USER_INFO); + PREPARE_DELETE(rc, db, delete_all_users_data, + DELETE_ALL_USERS_DATA, __ua_finalize_delete); + PREPARE_DELETE(rc, db, delete_user_info, + DELETE_USER_INFO, __ua_finalize_delete); initialized = 1; FUNC_EXIT; @@ -173,9 +133,12 @@ static int __ua_prepare_select(sqlite3 *db) return SQLITE_OK; } - PREPARE_SELECT(select_all_users_data, SELECT_ALL_USERS_DATA); - PREPARE_SELECT(select_user_data, SELECT_USER_DATA); - PREPARE_SELECT(select_max_user_id, SELECT_MAX_USER_ID); + PREPARE_SELECT(rc, db, select_all_users_data, + SELECT_ALL_USERS_DATA, __ua_finalize_select); + PREPARE_SELECT(rc, db, select_user_data, + SELECT_USER_DATA, __ua_finalize_select); + PREPARE_SELECT(rc, db, select_max_user_id, + SELECT_MAX_USER_ID, __ua_finalize_select); initialized = 1; FUNC_EXIT; @@ -201,7 +164,8 @@ static int __ua_prepare_insert(sqlite3 *db) return SQLITE_OK; } - PREPARE_INSERT(insert_user_info, INSERT_USER_INFO); + PREPARE_INSERT(rc, db, insert_user_info, + INSERT_USER_INFO, __ua_finalize_insert); initialized = 1; FUNC_EXIT; @@ -219,10 +183,10 @@ static int __ua_table_usersinfo_prepare(sqlite3 *db) return UAM_ERROR_DB_FAILED; } - DB_ACTION(__ua_prepare_delete(db)); - DB_ACTION(__ua_prepare_select(db)); - DB_ACTION(__ua_prepare_update(db)); - DB_ACTION(__ua_prepare_insert(db)); + DB_ACTION(__ua_prepare_delete(db), error_code, handle_error); + DB_ACTION(__ua_prepare_select(db), error_code, handle_error); + DB_ACTION(__ua_prepare_update(db), error_code, handle_error); + DB_ACTION(__ua_prepare_insert(db), error_code, handle_error); handle_error: @@ -230,47 +194,6 @@ handle_error: return error_code; } -static void __ua_finalize_delete(void) -{ - FUNC_ENTRY; - - FINALIZE(delete_all_users_data); - FINALIZE(delete_user_info); - - FUNC_EXIT; -} - -static void __ua_finalize_select(void) -{ - FUNC_ENTRY; - - FINALIZE(select_all_users_data); - FINALIZE(select_user_data); - FINALIZE(select_max_user_id); - - FUNC_EXIT; -} - -static void __ua_finalize_insert(void) -{ - FUNC_ENTRY; - - FINALIZE(insert_user_info); - - FUNC_EXIT; -} - -#if 0 -/* TODO */ -static void _ua_finalize_update(void) -{ - FUNC_ENTRY; - - - FUNC_EXIT; -} -#endif - static void __ua_table_usersinfo_finalize(void) { FUNC_ENTRY; @@ -325,7 +248,7 @@ int _ua_db_initialize(void) if (UAM_ERROR_NONE != _ua_db_initialize_once()) goto handle_error; - EXEC(UAM_ERROR_NONE, __ua_table_usersinfo_prepare(database)); + EXEC(UAM_ERROR_NONE, __ua_table_usersinfo_prepare(database), handle_error); if (_ua_device_db_initialize() != UAM_ERROR_NONE) goto handle_error; @@ -378,10 +301,12 @@ int _ua_db_insert_user_info(int *user_id, const char *name, const char *account) UAM_INFO("%s-%s", name, account); - DB_ACTION(sqlite3_bind_int(stmt, 1, max_user_id + 1)); + DB_ACTION(sqlite3_bind_int(stmt, 1, max_user_id + 1), + error_code, handle_error); DB_ACTION(sqlite3_bind_text(stmt, 2, name ? name : "", - -1, SQLITE_TRANSIENT)); - DB_ACTION(sqlite3_bind_text(stmt, 3, account, -1, SQLITE_TRANSIENT)); + -1, SQLITE_TRANSIENT), error_code, handle_error); + DB_ACTION(sqlite3_bind_text(stmt, 3, account, -1, SQLITE_TRANSIENT), + error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to insert user info: %s", @@ -410,7 +335,7 @@ int _ua_db_delete_by_user_id(int user_id) UAM_INFO("UserId: %d", user_id); - DB_ACTION(sqlite3_bind_int(stmt, 1, user_id)); + DB_ACTION(sqlite3_bind_int(stmt, 1, user_id), error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to delete user info %s", @@ -436,7 +361,7 @@ int _ua_db_get_user(int user_id, db_user_info_t *info) UAM_INFO("UserId: %d", user_id); - DB_ACTION(sqlite3_bind_int(stmt, 1, user_id)); + DB_ACTION(sqlite3_bind_int(stmt, 1, user_id), error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { UAM_ERR("Failed to select user info %s", @@ -445,8 +370,10 @@ int _ua_db_get_user(int user_id, db_user_info_t *info) } else { info = g_new0(db_user_info_t, 1); info->user_id = sqlite3_column_int(stmt, 0); - g_strlcpy(info->name, (char *)sqlite3_column_text(stmt, 1), UAM_USER_NAME_MAX_STRING_LEN); - g_strlcpy(info->account, (char *)sqlite3_column_text(stmt, 2), UAM_USER_ACCOUNT_MAX_STRING_LEN); + g_strlcpy(info->name, (char *)sqlite3_column_text(stmt, 1), + UAM_USER_NAME_MAX_STRING_LEN); + g_strlcpy(info->account, (char *)sqlite3_column_text(stmt, 2), + UAM_USER_ACCOUNT_MAX_STRING_LEN); UAM_INFO("%d-%s-%s", info->user_id, info->name, info->account); @@ -477,8 +404,10 @@ GSList *_ua_db_get_all_users(void) case SQLITE_ROW: info = g_new0(db_user_info_t, 1); info->user_id = sqlite3_column_int(stmt, 0); - g_strlcpy(info->name, (char *)sqlite3_column_text(stmt, 1), UAM_USER_NAME_MAX_STRING_LEN); - g_strlcpy(info->account, (char *)sqlite3_column_text(stmt, 2), UAM_USER_ACCOUNT_MAX_STRING_LEN); + g_strlcpy(info->name, (char *)sqlite3_column_text(stmt, 1), + UAM_USER_NAME_MAX_STRING_LEN); + g_strlcpy(info->account, (char *)sqlite3_column_text(stmt, 2), + UAM_USER_ACCOUNT_MAX_STRING_LEN); UAM_INFO("%d-%s-%s", info->user_id, info->name, info->account);