From b72f37ac0aacce17bc2ec3dac1791f14c871c15a Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Tue, 13 Feb 2018 10:09:31 +0100 Subject: [PATCH] refactor --- Classes/Utils/Utils.m | 78 +++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 44 deletions(-) diff --git a/Classes/Utils/Utils.m b/Classes/Utils/Utils.m index 443c87f31..c5a0509e9 100644 --- a/Classes/Utils/Utils.m +++ b/Classes/Utils/Utils.m @@ -454,53 +454,43 @@ } + (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; - 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; - } - } - } + LinphoneProxyConfig *cfg = linphone_core_get_default_proxy_config(LC); + const char *normvalue; + normvalue = linphone_proxy_config_is_phone_number(cfg, value.UTF8String) + ? linphone_proxy_config_normalize_phone_number(cfg, value.UTF8String) + : value.UTF8String; - // 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); - } - } - } + 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]; - return 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 && cfg) { + if (linphone_proxy_config_get_dial_escape_plus(cfg) && 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