authentication is in, but needs to be tested.
#import "MenuController.h"
#import "PreferencesController.h"
#import "NetworkController.h"
+#import "NetworkObject.h"
#import <ITKit/ITHotKeyCenter.h>
#import <ITKit/ITHotKey.h>
#import <ITKit/ITKeyCombo.h>
ITDebugLog(@"Attempting to connect to shared remote.");
//Connect
if ([networkController connectToHost:[df stringForKey:@"sharedPlayerHost"]]) {
- currentRemote = [[networkController networkObject] remote];
- [refreshTimer invalidate];
+ currentRemote = [[[networkController networkObject] remote] retain];
+ [self timerUpdate];
+ //[refreshTimer invalidate];
ITDebugLog(@"Connection successful.");
return YES;
} else {
{
ITDebugLog(@"Disconnecting from shared remote.");
//Disconnect
+ [currentRemote release];
currentRemote = [remoteArray objectAtIndex:0];
[networkController disconnect];
[self timerUpdate];
- (void)networkError:(NSException *)exception
{
ITDebugLog(@"Remote exception thrown: %@: %@", [exception name], [exception reason]);
- NSLog(@"Remote exception thrown: %@: %@", [exception name], [exception reason]);
- NSRunCriticalAlertPanel(@"Remote MenuTunes Disconnected", @"The MenuTunes server you were connected to stopped responding or quit. MenuTunes will revert back to the local player.", @"OK", nil, nil);
- if ([networkController isConnectedToServer] && [self disconnectFromServer]) {
- if ([[exception name] isEqualToString:NSPortTimeoutException]) {
+ if ([[exception name] isEqualToString:NSPortTimeoutException]) {
+ NSRunCriticalAlertPanel(@"Remote MenuTunes Disconnected", @"The MenuTunes server you were connected to stopped responding or quit. MenuTunes will revert back to the local player.", @"OK", nil, nil);
+ if ([networkController isConnectedToServer] && [self disconnectFromServer]) {
[NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(checkForRemoteServer:) userInfo:nil repeats:YES];
+ } else {
+ ITDebugLog(@"CRITICAL ERROR, DISCONNECTING!");
}
- } else {
- ITDebugLog(@"CRITICAL ERROR, DISCONNECTING!");
}
}
{
[self disconnect];
if (serverOn) {
- [serverConnection invalidate];
[serverConnection release];
}
[serverPass release];
sendPort:serverPort];
[serverConnection setRootObject:[[NetworkObject alloc] init]];
[serverConnection registerName:@"ITMTPlayerHost"];
- [serverConnection setDelegate:self];
NS_HANDLER
+ [[serverConnection rootObject] release];
[serverConnection release];
[serverPort release];
ITDebugLog(@"Error starting server!");
[service stop];
[serverConnection registerName:nil];
[[serverConnection rootObject] release];
- [serverPort invalidate];
- [serverConnection invalidate];
[serverConnection release];
ITDebugLog(@"Stopped server.");
serverOn = NO;
NSData *fullPass = [[NSUserDefaults standardUserDefaults] dataForKey:@"connectPassword"];
unsigned char buffer;
ITDebugLog(@"Connecting to host: %@", host);
+ [remoteHost release];
remoteHost = [host copy];
if (fullPass) {
[fullPass getBytes:&buffer range:NSMakeRange(6, 4)];
clientPort = [[NSSocketPort alloc] initRemoteWithTCPPort:SERVER_PORT
host:host];
clientConnection = [[NSConnection connectionWithReceivePort:nil sendPort:clientPort] retain];
- [clientConnection setDelegate:self];
[clientConnection setReplyTimeout:5];
clientProxy = [[clientConnection rootProxy] retain];
NS_HANDLER
ITDebugLog(@"Connection to host failed: %@", host);
return NO;
NS_ENDHANDLER
+
+ if (!clientProxy) {
+ ITDebugLog(@"Null proxy! Couldn't connect!");
+ [self disconnect];
+ return NO;
+ }
+
+ if ([clientProxy requiresPassword]) {
+ ITDebugLog(@"Sending password.");
+ if (![clientProxy sendPassword:[[NSUserDefaults standardUserDefaults] dataForKey:@"connectPassword"]]) {
+ ITDebugLog(@"Invalid password!");
+ [self disconnect];
+ if ( NSRunCriticalAlertPanel(@"Invalid Password", @"The MenuTunes server you attempted to connect to rejected your password. Would you like to try to reconnect?.", @"Yes", @"No", nil) == NSOKButton ) {
+ return [self connectToHost:host];
+ } else {
+ return NO;
+ }
+ }
+ }
+
ITDebugLog(@"Connected to host: %@", host);
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(disconnect) name:NSConnectionDidDieNotification object:clientConnection];
connectedToServer = YES;
remoteHost = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self];
[clientProxy release];
- [clientConnection invalidate];
[clientConnection release];
return YES;
}
NS_DURING
testPort = [[NSSocketPort alloc] initRemoteWithTCPPort:SERVER_PORT
- host:host];
+ host:host];
testConnection = [[NSConnection connectionWithReceivePort:nil sendPort:testPort] retain];
[testConnection setReplyTimeout:2];
- tempProxy = [testConnection rootProxy];
- [testConnection setDelegate:self];
+ tempProxy = (NetworkObject *)[testConnection rootProxy];
[tempProxy serverName];
NS_HANDLER
ITDebugLog(@"Connection to host failed: %@", host);
- [testConnection invalidate];
[testConnection release];
[testPort release];
return NO;
NS_ENDHANDLER
- [testConnection invalidate];
+
+ if (!clientProxy) {
+ ITDebugLog(@"Null proxy! Couldn't connect!");
+ [testConnection release];
+ [testPort release];
+ return NO;
+ }
[testConnection release];
[testPort release];
return YES;
return remoteServices;
}
-/*- (BOOL)authenticateComponents:(NSArray*)components withData:(NSData *)authenticationData
-{
- return YES;
- if (![[NSUserDefaults standardUserDefaults] boolForKey:@"enableSharingPassword"] || [authenticationData isEqualToData:serverPass]) {
- return YES;
- } else {
- return NO;
- }
-}
-
-- (NSData *)authenticationDataForComponents:(NSArray *)components
-{
- return clientPass;
-}*/
-
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing
{
ITDebugLog(@"Found service named %@.", [aNetService name]);
}
- (ITMTRemote *)remote;
- (NSString *)serverName;
+
+- (BOOL)requiresPassword;
+- (BOOL)sendPassword:(NSData *)password;
@end
-//
-// NetworkObject.m
-// MenuTunes
-//
-// Created by Kent Sutherland on Tue Oct 28 2003.
-// Copyright (c) 2003 __MyCompanyName__. All rights reserved.
-//
+/*
+ * MenuTunes
+ * NetworkObject
+ * Remote network object that is vended
+ *
+ * Original Author : Kent Sutherland <ksutherland@ithinksw.com>
+ * Responsibility : Kent Sutherland <ksutherland@ithinksw.com>
+ *
+ * Copyright (c) 2002 - 2003 iThink Software.
+ * All Rights Reserved
+ *
+ * This header defines the Objective-C protocol which all MenuTunes Remote
+ * plugins must implement. To build a remote, create a subclass of this
+ * object, and implement each method in the @protocol below.
+ *
+ */
#import "NetworkObject.h"
#import "MainController.h"
return name;
}
+- (BOOL)requiresPassword
+{
+ return [[NSUserDefaults standardUserDefaults] boolForKey:@"enableSharingPassword"];
+}
+
+- (BOOL)sendPassword:(NSData *)password
+{
+ if ([password isEqualToData:[[NSUserDefaults standardUserDefaults] dataForKey:@"sharedPlayerPassword"]]) {
+ return YES;
+ } else {
+ return NO;
+ }
+}
+
@end
//Set the server password
const char *instring = [[sender stringValue] UTF8String];
const char *password = "password";
- unsigned char result;
+ unsigned char *result;
NSData *hashedPass, *passwordStringHash;
- SHA1(instring, strlen(instring), &result);
- hashedPass = [NSData dataWithBytes:&result length:strlen(&result)];
- SHA1(password, strlen(password), &result);
- passwordStringHash = [NSData dataWithBytes:&result length:strlen(&result)];
+ result = SHA1(instring, strlen(instring), NULL);
+ hashedPass = [NSData dataWithBytes:result length:strlen(result)];
+ result = SHA1(password, strlen(password), NULL);
+ passwordStringHash = [NSData dataWithBytes:result length:strlen(result)];
if (![hashedPass isEqualToData:passwordStringHash]) {
[df setObject:hashedPass forKey:@"sharedPlayerPassword"];
+ [sender setStringValue:@"password"];
}
} else if ( [sender tag] == 5040 ) {
BOOL state = SENDER_STATE;
}
} else if ( [sender tag] == 5150 ) {
const char *instring = [[sender stringValue] UTF8String];
- unsigned char result;
- SHA1(instring, strlen(instring), &result);
- [df setObject:[NSData dataWithBytes:&result length:strlen(&result)] forKey:@"connectPassword"];
+ unsigned char *result;
+ result = SHA1(instring, strlen(instring), NULL);
+ [df setObject:[NSData dataWithBytes:result length:strlen(result)] forKey:@"connectPassword"];
} else if ( [sender tag] == 5110 ) {
//Cancel
[NSApp endSheet:selectPlayerSheet];
} else if ( effectTag == 2103 ) {
[sw setEntryEffect:[[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:sw] autorelease]];
} else if ( effectTag == 2104 ) {
- NSLog(@"dflhgldf");
[sw setEntryEffect:[[[ITPivotWindowEffect alloc] initWithWindow:sw] autorelease]];
}
return [[hotKeysDictionary objectForKey:[hotKeysArray objectAtIndex:rowIndex]] description];
}
} else {
- if ([[aTableColumn identifier] isEqualToString:@"name"]) {
- return [[[[NetworkController sharedController] remoteServices] objectAtIndex:rowIndex] name];
- } else {
- return @"X";
- }
+ return [[[[NetworkController sharedController] remoteServices] objectAtIndex:rowIndex] name];
}
}