Commit 7dab187b authored by jehan's avatar jehan

make sure publishs are restart after a network state changed from DOWN to UP

parent 35268a12
......@@ -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*/
......
......@@ -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*/
}
}
}
......
......@@ -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){
......
......@@ -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);
......
......@@ -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),
......
......@@ -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);
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment