From 87935e714c348fec6f1c4b0e30a64af36b3f0094 Mon Sep 17 00:00:00 2001 From: Abhay agarwal Date: Tue, 17 Dec 2019 19:54:08 +0530 Subject: [PATCH] Do not return from uam core initialization if no data in database - All the database tables must be checked before returning from uam_core_init function - Some/All of tables of uam database may be empty and can be updated by application Signed-off-by: Abhay agarwal --- ua-daemon/src/ua-manager-core.c | 110 ++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 37e7453..115ac3a 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -2288,49 +2288,49 @@ int _uam_core_init(void) db_users = _uam_db_get_all_users(); if (!db_users) { UAM_INFO_C("No users in database"); - return UAM_ERROR_NONE; } + else { + for (l = db_users; NULL != l; l = g_slist_next(l)) { + db_user_info_t *info = l->data; + uam_db_user_info_t *user; - for (l = db_users; NULL != l; l = g_slist_next(l)) { - db_user_info_t *info = l->data; - uam_db_user_info_t *user; - - if (!info) - continue; + if (!info) + continue; - user = g_new0(uam_db_user_info_t, 1); - user->user_id = info->user_id; - user->name = g_strdup(info->name); - user->account = g_strdup(info->account); - user->devices = NULL; + user = g_new0(uam_db_user_info_t, 1); + user->user_id = info->user_id; + user->name = g_strdup(info->name); + user->account = g_strdup(info->account); + user->devices = NULL; - users = g_slist_prepend(users, user); + users = g_slist_prepend(users, user); + } } /* Fetch service list */ db_svc_list = _uam_service_db_get_all_services(); if (!db_svc_list) { UAM_INFO_C("No services in database"); - return UAM_ERROR_NONE; } + else { + for (l = db_svc_list; NULL != l; l = g_slist_next(l)) { + db_service_info_t *db_svc = l->data; + uam_db_service_info_t *service; + GSList *l1; - for (l = db_svc_list; NULL != l; l = g_slist_next(l)) { - db_service_info_t *db_svc = l->data; - uam_db_service_info_t *service; - GSList *l1; - - if (!db_svc) - continue; + if (!db_svc) + continue; - l1 = g_slist_find_custom(services, - db_svc->service_name, __compare_svc_name); - if (!l1) { - service = g_new0(uam_db_service_info_t, 1); - service->name = g_strdup(db_svc->service_name); - service->cycle = db_svc->cycle; - service->presence_threshold = db_svc->presence_threshold; - service->absence_threshold = db_svc->absence_threshold; - services = g_slist_append(services, service); + l1 = g_slist_find_custom(services, + db_svc->service_name, __compare_svc_name); + if (!l1) { + service = g_new0(uam_db_service_info_t, 1); + service->name = g_strdup(db_svc->service_name); + service->cycle = db_svc->cycle; + service->presence_threshold = db_svc->presence_threshold; + service->absence_threshold = db_svc->absence_threshold; + services = g_slist_append(services, service); + } } } @@ -2338,35 +2338,35 @@ int _uam_core_init(void) db_devices = _uam_device_db_get_all_devices(); if (!db_devices) { UAM_INFO_C("No Devices registered in database"); - return UAM_ERROR_NONE; } + else { + for (l = db_devices; NULL != l; l = g_slist_next(l)) { + db_device_info_t *db_info = l->data; + uam_db_user_info_t *user; + GSList *svc_list = NULL; + GSList *l1; - for (l = db_devices; NULL != l; l = g_slist_next(l)) { - db_device_info_t *db_info = l->data; - uam_db_user_info_t *user; - GSList *svc_list = NULL; - GSList *l1; - - if (!db_info) - continue; + if (!db_info) + continue; - l1 = g_slist_find_custom(users, + l1 = g_slist_find_custom(users, &(db_info->user_id), __compare_user_id); - if (!l1) { - UAM_ERR("Invalid user Id: %d", db_info->user_id); - continue; - } - user = l1->data; + if (!l1) { + UAM_ERR("Invalid user Id: %d", db_info->user_id); + continue; + } + user = l1->data; - /* Fetch device services from DB */ - l1 = _uam_db_get_device_services( + /* Fetch device services from DB */ + l1 = _uam_db_get_device_services( db_info->dev_info.device_id, db_info->dev_info.type, db_info->dev_info.mac); - svc_list = __convert_db_svc_list_to_uam_svc_list(l1); - __uam_core_add_dev_to_list(user, &(db_info->dev_info), + svc_list = __convert_db_svc_list_to_uam_svc_list(l1); + __uam_core_add_dev_to_list(user, &(db_info->dev_info), db_info->presence_state, db_info->last_seen, svc_list); + } } /* Fetch iBeacon adv list */ @@ -2423,12 +2423,14 @@ int _uam_core_init(void) g_slist_free_full(db_svc_dev_list, g_free); g_slist_free_full(db_payload_list, g_free); - /* Set/update registered device list to plugins */ - if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices)) - UAM_ERR("_uam_pm_set_registered_devices failed"); + if (devices) { + /* Set/update registered device list to plugins */ + if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices)) + UAM_ERR("_uam_pm_set_registered_devices failed"); - /* Set/update registered device list to cloud plugin */ - _uam_cloud_update_registered_devices(); + /* Set/update registered device list to cloud plugin */ + _uam_cloud_update_registered_devices(); + } FUNC_EXIT; return UAM_ERROR_NONE; -- 2.7.4