Commit 8d7cac3b authored by Nicolas Michon's avatar Nicolas Michon
Browse files

Changes on dependent proxy configs

parent ee34ccbe
......@@ -166,13 +166,6 @@ LinphoneProxyConfig * linphone_account_creator_create_proxy_config(const Linphon
ms_free(url);
}
if (creator->idkey != NULL) {
linphone_proxy_config_set_idkey(cfg, creator->idkey);
}
if (creator->depends_on != NULL) {
linphone_proxy_config_set_depends_on(cfg, creator->depends_on);
}
linphone_proxy_config_enable_register(cfg, TRUE);
info = linphone_auth_info_new(linphone_address_get_username(identity), // username
......@@ -363,7 +356,6 @@ LinphoneAccountCreator * _linphone_account_creator_new(LinphoneCore *core, const
if (domain) {
linphone_account_creator_set_domain(creator, domain);
}
creator->set_as_default = TRUE;
creator->proxy_cfg = linphone_core_create_proxy_config(core);
......@@ -389,8 +381,6 @@ void linphone_account_creator_reset(LinphoneAccountCreator *creator) {
resetField(&creator->activation_code);
resetField(&creator->domain);
resetField(&creator->route);
resetField(&creator->idkey);
resetField(&creator->depends_on);
}
LinphoneAccountCreator * linphone_core_create_account_creator(LinphoneCore *core, const char *xmlrpc_url) {
......@@ -623,24 +613,6 @@ const char * linphone_account_creator_get_route(const LinphoneAccountCreator *cr
return creator->route;
}
LinphoneAccountCreatorStatus linphone_account_creator_set_idkey(LinphoneAccountCreator *creator, const char *idkey) {
set_string(&creator->idkey, idkey, FALSE);
return LinphoneAccountCreatorStatusRequestOk;
}
const char * linphone_account_creator_get_idkey(const LinphoneAccountCreator *creator) {
return creator->idkey;
}
LinphoneAccountCreatorStatus linphone_account_creator_set_depends_on(LinphoneAccountCreator *creator, const char *depends_on) {
set_string(&creator->depends_on, depends_on, FALSE);
return LinphoneAccountCreatorStatusRequestOk;
}
const char * linphone_account_creator_get_depends_on(const LinphoneAccountCreator *creator) {
return creator->depends_on;
}
LinphoneAccountCreatorStatus linphone_account_creator_set_as_default(LinphoneAccountCreator *creator, bool_t set_as_default) {
creator->set_as_default = set_as_default;
return LinphoneAccountCreatorStatusRequestOk;
......
......@@ -105,9 +105,6 @@ struct _LinphoneAccountCreator {
char *algorithm; /**< Digest authentication algorithm */
LinphoneTransportType transport; /**< Transport used */
char *depends_on; /**< Triggers proxy config depdendency mecanism if not NULL */
char *idkey; /**< Unique identification key */
bool_t set_as_default; /**< Set proxy config as the default one */
/* Deprecated */
......
......@@ -96,8 +96,7 @@ This mecanism must be enabled before the proxy configuration is added to the cor
LinphoneProxyConfig* dependent_proxy_cfg;
LinphoneProxyConfig* master_proxy_cfg;
linphone_proxy_config_set_ref_key(master_proxy_cfg, "unique-proxy-id");
linphone_proxy_config_set_depends_on(dependent_proxy_cfg, "unique-proxy-id");
linphone_proxy_config_set_dependency(dependent_proxy_cfg, master_proxy_cfg);
//Add master first
linphone_core_add_proxy_config(lc, master_proxy_cfg);
linphone_core_add_proxy_config(lc, dependent_proxy_cfg);
......
......@@ -137,6 +137,7 @@ struct _LinphoneProxyConfig
char *refkey;
char *sip_etag; /*publish context*/
char *depends_on; /* NULL or points to another proxy_config->idkey */
LinphoneProxyConfig *dependency; /* Points to another proxy config if depends_on is defined */
char *idkey; /* NULL or referenced by another proxy_config->depends_on */
char *conference_factory_uri;
......
......@@ -42,6 +42,12 @@ Copyright (C) 2000 Simon MORLAT (simon.morlat@linphone.org)
using namespace LinphonePrivate;
static char *generate_proxy_config_id() {
char id[17] = {0};
belle_sip_random_token(id, 16);
return bctbx_concat("proxy_config_", id, NULL);
}
/*store current config related to server location*/
static void linphone_proxy_config_store_server_config(LinphoneProxyConfig* cfg) {
if (cfg->saved_identity) linphone_address_unref(cfg->saved_identity);
......@@ -129,7 +135,6 @@ static void linphone_proxy_config_init(LinphoneCore* lc, LinphoneProxyConfig *cf
cfg->lc = lc;
cfg->expires = lc ? lp_config_get_default_int(lc->config, "proxy", "reg_expires", 3600) : 3600;
cfg->reg_sendregister = lc ? !!lp_config_get_default_int(lc->config, "proxy", "reg_sendregister", 1) : 1;
cfg->reg_dependent_disabled = cfg->depends_on && !cfg->reg_sendregister;
cfg->dial_prefix = dial_prefix ? ms_strdup(dial_prefix) : NULL;
cfg->dial_escape_plus = lc ? !!lp_config_get_default_int(lc->config, "proxy", "dial_escape_plus", 0) : 0;
cfg->privacy = lc ? (LinphonePrivacyMask)lp_config_get_default_int(lc->config, "proxy", "privacy", LinphonePrivacyDefault) : (LinphonePrivacyMask)LinphonePrivacyDefault;
......@@ -159,7 +164,14 @@ static void linphone_proxy_config_init(LinphoneCore* lc, LinphoneProxyConfig *cf
}
}
cfg->depends_on = depends_on ? ms_strdup(depends_on) : NULL;
cfg->idkey = idkey ? ms_strdup(idkey) : NULL;
cfg->reg_dependent_disabled = cfg->depends_on && !cfg->reg_sendregister;
if (idkey) {
cfg->idkey = ms_strdup(idkey);
} else {
cfg->idkey = generate_proxy_config_id();
ms_warning("generated proxyconfig idkey = [%s]", cfg->idkey);
}
linphone_proxy_config_set_conference_factory_uri(cfg, conference_factory_uri ? ms_strdup(conference_factory_uri) : NULL);
}
......@@ -262,8 +274,8 @@ void _linphone_proxy_config_destroy(LinphoneProxyConfig *cfg){
if (cfg->sent_headers != NULL) sal_custom_header_free(cfg->sent_headers);
if (cfg->pending_contact) linphone_address_unref(cfg->pending_contact);
if (cfg->refkey) ms_free(cfg->refkey);
if (cfg->depends_on) ms_free(cfg->depends_on);
if (cfg->idkey) ms_free(cfg->idkey);
linphone_proxy_config_set_dependency(cfg, NULL);
if (cfg->nat_policy != NULL) {
linphone_nat_policy_unref(cfg->nat_policy);
}
......@@ -425,9 +437,21 @@ bool_t linphone_proxy_config_check(LinphoneCore *lc, LinphoneProxyConfig *cfg){
return FALSE;
if (cfg->identity_address==NULL)
return FALSE;
if (cfg->depends_on != NULL && linphone_core_get_proxy_config_by_idkey(lc, cfg->depends_on) == NULL) {
ms_message("LinphoneProxyConfig marked as dependent but no proxy configuration found for idkey [%s]", cfg->depends_on);
return FALSE;
if (cfg->dependency != NULL && cfg->depends_on != NULL) {
if (linphone_core_get_proxy_config_by_idkey(lc, cfg->depends_on) != cfg->dependency) {
ms_warning("LinphoneProxyConfig as a dependency but idkeys do not match: [%s] != [%s]", cfg->depends_on, cfg->dependency->idkey);
return FALSE;
}
}
if (cfg->depends_on != NULL && cfg->dependency == NULL) {
LinphoneProxyConfig *dependency = linphone_core_get_proxy_config_by_idkey(lc, cfg->depends_on);
if (dependency == NULL) {
ms_warning("LinphoneProxyConfig marked as dependent but no proxy configuration found for idkey [%s]", cfg->depends_on);
return FALSE;
} else {
cfg->dependency = linphone_proxy_config_ref(dependency);
}
}
return TRUE;
}
......@@ -435,7 +459,7 @@ bool_t linphone_proxy_config_check(LinphoneCore *lc, LinphoneProxyConfig *cfg){
void linphone_proxy_config_enableregister(LinphoneProxyConfig *cfg, bool_t val){
if (val != cfg->reg_sendregister) cfg->register_changed = TRUE;
cfg->reg_sendregister = val;
if (cfg->depends_on && !val) {
if (cfg->dependency && !val) {
cfg->reg_dependent_disabled = TRUE;
}
}
......@@ -467,10 +491,9 @@ void linphone_proxy_config_edit(LinphoneProxyConfig *cfg){
void linphone_proxy_config_apply(LinphoneProxyConfig *cfg, LinphoneCore *lc){
cfg->lc=lc;
if (cfg->depends_on != NULL) {
if (cfg->dependency != NULL) {
//disable register if master cfg is not yet registered
LinphoneProxyConfig *masterCfg = linphone_core_get_proxy_config_by_idkey(lc, cfg->depends_on);
if (masterCfg && masterCfg->state != LinphoneRegistrationOk) {
if (cfg->dependency->state != LinphoneRegistrationOk) {
if (cfg->reg_sendregister != FALSE) {
cfg->register_changed = TRUE;
}
......@@ -516,11 +539,9 @@ static LinphoneAddress *guess_contact_for_register (LinphoneProxyConfig *cfg) {
LinphoneProxyConfig *ref = cfg;
LinphoneAddress *result = nullptr;
if (cfg->depends_on) {
if (cfg->dependency) {
//In case of dependent proxy config, force contact of 'master' proxy config, but only after a successful register
LinphoneProxyConfig *master = linphone_core_get_proxy_config_by_idkey(cfg->lc, cfg->depends_on);
//if (master) ref = master;
return linphone_address_clone(master->contact_address);
return linphone_address_clone(cfg->dependency->contact_address);
}
LinphoneAddress *proxy = linphone_address_new(ref->reg_proxy);
if (!proxy)
......@@ -610,7 +631,7 @@ void linphone_proxy_config_set_dial_prefix(LinphoneProxyConfig *cfg, const char
cfg->dial_prefix=NULL;
}
if (prefix && prefix[0]!='\0') cfg->dial_prefix=ms_strdup(prefix);
if (cfg->lc) {
bctbx_list_t *elem;
for (elem = cfg->lc->friends_lists; elem != NULL; elem = bctbx_list_next(elem)) {
......@@ -1088,14 +1109,25 @@ void linphone_proxy_config_set_custom_header(LinphoneProxyConfig *cfg, const cha
cfg->register_changed = TRUE;
}
const char *linphone_proxy_config_get_depends_on(LinphoneProxyConfig *cfg) {
return cfg->depends_on;
LinphoneProxyConfig *linphone_proxy_config_get_dependency(LinphoneProxyConfig *cfg) {
return cfg->dependency;
}
void linphone_proxy_config_set_depends_on(LinphoneProxyConfig *cfg, const char *depends_on) {
void linphone_proxy_config_set_dependency(LinphoneProxyConfig *cfg, LinphoneProxyConfig *dependency) {
if (cfg) {
if (cfg->depends_on) ms_free(cfg->depends_on);
cfg->depends_on = ms_strdup(depends_on);
if (cfg->depends_on) {
ms_free(cfg->depends_on);
}
if (cfg->dependency) {
linphone_proxy_config_unref(cfg->dependency);
}
if (dependency) {
cfg->dependency = linphone_proxy_config_ref(dependency);
cfg->depends_on = ms_strdup(dependency->idkey);
} else {
cfg->dependency = NULL;
cfg->depends_on = NULL;
}
}
}
......@@ -1111,7 +1143,7 @@ void linphone_proxy_config_set_idkey(LinphoneProxyConfig *cfg, const char *idkey
}
LinphoneStatus linphone_core_add_proxy_config(LinphoneCore *lc, LinphoneProxyConfig *cfg){
LinphoneStatus linphone_core_add_proxy_config(LinphoneCore *lc, LinphoneProxyConfig *cfg) {
if (!linphone_proxy_config_check(lc,cfg)) {
return -1;
}
......@@ -1124,16 +1156,15 @@ LinphoneStatus linphone_core_add_proxy_config(LinphoneCore *lc, LinphoneProxyCon
return 0;
}
//If a proxy config dependency is removed, re-enable 'normal' behavior for previously dependent configs
//If a proxy config dependency is removed, restore 'normal' behavior for previously dependent configs
void linphone_core_remove_dependent_proxy_config(LinphoneCore *lc, LinphoneProxyConfig *cfg) {
bctbx_list_t *it = lc->sip_conf.proxies;
for (;it;it = it->next) {
LinphoneProxyConfig *tmp = reinterpret_cast<LinphoneProxyConfig *>(it->data);
if (tmp != cfg && tmp->depends_on && strcmp(tmp->depends_on, cfg->idkey) == 0) {
if (tmp != cfg && tmp->dependency == cfg) {
ms_message("Updating dependent proxy config [%p] caused by removal of 'master' proxy config idkey[%s]", tmp, cfg->idkey);
bctbx_free(tmp->depends_on);
tmp->depends_on = NULL;
linphone_proxy_config_set_dependency(tmp, NULL);
linphone_proxy_config_edit(tmp);
//Only re-enable register if proxy wasn't explicitely disabled
linphone_proxy_config_enable_register(tmp, tmp->reg_dependent_disabled != TRUE);
......@@ -1358,8 +1389,17 @@ LinphoneProxyConfig *linphone_proxy_config_new_from_config_file(LinphoneCore* lc
CONFIGURE_INT_VALUE(cfg, config, key, privacy, "privacy", LinphonePrivacyMask)
CONFIGURE_STRING_VALUE(cfg, config, key, ref_key, "refkey")
CONFIGURE_STRING_VALUE(cfg, config, key, depends_on, "depends_on")
CONFIGURE_STRING_VALUE(cfg, config, key, idkey, "idkey")
if (cfg->idkey == NULL) {
cfg->idkey = generate_proxy_config_id();
ms_warning("generated proxyconfig idkey = [%s]", cfg->idkey);
}
const char *depends_on = lp_config_get_string(config, key, "depends_on", NULL);
if (cfg->depends_on) {
ms_free(cfg->depends_on);
}
cfg->depends_on = ms_strdup(depends_on);
CONFIGURE_INT_VALUE(cfg, config, key, publish_expires, "publish_expires", int)
nat_policy_ref = lp_config_get_string(config, key, "nat_policy_ref", NULL);
......@@ -1414,9 +1454,8 @@ static bool_t can_register(LinphoneProxyConfig *cfg){
if (lc->sip_conf.register_only_when_network_is_up && !lc->sip_network_state.global_state) {
return FALSE;
}
if (cfg->depends_on) {
LinphoneProxyConfig *masterCfg = linphone_core_get_proxy_config_by_idkey(lc, cfg->depends_on);
return masterCfg && linphone_proxy_config_get_state(masterCfg) == LinphoneRegistrationOk && !cfg->reg_dependent_disabled;
if (cfg->dependency) {
return linphone_proxy_config_get_state(cfg->dependency) == LinphoneRegistrationOk && !cfg->reg_dependent_disabled;
}
return TRUE;
}
......@@ -1468,7 +1507,7 @@ void _linphone_update_dependent_proxy_config(LinphoneProxyConfig *cfg, LinphoneR
for (;it;it = it->next) {
LinphoneProxyConfig *tmp = reinterpret_cast<LinphoneProxyConfig *>(it->data);
if (tmp != cfg && tmp->depends_on && strcmp(tmp->depends_on, cfg->idkey) == 0) {
if (tmp != cfg && tmp->dependency == cfg) {
if (tmp->reg_dependent_disabled) continue;
linphone_proxy_config_edit(tmp);
if (state == LinphoneRegistrationOk) {
......@@ -1518,7 +1557,7 @@ void linphone_proxy_config_set_state(LinphoneProxyConfig *cfg, LinphoneRegistrat
/*at this point state must be updated*/
cfg->state = state;
}
if (!cfg->depends_on) {
if (!cfg->dependency) {
_linphone_update_dependent_proxy_config(cfg, state, message);
}
if (lc) {
......
......@@ -333,36 +333,6 @@ LINPHONE_DEPRECATED LINPHONE_PUBLIC LinphoneAccountCreatorStatus linphone_accoun
**/
LINPHONE_DEPRECATED LINPHONE_PUBLIC const char * linphone_account_creator_get_route(const LinphoneAccountCreator *creator);
/**
* Set the idkey.
* @param[in] creator #LinphoneAccountCreator object
* @param[in] idkey The idkey to set
* @return #LinphoneAccountCreatorStatusRequestOk if everything is OK, or a specific error otherwise.
**/
LINPHONE_PUBLIC LinphoneAccountCreatorStatus linphone_account_creator_set_idkey(LinphoneAccountCreator *creator, const char *idkey);
/**
* Get the idkey.
* @param[in] creator #LinphoneAccountCreator object
* @return The idkey of the #LinphoneAccountCreator
**/
LINPHONE_PUBLIC const char * linphone_account_creator_get_idkey(const LinphoneAccountCreator *creator);
/**
* Set the depends_on property.
* @param[in] creator #LinphoneAccountCreator object
* @param[in] depends_on The idkey to set
* @return #LinphoneAccountCreatorStatusRequestOk if everything is OK, or a specific error otherwise.
**/
LINPHONE_PUBLIC LinphoneAccountCreatorStatus linphone_account_creator_set_depends_on(LinphoneAccountCreator *creator, const char *depends_on);
/**
* Get the depends_on property.
* @param[in] creator #LinphoneAccountCreator object
* @return The idkey of the #LinphoneAccountCreator
**/
LINPHONE_PUBLIC const char * linphone_account_creator_get_depends_on(const LinphoneAccountCreator *creator);
/**
* Set the set_as_default property.
* @param[in] creator #LinphoneAccountCreator object
......
......@@ -587,29 +587,29 @@ LINPHONE_PUBLIC const char * linphone_proxy_config_get_ref_key(const LinphonePro
LINPHONE_PUBLIC void linphone_proxy_config_set_ref_key(LinphoneProxyConfig *cfg, const char *refkey);
/**
* Get the depends_on property of a #LinphoneProxyConfig.
* Get the dependency of a #LinphoneProxyConfig.
*
* @param[in] cfg #LinphoneProxyConfig object.
* @return The idkey string this proxy config is dependent upon, or NULL if not marked dependent
* @return The proxy config this one is dependent upon, or NULL if not marked dependent
**/
LINPHONE_PUBLIC const char *linphone_proxy_config_get_depends_on(LinphoneProxyConfig *cfg);
LINPHONE_PUBLIC LinphoneProxyConfig *linphone_proxy_config_get_dependency(LinphoneProxyConfig *cfg);
/**
* Mark this proxy configuration as being dependent on another.
* The depends_on string must refer to an idkey of a proxy configuration previously added to the core.
* Mark this proxy configuration as being dependent on the given one.
* The dependency must refer to a proxy config previously added to the core and which idkey property is defined.
*
* @see linphone_proxy_config_set_idkey()
*
* The proxy configuration marked as dependent will wait for successful registration on its dependency before triggering its own.
*
* Once registered, both proxy configurations will share the same contact address (the 'master' one).
* Once registered, both proxy configurations will share the same contact address (the 'dependency' one).
*
* This mecanism must be enabled before the proxy configuration is added to the core
*
* @param[in] cfg #LinphoneProxyConfig object.
* @param[in] depends_on The reference key of a master #LinphoneProxyConfig
**/
LINPHONE_PUBLIC void linphone_proxy_config_set_depends_on(LinphoneProxyConfig *cfg, const char *depends_on);
LINPHONE_PUBLIC void linphone_proxy_config_set_dependency(LinphoneProxyConfig *cfg, LinphoneProxyConfig *dependency);
/**
* Get the idkey property of a #LinphoneProxyConfig.
......
......@@ -285,7 +285,7 @@ static void dependent_proxy_config(void) {
BC_ASSERT_PTR_NOT_NULL(marie_cfg);
BC_ASSERT_PTR_NOT_NULL(marie_dependent_cfg);
BC_ASSERT_STRING_EQUAL("master", linphone_proxy_config_get_depends_on(marie_dependent_cfg));
BC_ASSERT_PTR_EQUAL(marie_cfg, linphone_proxy_config_get_dependency(marie_dependent_cfg));
BC_ASSERT_TRUE(wait_for(pauline->lc, NULL, &pauline->stat.number_of_LinphoneRegistrationOk, 1));
......@@ -312,16 +312,14 @@ static void dependent_proxy_config(void) {
if (BC_ASSERT_TRUE(wait_for_until(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallIncomingReceived, 1, 10000))) {
linphone_call_accept(linphone_core_get_current_call(marie->lc));
BC_ASSERT_TRUE(wait_for_until(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneCallStreamsRunning, 1, 10000));
BC_ASSERT_TRUE(wait_for_until(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallStreamsRunning, 1, 10000));
end_call(pauline, marie);
}
linphone_address_unref(marie_dependent_addr);
linphone_core_manager_destroy(pauline);
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
}
//Dependent proxy config should not register if its dependency is not in a LinphoneRegistrationOk state
......@@ -388,10 +386,12 @@ static void invalid_dependent_proxy_config(void) {
BC_ASSERT_EQUAL(bctbx_list_size(proxyConfigs), 0, int, "%d");
linphone_proxy_config_set_idkey(master, "invalid");
linphone_core_add_proxy_config(marie->lc, master);
linphone_proxy_config_set_dependency(dependent, master);
linphone_proxy_config_set_idkey(master, "invalid");
//Adding a dependent proxy config linking to inexistent dependency should fail
BC_ASSERT_EQUAL(linphone_core_add_proxy_config(marie->lc, dependent), -1, int, "%d");
......
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