diff --git a/coreapi/address.c b/coreapi/address.c index 764a8fb24..d9d772337 100644 --- a/coreapi/address.c +++ b/coreapi/address.c @@ -159,6 +159,13 @@ bool_t linphone_address_is_secure(const LinphoneAddress *uri){ return sal_address_is_secure(uri); } +/** + * returns true if address is a routable sip address + */ +bool_t linphone_address_is_sip(const LinphoneAddress *uri){ + return sal_address_is_sip(uri); +} + static bool_t strings_equals(const char *s1, const char *s2){ if (s1==NULL && s2==NULL) return TRUE; if (s1!=NULL && s2!=NULL && strcmp(s1,s2)==0) return TRUE; diff --git a/coreapi/bellesip_sal/sal_address_impl.c b/coreapi/bellesip_sal/sal_address_impl.c index c4ff234d7..18e7dc84b 100644 --- a/coreapi/bellesip_sal/sal_address_impl.c +++ b/coreapi/bellesip_sal/sal_address_impl.c @@ -151,6 +151,11 @@ char *sal_address_as_string(const SalAddress *addr){ return ms_strdup(tmp); } +bool_t sal_address_is_sip(const SalAddress *addr){ + belle_sip_header_address_t* header_addr = BELLE_SIP_HEADER_ADDRESS(addr); + return belle_sip_header_address_get_uri(header_addr) != NULL; +} + char *sal_address_as_string_uri_only(const SalAddress *addr){ belle_sip_header_address_t* header_addr = BELLE_SIP_HEADER_ADDRESS(addr); belle_sip_uri_t* sip_uri = belle_sip_header_address_get_uri(header_addr); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 8205d5f09..ef4133d87 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2625,6 +2625,15 @@ void linphone_core_iterate(LinphoneCore *lc){ } } +static LinphoneAddress* _linphone_core_destroy_addr_if_not_sip( LinphoneAddress* addr ){ + if( linphone_address_is_sip(addr) ) { + return addr; + } else { + linphone_address_destroy(addr); + return NULL; + } +} + /** * Interpret a call destination as supplied by the user, and returns a fully qualified * LinphoneAddress. @@ -2661,7 +2670,7 @@ LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url) tmpurl=enumres->sip_address[0]; uri=linphone_address_new(tmpurl); enum_lookup_res_free(enumres); - return uri; + return _linphone_core_destroy_addr_if_not_sip(uri); } /* check if we have a "sip:" or a "sips:" */ if ( (strstr(url,"sip:")==NULL) && (strstr(url,"sips:")==NULL) ){ @@ -2672,7 +2681,7 @@ LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url) uri=linphone_address_new(tmpurl); ms_free(tmpurl); if (uri){ - return uri; + return _linphone_core_destroy_addr_if_not_sip(uri); } } @@ -2688,12 +2697,12 @@ LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url) linphone_proxy_config_normalize_number(proxy,url,normalized_username, sizeof(normalized_username)); linphone_address_set_username(uri,normalized_username); - return uri; + return _linphone_core_destroy_addr_if_not_sip(uri); }else return NULL; } uri=linphone_address_new(url); if (uri!=NULL){ - return uri; + return _linphone_core_destroy_addr_if_not_sip(uri); } return NULL; diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 8ff6cb69d..c8a259f25 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -397,6 +397,7 @@ LINPHONE_PUBLIC void linphone_address_set_port(LinphoneAddress *uri, int port); /*remove tags, params etc... so that it is displayable to the user*/ LINPHONE_PUBLIC void linphone_address_clean(LinphoneAddress *uri); LINPHONE_PUBLIC bool_t linphone_address_is_secure(const LinphoneAddress *uri); +LINPHONE_PUBLIC bool_t linphone_address_is_sip(const LinphoneAddress *uri); LINPHONE_PUBLIC LinphoneTransportType linphone_address_get_transport(const LinphoneAddress *uri); LINPHONE_PUBLIC void linphone_address_set_transport(LinphoneAddress *uri,LinphoneTransportType type); LINPHONE_PUBLIC char *linphone_address_as_string(const LinphoneAddress *u); diff --git a/include/sal/sal.h b/include/sal/sal.h index 040ab9951..39085074f 100644 --- a/include/sal/sal.h +++ b/include/sal/sal.h @@ -110,6 +110,7 @@ void sal_address_set_transport_name(SalAddress* addr,const char* transport); void sal_address_set_params(SalAddress *addr, const char *params); void sal_address_set_uri_params(SalAddress *addr, const char *params); bool_t sal_address_is_ipv6(SalAddress *addr); +bool_t sal_address_is_sip(const SalAddress *addr); void sal_address_set_password(SalAddress *addr, const char *passwd); const char *sal_address_get_password(const SalAddress *addr); void sal_address_set_header(SalAddress *addr, const char *header_name, const char *header_value);