diff --git a/Classes/AssistantView.m b/Classes/AssistantView.m index 65d748eb9..13bbfc142 100644 --- a/Classes/AssistantView.m +++ b/Classes/AssistantView.m @@ -707,7 +707,7 @@ static UICompositeViewDescription *compositeDescription = nil; LinphoneAccount *default_account = linphone_core_create_account(LC, default_account_params); const char *identity = linphone_account_params_get_identity(linphone_account_get_params(default_account)); if (identity) { - LinphoneAddress *default_addr = linphone_core_interpret_url(LC, identity); + LinphoneAddress *default_addr = linphone_core_interpret_url_2(LC, identity, false); if (default_addr) { const char *domain = linphone_address_get_domain(default_addr); const char *username = linphone_address_get_username(default_addr); diff --git a/Classes/ChatConversationCreateTableView.m b/Classes/ChatConversationCreateTableView.m index 9a512a997..c90887003 100644 --- a/Classes/ChatConversationCreateTableView.m +++ b/Classes/ChatConversationCreateTableView.m @@ -112,7 +112,7 @@ if (addr) { uri = linphone_address_as_string_uri_only(addr); address = [NSString stringWithUTF8String:uri]; - contact = [LinphoneManager.instance.fastAddressBook.addressBookMap objectForKey:[FastAddressBook normalizeSipURI:address]]; + contact = [LinphoneManager.instance.fastAddressBook.addressBookMap objectForKey:[FastAddressBook normalizeSipURI:address use_prefix:[CallManager.instance applyInternationalPrefix]]]; } const LinphoneFriend* friend = linphone_search_result_get_friend(result); @@ -203,7 +203,7 @@ NSString *key = [_addresses objectAtIndex:indexPath.row]; NSString *phoneOrAddr = [_phoneOrAddr objectAtIndex:indexPath.row]; - Contact *contact = [LinphoneManager.instance.fastAddressBook.addressBookMap objectForKey:[FastAddressBook normalizeSipURI:key]]; + Contact *contact = [LinphoneManager.instance.fastAddressBook.addressBookMap objectForKey:[FastAddressBook normalizeSipURI:key use_prefix:[CallManager.instance applyInternationalPrefix]]]; if (!contact) { contact = [_ldapContactAddressBookMap objectForKey:key]; } diff --git a/Classes/Contact.m b/Classes/Contact.m index 1a47d0672..baa6d9ccd 100644 --- a/Classes/Contact.m +++ b/Classes/Contact.m @@ -70,7 +70,7 @@ linphone_friend_set_ref_key(_friend, key); linphone_friend_set_name(_friend, [NSString stringWithFormat:@"%@%@", _firstName ? _firstName : @"", _lastName ? [_firstName ? @" " : @"" stringByAppendingString:_lastName] : @""] .UTF8String); for (NSString *sipAddr in _sipAddresses) { - LinphoneAddress *addr = linphone_core_interpret_url(LC, sipAddr.UTF8String); + LinphoneAddress *addr = linphone_core_interpret_url_2(LC, sipAddr.UTF8String, true); if (addr) { linphone_address_set_display_name(addr, [self displayName].UTF8String); linphone_friend_add_address(_friend, addr); @@ -287,7 +287,7 @@ [_person setValue:tmpSipAddresses forKey:CNContactInstantMessageAddressesKey]; ret = TRUE; } else { - LinphoneAddress *addr = linphone_core_interpret_url(LC, sip.UTF8String) ?: linphone_address_new(sip.UTF8String); + LinphoneAddress *addr = linphone_core_interpret_url_2(LC, sip.UTF8String, true) ?: linphone_address_new(sip.UTF8String); if (!addr) return FALSE; @@ -370,7 +370,7 @@ } ret = TRUE; } else { - LinphoneAddress *addr = linphone_core_interpret_url(LC, ((NSString *)_sipAddresses[index]).UTF8String); + LinphoneAddress *addr = linphone_core_interpret_url_2(LC, ((NSString *)_sipAddresses[index]).UTF8String, true); if (!addr) return FALSE; @@ -465,7 +465,7 @@ linphone_friend_set_ref_key(_friend, key); linphone_friend_set_name(_friend, [NSString stringWithFormat:@"%@%@", _firstName ? _firstName : @"", _lastName ? [_firstName ? @" " : @"" stringByAppendingString:_lastName] : @""] .UTF8String); for (NSString *sipAddr in _sipAddresses) { - LinphoneAddress *addr = linphone_core_interpret_url(LC, sipAddr.UTF8String); + LinphoneAddress *addr = linphone_core_interpret_url_2(LC, sipAddr.UTF8String, true); if (addr) { linphone_address_set_display_name(addr, [self displayName].UTF8String); linphone_friend_add_address(_friend, addr); diff --git a/Classes/ContactDetailsTableView.m b/Classes/ContactDetailsTableView.m index d12321175..81df785df 100644 --- a/Classes/ContactDetailsTableView.m +++ b/Classes/ContactDetailsTableView.m @@ -200,7 +200,7 @@ LinphoneAddress *addr = NULL; if ([LinphoneManager.instance lpConfigBoolForKey:@"contact_display_username_only"] && - (addr = linphone_core_interpret_url(LC, [value UTF8String]))) { + (addr = linphone_core_interpret_url_2(LC, [value UTF8String], YES))) { value = [NSString stringWithCString:linphone_address_get_username(addr) encoding:[NSString defaultCStringEncoding]]; diff --git a/Classes/ContactDetailsView.m b/Classes/ContactDetailsView.m index cb3000e29..845f15134 100644 --- a/Classes/ContactDetailsView.m +++ b/Classes/ContactDetailsView.m @@ -102,7 +102,7 @@ } for (NSString *sipAddr in _contact.sipAddresses) { - LinphoneAddress *addr = linphone_core_interpret_url(LC, sipAddr.UTF8String); + LinphoneAddress *addr = linphone_core_interpret_url_2(LC, sipAddr.UTF8String, true); if (addr) { linphone_friend_add_address(_contact.friend, addr); linphone_address_destroy(addr); @@ -146,7 +146,7 @@ } - (void)addCurrentContactContactField:(NSString *)address { - LinphoneAddress *linphoneAddress = linphone_core_interpret_url(LC, address.UTF8String); + LinphoneAddress *linphoneAddress = linphone_core_interpret_url_2(LC, address.UTF8String, true); NSString *username = linphoneAddress ? [NSString stringWithUTF8String:linphone_address_get_username(linphoneAddress)] : address; @@ -597,7 +597,7 @@ static UICompositeViewDescription *compositeDescription = nil; [[store unifiedContactWithIdentifier:contactToCheck.identifier keysToFetch:keysToFetch error:nil] mutableCopy]; if(mCNContact == NULL){ for(NSString *address in contactToCheck.sipAddresses){ - NSString *name = [FastAddressBook normalizeSipURI:address]; + NSString *name = [FastAddressBook normalizeSipURI:address use_prefix:TRUE]; if([LinphoneManager.instance.fastAddressBook.addressBookMap objectForKey:name]){ return TRUE; } diff --git a/Classes/LinphoneCoreSettingsStore.m b/Classes/LinphoneCoreSettingsStore.m index 7f6bffecc..8d62e8759 100644 --- a/Classes/LinphoneCoreSettingsStore.m +++ b/Classes/LinphoneCoreSettingsStore.m @@ -171,6 +171,7 @@ [self setInteger:-1 forKey:@"account_expire_preference"]; [self setInteger:-1 forKey:@"current_proxy_config_preference"]; [self setCString:"" forKey:@"account_prefix_preference"]; + [self setBool:YES forKey:@"apply_international_prefix_for_calls_and_chats"]; [self setBool:NO forKey:@"account_substitute_+_by_00_preference"]; [self setBool:NO forKey:@"account_ice_preference"]; [self setCString:"" forKey:@"account_stun_preference"]; @@ -186,7 +187,7 @@ const LinphoneAddress *identity_addr = linphone_account_params_get_identity_address(accountParams); const char *server_addr = linphone_account_params_get_server_addr(accountParams); - LinphoneAddress *proxy_addr = linphone_core_interpret_url(LC, server_addr); + LinphoneAddress *proxy_addr = linphone_core_interpret_url_2(LC, server_addr, [CallManager.instance applyInternationalPrefix]); if (identity_addr && proxy_addr) { int port = linphone_address_get_port(proxy_addr); @@ -256,6 +257,8 @@ { const char *dial_prefix = linphone_account_params_get_international_prefix(accountParams); [self setCString:dial_prefix forKey:@"account_prefix_preference"]; + BOOL apply_prefix = linphone_account_params_get_use_international_prefix_for_calls_and_chats(accountParams); + [self setBool:apply_prefix forKey:@"apply_international_prefix_for_calls_and_chats"]; BOOL dial_escape_plus = linphone_account_params_get_dial_escape_plus_enabled(accountParams); [self setBool:dial_escape_plus forKey:@"account_substitute_+_by_00_preference"]; } @@ -612,6 +615,7 @@ int expire = [self integerForKey:@"account_expire_preference"]; BOOL pushnotification = [self boolForKey:@"account_pushnotification_preference"]; NSString *prefix = [self stringForKey:@"account_prefix_preference"]; + BOOL use_prefix = [self boolForKey:@"apply_international_prefix_for_calls_and_chats"]; NSString *proxyAddress = [self stringForKey:@"account_proxy_preference"]; if ((!proxyAddress || [proxyAddress length] < 1) && domain) { @@ -622,7 +626,7 @@ proxyAddress = [NSString stringWithFormat:@"sip:%@", proxyAddress]; } - LinphoneAddress *proxy_addr = linphone_core_interpret_url(LC, proxyAddress.UTF8String); + LinphoneAddress *proxy_addr = linphone_core_interpret_url_2(LC, proxyAddress.UTF8String, use_prefix); if (proxy_addr) { LinphoneTransportType type = LinphoneTransportUdp; @@ -681,7 +685,7 @@ linphone_account_params_set_nat_policy(newAccountParams, policy); linphone_account_params_set_international_prefix(newAccountParams, [prefix UTF8String]); - + linphone_account_params_set_use_international_prefix_for_calls_and_chats(newAccountParams, use_prefix); if ([self objectForKey:@"account_substitute_+_by_00_preference"]) { bool substitute_plus_by_00 = [self boolForKey:@"account_substitute_+_by_00_preference"]; linphone_account_params_set_dial_escape_plus_enabled(newAccountParams, substitute_plus_by_00); @@ -721,7 +725,7 @@ } char *identity = linphone_address_as_string(linphoneAddress); - LinphoneAddress *from = linphone_core_interpret_url(LC, identity); + LinphoneAddress *from = linphone_core_interpret_url_2(LC, identity, [CallManager.instance applyInternationalPrefix]); ms_free(identity); if (from) { const char *userid_str = (userID != nil) ? [userID UTF8String] : NULL; diff --git a/Classes/LinphoneUI/UIContactDetailsCell.m b/Classes/LinphoneUI/UIContactDetailsCell.m index dd4acf9b1..1bed3495b 100644 --- a/Classes/LinphoneUI/UIContactDetailsCell.m +++ b/Classes/LinphoneUI/UIContactDetailsCell.m @@ -50,7 +50,7 @@ normAddr = linphone_account_normalize_phone_number(account, _addressLabel.text.UTF8String); } - LinphoneAddress *addr = linphone_core_interpret_url(LC, normAddr); + LinphoneAddress *addr = linphone_core_interpret_url_2(LC, normAddr, true); _chatButton.enabled = _callButton.enabled = _encryptedChatButton.enabled = (addr != NULL); _chatButton.accessibilityLabel = @@ -103,7 +103,7 @@ normAddr = linphone_account_normalize_phone_number(account, _addressLabel.text.UTF8String); } - LinphoneAddress *addr = linphone_core_interpret_url(LC, normAddr); + LinphoneAddress *addr = linphone_core_interpret_url_2(LC, normAddr, true); // Test presence Contact *contact = [FastAddressBook getContactWithAddress:(addr)]; diff --git a/Classes/MagicSearch.swift b/Classes/MagicSearch.swift index 984091328..13369618f 100644 --- a/Classes/MagicSearch.swift +++ b/Classes/MagicSearch.swift @@ -56,7 +56,7 @@ import linphonesw return LinphoneManager.instance().fastAddressBook.addressBookMap.object(forKey: addr.asStringUriOnly() as Any) as? Contact } func getContactFromPhoneNb(phoneNb: String) -> Contact? { - let contactKey = FastAddressBook.localizedLabel(FastAddressBook.normalizeSipURI( lc?.defaultAccount?.normalizePhoneNumber(username: phoneNb) ?? phoneNb)) + let contactKey = FastAddressBook.localizedLabel(FastAddressBook.normalizeSipURI(lc?.defaultAccount?.normalizePhoneNumber(username: phoneNb) ?? phoneNb, use_prefix: true)) return LinphoneManager.instance().fastAddressBook.addressBookMap.object(forKey: contactKey as Any) as? Contact } diff --git a/Classes/Swift/CallManager.swift b/Classes/Swift/CallManager.swift index dc40ce286..b1a38a957 100644 --- a/Classes/Swift/CallManager.swift +++ b/Classes/Swift/CallManager.swift @@ -792,8 +792,12 @@ import AVFoundation } } - - + @objc func applyInternationalPrefix() -> Bool { + if let account = lc?.defaultAccount, let params = account.params { + return params.useInternationalPrefixForCallsAndChats + } + return true; // Legacy behavior + } } diff --git a/Classes/Swift/Voip/ViewModels/CallData.swift b/Classes/Swift/Voip/ViewModels/CallData.swift index e94fc03fd..05cd032d3 100644 --- a/Classes/Swift/Voip/ViewModels/CallData.swift +++ b/Classes/Swift/Voip/ViewModels/CallData.swift @@ -150,7 +150,7 @@ class CallData { func getConferenceAddress(call: Call) -> Address? { let remoteContact = call.remoteContact - return call.dir == .Incoming ? (remoteContact != nil ? Core.get().interpretUrl(url: remoteContact) : nil) : call.remoteAddress + return call.dir == .Incoming ? (remoteContact != nil ? Core.get().interpretUrl(url: remoteContact, applyInternationalPrefix: CallManager.instance().applyInternationalPrefix()) : nil) : call.remoteAddress } func sendDTMF(dtmf:String) { diff --git a/Classes/Utils/FastAddressBook.h b/Classes/Utils/FastAddressBook.h index 650725bbc..f960b1e65 100644 --- a/Classes/Utils/FastAddressBook.h +++ b/Classes/Utils/FastAddressBook.h @@ -59,7 +59,7 @@ + (BOOL)isSipURI:(NSString *)address; + (BOOL)isSipAddress:(CNLabeledValue *)sipAddr; -+ (NSString *)normalizeSipURI:(NSString *)address; ++ (NSString *)normalizeSipURI:(NSString *)address use_prefix:(BOOL)use_prefix; + (NSString *)localizedLabel:(NSString *)label; - (void)registerAddrsFor:(Contact *)contact; diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index 23da63cca..fa2c99cf0 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -76,7 +76,7 @@ Contact *contact = nil; if (address) { char *uri = linphone_address_as_string_uri_only(address); - NSString *normalizedSipAddress = [FastAddressBook normalizeSipURI:[NSString stringWithUTF8String:uri]]; + NSString *normalizedSipAddress = [FastAddressBook normalizeSipURI:[NSString stringWithUTF8String:uri] use_prefix:TRUE]; contact = [FastAddressBook getContact:normalizedSipAddress]; ms_free(uri); @@ -128,10 +128,10 @@ return FALSE; } -+ (NSString *)normalizeSipURI:(NSString *)address { ++ (NSString *)normalizeSipURI:(NSString *)address use_prefix:(BOOL)use_prefix { // replace all whitespaces (non-breakable, utf8 nbsp etc.) by the "classical" whitespace NSString *normalizedSipAddress = nil; - LinphoneAddress *addr = linphone_core_interpret_url(LC, [address UTF8String]); + LinphoneAddress *addr = linphone_core_interpret_url_2(LC, [address UTF8String], use_prefix); if (addr != NULL) { linphone_address_clean(addr); char *tmp = linphone_address_as_string(addr); @@ -247,7 +247,7 @@ for (NSString *phone in mContact.phones) { char *normalizedPhone = account? linphone_account_normalize_phone_number(account, phone.UTF8String) : nil; - NSString *name = [FastAddressBook normalizeSipURI:normalizedPhone ? [NSString stringWithUTF8String:normalizedPhone] : phone]; + NSString *name = [FastAddressBook normalizeSipURI:(normalizedPhone ? [NSString stringWithUTF8String:normalizedPhone] : phone) use_prefix:TRUE]; if (phone != NULL) [_addressBookMap setObject:mContact forKey:(name ?: [FastAddressBook localizedLabel:phone])]; @@ -256,7 +256,7 @@ } for (NSString *sip in mContact.sipAddresses) - [_addressBookMap setObject:mContact forKey:([FastAddressBook normalizeSipURI:sip] ?: sip)]; + [_addressBookMap setObject:mContact forKey:([FastAddressBook normalizeSipURI:sip use_prefix:TRUE] ?: sip)]; } #pragma mark - Tools @@ -277,7 +277,7 @@ for (NSString *sip in contact.sipAddresses) { // check domain - LinphoneAddress *address = linphone_core_interpret_url(LC, sip.UTF8String); + LinphoneAddress *address = linphone_core_interpret_url_2(LC, sip.UTF8String, true); if (address) { const char *dom = linphone_address_get_domain(address); BOOL match = false; @@ -296,7 +296,7 @@ + (BOOL) isSipURIValid:(NSString*)addr { NSString *domain = LinphoneManager.instance.contactFilter; - LinphoneAddress* address = linphone_core_interpret_url(LC, addr.UTF8String); + LinphoneAddress* address = linphone_core_interpret_url_2(LC, addr.UTF8String, true); if (address) { const char *dom = linphone_address_get_domain(address); BOOL match = false; @@ -377,12 +377,12 @@ [LinphoneManager.instance setContactsUpdated:TRUE]; if([contact.sipAddresses count] > 0){ for (NSString *sip in contact.sipAddresses) { - [_addressBookMap removeObjectForKey:([FastAddressBook normalizeSipURI:sip] ?: sip)]; + [_addressBookMap removeObjectForKey:([FastAddressBook normalizeSipURI:sip use_prefix:TRUE] ?: sip)]; } } if([contact.phones count] > 0){ for (NSString *phone in contact.phones) { - [_addressBookMap removeObjectForKey:([FastAddressBook normalizeSipURI:phone] ?: phone)]; + [_addressBookMap removeObjectForKey:([FastAddressBook normalizeSipURI:phone use_prefix:TRUE] ?: phone)]; } } BOOL success = [store executeSaveRequest:saveRequest error:nil]; @@ -556,7 +556,7 @@ LinphoneAccount *account = linphone_core_get_default_account(LC); for (NSString *phone in contact.phones) { char *normalizedPhone = account? linphone_account_normalize_phone_number(account, phone.UTF8String) : nil; - NSString *name = [FastAddressBook normalizeSipURI:normalizedPhone ? [NSString stringWithUTF8String:normalizedPhone] : phone]; + NSString *name = [FastAddressBook normalizeSipURI:(normalizedPhone ? [NSString stringWithUTF8String:normalizedPhone] : phone) use_prefix:TRUE]; if (phone != NULL) { if ([FastAddressBook isSipURI:displayNames[name]]) { LOGD(@"removed %s from userdefaults addressBook", ((NSString *)displayNames[name]).UTF8String); @@ -590,7 +590,7 @@ } linphone_address_unref(addr); } else { - telAddr = [FastAddressBook normalizeSipURI:uri]; + telAddr = [FastAddressBook normalizeSipURI:uri use_prefix:TRUE]; } if (telAddr) { @@ -611,7 +611,7 @@ NSString *contact = [NSString stringWithUTF8String:str]; ms_free(str); - NSString *sipAddr = [FastAddressBook normalizeSipURI:contact]; + NSString *sipAddr = [FastAddressBook normalizeSipURI:contact use_prefix:TRUE]; if (sipAddr != nil && [displayNames objectForKey:sipAddr] == nil) { [displayNames setObject:displayName forKey:sipAddr]; diff --git a/Settings/InAppSettings.bundle/Account.plist b/Settings/InAppSettings.bundle/Account.plist index e64bb26a4..67dc9e37b 100644 --- a/Settings/InAppSettings.bundle/Account.plist +++ b/Settings/InAppSettings.bundle/Account.plist @@ -268,6 +268,16 @@ IASKTextAlignment IASKUITextAlignmentRight + + DefaultValue + + Key + apply_international_prefix_for_calls_and_chats + Title + Apply prefix for outgoing calls and chat + Type + PSToggleSwitchSpecifier + DefaultValue diff --git a/msgNotificationService/NotificationService.swift b/msgNotificationService/NotificationService.swift index 8fe8690c2..773b2a55a 100644 --- a/msgNotificationService/NotificationService.swift +++ b/msgNotificationService/NotificationService.swift @@ -242,7 +242,12 @@ class NotificationService: UNNotificationServiceExtension { return nil } - if let simpleAddr = lc?.interpretUrl(url: sipAddr) { + var usePrefix = true; + if let account = lc?.defaultAccount, let params = account.params { + usePrefix = params.useInternationalPrefixForCallsAndChats + } + + if let simpleAddr = lc?.interpretUrl(url: sipAddr, applyInternationalPrefix: usePrefix) { simpleAddr.clean() let nomalSipaddr = simpleAddr.asString() if let displayName = addressBook?[nomalSipaddr] as? String {