From e6032177a82a4c0c8c8f88b60d42a7e7e5c56e33 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Wed, 14 Sep 2016 12:08:04 +0200 Subject: [PATCH] fix flatten_number to remove trunk number from e164 number. ex +33 (0) 2222 becomes +332222 --- coreapi/proxy.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/coreapi/proxy.c b/coreapi/proxy.c index 8ae879f63..d04a6fdf8 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -592,8 +592,19 @@ static char *flatten_number(const char *number){ char *result=ms_malloc0(strlen(number)+1); char *w=result; const char *r; + bool_t removing_trunk_prefix = FALSE; for(r=number;*r!='\0';++r){ - if (*r=='+' || isdigit(*r)){ + if (result[0] == '+') { + /*e164 case*/ + if (*r=='(') { + /*start removing trunk prefix as we are in form +33 (0) 6 222222*/ + removing_trunk_prefix=TRUE; + } else if (*r==')') { + /*stop removing trunk prefix*/ + removing_trunk_prefix=FALSE; + } + } + if (removing_trunk_prefix == FALSE && (*r=='+' || isdigit(*r))){ *w++=*r; } } @@ -623,37 +634,40 @@ char* linphone_proxy_config_normalize_phone_number(LinphoneProxyConfig *proxy, c char* result = NULL; if (linphone_proxy_config_is_phone_number(tmpproxy, username)){ char * flatten=flatten_number(username); - const LinphoneDialPlan *dialplan = linphone_dial_plan_by_ccc(tmpproxy->dial_prefix); + LinphoneDialPlan dialplan = *linphone_dial_plan_by_ccc(tmpproxy->dial_prefix); //copy dial plan ms_debug("Flattened number is '%s' for '%s'",flatten, username); - + if (strcmp(tmpproxy->dial_prefix,dialplan.ccc)!=0){ + //probably generic dialplan, preserving proxy dial prefix + strcpy(dialplan.ccc,tmpproxy->dial_prefix); + } /*if proxy has a dial prefix, modify phonenumber accordingly*/ if (tmpproxy->dial_prefix!=NULL && tmpproxy->dial_prefix[0]!='\0'){ ms_debug("Using dial plan '%s'",dialplan->country); /* the number already starts with + or international prefix*/ - if (flatten[0]=='+'||strstr(flatten,dialplan->icp)==flatten){ + if (flatten[0]=='+'||strstr(flatten,dialplan.icp)==flatten){ ms_debug("Prefix already present."); if (tmpproxy->dial_escape_plus) { - result = replace_plus_with_icp(flatten,dialplan->icp); + result = replace_plus_with_icp(flatten,dialplan.icp); } else { - result = replace_icp_with_plus(flatten,dialplan->icp); + result = replace_icp_with_plus(flatten,dialplan.icp); } }else{ /*0. keep at most national number significant digits */ - char* flatten_start = flatten + MAX(0, (int)strlen(flatten) - (int)dialplan->nnl); + char* flatten_start = flatten + MAX(0, (int)strlen(flatten) - (int)dialplan.nnl); ms_debug("Prefix not present. Keeping at most %d digits: %s", dialplan->nnl, flatten_start); /*1. First prepend international calling prefix or +*/ /*2. Second add prefix*/ /*3. Finally add user digits */ result = ms_strdup_printf("%s%s%s" - , tmpproxy->dial_escape_plus ? dialplan->icp : "+" - , dialplan->ccc + , tmpproxy->dial_escape_plus ? dialplan.icp : "+" + , dialplan.ccc , flatten_start); ms_debug("Prepended prefix resulted in %s", result); } }else if (tmpproxy->dial_escape_plus){ /* user did not provide dial prefix, so we'll take the most generic one */ - result = replace_plus_with_icp(flatten,dialplan->icp); + result = replace_plus_with_icp(flatten,dialplan.icp); } if (result==NULL) { result = flatten;