From 2f80cd6ed1aa587183f63fcdd8f56f74b83d8f53 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Wed, 13 Mar 2013 13:04:48 +0100 Subject: [PATCH] ad linphone_proxy_config_get_transport --- .gitignore | 2 +- Makefile.am | 4 ++-- coreapi/bellesip_sal/sal_address_impl.c | 2 +- coreapi/linphonecore.h | 7 +++++++ coreapi/proxy.c | 22 +++++++++++++++++++++ tester/register_tester.c | 26 ++++++++++++++++++++----- 6 files changed, 54 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index df1c80316..9dd415435 100644 --- a/.gitignore +++ b/.gitignore @@ -52,4 +52,4 @@ coreapi/help/registration coreapi/test_ecc coreapi/test_lsd gtk/version_date.h - +specs.c diff --git a/Makefile.am b/Makefile.am index 37046726b..44ed0c07b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -230,6 +230,6 @@ bundle: $(LIBICONV_HACK) clean-local: rm -rf $(BUNDLEDIR) discovery: - touch specs.cpp + touch specs.c $(CC) --include $(top_builddir)/config.h \ - $(TUNNEL_CFLAGS) $(CFLAGS) $(MEDIASTREAMER2_CFLAGS) $(ORTP_CFLAGS) $(SIPSTACK_CFLAGS) $(CUNIT_CFLAGS) -E -P -v -dD specs.cpp + $(TUNNEL_CFLAGS) $(CFLAGS) $(MEDIASTREAMER2_CFLAGS) $(ORTP_CFLAGS) $(SIPSTACK_CFLAGS) $(CUNIT_CFLAGS) -E -P -v -dD specs.c diff --git a/coreapi/bellesip_sal/sal_address_impl.c b/coreapi/bellesip_sal/sal_address_impl.c index 5c210878c..c7a2603ca 100644 --- a/coreapi/bellesip_sal/sal_address_impl.c +++ b/coreapi/bellesip_sal/sal_address_impl.c @@ -85,7 +85,7 @@ int sal_address_get_port_int(const SalAddress *addr){ SalTransport sal_address_get_transport(const SalAddress* addr){ belle_sip_header_address_t* header_addr = BELLE_SIP_HEADER_ADDRESS(addr); belle_sip_uri_t* uri = belle_sip_header_address_get_uri(header_addr); - if (uri) { + if (uri && belle_sip_uri_get_transport_param(uri)) { return sal_transport_parse(belle_sip_uri_get_transport_param(uri)); } else return SalTransportUDP; diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 58b9179a5..3de3ddae0 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -539,6 +539,13 @@ bool_t linphone_proxy_config_get_dial_escape_plus(const LinphoneProxyConfig *cfg const char * linphone_proxy_config_get_dial_prefix(const LinphoneProxyConfig *cfg); LinphoneReason linphone_proxy_config_get_error(const LinphoneProxyConfig *cfg); +/* + * return the transport from either : service route, route, or addr + * @returns cfg object + * @return transport as string (I.E udp, tcp, tls, dtls)*/ + +LINPHONE_PUBLIC const char* linphone_proxy_config_get_transport(const LinphoneProxyConfig *cfg); + /* destruction is called automatically when removing the proxy config */ void linphone_proxy_config_destroy(LinphoneProxyConfig *cfg); diff --git a/coreapi/proxy.c b/coreapi/proxy.c index 2917d14b7..909500e59 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -1322,3 +1322,25 @@ void linphone_proxy_config_set_error(LinphoneProxyConfig *cfg,LinphoneReason err const LinphoneAddress* linphone_proxy_config_get_service_route(const LinphoneProxyConfig* cfg) { return cfg->op?(const LinphoneAddress*) sal_op_get_service_route(cfg->op):NULL; } +const char* linphone_proxy_config_get_transport(const LinphoneProxyConfig *cfg) { + const char* addr=NULL; + const char* ret="udp"; /*default value*/ + SalAddress* route_addr=NULL; + if (linphone_proxy_config_get_service_route(cfg)) { + route_addr=(SalAddress*)linphone_proxy_config_get_service_route(cfg); + } else if (linphone_proxy_config_get_route(cfg)) { + addr=linphone_proxy_config_get_route(cfg); + } else if(linphone_proxy_config_get_addr(cfg)) { + addr=linphone_proxy_config_get_addr(cfg); + } else { + ms_error("Cannot guess transport for proxy with identity [%s]",linphone_proxy_config_get_identity(cfg)); + return NULL; + } + + if ((route_addr || (route_addr=sal_address_new(addr))) && sal_address_get_transport(route_addr)) { + ret=sal_transport_to_string(sal_address_get_transport(route_addr)); + if (!linphone_proxy_config_get_service_route(cfg)) sal_address_destroy(route_addr); /*destroy except for service route*/ + } + + return ret; +} diff --git a/tester/register_tester.c b/tester/register_tester.c index 0ff192682..68a287079 100644 --- a/tester/register_tester.c +++ b/tester/register_tester.c @@ -263,7 +263,17 @@ static void network_state_change(){ wait_for(lc,lc,&counters->number_of_LinphoneRegistrationOk,2*register_ok); linphone_core_destroy(lc); } - +static int get_number_of_udp_proxy(const LinphoneCore* lc) { + int number_of_udp_proxy=0; + LinphoneProxyConfig* proxy_cfg; + MSList* proxys; + for (proxys=(MSList*)linphone_core_get_proxy_config_list(lc);proxys!=NULL;proxys=proxys->next) { + proxy_cfg=(LinphoneProxyConfig*)proxys->data; + if (strcmp("udp",linphone_proxy_config_get_transport(proxy_cfg))==0) + number_of_udp_proxy++; + } + return number_of_udp_proxy; +} static void transport_change(){ LinphoneCoreVTable v_table; LinphoneCore* lc; @@ -271,21 +281,25 @@ static void transport_change(){ stats* counters ; LCSipTransports sip_tr; LCSipTransports sip_tr_orig; - memset(&sip_tr,0,sizeof(sip_tr)); + int number_of_udp_proxy=0; + memset(&sip_tr,0,sizeof(sip_tr)); memset (&v_table,0,sizeof(LinphoneCoreVTable)); v_table.registration_state_changed=registration_state_changed; lc=configure_lc(&v_table); counters = (stats*)linphone_core_get_user_data(lc); register_ok=counters->number_of_LinphoneRegistrationOk; + + number_of_udp_proxy=get_number_of_udp_proxy(lc); linphone_core_get_sip_transports(lc,&sip_tr_orig); + sip_tr.udp_port=sip_tr_orig.udp_port; /*keep only udp*/ linphone_core_set_sip_transports(lc,&sip_tr); - CU_ASSERT_TRUE_FATAL(wait_for(lc,lc,&counters->number_of_LinphoneRegistrationOk,register_ok+1)); + CU_ASSERT_TRUE_FATAL(wait_for(lc,lc,&counters->number_of_LinphoneRegistrationOk,register_ok+number_of_udp_proxy)); - CU_ASSERT_TRUE_FATAL(wait_for(lc,lc,&counters->number_of_LinphoneRegistrationFailed,register_ok+2)); + CU_ASSERT_TRUE_FATAL(wait_for(lc,lc,&counters->number_of_LinphoneRegistrationFailed,register_ok+(ms_list_size(proxys)-number_of_udp_proxy))); linphone_core_destroy(lc); } @@ -295,15 +309,17 @@ static void io_recv_error(){ LinphoneCore* lc; int register_ok; stats* counters ; + int number_of_udp_proxy=0; memset (&v_table,0,sizeof(LinphoneCoreVTable)); v_table.registration_state_changed=registration_state_changed; lc=configure_lc(&v_table); counters = (stats*)linphone_core_get_user_data(lc); register_ok=counters->number_of_LinphoneRegistrationOk; + number_of_udp_proxy=get_number_of_udp_proxy(lc); sal_set_recv_error(lc->sal, 0); - CU_ASSERT_TRUE(wait_for(lc,lc,&counters->number_of_LinphoneRegistrationFailed,register_ok-1 /*because 1 udp*/)); + CU_ASSERT_TRUE(wait_for(lc,lc,&counters->number_of_LinphoneRegistrationFailed,register_ok-number_of_udp_proxy /*because 1 udp*/)); sal_set_recv_error(lc->sal, 1); /*reset*/ linphone_core_destroy(lc);