From 7dab187bfce254318aaa909ff64060a894f55644 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Wed, 6 Sep 2017 10:16:59 +0200 Subject: [PATCH] make sure publishs are restart after a network state changed from DOWN to UP --- coreapi/event.c | 7 +++++-- coreapi/linphonecore.c | 2 ++ coreapi/proxy.c | 12 ++++-------- tester/liblinphone_tester.c | 1 + tester/presence_tester.c | 35 +++++++++++++++++++++++++++++++++++ tester/register_tester.c | 1 + tester/tester.c | 1 + 7 files changed, 49 insertions(+), 10 deletions(-) diff --git a/coreapi/event.c b/coreapi/event.c index 221a6aa63..cb7a7f898 100644 --- a/coreapi/event.c +++ b/coreapi/event.c @@ -128,10 +128,14 @@ void linphone_event_set_state(LinphoneEvent *lev, LinphoneSubscriptionState stat void linphone_event_set_publish_state(LinphoneEvent *lev, LinphonePublishState state){ if (lev->publish_state!=state){ - ms_message("LinphoneEvent [%p] moving to publish state %s",lev,linphone_publish_state_to_string(state)); + ms_message("LinphoneEvent [%p] moving from [%s] to publish state %s" + , lev + , linphone_publish_state_to_string(lev->publish_state) + , linphone_publish_state_to_string(state)); lev->publish_state=state; linphone_core_notify_publish_state_changed(lev->lc,lev,state); switch(state){ + case LinphonePublishNone: /*this state is probably trigered by a network state change to DOWN, we should release the op*/ case LinphonePublishCleared: linphone_event_release(lev); break; @@ -141,7 +145,6 @@ void linphone_event_set_publish_state(LinphoneEvent *lev, LinphonePublishState s case LinphonePublishError: linphone_event_release(lev); break; - case LinphonePublishNone: case LinphonePublishProgress: case LinphonePublishExpiring: /*nothing special to do*/ diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index aa964e191..5c881db24 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -6165,6 +6165,8 @@ static void stop_refreshing_proxy_config(bool_t is_sip_reachable, LinphoneProxyC linphone_proxy_config_set_state(cfg, LinphoneRegistrationNone,"Registration impossible (network down)"); }else{ cfg->commit=TRUE; + if (linphone_proxy_config_publish_enabled(cfg)) + cfg->send_publish=TRUE; /*not sure if really the best place*/ } } } diff --git a/coreapi/proxy.c b/coreapi/proxy.c index 3dcf0ab7d..43ddd184a 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -434,14 +434,10 @@ void linphone_proxy_config_stop_refreshing(LinphoneProxyConfig * cfg){ } else linphone_address_unref(contact_addr); } - - if (cfg->presence_publish_event) { /*might probably do better*/ - linphone_event_terminate(cfg->presence_publish_event); - if (cfg->presence_publish_event) { - /*probably useless as cfg->long_term_event is already unref in linphone_proxy_config_notify_publish_state_changed. To be check with Ghislain*/ - linphone_event_unref(cfg->presence_publish_event); - cfg->presence_publish_event = NULL; - } + if (cfg->presence_publish_event){ /*might probably do better*/ + linphone_event_set_publish_state(cfg->presence_publish_event,LinphonePublishNone); + linphone_event_unref(cfg->presence_publish_event); /*probably useless as cfg->long_term_event is already unref in linphone_proxy_config_notify_publish_state_changed. To be check with Ghislain*/ + cfg->presence_publish_event=NULL; } if (cfg->op){ diff --git a/tester/liblinphone_tester.c b/tester/liblinphone_tester.c index 7421a20d0..178a8347a 100644 --- a/tester/liblinphone_tester.c +++ b/tester/liblinphone_tester.c @@ -171,6 +171,7 @@ static void log_handler(int lev, const char *fmt, va_list args) { } void liblinphone_tester_init(void(*ftester_printf)(int level, const char *fmt, va_list args)) { + bctbx_init_logger(FALSE); if (! log_file) { #if defined(__ANDROID__) linphone_core_set_log_handler(liblinphone_android_ortp_log_handler); diff --git a/tester/presence_tester.c b/tester/presence_tester.c index ea70681ca..7de76b692 100644 --- a/tester/presence_tester.c +++ b/tester/presence_tester.c @@ -306,6 +306,40 @@ static void subscribe_failure_handle_by_app(void) { linphone_core_manager_destroy(pauline); } +static void publish_with_network_state_changes(void) { + LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); + LinphoneProxyConfig* proxy; + LinphoneCoreCbs *cbs = linphone_factory_create_core_cbs(linphone_factory_get()); + + linphone_core_cbs_set_publish_state_changed(cbs, linphone_publish_state_changed); + _linphone_core_add_callbacks(marie->lc, cbs,TRUE); + linphone_core_cbs_unref(cbs); + + proxy = linphone_core_get_default_proxy_config(marie->lc); + linphone_proxy_config_edit(proxy); + linphone_proxy_config_enable_publish(proxy,TRUE); + linphone_proxy_config_done(proxy); + + BC_ASSERT_TRUE(wait_for(marie->lc,marie->lc,&marie->stat.number_of_LinphonePublishProgress,1)); + BC_ASSERT_TRUE(wait_for(marie->lc,marie->lc,&marie->stat.number_of_LinphonePublishOk,1)); + + linphone_core_set_network_reachable(marie->lc, FALSE); + BC_ASSERT_TRUE(wait_for(marie->lc,marie->lc,&marie->stat.number_of_LinphoneRegistrationNone,1)); + BC_ASSERT_FALSE(wait_for_until(marie->lc,marie->lc,&marie->stat.number_of_LinphonePublishProgress,2,1000)); + BC_ASSERT_EQUAL(marie->stat.number_of_LinphonePublishOk,1,int,"%i"); + BC_ASSERT_EQUAL(marie->stat.number_of_LinphonePublishError,0,int,"%i"); + + linphone_core_set_network_reachable(marie->lc, TRUE); + BC_ASSERT_TRUE(wait_for(marie->lc,marie->lc,&marie->stat.number_of_LinphonePublishProgress,2)); + BC_ASSERT_TRUE(wait_for(marie->lc,marie->lc,&marie->stat.number_of_LinphonePublishOk,2)); + + + linphone_core_manager_stop(marie); + BC_ASSERT_EQUAL(marie->stat.number_of_LinphonePublishCleared,1,int,"%i"); /*yes it is 3 because when we change the expires, a new LinphoneEvent is created*/ + BC_ASSERT_EQUAL(marie->stat.number_of_LinphonePublishOk,2,int,"%i"); + linphone_core_manager_destroy(marie); +} + static void simple_subscribe(void) { LinphoneCoreManager* marie = presence_linphone_core_manager_new("marie"); LinphoneCoreManager* pauline = presence_linphone_core_manager_new("pauline"); @@ -609,6 +643,7 @@ test_t presence_tests[] = { TEST_NO_TAG("Simple Publish", simple_publish), TEST_NO_TAG("Publish with 2 identities", publish_with_dual_identity), TEST_NO_TAG("Simple Publish with expires", publish_with_expires), + TEST_ONE_TAG("Publish with network state changes", publish_with_network_state_changes, "presence"), /*TEST_ONE_TAG("Call with presence", call_with_presence, "LeaksMemory"),*/ TEST_NO_TAG("Unsubscribe while subscribing", unsubscribe_while_subscribing), TEST_NO_TAG("Presence information", presence_information), diff --git a/tester/register_tester.c b/tester/register_tester.c index 106f94c3d..aa9b1f52e 100644 --- a/tester/register_tester.c +++ b/tester/register_tester.c @@ -553,6 +553,7 @@ static void network_state_change(void){ linphone_core_set_network_reachable(lc,FALSE); BC_ASSERT_TRUE(wait_for(lc,lc,&counters->number_of_NetworkReachableFalse,1)); BC_ASSERT_TRUE(wait_for(lc,lc,&counters->number_of_LinphoneRegistrationNone,register_ok)); + BC_ASSERT_FALSE(wait_for_until(lc,lc,&counters->number_of_LinphoneRegistrationProgress,register_ok+1,1000)); /*make sure no register is tried*/ linphone_core_set_network_reachable(lc,TRUE); BC_ASSERT_TRUE(wait_for(lc,lc,&counters->number_of_NetworkReachableTrue,1)); wait_for(lc,lc,&counters->number_of_LinphoneRegistrationOk,2*register_ok); diff --git a/tester/tester.c b/tester/tester.c index a3bfdddd6..49558cff1 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -676,6 +676,7 @@ void liblinphone_tester_uninit(void) { all_leaks_buffer = NULL; } bc_tester_uninit(); + bctbx_uninit_logger(); } static void check_ice_from_rtp(LinphoneCall *c1, LinphoneCall *c2, LinphoneStreamType stream_type) {