diff --git a/coreapi/call_log.c b/coreapi/call_log.c index bf6f7c755..235b0bdc2 100644 --- a/coreapi/call_log.c +++ b/coreapi/call_log.c @@ -637,6 +637,34 @@ LinphoneCallLog * linphone_core_get_last_outgoing_call_log(LinphoneCore *lc) { return result; } +LinphoneCallLog * linphone_core_find_call_log_from_call_id(LinphoneCore *lc, const char *call_id) { + 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 call_id = '%q' ORDER BY id DESC LIMIT 1", call_id); + + 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; + } + + if (lc->call_logs && result) { + copy_user_data_from_existing_log(lc->call_logs, result); + } + + return result; +} + #else void linphone_core_call_log_storage_init(LinphoneCore *lc) { @@ -670,4 +698,8 @@ LinphoneCallLog * linphone_core_get_last_outgoing_call_log(LinphoneCore *lc) { return NULL; } +LinphoneCallLog * linphone_core_find_call_log_from_call_id(LinphoneCore *lc, const char *call_id) { + return NULL; +} + #endif \ No newline at end of file diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 60a4bf54f..6d1f8daa3 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -3276,6 +3276,14 @@ LINPHONE_PUBLIC MSList * linphone_core_get_call_history_for_address(LinphoneCore **/ LINPHONE_PUBLIC LinphoneCallLog * linphone_core_get_last_outgoing_call_log(LinphoneCore *lc); +/** + * Get the call log matching the call id, or NULL if can't be found. + * @param[in] lc LinphoneCore object + * @param[in] call_id Call id of the call log to find + * @return {LinphoneCallLog} +**/ +LINPHONE_PUBLIC LinphoneCallLog * linphone_core_find_call_log_from_call_id(LinphoneCore *lc, const char *call_id); + /** * Erase the call log. * @param[in] lc LinphoneCore object diff --git a/tester/call_tester.c b/tester/call_tester.c index 00c7ad594..8932cc1c9 100644 --- a/tester/call_tester.c +++ b/tester/call_tester.c @@ -5314,6 +5314,7 @@ static void call_logs_sqlite_storage(void) { logs = linphone_core_get_call_history_for_address(marie->lc, linphone_proxy_config_get_identity_address(linphone_core_get_default_proxy_config(pauline->lc))); if (BC_ASSERT_TRUE(ms_list_size(logs) == 1)) { + const char *call_id; const char *ref_key = linphone_call_log_get_ref_key(call_log); call_log = logs->data; BC_ASSERT_EQUAL(linphone_call_log_get_dir(call_log), LinphoneCallOutgoing, int, "%d"); @@ -5331,7 +5332,11 @@ static void call_logs_sqlite_storage(void) { BC_ASSERT_STRING_EQUAL(ref_key, "ref_key"); } BC_ASSERT_PTR_EQUAL(linphone_call_log_get_user_data(call_log), &start_time); - BC_ASSERT_PTR_NOT_NULL(linphone_call_log_get_call_id(call_log)); + + call_id = linphone_call_log_get_call_id(call_log); + BC_ASSERT_PTR_NOT_NULL(call_id); + BC_ASSERT_PTR_NOT_NULL(linphone_core_find_call_log_from_call_id(marie->lc, call_id)); + BC_ASSERT_TRUE(linphone_address_equal( linphone_call_log_get_remote_address(call_log), linphone_proxy_config_get_identity_address(linphone_core_get_default_proxy_config(pauline->lc)))); @@ -5339,6 +5344,7 @@ static void call_logs_sqlite_storage(void) { BC_ASSERT_GREATER(linphone_call_log_get_start_date(call_log), start_time, int, "%d"); BC_ASSERT_EQUAL(linphone_call_log_get_status(call_log), LinphoneCallSuccess, int, "%d"); } + linphone_core_delete_call_log(marie->lc, (LinphoneCallLog *)ms_list_nth_data(logs, 0)); ms_list_free_with_data(logs, (void (*)(void*))linphone_call_log_unref); BC_ASSERT_TRUE(linphone_core_get_call_history_size(marie->lc) == 0);