diff --git a/coreapi/address.c b/coreapi/address.c index 1d893aede..4d4b1d2d6 100644 --- a/coreapi/address.c +++ b/coreapi/address.c @@ -136,5 +136,11 @@ void linphone_address_destroy(LinphoneAddress *u){ sal_address_destroy(u); } +int linphone_address_get_port_int(const LinphoneAddress *u) { + return sal_address_get_port_int(u); +} +const char* linphone_address_get_port(const LinphoneAddress *u) { + return sal_address_get_port(u); +} /** @} */ diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 8f86188ba..a68acd244 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -646,9 +646,16 @@ static void sip_config_read(LinphoneCore *lc) } linphone_core_enable_ipv6(lc,ipv6); memset(&tr,0,sizeof(tr)); - tr.udp_port=lp_config_get_int(lc->config,"sip","sip_port",5060); - tr.tcp_port=lp_config_get_int(lc->config,"sip","sip_tcp_port",0); - + if (lp_config_get_int(lc->config,"sip","sip_random_port",0)) { + tr.udp_port=(0xDFF&+random())+1024; + } else { + tr.udp_port=lp_config_get_int(lc->config,"sip","sip_port",5060); + } + if (lp_config_get_int(lc->config,"sip","sip_tcp_random_port",0)) { + tr.tcp_port=(0xDFF&+random())+1024; + } else { + tr.tcp_port=lp_config_get_int(lc->config,"sip","sip_tcp_port",0); + } /*start listening on ports*/ linphone_core_set_sip_transports(lc,&tr); @@ -1553,7 +1560,7 @@ int linphone_core_set_sip_transports(LinphoneCore *lc, const LCSipTransports * t * is not used. * @ingroup network_parameters **/ -int linphone_core_get_sip_transport(LinphoneCore *lc, LCSipTransports *tr){ +int linphone_core_get_sip_transports(LinphoneCore *lc, LCSipTransports *tr){ memcpy(tr,&lc->sip_conf.transports,sizeof(*tr)); return 0; } @@ -1639,6 +1646,16 @@ static void monitor_network_state(LinphoneCore *lc, time_t curtime){ static void proxy_update(LinphoneCore *lc){ ms_list_for_each(lc->sip_conf.proxies,(void (*)(void*))&linphone_proxy_config_update); + MSList* list=ms_list_copy(lc->sip_conf.deleted_proxies); + for(;list!=NULL;list=list->next){ + LinphoneProxyConfig* cfg = (LinphoneProxyConfig*) list->data; + if (ms_time(NULL) - cfg->deletion_date > 5) { + lc->sip_conf.deleted_proxies =ms_list_remove(lc->sip_conf.deleted_proxies,(void *)cfg); + ms_message("clearing proxy config for [%s]",linphone_proxy_config_get_addr(cfg)); + linphone_proxy_config_destroy(cfg); + } + } + ms_list_free(list); } static void assign_buddy_info(LinphoneCore *lc, BuddyInfo *info){ diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 34a3483ea..b780956ff 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -75,6 +75,15 @@ const char *linphone_address_get_scheme(const LinphoneAddress *u); const char *linphone_address_get_display_name(const LinphoneAddress* u); const char *linphone_address_get_username(const LinphoneAddress *u); const char *linphone_address_get_domain(const LinphoneAddress *u); +/** + * Get port number as an integer value. + * + */ +int linphone_address_get_port_int(const LinphoneAddress *u); +/** + * Get port number, null if not present. + */ +const char* linphone_address_get_port(const LinphoneAddress *u); void linphone_address_set_display_name(LinphoneAddress *u, const char *display_name); void linphone_address_set_username(LinphoneAddress *uri, const char *username); void linphone_address_set_domain(LinphoneAddress *uri, const char *host); diff --git a/coreapi/private.h b/coreapi/private.h index cd3abd3c9..43f4e0f08 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -207,6 +207,7 @@ struct _LinphoneProxyConfig bool_t publish; bool_t dial_escape_plus; void* user_data; + time_t deletion_date; }; struct _LinphoneAuthInfo diff --git a/coreapi/proxy.c b/coreapi/proxy.c index 80eb5d522..59d767303 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -22,6 +22,7 @@ Copyright (C) 2000 Simon MORLAT (simon.morlat@linphone.org) #include "sipsetup.h" #include "lpconfig.h" #include "private.h" +#include "mediastreamer2/mediastream.h" #include @@ -244,7 +245,13 @@ static char *guess_contact_for_register(LinphoneProxyConfig *obj){ contact=linphone_address_new(obj->reg_identity); linphone_address_set_domain (contact,localip); linphone_address_set_port_int(contact,linphone_core_get_sip_port(obj->lc)); - ret=linphone_address_as_string_uri_only (contact); + linphone_address_set_display_name(contact,NULL); + LCSipTransports tr; + linphone_core_get_sip_transports(obj->lc,&tr); + if (tr.udp_port <= 0 && tr.tcp_port>0) { + sal_address_add_param(contact,"transport","tcp"); + } + ret=linphone_address_as_string(contact); linphone_address_destroy(contact); } linphone_address_destroy (proxy); @@ -499,6 +506,7 @@ void linphone_core_remove_proxy_config(LinphoneCore *lc, LinphoneProxyConfig *cf lc->sip_conf.proxies=ms_list_remove(lc->sip_conf.proxies,(void *)cfg); /* add to the list of destroyed proxies, so that the possible unREGISTER request can succeed authentication */ lc->sip_conf.deleted_proxies=ms_list_append(lc->sip_conf.deleted_proxies,(void *)cfg); + cfg->deletion_date=ms_time(NULL); /* this will unREGISTER */ linphone_proxy_config_edit(cfg); if (lc->default_proxy==cfg){ @@ -787,3 +795,4 @@ void * linphone_proxy_config_get_user_data(LinphoneProxyConfig *cr) { + diff --git a/coreapi/sal.h b/coreapi/sal.h index 9790b8c71..d8d02edd9 100644 --- a/coreapi/sal.h +++ b/coreapi/sal.h @@ -48,6 +48,9 @@ const char *sal_address_get_display_name(const SalAddress* addr); char *sal_address_get_display_name_unquoted(const SalAddress *addr); const char *sal_address_get_username(const SalAddress *addr); const char *sal_address_get_domain(const SalAddress *addr); +const char * sal_address_get_port(const SalAddress *addr); +int sal_address_get_port_int(const SalAddress *uri); + void sal_address_set_display_name(SalAddress *addr, const char *display_name); void sal_address_set_username(SalAddress *addr, const char *username); void sal_address_set_domain(SalAddress *addr, const char *host); @@ -57,7 +60,7 @@ void sal_address_clean(SalAddress *addr); char *sal_address_as_string(const SalAddress *u); char *sal_address_as_string_uri_only(const SalAddress *u); void sal_address_destroy(SalAddress *u); - +void sal_address_add_param(SalAddress *u,const char* name,const char* value); diff --git a/coreapi/sal_eXosip2.c b/coreapi/sal_eXosip2.c index fa6fb5f11..bd3e7e664 100644 --- a/coreapi/sal_eXosip2.c +++ b/coreapi/sal_eXosip2.c @@ -1749,6 +1749,9 @@ char *sal_address_as_string_uri_only(const SalAddress *u){ osip_free(tmp); return ret; } +void sal_address_add_param(SalAddress *u,const char* name,const char* value) { + osip_uri_uparam_add (((osip_from_t*)u)->url,ms_strdup(name),ms_strdup(value)); +} void sal_address_destroy(SalAddress *u){ osip_from_free((osip_from_t*)u); @@ -1758,4 +1761,16 @@ void sal_set_keepalive_period(Sal *ctx,unsigned int value) { ctx->keepalive_period=value; eXosip_set_option (EXOSIP_OPT_UDP_KEEP_ALIVE, &value); } +const char * sal_address_get_port(const SalAddress *addr) { + const osip_from_t *u=(const osip_from_t*)addr; + return null_if_empty(u->url->port); +} +int sal_address_get_port_int(const SalAddress *uri) { + const char* port = sal_address_get_port(uri); + if (port != NULL) { + return atoi(port); + } else { + return 5060; + } +} diff --git a/java/common/org/linphone/core/LinphoneCoreFactory.java b/java/common/org/linphone/core/LinphoneCoreFactory.java index cd34cfe36..b3e2952fb 100644 --- a/java/common/org/linphone/core/LinphoneCoreFactory.java +++ b/java/common/org/linphone/core/LinphoneCoreFactory.java @@ -61,5 +61,5 @@ abstract public class LinphoneCoreFactory { */ abstract public void setDebugMode(boolean enable); - //abstract public void setLogHandler(LinphoneLogHandler handler); + abstract public void setLogHandler(LinphoneLogHandler handler); }