From c5b2b5cb2a6567a3ba895e71802ae41b16852a9b Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Tue, 21 Aug 2012 16:21:35 +0200 Subject: [PATCH] Add user/password/proxy configuration using qrcode --- Classes/BuschJaegerConfigParser.h | 3 +- Classes/BuschJaegerConfigParser.m | 18 +++++-- Classes/LinphoneManager.h | 4 ++ Classes/LinphoneManager.m | 4 ++ Classes/Model/Network.h | 33 ++++++++++++ Classes/Model/Network.m | 81 ++++++++++++++++++++++++++++++ Classes/Model/OutdoorStation.h | 1 - linphone.xcodeproj/project.pbxproj | 8 +++ 8 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 Classes/Model/Network.h create mode 100644 Classes/Model/Network.m diff --git a/Classes/BuschJaegerConfigParser.h b/Classes/BuschJaegerConfigParser.h index fe62b45e9..9f16c76d6 100644 --- a/Classes/BuschJaegerConfigParser.h +++ b/Classes/BuschJaegerConfigParser.h @@ -20,6 +20,7 @@ #import #import "OutdoorStation.h" +#import "Network.h" @protocol BuschJaegerConfigParser @@ -29,10 +30,10 @@ @end @interface BuschJaegerConfigParser : NSObject { - NSMutableSet *outdoorStations; } @property (readonly) NSMutableSet *outdoorStations; +@property (assign) Network *network; - (void)reset; - (BOOL)loadFile:(NSString*)file; diff --git a/Classes/BuschJaegerConfigParser.m b/Classes/BuschJaegerConfigParser.m index b6be1be9d..501ca8664 100644 --- a/Classes/BuschJaegerConfigParser.m +++ b/Classes/BuschJaegerConfigParser.m @@ -18,11 +18,13 @@ */ #import "BuschJaegerConfigParser.h" +#import "LinphoneManager.h" #import "Utils.h" @implementation BuschJaegerConfigParser @synthesize outdoorStations; +@synthesize network; /******** [outdoorstation_0] @@ -113,6 +115,8 @@ id obj; if((obj = [OutdoorStation parse:section array:array]) != nil) { [outdoorStations addObject:obj]; + } else if((obj = [Network parse:section array:array]) != nil) { + self.network = obj; } else { [LinphoneLogger log:LinphoneLoggerWarning format:@"Unknown section: %@", section]; } @@ -147,14 +151,12 @@ [self parseSection:last_section array:subArray]; } - dispatch_async(dispatch_get_main_queue(), ^{ - [delegate buschJaegerConfigParserSuccess]; - }); return TRUE; } - (void)reset { [outdoorStations removeAllObjects]; + self.network = nil; } - (BOOL)saveFile:(NSString*)file { @@ -213,7 +215,15 @@ [delegate buschJaegerConfigParserError:[error localizedDescription]]; }); } else { - [self parseConfig:[NSString stringWithUTF8String:[data bytes]] delegate:delegate]; + if([self parseConfig:[NSString stringWithUTF8String:[data bytes]] delegate:delegate]) { + [[NSUserDefaults standardUserDefaults] setObject:userString forKey:@"username_preference"]; + [[NSUserDefaults standardUserDefaults] setObject:network.domain forKey:@"domain_preference"]; + [[NSUserDefaults standardUserDefaults] setObject:passwordString forKey:@"password_preference"]; + [[LinphoneManager instance] reconfigureLinphone]; + dispatch_async(dispatch_get_main_queue(), ^{ + [delegate buschJaegerConfigParserSuccess]; + }); + } } }); return TRUE; diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index fd81c0e58..7d50809a1 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -120,6 +120,10 @@ typedef struct _LinphoneManagerSounds { - (void)call:(NSString *)address displayName:(NSString*)displayName transfer:(BOOL)transfer; +/* MODIFICATION: Add NSUSerdefault settings */ +- (BOOL)reconfigureLinphone; +/**/ + @property (readonly) FastAddressBook* fastAddressBook; @property Connectivity connectivity; @property (nonatomic) int defaultExpires; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index dcb31b2f4..c4e284af6 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -941,6 +941,10 @@ static LinphoneCoreVTable linphonec_vtable = { } } +- (BOOL)reconfigureLinphone { + return [self reconfigureLinphoneIfNeeded:currentSettings]; +} + - (BOOL)reconfigureLinphoneIfNeeded:(NSDictionary *)settings { [[NSUserDefaults standardUserDefaults] synchronize]; NSDictionary* newSettings = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]; diff --git a/Classes/Model/Network.h b/Classes/Model/Network.h new file mode 100644 index 000000000..8af169da5 --- /dev/null +++ b/Classes/Model/Network.h @@ -0,0 +1,33 @@ +/* Network.h + * + * Copyright (C) 2012 Belledonne Comunications, Grenoble, France + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#import + +@interface Network : NSObject + +@property (copy) NSString* domain; +@property (copy) NSString* localAddress; +@property (copy) NSString* globalAddress; +@property (copy) NSString* localHistory; +@property (copy) NSString* globalHistory; + +- (NSString*)write; ++ (id)parse:(NSString*)section array:(NSArray*)array; + +@end diff --git a/Classes/Model/Network.m b/Classes/Model/Network.m new file mode 100644 index 000000000..179623abc --- /dev/null +++ b/Classes/Model/Network.m @@ -0,0 +1,81 @@ +/* Network.m + * + * Copyright (C) 2012 Belledonne Comunications, Grenoble, France + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#import "Network.h" +#import "BuschJaegerConfigParser.h" +#import "Utils.h" + +@implementation Network + +@synthesize domain; +@synthesize localAddress; +@synthesize globalAddress; +@synthesize localHistory; +@synthesize globalHistory; + +/* + domain=abb + + local-address=192.168.1.1 + + global-address=welcome.dyndns.org + + local-history=http://192.168.1.1:8080/history.ini + + global-history=http://welcome.dyndns.org:8080/history.ini + */ + +- (NSString*)write { + NSMutableString *str = [NSMutableString string]; + [str appendString:[NSString stringWithFormat:@"\n[network]\n"]]; + [str appendString:[NSString stringWithFormat:@"domain=%@\n", domain]]; + [str appendString:[NSString stringWithFormat:@"local-address=%@\n", localAddress]]; + [str appendString:[NSString stringWithFormat:@"global-address=%@\n", globalAddress]]; + [str appendString:[NSString stringWithFormat:@"local-history=%@\n", localHistory]]; + [str appendString:[NSString stringWithFormat:@"global-history=%@\n", globalHistory]]; + return str; +} + ++ (id)parse:(NSString*)section array:(NSArray*)array { + NSString *param; + Network *net = nil; + if((param = [BuschJaegerConfigParser getRegexValue:@"^\\[(network)\\]$" data:section]) != nil) { + net = [[Network alloc] init]; + NSString *param; + for(NSString *entry in array) { + if((param = [BuschJaegerConfigParser getRegexValue:@"^domain=(.*)$" data:entry]) != nil) { + net.domain = param; + } else if((param = [BuschJaegerConfigParser getRegexValue:@"^local-address=(.*)$" data:entry]) != nil) { + net.localAddress = param; + } else if((param = [BuschJaegerConfigParser getRegexValue:@"^global-address=(.*)$" data:entry]) != nil) { + net.globalAddress = param; + } else if((param = [BuschJaegerConfigParser getRegexValue:@"^local-history=(.*)$" data:entry]) != nil) { + net.localHistory = param; + } else if((param = [BuschJaegerConfigParser getRegexValue:@"^global-history=(.*)$" data:entry]) != nil) { + net.globalHistory = param; + } else if([[entry stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] != 0){ + [LinphoneLogger log:LinphoneLoggerWarning format:@"Unknown entry in %@ section: %@", section, entry]; + } + } + } + + return net; +} + +@end diff --git a/Classes/Model/OutdoorStation.h b/Classes/Model/OutdoorStation.h index c82e704eb..acf966e14 100644 --- a/Classes/Model/OutdoorStation.h +++ b/Classes/Model/OutdoorStation.h @@ -17,7 +17,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - #import @interface OutdoorStation : NSObject diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index c9a42a11e..044bfc84d 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -224,6 +224,8 @@ D380800615C28A7A005BE9BC /* UILinphone.m in Sources */ = {isa = PBXBuildFile; fileRef = D380800415C28A7A005BE9BC /* UILinphone.m */; }; D380801315C299D0005BE9BC /* ColorSpaceUtilites.m in Sources */ = {isa = PBXBuildFile; fileRef = D380801215C299D0005BE9BC /* ColorSpaceUtilites.m */; }; D380801415C299D0005BE9BC /* ColorSpaceUtilites.m in Sources */ = {isa = PBXBuildFile; fileRef = D380801215C299D0005BE9BC /* ColorSpaceUtilites.m */; }; + D383A44E15E3C98C00CDE5C9 /* Network.m in Sources */ = {isa = PBXBuildFile; fileRef = D383A44D15E3C98C00CDE5C9 /* Network.m */; }; + D383A44F15E3C98C00CDE5C9 /* Network.m in Sources */ = {isa = PBXBuildFile; fileRef = D383A44D15E3C98C00CDE5C9 /* Network.m */; }; D3C6526715AC1A8F0092A874 /* UIEditableTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D3C6526615AC1A8F0092A874 /* UIEditableTableViewCell.m */; }; D3C6526815AC1A8F0092A874 /* UIEditableTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D3C6526615AC1A8F0092A874 /* UIEditableTableViewCell.m */; }; D3EA53FD159850E80037DC6B /* LinphoneManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D3EA53FC159850E80037DC6B /* LinphoneManager.m */; }; @@ -611,6 +613,8 @@ D380800415C28A7A005BE9BC /* UILinphone.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UILinphone.m; sourceTree = ""; }; D380801115C29984005BE9BC /* ColorSpaceUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ColorSpaceUtilities.h; path = Utils/ColorSpaceUtilities.h; sourceTree = ""; }; D380801215C299D0005BE9BC /* ColorSpaceUtilites.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ColorSpaceUtilites.m; path = Utils/ColorSpaceUtilites.m; sourceTree = ""; }; + D383A44C15E3C98C00CDE5C9 /* Network.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Network.h; path = Model/Network.h; sourceTree = ""; }; + D383A44D15E3C98C00CDE5C9 /* Network.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Network.m; path = Model/Network.m; sourceTree = ""; }; D3C6526515AC1A8F0092A874 /* UIEditableTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditableTableViewCell.h; sourceTree = ""; }; D3C6526615AC1A8F0092A874 /* UIEditableTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIEditableTableViewCell.m; sourceTree = ""; }; D3E84F3C15B018A600420DAC /* UILinphone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UILinphone.h; sourceTree = ""; }; @@ -1219,6 +1223,8 @@ D37CD35015E22A3E0028869A /* Model */ = { isa = PBXGroup; children = ( + D383A44C15E3C98C00CDE5C9 /* Network.h */, + D383A44D15E3C98C00CDE5C9 /* Network.m */, D37CD35115E22A470028869A /* OutdoorStation.h */, D37CD35215E22A470028869A /* OutdoorStation.m */, ); @@ -1529,6 +1535,7 @@ D37CD38715E22C020028869A /* BuschJaegerMainView.m in Sources */, D37CD39A15E244D10028869A /* UIStationCell.m in Sources */, D37CD3A115E2452C0028869A /* BuschJaegerStationViewController.m in Sources */, + D383A44E15E3C98C00CDE5C9 /* Network.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1574,6 +1581,7 @@ D37CD38815E22C020028869A /* BuschJaegerMainView.m in Sources */, D37CD39B15E244D10028869A /* UIStationCell.m in Sources */, D37CD3A215E2452C0028869A /* BuschJaegerStationViewController.m in Sources */, + D383A44F15E3C98C00CDE5C9 /* Network.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };