From 63cc85751ccc0c2839476e98d7f38066d62f9490 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 12 Jan 2017 16:40:10 +0100 Subject: [PATCH 1/4] Fixed an issue with LIME and Preferred policy + added tests --- coreapi/lime.c | 6 ++- coreapi/proxy.c | 2 +- include/linphone/proxy_config.h | 2 +- tester/message_tester.c | 69 ++++++++++++++++++++++----------- 4 files changed, 52 insertions(+), 27 deletions(-) diff --git a/coreapi/lime.c b/coreapi/lime.c index c72bef7ba..cc231eb08 100644 --- a/coreapi/lime.c +++ b/coreapi/lime.c @@ -1009,8 +1009,10 @@ int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneImEncryptionEn xmlFreeDoc(cacheXml); } } else { - ms_warning("Unable to access ZRTP ZID cache to encrypt message"); - errcode = 488; + if (linphone_core_lime_enabled(lc) == LinphoneLimeMandatory) { + ms_warning("Unable to access ZRTP ZID cache to encrypt message"); + errcode = 488; + } } } return errcode; diff --git a/coreapi/proxy.c b/coreapi/proxy.c index c4daca873..4f0cbf654 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -537,7 +537,7 @@ bool_t linphone_proxy_config_quality_reporting_enabled(LinphoneProxyConfig *cfg) return cfg->quality_reporting_enabled; } -void linphone_proxy_config_set_quality_reporting_interval(LinphoneProxyConfig *cfg, uint8_t interval) { +void linphone_proxy_config_set_quality_reporting_interval(LinphoneProxyConfig *cfg, int interval) { cfg->quality_reporting_interval = interval; } diff --git a/include/linphone/proxy_config.h b/include/linphone/proxy_config.h index f437bcc50..b38c09678 100644 --- a/include/linphone/proxy_config.h +++ b/include/linphone/proxy_config.h @@ -202,7 +202,7 @@ LINPHONE_PUBLIC const char *linphone_proxy_config_get_quality_reporting_collecto * @param[in] cfg #LinphoneProxyConfig object. * @param[in] interval The interval in seconds, 0 means interval reports are disabled. */ -LINPHONE_PUBLIC void linphone_proxy_config_set_quality_reporting_interval(LinphoneProxyConfig *cfg, uint8_t interval); +LINPHONE_PUBLIC void linphone_proxy_config_set_quality_reporting_interval(LinphoneProxyConfig *cfg, int interval); /** * Get the interval between interval reports when using quality reporting. diff --git a/tester/message_tester.c b/tester/message_tester.c index 432b07ffe..a2b15c008 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -647,8 +647,8 @@ static void file_transfer_using_external_body_url(void) { LinphoneCoreManager *pauline = linphone_core_manager_new("pauline_rc"); /* make sure lime is disabled */ - linphone_core_enable_lime(marie->lc, FALSE); - linphone_core_enable_lime(pauline->lc, FALSE); + linphone_core_enable_lime(marie->lc, LinphoneLimeDisabled); + linphone_core_enable_lime(pauline->lc, LinphoneLimeDisabled); /* create a chatroom on pauline's side */ chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); @@ -854,8 +854,8 @@ static void _is_composing_notification(bool_t lime_enabled) { goto end; } /* make sure lime is enabled */ - linphone_core_enable_lime(marie->lc, 1); - linphone_core_enable_lime(pauline->lc, 1); + linphone_core_enable_lime(marie->lc, LinphoneLimeMandatory); + linphone_core_enable_lime(pauline->lc, LinphoneLimeMandatory); /* set the zid caches files : create two ZID cache from this valid one inserting the auto-generated sip URI for the peer account as keys in ZID cache are indexed by peer sip uri */ ZIDCacheMarieFD = fopen_from_write_dir("tmpZIDCacheMarie.xml", "w"); @@ -1032,8 +1032,8 @@ static void _im_error_delivery_notification(bool_t online) { } /* Make sure lime is enabled */ - linphone_core_enable_lime(marie->lc, 1); - linphone_core_enable_lime(pauline->lc, 1); + linphone_core_enable_lime(marie->lc, LinphoneLimeMandatory); + linphone_core_enable_lime(pauline->lc, LinphoneLimeMandatory); /* Set the zid cache files : create two ZID cache from this valid one inserting the auto-generated sip URI for the peer account as keys in ZID cache are indexed by peer sip uri. */ ZIDCacheMarieFD = fopen_from_write_dir("tmpZIDCacheMarie.xml", "w"); @@ -1112,8 +1112,8 @@ static void lime_text_message(void) { goto end; } /* make sure lime is enabled */ - linphone_core_enable_lime(marie->lc, 1); - linphone_core_enable_lime(pauline->lc, 1); + linphone_core_enable_lime(marie->lc, LinphoneLimeMandatory); + linphone_core_enable_lime(pauline->lc, LinphoneLimeMandatory); /* set the zid caches files : create two ZID cache from this valid one inserting the auto-generated sip URI for the peer account as keys in ZID cache are indexed by peer sip uri */ ZIDCacheMarieFD = fopen_from_write_dir("tmpZIDCacheMarie.xml", "w"); @@ -1150,7 +1150,7 @@ end: linphone_core_manager_destroy(pauline); } -static void lime_text_message_to_non_lime(void) { +static void lime_text_message_to_non_lime(bool_t sender_policy_mandatory, bool_t lime_key_available) { FILE *ZIDCachePaulineFD; LinphoneChatRoom* chat_room; char* filepath; @@ -1162,24 +1162,32 @@ static void lime_text_message_to_non_lime(void) { goto end; } /* make sure lime is enabled */ - linphone_core_enable_lime(marie->lc, 0); - linphone_core_enable_lime(pauline->lc, 1); + linphone_core_enable_lime(marie->lc, LinphoneLimeDisabled); + linphone_core_enable_lime(pauline->lc, sender_policy_mandatory ? LinphoneLimeMandatory : LinphoneLimePreferred); - /* set the zid caches files : create two ZID cache from this valid one inserting the auto-generated sip URI for the peer account as keys in ZID cache are indexed by peer sip uri */ - ZIDCachePaulineFD = fopen_from_write_dir("tmpZIDCachePauline.xml", "w"); - fprintf(ZIDCachePaulineFD, pauline_zid_cache, linphone_address_as_string_uri_only(marie->identity), linphone_address_as_string_uri_only(marie->identity)); - fclose(ZIDCachePaulineFD); + if (lime_key_available) { + /* set the zid caches files : create two ZID cache from this valid one inserting the auto-generated sip URI for the peer account as keys in ZID cache are indexed by peer sip uri */ + ZIDCachePaulineFD = fopen_from_write_dir("tmpZIDCachePauline.xml", "w"); + fprintf(ZIDCachePaulineFD, pauline_zid_cache, linphone_address_as_string_uri_only(marie->identity), linphone_address_as_string_uri_only(marie->identity)); + fclose(ZIDCachePaulineFD); - filepath = bc_tester_file("tmpZIDCachePauline.xml"); - linphone_core_set_zrtp_secrets_file(pauline->lc, filepath); - bc_free(filepath); + filepath = bc_tester_file("tmpZIDCachePauline.xml"); + linphone_core_set_zrtp_secrets_file(pauline->lc, filepath); + bc_free(filepath); + } chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); linphone_chat_room_send_message(chat_room,"Bla bla bla bla"); //since we cannot decrypt message, we should not receive any message - BC_ASSERT_FALSE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceived,1)); - BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageReceivedLegacy,0, int, "%d"); + if (sender_policy_mandatory || lime_key_available) { + BC_ASSERT_FALSE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceived,1)); + BC_ASSERT_FALSE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageNotDelivered,1)); + BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageReceivedLegacy, 0, int, "%d"); + } else { + BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceived,1)); + BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageReceivedLegacy, 1, int, "%d"); + } BC_ASSERT_PTR_NOT_NULL(linphone_core_get_chat_room(marie->lc,pauline->identity)); end: @@ -1187,6 +1195,19 @@ end: linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); } + +static void lime_text_message_to_non_lime_mandatory_policy(void) { + lime_text_message_to_non_lime(TRUE, TRUE); +} + +static void lime_text_message_to_non_lime_preferred_policy(void) { + lime_text_message_to_non_lime(FALSE, TRUE); +} + +static void lime_text_message_to_non_lime_preferred_policy_2(void) { + lime_text_message_to_non_lime(FALSE, FALSE); +} + void lime_transfer_message_base(bool_t encrypt_file,bool_t download_file_from_stored_msg, bool_t use_file_body_handler_in_upload, bool_t use_file_body_handler_in_download) { FILE *ZIDCacheMarieFD, *ZIDCachePaulineFD; LinphoneCoreManager *marie, *pauline; @@ -1209,8 +1230,8 @@ void lime_transfer_message_base(bool_t encrypt_file,bool_t download_file_from_st goto end; } /* make sure lime is enabled */ - linphone_core_enable_lime(marie->lc, 1); - linphone_core_enable_lime(pauline->lc, 1); + linphone_core_enable_lime(marie->lc, LinphoneLimeMandatory); + linphone_core_enable_lime(pauline->lc, LinphoneLimeMandatory); if (!encrypt_file) { LpConfig *pauline_lp = linphone_core_get_config(pauline->lc); lp_config_set_int(pauline_lp,"sip","lime_for_file_sharing",0); @@ -2271,7 +2292,9 @@ test_t message_tests[] = { TEST_ONE_TAG("IM error delivery notification online", im_error_delivery_notification_online, "LIME"), TEST_ONE_TAG("IM error delivery notification offline", im_error_delivery_notification_offline, "LIME"), TEST_ONE_TAG("Lime text message", lime_text_message, "LIME"), - TEST_ONE_TAG("Lime text message to non lime", lime_text_message_to_non_lime, "LIME"), + TEST_ONE_TAG("Lime text message to non lime", lime_text_message_to_non_lime_mandatory_policy, "LIME"), + TEST_ONE_TAG("Lime text message to non lime with preferred policy", lime_text_message_to_non_lime_preferred_policy, "LIME"), + TEST_ONE_TAG("Lime text message to non lime with preferred policy 2", lime_text_message_to_non_lime_preferred_policy_2, "LIME"), TEST_ONE_TAG("Lime transfer message", lime_transfer_message, "LIME"), TEST_ONE_TAG("Lime transfer message 2", lime_transfer_message_2, "LIME"), TEST_ONE_TAG("Lime transfer message 3", lime_transfer_message_3, "LIME"), From 7793ff2ccebaeed6b10d216b5a65ab1008fd582b Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 12 Jan 2017 17:04:18 +0100 Subject: [PATCH 2/4] Set from while sending chat message before encryption step, so if it fails information is available --- coreapi/chat.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/coreapi/chat.c b/coreapi/chat.c index a484763b8..ff14138a3 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -392,6 +392,23 @@ void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage } } + if (!identity) { + LinphoneProxyConfig *proxy = linphone_core_lookup_known_proxy(cr->lc, cr->peer_url); + if (proxy) { + identity = linphone_proxy_config_get_identity(proxy); + } else { + identity = linphone_core_get_primary_contact(cr->lc); + } + } + if (msg->from){ + /* + * BUG + * the file transfer message constructor sets the from, but doesn't do it as well as here. + */ + linphone_address_destroy(msg->from); + } + msg->from = linphone_address_new(identity); + if (imee) { LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee); LinphoneImEncryptionEngineCbsOutgoingMessageCb cb_process_outgoing_message = linphone_im_encryption_engine_cbs_get_process_outgoing_message(imee_cbs); @@ -401,11 +418,6 @@ void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage } if (op == NULL) { - LinphoneProxyConfig *proxy = linphone_core_lookup_known_proxy(cr->lc, cr->peer_url); - if (proxy) { - identity = linphone_proxy_config_get_identity(proxy); - } else - identity = linphone_core_get_primary_contact(cr->lc); /*sending out of calls*/ msg->op = op = sal_op_new(cr->lc->sal); linphone_configure_op(cr->lc, op, cr->peer_url, msg->custom_headers, @@ -435,19 +447,11 @@ void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage ms_free(peer_uri); } - if (msg->from){ - /* - * BUG - * the file transfer message constructor sets the from, but doesn't do it as well as here. - */ - linphone_address_destroy(msg->from); - } if (msg->message && message_not_encrypted && strcmp(msg->message, message_not_encrypted) != 0) { // We replace the encrypted message by the original one so it can be correctly stored and displayed by the application ms_free(msg->message); msg->message = ms_strdup(message_not_encrypted); } - msg->from = linphone_address_new(identity); msg->message_id = ms_strdup(sal_op_get_call_id(op)); /* must be known at that time */ msg->storage_id = linphone_chat_message_store(msg); From 17fd6667e09afc4de233b7ba292db25b726c813e Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Thu, 12 Jan 2017 17:47:25 +0100 Subject: [PATCH 3/4] Prevent crash in Windows 10 tester for tests with the "Skip" tag. --- tester/liblinphone_tester_windows.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tester/liblinphone_tester_windows.cpp b/tester/liblinphone_tester_windows.cpp index 1748e712b..03ae5912a 100644 --- a/tester/liblinphone_tester_windows.cpp +++ b/tester/liblinphone_tester_windows.cpp @@ -147,6 +147,7 @@ Platform::String^ NativeTester::testName(Platform::String^ suiteName, int testIn char csuitename[MAX_SUITE_NAME_SIZE] = { 0 }; wcstombs(csuitename, suitename.c_str(), sizeof(csuitename)); const char *cname = bc_tester_test_name(csuitename, testIndex); + if (cname == NULL) return ref new String(); wchar_t wcname[MAX_SUITE_NAME_SIZE]; mbstowcs(wcname, cname, sizeof(wcname)); return ref new String(wcname); From 1f3b1395513a4c1578597e36673ee6eaf6149650 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Thu, 12 Jan 2017 17:48:18 +0100 Subject: [PATCH 4/4] Fix crash during call invite if no SIP transport is available. --- coreapi/linphonecore.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index c0ffc626f..aff09159d 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2905,7 +2905,8 @@ int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, const Linph barmsg=ortp_strdup_printf("%s %s", _("Contacting"), real_url); linphone_core_notify_display_status(lc,barmsg); ms_free(barmsg); - + + linphone_call_ref(call); /* Take a ref because sal_call() may destroy the call if no SIP transport is available */ err=sal_call(call->op,from,real_url); if (err < 0){ @@ -2928,6 +2929,7 @@ int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, const Linph linphone_call_set_state(call,LinphoneCallOutgoingProgress,"Outgoing call in progress"); end: + linphone_call_unref(call); /* Revert the ref taken before calling sal_call() */ ms_free(real_url); ms_free(from); return err;