mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-06 21:23:04 +00:00
add default values for nat policy in link with proxy config default values
This commit is contained in:
parent
be0807d024
commit
bb29521ab0
7 changed files with 124 additions and 51 deletions
|
|
@ -500,30 +500,50 @@ static char* _linphone_config_xml_convert(LpConfig *lpc, xml2lpc_context *contex
|
|||
return error_msg;
|
||||
}
|
||||
|
||||
char* linphone_config_load_from_xml_file(LinphoneConfig *lpc, const char *filename, void* lc, void* ctx) {
|
||||
char* linphone_config_load_from_xml_file(LinphoneConfig *lpc, const char *filename) {
|
||||
xml2lpc_context *context = NULL;
|
||||
char* path = lp_realpath(filename, NULL);
|
||||
char* error_msg = NULL;
|
||||
|
||||
if (path) {
|
||||
context = xml2lpc_context_new(ctx, lc);
|
||||
context = xml2lpc_context_new(NULL, NULL);
|
||||
error_msg = _linphone_config_xml_convert(lpc, context, xml2lpc_set_xml_file(context, path));
|
||||
}
|
||||
if (context) xml2lpc_context_destroy(context);
|
||||
return error_msg;
|
||||
}
|
||||
|
||||
char* linphone_config_load_from_xml_string(LpConfig *lpc, const char *buffer, void* lc, void* ctx) {
|
||||
static void xml2lpc_callback(void *ctx, xml2lpc_log_level level, const char *fmt, va_list list) {
|
||||
BctbxLogLevel bctbx_level;
|
||||
switch(level) {
|
||||
case XML2LPC_DEBUG: bctbx_level = BCTBX_LOG_DEBUG; break;
|
||||
case XML2LPC_MESSAGE: bctbx_level = BCTBX_LOG_MESSAGE;break;
|
||||
case XML2LPC_WARNING: bctbx_level = BCTBX_LOG_WARNING;break;
|
||||
case XML2LPC_ERROR: bctbx_level = BCTBX_LOG_ERROR;break;
|
||||
}
|
||||
bctbx_logv(BCTBX_LOG_DOMAIN, bctbx_level,fmt,list);
|
||||
}
|
||||
|
||||
char* _linphone_config_load_from_xml_string(LpConfig *lpc, const char *buffer) {
|
||||
xml2lpc_context *context = NULL;
|
||||
char* error_msg = NULL;
|
||||
|
||||
if (buffer != NULL) {
|
||||
context = xml2lpc_context_new(ctx, lc);
|
||||
context = xml2lpc_context_new(xml2lpc_callback, NULL);
|
||||
error_msg = _linphone_config_xml_convert(lpc, context, xml2lpc_set_xml_string(context, buffer));
|
||||
}
|
||||
if (context) xml2lpc_context_destroy(context);
|
||||
return error_msg;
|
||||
}
|
||||
LinphoneStatus linphone_config_load_from_xml_string(LpConfig *lpc, const char *buffer) {
|
||||
char *status;
|
||||
if ((status =_linphone_config_load_from_xml_string(lpc,buffer))) {
|
||||
ms_error("%s",status);
|
||||
//ms_free(status)
|
||||
return -1;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void lp_item_set_value(LpItem *item, const char *value){
|
||||
if (item->value != value) {
|
||||
|
|
|
|||
|
|
@ -267,40 +267,51 @@ LinphoneNatPolicy * linphone_core_create_nat_policy(LinphoneCore *lc) {
|
|||
return linphone_nat_policy_new(lc);
|
||||
}
|
||||
|
||||
LinphoneNatPolicy * linphone_config_create_nat_policy_from_section(const LinphoneConfig *config, const char* section) {
|
||||
const char *config_ref = lp_config_get_string(config, section, "ref", NULL);
|
||||
const char *server = lp_config_get_string(config, section, "stun_server", NULL);
|
||||
const char *username = lp_config_get_string(config, section, "stun_server_username", NULL);
|
||||
bctbx_list_t *l = lp_config_get_string_list(config, section, "protocols", NULL);
|
||||
LinphoneNatPolicy *policy;
|
||||
if (config_ref)
|
||||
policy = _linphone_nat_policy_new_with_ref(NULL, config_ref);
|
||||
else
|
||||
policy = linphone_nat_policy_new(NULL);
|
||||
|
||||
if (server != NULL) linphone_nat_policy_set_stun_server(policy, server);
|
||||
if (username != NULL) linphone_nat_policy_set_stun_server_username(policy, username);
|
||||
if (l != NULL) {
|
||||
bool_t upnp_enabled = FALSE;
|
||||
bctbx_list_t *elem;
|
||||
for (elem = l; elem != NULL; elem = elem->next) {
|
||||
const char *value = (const char *)elem->data;
|
||||
if (strcmp(value, "stun") == 0) linphone_nat_policy_enable_stun(policy, TRUE);
|
||||
else if (strcmp(value, "turn") == 0) linphone_nat_policy_enable_turn(policy, TRUE);
|
||||
else if (strcmp(value, "ice") == 0) linphone_nat_policy_enable_ice(policy, TRUE);
|
||||
else if (strcmp(value, "upnp") == 0) upnp_enabled = TRUE;
|
||||
}
|
||||
if (upnp_enabled) linphone_nat_policy_enable_upnp(policy, TRUE);
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
LinphoneNatPolicy * linphone_core_create_nat_policy_from_config(LinphoneCore *lc, const char *ref) {
|
||||
LpConfig *config = lc->config;
|
||||
LinphoneNatPolicy *policy = NULL;
|
||||
char *section;
|
||||
int index;
|
||||
bool_t finished = FALSE;
|
||||
|
||||
|
||||
for (index = 0; finished != TRUE; index++) {
|
||||
section = belle_sip_strdup_printf("nat_policy_%i", index);
|
||||
if (lp_config_has_section(config, section)) {
|
||||
const char *config_ref = lp_config_get_string(config, section, "ref", NULL);
|
||||
if ((config_ref != NULL) && (strcmp(config_ref, ref) == 0)) {
|
||||
const char *server = lp_config_get_string(config, section, "stun_server", NULL);
|
||||
const char *username = lp_config_get_string(config, section, "stun_server_username", NULL);
|
||||
bctbx_list_t *l = lp_config_get_string_list(config, section, "protocols", NULL);
|
||||
policy = _linphone_nat_policy_new_with_ref(lc, ref);
|
||||
if (server != NULL) linphone_nat_policy_set_stun_server(policy, server);
|
||||
if (username != NULL) linphone_nat_policy_set_stun_server_username(policy, username);
|
||||
if (l != NULL) {
|
||||
bool_t upnp_enabled = FALSE;
|
||||
bctbx_list_t *elem;
|
||||
for (elem = l; elem != NULL; elem = elem->next) {
|
||||
const char *value = (const char *)elem->data;
|
||||
if (strcmp(value, "stun") == 0) linphone_nat_policy_enable_stun(policy, TRUE);
|
||||
else if (strcmp(value, "turn") == 0) linphone_nat_policy_enable_turn(policy, TRUE);
|
||||
else if (strcmp(value, "ice") == 0) linphone_nat_policy_enable_ice(policy, TRUE);
|
||||
else if (strcmp(value, "upnp") == 0) upnp_enabled = TRUE;
|
||||
}
|
||||
if (upnp_enabled) linphone_nat_policy_enable_upnp(policy, TRUE);
|
||||
}
|
||||
policy = linphone_config_create_nat_policy_from_section(config, section);
|
||||
policy->lc = lc;
|
||||
finished = TRUE;
|
||||
}
|
||||
} else finished = TRUE;
|
||||
belle_sip_free(section);
|
||||
belle_sip_free(section);
|
||||
}
|
||||
return policy;
|
||||
return policy;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2029,6 +2029,10 @@ LinphoneVideoDefinition * linphone_video_definition_new(unsigned int width, unsi
|
|||
LinphoneVideoDefinition * linphone_factory_find_supported_video_definition(const LinphoneFactory *factory, unsigned int width, unsigned int height);
|
||||
LinphoneVideoDefinition * linphone_factory_find_supported_video_definition_by_name(const LinphoneFactory *factory, const char *name);
|
||||
|
||||
char* _linphone_config_load_from_xml_string(LpConfig *lpc, const char *buffer);
|
||||
LinphoneNatPolicy * linphone_config_create_nat_policy_from_section(const LinphoneConfig *config, const char* section);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -107,6 +107,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 *nat_policy_ref = lc ? lp_config_get_default_string(lc->config, "proxy", "nat_policy_ref", NULL):NULL;
|
||||
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;
|
||||
|
|
@ -127,6 +128,15 @@ static void linphone_proxy_config_init(LinphoneCore* lc, LinphoneProxyConfig *cf
|
|||
cfg->avpf_rr_interval = lc ? lp_config_get_default_int(lc->config, "proxy", "avpf_rr_interval", 5) : 5;
|
||||
cfg->publish_expires= lc ? lp_config_get_default_int(lc->config, "proxy", "publish_expires", -1) : -1;
|
||||
cfg->refkey = refkey ? ms_strdup(refkey) : NULL;
|
||||
if (nat_policy_ref) {
|
||||
LinphoneNatPolicy *policy = linphone_config_create_nat_policy_from_section(lc->config,nat_policy_ref);
|
||||
linphone_proxy_config_set_nat_policy(cfg, policy);
|
||||
if (policy) {
|
||||
linphone_nat_policy_unref(policy);
|
||||
} else {
|
||||
ms_error("Cannot create default nat policy with ref [%s] for proxy config [%p]",nat_policy_ref,cfg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LinphoneProxyConfig *linphone_proxy_config_new() {
|
||||
|
|
|
|||
|
|
@ -22,20 +22,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
|
||||
#define XML2LPC_CALLBACK_BUFFER_SIZE 1024
|
||||
|
||||
static void xml2lpc_callback(void *ctx, xml2lpc_log_level level, const char *fmt, va_list list) {
|
||||
char buffer[XML2LPC_CALLBACK_BUFFER_SIZE];
|
||||
vsnprintf(buffer, XML2LPC_CALLBACK_BUFFER_SIZE, fmt, list);
|
||||
|
||||
if (level == XML2LPC_ERROR)
|
||||
ms_error("%s", buffer);
|
||||
else if (level == XML2LPC_WARNING)
|
||||
ms_warning("%s", buffer);
|
||||
/*else
|
||||
ms_message("%s", buffer); // Don't log debug messages */
|
||||
}
|
||||
|
||||
static void linphone_remote_provisioning_apply(LinphoneCore *lc, const char *xml) {
|
||||
char* error_msg = linphone_config_load_from_xml_string(linphone_core_get_config(lc), xml, lc, xml2lpc_callback);
|
||||
char* error_msg = _linphone_config_load_from_xml_string(linphone_core_get_config(lc), xml);
|
||||
|
||||
linphone_configuring_terminated(lc
|
||||
,error_msg ? LinphoneConfiguringFailed : LinphoneConfiguringSuccessful
|
||||
|
|
|
|||
|
|
@ -87,20 +87,17 @@ LINPHONE_PUBLIC LinphoneStatus linphone_config_read_file(LinphoneConfig *lpconfi
|
|||
* @ingroup misc
|
||||
* @param lpconfig The LinphoneConfig object to fill with the content of the file
|
||||
* @param filename The filename of the config file to read to fill the LinphoneConfig
|
||||
* @param lc LinphoneCore to share with xml2lpc
|
||||
* @param ctx The context given to xml2lpc callback
|
||||
*/
|
||||
LINPHONE_PUBLIC char* linphone_config_load_from_xml_file(LinphoneConfig *lpc, const char *filename, void* lc, void* ctx);
|
||||
LINPHONE_PUBLIC char* linphone_config_load_from_xml_file(LinphoneConfig *lpc, const char *filename);
|
||||
|
||||
/**
|
||||
* Reads a xml config string and fill the LinphoneConfig with the read config dynamic values.
|
||||
* @ingroup misc
|
||||
* @param lpconfig The LinphoneConfig object to fill with the content of the file
|
||||
* @param buffer The string of the config file to fill the LinphoneConfig
|
||||
* @param lc LinphoneCore to share with xml2lpc
|
||||
* @param ctx The context given to xml2lpc callback
|
||||
* @return 0 in case of success
|
||||
*/
|
||||
LINPHONE_PUBLIC char* linphone_config_load_from_xml_string(LpConfig *lpc, const char *buffer, void* lc, void* ctx);
|
||||
LINPHONE_PUBLIC LinphoneStatus linphone_config_load_from_xml_string(LpConfig *lpc, const char *buffer);
|
||||
|
||||
/**
|
||||
* Retrieves a configuration item as a string, given its section, key, and default value.
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ static void phone_normalization_with_dial_escape_plus(void){
|
|||
BC_ASSERT_STRING_EQUAL(actual_str, expected); \
|
||||
ms_free(actual_str); \
|
||||
linphone_address_unref(res); \
|
||||
linphone_proxy_config_destroy(proxy); \
|
||||
linphone_proxy_config_unref(proxy); \
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -179,20 +179,62 @@ static void sip_uri_normalization(void) {
|
|||
SIP_URI_CHECK("١", expected); //test that no more invalid memory writes are made (valgrind only)
|
||||
}
|
||||
|
||||
/*static void load_dynamic_proxy_config(void) {
|
||||
static void load_dynamic_proxy_config(void) {
|
||||
LinphoneCoreManager *lauriane = linphone_core_manager_new(NULL);
|
||||
LinphoneProxyConfig *proxy;
|
||||
|
||||
//Load file
|
||||
|
||||
proxy = linphone_proxy_config_new();
|
||||
}*/
|
||||
LinphoneAddress *read, *expected;
|
||||
LinphoneNatPolicy *nat_policy;
|
||||
const char* config = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
|
||||
"<config xmlns=\"http://www.linphone.org/xsds/lpconfig.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.linphone.org/xsds/lpconfig.xsd lpconfig.xsd\">\r\n"
|
||||
"<section name=\"proxy_default_values\">\r\n"
|
||||
"<entry name=\"avpf\" overwrite=\"true\">1</entry>\r\n"
|
||||
"<entry name=\"dial_escape_plus\" overwrite=\"true\">0</entry>\r\n"
|
||||
"<entry name=\"publish\" overwrite=\"true\">0</entry>\r\n"
|
||||
"<entry name=\"quality_reporting_collector\" overwrite=\"true\">sip:voip-metrics@sip.linphone.org;transport=tls</entry>\r\n"
|
||||
"<entry name=\"quality_reporting_enabled\" overwrite=\"true\">1</entry>\r\n"
|
||||
"<entry name=\"quality_reporting_interval\" overwrite=\"true\">180</entry>\r\n"
|
||||
"<entry name=\"reg_expires\" overwrite=\"true\">31536000</entry>\r\n"
|
||||
"<entry name=\"reg_identity\" overwrite=\"true\">sip:?@sip.linphone.org</entry>\r\n"
|
||||
"<entry name=\"reg_proxy\" overwrite=\"true\"><sip:sip.linphone.org;transport=tls></entry>\r\n"
|
||||
"<entry name=\"reg_sendregister\" overwrite=\"true\">1</entry>\r\n"
|
||||
"<entry name=\"nat_policy_ref\" overwrite=\"true\">nat_policy_default_values</entry>\r\n"
|
||||
"<entry name=\"realm\" overwrite=\"true\">sip.linphone.org</entry>\r\n"
|
||||
"</section>\r\n"
|
||||
"<section name=\"nat_policy_default_values\">\r\n"
|
||||
"<entry name=\"stun_server\" overwrite=\"true\">stun.linphone.org</entry>\r\n"
|
||||
"<entry name=\"protocols\" overwrite=\"true\">stun,ice</entry>\r\n"
|
||||
"</section>\r\n"
|
||||
"</config>";
|
||||
BC_ASSERT_FALSE(linphone_config_load_from_xml_string(linphone_core_get_config(lauriane->lc),config));
|
||||
proxy = linphone_core_create_proxy_config(lauriane->lc);
|
||||
|
||||
read = linphone_address_new(linphone_proxy_config_get_server_addr(proxy));
|
||||
expected = linphone_address_new("sip:sip.linphone.org;transport=tls");
|
||||
|
||||
BC_ASSERT_TRUE(linphone_address_equal(read,expected));
|
||||
linphone_address_unref(read);
|
||||
linphone_address_unref(expected);
|
||||
|
||||
nat_policy = linphone_proxy_config_get_nat_policy(proxy);
|
||||
|
||||
if (BC_ASSERT_PTR_NOT_NULL(nat_policy)) {
|
||||
BC_ASSERT_TRUE(linphone_nat_policy_ice_enabled(nat_policy));
|
||||
BC_ASSERT_TRUE(linphone_nat_policy_stun_enabled(nat_policy));
|
||||
BC_ASSERT_FALSE(linphone_nat_policy_turn_enabled(nat_policy));
|
||||
}
|
||||
linphone_proxy_config_unref(proxy);
|
||||
linphone_core_manager_destroy(lauriane);
|
||||
|
||||
//BC_ASSERT_STRING_EQUAL(linphone_proxy_config_get(proxy), "sip:sip.linphone.org;transport=tls");
|
||||
|
||||
}
|
||||
|
||||
test_t proxy_config_tests[] = {
|
||||
TEST_NO_TAG("Phone normalization without proxy", phone_normalization_without_proxy),
|
||||
TEST_NO_TAG("Phone normalization with proxy", phone_normalization_with_proxy),
|
||||
TEST_NO_TAG("Phone normalization with dial escape plus", phone_normalization_with_dial_escape_plus),
|
||||
TEST_NO_TAG("SIP URI normalization", sip_uri_normalization),
|
||||
//TEST_NO_TAG("Load new default value for proxy config", load_dynamic_proxy_config)
|
||||
TEST_NO_TAG("Load new default value for proxy config", load_dynamic_proxy_config)
|
||||
};
|
||||
|
||||
test_suite_t proxy_config_test_suite = {"Proxy config", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue