diff --git a/coreapi/call_log.c b/coreapi/call_log.c index b3d9cbb75..df6ce74e5 100644 --- a/coreapi/call_log.c +++ b/coreapi/call_log.c @@ -571,6 +571,30 @@ MSList * linphone_core_get_call_history_for_address(LinphoneCore *lc, const Linp return result; } +LinphoneCallLog * linphone_core_get_last_outgoing_call_log(LinphoneCore *lc) { + char *buf; + uint64_t begin,end; + MSList *list = NULL; + LinphoneCallLog* result = NULL; + + if (!lc || lc->logs_db == NULL) return NULL; + + /*since we want to append query parameters depending on arguments given, we use malloc instead of sqlite3_mprintf*/ + buf = sqlite3_mprintf("SELECT * FROM call_history WHERE direction = 0 ORDER BY id DESC LIMIT 1"); + + begin = ortp_get_cur_time_ms(); + linphone_sql_request_call_log(lc->logs_db, buf, &list); + end = ortp_get_cur_time_ms(); + ms_message("%s(): completed in %i ms",__FUNCTION__, (int)(end-begin)); + sqlite3_free(buf); + + if (list) { + result = (LinphoneCallLog*)list->data; + } + + return result; +} + #else void linphone_core_call_log_storage_init(LinphoneCore *lc) { @@ -600,4 +624,8 @@ MSList * linphone_core_get_call_history_for_address(LinphoneCore *lc, const Linp return NULL; } +const LinphoneCallLog * linphone_core_get_last_outgoing_call_log(LinphoneCore *lc) { + return NULL; +} + #endif \ No newline at end of file diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 0d9326967..56ebcb397 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -3245,6 +3245,13 @@ LINPHONE_PUBLIC const MSList * linphone_core_get_call_logs(LinphoneCore *lc); **/ LINPHONE_PUBLIC MSList * linphone_core_get_call_history_for_address(LinphoneCore *lc, const LinphoneAddress *addr); +/** + * Get the latest outgoing call log. + * @param[in] lc LinphoneCore object + * @return {LinphoneCallLog} +**/ +LINPHONE_PUBLIC LinphoneCallLog * linphone_core_get_last_outgoing_call_log(LinphoneCore *lc); + /** * Erase the call log. * @param[in] lc LinphoneCore object diff --git a/tester/call_tester.c b/tester/call_tester.c index 3b905d808..d051edd91 100644 --- a/tester/call_tester.c +++ b/tester/call_tester.c @@ -5007,6 +5007,16 @@ static void call_logs_migrate(void) { BC_ASSERT_TRUE(aborted_count == 3); BC_ASSERT_TRUE(decline_count == 2); BC_ASSERT_TRUE(video_enabled_count == 3); + + { + LinphoneCallLog *log = linphone_core_get_last_outgoing_call_log(laure->lc); + BC_ASSERT_PTR_NOT_NULL(log); + if (log) { + BC_ASSERT_EQUAL((int)log->start_date_time, 1441738272, int, "%d"); + linphone_call_log_unref(log); + log = NULL; + } + } laure->lc->call_logs = ms_list_free_with_data(laure->lc->call_logs, (void (*)(void*))linphone_call_log_unref); call_logs_read_from_config_file(laure->lc);