mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-28 16:49:20 +00:00
fix flatten_number to remove trunk number from e164 number. ex +33 (0) 2222 becomes +332222
This commit is contained in:
parent
a6e7eec3b3
commit
e6032177a8
1 changed files with 24 additions and 10 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue