static void phone_normalization_with_proxy(void) { 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_PTR_NULL(phone_normalization(proxy, "I_AM_NOT_A_NUMBER")); // invalid phone number BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+990012345678"), "+990012345678"); BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0952636505"), "+33952636505"); BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "09 52 63 65 05"), "+33952636505"); BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "09-52-63-65-05"), "+33952636505"); BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+31952636505"), "+31952636505"); BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0033952636505"), "+33952636505"); BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0033952636505"), "+33952636505"); BC_ASSERT_PTR_NULL(phone_normalization(proxy, "toto")); linphone_proxy_config_set_dial_prefix(proxy, "99"); BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0012345678"), "+12345678"); linphone_proxy_config_destroy(proxy); }
LinphoneAccountCreatorStatus linphone_account_creator_set_phone_number(LinphoneAccountCreator *creator, const char *phone_number, const char *country_code) { char *normalized_phone_number; if (!phone_number || !country_code) { if (!phone_number && !country_code) { creator->phone_number = NULL; return LinphoneAccountCreatorOK; } else { return LinphoneAccountCreatorPhoneNumberInvalid; } } else { LinphoneProxyConfig *numCfg = linphone_proxy_config_new(); linphone_proxy_config_set_dial_prefix(numCfg, country_code); normalized_phone_number = linphone_proxy_config_normalize_phone_number(numCfg, phone_number); linphone_proxy_config_destroy(numCfg); if (!normalized_phone_number) { return LinphoneAccountCreatorPhoneNumberInvalid; } // if phone is valid, we lastly want to check that length is OK { const LinphoneDialPlan* plan = linphone_dial_plan_by_ccc(country_code); int size = (int)strlen(phone_number); if (size < plan->nnl) { return LinphoneAccountCreatorPhoneNumberTooShort; } else if (size > plan->nnl + 1) { return LinphoneAccountCreatorPhoneNumberTooLong; } } } set_string(&creator->phone_number, normalized_phone_number, TRUE); ms_free(normalized_phone_number); return LinphoneAccountCreatorOK; }
static void phone_normalization_with_dial_escape_plus(void){ LinphoneProxyConfig *proxy = linphone_proxy_config_new(); linphone_proxy_config_set_dial_prefix(proxy, "33"); linphone_proxy_config_set_dial_escape_plus(proxy, TRUE); BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0033952636505"), "0033952636505"); BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0952636505"), "0033952636505"); BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+34952636505"), "0034952636505"); linphone_proxy_config_destroy(proxy); }
LinphoneProxyConfig *linphone_proxy_config_new_from_config_file(LpConfig *config, int index) { const char *tmp; const char *identity; const char *proxy; LinphoneProxyConfig *cfg; char key[50]; sprintf(key,"proxy_%i",index); if (!lp_config_has_section(config,key)){ return NULL; } cfg=linphone_proxy_config_new(); identity=lp_config_get_string(config,key,"reg_identity",NULL); proxy=lp_config_get_string(config,key,"reg_proxy",NULL); linphone_proxy_config_set_identity(cfg,identity); linphone_proxy_config_set_server_addr(cfg,proxy); tmp=lp_config_get_string(config,key,"reg_route",NULL); if (tmp!=NULL) linphone_proxy_config_set_route(cfg,tmp); linphone_proxy_config_expires(cfg,lp_config_get_int(config,key,"reg_expires",600)); linphone_proxy_config_enableregister(cfg,lp_config_get_int(config,key,"reg_sendregister",0)); linphone_proxy_config_enable_publish(cfg,lp_config_get_int(config,key,"publish",0)); linphone_proxy_config_set_dial_escape_plus(cfg,lp_config_get_int(config,key,"dial_escape_plus",0)); linphone_proxy_config_set_dial_prefix(cfg,lp_config_get_string(config,key,"dial_prefix",NULL)); tmp=lp_config_get_string(config,key,"type",NULL); if (tmp!=NULL && strlen(tmp)>0) linphone_proxy_config_set_sip_setup(cfg,tmp); return cfg; }