Commit 5cf68816 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Unescape characters if possible in linphone_core_interpret_url()

parent 7079e79c
......@@ -3977,17 +3977,19 @@ void linphone_core_iterate(LinphoneCore *lc){
}
}
LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url){
LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url) {
if (!url) return NULL;
LinphoneProxyConfig *proxy = linphone_core_get_default_proxy_config(lc);
LinphoneAddress *result=NULL;
LinphoneAddress *result = NULL;
if (linphone_proxy_config_is_phone_number(proxy,url)) {
char *normalized_number = linphone_proxy_config_normalize_phone_number(proxy, url);
char *normalized_number = linphone_proxy_config_normalize_phone_number(proxy, url);
if (normalized_number) {
result = linphone_proxy_config_normalize_sip_uri(proxy, normalized_number);
ms_free(normalized_number);
} else {
result = linphone_proxy_config_normalize_sip_uri(proxy, url);
}
return result;
}
......
......@@ -701,37 +701,47 @@ const char *linphone_proxy_config_get_quality_reporting_collector(const Linphone
bool_t linphone_proxy_config_is_phone_number(LinphoneProxyConfig *proxy, const char *username){
const char *p;
if (!username) return FALSE;
for(p=username;*p!='\0';++p){
const char *p;
char* unescaped_username = belle_sip_username_unescape_unnecessary_characters(username);
for (p = unescaped_username; *p != '\0'; ++p) {
if (isdigit(*p) ||
*p==' ' ||
*p=='.' ||
*p=='-' ||
*p==')' ||
*p=='(' ||
*p=='/' ||
*p=='+' ||
(unsigned char)*p==0xca || (unsigned char)*p==0xc2 || (unsigned char)*p==0xa0 // non-breakable space (iOS uses it to format contacts phone number)
) {
*p==' ' ||
*p=='.' ||
*p=='-' ||
*p==')' ||
*p=='(' ||
*p=='/' ||
*p=='+' ||
// non-breakable space (iOS uses it to format contacts phone number)
(unsigned char)*p == 0xca || (unsigned char)*p == 0xc2 || (unsigned char)*p == 0xa0) {
continue;
}
belle_sip_free(unescaped_username);
return FALSE;
}
belle_sip_free(unescaped_username);
return TRUE;
}
//remove anything but [0-9] and +
static char *linphone_proxy_config_flatten_phone_number(LinphoneProxyConfig *proxy, const char *number) {
char *result=reinterpret_cast<char *>(ms_malloc0(strlen(number)+1));
char *w=result;
char *unescaped_phone_number = belle_sip_username_unescape_unnecessary_characters(number);
char *result = reinterpret_cast<char *>(ms_malloc0(strlen(unescaped_phone_number) + 1));
char *w = result;
const char *r;
for(r=number;*r!='\0';++r){
if (*r=='+' || isdigit(*r)){
*w++=*r;
for (r = unescaped_phone_number; *r != '\0'; ++r) {
if (*r == '+' || isdigit(*r)) {
*w++ = *r;
}
}
*w++='\0';
*w++ = '\0';
belle_sip_free(unescaped_phone_number);
return result;
}
......@@ -876,7 +886,10 @@ LinphoneAddress* linphone_proxy_config_normalize_sip_uri(LinphoneProxyConfig *pr
} else {
linphone_address_clean(uri);
linphone_address_set_display_name(uri,NULL);
linphone_address_set_username(uri,username);
// Unescape character if possible
char *unescaped_username = belle_sip_username_unescape_unnecessary_characters(username);
linphone_address_set_username(uri,unescaped_username);
belle_sip_free(unescaped_username);
return _linphone_core_destroy_addr_if_not_sip(uri);
}
} else {
......
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