You can now connect through the new NetworkObject. Password
authorKent Sutherland <ksuther@ithinksw.com>
Wed, 29 Oct 2003 02:36:59 +0000 (02:36 +0000)
committerKent Sutherland <ksuther@ithinksw.com>
Wed, 29 Oct 2003 02:36:59 +0000 (02:36 +0000)
authentication is in, but needs to be tested.

English.lproj/Preferences.nib/keyedobjects.nib
MainController.m
NetworkController.m
NetworkObject.h
NetworkObject.m
PreferencesController.m
libValidate.a

index 88ffb88..7e4be37 100755 (executable)
Binary files a/English.lproj/Preferences.nib/keyedobjects.nib and b/English.lproj/Preferences.nib/keyedobjects.nib differ
index 92f3ee6..aaddc7f 100755 (executable)
@@ -2,6 +2,7 @@
 #import "MenuController.h"
 #import "PreferencesController.h"
 #import "NetworkController.h"
+#import "NetworkObject.h"
 #import <ITKit/ITHotKeyCenter.h>
 #import <ITKit/ITHotKey.h>
 #import <ITKit/ITKeyCombo.h>
@@ -947,8 +948,9 @@ static MainController *sharedController;
     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 {
@@ -962,6 +964,7 @@ static MainController *sharedController;
 {
     ITDebugLog(@"Disconnecting from shared remote.");
     //Disconnect
+    [currentRemote release];
     currentRemote = [remoteArray objectAtIndex:0];
     [networkController disconnect];
     [self timerUpdate];
@@ -983,14 +986,13 @@ static MainController *sharedController;
 - (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!");
     }
 }
 
index 9edb713..230e136 100755 (executable)
@@ -40,7 +40,6 @@ static NetworkController *sharedController;
 {
     [self disconnect];
     if (serverOn) {
-        [serverConnection invalidate];
         [serverConnection release];
     }
     [serverPass release];
@@ -78,8 +77,8 @@ static NetworkController *sharedController;
                                                      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!");
@@ -107,8 +106,6 @@ static NetworkController *sharedController;
         [service stop];
         [serverConnection registerName:nil];
         [[serverConnection rootObject] release];
-        [serverPort invalidate];
-        [serverConnection invalidate];
         [serverConnection release];
         ITDebugLog(@"Stopped server.");
         serverOn = NO;
@@ -120,6 +117,7 @@ static NetworkController *sharedController;
     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)];
@@ -132,7 +130,6 @@ static NetworkController *sharedController;
         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
@@ -141,6 +138,26 @@ static NetworkController *sharedController;
         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;
@@ -155,7 +172,6 @@ static NetworkController *sharedController;
     remoteHost = nil;
     [[NSNotificationCenter defaultCenter] removeObserver:self];
     [clientProxy release];
-    [clientConnection invalidate];
     [clientConnection release];
     return YES;
 }
@@ -178,20 +194,24 @@ static NetworkController *sharedController;
     
     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;
@@ -227,21 +247,6 @@ static NetworkController *sharedController;
     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]);
index f211d19..75d534c 100755 (executable)
@@ -25,4 +25,7 @@
 }
 - (ITMTRemote *)remote;
 - (NSString *)serverName;
+
+- (BOOL)requiresPassword;
+- (BOOL)sendPassword:(NSData *)password;
 @end
index 5ab7c79..da316e1 100755 (executable)
@@ -1,10 +1,19 @@
-//
-//  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
index 5f38b44..96c19e8 100755 (executable)
@@ -199,14 +199,15 @@ static PreferencesController *prefs = nil;
         //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;
@@ -249,9 +250,9 @@ static PreferencesController *prefs = nil;
         }
     } 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];
@@ -308,7 +309,6 @@ static PreferencesController *prefs = nil;
         } else if ( effectTag == 2103 ) {
             [sw setEntryEffect:[[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:sw] autorelease]];
         } else if ( effectTag == 2104 ) {
-            NSLog(@"dflhgldf");
             [sw setEntryEffect:[[[ITPivotWindowEffect alloc] initWithWindow:sw] autorelease]];
         }
 
@@ -795,11 +795,7 @@ static PreferencesController *prefs = nil;
             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];
     }
 }
 
index 533f7db..4a42a33 100755 (executable)
Binary files a/libValidate.a and b/libValidate.a differ