diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index 7c347d88e..33d44cec7 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -449,9 +449,12 @@ void sal_uninit(Sal* sal){ return ; }; -int sal_listen_port(Sal *ctx, const char *addr, int port, SalTransport tr, int is_secure){ +int sal_add_listen_port(Sal *ctx, SalAddress* addr){ int result; - belle_sip_listening_point_t* lp = belle_sip_stack_create_listening_point(ctx->stack,addr,port,sal_transport_to_string(tr)); + belle_sip_listening_point_t* lp = belle_sip_stack_create_listening_point(ctx->stack + ,sal_address_get_domain(addr) + ,sal_address_get_port_int(addr) + ,sal_transport_to_string(sal_address_get_transport(addr))); if (lp) { result = belle_sip_provider_add_listening_point(ctx->prov,lp); } else { @@ -459,6 +462,16 @@ int sal_listen_port(Sal *ctx, const char *addr, int port, SalTransport tr, int i } return result; } +int sal_listen_port(Sal *ctx, const char *addr, int port, SalTransport tr, int is_secure) { + SalAddress* sal_addr = sal_address_new(NULL); + int result; + sal_address_set_domain(sal_addr,addr); + sal_address_set_port_int(sal_addr,port); + sal_address_set_transport(sal_addr,tr); + result = sal_add_listen_port(ctx,sal_addr); + sal_address_destroy(sal_addr); + return result; +} static void remove_listening_point(belle_sip_listening_point_t* lp,belle_sip_provider_t* prov) { belle_sip_provider_remove_listening_point(prov,lp); } @@ -557,8 +570,9 @@ const char *sal_get_root_ca(Sal* ctx) { return NULL; } int sal_reset_transports(Sal *ctx){ - ms_warning("sal_reset_transports() not implemented in this version."); - return -1; + ms_message("reseting transport"); + belle_sip_provider_clean_channels(ctx->prov); + return 0; } void sal_set_dscp(Sal *ctx, int dscp){ ms_warning("sal_set_dscp not implemented"); diff --git a/tester/call_tester.c b/tester/call_tester.c index b15004264..a0e0923ee 100644 --- a/tester/call_tester.c +++ b/tester/call_tester.c @@ -29,6 +29,37 @@ static int uninit(void) { return 0; } +void call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *msg){ + char* to=linphone_address_as_string(linphone_call_get_call_log(call)->to); + char* from=linphone_address_as_string(linphone_call_get_call_log(call)->from); + + ms_message("call from [%s] to [%s], new state is [%s]",from,to,linphone_call_state_to_string(cstate)); + ms_free(to); + ms_free(from); + stats* counters = (stats*)linphone_core_get_user_data(lc); + switch (cstate) { + case LinphoneCallIncomingReceived:counters->number_of_LinphoneCallIncomingReceived++;break; + case LinphoneCallOutgoingInit :counters->number_of_LinphoneCallOutgoingInit++;break; + case LinphoneCallOutgoingProgress :counters->number_of_LinphoneCallOutgoingProgress++;break; + case LinphoneCallOutgoingRinging :counters->number_of_LinphoneCallOutgoingRinging++;break; + case LinphoneCallOutgoingEarlyMedia :counters->number_of_LinphoneCallOutgoingEarlyMedia++;break; + case LinphoneCallConnected :counters->number_of_LinphoneCallConnected++;break; + case LinphoneCallStreamsRunning :counters->number_of_LinphoneCallStreamsRunning++;break; + case LinphoneCallPausing :counters->number_of_LinphoneCallPausing++;break; + case LinphoneCallPaused :counters->number_of_LinphoneCallPaused++;break; + case LinphoneCallResuming :counters->number_of_LinphoneCallResuming++;break; + case LinphoneCallRefered :counters->number_of_LinphoneCallRefered++;break; + case LinphoneCallError :counters->number_of_LinphoneCallError++;break; + case LinphoneCallEnd :counters->number_of_LinphoneCallEnd++;break; + case LinphoneCallPausedByRemote :counters->number_of_LinphoneCallPausedByRemote++;break; + case LinphoneCallUpdatedByRemote :counters->number_of_LinphoneCallUpdatedByRemote++;break; + case LinphoneCallIncomingEarlyMedia :counters->number_of_LinphoneCallIncomingEarlyMedia++;break; + case LinphoneCallUpdating :counters->number_of_LinphoneCallUpdating++;break; + case LinphoneCallReleased :counters->number_of_LinphoneCallReleased++;break; + default: + CU_FAIL("unexpected event");break; + } +} static bool_t call(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_mgr) { LinphoneProxyConfig* proxy; diff --git a/tester/flexisip.conf b/tester/flexisip.conf index c59ed0a5e..de5809da9 100755 --- a/tester/flexisip.conf +++ b/tester/flexisip.conf @@ -18,7 +18,7 @@ auto-respawn=true # List of white space separated host names pointing to this machine. # This is to prevent loops while routing SIP messages. # Default value: localhost -aliases=localhost sipopen.example.org sip.example.org +aliases=localhost sipopen.example.org sip.example.org auth.example.org auth1.example.org auth2.example.org # List of white space separated SIP uris where the proxy must listen.Wildcard # (*) can be used to mean 'all local ip addresses'. If 'transport' @@ -130,12 +130,12 @@ enabled=true # in 'a.org b.org c.org', (to.uri.domain in 'a.org b.org c.org') # && (user-agent == 'Linphone v2') # Default value: -filter= from.uri.domain contains 'sip.example.org' +filter= from.uri.domain contains 'sip.example.org' || from.uri.domain contains 'auth.example.org' || from.uri.domain contains 'auth1.example.org' || from.uri.domain contains 'auth2.example.org' # List of whitespace separated domain names to challenge. Others # are denied. # Default value: -auth-domains= sip.example.org +auth-domains= sip.example.org auth.example.org auth1.example.org auth2.example.org # List of whitespace separated IP which will not be challenged. # Default value: @@ -261,7 +261,7 @@ filter= # List of whitelist separated domain names to be managed by the # registrar. # Default value: localhost -reg-domains=localhost sip.example.org sipopen.example.org +reg-domains=localhost sip.example.org sipopen.example.org auth1.example.org # Maximum number of registered contacts of an address of record. # Default value: 15 diff --git a/tester/liblinphone_tester.c b/tester/liblinphone_tester.c index adf1526c8..8bfc5352b 100644 --- a/tester/liblinphone_tester.c +++ b/tester/liblinphone_tester.c @@ -111,62 +111,7 @@ LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* file,in } -static void call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *msg){ - char* to=linphone_address_as_string(linphone_call_get_call_log(call)->to); - char* from=linphone_address_as_string(linphone_call_get_call_log(call)->from); - ms_message("call from [%s] to [%s], new state is [%s]",from,to,linphone_call_state_to_string(cstate)); - ms_free(to); - ms_free(from); - stats* counters = (stats*)linphone_core_get_user_data(lc); - switch (cstate) { - case LinphoneCallIncomingReceived:counters->number_of_LinphoneCallIncomingReceived++;break; - case LinphoneCallOutgoingInit :counters->number_of_LinphoneCallOutgoingInit++;break; - case LinphoneCallOutgoingProgress :counters->number_of_LinphoneCallOutgoingProgress++;break; - case LinphoneCallOutgoingRinging :counters->number_of_LinphoneCallOutgoingRinging++;break; - case LinphoneCallOutgoingEarlyMedia :counters->number_of_LinphoneCallOutgoingEarlyMedia++;break; - case LinphoneCallConnected :counters->number_of_LinphoneCallConnected++;break; - case LinphoneCallStreamsRunning :counters->number_of_LinphoneCallStreamsRunning++;break; - case LinphoneCallPausing :counters->number_of_LinphoneCallPausing++;break; - case LinphoneCallPaused :counters->number_of_LinphoneCallPaused++;break; - case LinphoneCallResuming :counters->number_of_LinphoneCallResuming++;break; - case LinphoneCallRefered :counters->number_of_LinphoneCallRefered++;break; - case LinphoneCallError :counters->number_of_LinphoneCallError++;break; - case LinphoneCallEnd :counters->number_of_LinphoneCallEnd++;break; - case LinphoneCallPausedByRemote :counters->number_of_LinphoneCallPausedByRemote++;break; - case LinphoneCallUpdatedByRemote :counters->number_of_LinphoneCallUpdatedByRemote++;break; - case LinphoneCallIncomingEarlyMedia :counters->number_of_LinphoneCallIncomingEarlyMedia++;break; - case LinphoneCallUpdating :counters->number_of_LinphoneCallUpdating++;break; - case LinphoneCallReleased :counters->number_of_LinphoneCallReleased++;break; - default: - CU_FAIL("unexpected event");break; - } -} - -static void text_message_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from_address, const char *message) { - char* from=linphone_address_as_string(from_address); - ms_message("Message from [%s] is [%s]",from,message); - ms_free(from); - stats* counters = (stats*)linphone_core_get_user_data(lc); - counters->number_of_LinphoneMessageReceived++; -} - -void new_subscribtion_request(LinphoneCore *lc, LinphoneFriend *lf, const char *url){ - char* from=linphone_address_as_string(linphone_friend_get_address(lf)); - ms_message("New subscription request from [%s] url [%s]",from,url); - ms_free(from); - stats* counters = (stats*)linphone_core_get_user_data(lc); - counters->number_of_NewSubscriptionRequest++; - linphone_core_add_friend(lc,lf); /*accept subscription*/ - -} -static void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf) { - char* from=linphone_address_as_string(linphone_friend_get_address(lf)); - ms_message("New Notify request from [%s] ",from); - ms_free(from); - stats* counters = (stats*)linphone_core_get_user_data(lc); - counters->number_of_NotifyReceived++; -} bool_t wait_for(LinphoneCore* lc_1, LinphoneCore* lc_2,int* counter,int value) { int retry=0; while (*counternumber_of_LinphoneMessageReceived++; +} + static void text_message() { LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc"); diff --git a/tester/multi_account_lrc b/tester/multi_account_lrc index 6f362c533..df91cf251 100644 --- a/tester/multi_account_lrc +++ b/tester/multi_account_lrc @@ -14,7 +14,7 @@ realm="auth.example.org" username=pauline userid=pauline passwd=secret -realm="auth.example.org" +realm="sip.example.org" [auth_info_2] username=liblinphone_tester @@ -26,26 +26,26 @@ realm="auth1.example.org" username=marie userid=marie passwd=secret -realm="auth.example.org" +realm="sip.example.org" [proxy_0] -reg_proxy=auth.example.org;transport=tls -reg_identity=sip:pauline@auth.example.org +reg_proxy=sip.example.org;transport=tls +reg_identity=sip:pauline@sip.example.org reg_expires=3600 reg_sendregister=1 publish=0 dial_escape_plus=0 [proxy_1] -reg_proxy=auth.example.org;transport=tcp -reg_identity=sip:marie@auth.example.org +reg_proxy=sip.example.org;transport=tcp +reg_identity=sip:marie@sip.example.org reg_expires=3600 reg_sendregister=1 publish=0 dial_escape_plus=0 [proxy_2] -reg_proxy=auth.example.org +reg_proxy=auth1.example.org reg_identity=sip:liblinphone_tester@auth1.example.org reg_expires=3600 reg_sendregister=1 diff --git a/tester/presence_tester.c b/tester/presence_tester.c index 7df079b0c..eb4bb1b95 100644 --- a/tester/presence_tester.c +++ b/tester/presence_tester.c @@ -22,6 +22,23 @@ #include "liblinphone_tester.h" +void new_subscribtion_request(LinphoneCore *lc, LinphoneFriend *lf, const char *url){ + char* from=linphone_address_as_string(linphone_friend_get_address(lf)); + ms_message("New subscription request from [%s] url [%s]",from,url); + ms_free(from); + stats* counters = (stats*)linphone_core_get_user_data(lc); + counters->number_of_NewSubscriptionRequest++; + linphone_core_add_friend(lc,lf); /*accept subscription*/ + +} +void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf) { + char* from=linphone_address_as_string(linphone_friend_get_address(lf)); + ms_message("New Notify request from [%s] ",from); + ms_free(from); + stats* counters = (stats*)linphone_core_get_user_data(lc); + counters->number_of_NotifyReceived++; +} + static void simple_publish() { LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc"); LinphoneProxyConfig* proxy; diff --git a/tester/register_tester.c b/tester/register_tester.c index 80da637c5..826c3703d 100644 --- a/tester/register_tester.c +++ b/tester/register_tester.c @@ -45,7 +45,7 @@ void registration_state_changed(struct _LinphoneCore *lc, LinphoneProxyConfig *c } } -static void register_with_refresh_base(LinphoneCore* lc, bool_t refresh,const char* domain,const char* route) { +static void register_with_refresh_base_2(LinphoneCore* lc, bool_t refresh,const char* domain,const char* route,bool_t late_auth_info) { int retry=0; LCSipTransports transport = {5070,5070,0,5071}; @@ -77,16 +77,23 @@ static void register_with_refresh_base(LinphoneCore* lc, bool_t refresh,const ch while (counters->number_of_LinphoneRegistrationOk<1+(refresh!=0) && retry++ <310) { linphone_core_iterate(lc); + if (counters->number_of_auth_info_requested>0 && late_auth_info) { + LinphoneAuthInfo *info=linphone_auth_info_new(test_username,NULL,test_password,NULL,auth_domain); /*create authentication structure from identity*/ + linphone_core_add_auth_info(lc,info); /*add authentication info to LinphoneCore*/ + } ms_usleep(100000); } CU_ASSERT_TRUE_FATAL(linphone_proxy_config_is_registered(proxy_cfg)); CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationNone,0); - CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationProgress,1+(refresh!=0)); + CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationProgress,1); CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationOk,1+(refresh!=0)); CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationFailed,0); CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationCleared,0); } +static void register_with_refresh_base(LinphoneCore* lc, bool_t refresh,const char* domain,const char* route) { + register_with_refresh_base_2(lc,refresh,domain,route,FALSE); +} static void register_with_refresh(LinphoneCore* lc, bool_t refresh,const char* domain,const char* route) { stats* counters = (stats*)linphone_core_get_user_data(lc); register_with_refresh_base(lc,refresh,domain,route); @@ -161,8 +168,6 @@ static void simple_authenticated_register(){ CU_ASSERT_EQUAL(counters->number_of_auth_info_requested,0); } - - static void authenticated_register_with_no_initial_credentials(){ LinphoneCoreVTable v_table; LinphoneCore* lc; @@ -177,6 +182,27 @@ static void authenticated_register_with_no_initial_credentials(){ register_with_refresh(lc,FALSE,auth_domain,NULL); CU_ASSERT_EQUAL(counters->number_of_auth_info_requested,1); } +static void auth_info_requested2(LinphoneCore *lc, const char *realm, const char *username) { + ms_message("Auth info requested for user id [%s] at realm [%s]\n" + ,username + ,realm); + stats* counters = (stats*)linphone_core_get_user_data(lc); + counters->number_of_auth_info_requested++; +} + +static void authenticated_register_with_late_credentials(){ + LinphoneCoreVTable v_table; + LinphoneCore* lc; + stats stat; + memset (&v_table,0,sizeof(v_table)); + v_table.registration_state_changed=registration_state_changed; + v_table.auth_info_requested=auth_info_requested2; + lc = linphone_core_new(&v_table,NULL,NULL,NULL); + linphone_core_set_user_data(lc,&stat); + stats* counters = (stats*)linphone_core_get_user_data(lc); + register_with_refresh_base_2(lc,FALSE,auth_domain,NULL,TRUE); + CU_ASSERT_EQUAL(counters->number_of_auth_info_requested,1); +} static LinphoneCore* configure_lc(LinphoneCoreVTable* v_table) { return configure_lc_from(v_table,"./tester/multi_account_lrc",3); @@ -191,6 +217,24 @@ static void multiple_proxy(){ linphone_core_destroy(lc); } +static void network_state_change(){ + LinphoneCoreVTable v_table; + LinphoneCore* lc; + int register_ok; + stats* counters ; + + 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; + linphone_core_set_network_reachable(lc,FALSE); + CU_ASSERT_TRUE_FATAL(wait_for(lc,lc,&counters->number_of_LinphoneRegistrationNone,register_ok)); + linphone_core_set_network_reachable(lc,TRUE); + wait_for(lc,lc,&counters->number_of_LinphoneRegistrationOk,2*register_ok); + linphone_core_destroy(lc); +} + int register_test_suite () { CU_pSuite pSuite = CU_add_suite("Register", NULL, NULL); @@ -209,6 +253,9 @@ int register_test_suite () { if (NULL == CU_add_test(pSuite, "register with digest auth tester without initial credentials", authenticated_register_with_no_initial_credentials)) { return CU_get_error(); } + if (NULL == CU_add_test(pSuite, "authenticated_register_with_late_credentials", authenticated_register_with_late_credentials)) { + return CU_get_error(); + } if (NULL == CU_add_test(pSuite, "simple_register_with_refresh", simple_register_with_refresh)) { return CU_get_error(); } @@ -222,5 +269,9 @@ int register_test_suite () { return CU_get_error(); } + if (NULL == CU_add_test(pSuite, "network_state_change", network_state_change)) { + return CU_get_error(); + } + return 0; } diff --git a/tester/userdb.conf b/tester/userdb.conf index 4be5cd891..3326e1f48 100644 --- a/tester/userdb.conf +++ b/tester/userdb.conf @@ -1,8 +1,8 @@ +liblinphone_tester@sip.example.org secret liblinphone_tester@auth.example.org secret liblinphone_tester@auth1.example.org secret -liblinphone_tester@auth2.example.org secret - -pauline@auth.example.org secret -marie@auth.example.org secret -bellesip@auth.example.org secret +tester@sip.example.org secret +pauline@sip.example.org secret +marie@sip.example.org secret +bellesip@sip.example.org secret