From 870852c522dfe91fadad7aafe2390172059da76e Mon Sep 17 00:00:00 2001 From: Brieuc Viel Date: Thu, 15 Feb 2018 10:46:41 +0100 Subject: [PATCH] [DialPrefix] fix country code prefix automatically added on call --- Classes/Utils/Utils.m | 84 ++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/Classes/Utils/Utils.m b/Classes/Utils/Utils.m index 443c87f31..9ffea111a 100644 --- a/Classes/Utils/Utils.m +++ b/Classes/Utils/Utils.m @@ -454,53 +454,47 @@ } + (LinphoneAddress *)normalizeSipOrPhoneAddress:(NSString *)value { - if (!value || [value isEqualToString:@""]) { - return NULL; - } - LinphoneProxyConfig *cfg = linphone_core_get_default_proxy_config(LC); - const char *normvalue; - if (linphone_proxy_config_is_phone_number(cfg, value.UTF8String)) { - normvalue = - linphone_proxy_config_normalize_phone_number(cfg, value.UTF8String); - } else { - normvalue = value.UTF8String; - } - LinphoneAddress *addr = - linphone_proxy_config_normalize_sip_uri(cfg, normvalue); - // first try to find a friend with the given address - Contact *c = [FastAddressBook getContactWithAddress:addr]; + if (!value || [value isEqualToString:@""]) { + return NULL; + } + LinphoneProxyConfig *cfg = linphone_core_get_default_proxy_config(LC); + const char *normvalue; + if (linphone_proxy_config_is_phone_number(cfg, value.UTF8String)) { + normvalue = linphone_proxy_config_normalize_phone_number(cfg, value.UTF8String); + } else { + normvalue = value.UTF8String; + } + LinphoneAddress *addr = linphone_proxy_config_normalize_sip_uri(cfg, normvalue); + // first try to find a friend with the given address + Contact *c = [FastAddressBook getContactWithAddress:addr]; - if (c && c.friend) { - LinphoneFriend *f = c.friend; - const LinphonePresenceModel *m = - f ? linphone_friend_get_presence_model_for_uri_or_tel(f, - value.UTF8String) - : NULL; - const char *contact = m ? linphone_presence_model_get_contact(m) : NULL; - if (contact) { - LinphoneAddress *contact_addr = linphone_address_new(contact); - if (contact_addr) { - linphone_address_destroy(addr); - return contact_addr; - } - } - } + if (c && c.friend) { + LinphoneFriend *f = c.friend; + const LinphonePresenceModel *m = f ? linphone_friend_get_presence_model_for_uri_or_tel(f, value.UTF8String) : NULL; + const char *contact = m ? linphone_presence_model_get_contact(m) : NULL; + if (contact) { + LinphoneAddress *contact_addr = linphone_address_new(contact); + if (contact_addr) { + linphone_address_destroy(addr); + return contact_addr; + } + } + } - // since user wants to escape plus, we assume it expects to have phone - // numbers by default - if (addr) { - if (cfg && (linphone_proxy_config_get_dial_escape_plus(cfg))) { - if (linphone_proxy_config_is_phone_number(cfg, normvalue)) { - linphone_address_set_username(addr, normvalue); - } - } else { - if (linphone_proxy_config_is_phone_number(cfg, value.UTF8String)) { - linphone_address_set_username(addr, value.UTF8String); - } - } - } - - return addr; + // since user wants to escape plus, we assume it expects to have phone + // numbers by default + if (addr) { + if (cfg || (linphone_proxy_config_get_dial_escape_plus(cfg))) { + if (linphone_proxy_config_is_phone_number(cfg, normvalue)) { + linphone_address_set_username(addr, normvalue); + } + } else { + if (linphone_proxy_config_is_phone_number(cfg, value.UTF8String)) { + linphone_address_set_username(addr, value.UTF8String); + } + } + } + return addr; } @end