Add user/password/proxy configuration using qrcode

This commit is contained in:
Yann Diorcet 2012-08-21 16:21:35 +02:00
parent 0d7f02b3b0
commit c5b2b5cb2a
8 changed files with 146 additions and 6 deletions

View file

@ -20,6 +20,7 @@
#import <Foundation/Foundation.h>
#import "OutdoorStation.h"
#import "Network.h"
@protocol BuschJaegerConfigParser <NSObject>
@ -29,10 +30,10 @@
@end
@interface BuschJaegerConfigParser : NSObject {
NSMutableSet *outdoorStations;
}
@property (readonly) NSMutableSet *outdoorStations;
@property (assign) Network *network;
- (void)reset;
- (BOOL)loadFile:(NSString*)file;

View file

@ -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;

View file

@ -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;

View file

@ -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];

33
Classes/Model/Network.h Normal file
View file

@ -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 <UIKit/UIKit.h>
@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

81
Classes/Model/Network.m Normal file
View file

@ -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

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import <Foundation/Foundation.h>
@interface OutdoorStation : NSObject

View file

@ -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 = "<group>"; };
D380801115C29984005BE9BC /* ColorSpaceUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ColorSpaceUtilities.h; path = Utils/ColorSpaceUtilities.h; sourceTree = "<group>"; };
D380801215C299D0005BE9BC /* ColorSpaceUtilites.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ColorSpaceUtilites.m; path = Utils/ColorSpaceUtilites.m; sourceTree = "<group>"; };
D383A44C15E3C98C00CDE5C9 /* Network.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Network.h; path = Model/Network.h; sourceTree = "<group>"; };
D383A44D15E3C98C00CDE5C9 /* Network.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Network.m; path = Model/Network.m; sourceTree = "<group>"; };
D3C6526515AC1A8F0092A874 /* UIEditableTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditableTableViewCell.h; sourceTree = "<group>"; };
D3C6526615AC1A8F0092A874 /* UIEditableTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIEditableTableViewCell.m; sourceTree = "<group>"; };
D3E84F3C15B018A600420DAC /* UILinphone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UILinphone.h; sourceTree = "<group>"; };
@ -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;
};