diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPConnectionController.h | 7 | ||||
-rw-r--r-- | Source/SPConnectionController.m | 46 | ||||
-rw-r--r-- | Source/SPConstants.h | 7 | ||||
-rw-r--r-- | Source/SPPreferenceController.m | 12 | ||||
-rw-r--r-- | Source/TableDocument.m | 38 |
5 files changed, 55 insertions, 55 deletions
diff --git a/Source/SPConnectionController.h b/Source/SPConnectionController.h index 824c2f46..d0a70148 100644 --- a/Source/SPConnectionController.h +++ b/Source/SPConnectionController.h @@ -30,13 +30,6 @@ #import "SPKeychain.h" #import "SPSSHTunnel.h" -enum spconnection_types -{ - SP_CONNECTION_TCPIP = 0, - SP_CONNECTION_SOCKET = 1, - SP_CONNECTION_SSHTUNNEL = 2 -}; - @class BWAnchoredButtonBar; @interface NSObject (BWAnchoredButtonBar) diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index d1bab4aa..27c5c8fd 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -109,8 +109,8 @@ [favoritesTable selectRowIndexes:[NSIndexSet indexSetWithIndex:tableRow] byExtendingSelection:NO]; [favoritesTable scrollRowToVisible:[favoritesTable selectedRow]]; } else { - previousType = SP_CONNECTION_TCPIP; - [self resizeTabViewToConnectionType:SP_CONNECTION_TCPIP animating:NO]; + previousType = SPTCPIPConnection; + [self resizeTabViewToConnectionType:SPTCPIPConnection animating:NO]; } // If the document is set to automatically connect, do so. @@ -149,13 +149,13 @@ - (IBAction)initiateConnection:(id)sender { // Ensure that host is not empty if this is a TCP/IP or SSH connection - if (([self type] == SP_CONNECTION_TCPIP || [self type] == SP_CONNECTION_SSHTUNNEL) && ![[self host] length]) { + if (([self type] == SPTCPIPConnection || [self type] == SPSSHTunnelConnection) && ![[self host] length]) { NSBeginAlertSheet(NSLocalizedString(@"Insufficient connection details", @"insufficient details message"), NSLocalizedString(@"OK", @"OK button"), nil, nil, documentWindow, self, nil, nil, nil, NSLocalizedString(@"Insufficient details provided to establish a connection. Please enter at least the hostname.", @"insufficient details informative message")); return; } // If SSH is enabled, ensure that the SSH host is not nil - if ([self type] == SP_CONNECTION_SSHTUNNEL && ![[self sshHost] length]) { + if ([self type] == SPSSHTunnelConnection && ![[self sshHost] length]) { NSBeginAlertSheet(NSLocalizedString(@"Insufficient connection details", @"insufficient details message"), NSLocalizedString(@"OK", @"OK button"), nil, nil, documentWindow, self, nil, nil, nil, NSLocalizedString(@"Insufficient details provided to establish a connection. Please enter the hostname for the SSH Tunnel, or disable the SSH Tunnel.", @"insufficient SSH tunnel details informative message")); return; } @@ -205,7 +205,7 @@ } // Initiate the SSH connection process for tunnels - if ([self type] == SP_CONNECTION_SSHTUNNEL) { + if ([self type] == SPSSHTunnelConnection) { [self performSelector:@selector(initiateSSHTunnelConnection) withObject:nil afterDelay:0.0]; return; } @@ -276,12 +276,12 @@ [progressIndicatorText display]; // Initialise to socket if appropriate. - if ([self type] == SP_CONNECTION_SOCKET) { + if ([self type] == SPSocketConnection) { mySQLConnection = [[MCPConnection alloc] initToSocket:[self socket] withLogin:[self user]]; // Otherwise, initialise to host, using tunnel if appropriate } else { - if ([self type] == SP_CONNECTION_SSHTUNNEL) { + if ([self type] == SPSSHTunnelConnection) { mySQLConnection = [[MCPConnection alloc] initToHost:@"127.0.0.1" withLogin:[self user] usingPort:[sshTunnel localPort]]; @@ -338,10 +338,10 @@ } 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]]; [self failConnectionWithTitle:NSLocalizedString(@"Access denied!", @"connection failed due to access denied title") errorMessage:errorMessage detail:nil]; - } else if ([self type] == SP_CONNECTION_SOCKET && (![self socket] || ![[self socket] length]) && ![mySQLConnection findSocketPath]) { + } 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]]; [self failConnectionWithTitle:NSLocalizedString(@"Socket not found!", @"socket not found title") errorMessage:errorMessage detail:nil]; - } else if ([self type] == SP_CONNECTION_SOCKET) { + } 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]]; [self failConnectionWithTitle:NSLocalizedString(@"Socket connection failed!", @"socket connection failed title") errorMessage:errorMessage detail:nil]; } else { @@ -443,14 +443,14 @@ NSString *tunnelPort = [[[errorDetailText string] componentsMatchedByRegex:@"LOCALHOST:([0-9]+)" capture:1L] lastObject]; // Change the connection type to standard TCP/IP - [self setType:SP_CONNECTION_TCPIP]; + [self setType:SPTCPIPConnection]; // Change connection details [self setPort:tunnelPort]; [self setHost:@"127.0.0.1"]; // Change to standard TCP/IP connection view - [self resizeTabViewToConnectionType:SP_CONNECTION_TCPIP animating:YES]; + [self resizeTabViewToConnectionType:SPTCPIPConnection animating:YES]; // Initiate the connection after half a second to give the connection view a chance to resize [self performSelector:@selector(initiateConnection:) withObject:self afterDelay:0.5]; @@ -531,7 +531,7 @@ [self resizeTabViewToConnectionType:selectedTabView animating:YES]; // Update the host as appropriate - if ((selectedTabView != SP_CONNECTION_SOCKET) && [[self host] isEqualToString:@"localhost"]) { + if ((selectedTabView != SPSocketConnection) && [[self host] isEqualToString:@"localhost"]) { [self setHost:@""]; } @@ -571,13 +571,13 @@ frameRect = [connectionResizeContainer frame]; switch (theType) { - case SP_CONNECTION_TCPIP: + case SPTCPIPConnection: targetResizeRect = [standardConnectionFormContainer frame]; break; - case SP_CONNECTION_SOCKET: + case SPSocketConnection: targetResizeRect = [socketConnectionFormContainer frame]; break; - case SP_CONNECTION_SSHTUNNEL: + case SPSSHTunnelConnection: targetResizeRect = [sshConnectionFormContainer frame]; break; } @@ -597,7 +597,7 @@ */ - (BOOL) checkHost { - if ([self type] != SP_CONNECTION_SOCKET && [[self host] isEqualToString:@"localhost"]) { + if ([self type] != SPSocketConnection && [[self host] isEqualToString:@"localhost"]) { NSBeginAlertSheet(NSLocalizedString(@"You have entered 'localhost' for a non-socket connection", @"title of error when using 'localhost' for a network connection"), NSLocalizedString(@"Use 127.0.0.1", @"Use 127.0.0.1 button"), // Main button NSLocalizedString(@"Connect via socket", @"Connect via socket button"), // Alternate button @@ -621,7 +621,7 @@ { [sheet orderOut:self]; if (returnCode == NSAlertAlternateReturn) { - [self setType:SP_CONNECTION_SOCKET]; + [self setType:SPSocketConnection]; [self setHost:@""]; } else { [self setHost:@"127.0.0.1"]; @@ -665,7 +665,7 @@ if (connectionSSHKeychainItemAccount) [connectionSSHKeychainItemAccount release], connectionSSHKeychainItemAccount = nil; // Update key-value properties from the selected favourite, using empty strings where not found - [self setType:([self valueForKeyPath:@"selectedFavorite.type"] ? [[self valueForKeyPath:@"selectedFavorite.type"] intValue] : SP_CONNECTION_TCPIP)]; + [self setType:([self valueForKeyPath:@"selectedFavorite.type"] ? [[self valueForKeyPath:@"selectedFavorite.type"] intValue] : SPTCPIPConnection)]; [self setName:([self valueForKeyPath:@"selectedFavorite.name"] ? [self valueForKeyPath:@"selectedFavorite.name"] : @"")]; [self setHost:([self valueForKeyPath:@"selectedFavorite.host"] ? [self valueForKeyPath:@"selectedFavorite.host"] : @"")]; [self setSocket:([self valueForKeyPath:@"selectedFavorite.socket"] ? [self valueForKeyPath:@"selectedFavorite.socket"] : @"")]; @@ -679,7 +679,7 @@ // Check whether the password exists in the keychain, and if so add it; also record the // keychain details so we can pass around only those details if the password doesn't change connectionKeychainItemName = [[keychain nameForFavoriteName:[self valueForKeyPath:@"selectedFavorite.name"] id:[self valueForKeyPath:@"selectedFavorite.id"]] retain]; - connectionKeychainItemAccount = [[keychain accountForUser:[self valueForKeyPath:@"selectedFavorite.user"] host:(([self type] == SP_CONNECTION_SOCKET)?@"localhost":[self valueForKeyPath:@"selectedFavorite.host"]) database:[self valueForKeyPath:@"selectedFavorite.database"]] retain]; + connectionKeychainItemAccount = [[keychain accountForUser:[self valueForKeyPath:@"selectedFavorite.user"] host:(([self type] == SPSocketConnection)?@"localhost":[self valueForKeyPath:@"selectedFavorite.host"]) database:[self valueForKeyPath:@"selectedFavorite.database"]] retain]; [self setPassword:[keychain getPasswordForName:connectionKeychainItemName account:connectionKeychainItemAccount]]; if (![[self password] length]) { [connectionKeychainItemName release], connectionKeychainItemName = nil; @@ -717,18 +717,18 @@ { NSString *thePassword, *theSSHPassword; NSNumber *favoriteid = [NSNumber numberWithInt:[[NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]] hash]]; - NSString *favoriteName = [[self name] length]?[self name]:[NSString stringWithFormat:@"%@@%@", ([self user] && [[self user] length])?[self user]:@"anonymous", (([self type] == SP_CONNECTION_SOCKET)?@"localhost":[self host])]; + NSString *favoriteName = [[self name] length]?[self name]:[NSString stringWithFormat:@"%@@%@", ([self user] && [[self user] length])?[self user]:@"anonymous", (([self type] == SPSocketConnection)?@"localhost":[self host])]; if (![[self name] length] && [self database] && ![[self database] isEqualToString:@""]) favoriteName = [NSString stringWithFormat:@"%@ %@", [self database], favoriteName]; // Ensure that host is not empty if this is a TCP/IP or SSH connection - if (([self type] == SP_CONNECTION_TCPIP || [self type] == SP_CONNECTION_SSHTUNNEL) && ![[self host] length]) { + if (([self type] == SPTCPIPConnection || [self type] == SPSSHTunnelConnection) && ![[self host] length]) { NSRunAlertPanel(NSLocalizedString(@"Insufficient connection details", @"insufficient details message"), NSLocalizedString(@"Insufficient details provided to establish a connection. Please provide at least a host.", @"insufficient details informative message"), NSLocalizedString(@"OK", @"OK button"), nil, nil); return; } // If SSH is enabled, ensure that the SSH host is not nil - if ([self type] == SP_CONNECTION_SSHTUNNEL && ![[self sshHost] length]) { + if ([self type] == SPSSHTunnelConnection && ![[self sshHost] length]) { NSRunAlertPanel(NSLocalizedString(@"Insufficient connection details", @"insufficient details message"), NSLocalizedString(@"Please enter the hostname for the SSH Tunnel, or disable the SSH Tunnel.", @"message of panel when ssh details are incomplete"), NSLocalizedString(@"OK", @"OK button"), nil, nil); return; } @@ -770,7 +770,7 @@ if (thePassword && ![thePassword isEqualToString:@""]) { [keychain addPassword:thePassword forName:[keychain nameForFavoriteName:favoriteName id:[NSString stringWithFormat:@"%i", [favoriteid intValue]]] - account:[keychain accountForUser:[self user] host:(([self type] == SP_CONNECTION_SOCKET)?@"localhost":[self host]) database:[self database]]]; + account:[keychain accountForUser:[self user] host:(([self type] == SPSocketConnection)?@"localhost":[self host]) database:[self database]]]; } // Add the SSH password to keychain as appropriate diff --git a/Source/SPConstants.h b/Source/SPConstants.h index af884ac3..30645a7d 100644 --- a/Source/SPConstants.h +++ b/Source/SPConstants.h @@ -74,6 +74,13 @@ typedef enum { SPImportExportQueryMode = 2 } SPQueryMode; +// Connection types +typedef enum { + SPTCPIPConnection = 0, + SPSocketConnection = 1, + SPSSHTunnelConnection = 2 +} SPConnectionType; + // Kill mode constants extern NSString *SPKillProcessQueryMode; extern NSString *SPKillProcessConnectionMode; diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m index 3e938ff0..da5c03ae 100644 --- a/Source/SPPreferenceController.m +++ b/Source/SPPreferenceController.m @@ -336,7 +336,7 @@ // Remove passwords from the Keychain [keychain deletePasswordForName:[keychain nameForFavoriteName:name id:favoriteid] - account:[keychain accountForUser:user host:((type == SP_CONNECTION_SOCKET)?@"localhost":host) database:database]]; + account:[keychain accountForUser:user host:((type == SPSocketConnection)?@"localhost":host) database:database]]; [keychain deletePasswordForName:[keychain nameForSSHForFavoriteName:name id:favoriteid] account:[keychain accountForSSHUser:sshUser sshHost:sshHost]]; @@ -370,7 +370,7 @@ // Select the keychain passwords for duplication keychainName = [keychain nameForFavoriteName:[favorite objectForKey:@"name"] id:[favorite objectForKey:@"id"]]; - keychainAccount = [keychain accountForUser:[favorite objectForKey:@"user"] host:((duplicatedFavoriteType == SP_CONNECTION_SOCKET)?@"localhost":[favorite objectForKey:@"host"]) database:[favorite objectForKey:@"database"]]; + keychainAccount = [keychain accountForUser:[favorite objectForKey:@"user"] host:((duplicatedFavoriteType == SPSocketConnection)?@"localhost":[favorite objectForKey:@"host"]) database:[favorite objectForKey:@"database"]]; password = [keychain getPasswordForName:keychainName account:keychainAccount]; keychainSSHName = [keychain nameForSSHForFavoriteName:[favorite objectForKey:@"name"] id:[favorite objectForKey:@"id"]]; keychainSSHAccount = [keychain accountForSSHUser:[favorite objectForKey:@"sshUser"] sshHost:[favorite objectForKey:@"sshHost"]]; @@ -641,7 +641,7 @@ { if ([cell isKindOfClass:[SPFavoriteTextFieldCell class]]) { [cell setFavoriteName:[[[favoritesController arrangedObjects] objectAtIndex:index] objectForKey:@"name"]]; - if ([[[[favoritesController arrangedObjects] objectAtIndex:index] objectForKey:@"type"] intValue] == SP_CONNECTION_SOCKET) { + if ([[[[favoritesController arrangedObjects] objectAtIndex:index] objectForKey:@"type"] intValue] == SPSocketConnection) { [cell setFavoriteHost:@"localhost"]; } else { [cell setFavoriteHost:[[[favoritesController arrangedObjects] objectAtIndex:index] objectForKey:@"host"]]; @@ -673,7 +673,7 @@ // Retrieve and set the password. NSString *keychainName = [keychain nameForFavoriteName:[currentFavorite objectForKey:@"name"] id:[currentFavorite objectForKey:@"id"]]; - NSString *keychainAccount = [keychain accountForUser:[currentFavorite objectForKey:@"user"] host:(([[currentFavorite objectForKey:@"type"] intValue] == SP_CONNECTION_SOCKET)?@"localhost":[currentFavorite objectForKey:@"host"]) database:[currentFavorite objectForKey:@"database"]]; + NSString *keychainAccount = [keychain accountForUser:[currentFavorite objectForKey:@"user"] host:(([[currentFavorite objectForKey:@"type"] intValue] == SPSocketConnection)?@"localhost":[currentFavorite objectForKey:@"host"]) database:[currentFavorite objectForKey:@"database"]]; NSString *passwordValue = [keychain getPasswordForName:keychainName account:keychainAccount]; [standardPasswordField setStringValue:passwordValue]; [socketPasswordField setStringValue:passwordValue]; @@ -881,8 +881,8 @@ NSString *passwordValue; NSString *oldKeychainName, *newKeychainName; NSString *oldKeychainAccount, *newKeychainAccount; - NSString *oldHostnameForPassword = ([[currentFavorite objectForKey:@"type"] intValue] == SP_CONNECTION_SOCKET) ? @"localhost" : [currentFavorite objectForKey:@"host"]; - NSString *newHostnameForPassword = ([[favoritesController valueForKeyPath:@"selection.type"] intValue] == SP_CONNECTION_SOCKET) ? @"localhost" : [favoritesController valueForKeyPath:@"selection.host"]; + NSString *oldHostnameForPassword = ([[currentFavorite objectForKey:@"type"] intValue] == SPSocketConnection) ? @"localhost" : [currentFavorite objectForKey:@"host"]; + NSString *newHostnameForPassword = ([[favoritesController valueForKeyPath:@"selection.type"] intValue] == SPSocketConnection) ? @"localhost" : [favoritesController valueForKeyPath:@"selection.host"]; // SQL passwords are indexed by name, host, user and database. If any of these // have changed, or a standard password field has, alter the keychain item to match. diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 69fc54d5..fa07e143 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -421,14 +421,14 @@ connection = [NSDictionary dictionaryWithDictionary:[data objectForKey:@"connection"]]; if([connection objectForKey:@"type"]) { - if([[connection objectForKey:@"type"] isEqualToString:@"SP_CONNECTION_TCPIP"]) - connectionType = SP_CONNECTION_TCPIP; - else if([[connection objectForKey:@"type"] isEqualToString:@"SP_CONNECTION_SOCKET"]) - connectionType = SP_CONNECTION_SOCKET; - else if([[connection objectForKey:@"type"] isEqualToString:@"SP_CONNECTION_SSHTUNNEL"]) - connectionType = SP_CONNECTION_SSHTUNNEL; + if([[connection objectForKey:@"type"] isEqualToString:@"SPTCPIPConnection"]) + connectionType = SPTCPIPConnection; + else if([[connection objectForKey:@"type"] isEqualToString:@"SPSocketConnection"]) + connectionType = SPSocketConnection; + else if([[connection objectForKey:@"type"] isEqualToString:@"SPSSHTunnelConnection"]) + connectionType = SPSSHTunnelConnection; else - connectionType = SP_CONNECTION_TCPIP; + connectionType = SPTCPIPConnection; [connectionController setType:connectionType]; [connectionController resizeTabViewToConnectionType:connectionType animating:NO]; @@ -454,10 +454,10 @@ [connectionController setPassword:pw]; } - if(connectionType == SP_CONNECTION_SOCKET && [connection objectForKey:@"socket"]) + if(connectionType == SPSocketConnection && [connection objectForKey:@"socket"]) [connectionController setSocket:[connection objectForKey:@"socket"]]; - if(connectionType == SP_CONNECTION_SSHTUNNEL) { + if(connectionType == SPSSHTunnelConnection) { if([connection objectForKey:@"ssh_host"]) [connectionController setSshHost:[connection objectForKey:@"ssh_host"]]; if([connection objectForKey:@"ssh_user"]) @@ -2156,7 +2156,7 @@ */ - (NSString *)host { - if ([connectionController type] == SP_CONNECTION_SOCKET) return @"localhost"; + if ([connectionController type] == SPSocketConnection) return @"localhost"; NSString *theHost = [connectionController host]; if (!theHost) theHost = @""; return theHost; @@ -2170,7 +2170,7 @@ if ([connectionController name] && [[connectionController name] length]) { return [connectionController name]; } - if ([connectionController type] == SP_CONNECTION_SOCKET) { + if ([connectionController type] == SPSocketConnection) { return [NSString stringWithFormat:@"%@@localhost", ([connectionController user] && [[connectionController user] length])?[connectionController user]:@"anonymous"]; } return [NSString stringWithFormat:@"%@@%@", ([connectionController user] && [[connectionController user] length])?[connectionController user]:@"anonymous", [connectionController host]?[connectionController host]:@""]; @@ -2556,22 +2556,22 @@ [connection setObject:[self user] forKey:@"user"]; switch([connectionController type]) { - case SP_CONNECTION_TCPIP: - aString = @"SP_CONNECTION_TCPIP"; + case SPTCPIPConnection: + aString = @"SPTCPIPConnection"; break; - case SP_CONNECTION_SOCKET: - aString = @"SP_CONNECTION_SOCKET"; + case SPSocketConnection: + aString = @"SPSocketConnection"; [connection setObject:[connectionController socket] forKey:@"socket"]; break; - case SP_CONNECTION_SSHTUNNEL: - aString = @"SP_CONNECTION_SSHTUNNEL"; + case SPSSHTunnelConnection: + aString = @"SPSSHTunnelConnection"; [connection setObject:[connectionController sshHost] forKey:@"ssh_host"]; [connection setObject:[connectionController sshUser] forKey:@"ssh_user"]; if([connectionController port] && [[connectionController port] length]) [connection setObject:[NSNumber numberWithInt:[[connectionController sshPort] intValue]] forKey:@"ssh_port"]; break; default: - aString = @"SP_CONNECTION_TCPIP"; + aString = @"SPTCPIPConnection"; } [connection setObject:aString forKey:@"type"]; @@ -2580,7 +2580,7 @@ NSString *pw = [self keychainPasswordForConnection:nil]; if(![pw length]) pw = [connectionController password]; [connection setObject:pw forKey:@"password"]; - if([connectionController type] == SP_CONNECTION_SSHTUNNEL) + if([connectionController type] == SPSSHTunnelConnection) [connection setObject:[connectionController sshPassword] forKey:@"ssh_password"]; } |