diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 8bc21c4a09fc1e5b3faf089d9f2be2dae6547569..75d1c51b55314b4df36bb51f51876e6406a5dbb9 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -3498,6 +3498,62 @@ static void linphone_core_init(LinphoneCore *lc, } } +/* The management of settings needs to be revisited. + * The reading and application of settings is not consistent between the case where + * the Core is started for the first time, or is being restarted. + * Currently, the following is done when a core is created: + * 1) create the Core object + * 2) read user settings from config file + * 3) apply the settings to Sal or other sub-entities + * + * When the core is started following creation (case A): + * 4) fetch the remote provisioning if any + * 5) if remote provisioning was done, re-apply the settings to Sal or other sub-entities. + * + * When the core is being stopped: + * 6) the Sal is destroyed + * + * When the core is now restarted (case B): + * 7) re-instanciate the Sal and apply settings + * 8) fetch the remote provisioning if any + * 9) if remote provisioning was done, re-apply the settings to Sal or other sub-entities. + * + * As a result the Core does not perform the same things in case A and B, despite the same + * action is requested. + * + * This tyically leads to the following situation where an app does settings modification + * through LinphoneConfig API before calling linphone_core_start(): + * - at first start, the settings won't have any effect. + * - at second start, the settings will take effect. + * This is extremely error-prone, a big refactoring is required here. + * Meanwhile, in order to circumvent this problem the below function + * linphone_core_before_start_apply_settings() re-applies a few settings + * that are frequently modified before linphone_core_start(), and need specific + * code in order to be applied. + * Note that not all settings are subject to this problem (mainly the Sal related ones). + * Most settings are just read and use on demand. + */ + +static void linphone_core_before_start_apply_settings(LinphoneCore *lc) { + lc->conference_version = ms_strdup(L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->conferenceVersionAsString())); + lc->groupchat_version = ms_strdup(L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->groupChatVersionAsString())); + lc->ephemeral_version = ms_strdup(L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->ephemeralVersionAsString())); + + // to give a chance to change uuid before starting + const char *uuid = linphone_config_get_string(lc->config, "misc", "uuid", NULL); + if (!uuid) { + string uuid = lc->sal->createUuid(); + linphone_config_set_string(lc->config, "misc", "uuid", uuid.c_str()); + } else if (strcmp(uuid, "0") != 0) /*to allow to disable sip.instance*/ + lc->sal->setUuid(uuid); + + if (!lc->sal->getRootCa().empty()) { + auto &httpClient = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->getHttpClient(); + belle_tls_crypto_config_set_root_ca(httpClient.getCryptoConfig(), lc->sal->getRootCa().c_str()); + } + lc->sal->forceNameAddr(linphone_config_get_int(lc->config, "sip", "force_name_addr", 0)); +} + LinphoneStatus linphone_core_start(LinphoneCore *lc) { CoreLogContextualizer logContextualizer(lc); try { @@ -3543,22 +3599,7 @@ LinphoneStatus linphone_core_start(LinphoneCore *lc) { linphone_core_set_state(lc, LinphoneGlobalStartup, "Starting up"); L_GET_PRIVATE_FROM_C_OBJECT(lc)->init(); - lc->conference_version = ms_strdup(L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->conferenceVersionAsString())); - lc->groupchat_version = ms_strdup(L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->groupChatVersionAsString())); - lc->ephemeral_version = ms_strdup(L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->ephemeralVersionAsString())); - - // to give a chance to change uuid before starting - const char *uuid = linphone_config_get_string(lc->config, "misc", "uuid", NULL); - if (!uuid) { - string uuid = lc->sal->createUuid(); - linphone_config_set_string(lc->config, "misc", "uuid", uuid.c_str()); - } else if (strcmp(uuid, "0") != 0) /*to allow to disable sip.instance*/ - lc->sal->setUuid(uuid); - - if (!lc->sal->getRootCa().empty()) { - auto &httpClient = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->getHttpClient(); - belle_tls_crypto_config_set_root_ca(httpClient.getCryptoConfig(), lc->sal->getRootCa().c_str()); - } + linphone_core_before_start_apply_settings(lc); bool autoNetworkStateMonitoringEnabled = !!lc->auto_net_state_mon; if (!autoNetworkStateMonitoringEnabled) { diff --git a/src/sal/sal.cpp b/src/sal/sal.cpp index f4c7c10f76dabfa813353b8f1f2c1ac6761e7797..e31d5b410d2bacbf2631c0f973e72dfd83c68982 100644 --- a/src/sal/sal.cpp +++ b/src/sal/sal.cpp @@ -956,6 +956,10 @@ void Sal::setRefreshWindow(const int min_value, const int max_value) { } } +void Sal::forceNameAddr(bool value) { + belle_sip_stack_force_name_addr(value); +} + void Sal::disableMedia(bool enable) { mDisableMedia = enable; } diff --git a/src/sal/sal.h b/src/sal/sal.h index 4084a99a44691f5bc32941997271596ad3015b81..137047e0e6e304d9543f9eef89b5d2bc593bdf3f 100644 --- a/src/sal/sal.h +++ b/src/sal/sal.h @@ -337,6 +337,7 @@ public: void useTcpTlsKeepAlive(bool value) { mUseTcpTlsKeepAlive = value; } + void forceNameAddr(bool value); void sendKeepAlive(); void setDscp(int dscp) { diff --git a/tester/call_multi_tester.c b/tester/call_multi_tester.c index e31c10ab1c24a478d7c9a062f8e0a75f4c3edeaa..69afabbc2811072234da19b23762fde4fe5114cf 100644 --- a/tester/call_multi_tester.c +++ b/tester/call_multi_tester.c @@ -367,7 +367,12 @@ static void simple_call_transfer(void) { } static void simple_call_transfer_from_non_default_account(void) { + /* this test is run in force_name_addr mode (ie enclose all URIs within < > within SIP headers) + * to make sure it has no incidence on the good execution of call transfers. + */ + belle_sip_stack_force_name_addr(TRUE); _simple_call_transfer(FALSE, FALSE); + belle_sip_stack_force_name_addr(FALSE); } static void simple_call_transfer_with_pause_before(void) { diff --git a/tester/setup_tester.c b/tester/setup_tester.c index 09e271ce7a8996877b643dcf4f2e92b4f674bf0c..34f8717bd77a9455539f6c2dc1bfd33dfbf635c3 100644 --- a/tester/setup_tester.c +++ b/tester/setup_tester.c @@ -429,6 +429,7 @@ static void core_set_user_agent(void) { static void linphone_address_test(void) { LinphoneAddress *address; + char *str; linphone_address_unref(create_linphone_address(NULL)); BC_ASSERT_PTR_NULL(linphone_address_new("sip:@sip.linphone.org")); @@ -447,6 +448,30 @@ static void linphone_address_test(void) { address = linphone_address_new("sip:[::ffff:90.110.127.31]"); if (!BC_ASSERT_PTR_NOT_NULL(address)) return; linphone_address_unref(address); + + /* Verifies that the [sip]/force_name_addr works as expected. */ + LinphoneCoreManager *lcm = linphone_core_manager_create("empty_rc"); + linphone_config_set_int(linphone_core_get_config(lcm->lc), "sip", "force_name_addr", 1); + bctbx_message("force_name_addr enabled"); + linphone_core_start(lcm->lc); + address = linphone_address_new("sip:bob@example.com"); + if (BC_ASSERT_PTR_NOT_NULL(address)) { + str = linphone_address_as_string(address); + BC_ASSERT_STRING_EQUAL(str, "<sip:bob@example.com>"); + bctbx_free(str); + linphone_address_unref(address); + } + linphone_core_stop(lcm->lc); + linphone_config_set_int(linphone_core_get_config(lcm->lc), "sip", "force_name_addr", 0); + linphone_core_start(lcm->lc); + address = linphone_address_new("sip:bob@example.com"); + if (BC_ASSERT_PTR_NOT_NULL(address)) { + str = linphone_address_as_string(address); + BC_ASSERT_STRING_EQUAL(str, "sip:bob@example.com"); + bctbx_free(str); + linphone_address_unref(address); + } + linphone_core_manager_destroy(lcm); } static void core_sip_transport_test(void) {