diff options
author | rowanbeentje <rowan@beent.je> | 2012-03-17 15:32:00 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2012-03-17 15:32:00 +0000 |
commit | ac8ebfe4bba6d7da6edad87c75b174156d919621 (patch) | |
tree | 08a3c2843d3c520090f40e6341b26043a7ccf014 /Source/SPSSHTunnel.m | |
parent | 8886d935e933c6239aa9b35e900d96f7d07527c7 (diff) | |
parent | eab6df4de773259f90dd5a1d25e44ca4d2765bbf (diff) | |
download | sequelpro-ac8ebfe4bba6d7da6edad87c75b174156d919621.tar.gz sequelpro-ac8ebfe4bba6d7da6edad87c75b174156d919621.tar.bz2 sequelpro-ac8ebfe4bba6d7da6edad87c75b174156d919621.zip |
Merge in the SPMySQL Framework. This new framework should provide much of the functionality required from MCPKit and is based around its interface for relatively easy integration.
Externally visible changes as a result of this merge:
- Speed improvements, particularly when loading large data sets
- Stability improvements, particularly related to connection state after the connection is dropped (eg Issue #1256)
- Improved support for new MySQL data types, which should address Issue #1052.
- Database structure retrieval and query cancellation now use a single persistent helper connection instead of lots of connections on-demand. This should help Issue #1097.
- More internal commands now use queries instead of MySQL functions; for example USE queries are now used to trigger database selection, improving transcripts. This addresses Issue #1247.
- Improved internal encoding work; while this needs support within the UI, it lays the foundation for issues like Issue #1280.
Code improvements:
- Much improved class layouts including extensive category usage
- Improved documentation across framework methods
- Support for fast enumeration across result objects
- Rewrite fixes use of a number of deprecate functions
- Much less code duplication across result set types
- Improved encapsultation within the framework, limiting the number of methods exposed, and also not exposing all the MySQL headers
From the Readme file:
The SPMySQL Framework is intended to provide a stable MySQL connection framework, with the ability to run text-based queries and rapidly retrieve result sets with conversion from MySQL data types to Cocoa objects.
SPMySQL.framework has an interface loosely based around that provided by MCPKit by Serge Cohen and Bertrand Mansion (http://mysql-cocoa.sourceforge.net/), and in particular the heavily modified Sequel Pro version (http://www.sequelpro.com/). It is a full rewrite of the original framework, although it includes code from patches implementing the following Sequel Pro functionality, largely contributed by Hans-Jörg Bibiko, Stuart Connolly, Jakob Egger, and Rowan Beentje:
- Connection locking (Jakob et al)
- Ping & keepalive (Rowan et al)
- Query cancellation (Rowan et al)
- Delegate setup (Stuart et al)
- SSL support (Rowan et al)
- Connection checking (Rowan et al)
- Version state (Stuart et al)
- Maximum packet size control (Hans et al)
- Result multithreading and streaming (Rowan et al)
- Improved encoding support & switching (Rowan et al)
- Database structure; moved to inside the app (Hans et al)
- Query reattempts and error-handling approach (Rowan et al)
- Geometry result class (Hans et al)
- Connection proxy (Stuart et al)
Diffstat (limited to 'Source/SPSSHTunnel.m')
-rw-r--r-- | Source/SPSSHTunnel.m | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/Source/SPSSHTunnel.m b/Source/SPSSHTunnel.m index 0c25c181..1d4870b2 100644 --- a/Source/SPSSHTunnel.m +++ b/Source/SPSSHTunnel.m @@ -27,6 +27,7 @@ #import "RegexKitLite.h" #import "SPKeychain.h" #import "SPAlertSheets.h" +#import "SPMySQL.h" #import <netinet/in.h> @@ -81,7 +82,7 @@ requestedPassphrase = nil; task = nil; localPort = 0; - connectionState = PROXY_STATE_IDLE; + connectionState = SPMySQLProxyIdle; requestedResponse = NO; passwordInKeychain = NO; @@ -163,12 +164,12 @@ /* * Get the state of the connection. */ -- (NSInteger)state +- (SPMySQLConnectionProxyState)state { // See if an auth dialog is up if (![answerAvailableLock tryLock]) { - return PROXY_STATE_WAITING_FOR_AUTH; + return SPMySQLProxyWaitingForAuth; } [answerAvailableLock unlock]; @@ -204,7 +205,7 @@ { localPort = 0; - if (connectionState != PROXY_STATE_IDLE) return; + if (connectionState != SPMySQLProxyIdle) return; [debugMessagesLock lock]; [debugMessages removeAllObjects]; [debugMessagesLock unlock]; @@ -218,18 +219,18 @@ */ - (void)launchTask:(id) dummy { - if (connectionState != PROXY_STATE_IDLE || task) return; + if (connectionState != SPMySQLProxyIdle || task) return; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSMutableArray *taskArguments; NSMutableDictionary *taskEnvironment; NSString *authenticationAppPath; - connectionState = PROXY_STATE_CONNECTING; + connectionState = SPMySQLProxyConnecting; if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO]; // Enforce a parent window being present for dialogs if (!parentWindow) { - connectionState = PROXY_STATE_IDLE; + connectionState = SPMySQLProxyIdle; if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO]; if (lastError) [lastError release]; lastError = [[NSString alloc] initWithString:@"SSH Tunnel started without a parent window. A parent window must be present."]; @@ -279,7 +280,7 @@ // Abort if no local free port could be allocated if (!localPort || (useHostFallback && !localPortFallback)) { - connectionState = PROXY_STATE_IDLE; + connectionState = SPMySQLProxyIdle; if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO]; if (lastError) [lastError release]; lastError = [[NSString alloc] initWithString:NSLocalizedString(@"No local port could be allocated for the SSH Tunnel.", @"SSH tunnel could not be created because no local port could be allocated")]; @@ -379,8 +380,8 @@ object:nil]; // If the task closed unexpectedly, alert appropriately - if (connectionState != PROXY_STATE_IDLE) { - connectionState = PROXY_STATE_IDLE; + if (connectionState != SPMySQLProxyIdle) { + connectionState = SPMySQLProxyIdle; if (lastError) [lastError release]; lastError = [[NSString alloc] initWithString:NSLocalizedString(@"The SSH Tunnel has unexpectedly closed.", @"SSH tunnel unexpectedly closed")]; if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO]; @@ -400,7 +401,7 @@ */ - (void)disconnect { - if (connectionState == PROXY_STATE_IDLE) return; + if (connectionState == SPMySQLProxyIdle) return; // Before terminating the tunnel, check that it's actually running. This is to accommodate tunnels which // suddenly disappear as a result of network disconnections. @@ -434,17 +435,17 @@ if ([message rangeOfString:@"Entering interactive session."].location != NSNotFound || [message rangeOfString:@"mux_client_request_session: master session id: "].location != NSNotFound) { - connectionState = PROXY_STATE_CONNECTED; + connectionState = SPMySQLProxyConnected; if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO]; } if ([message rangeOfString:@"Connection established"].location != NSNotFound) { - connectionState = PROXY_STATE_WAITING_FOR_AUTH; + connectionState = SPMySQLProxyWaitingForAuth; if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO]; } if ([message rangeOfString:@"bind: Address already in use"].location != NSNotFound) { - connectionState = PROXY_STATE_IDLE; + connectionState = SPMySQLProxyIdle; [task terminate]; if (lastError) [lastError release]; lastError = [[NSString alloc] initWithString:NSLocalizedString(@"The SSH Tunnel was unable to bind to the local port. This error may occur if you already have an SSH connection to the same server and are using a 'LocalForward' setting in your SSH configuration.\n\nWould you like to fall back to a standard connection to localhost in order to use the existing tunnel?", @"SSH tunnel unable to bind to local port message")]; @@ -452,26 +453,26 @@ } if ([message rangeOfString:@"closed by remote host." ].location != NSNotFound) { - connectionState = PROXY_STATE_IDLE; + connectionState = SPMySQLProxyIdle; [task terminate]; if (lastError) [lastError release]; lastError = [[NSString alloc] initWithString:NSLocalizedString(@"The SSH Tunnel was closed 'by the remote host'. This may indicate a networking issue or a network timeout.", @"SSH tunnel was closed by remote host message")]; if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO]; } if ([message rangeOfString:@"Permission denied (" ].location != NSNotFound || [message rangeOfString:@"No more authentication methods to try" ].location != NSNotFound) { - connectionState = PROXY_STATE_IDLE; + connectionState = SPMySQLProxyIdle; [task terminate]; if (lastError) [lastError release]; lastError = [[NSString alloc] initWithString:NSLocalizedString(@"The SSH Tunnel could not authenticate with the remote host. Please check your password and ensure you still have access.", @"SSH tunnel authentication failed message")]; if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO]; } if ([message rangeOfString:@"connect failed: Connection refused" ].location != NSNotFound) { - connectionState = PROXY_STATE_FORWARDING_FAILED; + connectionState = SPMySQLProxyForwardingFailed; if (lastError) [lastError release]; lastError = [[NSString alloc] initWithString:NSLocalizedString(@"The SSH Tunnel was established successfully, but could not forward data to the remote port as the remote port refused the connection.", @"SSH tunnel forwarding port connection refused message")]; } if ([message rangeOfString:@"Operation timed out" ].location != NSNotFound) { - connectionState = PROXY_STATE_IDLE; + connectionState = SPMySQLProxyIdle; [task terminate]; if (lastError) [lastError release]; lastError = [[NSString alloc] initWithFormat:NSLocalizedString(@"The SSH Tunnel was unable to connect to host %@, or the request timed out.\n\nBe sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently %ld seconds).", @"SSH tunnel failed or timed out message"), sshHost, (long)[[[NSUserDefaults standardUserDefaults] objectForKey:SPConnectionTimeoutValue] integerValue]]; @@ -480,7 +481,7 @@ } } - if (connectionState != PROXY_STATE_IDLE) { + if (connectionState != SPMySQLProxyIdle) { [[standardError fileHandleForReading] waitForDataInBackgroundAndNotify]; } @@ -674,7 +675,7 @@ { delegate = nil; [[NSNotificationCenter defaultCenter] removeObserver:self]; - if (connectionState != PROXY_STATE_IDLE) [self disconnect]; + if (connectionState != SPMySQLProxyIdle) [self disconnect]; [sshHost release]; [sshLogin release]; [remoteHost release]; |