diff --git a/coreapi/proxy.c b/coreapi/proxy.c index 463be992d..14204dd2d 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -852,6 +852,8 @@ void linphone_proxy_config_set_realm(LinphoneProxyConfig *cfg, const char *realm int linphone_proxy_config_send_publish(LinphoneProxyConfig *proxy, LinphonePresenceModel *presence){ int err=0; + LinphoneAddress *presentity_address = NULL; + char* contact = NULL; if (proxy->state==LinphoneRegistrationOk || proxy->state==LinphoneRegistrationCleared){ LinphoneContent *content; @@ -869,6 +871,16 @@ int linphone_proxy_config_send_publish(LinphoneProxyConfig *proxy, LinphonePrese linphone_presence_model_set_presentity(presence,linphone_proxy_config_get_identity_address(proxy)); } + if (!linphone_address_equal(linphone_presence_model_get_presentity(presence), linphone_proxy_config_get_identity_address(proxy))) { + ms_message("Presentity for model [%p] differ proxy config [%p], using proxy", presence, proxy); + presentity_address = linphone_address_clone(linphone_presence_model_get_presentity(presence)); /*saved, just in case*/ + if (linphone_presence_model_get_contact(presence)) { + contact = bctbx_strdup(linphone_presence_model_get_contact(presence)); + } + linphone_presence_model_set_presentity(presence,linphone_proxy_config_get_identity_address(proxy)); + linphone_presence_model_set_contact(presence,NULL); /*it will be automatically computed*/ + + } if (!(presence_body = linphone_presence_model_to_xml(presence))) { ms_error("Cannot publish presence model [%p] for proxy config [%p] because of xml serialization error",presence,proxy); return -1; @@ -886,6 +898,15 @@ int linphone_proxy_config_send_publish(LinphoneProxyConfig *proxy, LinphonePrese err = linphone_event_send_publish(proxy->presence_publish_event, content); linphone_content_unref(content); ms_free(presence_body); + if (presentity_address) { + linphone_presence_model_set_presentity(presence,presentity_address); + linphone_address_unref(presentity_address); + } + if (contact) { + linphone_presence_model_set_contact(presence,contact); + bctbx_free(contact); + } + }else proxy->send_publish=TRUE; /*otherwise do not send publish if registration is in progress, this will be done later*/ return err; } diff --git a/tester/presence_tester.c b/tester/presence_tester.c index 2d5ee2a28..843d50f65 100644 --- a/tester/presence_tester.c +++ b/tester/presence_tester.c @@ -212,6 +212,31 @@ static void publish_with_expires(void) { simple_publish_with_expire(2); } +static void publish_with_dual_identity(void) { + LinphoneCoreManager* pauline = linphone_core_manager_new("multi_account_rc"); + const bctbx_list_t* proxies; + 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(pauline->lc, cbs, TRUE); + linphone_core_cbs_unref(cbs); + + for (proxies = linphone_core_get_proxy_config_list(pauline->lc); proxies!=NULL; proxies = proxies->next) { + LinphoneProxyConfig *proxy = (LinphoneProxyConfig *) proxies->data; + linphone_proxy_config_edit(proxy); + linphone_proxy_config_enable_publish(proxy,TRUE); + linphone_proxy_config_done(proxy); + } + + BC_ASSERT_TRUE(wait_for(pauline->lc,pauline->lc,&pauline->stat.number_of_LinphonePublishProgress,4)); + BC_ASSERT_TRUE(wait_for(pauline->lc,pauline->lc,&pauline->stat.number_of_LinphonePublishOk,4)); + + linphone_core_manager_stop(pauline); + BC_ASSERT_EQUAL(pauline->stat.number_of_LinphonePublishCleared,4,int,"%i"); + BC_ASSERT_EQUAL(pauline->stat.number_of_LinphonePublishOk,4,int,"%i"); + linphone_core_manager_destroy(pauline); + +} static bool_t subscribe_to_callee_presence(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_mgr) { stats initial_caller=caller_mgr->stat; stats initial_callee=callee_mgr->stat; @@ -582,6 +607,7 @@ test_t presence_tests[] = { TEST_ONE_TAG("Simple Subscribe with early NOTIFY", simple_subscribe_with_early_notify,"presence"), TEST_NO_TAG("Simple Subscribe with friend from rc", simple_subscribe_with_friend_from_rc), 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("Call with presence", call_with_presence, "LeaksMemory"),*/ TEST_NO_TAG("Unsubscribe while subscribing", unsubscribe_while_subscribing),