diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 95a2c2dd5..7a0b53e0d 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2085,6 +2085,20 @@ static void linphone_core_internal_subscription_state_changed(LinphoneCore *lc, } } +static void linphone_core_internal_publish_state_changed(LinphoneCore *lc, LinphoneEvent *lev, LinphonePublishState state) { + if (strcasecmp(linphone_event_get_name(lev), "Presence") == 0) { + const bctbx_list_t *cfgs = linphone_core_get_proxy_config_list(lc); + const bctbx_list_t *item; + for (item = cfgs; item != NULL; item = bctbx_list_next(item)) { + LinphoneProxyConfig *cfg = (LinphoneProxyConfig *)bctbx_list_get_data(item); + if (cfg->long_term_event == lev) { + linphone_proxy_config_notify_publish_state_changed(cfg, state); + break; + } + } + } +} + static void _linphone_core_init_account_creator_service(LinphoneCore *lc) { LinphoneAccountCreatorService *service = linphone_account_creator_service_new(); service->account_creator_service_constructor_cb = linphone_account_creator_constructor_linphone; @@ -2121,6 +2135,7 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig linphone_core_cbs_set_notify_received(internal_cbs, linphone_core_internal_notify_received); linphone_core_cbs_set_subscription_state_changed(internal_cbs, linphone_core_internal_subscription_state_changed); + linphone_core_cbs_set_publish_state_changed(internal_cbs, linphone_core_internal_publish_state_changed); _linphone_core_add_callbacks(lc, internal_cbs, TRUE); belle_sip_object_unref(internal_cbs); diff --git a/coreapi/private.h b/coreapi/private.h index 8546ca9d4..a5ab60f19 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -453,6 +453,7 @@ void linphone_proxy_config_stop_refreshing(LinphoneProxyConfig *obj); void linphone_proxy_config_write_all_to_config_file(LinphoneCore *lc); void _linphone_proxy_config_release(LinphoneProxyConfig *cfg); void _linphone_proxy_config_unpublish(LinphoneProxyConfig *obj); +void linphone_proxy_config_notify_publish_state_changed(LinphoneProxyConfig *cfg, LinphonePublishState state); /* * returns service route as defined in as defined by rfc3608, might be a list instead of just one. diff --git a/coreapi/proxy.c b/coreapi/proxy.c index 09a9cc801..fc8519429 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -824,8 +824,6 @@ LinphoneStatus linphone_proxy_config_done(LinphoneProxyConfig *cfg) } /*publish is terminated*/ linphone_event_terminate(cfg->long_term_event); - linphone_event_unref(cfg->long_term_event); - cfg->long_term_event = NULL; } if (cfg->publish) cfg->send_publish=TRUE; } else { @@ -1461,3 +1459,10 @@ void linphone_proxy_config_set_nat_policy(LinphoneProxyConfig *cfg, LinphoneNatP if (cfg->nat_policy != NULL) linphone_nat_policy_unref(cfg->nat_policy); cfg->nat_policy = policy; } + +void linphone_proxy_config_notify_publish_state_changed(LinphoneProxyConfig *cfg, LinphonePublishState state) { + if ((cfg->long_term_event != NULL) && ((state == LinphonePublishCleared) || (state == LinphonePublishError))) { + linphone_event_unref(cfg->long_term_event); + cfg->long_term_event = NULL; + } +}