misc: parse user input as phone numbers if proxy config must deal with phone numbers only

This commit is contained in:
Gautier Pelloux-Prayer 2016-04-04 13:36:06 +02:00
parent 7ca5ddbee3
commit f357fd0975
14 changed files with 76 additions and 69 deletions

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="DialerView">
@ -51,7 +51,7 @@
<rect key="frame" x="31" y="0.0" width="426" height="66"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<accessibility key="accessibilityConfiguration" label="Enter a address"/>
<accessibility key="accessibilityConfiguration" label="Enter an address"/>
<fontDescription key="fontDescription" type="system" pointSize="33"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" keyboardType="alphabet" returnKeyType="join"/>
<connections>

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="DialerView">
@ -68,7 +68,7 @@
<rect key="frame" x="8" y="0.0" width="239" height="80"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<accessibility key="accessibilityConfiguration" label="Enter a address"/>
<accessibility key="accessibilityConfiguration" label="Enter an address"/>
<fontDescription key="fontDescription" type="system" pointSize="21"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" keyboardType="alphabet" returnKeyType="join"/>
<connections>
@ -366,7 +366,7 @@
<rect key="frame" x="8" y="0.0" width="237" height="80"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<accessibility key="accessibilityConfiguration" label="Enter a address"/>
<accessibility key="accessibilityConfiguration" label="Enter an address"/>
<fontDescription key="fontDescription" type="system" pointSize="21"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" keyboardType="alphabet" returnKeyType="join"/>
<connections>

View file

@ -45,7 +45,7 @@
}];
// also add current entry, if not listed
NSString *nsuri = filter.lowercaseString;
LinphoneAddress *addr = linphone_core_interpret_url(LC, nsuri.UTF8String);
LinphoneAddress *addr = [LinphoneUtils normalizeSipOrPhoneAddress:nsuri];
if (addr) {
char *uri = linphone_address_as_string(addr);
nsuri = [NSString stringWithUTF8String:uri];

View file

@ -328,7 +328,7 @@ static UICompositeViewDescription *compositeDescription = nil;
[_addressField resignFirstResponder];
}
if (textField.text.length > 0) {
LinphoneAddress *addr = linphone_core_interpret_url(LC, textField.text.UTF8String);
LinphoneAddress *addr = [LinphoneUtils normalizeSipOrPhoneAddress:textField.text];
[LinphoneManager.instance call:addr];
if (addr)
linphone_address_destroy(addr);
@ -390,7 +390,7 @@ static UICompositeViewDescription *compositeDescription = nil;
- (void)onOneLongClick:(id)sender {
LinphoneManager *lm = LinphoneManager.instance;
NSString *voiceMail = [lm lpConfigStringForKey:@"voice_mail_uri"];
LinphoneAddress *addr = linphone_core_interpret_url(LC, voiceMail ? voiceMail.UTF8String : NULL);
LinphoneAddress *addr = [LinphoneUtils normalizeSipOrPhoneAddress:voiceMail];
if (addr) {
linphone_address_set_display_name(addr, NSLocalizedString(@"Voice mail", nil).UTF8String);
[lm call:addr];

View file

@ -86,7 +86,7 @@
}
if ([address length] > 0) {
LinphoneAddress *addr = linphone_core_interpret_url(LC, address.UTF8String);
LinphoneAddress *addr = [LinphoneUtils normalizeSipOrPhoneAddress:address];
[LinphoneManager.instance call:addr];
if (addr)
linphone_address_destroy(addr);

View file

@ -90,14 +90,14 @@
}
- (IBAction)onCallClick:(id)event {
LinphoneAddress *addr = linphone_core_interpret_url(LC, _addressLabel.text.UTF8String);
LinphoneAddress *addr = [LinphoneUtils normalizeSipOrPhoneAddress:_addressLabel.text];
[LinphoneManager.instance call:addr];
if (addr)
linphone_address_destroy(addr);
}
- (IBAction)onChatClick:(id)event {
LinphoneAddress *addr = linphone_core_interpret_url(LC, _addressLabel.text.UTF8String);
LinphoneAddress *addr = [LinphoneUtils normalizeSipOrPhoneAddress:_addressLabel.text];
if (addr == NULL)
return;
ChatConversationView *view = VIEW(ChatConversationView);

View file

@ -76,22 +76,15 @@ static void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info
+ (NSString *)normalizeSipURI:(NSString *)address {
// replace all whitespaces (non-breakable, utf8 nbsp etc.) by the "classical" whitespace
address = [[address componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]
componentsJoinedByString:@" "];
NSString *normalizedSipAddress = nil;
LinphoneAddress *linphoneAddress = linphone_core_interpret_url(LC, [address UTF8String]);
if (linphoneAddress != NULL) {
char *tmp = linphone_address_as_string_uri_only(linphoneAddress);
if (tmp != NULL) {
normalizedSipAddress = [NSString stringWithUTF8String:tmp];
// remove transport, if any
NSRange pos = [normalizedSipAddress rangeOfString:@";"];
if (pos.location != NSNotFound) {
normalizedSipAddress = [normalizedSipAddress substringToIndex:pos.location];
}
ms_free(tmp);
}
linphone_address_destroy(linphoneAddress);
NSString *normalizedSipAddress = [[address
componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] componentsJoinedByString:@" "];
LinphoneAddress *addr = linphone_core_interpret_url(LC, [address UTF8String]);
if (addr != NULL) {
linphone_address_clean(addr);
char *tmp = linphone_address_as_string(addr);
normalizedSipAddress = [NSString stringWithUTF8String:tmp];
ms_free(tmp);
linphone_address_destroy(addr);
}
return normalizedSipAddress;
}

View file

@ -32,6 +32,8 @@
+ (void)buttonMultiViewApplyAttributes:(NSDictionary*)attributes button:(UIButton*)button;
+ (NSString *)deviceName;
+ (LinphoneAddress *)normalizeSipOrPhoneAddress:(NSString *)addr;
typedef enum {
LinphoneDateHistoryList,
LinphoneDateHistoryDetails,

View file

@ -339,6 +339,26 @@
return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
}
+ (LinphoneAddress *)normalizeSipOrPhoneAddress:(NSString *)value {
if (!value) {
return NULL;
}
LinphoneProxyConfig *cfg = linphone_core_get_default_proxy_config(LC);
LinphoneAddress *addr = linphone_proxy_config_normalize_sip_uri(cfg, value.UTF8String);
// since user wants to escape plus, we assume it expects to have phone numbers by default
if (addr && cfg && linphone_proxy_config_get_dial_escape_plus(cfg)) {
char *phone = linphone_proxy_config_normalize_phone_number(cfg, value.UTF8String);
if (phone) {
linphone_address_set_username(addr, phone);
ms_free(phone);
}
}
return addr;
}
@end
@implementation NSNumber (HumanReadableSize)

View file

@ -4,7 +4,6 @@
<dict>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
@ -205,7 +204,7 @@
<key>Key</key>
<string>account_prefix_preference</string>
<key>Title</key>
<string>Prefix</string>
<string>Country code prefix</string>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
<key>IASKTextAlignment</key>
@ -217,11 +216,11 @@
<key>Key</key>
<string>account_substitute_+_by_00_preference</string>
<key>Title</key>
<string>Substitute + by 00</string>
<string>Substitute + in phone numbers</string>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
</dict>
<dict>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
<key>Title</key>
@ -231,7 +230,7 @@
<key>DefaultValue</key>
<false/>
</dict>
<dict>
<dict>
<key>Key</key>
<string>account_mandatory_remove_button</string>
<key>Title</key>

View file

@ -2,7 +2,7 @@
// CallTester.h
// linphone
//
// Created by Gautier Pelloux-Prayer on 24/08/15.
// Created by Gautier Pelloux-Prayer on 04/04/16.
//
//

View file

@ -2,17 +2,17 @@
// CallTester.m
// linphone
//
// Created by Gautier Pelloux-Prayer on 24/08/15.
// Created by Gautier Pelloux-Prayer on 04/04/16.
//
//
#import "CallTester.h"
#include "LinphoneManager.h"
@implementation CallTester
#pragma mark - Setup
- (void)beforeAll {
[super beforeAll];
[self switchToValidAccountIfNeeded];
}
@ -24,40 +24,27 @@
[tester tapViewWithAccessibilityLabel:@"Dialer"];
}
- (void)afterEach {
if ([tester tryFindingTappableViewWithAccessibilityLabel:@"Hangup" error:nil]) {
[tester tapViewWithAccessibilityLabel:@"Hangup"];
}
[super afterEach];
}
#pragma mark - Tools
- (void)callURI:(NSString *)address {
[tester enterText:address intoViewWithAccessibilityLabel:@"Enter an address"];
[tester tapViewWithAccessibilityLabel:@"Call" traits:UIAccessibilityTraitButton];
}
#pragma mark - Tests
- (void)testCallMeBusy {
[self callURI:[self me]];
[tester waitForViewWithAccessibilityLabel:[NSString stringWithFormat:@"%@ is busy.", [self me]]];
[tester tapViewWithAccessibilityLabel:@"Cancel" traits:UIAccessibilityTraitButton];
- (void)testCallPhoneNumberEscaped {
LinphoneProxyConfig *cfg = linphone_core_get_default_proxy_config(LC);
linphone_proxy_config_set_dial_escape_plus(cfg, TRUE);
NSString *num = @"+3312345-6789";
[tester enterText:num intoViewWithAccessibilityLabel:@"Enter an address"];
[tester tapViewWithAccessibilityLabel:@"Call" traits:UIAccessibilityTraitButton];
[tester waitForViewWithAccessibilityLabel:@"0033123456789 is not registered."];
[tester tapViewWithAccessibilityLabel:@"Cancel"];
linphone_proxy_config_set_dial_escape_plus(cfg, FALSE);
}
- (void)testCallUnregisteredUser {
NSString *unregisteredUser = [self getUUID];
[self callURI:unregisteredUser];
[tester waitForViewWithAccessibilityLabel:[NSString stringWithFormat:@"%@ is not registered.", unregisteredUser]];
[tester tapViewWithAccessibilityLabel:@"Cancel" traits:UIAccessibilityTraitButton];
}
- (void)testDialInvalidSIPURI {
NSString *user = @"123 😀";
[self callURI:user];
[tester waitForViewWithAccessibilityLabel:[NSString
stringWithFormat:@"Cannot call %@.\nReason was: Call failed", user]];
[tester tapViewWithAccessibilityLabel:@"Cancel" traits:UIAccessibilityTraitButton];
- (void)testCallSIPNotEscaped {
LinphoneProxyConfig *cfg = linphone_core_get_default_proxy_config(LC);
linphone_proxy_config_set_dial_escape_plus(cfg, FALSE);
NSString *num = @"+3312345-6789";
[tester enterText:num intoViewWithAccessibilityLabel:@"Enter an address"];
[tester tapViewWithAccessibilityLabel:@"Call" traits:UIAccessibilityTraitButton];
[tester waitForViewWithAccessibilityLabel:@"+3312345-6789 is not registered."];
[tester tapViewWithAccessibilityLabel:@"Cancel"];
}
@end

View file

@ -532,6 +532,7 @@
634610061B61330300548952 /* UILabel+Boldify.m in Sources */ = {isa = PBXBuildFile; fileRef = 634610051B61330300548952 /* UILabel+Boldify.m */; };
6346100F1B61409800548952 /* CallOutgoingView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6346100E1B61409800548952 /* CallOutgoingView.m */; };
634610121B6140A500548952 /* CallOutgoingView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 634610101B6140A500548952 /* CallOutgoingView.xib */; };
63510D9E1CB2757300FB5E90 /* CallTester.m in Sources */ = {isa = PBXBuildFile; fileRef = 63510D981CB2752600FB5E90 /* CallTester.m */; };
635173F91BA082A40095EB0A /* UIChatBubblePhotoCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 635173F81BA082A40095EB0A /* UIChatBubblePhotoCell.m */; };
6352A5751BE0D4B800594C1C /* CallSideMenuView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6352A5731BE0D4B800594C1C /* CallSideMenuView.m */; };
6352A5761BE0D4B800594C1C /* CallSideMenuView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6352A5741BE0D4B800594C1C /* CallSideMenuView.xib */; };
@ -1436,6 +1437,8 @@
6346100D1B61409800548952 /* CallOutgoingView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CallOutgoingView.h; sourceTree = "<group>"; };
6346100E1B61409800548952 /* CallOutgoingView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CallOutgoingView.m; sourceTree = "<group>"; };
634610111B6140A500548952 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/CallOutgoingView.xib; sourceTree = "<group>"; };
63510D971CB2752600FB5E90 /* CallTester.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CallTester.h; sourceTree = "<group>"; };
63510D981CB2752600FB5E90 /* CallTester.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CallTester.m; sourceTree = "<group>"; };
635173F71BA082A40095EB0A /* UIChatBubblePhotoCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIChatBubblePhotoCell.h; sourceTree = "<group>"; };
635173F81BA082A40095EB0A /* UIChatBubblePhotoCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIChatBubblePhotoCell.m; sourceTree = "<group>"; };
6352A5721BE0D4B800594C1C /* CallSideMenuView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CallSideMenuView.h; sourceTree = "<group>"; };
@ -2261,6 +2264,8 @@
630589E61B4E810900EFAE36 /* AssistantTester.m */,
63CAACD41C91D0D100216F8D /* NotificationTester.h */,
63CAACD51C91D0D100216F8D /* NotificationTester.m */,
63510D971CB2752600FB5E90 /* CallTester.h */,
63510D981CB2752600FB5E90 /* CallTester.m */,
);
path = TestsUI;
sourceTree = "<group>";
@ -3891,6 +3896,7 @@
630589EB1B4E810900EFAE36 /* AssistantTester.m in Sources */,
630589E71B4E810900EFAE36 /* ChatTester.m in Sources */,
630589E81B4E810900EFAE36 /* ContactsTester.m in Sources */,
63510D9E1CB2757300FB5E90 /* CallTester.m in Sources */,
63CAACDB1C91D10200216F8D /* NotificationTester.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

@ -1 +1 @@
Subproject commit cff024b8f9f73b6f708b5f50ad86128cb7dd8607
Subproject commit 3f495448e11a973f7d5c7cadebd646f9ae76dde2