From 868c725dae0c46442add91caeb2d95cd3da8f396 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 2 Nov 2015 12:05:36 +0100 Subject: [PATCH] Improved a few things in RTT + added tests for message end character compatibility --- coreapi/chat.c | 45 ++++++++++++++++++++++++-------- coreapi/private.h | 6 +++++ tester/message_tester.c | 58 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 11 deletions(-) diff --git a/coreapi/chat.c b/coreapi/chat.c index b1980c7fc..e754ff0c7 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -188,6 +188,7 @@ static LinphoneChatRoom *_linphone_core_create_chat_room_base(LinphoneCore *lc, cr->peer = linphone_address_as_string(addr); cr->peer_url = addr; cr->unread_count = -1; + cr->received_rtt_characters = NULL; return cr; } @@ -291,6 +292,9 @@ static void linphone_chat_room_delete_remote_composing_refresh_timer(LinphoneCha } void linphone_chat_room_destroy(LinphoneChatRoom *cr) { + if (cr->received_rtt_characters) { + cr->received_rtt_characters = ms_list_free(cr->received_rtt_characters); + } linphone_chat_room_unref(cr); } @@ -810,12 +814,30 @@ static void linphone_chat_room_send_is_composing_notification(LinphoneChatRoom * void linphone_core_real_time_text_received(LinphoneCore *lc, LinphoneChatRoom *cr, uint32_t character, LinphoneCall *call) { uint32_t new_line = 0x2028; + uint32_t crlf = 0x0D0A; + uint32_t lf = 0x0A; + if (call && linphone_call_params_realtime_text_enabled(linphone_call_get_current_params(call))) { + char *value = NULL; + LinphoneChatMessageCharacter *cmc = ms_new0(LinphoneChatMessageCharacter, 1); + if (cr->pending_message == NULL) { cr->pending_message = linphone_chat_room_create_message(cr, ""); } - if (character == new_line) { + value = ms_strdup_printf("%c%c%c%c",((char*)&character)[0],((char*)&character)[1],((char*)&character)[2],((char*)&character)[3]); + cr->pending_message->message = ms_strcat_printf(cr->pending_message->message, value); + ms_message("Received RTT character: %s (%lu), pending text is %s", value, (unsigned long)character, cr->pending_message->message); + ms_free(value); + + cmc->value = character; + cmc->has_been_read = FALSE; + cr->received_rtt_characters = ms_list_append(cr->received_rtt_characters, (void *)cmc); + + cr->remote_is_composing = LinphoneIsComposingActive; + linphone_core_notify_is_composing_received(cr->lc, cr); + + if (character == new_line || character == crlf || character == lf) { // End of message LinphoneChatMessage *msg = cr->pending_message; ms_message("New line received, forge a message with content %s", cr->pending_message->message); @@ -837,21 +859,22 @@ void linphone_core_real_time_text_received(LinphoneCore *lc, LinphoneChatRoom *c linphone_chat_room_message_received(cr, lc, msg); linphone_chat_message_unref(msg); cr->pending_message = NULL; - } else { - char *value = ms_strdup_printf("%c%c%c%c",((char*)&character)[0],((char*)&character)[1],((char*)&character)[2],((char*)&character)[3]); - cr->pending_message->message = ms_strcat_printf(cr->pending_message->message, value); - ms_message("Received RTT character: %s (%lu), pending text is %s", value, (unsigned long)character, cr->pending_message->message); - ms_free(value); - - cr->remote_is_composing = LinphoneIsComposingActive; - linphone_core_notify_is_composing_received(cr->lc, cr); + cr->received_rtt_characters = ms_list_free(cr->received_rtt_characters); } } } uint32_t linphone_chat_room_get_char(const LinphoneChatRoom *cr) { - if (cr->pending_message && strlen(cr->pending_message->message) > 0) { - return cr->pending_message->message[strlen(cr->pending_message->message)-1]; + if (cr && cr->received_rtt_characters) { + MSList *characters = cr->received_rtt_characters; + while (characters != NULL) { + LinphoneChatMessageCharacter *cmc = (LinphoneChatMessageCharacter *)characters->data; + if (!cmc->has_been_read) { + cmc->has_been_read = TRUE; + return cmc->value; + } + characters = ms_list_next(characters); + } } return 0; } diff --git a/coreapi/private.h b/coreapi/private.h index 11f0147e5..f0bf47cdf 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -608,8 +608,14 @@ struct _LinphoneChatRoom{ belle_sip_source_t *composing_refresh_timer; LinphoneCall *call; LinphoneChatMessage *pending_message; + MSList *received_rtt_characters; }; +typedef struct _LinphoneChatMessageCharacter { + uint32_t value; + bool_t has_been_read; +} LinphoneChatMessageCharacter; + BELLE_SIP_DECLARE_VPTR(LinphoneChatRoom); diff --git a/tester/message_tester.c b/tester/message_tester.c index 8927455d6..b6fe1b23d 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -1335,6 +1335,7 @@ static void real_time_text(bool_t audio_stream_enabled, bool_t srtp_enabled) { BC_ASSERT_EQUAL(linphone_chat_room_get_char(marie_chat_room), message[i], char, "%c"); } linphone_chat_room_send_chat_message(pauline_chat_room, rtt_message); + BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageReceived, 1)); } if (!audio_stream_enabled) { @@ -1462,6 +1463,61 @@ static void real_time_text_srtp(void) { real_time_text(TRUE, TRUE); } +static void real_time_text_message_compat(bool_t end_with_crlf, bool_t end_with_lf) { + LinphoneChatRoom *pauline_chat_room; + LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); + LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); + LinphoneCallParams *marie_params = NULL; + LinphoneCall *pauline_call, *marie_call; + + marie_params = linphone_core_create_call_params(marie->lc, NULL); + linphone_call_params_enable_realtime_text(marie_params,TRUE); + + BC_ASSERT_TRUE(call_with_caller_params(marie, pauline, marie_params)); + pauline_call=linphone_core_get_current_call(pauline->lc); + marie_call=linphone_core_get_current_call(marie->lc); + if (pauline_call) { + BC_ASSERT_TRUE(linphone_call_params_realtime_text_enabled(linphone_call_get_current_params(pauline_call))); + + pauline_chat_room = linphone_call_get_chat_room(pauline_call); + BC_ASSERT_PTR_NOT_NULL(pauline_chat_room); + if (pauline_chat_room) { + const char* message = "Lorem Ipsum Belledonnum Communicatum"; + int i; + LinphoneChatMessage* rtt_message = linphone_chat_room_create_message(pauline_chat_room,NULL); + LinphoneChatRoom *marie_chat_room = linphone_call_get_chat_room(marie_call); + uint32_t crlf = 0x0D0A; + uint32_t lf = 0x0A; + + for (i = 0; i < strlen(message); i++) { + linphone_chat_message_put_char(rtt_message, message[i]); + BC_ASSERT_TRUE(wait_for_until(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneIsComposingActiveReceived, i+1, 1000)); + BC_ASSERT_EQUAL(linphone_chat_room_get_char(marie_chat_room), message[i], char, "%c"); + } + + if (end_with_crlf) { + linphone_chat_message_put_char(rtt_message, crlf); + } else if (end_with_lf) { + linphone_chat_message_put_char(rtt_message, lf); + } + BC_ASSERT_TRUE(wait_for_until(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneIsComposingActiveReceived, strlen(message), 1000)); + BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageReceived, 1)); + } + end_call(marie, pauline); + } + linphone_call_params_destroy(marie_params); + linphone_core_manager_destroy(marie); + linphone_core_manager_destroy(pauline); +} + +static void real_time_text_message_compat_crlf() { + real_time_text_message_compat(TRUE, FALSE); +} + +static void real_time_text_message_compat_lf() { + real_time_text_message_compat(FALSE, TRUE); +} + void file_transfer_with_http_proxy(void) { if (transport_supported(LinphoneTransportTls)) { LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); @@ -1514,6 +1570,8 @@ test_t message_tests[] = { {"Real Time Text conversation", real_time_text_conversation}, {"Real Time Text without audio", real_time_text_without_audio}, {"Real Time Text with srtp", real_time_text_srtp}, + {"Real Time Text message compatibility crlf", real_time_text_message_compat_crlf}, + {"Real Time Text message compatibility lf", real_time_text_message_compat_lf}, }; test_suite_t message_test_suite = {