diff --git a/tester/accountmanager.c b/tester/accountmanager.c index 06ca07ee2..63d25c08e 100644 --- a/tester/accountmanager.c +++ b/tester/accountmanager.c @@ -30,7 +30,7 @@ struct _Account{ typedef struct _Account Account; -Account *account_new(LinphoneAddress *identity, const char *unique_id){ +static Account *account_new(LinphoneAddress *identity, const char *unique_id){ char *modified_username; Account *obj=ms_new0(Account,1); @@ -121,7 +121,7 @@ static void account_created_auth_requested_cb(LinphoneCore *lc, const char *user } // TEMPORARY CODE: remove line above when flexisip is updated, this is not needed anymore! -void account_create_on_server(Account *account, const LinphoneProxyConfig *refcfg){ +void account_create_on_server(Account *account, const LinphoneProxyConfig *refcfg, const char* phone_alias){ LinphoneCoreVTable vtable={0}; LinphoneCore *lc; LinphoneAddress *tmp_identity=linphone_address_clone(account->modified_identity); @@ -144,6 +144,7 @@ void account_create_on_server(Account *account, const LinphoneProxyConfig *refcf linphone_address_set_secure(tmp_identity, FALSE); linphone_address_set_password(tmp_identity,account->password); linphone_address_set_header(tmp_identity,"X-Create-Account","yes"); + if (phone_alias) linphone_address_set_header(tmp_identity, "X-Phone-Alias", phone_alias); tmp=linphone_address_as_string(tmp_identity); linphone_proxy_config_set_identity(cfg,tmp); ms_free(tmp); @@ -191,7 +192,7 @@ void account_create_on_server(Account *account, const LinphoneProxyConfig *refcf linphone_core_destroy(lc); } -LinphoneAddress *account_manager_check_account(AccountManager *m, LinphoneProxyConfig *cfg){ +static LinphoneAddress *account_manager_check_account(AccountManager *m, LinphoneProxyConfig *cfg,const char* phone_alias){ LinphoneCore *lc=linphone_proxy_config_get_core(cfg); const char *identity=linphone_proxy_config_get_identity(cfg); LinphoneAddress *id_addr=linphone_address_new(identity); @@ -217,7 +218,7 @@ LinphoneAddress *account_manager_check_account(AccountManager *m, LinphoneProxyC ms_free(tmp); if (create_account){ - account_create_on_server(account,cfg); + account_create_on_server(account,cfg,phone_alias); } /*remove previous auth info to avoid mismatching*/ @@ -240,6 +241,6 @@ void linphone_core_manager_check_accounts(LinphoneCoreManager *m){ for(it=linphone_core_get_proxy_config_list(m->lc);it!=NULL;it=it->next){ LinphoneProxyConfig *cfg=(LinphoneProxyConfig *)it->data; - account_manager_check_account(am,cfg); + account_manager_check_account(am,cfg,m->phone_alias); } } diff --git a/tester/liblinphone_tester.h b/tester/liblinphone_tester.h index a1305d346..baa274f94 100644 --- a/tester/liblinphone_tester.h +++ b/tester/liblinphone_tester.h @@ -262,6 +262,7 @@ typedef struct _LinphoneCoreManager { LinphoneEvent *lev; bool_t decline_subscribe; int number_of_bcunit_error_at_creation; + char* phone_alias; } LinphoneCoreManager; typedef struct _LinphoneConferenceServer { @@ -280,8 +281,9 @@ typedef struct _LinphoneCallTestParams { void liblinphone_tester_add_suites(void); -void linphone_core_manager_init(LinphoneCoreManager *mgr, const char* rc_file); +void linphone_core_manager_init(LinphoneCoreManager *mgr, const char* rc_file, const char* phone_alias); void linphone_core_manager_start(LinphoneCoreManager *mgr, int check_for_proxies); +LinphoneCoreManager* linphone_core_manager_new3(const char* rc_file, int check_for_proxies, const char* phone_alias); LinphoneCoreManager* linphone_core_manager_new2(const char* rc_file, int check_for_proxies); LinphoneCoreManager* linphone_core_manager_new(const char* rc_file); void linphone_core_manager_stop(LinphoneCoreManager *mgr); diff --git a/tester/presence_server_tester.c b/tester/presence_server_tester.c index ae18a9712..969280d54 100644 --- a/tester/presence_server_tester.c +++ b/tester/presence_server_tester.c @@ -687,6 +687,28 @@ static void long_term_presence_phone_alias(void) { long_term_presence_base("sip:+331234567890@sip.example.org", TRUE, "sip:liblinphone_tester@sip.example.org"); } +static const char* random_phone_number() { + static char phone[10]; + int i; + phone[0] = '+'; + for (i = 1; i < 10; i++) { + phone[i] = '0' + rand() % 10; + } + return phone; +} + +static void long_term_presence_phone_alias2(void) { + LinphoneCoreManager *marie = linphone_core_manager_new3("marie_rc", TRUE, random_phone_number()); + char * identity = linphone_address_as_string_uri_only(marie->identity); + LinphoneAddress * phone_addr = linphone_core_interpret_url(marie->lc, marie->phone_alias); + char *phone_addr_uri = linphone_address_as_string(phone_addr); + long_term_presence_base(phone_addr_uri, TRUE, identity); + ms_free(identity); + ms_free(phone_addr_uri); + linphone_address_destroy(phone_addr); + linphone_core_manager_destroy(marie); +} + static void long_term_presence_list(void) { LinphoneFriend *f1, *f2; LinphoneFriendList* friends; @@ -733,6 +755,7 @@ test_t presence_server_tests[] = { TEST_NO_TAG("Long term presence existing friend",long_term_presence_existing_friend), TEST_NO_TAG("Long term presence inexistent friend",long_term_presence_inexistent_friend), TEST_NO_TAG("Long term presence phone alias",long_term_presence_phone_alias), + TEST_NO_TAG("Long term presence phone alias 2",long_term_presence_phone_alias2), TEST_NO_TAG("Long term presence list",long_term_presence_list), }; diff --git a/tester/remote_provisioning_tester.c b/tester/remote_provisioning_tester.c index 16661b423..654fd9c82 100644 --- a/tester/remote_provisioning_tester.c +++ b/tester/remote_provisioning_tester.c @@ -114,7 +114,7 @@ static void remote_provisioning_file(void) { marie = linphone_core_manager_new2("marie_remote_localfile_win10_rc", FALSE); #else marie = ms_new0(LinphoneCoreManager, 1); - linphone_core_manager_init(marie, "marie_remote_localfile_rc"); + linphone_core_manager_init(marie, "marie_remote_localfile_rc",NULL); // fix relative path to absolute path { char* path = bc_tester_res("rcfiles/marie_remote_localfile2_rc"); diff --git a/tester/tester.c b/tester/tester.c index 9d8c768f5..09a71758b 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -277,7 +277,7 @@ bool_t transport_supported(LinphoneTransportType transport) { #else #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif -void linphone_core_manager_init(LinphoneCoreManager *mgr, const char* rc_file) { +void linphone_core_manager_init(LinphoneCoreManager *mgr, const char* rc_file, const char* phone_alias) { char *rc_path = NULL; char *hellopath = bc_tester_res("sounds/hello8000.wav"); mgr->number_of_bcunit_error_at_creation = bc_get_number_of_failures(); @@ -300,6 +300,8 @@ void linphone_core_manager_init(LinphoneCoreManager *mgr, const char* rc_file) { mgr->v_table.dtmf_received=dtmf_received; mgr->v_table.call_stats_updated=call_stats_updated; + mgr->phone_alias = phone_alias ? ms_strdup(phone_alias) : NULL; + reset_counters(&mgr->stat); if (rc_file) rc_path = ms_strdup_printf("rcfiles/%s", rc_file); mgr->lc=configure_lc_from(&mgr->v_table, bc_tester_get_resource_dir_prefix(), rc_path, mgr); @@ -393,26 +395,25 @@ void linphone_core_manager_start(LinphoneCoreManager *mgr, int check_for_proxies } -LinphoneCoreManager* linphone_core_manager_new( const char* rc_file) { +LinphoneCoreManager* linphone_core_manager_new3(const char* rc_file, int check_for_proxies, const char* phone_alias) { int old_log_level = ortp_get_log_level_mask(NULL); LinphoneCoreManager *manager = ms_new0(LinphoneCoreManager, 1); linphone_core_set_log_level(ORTP_ERROR); - linphone_core_manager_init(manager, rc_file); - linphone_core_manager_start(manager, TRUE); + linphone_core_manager_init(manager, rc_file, phone_alias); + linphone_core_manager_start(manager, check_for_proxies); linphone_core_set_log_level(old_log_level); return manager; } LinphoneCoreManager* linphone_core_manager_new2(const char* rc_file, int check_for_proxies) { - int old_log_level = ortp_get_log_level_mask(NULL); - LinphoneCoreManager *manager = ms_new0(LinphoneCoreManager, 1); - linphone_core_set_log_level(ORTP_ERROR); - linphone_core_manager_init(manager, rc_file); - linphone_core_manager_start(manager, check_for_proxies); - linphone_core_set_log_level(old_log_level); - return manager; + return linphone_core_manager_new3(rc_file, check_for_proxies, NULL); } +LinphoneCoreManager* linphone_core_manager_new( const char* rc_file) { + return linphone_core_manager_new2(rc_file, TRUE); +} + + void linphone_core_manager_stop(LinphoneCoreManager *mgr){ if (mgr->lc) { linphone_core_destroy(mgr->lc); @@ -423,6 +424,9 @@ void linphone_core_manager_stop(LinphoneCoreManager *mgr){ void linphone_core_manager_uninit(LinphoneCoreManager *mgr) { int old_log_level = ortp_get_log_level_mask(NULL); linphone_core_set_log_level(ORTP_ERROR); + if (mgr->phone_alias) { + ms_free(mgr->phone_alias); + } if (mgr->stat.last_received_chat_message) { linphone_chat_message_unref(mgr->stat.last_received_chat_message); } @@ -849,7 +853,7 @@ LinphoneConferenceServer* linphone_conference_server_new(const char *rc_file, bo conf_srv->vtable->registration_state_changed = linphone_conference_server_registration_state_changed; conf_srv->vtable->user_data = conf_srv; conf_srv->reg_state = LinphoneRegistrationNone; - linphone_core_manager_init(lm, rc_file); + linphone_core_manager_init(lm, rc_file,NULL); linphone_core_add_listener(lm->lc, conf_srv->vtable); linphone_core_manager_start(lm, do_registration); return conf_srv;