diff --git a/Classes/BuschJaegerConfiguration.h b/Classes/BuschJaegerConfiguration.h index 7d20c40c6..15e8c9020 100644 --- a/Classes/BuschJaegerConfiguration.h +++ b/Classes/BuschJaegerConfiguration.h @@ -40,6 +40,7 @@ typedef enum _BuschJaegerConfigurationRequestType{ BuschJaegerConfigurationRequestType_Global } BuschJaegerConfigurationRequestType; +@property (readonly) NSData *homeAP; @property (readonly) NSMutableSet *history; @property (readonly) NSMutableSet *users; @property (readonly) NSMutableSet *outdoorStations; @@ -53,14 +54,15 @@ typedef enum _BuschJaegerConfigurationRequestType{ - (BOOL)saveFile:(NSString*)file; - (BOOL)parseQRCode:(NSString*)data delegate:(id)delegate; -- (BOOL)loadHistory:(BuschJaegerConfigurationRequestType)type delegate:(id)delegate; -- (BOOL)removeHistory:(BuschJaegerConfigurationRequestType)type history:(History*)history delegate:(id)delegate; +- (BOOL)loadHistory:(id)delegate; +- (BOOL)removeHistory:(History*)history delegate:(id)delegate; - (User*)getCurrentUser; -- (NSString*)getImageUrl:(BuschJaegerConfigurationRequestType)type image:(NSString *)image; +- (NSString*)getImageUrl:(NSString *)image; -- (NSString*)getGateway:(BuschJaegerConfigurationRequestType)type; +- (BuschJaegerConfigurationRequestType)getCurrentRequestType; +- (NSString*)getGateway; - (BOOL)canHandleAuthChallenge : (NSURLConnection*)connection : (NSURLProtectionSpace*)protectionSpace; diff --git a/Classes/BuschJaegerConfiguration.m b/Classes/BuschJaegerConfiguration.m index fb50556c0..bb942fb8f 100644 --- a/Classes/BuschJaegerConfiguration.m +++ b/Classes/BuschJaegerConfiguration.m @@ -22,8 +22,11 @@ #import "Utils.h" #import "NSURLConnection+SynchronousDelegate.h" +static NSString *const CONFIGURATION_HOME_AP_KEY = @"CONFIGURATION_HOME_AP_KEY"; + @implementation BuschJaegerConfiguration +@synthesize homeAP; @synthesize outdoorStations; @synthesize users; @synthesize network; @@ -98,11 +101,13 @@ levelPushButton = [[LevelPushButton alloc] init]; certificate = NULL; [self reloadCertificates]; + homeAP = [[[NSUserDefaults standardUserDefaults] dataForKey:CONFIGURATION_HOME_AP_KEY] retain]; } return self; } - (void)dealloc { + [homeAP release]; [outdoorStations release]; [users release]; [history release]; @@ -287,7 +292,6 @@ } - (void)loadCertificates { - if(certificate != NULL) { CFRelease(certificate); certificate = NULL; @@ -306,15 +310,18 @@ } - (void)reset { + [homeAP release]; [history removeAllObjects]; [outdoorStations removeAllObjects]; [users removeAllObjects]; if(network != nil) { [network release]; + network = nil; } network = [[Network alloc] init]; if(levelPushButton != nil) { [levelPushButton release]; + levelPushButton = nil; } levelPushButton = [[LevelPushButton alloc] init]; } @@ -380,6 +387,8 @@ NSHTTPURLResponse *urlResponse = (NSHTTPURLResponse*) response; if(urlResponse.statusCode == 200) { if([self parseConfig:[NSString stringWithUTF8String:[data bytes]] delegate:delegate]) { + homeAP = [[LinphoneManager getWifiData] retain]; + [[NSUserDefaults standardUserDefaults] setObject:homeAP forKey:CONFIGURATION_HOME_AP_KEY]; [[NSUserDefaults standardUserDefaults] setObject:userString forKey:@"username_preference"]; [[NSUserDefaults standardUserDefaults] setObject:network.domain forKey:@"domain_preference"]; [[NSUserDefaults standardUserDefaults] setObject:passwordString forKey:@"password_preference"]; @@ -404,12 +413,10 @@ return FALSE; } -- (BOOL)loadHistory:(BuschJaegerConfigurationRequestType)type delegate:(id)delegate { +- (BOOL)loadHistory:(id)delegate { [history removeAllObjects]; - - NSString *domain = (type == BuschJaegerConfigurationRequestType_Local)? network.localHistory: network.globalHistory; - domain = [self addUserNameAndPasswordToUrl:domain]; - NSString* url = [NSString stringWithFormat:@"%@", domain]; + NSString *url = ([self getCurrentRequestType] == BuschJaegerConfigurationRequestType_Local)? network.localHistory: network.globalHistory; + url = [self addUserNameAndPasswordToUrl:url]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:5]; if(request != nil) { //[NSURLConnection connectionWithRequest:request delegate:self]; @@ -531,8 +538,8 @@ } -- (BOOL)removeHistory:(BuschJaegerConfigurationRequestType)type history:(History*)ahistory delegate:(id)delegate { - NSString *url = [NSString stringWithFormat:@"%@/adduser.cgi?type=delhistory&id=%d", [self getGateway:type], ahistory.ID]; +- (BOOL)removeHistory:(History*)ahistory delegate:(id)delegate { + NSString *url = [NSString stringWithFormat:@"%@/adduser.cgi?type=delhistory&id=%d", [self getGateway], ahistory.ID]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:5]; if(request != nil) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) { @@ -585,9 +592,16 @@ return [NSString stringWithFormat:@"%@%@:%@@%@", proto, username, password, domain]; } -- (NSString*)getGateway:(BuschJaegerConfigurationRequestType)type { +- (BuschJaegerConfigurationRequestType)getCurrentRequestType { + if([[LinphoneManager getWifiData] isEqualToData:homeAP]) { + return BuschJaegerConfigurationRequestType_Local; + } + return BuschJaegerConfigurationRequestType_Global; +} + +- (NSString*)getGateway { NSString *gateway = nil; - NSString *urlString = (type == BuschJaegerConfigurationRequestType_Local)? network.localHistory: network.globalHistory; + NSString *urlString = ([self getCurrentRequestType] == BuschJaegerConfigurationRequestType_Local)? network.localHistory: network.globalHistory; NSURL *url = [NSURL URLWithString:urlString]; NSRange range = [urlString rangeOfString:[url relativePath]]; @@ -600,8 +614,9 @@ } -- (NSString*)getImageUrl:(BuschJaegerConfigurationRequestType)type image:(NSString *)image { - return [NSString stringWithFormat:@"%@/%@", [self getGateway:type], image]; +- (NSString*)getImageUrl:(NSString *)image { + NSString *url = [self getGateway]; + return [NSString stringWithFormat:@"%@/%@", url, image]; } - (User*)getCurrentUser { diff --git a/Classes/BuschJaegerHistoryDetailsView.m b/Classes/BuschJaegerHistoryDetailsView.m index 73cb2291b..e777ad1e8 100644 --- a/Classes/BuschJaegerHistoryDetailsView.m +++ b/Classes/BuschJaegerHistoryDetailsView.m @@ -160,7 +160,7 @@ } - (IBAction)onDeleteClick:(id)sender { - [[LinphoneManager instance].configuration removeHistory:BuschJaegerConfigurationRequestType_Local history:history delegate:self]; + [[LinphoneManager instance].configuration removeHistory:history delegate:self]; } - (IBAction)doDetailsSwipe:(UISwipeGestureRecognizer *)sender { @@ -168,12 +168,12 @@ if([history.images count]) { currentIndex = (currentIndex - 1); if(currentIndex < 0) currentIndex = [history.images count] - 1; - [imageView loadImage:[[LinphoneManager instance].configuration getImageUrl:BuschJaegerConfigurationRequestType_Local image:[history.images objectAtIndex:currentIndex]]]; + [imageView loadImage:[[LinphoneManager instance].configuration getImageUrl:[history.images objectAtIndex:currentIndex]]]; } } else if (sender.direction == UISwipeGestureRecognizerDirectionLeft) { if([history.images count]) { currentIndex = (currentIndex + 1) % [history.images count]; - [imageView loadImage:[[LinphoneManager instance].configuration getImageUrl:BuschJaegerConfigurationRequestType_Local image:[history.images objectAtIndex:currentIndex]]]; + [imageView loadImage:[[LinphoneManager instance].configuration getImageUrl:[history.images objectAtIndex:currentIndex]]]; } } } @@ -222,7 +222,7 @@ currentIndex = [indexPath row]; [fullscreenView setHidden:FALSE]; [imageView setImage:nil]; - [imageView loadImage:[[LinphoneManager instance].configuration getImageUrl:BuschJaegerConfigurationRequestType_Local image:[history.images objectAtIndex:currentIndex]]]; + [imageView loadImage:[[LinphoneManager instance].configuration getImageUrl:[history.images objectAtIndex:currentIndex]]]; } #pragma mark - BuschJaegerConfigurationDelegate Functions diff --git a/Classes/BuschJaegerHistoryTableViewController.m b/Classes/BuschJaegerHistoryTableViewController.m index 34cfee055..3f99db674 100644 --- a/Classes/BuschJaegerHistoryTableViewController.m +++ b/Classes/BuschJaegerHistoryTableViewController.m @@ -96,7 +96,7 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if(editingStyle == UITableViewCellEditingStyleDelete) { History *ahistory = [history objectAtIndex:[indexPath row]]; - [[LinphoneManager instance].configuration removeHistory:BuschJaegerConfigurationRequestType_Local history:ahistory delegate:self]; + [[LinphoneManager instance].configuration removeHistory:ahistory delegate:self]; [tableView beginUpdates]; [history removeObjectAtIndex:[indexPath row]]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; diff --git a/Classes/BuschJaegerHistoryView.m b/Classes/BuschJaegerHistoryView.m index 256598fa1..e253e7bf6 100644 --- a/Classes/BuschJaegerHistoryView.m +++ b/Classes/BuschJaegerHistoryView.m @@ -70,7 +70,7 @@ - (void)reload { [self view]; // Force view load - if([[LinphoneManager instance].configuration loadHistory:BuschJaegerConfigurationRequestType_Local delegate:self]) { + if([[LinphoneManager instance].configuration loadHistory:self]) { [waitView setHidden:FALSE]; } else { [waitView setHidden:TRUE]; diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index 8db7cfca3..d34d8a0b8 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -154,6 +154,8 @@ typedef struct _LinphoneManagerSounds { - (void)lpConfigSetBool:(BOOL)value forKey:(NSString*)key forSection:(NSString*)section; - (BOOL)lpConfigBoolForKey:(NSString*)key forSection:(NSString*)section; ++ (NSData*)getWifiData; + /* MODIFICATION: Add NSUSerdefault settings */ - (BOOL)reconfigureLinphone; /**/ diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 62c57f075..718311f9c 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -26,6 +26,7 @@ #import #import #import +#import #import "LinphoneManager.h" @@ -1591,6 +1592,18 @@ static void audioRouteChangeListenerCallback ( /**/ ++ (NSData*)getWifiData { + NSData *data = nil; + CFDictionaryRef dict = CNCopyCurrentNetworkInfo((CFStringRef)@"en0"); + if(dict) { + [LinphoneLogger log:LinphoneLoggerDebug format:@"AP Wifi: %@", dict]; + data = [NSData dataWithData:(NSData*) CFDictionaryGetValue(dict, @"SSIDDATA")]; + CFRelease(dict); + } + return data; +} + + #pragma mark - LPConfig Functions - (void)lpConfigSetString:(NSString*)value forKey:(NSString*)key { @@ -1649,6 +1662,7 @@ static void audioRouteChangeListenerCallback ( return [self lpConfigIntForKey:key forSection:section] == 1; } + #pragma GSM management - (void)setupGSMInteraction { diff --git a/Classes/LinphoneUI/UIHistoryCell.m b/Classes/LinphoneUI/UIHistoryCell.m index 361046006..3146a2308 100644 --- a/Classes/LinphoneUI/UIHistoryCell.m +++ b/Classes/LinphoneUI/UIHistoryCell.m @@ -90,7 +90,7 @@ if([history.images count] > 0) { NSString *image = [history.images objectAtIndex:0]; [iconImage setImage:nil]; - [iconImage loadImage:[[LinphoneManager instance].configuration getImageUrl:BuschJaegerConfigurationRequestType_Local image:image]]; + [iconImage loadImage:[[LinphoneManager instance].configuration getImageUrl:image]]; } } diff --git a/Classes/LinphoneUI/UIHistoryDetailsCell.m b/Classes/LinphoneUI/UIHistoryDetailsCell.m index cdb9960e6..b34814600 100644 --- a/Classes/LinphoneUI/UIHistoryDetailsCell.m +++ b/Classes/LinphoneUI/UIHistoryDetailsCell.m @@ -64,7 +64,7 @@ - (void)update { if(image) { [imageView setImage:nil]; - [imageView loadImage:[[LinphoneManager instance].configuration getImageUrl:BuschJaegerConfigurationRequestType_Local image:image]]; + [imageView loadImage:[[LinphoneManager instance].configuration getImageUrl:image]]; } }