chat.c: split chat and file transfer in 2 files and fix various memory leaks

parent 8a2f20ce
......@@ -52,6 +52,7 @@ set(SOURCE_FILES
call_log.c
call_params.c
chat.c
chat_file_transfer.c
conference.c
contactprovider.c
content.c
......
......@@ -54,6 +54,7 @@ liblinphone_la_SOURCES=\
call_log.c \
call_params.c \
chat.c \
chat_file_transfer.c \
conference.c \
contactprovider.c contactprovider.h contact_providers_priv.h \
content.c \
......
This diff is collapsed.
This diff is collapsed.
......@@ -511,6 +511,10 @@ void _linphone_proxy_config_release_ops(LinphoneProxyConfig *obj);
void linphone_chat_room_release(LinphoneChatRoom *cr);
void linphone_chat_message_destroy(LinphoneChatMessage* msg);
void linphone_chat_message_update_state(LinphoneChatMessage *msg, LinphoneChatMessageState new_state);
void linphone_chat_message_set_state(LinphoneChatMessage *msg, LinphoneChatMessageState state);
void linphone_chat_room_upload_file(LinphoneChatMessage *msg);
void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg);
LinphoneChatMessageCbs *linphone_chat_message_cbs_new(void);
/**/
struct _LinphoneProxyConfig
......
mediastreamer2 @ 8799e7b8
Subproject commit e4bbeb2123bd501b90ccfee958a4e20d3eebbf24
Subproject commit 8799e7b89e11d46aebfec8e948de3bf8e754e2ec
......@@ -216,6 +216,7 @@ static void text_message_within_dialog(void) {
linphone_chat_room_send_message(chat_room,"Bla bla bla bla");
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceived,1));
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageDelivered,1));
BC_ASSERT_PTR_NOT_NULL(linphone_core_get_chat_room(marie->lc,pauline->identity));
......@@ -482,6 +483,7 @@ LinphoneChatMessage* create_message_from_nowebcam(LinphoneChatRoom *chat_room) {
fseek(file_to_send, 0, SEEK_SET);
content = linphone_core_create_content(chat_room->lc);
belle_sip_object_set_name(&content->base, "nowebcam content");
linphone_content_set_type(content,"image");
linphone_content_set_subtype(content,"jpeg");
linphone_content_set_size(content,file_size); /*total size to be transfered*/
......@@ -494,22 +496,19 @@ LinphoneChatMessage* create_message_from_nowebcam(LinphoneChatRoom *chat_room) {
linphone_chat_message_set_user_data(msg, file_to_send);
linphone_content_unref(content);
ms_free(send_filepath);
return msg;
}
static void transfer_message(void) {
if (transport_supported(LinphoneTransportTls)) {
LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
LinphoneChatRoom* chat_room;
LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
char *send_filepath = bc_tester_res("images/nowebcamCIF.jpg");
char *receive_filepath = bc_tester_file("receive_file.dump");
LinphoneChatRoom* chat_room;
LinphoneChatMessage* msg;
LinphoneChatMessageCbs *cbs;
char *receive_filepath = bc_tester_file("receive_file.dump");
LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
reset_counters(&marie->stat);
reset_counters(&pauline->stat);
/* Globally configure an http file transfer server. */
linphone_core_set_file_transfer_server(pauline->lc,"https://www.linphone.org:444/lft.php");
......@@ -519,12 +518,7 @@ static void transfer_message(void) {
/* create a file transfer msg */
msg = create_message_from_nowebcam(chat_room);
cbs = linphone_chat_message_get_callbacks(msg);
{
int dummy=0;
wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge msg stored in the server*/
reset_counters(&marie->stat);
reset_counters(&pauline->stat);
}
linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed);
linphone_chat_room_send_chat_message(chat_room,msg);
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1));
......@@ -533,17 +527,16 @@ static void transfer_message(void) {
linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received);
linphone_chat_message_download_file(marie->stat.last_received_chat_message);
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,1));
compare_files(send_filepath, receive_filepath);
}
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,1));
BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,2, int, "%d"); //sent twice because of file transfer
BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,1, int, "%d");
BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,1, int, "%d");
compare_files(send_filepath, receive_filepath);
linphone_core_manager_destroy(pauline);
ms_free(send_filepath);
ms_free(receive_filepath);
linphone_core_manager_destroy(pauline);
linphone_core_manager_destroy(marie);
}
}
......@@ -1037,14 +1030,14 @@ static void transfer_message_io_error_download(void) {
/* wait for file to be 50% downloaded */
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.progress_of_LinphoneFileTransfer, 50));
/* and simulate network error */
sal_set_recv_error(marie->lc->sal, -1);
belle_http_provider_set_recv_error(marie->lc->http_provider, -1);
}
BC_ASSERT_TRUE(wait_for_until(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneMessageNotDelivered,1, 10000));
BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,2, int, "%d");
BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,1, int, "%d");
BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,0, int, "%d");
sal_set_recv_error(marie->lc->sal, 0);
belle_http_provider_set_recv_error(marie->lc->http_provider, 0);
linphone_core_manager_destroy(pauline);
linphone_core_manager_destroy(marie);
}
......@@ -1675,7 +1668,7 @@ static void file_transfer_io_error_after_destroying_chatroom() {
test_t message_tests[] = {
{"Text message", text_message},
{"Text message within call's dialog", text_message_within_dialog},
{"Text message within call dialog", text_message_within_dialog},
{"Text message with credentials from auth info cb", text_message_with_credential_from_auth_cb},
{"Text message with privacy", text_message_with_privacy},
{"Text message compatibility mode", text_message_compatibility_mode},
......
......@@ -494,11 +494,11 @@ void liblinphone_tester_after_each() {
BC_ASSERT_EQUAL(leaked_objects, 0, int, "%d");
if (leaked_objects > 0) {
belle_sip_object_dump_active_objects();
ms_error("%d objects were leaked in latest test, please fix that!", leaked_objects);
ms_error("%d object%s leaked in latest test, please fix that!", leaked_objects, leaked_objects>1?"s were":"was");
}
if (manager_count != 0) {
ms_fatal("%d linphone core managers are still alive!", manager_count);
ms_fatal("%d Linphone core managers are still alive!", manager_count);
}
}
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