Changeset 3643

Show
Ignore:
Timestamp:
04/18/07 23:53:34 (1 year ago)
Author:
timothy
Message:

Add support for Jabber of SSL and Google Talk accounts.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Chat Core/MVXMPPChatConnection.m

    r3638 r3643  
    8888        [self _willConnect];     
    8989 
    90         MVSafeAdoptAssign( &_localID, [[JabberID alloc] initWithFormat:@"%@@%@/colloquy", _username, _server] ); 
    91         MVSafeAdoptAssign( &_localUser, [[MVXMPPChatUser allocWithZone:nil] initLocalUserWithConnection:self] ); 
    92  
    93     [_session startSession:_localID onPort:_serverPort]; 
     90        JabberID *localId = nil; 
     91        NSRange atRange = [_username rangeOfString:@"@" options:NSLiteralSearch]; 
     92        if( atRange.location == NSNotFound ) 
     93                localId = [[JabberID alloc] initWithFormat:@"%@@%@/colloquy", _username, _server]; 
     94        else localId = [[JabberID alloc] initWithFormat:@"%@/colloquy", _username]; 
     95 
     96        MVChatUser *localUser = [[MVXMPPChatUser allocWithZone:nil] initWithJabberID:localId andConnection:self]; 
     97        [localUser _setType:MVChatLocalUserType]; 
     98 
     99        MVSafeAdoptAssign( &_localID, localId ); 
     100        MVSafeAdoptAssign( &_localUser, localUser ); 
     101 
     102        [_session setUseSSL:_secure]; 
     103        [_session startSession:_localID onPort:_serverPort withServer:_server]; 
    94104} 
    95105 
     
    235245        } 
    236246 
     247        NSString *localUserStringId = [[NSString allocWithZone:nil] initWithFormat:@"%@/%@", room, [self nickname]]; 
    237248        JabberPresence *presence = [[JabberPresence allocWithZone:nil] initWithQName:JABBER_PRESENCE_QN]; 
    238         [presence putAttribute:@"from" withValue:[_localID escapedCompleteID]]; 
    239  
    240         NSString *localUserStringId = [[NSString allocWithZone:nil] initWithFormat:@"%@/%@", room, [self nickname]]; 
    241249        [presence putAttribute:@"to" withValue:localUserStringId]; 
    242250 
     
    283291 
    284292- (void) authorizationReady:(NSNotification *) notification { 
    285         [[notification object] authenticateWithPassword:_password]; 
     293        if( _password ) 
     294                [[notification object] authenticateWithPassword:_password]; 
    286295} 
    287296 
     
    305314 
    306315- (void) incomingPacket:(NSNotification *) notification { 
    307     NSString *string = [[NSString alloc] initWithData:[notification object] encoding:NSUTF8StringEncoding]; 
     316       NSString *string = [[NSString alloc] initWithData:[notification object] encoding:NSUTF8StringEncoding]; 
    308317        [[NSNotificationCenter defaultCenter] postNotificationName:MVChatConnectionGotRawMessageNotification object:self userInfo:[NSDictionary dictionaryWithObjectsAndKeys:string, @"message", [NSNumber numberWithBool:NO], @"outbound", nil]]; 
    309318        [string release]; 
     
    311320 
    312321- (void) incomingMessage:(NSNotification *) notification { 
    313     JabberMessage *message = [notification object]; 
    314  
    315     switch( [message eventType] ) { 
    316     case JMEVENT_COMPOSING_REQUEST: 
     322        JabberMessage *message = [notification object]; 
     323 
     324        if( [[message type] isEqualToString:@"error"] ) { 
     325                // handle error 
     326                return; 
     327        } 
     328 
     329        switch( [message eventType] ) { 
     330        case JMEVENT_COMPOSING_REQUEST: 
    317331                // fall through 
    318     case JMEVENT_NONE: { 
     332       case JMEVENT_NONE: { 
    319333                MVChatRoom *room = nil; 
    320334                MVChatUser *sender = nil; 
     
    354368                [msgData release]; 
    355369                [msgAttributes release]; 
    356         break; 
    357         } 
    358  
    359     case JMEVENT_COMPOSING: 
    360         break; 
    361     case JMEVENT_COMPOSING_CANCEL: 
    362         break; 
    363    
     370               break; 
     371        } 
     372 
     373       case JMEVENT_COMPOSING: 
     374               break; 
     375       case JMEVENT_COMPOSING_CANCEL: 
     376               break; 
     377       
    364378} 
    365379 
    366380- (void) incomingPresence:(NSNotification *) notification { 
    367     JabberPresence *presence = [notification object]; 
     381       JabberPresence *presence = [notification object]; 
    368382        JabberID *roomID = [[presence from] userhostJID]; 
    369383        MVChatRoom *room = [self joinedChatRoomWithUniqueIdentifier:roomID]; 
     
    423437- (XMLElement *) _capabilitiesElement { 
    424438        XMLElement *caps = [[XMLElement allocWithZone:nil] initWithQName:JABBER_CLIENTCAP_QN]; 
    425     [caps putAttribute:@"node" withValue:@"http://colloquy.info/caps"]; 
    426     [caps putAttribute:@"ver" withValue:@"2.1"]; 
     439       [caps putAttribute:@"node" withValue:@"http://colloquy.info/caps"]; 
     440       [caps putAttribute:@"ver" withValue:@"2.1"]; 
    427441        return [caps autorelease]; 
    428442} 
  • trunk/Chat Core/MVXMPPChatUser.h

    r3638 r3643  
    99        BOOL _roomMember; 
    1010} 
    11 - (id) initLocalUserWithConnection:(MVXMPPChatConnection *) connection; 
    1211- (id) initWithJabberID:(JabberID *) identifier andConnection:(MVXMPPChatConnection *) connection; 
    1312@end 
  • trunk/Chat Core/MVXMPPChatUser.m

    r3638 r3643  
    66 
    77@implementation MVXMPPChatUser 
    8 - (id) initLocalUserWithConnection:(MVXMPPChatConnection *) userConnection { 
    9         if( ( self = [self initWithJabberID:[userConnection _localUserID] andConnection:userConnection] ) ) 
    10                 _type = MVChatLocalUserType; 
    11         return self; 
    12 } 
    13  
    148- (id) initWithJabberID:(JabberID *) identifier andConnection:(MVXMPPChatConnection *) userConnection { 
    159        if( ( self = [self init] ) ) { 
     
    4438        if( _roomMember ) 
    4539                return [_uniqueIdentifier resource]; 
    46         if( _type == MVChatLocalUserType ) 
    47                 return [[self connection] username]; 
    4840        return [_uniqueIdentifier username]; 
    4941} 
  • trunk/Frameworks/Acid/Acid.xcodeproj/project.pbxproj

    r3641 r3643  
    5252                DDBE55910BD1845D004ED228 /* libssl.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = DDBE55900BD1845D004ED228 /* libssl.dylib */; }; 
    5353                DDBE55BA0BD187D5004ED228 /* libcrypto.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = DDBE55B90BD187D5004ED228 /* libcrypto.dylib */; }; 
     54                DDE46AAD0BD7246C0064D202 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DDE46AAC0BD7246C0064D202 /* CoreServices.framework */; }; 
    5455                DDF45AC40BD5CC500050911E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D69BFE84028FC02AAC07 /* Foundation.framework */; }; 
    5556                DDF45BBD0BD5CD6D0050911E /* AsyncSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = DDF45BBC0BD5CD6D0050911E /* AsyncSocket.h */; }; 
     
    127128                DDBE55B90BD187D5004ED228 /* libcrypto.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcrypto.dylib; path = /usr/lib/libcrypto.dylib; sourceTree = "<absolute>"; }; 
    128129                DDCB77A00BD5CB8700693892 /* Acid.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Acid.pch; sourceTree = "<group>"; }; 
     130                DDE46AAC0BD7246C0064D202 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = /System/Library/Frameworks/CoreServices.framework; sourceTree = "<absolute>"; }; 
    129131                DDF45BBC0BD5CD6D0050911E /* AsyncSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AsyncSocket.h; path = "../../Chat Core/AsyncSocket.h"; sourceTree = SOURCE_ROOT; }; 
    130132                DDF45C0C0BD5CF0E0050911E /* Common Settings.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = "Common Settings.xcconfig"; path = "../../Settings/Common Settings.xcconfig"; sourceTree = SOURCE_ROOT; }; 
     
    139141                                DDBE55BA0BD187D5004ED228 /* libcrypto.dylib in Frameworks */, 
    140142                                DDF45AC40BD5CC500050911E /* Foundation.framework in Frameworks */, 
     143                                DDE46AAD0BD7246C0064D202 /* CoreServices.framework in Frameworks */, 
    141144                        ); 
    142145                        runOnlyForDeploymentPostprocessing = 0; 
     
    202205                                DDBE55B90BD187D5004ED228 /* libcrypto.dylib */, 
    203206                                DDBE55900BD1845D004ED228 /* libssl.dylib */, 
     207                                DDE46AAC0BD7246C0064D202 /* CoreServices.framework */, 
    204208                                0867D69BFE84028FC02AAC07 /* Foundation.framework */, 
    205209                        ); 
  • trunk/Frameworks/Acid/jabber/JabberSocket.m

    r3641 r3643  
    101101{} 
    102102 
     103- (BOOL) socketWillConnect:(AsyncSocket *)sock { 
     104        if( _useSSL ) { 
     105                CFReadStreamSetProperty( [sock getCFReadStream], kCFStreamPropertySocketSecurityLevel, kCFStreamSocketSecurityLevelNegotiatedSSL ); 
     106                CFWriteStreamSetProperty( [sock getCFWriteStream], kCFStreamPropertySocketSecurityLevel, kCFStreamSocketSecurityLevelNegotiatedSSL ); 
     107 
     108                NSMutableDictionary *settings = [[NSMutableDictionary allocWithZone:nil] init]; 
     109                [settings setObject:[NSNumber numberWithBool:YES] forKey:(NSString *)kCFStreamSSLAllowsAnyRoot]; 
     110 
     111                CFReadStreamSetProperty( [sock getCFReadStream], kCFStreamPropertySSLSettings, (CFDictionaryRef) settings ); 
     112                CFWriteStreamSetProperty( [sock getCFWriteStream], kCFStreamPropertySSLSettings, (CFDictionaryRef) settings ); 
     113        } 
     114 
     115        return YES; 
     116} 
     117 
    103118- (void) socket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port 
    104119{ 
  • trunk/Panels/JVDirectChatPanel.m

    r3637 r3643  
    181181                                int org = [[NSUserDefaults standardUserDefaults] integerForKey:@"JVChatTranscriptFolderOrganization"]; 
    182182                                if( org == 1 ) { 
    183                                         logs = [logs stringByAppendingPathComponent:[[self connection] server]]; 
     183                                        logs = [logs stringByAppendingPathComponent:[[self user] serverAddress]]; 
    184184                                        if( ! [fileManager fileExistsAtPath:logs] ) [fileManager createDirectoryAtPath:logs attributes:nil]; 
    185185                                } else if( org == 2 ) { 
    186                                         logs = [logs stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ (%@)", [self target], [[self connection] server]]]; 
     186                                        logs = [logs stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ (%@)", [self target], [[self user] serverAddress]]]; 
    187187                                        if( ! [fileManager fileExistsAtPath:logs] ) [fileManager createDirectoryAtPath:logs attributes:nil]; 
    188188                                } else if( org == 3 ) { 
    189                                         logs = [logs stringByAppendingPathComponent:[[self connection] server]]; 
     189                                        logs = [logs stringByAppendingPathComponent:[[self user] serverAddress]]; 
    190190                                        if( ! [fileManager fileExistsAtPath:logs] ) [fileManager createDirectoryAtPath:logs attributes:nil]; 
    191191 
     
    204204 
    205205                                        if( org ) logName = [NSString stringWithFormat:@"%@.colloquyTranscript", [self target]]; 
    206                                         else logName = [NSString stringWithFormat:@"%@ (%@).colloquyTranscript", [self target], [[self connection] server]]; 
     206                                        else logName = [NSString stringWithFormat:@"%@ (%@).colloquyTranscript", [self target], [[self user] serverAddress]]; 
    207207                                        nameFound = ! [fileManager fileExistsAtPath:[logs stringByAppendingPathComponent:logName]]; 
    208208 
    209209                                        while( ! nameFound ) { 
    210210                                                if( org ) logName = [NSString stringWithFormat:@"%@ %d.colloquyTranscript", [self target], i++]; 
    211                                                 else logName = [NSString stringWithFormat:@"%@ (%@) %d.colloquyTranscript", [self target], [[self connection] server], i++]; 
     211                                                else logName = [NSString stringWithFormat:@"%@ (%@) %d.colloquyTranscript", [self target], [[self user] serverAddress], i++]; 
    212212                                                nameFound = ! [fileManager fileExistsAtPath:[logs stringByAppendingPathComponent:logName]]; 
    213213                                        } 
    214214                                } else if( session == 1 ) { 
    215215                                        if( org ) logName = [NSString stringWithFormat:@"%@.colloquyTranscript", [self target]]; 
    216                                         else logName = [NSString stringWithFormat:@"%@ (%@).colloquyTranscript", [self target], [[self connection] server]]; 
     216                                        else logName = [NSString stringWithFormat:@"%@ (%@).colloquyTranscript", [self target], [[self user] serverAddress]]; 
    217217                                } else if( session == 2 ) { 
    218218                                        if( org ) logName = [NSMutableString stringWithFormat:@"%@ %@.colloquyTranscript", [self target], dateString]; 
    219                                         else logName = [NSMutableString stringWithFormat:@"%@ (%@) %@.colloquyTranscript", [self target], [[self connection] server], dateString]; 
     219                                        else logName = [NSMutableString stringWithFormat:@"%@ (%@) %@.colloquyTranscript", [self target], [[self user] serverAddress], dateString]; 
    220220                                        [(NSMutableString *)logName replaceOccurrencesOfString:@"/" withString:@"-" options:NSLiteralSearch range:NSMakeRange( 0, [logName length] )]; 
    221221                                        [(NSMutableString *)logName replaceOccurrencesOfString:@":" withString:@"-" options:NSLiteralSearch range:NSMakeRange( 0, [logName length] )]; 
     
    282282 
    283283/*      if( [self isMemberOfClass:[JVDirectChatPanel class]] ) { 
    284                 NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@/%@", [[self connection] urlScheme], [[self connection] server], [[[self target] description] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; 
    285  
    286                 NSString *path = [[NSString stringWithFormat:@"~/Library/Application Support/Colloquy/Recent Acquaintances/%@ (%@).inetloc", [self target], [[self connection] server]] stringByExpandingTildeInPath]; 
     284                NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@/%@", [[self connection] urlScheme], [[self user] serverAddress], [[[self target] description] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; 
     285 
     286                NSString *path = [[NSString stringWithFormat:@"~/Library/Application Support/Colloquy/Recent Acquaintances/%@ (%@).inetloc", [self target], [[self user] serverAddress]] stringByExpandingTildeInPath]; 
    287287 
    288288                [url writeToInternetLocationFile:path]; 
     
    392392- (NSString *) windowTitle { 
    393393/*      if( _buddy && [_buddy preferredNameWillReturn] != JVBuddyActiveNickname ) 
    394                 return [NSString stringWithFormat:@"%@ (%@)", [_buddy preferredName], [[self connection] server]]; */ 
     394                return [NSString stringWithFormat:@"%@ (%@)", [_buddy preferredName], [[self user] serverAddress]]; */ 
    395395 
    396396        if( [[self target] isKindOfClass:[MVDirectChatConnection class]] ) { 
     
    401401        } 
    402402 
    403         return [NSString stringWithFormat:@"%@ (%@)", [self title], [[self connection] server]]; 
     403        return [NSString stringWithFormat:@"%@ (%@)", [self title], [[self user] serverAddress]]; 
    404404} 
    405405 
    406406- (NSString *) information { 
    407407/*      if( _buddy && [_buddy preferredNameWillReturn] != JVBuddyActiveNickname && ! [[self target] isEqualToString:[_buddy preferredName]] ) 
    408                 return [NSString stringWithFormat:@"%@ (%@)", [self target], [[self connection] server]]; */ 
     408                return [NSString stringWithFormat:@"%@ (%@)", [self target], [[self user] serverAddress]]; */ 
    409409        if( [[self target] isKindOfClass:[MVDirectChatConnection class]] ) { 
    410410                if( [(MVDirectChatConnection *)[self target] status] == MVDirectChatConnectionWaitingStatus ) 
     
    428428 
    429429/*      if( _buddy && [_buddy preferredNameWillReturn] != JVBuddyActiveNickname ) 
    430                 return [NSString stringWithFormat:@"%@\n%@ (%@)\n%@", [_buddy preferredName], [self target], [[self connection] server], messageCount]; */ 
     430                return [NSString stringWithFormat:@"%@\n%@ (%@)\n%@", [_buddy preferredName], [self target], [[self user] serverAddress], messageCount]; */ 
    431431 
    432432        if( [[self target] isKindOfClass:[MVDirectChatConnection class]] ) { 
     
    445445        } 
    446446 
    447         return [NSString stringWithFormat:@"%@ (%@)\n%@", [self title], [[self connection] server], messageCount]; 
     447        return [NSString stringWithFormat:@"%@ (%@)\n%@", [self title], [[self user] serverAddress], messageCount]; 
    448448} 
    449449 
     
    527527        if( [[self target] isKindOfClass:[MVDirectChatConnection class]] ) 
    528528                return [NSString stringWithFormat:@"Direct Chat %@", [self user]]; 
    529         return [NSString stringWithFormat:@"Direct Chat %@ (%@)", [self user], [[self connection] server]]; 
     529        return [NSString stringWithFormat:@"Direct Chat %@ (%@)", [self user], [[self user] serverAddress]]; 
    530530} 
    531531