Commit 6b134f5a authored by Gautier Pelloux-Prayer's avatar Gautier Pelloux-Prayer
Browse files

proxy config: add tests for phone number normalization and fix API accordingly

parent 89e547fa
......@@ -868,17 +868,18 @@ int linphone_dial_plan_lookup_ccc_from_iso(const char* iso) {
return -1;
}
static void lookup_dial_plan(const char *ccc, dial_plan_t *plan){
static bool_t lookup_dial_plan_by_ccc(const char *ccc, dial_plan_t *plan){
int i;
for(i=0;dial_plans[i].country!=NULL;++i){
if (strcmp(ccc,dial_plans[i].ccc)==0){
*plan=dial_plans[i];
return;
return TRUE;
}
}
/*else return a generic "most common" dial plan*/
*plan=most_common_dialplan;
strcpy(plan->ccc,ccc);
return FALSE;
}
bool_t linphone_proxy_config_is_phone_number(LinphoneProxyConfig *proxy, const char *username){
......@@ -900,6 +901,7 @@ bool_t linphone_proxy_config_is_phone_number(LinphoneProxyConfig *proxy, const c
return TRUE;
}
//remove anything but [0-9] and +
static char *flatten_number(const char *number){
char *result=ms_malloc0(strlen(number)+1);
char *w=result;
......@@ -913,7 +915,7 @@ static char *flatten_number(const char *number){
return result;
}
static void replace_plus(const char *src, char *dest, size_t destlen, const char *icp){
static void replace_plus_with_icp(const char *src, char *dest, size_t destlen, const char *icp){
int i=0;
if (icp && src[0]=='+' && (destlen>(i=strlen(icp))) ){
......@@ -928,7 +930,7 @@ 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){
static void replace_icp_with_plus(const char *src, char *dest, size_t destlen, const char *icp){
int i=0;
if (strstr(src, icp) == src){
dest[0]='+';
......@@ -943,26 +945,35 @@ bool_t linphone_proxy_config_normalize_number(LinphoneProxyConfig *inproxy, cons
LinphoneProxyConfig *proxy = inproxy ? inproxy : linphone_proxy_config_new();
memset(result, 0, result_len);
if (linphone_proxy_config_is_phone_number(proxy, username)){
dial_plan_t dialplan = {0};
char *flatten=flatten_number(username);
bool_t dialplan_found = FALSE;
ms_debug("Flattened number is '%s'",flatten);
/*username does not contain a dial prefix nor the proxy, nothing else to do*/
if (proxy->dial_prefix==NULL || proxy->dial_prefix[0]=='\0'){
/*no prefix configured, nothing else to do*/
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);
} else {
dialplan_found = lookup_dial_plan_by_ccc(proxy->dial_prefix,&dialplan);
}
if (dialplan_found) {
ms_debug("Using dial plan '%s'",dialplan.country);
/* the number has international prefix or +, so nothing to do*/
if (flatten[0]=='+'){
/* the number has international prefix or +, so nothing to do*/
ms_debug("Prefix already present.");
/*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);
if (proxy->dial_escape_plus) {
replace_plus_with_icp(flatten,result,result_len,dialplan.icp);
}else{
strncpy(result, flatten, result_len-1);
}
}else if (strstr(flatten,dialplan.icp)==flatten){
if (!proxy->dial_escape_plus)
replace_icp(flatten, result, result_len, dialplan.icp);
else
if (proxy->dial_escape_plus){
strncpy(result, flatten, result_len-1);
}else{
replace_icp_with_plus(flatten, result, result_len, dialplan.icp);
}
}else{
int numlen;
int i=0;
......
......@@ -25,32 +25,7 @@ if(WIN32)
endif()
find_package(GTK2 2.18 COMPONENTS gtk)
set(SOURCE_FILES
common/bc_tester_utils.c
common/bc_tester_utils.h
accountmanager.c
call_tester.c
dtmf_tester.c
eventapi_tester.c
flexisip_tester.c
liblinphone_tester.c
log_collection_tester.c
message_tester.c
multi_call.c
multicast_call_tester.c
offeranswer_tester.c
player_tester.c
presence_tester.c
quality_reporting_tester.c
register_tester.c
remote_provisioning_tester.c
setup_tester.c
stun_tester.c
tester.c
tunnel_tester.c
upnp_tester.c
video_tester.c
)
file (GLOB_RECURSE SOURCE_FILES *.c)
add_definitions(-DBC_CONFIG_FILE="config.h")
......
......@@ -18,11 +18,12 @@ liblinphonetester_la_SOURCES = \
flexisip_tester.c \
log_collection_tester.c \
message_tester.c \
multi_call.c \
multi_call_tester.c \
multicast_call_tester.c \
offeranswer_tester.c \
player_tester.c \
presence_tester.c \
proxy_config_tester.c \
quality_reporting_tester.c \
register_tester.c \
remote_provisioning_tester.c \
......
......@@ -51,7 +51,7 @@ extern test_suite_t offeranswer_test_suite;
extern test_suite_t video_test_suite;
extern test_suite_t multicast_call_test_suite;
extern test_suite_t multi_call_test_suite;
extern test_suite_t proxy_config_test_suite;
extern int liblinphone_tester_ipv6_available(void);
......
/*
liblinphone_tester - liblinphone test suite
Copyright (C) 2013 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "liblinphone_tester.h"
const char* phone_normalization(LinphoneProxyConfig *proxy, const char* in) {
const size_t RESULTLENGTH = 255;
static char result[RESULTLENGTH];
linphone_proxy_config_normalize_number(proxy, in, result, RESULTLENGTH-1);
return result;
}
static void phone_normalization_without_proxy() {
BC_ASSERT_STRING_EQUAL(phone_normalization(NULL, "012 345 6789"), "0123456789");
BC_ASSERT_STRING_EQUAL(phone_normalization(NULL, "+33123456789"), "+33123456789");
BC_ASSERT_STRING_EQUAL(phone_normalization(NULL, "+33012345678"), "+33012345678");
BC_ASSERT_STRING_EQUAL(phone_normalization(NULL, "+33 0012345678"), "+330012345678");
BC_ASSERT_STRING_EQUAL(phone_normalization(NULL, "+33012345678"), "+33012345678");
BC_ASSERT_STRING_EQUAL(phone_normalization(NULL, "+3301234567891"), "+3301234567891");
BC_ASSERT_STRING_EQUAL(phone_normalization(NULL, "+33 01234567891"), "+3301234567891");
BC_ASSERT_STRING_EQUAL(phone_normalization(NULL, "I_AM_NOT_A_NUMBER"), "I_AM_NOT_A_NUMBER"); // invalid phone number
}
static void phone_normalization_with_proxy() {
LinphoneProxyConfig *proxy = linphone_proxy_config_new();
linphone_proxy_config_set_dial_prefix(proxy, "33");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "012 3456 789"), "+33123456789");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+33123456789"), "+33123456789");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+33 0123456789"), "+330123456789");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+330012345678"), "+330012345678");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+3301 2345678"), "+33012345678");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+3301234567891"), "+3301234567891");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "123456789"), "+33123456789");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, " 0123456789"), "+33123456789");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0012345678"), "+12345678");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "01 2345678"), "+33012345678");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "01234567891"), "+33234567891"); // invalid phone number (too long)
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "I_AM_NOT_A_NUMBER"), "I_AM_NOT_A_NUMBER"); // invalid phone number
linphone_proxy_config_destroy(proxy);
}
test_t proxy_config_tests[] = {
{ "Phone normalization without proxy", phone_normalization_without_proxy },
{ "Phone normalization with proxy", phone_normalization_with_proxy },
};
test_suite_t proxy_config_test_suite = {
"Proxy config",
NULL,
NULL,
sizeof(proxy_config_tests) / sizeof(proxy_config_tests[0]),
proxy_config_tests
};
......@@ -415,6 +415,7 @@ void liblinphone_tester_add_suites() {
bc_tester_add_suite(&video_test_suite);
#endif
bc_tester_add_suite(&multicast_call_test_suite);
bc_tester_add_suite(&proxy_config_test_suite);
}
static bool_t linphone_core_manager_get_max_audio_bw_base(const int array[],int array_size) {
......
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