From de4b77f54e9ce3c34429606c55f88c47fb15fb61 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Tue, 15 Nov 2016 09:25:54 +0100 Subject: [PATCH] make sure normalized phone numbers are computed for each new subscription to take into account potentiel proxy config changes. --- coreapi/friend.c | 14 ++++++- tester/flexisip_tester.c | 26 ++++++++++++ tester/local_tester_hosts | 2 +- tester/presence_server_tester.c | 73 ++++++++++++++++++++++++++++++++- 4 files changed, 110 insertions(+), 5 deletions(-) diff --git a/coreapi/friend.c b/coreapi/friend.c index 0cecfb3a0..b5f93e795 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -1669,8 +1669,18 @@ const char * linphone_friend_phone_number_to_sip_uri(LinphoneFriend *lf, const c while (iterator) { lfpnsu = (LinphoneFriendPhoneNumberSipUri *)bctbx_list_get_data(iterator); - if (strcmp(lfpnsu->number, phone_number) == 0) return lfpnsu->uri; - iterator = bctbx_list_next(iterator); + if (strcmp(lfpnsu->number, phone_number) == 0) { + /*force sip uri computation because proxy config may have changed, specially, ccc could have been added since last computation*/ + free_phone_number_sip_uri(lfpnsu); + if (lf->phone_number_sip_uri_map == iterator) { + /*change list head if head is removed*/ + iterator = lf->phone_number_sip_uri_map = bctbx_list_erase_link(lf->phone_number_sip_uri_map, iterator); + } else { + iterator = bctbx_list_erase_link(lf->phone_number_sip_uri_map, iterator); + } + } else { + iterator = bctbx_list_next(iterator); + } } proxy_config = linphone_core_get_default_proxy_config(linphone_friend_get_core(lf)); diff --git a/tester/flexisip_tester.c b/tester/flexisip_tester.c index 82fefe92a..919f181bf 100644 --- a/tester/flexisip_tester.c +++ b/tester/flexisip_tester.c @@ -1170,6 +1170,31 @@ static void test_subscribe_on_wrong_dialog(void) { } #endif +static void test_list_subscribe_wrong_body(void) { + LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); + + LinphoneEvent *lev; + LinphoneAddress *sub_addr = linphone_address_new("sip:rls@sip.example.com"); + + lev=linphone_core_create_subscribe(marie->lc,sub_addr,"presence",60); + + linphone_event_add_custom_header(lev,"Supported","eventlist"); + linphone_event_add_custom_header(lev,"Accept","application/pidf+xml, application/rlmi+xml"); + linphone_event_add_custom_header(lev,"Content-Disposition", "recipient-list"); + linphone_event_add_custom_header(lev,"Require", "recipient-list-subscribe"); + linphone_event_add_custom_header(lev,"Content-type", "application/resource-lists+xml"); + + linphone_event_send_subscribe(lev,NULL); + + BC_ASSERT_TRUE(wait_for_until(marie->lc,NULL,&marie->stat.number_of_LinphoneSubscriptionOutgoingProgress,1,1000)); + BC_ASSERT_FALSE(wait_for_until(marie->lc,NULL,&marie->stat.number_of_LinphoneSubscriptionActive,1,2000)); + + linphone_event_terminate(lev); + linphone_core_manager_destroy(marie); + linphone_address_unref(sub_addr); +} + + static void publish_subscribe(void) { LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc"); @@ -1215,6 +1240,7 @@ test_t flexisip_tests[] = { #endif TEST_NO_TAG("Publish/unpublish", test_publish_unpublish), TEST_NO_TAG("List subscribe", test_list_subscribe), + TEST_NO_TAG("List subscribe without body", test_list_subscribe_wrong_body), TEST_NO_TAG("File transfer message rcs to external body client", file_transfer_message_rcs_to_external_body_client), TEST_ONE_TAG("File transfer message external body to rcs client", file_transfer_message_external_body_to_rcs_client, "LeaksMemory"), TEST_ONE_TAG("File transfer message external body to external body client", file_transfer_message_external_body_to_external_body_client, "LeaksMemory"), diff --git a/tester/local_tester_hosts b/tester/local_tester_hosts index 0a78dd3e9..5966c32bb 100644 --- a/tester/local_tester_hosts +++ b/tester/local_tester_hosts @@ -1,4 +1,4 @@ 127.0.0.1 sip2.linphone.org sip.example.org sipopen.example.org auth.example.org auth1.example.org auth2.example.org altname.linphone.org sip.wildcard1.linphone.org altname.wildcard2.linphone.org sipv4.example.org -2001:41d0:2:14b0::1 sip2.linphone.org sip.example.org sipopen.example.org auth.example.org auth1.example.org auth2.example.org altname.linphone.org sip.wildcard1.linphone.org altname.wildcard2.linphone.org +::1 sip2.linphone.org sip.example.org sipopen.example.org auth.example.org auth1.example.org auth2.example.org altname.linphone.org sip.wildcard1.linphone.org altname.wildcard2.linphone.org 188.165.46.90 tunnel.wildcard2.linphone.org 64:ff9b::94.23.19.176 sipv4-nat64.example.org diff --git a/tester/presence_server_tester.c b/tester/presence_server_tester.c index a74abc7d0..18305bdb9 100644 --- a/tester/presence_server_tester.c +++ b/tester/presence_server_tester.c @@ -771,7 +771,7 @@ static void long_term_presence_list(void) { }else ms_warning("Test skipped, no vcard support"); } -static void long_term_presence_phone_without_sip(void) { +static void long_term_presence_with_e164_phone_without_sip(void) { if (linphone_core_vcard_supported()){ LinphoneCoreManager *marie = linphone_core_manager_new3("marie_rc", TRUE, random_phone_number()); char * identity = linphone_address_as_string_uri_only(marie->identity); @@ -811,6 +811,74 @@ static void long_term_presence_phone_without_sip(void) { }else ms_warning("Test skipped, no vcard support"); } +static void long_term_presence_with_phone_without_sip(void) { + if (linphone_core_vcard_supported()){ + const LinphoneDialPlan *dialPlan; + char phone[20]; + char* e164; + size_t i; + LinphoneProxyConfig * proxy_config; + LinphoneFriend* friend2; + char *presence_contact; + LinphoneCoreManager *marie = NULL; + char * identity=NULL; + + while ((dialPlan = linphone_dial_plan_by_ccc_as_int(bctbx_random()%900)) == linphone_dial_plan_by_ccc(NULL)); + /*now with have a dialplan*/ + for (i = 0; i < MIN((size_t)dialPlan->nnl,sizeof(phone)-1); i++) { + phone[i] = '0' + rand() % 10; + } + phone[i+1]='\0'; + + e164=ms_strdup_printf("+%s%s",dialPlan->ccc,phone); + + marie = linphone_core_manager_new3("marie_rc", TRUE, e164); + identity = linphone_address_as_string_uri_only(marie->identity); + + LinphoneCoreManager *pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc"); + linphone_core_set_user_agent(pauline->lc, "full-presence-support", NULL); + + friend2=linphone_core_create_friend(pauline->lc); + linphone_friend_add_phone_number(friend2, phone); + linphone_core_add_friend(pauline->lc,friend2); + + linphone_friend_list_set_rls_uri(linphone_core_get_default_friend_list(pauline->lc), "sip:rls@sip.example.org"); + linphone_friend_list_enable_subscriptions(linphone_core_get_default_friend_list(pauline->lc), TRUE); + linphone_core_refresh_registers(pauline->lc); + + /*because phone is not normalized*/ + BC_ASSERT_FALSE(wait_for_until(pauline->lc,NULL,&pauline->stat.number_of_LinphonePresenceActivityOnline,1,2000)); + + /*know adding ccc to proxy config*/ + proxy_config = linphone_core_get_default_proxy_config(pauline->lc); + linphone_proxy_config_edit(proxy_config); + linphone_proxy_config_set_dial_prefix(proxy_config, dialPlan->ccc); + linphone_proxy_config_done(proxy_config); + /*re-create sub list*/ + linphone_friend_list_enable_subscriptions(linphone_core_get_default_friend_list(pauline->lc), FALSE); + + wait_for_until(pauline->lc, NULL, NULL, 0,2000); /*wait for unsubscribe*/ + + linphone_friend_list_enable_subscriptions(linphone_core_get_default_friend_list(pauline->lc), TRUE); + + BC_ASSERT_TRUE(wait_for(pauline->lc,NULL,&pauline->stat.number_of_LinphonePresenceActivityOnline,1)); + BC_ASSERT_EQUAL(pauline->stat.number_of_LinphonePresenceActivityOnline, 1, int, "%d"); + BC_ASSERT_EQUAL(linphone_presence_model_get_basic_status(linphone_friend_get_presence_model(friend2)), LinphonePresenceBasicStatusOpen, int, "%d"); + if(BC_ASSERT_PTR_NOT_NULL(linphone_friend_get_presence_model(friend2))) { + presence_contact = linphone_presence_model_get_contact(linphone_friend_get_presence_model(friend2)); + if (BC_ASSERT_PTR_NOT_NULL(presence_contact)) { + BC_ASSERT_STRING_EQUAL(presence_contact, identity); + ms_free(presence_contact); + } + } + linphone_friend_unref(friend2); + linphone_core_manager_destroy(pauline); + ms_free(e164); + ms_free(identity); + linphone_core_manager_destroy(marie); + }else ms_warning("Test skipped, no vcard support"); +} + test_t presence_server_tests[] = { TEST_NO_TAG("Simple", simple), @@ -826,7 +894,8 @@ test_t presence_server_tests[] = { TEST_ONE_TAG("Long term presence phone alias",long_term_presence_phone_alias, "longterm"), TEST_ONE_TAG("Long term presence phone alias 2",long_term_presence_phone_alias2, "longterm"), TEST_ONE_TAG("Long term presence list",long_term_presence_list, "longterm"), - TEST_ONE_TAG("Long term presence phone without sip",long_term_presence_phone_without_sip, "longterm"), + TEST_ONE_TAG("Long term presence with +164 phone, without sip",long_term_presence_with_e164_phone_without_sip, "longterm"), + TEST_ONE_TAG("Long term presence with phone, without sip",long_term_presence_with_phone_without_sip, "longterm"), TEST_NO_TAG("Subscriber no longer reachable using server",subscriber_no_longer_reachable), TEST_NO_TAG("Subscribe with late publish", subscribe_with_late_publish), };