diff --git a/coreapi/call_log.c b/coreapi/call_log.c index 6e9184f77..99ad154da 100644 --- a/coreapi/call_log.c +++ b/coreapi/call_log.c @@ -116,12 +116,14 @@ void call_logs_write_to_config_file(LinphoneCore *lc){ } } -void call_logs_read_from_config_file(LinphoneCore *lc){ +bctbx_list_t * call_logs_read_from_config_file(LinphoneCore *lc){ char logsection[32]; int i; const char *tmp; uint64_t sec; LpConfig *cfg=lc->config; + bctbx_list_t *call_logs; + for(i=0;;++i){ snprintf(logsection,sizeof(logsection),"call_log_%i",i); if (lp_config_has_section(cfg,logsection)){ @@ -154,9 +156,10 @@ void call_logs_read_from_config_file(LinphoneCore *lc){ cl->video_enabled=lp_config_get_int(cfg,logsection,"video_enabled",0); tmp=lp_config_get_string(cfg,logsection,"call_id",NULL); if (tmp) cl->call_id=ms_strdup(tmp); - lc->call_logs=bctbx_list_append(lc->call_logs,cl); + call_logs=bctbx_list_append(call_logs,cl); }else break; } + return call_logs; } diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index a7af0c675..e08ef3413 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -1730,13 +1730,15 @@ static void ui_config_read(LinphoneCore *lc) { #ifndef SQLITE_STORAGE_ENABLED read_friends_from_rc(lc); + lc->call_logs = call_logs_read_from_config_file(lc); #else if (!lc->friends_db) { read_friends_from_rc(lc); } + if (!lc->logs_db) { + lc->call_logs = call_logs_read_from_config_file(lc); + } #endif - - call_logs_read_from_config_file(lc); } /* @@ -4624,17 +4626,16 @@ void linphone_core_migrate_logs_from_rc_to_db(LinphoneCore *lc) { return; } - // This is because there must have been a call previously to linphone_core_call_log_storage_init - lc->call_logs = bctbx_list_free_with_data(lc->call_logs, (void (*)(void*))linphone_call_log_unref); - - call_logs_read_from_config_file(lc); - if (!lc->call_logs) { + logs_to_migrate = call_logs_read_from_config_file(lc); + if (!logs_to_migrate) { ms_warning("nothing to migrate, skipping..."); return; } - logs_to_migrate = lc->call_logs; + // This is because there must have been a call previously to linphone_core_call_log_storage_init + lc->call_logs = bctbx_list_free_with_data(lc->call_logs, (void (*)(void*))linphone_call_log_unref); lc->call_logs = NULL; + // We can't use bctbx_list_for_each because logs_to_migrate are listed in the wrong order (latest first), and we want to store the logs latest last for (i = (int)bctbx_list_size(logs_to_migrate) - 1; i >= 0; i--) { LinphoneCallLog *log = (LinphoneCallLog *) bctbx_list_nth_data(logs_to_migrate, i); diff --git a/coreapi/private.h b/coreapi/private.h index 70f1f6820..b0c9d47e9 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -1254,7 +1254,7 @@ void _linphone_core_codec_config_write(LinphoneCore *lc); #endif #endif -LINPHONE_PUBLIC void call_logs_read_from_config_file(LinphoneCore *lc); +LINPHONE_PUBLIC bctbx_list_t * call_logs_read_from_config_file(LinphoneCore *lc); void call_logs_write_to_config_file(LinphoneCore *lc); void linphone_core_call_log_storage_init(LinphoneCore *lc); void linphone_core_call_log_storage_close(LinphoneCore *lc); diff --git a/tester/call_single_tester.c b/tester/call_single_tester.c index 2c08c73c5..991f28482 100644 --- a/tester/call_single_tester.c +++ b/tester/call_single_tester.c @@ -4898,7 +4898,7 @@ static void call_logs_migrate(void) { } laure->lc->call_logs = bctbx_list_free_with_data(laure->lc->call_logs, (void (*)(void*))linphone_call_log_unref); - call_logs_read_from_config_file(laure->lc); + laure->lc->call_logs = call_logs_read_from_config_file(laure->lc); BC_ASSERT_TRUE(bctbx_list_size(laure->lc->call_logs) == 0); unlink(logs_db);