Commit 10458ff9 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Added method to find call log from call id

parent f1a872ce
......@@ -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
......@@ -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
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment