Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI for username/password #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,012 changes: 320 additions & 1,692 deletions Resources/English.lproj/ServerDisplay.nib/designable.nib

Large diffs are not rendered by default.

Binary file modified Resources/English.lproj/ServerDisplay.nib/keyedobjects.nib
Binary file not shown.
2 changes: 2 additions & 0 deletions Source/IServerData.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ typedef enum
EDIT_ADDRESS,
EDIT_PORT,
EDIT_NAME,
EDIT_USERNAME,
EDIT_PASSWORD,
CONNECT,
} SUPPORT_TYPE;
Expand All @@ -41,6 +42,7 @@ typedef enum

- (NSString*)name;
- (NSString*)host;
- (NSString*)userName;
- (NSString*)password;
- (bool)rememberPassword;
- (int)port;
Expand Down
3 changes: 3 additions & 0 deletions Source/RFBConnection.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
ByteReader *currentReader;
RFBHandshaker *handshaker;
id<IServerData> server_;
NSString *userName;
NSString *password;
RFBProtocol *rfbProtocol;
CARD16 lastMouseX; // location of last mouse position we sent
Expand Down Expand Up @@ -95,6 +96,7 @@

- (void)setRfbView:(RFBView *)view;
- (void)setSession:(Session *)aSession;
- (void)setUserName:(NSString *)userName;
- (void)setPassword:(NSString *)password;
- (void)setSshTunnel:(SshTunnel *)tunnel;
- (void)setReader:(ByteReader*)aReader;
Expand Down Expand Up @@ -133,6 +135,7 @@
- (Profile*)profile;
- (int) protocolMajorVersion;
- (int) protocolMinorVersion;
- (NSString*)userName;
- (NSString*)password;
- (BOOL)connectShared;
- (BOOL)viewOnly;
Expand Down
12 changes: 12 additions & 0 deletions Source/RFBConnection.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ - (id)initWithFileHandle:(NSFileHandle*)file server:(id<IServerData>)server
currentReader = nil;

server_ = [(id)server retain];
userName = [[server userName] retain];
password = [[server password] retain];

_eventFilter = [[EventFilter alloc] init];
Expand Down Expand Up @@ -177,6 +178,12 @@ - (void)setSession:(Session *)aSession
session = aSession;
}

- (void)setUserName:(NSString *)aUserName
{
[userName release];
userName = [aUserName retain];
}

- (void)setPassword:(NSString *)aPassword
{
[password release];
Expand Down Expand Up @@ -300,6 +307,11 @@ - (void)start:(ServerInitMessage*)info
handshaker = nil;
}

- (NSString*)userName
{
return userName;
}

- (NSString*)password
{
return password;
Expand Down
13 changes: 11 additions & 2 deletions Source/RFBHandshaker.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,18 @@ - (void)setAuthArray:(NSData*)authTypeArray {
}

- (void)atenDiscardDone {
const char *userName = [connection.userName UTF8String];
if (userName == NULL) {
userName = "";
}
const char *password = [connection.password UTF8String];
if (password == NULL) {
password = "";
}

unsigned char auth[48] = {0}; // *SPIT*
strlcpy((char*) &auth[0], "testuser", 24);
strlcpy((char*) &auth[24], "testpass", 24);
strlcpy((char*) &auth[0], userName, 24);
strlcpy((char*) &auth[24], password, 24);
[connection writeBytes:&auth[0] length:sizeof(auth)];
[connection setReader:authResultReader];
}
Expand Down
3 changes: 3 additions & 0 deletions Source/ServerBase.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// This represents all the data and settings needed to connect to a VNC server.
@interface ServerBase : NSObject <IServerData> {
NSString* _host;
NSString* _userName;
NSString* _password;
int _port;
bool _shared;
Expand All @@ -52,6 +53,7 @@

- (NSString*)name;
- (NSString*)host;
- (NSString*)userName;
- (NSString*)password;
- (BOOL)rememberPassword;
- (int)port;
Expand All @@ -68,6 +70,7 @@

- (void)setHost: (NSString*)host;
- (BOOL)setHostAndPort: (NSString*)host;
- (void)setUserName: (NSString*)userName;
- (void)setPassword: (NSString*)password;
- (void)setDisplay: (int)display;
- (void)setShared: (bool)shared;
Expand Down
12 changes: 12 additions & 0 deletions Source/ServerBase.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ - (id)init
if( self = [super init] )
{
_host = @"localhost";
_userName = nil;
_password = nil;
_port = 5900;
_shared = NO;
Expand Down Expand Up @@ -81,6 +82,11 @@ - (NSString*)host
return _host;
}

- (NSString*)userName
{
return _userName;
}

- (NSString*)password
{
return _password;
Expand Down Expand Up @@ -204,6 +210,12 @@ - (BOOL)setHostAndPort: (NSString*)hostAndPort
return NO;
}

- (void)setUserName:(NSString *)userName
{
[_userName autorelease];
_userName = [userName retain];
}

- (void)setPassword: (NSString*)password
{
[_password autorelease];
Expand Down
2 changes: 2 additions & 0 deletions Source/ServerDataViewController.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
IBOutlet NSTextField *display;
IBOutlet NSTextField *displayDescription;
IBOutlet NSTextField *hostName;
IBOutlet NSTextField *userName;
IBOutlet NSTextField *password;
IBOutlet NSPopUpButton *profilePopup;
IBOutlet NSButton *rememberPwd;
Expand Down Expand Up @@ -66,6 +67,7 @@
- (void)setServer:(id<IServerData>)server;
- (id<IServerData>)server;

- (IBAction)userNameChanged:(id)sender;
- (IBAction)passwordChanged:(id)sender;
- (IBAction)rememberPwdChanged:(id)sender;
- (IBAction)profileSelectionChanged:(id)sender;
Expand Down
67 changes: 43 additions & 24 deletions Source/ServerDataViewController.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ - (id)init
if (self = [super init])
{
[NSBundle loadNibNamed:@"ServerDisplay.nib" owner:self];

selfTerminate = NO;
removedSaveCheckbox = NO;

[connectIndicatorText setStringValue:@""];
[box setBorderType:NSNoBorder];

connectionWaiter = nil;

[self loadProfileIntoView];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateProfileView:)
name:ProfileListChangeMsg
object:(id)[ProfileDataManager sharedInstance]];
}

return self;
}

Expand All @@ -68,7 +68,7 @@ - (id)initWithServer:(id<IServerData>)server
{
[self setServer:server];
}

return self;
}

Expand All @@ -77,13 +77,13 @@ - (id)initWithReleaseOnCloseOrConnect
if (self = [self init])
{
selfTerminate = YES;

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(windowClose:)
name:NSWindowWillCloseNotification
object:(id)[self window]];
}

return self;
}

Expand All @@ -94,11 +94,11 @@ - (void)dealloc
{
[save release];
}

[connectionWaiter cancel];
[connectionWaiter release];
[super dealloc];

[[NSNotificationCenter defaultCenter] removeObserver:self];
}

Expand All @@ -111,18 +111,18 @@ - (void)setServer:(id<IServerData>)server
object:(id)mServer];
[(id)mServer autorelease];
}

mServer = [(id)server retain];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateView:)
name:ServerChangeMsg
object:(id)mServer];

[self updateView:nil];
}

- (void)updateView:(id)notification
{
{
// Set properties in dialog box
if (mServer != nil)
{
Expand All @@ -133,12 +133,13 @@ - (void)updateView:(id)notification
{
[self setSaveCheckboxIsVisible: NO];
}

[hostName setEnabled: YES];
[userName setEnabled: YES];
[password setEnabled: YES];
[shared setEnabled: YES];
[profilePopup setEnabled: YES];

if (port < DISPLAY_MAX) {
// Low port numbers have to be encoded as host:port so they won't be
// interpreted as display numbers
Expand Down Expand Up @@ -173,6 +174,7 @@ - (void)updateView:(id)notification
/* It's important to do password before rememberPwd so that
* the latter will reflect a failure to retrieve the
* passsword from the key chain. */
[userName setStringValue:[mServer userName] ? [mServer userName] : @""];
[password setStringValue:[mServer password] ? [mServer password] : @""];
[rememberPwd setIntValue:[mServer rememberPassword]];
[shared setIntValue:[mServer shared]];
Expand All @@ -186,8 +188,9 @@ - (void)updateView:(id)notification
[useSshTunnel setIntValue:YES];
[sshHost setStringValue:[mServer sshString]];
}

[hostName setEnabled: [mServer doYouSupport:EDIT_ADDRESS]];
[userName setEnabled: [mServer doYouSupport:EDIT_USERNAME]];
[password setEnabled: [mServer doYouSupport:EDIT_PASSWORD]];
[rememberPwd setEnabled: [mServer respondsToSelector:@selector(setRememberPassword:)]];
[useSshTunnel setEnabled: YES];
Expand All @@ -200,6 +203,7 @@ - (void)updateView:(id)notification
else
{
[hostName setEnabled: NO];
[userName setEnabled: NO];
[password setEnabled: NO];
[rememberPwd setEnabled: NO];
[display setEnabled: NO];
Expand All @@ -210,6 +214,7 @@ - (void)updateView:(id)notification
[sshHost setEnabled: NO];

[hostName setStringValue:@""];
[userName setStringValue:@""];
[password setStringValue:@""];
[rememberPwd setIntValue:0];
[display setStringValue:@""];
Expand Down Expand Up @@ -243,13 +248,13 @@ - (void)setProfilePopupToProfile: (Profile *)profile
- (void)loadProfileIntoView
{
[profilePopup removeAllItems];

NSArray* profileKeys = [NSArray arrayWithArray:[[ProfileDataManager sharedInstance] sortedKeyArray]];

[profilePopup addItemsWithTitles:profileKeys];
[[profilePopup menu] addItem: [NSMenuItem separatorItem]];
[profilePopup addItemWithTitle:NSLocalizedString(@"EditProfiles", nil)];

[self setProfilePopupToProfile: [mServer profile]];
}

Expand Down Expand Up @@ -286,7 +291,7 @@ - (void)descriptionFromPort
{
int port = [mServer port];
NSString *str;

if (port >= PORT_BASE && port < PORT_BASE + DISPLAY_MAX) {
NSString *fmt = NSLocalizedString(@"PortIsDisplay", nil);

Expand Down Expand Up @@ -321,7 +326,7 @@ - (void)takePortFromDisplay
- (void)controlTextDidChange:(NSNotification *)aNotification
{
NSControl* sender = [aNotification object];

if( display == sender )
{
if( nil != mServer && [mServer doYouSupport:EDIT_PORT] )
Expand Down Expand Up @@ -354,6 +359,19 @@ - (void)controlTextDidChange:(NSNotification *)aNotification
}
}

- (IBAction)userNameChanged:(id)sender {
if ([mServer doYouSupport:EDIT_USERNAME]) {
NSString *str = [sender stringValue];

if ([str length] > 0)
[mServer setUserName:str];
else {
[mServer setUserName:nil];
}
}

}

- (IBAction)passwordChanged:(id)sender
{
if ([mServer doYouSupport:EDIT_PASSWORD]) {
Expand Down Expand Up @@ -483,7 +501,7 @@ - (IBAction)connectToServer:(id)sender
server = s;
} else
server = mServer;

// Asynchronously creates a connection to the server
connectionWaiter = [[ConnectionWaiter waiterForServer:server
delegate:self
Expand Down Expand Up @@ -545,6 +563,7 @@ - (void)disableControls
{
[display setEnabled: NO];
[hostName setEnabled: NO];
[userName setEnabled: NO];
[password setEnabled: NO];
[profilePopup setEnabled: NO];
[rememberPwd setEnabled: NO];
Expand All @@ -557,7 +576,7 @@ - (void)disableControls
}

- (void)windowClose:(id)notification
{
{
if([notification object] == [self window])
{
if( YES == selfTerminate )
Expand Down
1 change: 1 addition & 0 deletions Source/ServerFromConnection.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ - (bool)doYouSupport: (SUPPORT_TYPE)type
case EDIT_ADDRESS:
case EDIT_PORT:
case EDIT_NAME:
case EDIT_USERNAME:
case EDIT_PASSWORD:
case CONNECT:
return NO;
Expand Down
Loading