Commit 330a4ca9 authored by Simon Morlat's avatar Simon Morlat
Browse files

implement replacing of international calling prefix by +, so that number get really normalized.

parent ebb81498
......@@ -510,7 +510,7 @@ void linphone_proxy_config_refresh_register(LinphoneProxyConfig *obj){
/**
* Sets a dialing prefix to be automatically prepended when inviting a number with
* linphone_core_invite();
* This dialing prefix shall usually be the country code of the country where the user is living.
* This dialing prefix shall usually be the country code of the country where the user is living, without "+".
*
**/
void linphone_proxy_config_set_dial_prefix(LinphoneProxyConfig *cfg, const char *prefix){
......@@ -917,7 +917,7 @@ static void replace_plus(const char *src, char *dest, size_t destlen, const char
if (icp && src[0]=='+' && (destlen>(i=strlen(icp))) ){
src++;
strcpy(dest,icp);
strncpy(dest, icp, destlen);
}
for(;(i<destlen-1) && *src!='\0';++i){
......@@ -927,8 +927,18 @@ static void replace_plus(const char *src, char *dest, size_t destlen, const char
dest[i]='\0';
}
static void replace_icp(const char *src, char *dest, size_t destlen, const char *icp){
int i=0;
if (strstr(src, icp) == src){
dest[0]='+';
i++;
}
strncpy(dest+i, src+strlen(icp), destlen-i-1);
}
bool_t linphone_proxy_config_normalize_number(LinphoneProxyConfig *proxy, const char *username, char *result, size_t result_len){
memset(result, 0, result_len);
if (linphone_proxy_config_is_phone_number(proxy, username)){
char *flatten;
flatten=flatten_number(username);
......@@ -936,18 +946,21 @@ bool_t linphone_proxy_config_normalize_number(LinphoneProxyConfig *proxy, const
if (proxy->dial_prefix==NULL || proxy->dial_prefix[0]=='\0'){
/*no prefix configured, nothing else to do*/
strncpy(result,flatten,result_len);
ms_free(flatten);
strncpy(result,flatten,result_len-1);
}else{
dial_plan_t dialplan;
lookup_dial_plan(proxy->dial_prefix,&dialplan);
ms_debug("Using dialplan '%s'",dialplan.country);
if (flatten[0]=='+' || strstr(flatten,dialplan.icp)==flatten){
if (flatten[0]=='+'){
/* the number has international prefix or +, so nothing to do*/
ms_debug("Prefix already present.");
/*eventually replace the plus*/
/*eventually replace the plus by the international calling prefix of the country*/
replace_plus(flatten,result,result_len,proxy->dial_escape_plus ? dialplan.icp : NULL);
ms_free(flatten);
}else if (strstr(flatten,dialplan.icp)==flatten){
if (!proxy->dial_escape_plus)
replace_icp(flatten, result, result_len, dialplan.icp);
else
strncpy(result, flatten, result_len-1);
}else{
int numlen;
int i=0;
......@@ -956,7 +969,7 @@ bool_t linphone_proxy_config_normalize_number(LinphoneProxyConfig *proxy, const
/*keep at most national number significant digits */
skip=numlen-dialplan.nnl;
if (skip<0) skip=0;
/*first prepend internation calling prefix or +*/
/*first prepend international calling prefix or +*/
if (proxy->dial_escape_plus){
strncpy(result,dialplan.icp,result_len);
i+=strlen(dialplan.icp);
......@@ -971,12 +984,12 @@ bool_t linphone_proxy_config_normalize_number(LinphoneProxyConfig *proxy, const
}
/*add user digits */
strncpy(result+i,flatten+skip,result_len-i-1);
ms_free(flatten);
}
}
ms_free(flatten);
return TRUE;
} else {
strncpy(result,username,result_len);
strncpy(result,username,result_len-1);
return FALSE;
}
}
......
mediastreamer2 @ a56f04bf
Subproject commit 751080a93527a38f9ef0a89d7bd5939a6c461976
Subproject commit a56f04bfa4619186ba51ac8d3d2d73c942ee4fcf
......@@ -391,9 +391,11 @@ void simple_call_base(bool_t enable_multicast_recv_side) {
belle_sip_object_dump_active_objects();
}
}
static void simple_call() {
simple_call_base(FALSE);
}
static void call_with_timeouted_bye(void) {
int begin;
int leaked_objects;
......@@ -436,6 +438,38 @@ static void call_with_timeouted_bye(void) {
}
}
static void phone_number_normalization(void){
LinphoneCoreManager *marie = linphone_core_manager_new( "marie_rc");
LinphoneProxyConfig *cfg = linphone_core_create_proxy_config(marie->lc);
char result[128];
linphone_proxy_config_set_dial_prefix(cfg, "33");
linphone_proxy_config_normalize_number(cfg, "0952636505", result, sizeof(result));
CU_ASSERT_STRING_EQUAL(result, "+33952636505");
linphone_proxy_config_normalize_number(cfg, "09 52 63 65 05", result, sizeof(result));
CU_ASSERT_STRING_EQUAL(result, "+33952636505");
linphone_proxy_config_normalize_number(cfg, "09-52-63-65-05", result, sizeof(result));
CU_ASSERT_STRING_EQUAL(result, "+33952636505");
linphone_proxy_config_normalize_number(cfg, "+31952636505", result, sizeof(result));
CU_ASSERT_STRING_EQUAL(result, "+31952636505");
linphone_proxy_config_normalize_number(cfg, "0033952636505", result, sizeof(result));
CU_ASSERT_STRING_EQUAL(result, "+33952636505");
linphone_proxy_config_normalize_number(cfg, "0033952636505", result, sizeof(result));
CU_ASSERT_STRING_EQUAL(result, "+33952636505");
linphone_proxy_config_normalize_number(cfg, "toto", result, sizeof(result));
CU_ASSERT_STRING_EQUAL(result, "toto");
linphone_proxy_config_set_dial_escape_plus(cfg, TRUE);
linphone_proxy_config_normalize_number(cfg, "0033952636505", result, sizeof(result));
CU_ASSERT_STRING_EQUAL(result, "0033952636505");
linphone_proxy_config_normalize_number(cfg, "0952636505", result, sizeof(result));
CU_ASSERT_STRING_EQUAL(result, "0033952636505");
linphone_proxy_config_normalize_number(cfg, "+34952636505", result, sizeof(result));
CU_ASSERT_STRING_EQUAL(result, "0034952636505");
linphone_proxy_config_unref(cfg);
linphone_core_manager_destroy(marie);
}
static void direct_call_over_ipv6(){
LinphoneCoreManager* marie;
......@@ -3469,6 +3503,7 @@ static void unsucessfull_call_with_transport_change_after_released(void) {
}
test_t call_tests[] = {
{ "Phone number normalization", phone_number_normalization },
{ "Early declined call", early_declined_call },
{ "Call declined", call_declined },
{ "Cancelled call", cancelled_call },
......
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