From 6e734e6b0bb4bca73dc1c3050904dfc64d633deb Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Mon, 25 Sep 2017 11:01:57 +0200 Subject: [PATCH] Add Gruu implementation completion from master in dev_refactor_cpp branch --- coreapi/bellesip_sal/sal_address_impl.c | 5 ++ coreapi/bellesip_sal/sal_op_impl.c | 4 +- coreapi/linphonecore.c | 19 +++++- src/c-wrapper/internal/c-sal.h | 1 + src/sal/op.cpp | 16 +++-- tester/call_single_tester.c | 84 ++++++++++++++++++------- tester/complex_sip_case_tester.c | 8 ++- tester/flexisip_tester.c | 11 ++++ tester/register_tester.c | 38 ++++++++++- 9 files changed, 146 insertions(+), 40 deletions(-) diff --git a/coreapi/bellesip_sal/sal_address_impl.c b/coreapi/bellesip_sal/sal_address_impl.c index a78bf28e6..8ee6b0f8e 100644 --- a/coreapi/bellesip_sal/sal_address_impl.c +++ b/coreapi/bellesip_sal/sal_address_impl.c @@ -232,6 +232,11 @@ const char * sal_address_get_uri_param(const SalAddress *addr, const char *name) return belle_sip_parameters_get_parameter(parameters, name); } +void sal_address_remove_uri_param(const SalAddress *addr, const char *name) { + belle_sip_parameters_t* parameters = BELLE_SIP_PARAMETERS(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(addr))); + belle_sip_parameters_remove_parameter(parameters, name); +} + void sal_address_set_header(SalAddress *addr, const char *header_name, const char *header_value){ belle_sip_uri_set_header(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(addr)),header_name, header_value); } diff --git a/coreapi/bellesip_sal/sal_op_impl.c b/coreapi/bellesip_sal/sal_op_impl.c index f3a9bce2e..80f661b54 100644 --- a/coreapi/bellesip_sal/sal_op_impl.c +++ b/coreapi/bellesip_sal/sal_op_impl.c @@ -134,6 +134,4 @@ void sal_error_info_set(SalErrorInfo *ei, SalReason reason, const char *protocol ei->full_string=ms_strdup_printf("%s %s",ei->status_string,ei->warnings); else ei->full_string=ms_strdup(ei->status_string); } -} - - +} \ No newline at end of file diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 7dedc0672..3401c9bec 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -3454,6 +3454,7 @@ static void linphone_transfer_routes_to_op(bctbx_list_t *routes, SalOp *op){ void linphone_configure_op_with_proxy(LinphoneCore *lc, SalOp *op, const LinphoneAddress *dest, SalCustomHeader *headers, bool_t with_contact, LinphoneProxyConfig *proxy){ bctbx_list_t *routes=NULL; const char *identity; + if (proxy){ identity=linphone_proxy_config_get_identity(proxy); if (linphone_proxy_config_get_privacy(proxy)!=LinphonePrivacyDefault) { @@ -3465,12 +3466,24 @@ void linphone_configure_op_with_proxy(LinphoneCore *lc, SalOp *op, const Linphon routes=make_routes_for_proxy(proxy,dest); linphone_transfer_routes_to_op(routes,op); } - char *addr = linphone_address_as_string(dest); - op->set_to(addr); - ms_free(addr); + + const SalAddress *sal_dest = L_GET_PRIVATE_FROM_C_OBJECT(dest)->getInternalAddress(); + if (sal_address_has_uri_param(sal_dest,"gr")) { + /*in case of gruu destination remove gruu parram from to*/ + SalAddress *dest_copy = sal_address_clone(sal_dest); + sal_address_remove_uri_param(dest_copy,"gr"); + op->set_to_address(dest_copy); + sal_address_unref(dest_copy); + } else { + char *addr = linphone_address_as_string(dest); + op->set_to(addr); + ms_free(addr); + } + op->set_from(identity); op->set_sent_custom_header(headers); op->set_realm(linphone_proxy_config_get_realm(proxy)); + if (with_contact && proxy && proxy->op){ const LinphoneAddress *contact = linphone_proxy_config_get_contact(proxy); SalAddress *salAddress = nullptr; diff --git a/src/c-wrapper/internal/c-sal.h b/src/c-wrapper/internal/c-sal.h index 7c4d5d1a5..6b869f02b 100644 --- a/src/c-wrapper/internal/c-sal.h +++ b/src/c-wrapper/internal/c-sal.h @@ -130,6 +130,7 @@ void sal_address_set_uri_param(SalAddress *addr, const char *name, const char *v void sal_address_set_uri_params(SalAddress *addr, const char *params); bool_t sal_address_has_uri_param(const SalAddress *addr, const char *name); const char * sal_address_get_uri_param(const SalAddress *addr, const char *name); +void sal_address_remove_uri_param(const SalAddress *addr, const char *name); bool_t sal_address_is_ipv6(const SalAddress *addr); bool_t sal_address_is_sip(const SalAddress *addr); void sal_address_set_password(SalAddress *addr, const char *passwd); diff --git a/src/sal/op.cpp b/src/sal/op.cpp index 2b6912043..e9a07b34a 100644 --- a/src/sal/op.cpp +++ b/src/sal/op.cpp @@ -620,6 +620,7 @@ belle_sip_request_t* SalOp::build_request(const char* method) { belle_sip_uri_set_secure(req_uri,is_secure()); to_header = belle_sip_header_to_create(BELLE_SIP_HEADER_ADDRESS(to_address),NULL); + belle_sip_parameters_remove_parameter(BELLE_SIP_PARAMETERS(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(to_header))), "gr"); /*remove gruu in any case*/ call_id_header = belle_sip_provider_create_call_id(prov); if (get_call_id()) { belle_sip_header_call_id_set_call_id(call_id_header, get_call_id()); @@ -773,12 +774,15 @@ belle_sip_header_contact_t *SalOp::create_contact() { if (this->privacy!=SalPrivacyNone){ belle_sip_uri_set_user(contact_uri,NULL); } - belle_sip_header_contact_set_automatic(contact_header,this->root->auto_contacts); - if (this->root->uuid){ - if (belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(contact_header),"+sip.instance")==0){ - char *instance_id=belle_sip_strdup_printf("\"\"",this->root->uuid); - belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS(contact_header),"+sip.instance",instance_id); - belle_sip_free(instance_id); + /*don't touch contact in case of gruu*/ + if (!belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(contact_header))),"gr")) { + belle_sip_header_contact_set_automatic(contact_header,this->root->auto_contacts); + if (this->root->uuid) { + if (belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(contact_header),"+sip.instance")==0){ + char *instance_id=belle_sip_strdup_printf("\"\"",this->root->uuid); + belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS(contact_header),"+sip.instance",instance_id); + belle_sip_free(instance_id); + } } } return contact_header; diff --git a/tester/call_single_tester.c b/tester/call_single_tester.c index 514c524dc..9d3d108c6 100644 --- a/tester/call_single_tester.c +++ b/tester/call_single_tester.c @@ -1414,7 +1414,7 @@ static void call_declined_with_error(void) { BC_ASSERT_PTR_NOT_NULL(in_call=linphone_core_get_current_call(callee_mgr->lc)); linphone_call_ref(out_call); - BC_ASSERT_TRUE(wait_for(caller_mgr->lc,callee_mgr->lc,&callee_mgr->stat.number_of_LinphoneCallIncomingReceived,1)); + BC_ASSERT_TRUE(wait_for(caller_mgr->lc,callee_mgr->lc,&caller_mgr->stat.number_of_LinphoneCallOutgoingRinging,1)); BC_ASSERT_PTR_NOT_NULL(in_call=linphone_core_get_current_call(callee_mgr->lc)); if (in_call) { linphone_call_ref(in_call); @@ -6215,40 +6215,72 @@ static void recreate_zrtpdb_when_corrupted(void) { } static void simple_call_with_gruu(void) { - LinphoneCoreManager* marie; - LinphoneCoreManager* pauline; - const LinphoneAddress *addr; + const LinphoneAddress *pauline_addr, *marie_addr; LinphoneCall *marie_call = NULL; LinphoneCall *pauline_call = NULL; LinphoneProxyConfig* pauline_cfg; - - marie = linphone_core_manager_new( "marie_rc"); - pauline = linphone_core_manager_new("pauline_tcp_rc"); + LinphoneAddress *contact_addr; + LinphoneCoreManager *marie = ms_new0(LinphoneCoreManager, 1); + linphone_core_manager_init(marie, "marie_rc", NULL); + linphone_core_add_supported_tag(marie->lc,"gruu"); + linphone_core_manager_start(marie,TRUE); + LinphoneCoreManager *pauline = ms_new0(LinphoneCoreManager, 1); + linphone_core_manager_init(pauline, "pauline_tcp_rc", NULL); + linphone_core_add_supported_tag(pauline->lc,"gruu"); + linphone_core_manager_start(pauline,TRUE); + BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneRegistrationOk, 1)); BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneRegistrationOk, 1)); pauline_cfg = linphone_core_get_default_proxy_config(pauline->lc); - addr = linphone_proxy_config_get_contact(pauline_cfg); - BC_ASSERT_PTR_NOT_NULL(addr); - BC_ASSERT_PTR_NOT_NULL(strstr(linphone_address_as_string_uri_only(addr), "gr")); - - marie_call = linphone_core_invite_address(marie->lc, addr); + pauline_addr = linphone_proxy_config_get_contact(pauline_cfg); + + BC_ASSERT_PTR_NOT_NULL(pauline_addr); + BC_ASSERT_TRUE(linphone_address_has_uri_param(pauline_addr,"gr")); + BC_ASSERT_STRING_EQUAL(linphone_address_get_domain(pauline_addr),"sip.example.org"); + + marie_call = linphone_core_invite_address(marie->lc, pauline_addr); BC_ASSERT_PTR_NOT_NULL(marie_call); if(!marie_call) goto end; BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallIncomingReceived, 1)); pauline_call = linphone_core_get_current_call(pauline->lc); BC_ASSERT_PTR_NOT_NULL(pauline_call); if(!pauline_call) goto end; + + marie_addr = linphone_proxy_config_get_contact(linphone_core_get_default_proxy_config(marie->lc)); + BC_ASSERT_TRUE(linphone_address_has_uri_param(marie_addr,"gr")); + BC_ASSERT_STRING_EQUAL(linphone_address_get_domain(marie_addr),"sip.example.org"); + contact_addr = linphone_address_new(linphone_call_get_remote_contact(pauline_call)); + if (!BC_ASSERT_TRUE(linphone_address_equal(contact_addr, marie_addr))) { + char* expected = linphone_address_as_string(marie_addr); + char* result = linphone_address_as_string(contact_addr); + ms_error("Expected contact is [%s], result is [%s]",expected,result); + ms_free(expected); + ms_free(result); + } + linphone_address_unref(contact_addr); + linphone_call_accept(pauline_call); BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallStreamsRunning, 1)); BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallStreamsRunning, 1)); - - linphone_call_terminate(pauline_call); - - BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallEnd, 1)); - BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallEnd, 1)); + + contact_addr = linphone_address_new(linphone_call_get_remote_contact(marie_call)); + if (!BC_ASSERT_TRUE(linphone_address_equal(contact_addr, pauline_addr))) { + char* expected = linphone_address_as_string(pauline_addr); + char* result = linphone_address_as_string(contact_addr); + ms_error("Expected contact is [%s], result is [%s]",expected,result); + ms_free(expected); + ms_free(result); + } + linphone_address_unref(contact_addr); + + liblinphone_tester_check_rtcp(marie,pauline); + end_call(marie,pauline); + + //BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallEnd, 1)); + //BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallEnd, 1)); end: linphone_core_manager_destroy(pauline); @@ -6256,9 +6288,6 @@ end: } static void simple_call_with_gruu_only_one_device_ring(void) { - LinphoneCoreManager* marie; - LinphoneCoreManager* pauline; - LinphoneCoreManager* pauline2; const LinphoneAddress *pauline_addr; const LinphoneAddress *pauline_addr2; LinphoneCall *marie_call = NULL; @@ -6266,9 +6295,18 @@ static void simple_call_with_gruu_only_one_device_ring(void) { LinphoneProxyConfig* pauline_cfg; LinphoneProxyConfig* pauline_cfg2; - marie = linphone_core_manager_new( "marie_rc"); - pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc"); - pauline2 = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc"); + LinphoneCoreManager *marie = ms_new0(LinphoneCoreManager, 1); + linphone_core_manager_init(marie, "marie_rc", NULL); + linphone_core_add_supported_tag(marie->lc,"gruu"); + linphone_core_manager_start(marie,TRUE); + LinphoneCoreManager *pauline = ms_new0(LinphoneCoreManager, 1); + linphone_core_manager_init(pauline, transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc", NULL); + linphone_core_add_supported_tag(pauline->lc,"gruu"); + linphone_core_manager_start(pauline,TRUE); + LinphoneCoreManager *pauline2 = ms_new0(LinphoneCoreManager, 1); + linphone_core_manager_init(pauline2, transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc", NULL); + linphone_core_add_supported_tag(pauline2->lc,"gruu"); + linphone_core_manager_start(pauline2,TRUE); BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneRegistrationOk, 1)); BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneRegistrationOk, 1)); diff --git a/tester/complex_sip_case_tester.c b/tester/complex_sip_case_tester.c index a0a9fe1e5..eacf21aba 100644 --- a/tester/complex_sip_case_tester.c +++ b/tester/complex_sip_case_tester.c @@ -140,9 +140,11 @@ static void sip_update_within_icoming_reinvite_with_no_sdp(void) { if (sipp_out) { BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallIncomingReceived, 1)); - linphone_call_accept(linphone_core_get_current_call(mgr->lc)); - BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallStreamsRunning, 2)); - BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallEnd, 1)); + if (linphone_core_get_current_call(mgr->lc)) { + linphone_call_accept(linphone_core_get_current_call(mgr->lc)); + BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallStreamsRunning, 2)); + BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallEnd, 1)); + } pclose(sipp_out); } linphone_core_manager_destroy(mgr); diff --git a/tester/flexisip_tester.c b/tester/flexisip_tester.c index 07c9d14d8..9c46c2942 100644 --- a/tester/flexisip_tester.c +++ b/tester/flexisip_tester.c @@ -1205,6 +1205,17 @@ static void redis_publish_subscribe(void) { marie2 = linphone_core_manager_new("marie2_rc"); BC_ASSERT_TRUE(wait_for_until(marie2->lc, NULL, &marie2->stat.number_of_LinphoneCallIncomingReceived, 1, 3000)); + linphone_call_accept(linphone_core_get_current_call(marie2->lc)); + BC_ASSERT_TRUE(wait_for_until(marie2->lc, pauline->lc, &marie2->stat.number_of_LinphoneCallStreamsRunning, 1, 3000)); + BC_ASSERT_TRUE(wait_for_until(marie2->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallStreamsRunning, 1, 3000)); + + liblinphone_tester_check_rtcp(marie2, pauline); + + linphone_call_terminate(linphone_core_get_current_call(marie2->lc)); + + BC_ASSERT_TRUE(wait_for_until(marie2->lc, pauline->lc, &marie2->stat.number_of_LinphoneCallEnd, 1, 3000)); + BC_ASSERT_TRUE(wait_for_until(marie2->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallEnd, 1, 3000)); + linphone_address_unref(marie_identity); linphone_core_manager_destroy(pauline); linphone_core_manager_destroy(marie2); diff --git a/tester/register_tester.c b/tester/register_tester.c index e3b750480..eeeec13ec 100644 --- a/tester/register_tester.c +++ b/tester/register_tester.c @@ -1186,7 +1186,10 @@ static void tls_auth_info_client_cert_cb_2(void) { } static void register_get_gruu(void) { - LinphoneCoreManager *marie=linphone_core_manager_new("marie_rc"); + LinphoneCoreManager *marie = ms_new0(LinphoneCoreManager, 1); + linphone_core_manager_init(marie, "marie_rc", NULL); + linphone_core_add_supported_tag(marie->lc,"gruu"); + linphone_core_manager_start(marie,TRUE); LinphoneProxyConfig *cfg=linphone_core_get_default_proxy_config(marie->lc); if(cfg) { const LinphoneAddress *addr = linphone_proxy_config_get_contact(cfg); @@ -1196,6 +1199,36 @@ static void register_get_gruu(void) { linphone_core_manager_destroy(marie); } +static void multi_devices_register_with_gruu(void) { + LinphoneCoreManager *marie = ms_new0(LinphoneCoreManager, 1); + linphone_core_manager_init(marie, "marie_rc", NULL); + linphone_core_add_supported_tag(marie->lc,"gruu"); + linphone_core_manager_start(marie,TRUE); + LinphoneProxyConfig *cfg=linphone_core_get_default_proxy_config(marie->lc); + + if(cfg) { + const LinphoneAddress *addr = linphone_proxy_config_get_contact(cfg); + BC_ASSERT_PTR_NOT_NULL(addr); + BC_ASSERT_STRING_EQUAL(linphone_address_get_domain(addr),linphone_proxy_config_get_domain(cfg)); + BC_ASSERT_TRUE(linphone_address_has_uri_param(addr,"gr")); + } + + linphone_core_set_network_reachable(marie->lc,FALSE); /*to make sure first instance is not unregistered*/ + linphone_core_manager_destroy(marie); + + marie=linphone_core_manager_new("marie_rc"); + cfg=linphone_core_get_default_proxy_config(marie->lc); + if(cfg) { + const LinphoneAddress *addr = linphone_proxy_config_get_contact(cfg); + BC_ASSERT_PTR_NOT_NULL(addr); + BC_ASSERT_STRING_EQUAL(linphone_address_get_domain(addr),linphone_proxy_config_get_domain(cfg)); + BC_ASSERT_TRUE(linphone_address_has_uri_param(addr,"gr")); + } + + linphone_core_manager_destroy(marie); +} + + test_t register_tests[] = { TEST_NO_TAG("Simple register", simple_register), TEST_NO_TAG("Simple register unregister", simple_unregister), @@ -1241,7 +1274,8 @@ test_t register_tests[] = { TEST_NO_TAG("AuthInfo TLS client certificate authentication using API 2", tls_auth_info_client_cert_api_path), TEST_NO_TAG("AuthInfo TLS client certificate authentication in callback", tls_auth_info_client_cert_cb), TEST_NO_TAG("AuthInfo TLS client certificate authentication in callback 2", tls_auth_info_client_cert_cb_2), - TEST_NO_TAG("Register get GRUU", register_get_gruu) + TEST_NO_TAG("Register get GRUU", register_get_gruu), + TEST_NO_TAG("Register get GRUU for multi device", multi_devices_register_with_gruu) }; test_suite_t register_test_suite = {"Register", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each,