Commit 670d8116 authored by Nicolas Michon's avatar Nicolas Michon

Change property used by dependent proxy configs

parent 634c6455
......@@ -136,7 +136,8 @@ struct _LinphoneProxyConfig
char *refkey;
char *sip_etag; /*publish context*/
char *depends_on; /* NULL or points to another proxy_config->refkey */
char *depends_on; /* NULL or points to another proxy_config->dependency */
char *idkey; /* NULL or referenced by another proxy_config->depends_on */
char *conference_factory_uri;
bool_t push_notification_allowed;
......
......@@ -122,6 +122,7 @@ static void linphone_proxy_config_init(LinphoneCore* lc, LinphoneProxyConfig *cf
const char *contact_params = lc ? lp_config_get_default_string(lc->config, "proxy", "contact_parameters", NULL) : NULL;
const char *contact_uri_params = lc ? lp_config_get_default_string(lc->config, "proxy", "contact_uri_parameters", NULL) : NULL;
const char *refkey = lc ? lp_config_get_default_string(lc->config, "proxy", "refkey", NULL) : NULL;
const char *idkey = lc ? lp_config_get_default_string(lc->config, "proxy", "idkey", NULL) : NULL;
const char *depends_on = lc ? lp_config_get_default_string(lc->config, "proxy", "depends_on", NULL) : NULL;
const char *nat_policy_ref = lc ? lp_config_get_default_string(lc->config, "proxy", "nat_policy_ref", NULL):NULL;
const char *conference_factory_uri = lc ? lp_config_get_default_string(lc->config, "proxy", "conference_factory_uri", NULL):NULL;
......@@ -158,6 +159,7 @@ 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;
linphone_proxy_config_set_conference_factory_uri(cfg, conference_factory_uri ? ms_strdup(conference_factory_uri) : NULL);
}
......@@ -261,6 +263,7 @@ void _linphone_proxy_config_destroy(LinphoneProxyConfig *cfg){
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);
if (cfg->nat_policy != NULL) {
linphone_nat_policy_unref(cfg->nat_policy);
}
......@@ -422,11 +425,10 @@ 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_refkey(lc, cfg->depends_on) == NULL) {
ms_message("LinphoneProxyConfig marked as dependent but no proxy configuration found for refkey [%s]", cfg->depends_on);
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;
}
return TRUE;
}
......@@ -467,7 +469,7 @@ void linphone_proxy_config_apply(LinphoneProxyConfig *cfg, LinphoneCore *lc){
cfg->lc=lc;
if (cfg->depends_on != NULL) {
//disable register if master cfg is not yet registered
LinphoneProxyConfig *masterCfg = linphone_core_get_proxy_config_by_refkey(lc, cfg->depends_on);
LinphoneProxyConfig *masterCfg = linphone_core_get_proxy_config_by_idkey(lc, cfg->depends_on);
if (masterCfg && masterCfg->state != LinphoneRegistrationOk) {
if (cfg->reg_sendregister != FALSE) {
cfg->register_changed = TRUE;
......@@ -516,7 +518,7 @@ static LinphoneAddress *guess_contact_for_register (LinphoneProxyConfig *cfg) {
if (cfg->depends_on) {
//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_refkey(cfg->lc, cfg->depends_on);
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);
}
......@@ -1097,6 +1099,18 @@ void linphone_proxy_config_set_depends_on(LinphoneProxyConfig *cfg, const char *
}
}
const char *linphone_proxy_config_get_idkey(LinphoneProxyConfig *cfg) {
return cfg->idkey;
}
void linphone_proxy_config_set_idkey(LinphoneProxyConfig *cfg, const char *idkey) {
if (cfg) {
if (cfg->idkey) ms_free(cfg->idkey);
cfg->idkey = ms_strdup(idkey);
}
}
LinphoneStatus linphone_core_add_proxy_config(LinphoneCore *lc, LinphoneProxyConfig *cfg){
if (!linphone_proxy_config_check(lc,cfg)) {
return -1;
......@@ -1116,8 +1130,8 @@ void linphone_core_remove_dependent_proxy_config(LinphoneCore *lc, LinphoneProxy
for (;it;it = it->next) {
LinphoneProxyConfig *tmp = reinterpret_cast<LinphoneProxyConfig *>(it->data);
if (tmp != cfg && tmp->depends_on && strcmp(tmp->depends_on, cfg->refkey) == 0) {
ms_message("Updating dependent proxy config [%p] caused by removal of 'master' proxy config refkey[%s]", tmp, cfg->refkey);
if (tmp != cfg && tmp->depends_on && strcmp(tmp->depends_on, cfg->idkey) == 0) {
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_edit(tmp);
......@@ -1182,12 +1196,12 @@ int linphone_core_get_default_proxy_config_index(LinphoneCore *lc) {
return pos;
}
LinphoneProxyConfig *linphone_core_get_proxy_config_by_refkey(LinphoneCore *lc, const char *refkey) {
if (refkey == NULL || lc == NULL) return NULL;
LinphoneProxyConfig *linphone_core_get_proxy_config_by_idkey(LinphoneCore *lc, const char *idkey) {
if (idkey == NULL || lc == NULL) return NULL;
bctbx_list_t *list = lc->sip_conf.proxies;
for (;list!=NULL;list=list->next) {
LinphoneProxyConfig *tmp = reinterpret_cast<LinphoneProxyConfig *>(list->data);
if (tmp && tmp->refkey && strcmp(refkey, tmp->refkey) == 0) {
if (tmp && tmp->idkey && strcmp(idkey, tmp->idkey) == 0) {
return tmp;
}
}
......@@ -1272,6 +1286,7 @@ void linphone_proxy_config_write_to_config_file(LpConfig *config, LinphoneProxyC
lp_config_set_int(config, key, "push_notification_allowed", (int)cfg->push_notification_allowed);
if (cfg->refkey) lp_config_set_string(config, key, "refkey", cfg->refkey);
if (cfg->depends_on) lp_config_set_string(config, key, "depends_on", cfg->depends_on);
if (cfg->idkey) lp_config_set_string(config, key, "idkey", cfg->idkey);
lp_config_set_int(config, key, "publish_expires", cfg->publish_expires);
if (cfg->nat_policy != NULL) {
......@@ -1344,6 +1359,7 @@ LinphoneProxyConfig *linphone_proxy_config_new_from_config_file(LinphoneCore* lc
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")
CONFIGURE_INT_VALUE(cfg, config, key, publish_expires, "publish_expires", int)
nat_policy_ref = lp_config_get_string(config, key, "nat_policy_ref", NULL);
......@@ -1399,7 +1415,7 @@ static bool_t can_register(LinphoneProxyConfig *cfg){
return FALSE;
}
if (cfg->depends_on) {
LinphoneProxyConfig *masterCfg = linphone_core_get_proxy_config_by_refkey(lc, 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;
}
return TRUE;
......@@ -1452,7 +1468,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->refkey) == 0) {
if (tmp != cfg && tmp->depends_on && strcmp(tmp->depends_on, cfg->idkey) == 0) {
if (tmp->reg_dependent_disabled) continue;
linphone_proxy_config_edit(tmp);
if (state == LinphoneRegistrationOk) {
......
......@@ -2211,10 +2211,10 @@ LINPHONE_PUBLIC const bctbx_list_t *linphone_core_get_proxy_config_list(const Li
LINPHONE_PUBLIC void linphone_core_set_default_proxy_index(LinphoneCore *lc, int index);
/**
* @param[in] refkey An arbitrary reference key associated to a proxy configuration
* @return the proxy configuration for the given refkey, or NULL if none found
* @param[in] idkey An arbitrary idkey string associated to a proxy configuration
* @return the proxy configuration for the given idkey value, or NULL if none found
**/
LINPHONE_PUBLIC LinphoneProxyConfig *linphone_core_get_proxy_config_by_refkey(LinphoneCore *lc, const char *refkey);
LINPHONE_PUBLIC LinphoneProxyConfig *linphone_core_get_proxy_config_by_idkey(LinphoneCore *lc, const char *idkey);
/**
* @return the default proxy configuration, that is the one used to determine the current identity.
......
......@@ -587,18 +587,18 @@ 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 refkey of a #LinphoneProxyConfig this proxy config is dependent on.
* Get the depends_on property of a #LinphoneProxyConfig.
*
* @param[in] cfg #LinphoneProxyConfig object.
* @return The reference key string this proxy config is dependent on, or NULL if not marked dependent
* @return The idkey string this proxy config is dependent upon, or NULL if not marked dependent
**/
LINPHONE_PUBLIC const char *linphone_proxy_config_get_depends_on(LinphoneProxyConfig *cfg);
/**
* Mark this proxy configuration as being dependent on another.
* The depends_on string must refer to a refkey of a proxy configuration previously added to the core.
* The depends_on string must refer to an idkey of a proxy configuration previously added to the core.
*
* @see linphone_proxy_config_set_ref_key()
* @see linphone_proxy_config_set_idkey()
*
* The proxy configuration marked as dependent will wait for successful registration on its dependency before triggering its own.
*
......@@ -611,6 +611,24 @@ LINPHONE_PUBLIC const char *linphone_proxy_config_get_depends_on(LinphoneProxyCo
**/
LINPHONE_PUBLIC void linphone_proxy_config_set_depends_on(LinphoneProxyConfig *cfg, const char *depends_on);
/**
* Get the idkey property of a #LinphoneProxyConfig.
*
* @param[in] cfg #LinphoneProxyConfig object.
* @return The idkey string, or NULL
**/
LINPHONE_PUBLIC const char *linphone_proxy_config_get_idkey(LinphoneProxyConfig *cfg);
/**
* Set the idkey property on the given proxy configuration.
* This property can the be referenced by another proxy config 'depends_on' to create a dependency relation between them.
* @see linphone_proxy_config_set_depends_on()
*
* @param[in] cfg #LinphoneProxyConfig object.
* @param[in] idkey The idkey string to associate to the given #LinphoneProxyConfig
**/
LINPHONE_PUBLIC void linphone_proxy_config_set_idkey(LinphoneProxyConfig *cfg, const char *idkey);
/**
* Get The policy that is used to pass through NATs/firewalls when using this proxy config.
* If it is set to NULL, the default NAT policy from the core will be used instead.
......
......@@ -311,7 +311,6 @@ static void dependent_proxy_config(void) {
linphone_core_invite_address(pauline->lc, marie_dependent_addr);
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));
......@@ -389,11 +388,11 @@ static void invalid_dependent_proxy_config(void) {
BC_ASSERT_EQUAL(bctbx_list_size(proxyConfigs), 0, int, "%d");
linphone_proxy_config_set_ref_key(master, "invalid");
linphone_proxy_config_set_idkey(master, "invalid");
linphone_core_add_proxy_config(marie->lc, master);
//Adding a dependent proxy config linking to inexistent refkey should fail
//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");
proxyConfigs = linphone_core_get_proxy_config_list(marie->lc);
......
......@@ -20,7 +20,7 @@ reg_expires=3600
reg_sendregister=1
publish=0
dial_escape_plus=0
refkey=master
idkey=master
[proxy_1]
reg_proxy=<sip:sip2.linphone.org:5069;transport=tls>
......
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