diff options
Diffstat (limited to 'SSHTunnel_old.m')
-rwxr-xr-x | SSHTunnel_old.m | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/SSHTunnel_old.m b/SSHTunnel_old.m index 7657ba22..8080a9bf 100755 --- a/SSHTunnel_old.m +++ b/SSHTunnel_old.m @@ -34,10 +34,10 @@ Modified by Lorenz Textor for use with Sequel Pro // initialization - (id)init { - self = [super init]; + self = [super init]; - // Make this class the root one for AppleEvent calls -// [[ NSScriptExecutionContext sharedScriptExecutionContext] setTopLevelObject: self ]; + // Make this class the root one for AppleEvent calls +// [[ NSScriptExecutionContext sharedScriptExecutionContext] setTopLevelObject: self ]; return self; } @@ -46,14 +46,14 @@ Modified by Lorenz Textor for use with Sequel Pro - (BOOL)isRunning /* returns YES if tunnel is running */ { - return [ task isRunning ]; + return [ task isRunning ]; } - (NSString*)status { - if (status) + if (status) return status; - return S_IDLE; + return S_IDLE; } // starting & stopping the tunnel @@ -77,7 +77,7 @@ Modified by Lorenz Textor for use with Sequel Pro // [self stopTunnel]; return; - shouldStop = NO; + shouldStop = NO; // get arguments [ arguments addObject: @"-N" ]; @@ -95,9 +95,9 @@ Modified by Lorenz Textor for use with Sequel Pro [ arguments addObject: @"-L" ]; [ arguments addObject: [NSString stringWithFormat:@"%@/%@/%@", [args objectForKey:@"localPort"], [args objectForKey:@"host"], [args objectForKey:@"remotePort"]] ]; - [ NSThread detachNewThreadSelector:@selector(launchTunnel:) - toTarget: self - withObject: arguments ]; + [ NSThread detachNewThreadSelector:@selector(launchTunnel:) + toTarget: self + withObject: arguments ]; [ arguments release ]; } @@ -105,74 +105,74 @@ Modified by Lorenz Textor for use with Sequel Pro - (void)stopTunnel /* stops the tunnel */ { - if (! [ self isRunning ]) + if (! [ self isRunning ]) return; - shouldStop=YES; - [ self setValue: nil forKey: @"status" ]; - [ task terminate ]; - [[ NSNotificationCenter defaultCenter] postNotificationName:@"STMStatusChanged" object:self ]; + shouldStop=YES; + [ self setValue: nil forKey: @"status" ]; + [ task terminate ]; + [[ NSNotificationCenter defaultCenter] postNotificationName:@"STMStatusChanged" object:self ]; } - (void)launchTunnel:(NSArray*)arguments /* launches the tunnel in a separate thread */ { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - if (task) + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + if (task) [ task release ]; - task = [[ NSTask alloc ] init ]; - NSMutableDictionary *environment = [ NSMutableDictionary dictionaryWithDictionary: [[ NSProcessInfo processInfo ] environment ]]; - NSString *pathToAuthentifier = [[ NSBundle mainBundle ] pathForResource: @"askForPass" ofType: @"sh" ]; - - [ task setLaunchPath: @"/usr/bin/ssh" ]; - [ task setArguments: arguments ]; + task = [[ NSTask alloc ] init ]; + NSMutableDictionary *environment = [ NSMutableDictionary dictionaryWithDictionary: [[ NSProcessInfo processInfo ] environment ]]; + NSString *pathToAuthentifier = [[ NSBundle mainBundle ] pathForResource: @"askForPass" ofType: @"sh" ]; + + [ task setLaunchPath: @"/usr/bin/ssh" ]; + [ task setArguments: arguments ]; // really necessary??? [ environment removeObjectForKey: @"SSH_AGENT_PID" ]; [ environment removeObjectForKey: @"SSH_AUTH_SOCK" ]; [ environment setObject: pathToAuthentifier forKey: @"SSH_ASKPASS" ]; [ environment setObject:@":0" forKey:@"DISPLAY" ]; - - [ environment setObject: @"Sequel Pro Tunnel" forKey: @"TUNNEL_NAME" ]; - [ task setEnvironment: environment ]; - stdErrPipe = [[ NSPipe alloc ] init ]; - [ task setStandardError: stdErrPipe ]; - - [[ NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(stdErr:) + [ environment setObject: @"Sequel Pro Tunnel" forKey: @"TUNNEL_NAME" ]; + [ task setEnvironment: environment ]; + + stdErrPipe = [[ NSPipe alloc ] init ]; + [ task setStandardError: stdErrPipe ]; + + [[ NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(stdErr:) name: @"NSFileHandleDataAvailableNotification" object:[ stdErrPipe fileHandleForReading]]; - - [[ stdErrPipe fileHandleForReading] waitForDataInBackgroundAndNotify ]; - - NSLog(T_START,@"Sequel Pro Tunnel"); - [ self setValue: S_CONNECTING forKey: @"status" ]; - [ task launch ]; - [[ NSNotificationCenter defaultCenter] postNotificationName:@"STMStatusChanged" object:self ]; - [ task waitUntilExit ]; - sleep(1); - [ self setValue: S_IDLE forKey: @"status" ]; - NSLog(T_STOP,@"Sequel Pro Tunnel"); - [[ NSNotificationCenter defaultCenter] removeObserver:self - name: @"NSFileHandleDataAvailableNotification" - object:[ stdErrPipe fileHandleForReading]]; - [ task release ]; - task = nil; - [ stdErrPipe release ]; - stdErrPipe = nil; - [[ NSNotificationCenter defaultCenter] postNotificationName:@"STMStatusChanged" object:self ]; - if (! shouldStop) + + [[ stdErrPipe fileHandleForReading] waitForDataInBackgroundAndNotify ]; + + NSLog(T_START,@"Sequel Pro Tunnel"); + [ self setValue: S_CONNECTING forKey: @"status" ]; + [ task launch ]; + [[ NSNotificationCenter defaultCenter] postNotificationName:@"STMStatusChanged" object:self ]; + [ task waitUntilExit ]; + sleep(1); + [ self setValue: S_IDLE forKey: @"status" ]; + NSLog(T_STOP,@"Sequel Pro Tunnel"); + [[ NSNotificationCenter defaultCenter] removeObserver:self + name: @"NSFileHandleDataAvailableNotification" + object:[ stdErrPipe fileHandleForReading]]; + [ task release ]; + task = nil; + [ stdErrPipe release ]; + stdErrPipe = nil; + [[ NSNotificationCenter defaultCenter] postNotificationName:@"STMStatusChanged" object:self ]; + if (! shouldStop) [ self startTunnel ]; - [ pool release ]; + [ pool release ]; } - (void)stdErr:(NSNotification*)aNotification { - NSData *data = [[ aNotification object ] availableData ]; - NSString *log = [[ NSString alloc ] initWithData: data encoding: NSASCIIStringEncoding ]; - BOOL wait = YES; - if ([ log length ]) - { + NSData *data = [[ aNotification object ] availableData ]; + NSString *log = [[ NSString alloc ] initWithData: data encoding: NSASCIIStringEncoding ]; + BOOL wait = YES; + if ([ log length ]) + { NSLog(log); NSArray *lines = [ log componentsSeparatedByString:@"\n" ]; NSEnumerator *e = [ lines objectEnumerator ]; @@ -205,8 +205,8 @@ Modified by Lorenz Textor for use with Sequel Pro } if (wait) [[ stdErrPipe fileHandleForReading ] waitForDataInBackgroundAndNotify ]; - } - [ log release] ; + } + [ log release] ; } // deallocation @@ -215,11 +215,11 @@ Modified by Lorenz Textor for use with Sequel Pro [self stopTunnel]; [task release]; - [stdErrPipe release]; - [status release]; + [stdErrPipe release]; + [status release]; [tunnelArguments release]; - [super dealloc]; + [super dealloc]; } @end |