From 9b0c21cc233f85b79364acdd9762536f50b2be92 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 13 Mar 2018 15:03:20 +0100 Subject: [PATCH] Fixed multi routes crash --- coreapi/proxy.c | 37 ++++++++++++++++++++++++++++++--- include/linphone/proxy_config.h | 10 +++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/coreapi/proxy.c b/coreapi/proxy.c index dad8307e5..067b95790 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -353,9 +353,9 @@ const char *linphone_proxy_config_get_domain(const LinphoneProxyConfig *cfg){ LinphoneStatus linphone_proxy_config_set_route(LinphoneProxyConfig *cfg, const char *route) { - if (cfg->reg_routes!=NULL){ + if (cfg->reg_routes != NULL) { bctbx_list_free_with_data(cfg->reg_routes, ms_free); - cfg->reg_routes=NULL; + cfg->reg_routes = NULL; } if (route!=NULL && route[0] !='\0'){ SalAddress *addr; @@ -378,6 +378,37 @@ LinphoneStatus linphone_proxy_config_set_route(LinphoneProxyConfig *cfg, const c } } +LinphoneStatus linphone_proxy_config_set_routes(LinphoneProxyConfig *cfg, const bctbx_list_t *routes) { + if (cfg->reg_routes != NULL) { + bctbx_list_free_with_data(cfg->reg_routes, ms_free); + cfg->reg_routes = NULL; + } + bctbx_list_t *iterator = (bctbx_list_t *)routes; + while (iterator != NULL) { + char *route = (char *)bctbx_list_get_data(iterator); + if (route != NULL && route[0] !='\0') { + SalAddress *addr; + char *tmp; + /*try to prepend 'sip:' */ + if (strstr(route,"sip:") == NULL && strstr(route,"sips:") == NULL) { + tmp = ms_strdup_printf("sip:%s",route); + } else { + tmp = ms_strdup(route); + } + addr = sal_address_new(tmp); + if (addr != NULL) { + sal_address_destroy(addr); + cfg->reg_routes = bctbx_list_append(cfg->reg_routes, tmp); + } else { + ms_free(tmp); + return -1; + } + } + iterator = bctbx_list_next(iterator); + } + return 0; +} + bool_t linphone_proxy_config_check(LinphoneCore *lc, LinphoneProxyConfig *cfg){ if (cfg->reg_proxy==NULL) return FALSE; @@ -1197,7 +1228,7 @@ LinphoneProxyConfig *linphone_proxy_config_new_from_config_file(LinphoneCore* lc CONFIGURE_STRING_VALUE(cfg,config,key,identity,"reg_identity") CONFIGURE_STRING_VALUE(cfg,config,key,server_addr,"reg_proxy") - cfg->reg_routes = linphone_config_get_string_list(config, key, "reg_route", NULL); + linphone_proxy_config_set_routes(cfg, linphone_config_get_string_list(config, key, "reg_route", NULL)); CONFIGURE_STRING_VALUE(cfg,config,key,realm,"realm") diff --git a/include/linphone/proxy_config.h b/include/linphone/proxy_config.h index 13ef5d294..edaa9d8c8 100644 --- a/include/linphone/proxy_config.h +++ b/include/linphone/proxy_config.h @@ -99,6 +99,16 @@ LINPHONE_PUBLIC LinphoneStatus linphone_proxy_config_set_identity_address(Linpho **/ LINPHONE_PUBLIC LinphoneStatus linphone_proxy_config_set_route(LinphoneProxyConfig *cfg, const char *route); +/** + * Sets a list of SIP route. + * When a route is set, all outgoing calls will go to the route's destination if this proxy + * is the default one (see linphone_core_set_default_proxy() ). + * @param[in] cfg the #LinphoneProxyConfig + * @param[in] routes A \bctbx_list{const char *} of routes + * @return -1 if routes are invalid, 0 otherwise. +**/ +LINPHONE_PUBLIC LinphoneStatus linphone_proxy_config_set_routes(LinphoneProxyConfig *cfg, const bctbx_list_t *routes); + /** * Sets the registration expiration time in seconds. **/