aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPConnectionController.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/SPConnectionController.m')
-rw-r--r--Source/SPConnectionController.m73
1 files changed, 42 insertions, 31 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index 94af9056..acec49de 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -25,6 +25,7 @@
#import "SPConnectionController.h"
#import "SPDatabaseDocument.h"
+#import "SPMySQL.h"
#ifndef SP_REFACTOR /* headers */
#import "SPAppController.h"
@@ -437,7 +438,7 @@
return;
}
- if (newState == PROXY_STATE_IDLE) {
+ if (newState == SPMySQLProxyIdle) {
#ifndef SP_REFACTOR
[tableDocument setTitlebarStatus:NSLocalizedString(@"SSH Disconnected", @"SSH disconnected titlebar marker")];
#endif
@@ -445,7 +446,7 @@
[self failConnectionWithTitle:NSLocalizedString(@"SSH connection failed!", @"SSH connection failed title") errorMessage:[theTunnel lastError] detail:[sshTunnel debugMessages]];
[self _restoreConnectionInterface];
}
- else if (newState == PROXY_STATE_CONNECTED) {
+ else if (newState == SPMySQLProxyConnected) {
#ifndef SP_REFACTOR
[tableDocument setTitlebarStatus:NSLocalizedString(@"SSH Connected", @"SSH connected titlebar marker")];
#endif
@@ -600,7 +601,7 @@
/**
* Opens the SSH/SSL key selection window, ready to select a key file.
*/
-- (IBAction)chooseKeyLocation:(id)sender
+- (IBAction)chooseKeyLocation:(NSButton *)sender
{
#ifndef SP_REFACTOR /* favorites */
[favoritesTable deselectAll:self];
@@ -930,7 +931,7 @@
/**
* Reverses the favorites table view sorting based on the selected criteria.
*/
-- (void)reverseSortFavorites:(id)sender
+- (void)reverseSortFavorites:(NSMenuItem *)sender
{
reverseFavoritesSort = (![sender state]);
@@ -1388,22 +1389,26 @@
- (void)_initiateMySQLConnectionInBackground
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ mySQLConnection = [[SPMySQLConnection alloc] init];
+
+ // Set up shared details
+ [mySQLConnection setUsername:[self user]];
// Initialise to socket if appropriate.
if ([self type] == SPSocketConnection) {
- mySQLConnection = [[MCPConnection alloc] initToSocket:[self socket] withLogin:[self user]];
+ [mySQLConnection setUseSocket:YES];
+ [mySQLConnection setSocketPath:[self socket]];
- // Otherwise, initialise to host, using tunnel if appropriate
+ // Otherwise, initialise to host, using tunnel if appropriate
} else {
+ [mySQLConnection setUseSocket:NO];
if ([self type] == SPSSHTunnelConnection) {
- mySQLConnection = [[MCPConnection alloc] initToHost:@"127.0.0.1"
- withLogin:[self user]
- usingPort:[sshTunnel localPort]];
- [mySQLConnection setConnectionProxy:sshTunnel];
+ [mySQLConnection setHost:@"127.0.0.1"];
+ [mySQLConnection setPort:[sshTunnel localPort]];
+ [mySQLConnection setProxy:sshTunnel];
} else {
- mySQLConnection = [[MCPConnection alloc] initToHost:[self host]
- withLogin:[self user]
- usingPort:([[self port] length]?[[self port] integerValue]:3306)];
+ [mySQLConnection setHost:[self host]];
+ if ([[self port] length]) [mySQLConnection setPort:[[self port] integerValue]];
}
}
@@ -1414,24 +1419,30 @@
// Enable SSL if set
if ([self useSSL]) {
- [mySQLConnection setSSL:YES
- usingKeyFilePath:[self sslKeyFileLocationEnabled] ? [self sslKeyFileLocation] : nil
- certificatePath:[self sslCertificateFileLocationEnabled] ? [self sslCertificateFileLocation] : nil
- certificateAuthorityCertificatePath:[self sslCACertFileLocationEnabled] ? [self sslCACertFileLocation] : nil];
+ [mySQLConnection setUseSSL:YES];
+ if ([self sslKeyFileLocationEnabled]) {
+ [mySQLConnection setSslKeyFilePath:[self sslKeyFileLocation]];
+ }
+ if ([self sslCertificateFileLocationEnabled]) {
+ [mySQLConnection setSslCertificatePath:[self sslCertificateFileLocation]];
+ }
+ if ([self sslCACertFileLocationEnabled]) {
+ [mySQLConnection setSslCACertificatePath:[self sslCACertFileLocation]];
+ }
}
-
// Connection delegate must be set before actual connection attempt is made
[mySQLConnection setDelegate:tableDocument];
+
#ifndef SP_REFACTOR /* set mysql connection settings from prefs */
// Set whether or not we should enable delegate logging according to the prefs
[mySQLConnection setDelegateQueryLogging:[prefs boolForKey:SPConsoleEnableLogging]];
#endif
// Set options from preferences
- [mySQLConnection setConnectionTimeout:[[prefs objectForKey:SPConnectionTimeoutValue] integerValue]];
+ [mySQLConnection setTimeout:[[prefs objectForKey:SPConnectionTimeoutValue] integerValue]];
[mySQLConnection setUseKeepAlive:[[prefs objectForKey:SPUseKeepAlive] boolValue]];
- [mySQLConnection setKeepAliveInterval:[[prefs objectForKey:SPKeepAliveInterval] doubleValue]];
+ [mySQLConnection setKeepAliveInterval:[[prefs objectForKey:SPKeepAliveInterval] floatValue]];
// Connect
[mySQLConnection connect];
@@ -1443,7 +1454,7 @@
[[NSRunLoop currentRunLoop] runMode:NSModalPanelRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.2]];
// If the state is connection refused, attempt the MySQL connection again with the host using the hostfield value.
- if ([sshTunnel state] == PROXY_STATE_FORWARDING_FAILED) {
+ if ([sshTunnel state] == SPMySQLProxyForwardingFailed) {
if ([sshTunnel localPortFallback]) {
[mySQLConnection setPort:[sshTunnel localPortFallback]];
[mySQLConnection connect];
@@ -1456,20 +1467,20 @@
if (![mySQLConnection isConnected]) {
NSString *errorMessage = @"";
- if (sshTunnel && [sshTunnel state] == PROXY_STATE_FORWARDING_FAILED) {
- errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@ because the port connection via SSH was refused.\n\nPlease ensure that your MySQL host is set up to allow TCP/IP connections (no --skip-networking) and is configured to allow connections from the host you are tunnelling via.\n\nYou may also want to check the port is correct and that you have the necessary privileges.\n\nChecking the error detail will show the SSH debug log which may provide more details.\n\nMySQL said: %@", @"message of panel when SSH port forwarding failed"), [self host], [mySQLConnection getLastErrorMessage]];
+ if (sshTunnel && [sshTunnel state] == SPMySQLProxyForwardingFailed) {
+ errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@ because the port connection via SSH was refused.\n\nPlease ensure that your MySQL host is set up to allow TCP/IP connections (no --skip-networking) and is configured to allow connections from the host you are tunnelling via.\n\nYou may also want to check the port is correct and that you have the necessary privileges.\n\nChecking the error detail will show the SSH debug log which may provide more details.\n\nMySQL said: %@", @"message of panel when SSH port forwarding failed"), [self host], [mySQLConnection lastErrorMessage]];
[[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"SSH port forwarding failed", @"title when ssh tunnel port forwarding failed") errorMessage:errorMessage detail:[sshTunnel debugMessages]];
- } else if ([mySQLConnection getLastErrorID] == 1045) { // "Access denied" error
- errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@ because access was denied.\n\nDouble-check your username and password and ensure that access from your current location is permitted.\n\nMySQL said: %@", @"message of panel when connection to host failed due to access denied error"), [self host], [mySQLConnection getLastErrorMessage]];
+ } else if ([mySQLConnection lastErrorID] == 1045) { // "Access denied" error
+ errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@ because access was denied.\n\nDouble-check your username and password and ensure that access from your current location is permitted.\n\nMySQL said: %@", @"message of panel when connection to host failed due to access denied error"), [self host], [mySQLConnection lastErrorMessage]];
[[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"Access denied!", @"connection failed due to access denied title") errorMessage:errorMessage detail:nil];
- } else if ([self type] == SPSocketConnection && (![self socket] || ![[self socket] length]) && ![mySQLConnection findSocketPath]) {
- errorMessage = [NSString stringWithFormat:NSLocalizedString(@"The socket file could not be found in any common location. Please supply the correct socket location.\n\nMySQL said: %@", @"message of panel when connection to socket failed because optional socket could not be found"), [mySQLConnection getLastErrorMessage]];
+ } else if ([self type] == SPSocketConnection && (![self socket] || ![[self socket] length]) && ![SPMySQLConnection findSocketPath]) {
+ errorMessage = [NSString stringWithFormat:NSLocalizedString(@"The socket file could not be found in any common location. Please supply the correct socket location.\n\nMySQL said: %@", @"message of panel when connection to socket failed because optional socket could not be found"), [mySQLConnection lastErrorMessage]];
[[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"Socket not found!", @"socket not found title") errorMessage:errorMessage detail:nil];
} else if ([self type] == SPSocketConnection) {
- errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect via the socket, or the request timed out.\n\nDouble-check that the socket path is correct and that you have the necessary privileges, and that the server is running.\n\nMySQL said: %@", @"message of panel when connection to host failed"), [mySQLConnection getLastErrorMessage]];
+ errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect via the socket, or the request timed out.\n\nDouble-check that the socket path is correct and that you have the necessary privileges, and that the server is running.\n\nMySQL said: %@", @"message of panel when connection to host failed"), [mySQLConnection lastErrorMessage]];
[[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"Socket connection failed!", @"socket connection failed title") errorMessage:errorMessage detail:nil];
} else {
- errorMessage = [NSString stringWithFormat:NSLocalizedString(@"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).\n\nMySQL said: %@", @"message of panel when connection to host failed"), [self host], (long)[[prefs objectForKey:SPConnectionTimeoutValue] integerValue], [mySQLConnection getLastErrorMessage]];
+ errorMessage = [NSString stringWithFormat:NSLocalizedString(@"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).\n\nMySQL said: %@", @"message of panel when connection to host failed"), [self host], (long)[[prefs objectForKey:SPConnectionTimeoutValue] integerValue], [mySQLConnection lastErrorMessage]];
[[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"Connection failed!", @"connection failed title") errorMessage:errorMessage detail:nil];
}
@@ -1489,8 +1500,8 @@
}
if ([self database] && ![[self database] isEqualToString:@""]) {
- if (![mySQLConnection selectDB:[self database]]) {
- [[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"Could not select database", @"message when database selection failed") errorMessage:[NSString stringWithFormat:NSLocalizedString(@"Connected to host, but unable to connect to database %@.\n\nBe sure that the database exists and that you have the necessary privileges.\n\nMySQL said: %@", @"message of panel when connection to db failed"), [self database], [mySQLConnection getLastErrorMessage]] detail:nil];
+ if (![mySQLConnection selectDatabase:[self database]]) {
+ [[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"Could not select database", @"message when database selection failed") errorMessage:[NSString stringWithFormat:NSLocalizedString(@"Connected to host, but unable to connect to database %@.\n\nBe sure that the database exists and that you have the necessary privileges.\n\nMySQL said: %@", @"message of panel when connection to db failed"), [self database], [mySQLConnection lastErrorMessage]] detail:nil];
// Tidy up
isConnecting = NO;