Changeset 3174

Show
Ignore:
Timestamp:
03/25/06 16:20:12 (2 years ago)
Author:
timothy
Message:

Fixes a crash when the encoding does not accept specific input. We now fallback to ISO-Latin 1 like before. Fixes #551 and http://colloquy.info/admin/crash.html?id=902.

Files:

Legend:

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

    r3173 r3174  
    225225        [_threadWaitLock unlockWithCondition:0]; 
    226226 
    227         [self performSelector:@selector( _connect ) inThread:_connectionThread]; 
     227        if( _connectionThread ) 
     228                [self performSelector:@selector( _connect ) inThread:_connectionThread]; 
    228229} 
    229230 
    230231- (void) disconnectWithReason:(NSAttributedString *) reason { 
    231232        [self cancelPendingReconnectAttempts]; 
    232         if( _sendQueueTimer ) [self performSelector:@selector( _stopSendQueueTimer ) withObject:nil inThread:_connectionThread]; 
     233        if( _sendQueueTimer && _connectionThread ) 
     234                [self performSelector:@selector( _stopSendQueueTimer ) withObject:nil inThread:_connectionThread]; 
    233235 
    234236        if( _status == MVChatConnectionConnectedStatus ) { 
     
    239241        } 
    240242 
    241         [_chatConnection performSelector:@selector( disconnectAfterWriting ) inThread:_connectionThread]; 
     243        if( _connectionThread ) 
     244                [_chatConnection performSelector:@selector( disconnectAfterWriting ) inThread:_connectionThread]; 
    242245} 
    243246 
     
    363366 
    364367        if( now ) { 
    365                 [self performSelector:@selector( _writeDataToServer: ) withObject:raw inThread:_connectionThread]; 
     368                if( _connectionThread ) 
     369                        [self performSelector:@selector( _writeDataToServer: ) withObject:raw inThread:_connectionThread]; 
    366370 
    367371                id old = _lastCommand; 
     
    375379                } 
    376380 
    377                 if( ! _sendQueueTimer
     381                if( ! _sendQueueTimer && _connectionThread
    378382                        [self performSelector:@selector( _startQueueTimer ) withObject:nil inThread:_connectionThread]; 
    379383        } 
     
    682686- (void) socket:(AsyncSocket *) sock didReadData:(NSData *) data withTag:(long) tag { 
    683687        NSString *rawString = [[NSString allocWithZone:nil] initWithData:data encoding:[self encoding]]; 
     688        if( ! rawString ) rawString = [[NSString allocWithZone:nil] initWithData:data encoding:NSISOLatin1StringEncoding]; 
     689 
    684690        const char *line = (const char *)[data bytes]; 
    685691        unsigned int len = [data length]; 
     
    758764                                while( notEndOfLine() && *line != ' ' ) line++; 
    759765                                param = [[NSString allocWithZone:nil] initWithBytes:currentParameter length:(line - currentParameter) encoding:[self encoding]]; 
     766                                if( ! param ) param = [[NSString allocWithZone:nil] initWithBytes:currentParameter length:(line - currentParameter) encoding:NSISOLatin1StringEncoding]; 
    760767                                checkAndMarkIfDone(); 
    761768                                if( ! done ) line++; 
     
    777784 
    778785        if( command && commandLength ) { 
    779                 NSString *commandString = [[NSString allocWithZone:nil] initWithBytes:command length:commandLength encoding:[self encoding]]; 
     786                NSString *commandString = [[NSString allocWithZone:nil] initWithBytes:command length:commandLength encoding:NSASCIIStringEncoding]; 
    780787                NSString *selectorString = [[NSString allocWithZone:nil] initWithFormat:@"_handle%@WithParameters:fromSender:", [commandString capitalizedString]]; 
    781788                SEL selector = NSSelectorFromString( selectorString ); 
     
    785792                if( [self respondsToSelector:selector] ) { 
    786793                        NSString *senderString = nil; 
    787                         if( sender ) senderString = [[NSString allocWithZone:nil] initWithBytes:sender length:senderLength encoding:[self encoding]]; 
     794                        if( sender && senderLength ) { 
     795                                senderString = [[NSString allocWithZone:nil] initWithBytes:sender length:senderLength encoding:[self encoding]]; 
     796                                if( ! senderString ) senderString = [[NSString allocWithZone:nil] initWithBytes:sender length:senderLength encoding:NSISOLatin1StringEncoding]; 
     797                        } 
    788798 
    789799                        MVChatUser *chatUser = nil; 
    790                         if( user && userLength ) { 
     800                        if( senderString && user && userLength ) { // if user is not null that shows it was a user not a server sender  
    791801                                chatUser = [self chatUserWithUniqueIdentifier:senderString]; 
    792802                                if( ! [chatUser address] && host && hostLength ) { 
    793803                                        NSString *hostString = [[NSString allocWithZone:nil] initWithBytes:host length:hostLength encoding:[self encoding]]; 
     804                                        if( ! hostString ) hostString = [[NSString allocWithZone:nil] initWithBytes:host length:hostLength encoding:NSISOLatin1StringEncoding]; 
    794805                                        [chatUser _setAddress:hostString]; 
    795806                                        [hostString release]; 
     
    798809                                if( ! [chatUser username] ) { 
    799810                                        NSString *userString = [[NSString allocWithZone:nil] initWithBytes:user length:userLength encoding:[self encoding]]; 
     811                                        if( ! userString ) userString = [[NSString allocWithZone:nil] initWithBytes:user length:userLength encoding:NSISOLatin1StringEncoding]; 
    800812                                        [chatUser _setUsername:userString]; 
    801813                                        [userString release]; 
     
    10101022 
    10111023- (NSString *) _stringFromPossibleData:(id) input { 
    1012         if( [input isKindOfClass:[NSData class]] ) 
    1013                 return [[[NSString allocWithZone:nil] initWithData:input encoding:[self encoding]] autorelease]; 
     1024        if( [input isKindOfClass:[NSData class]] ) { 
     1025                NSString *ret = [[[NSString allocWithZone:nil] initWithData:input encoding:[self encoding]] autorelease]; 
     1026                if( ret ) return ret; 
     1027                return [[[NSString allocWithZone:nil] initWithData:input encoding:NSISOLatin1StringEncoding] autorelease]; 
     1028        } 
    10141029        return input; 
    10151030} 
     
    11241139                                if( [[sender nickname] isEqualToString:@"NickServ"] ) { 
    11251140                                        NSString *msg = [[NSString allocWithZone:nil] initWithData:msgData encoding:[self encoding]]; 
     1141                                        if( ! msg ) msg = [[NSString allocWithZone:nil] initWithData:msgData encoding:NSISOLatin1StringEncoding]; 
    11261142                                        if( [msg rangeOfString:@"NickServ"].location != NSNotFound && [msg rangeOfString:@"IDENTIFY"].location != NSNotFound ) { 
    11271143                                                if( ! [self nicknamePassword] ) { 
     
    11521168        while( line != end && *line != ' ' ) line++; 
    11531169        NSString *command = [[NSString allocWithZone:nil] initWithBytes:current length:(line - current) encoding:[self encoding]]; 
     1170        if( ! command ) command = [[NSString allocWithZone:nil] initWithBytes:current length:(line - current) encoding:NSISOLatin1StringEncoding]; 
     1171 
    11541172        NSMutableData *arguments = nil; 
    11551173        if( line != end ) arguments = [[NSMutableData allocWithZone:nil] initWithBytes:++line length:(end - line)]; 
     
    12071225                } else if( [command caseInsensitiveCompare:@"DCC"] == NSOrderedSame ) { 
    12081226                        NSString *msg = [[NSString allocWithZone:nil] initWithData:arguments encoding:[self encoding]]; 
     1227                        if( ! msg ) msg = [[NSString allocWithZone:nil] initWithData:arguments encoding:NSISOLatin1StringEncoding]; 
    12091228 
    12101229                        NSString *subCommand = nil; 
     
    16621681                if( room && ! [room _namesSynced] ) { 
    16631682                        NSAutoreleasePool *pool = [[NSAutoreleasePool allocWithZone:nil] init]; 
    1664                         NSString *names = [[NSString allocWithZone:nil] initWithData:[parameters objectAtIndex:3] encoding:[self encoding]]; 
     1683                        NSString *names = [self _stringFromPossibleData:[parameters objectAtIndex:3]]; 
    16651684                        NSArray *members = [names componentsSeparatedByString:@" "]; 
    16661685                        NSEnumerator *enumerator = [members objectEnumerator]; 
     
    16911710                        } 
    16921711 
    1693                         [names release]; 
    16941712                        [pool drain]; 
    16951713                        [pool release]; 
     
    18021820                [user _setUsername:[parameters objectAtIndex:2]]; 
    18031821                [user _setAddress:[parameters objectAtIndex:3]]; 
    1804                 NSString *realName = [[NSString allocWithZone:nil] initWithData:[parameters objectAtIndex:5] encoding:[self encoding]]; 
    1805                 [user _setRealName:realName]; 
    1806                 [realName release]; 
     1822                [user _setRealName:[self _stringFromPossibleData:[parameters objectAtIndex:5]]]; 
    18071823        } 
    18081824} 
     
    18511867- (void) _handle319WithParameters:(NSArray *) parameters fromSender:(id) sender { // RPL_WHOISCHANNELS 
    18521868        if( [parameters count] == 3 ) { 
    1853                 NSString *rooms = [[NSString allocWithZone:nil] initWithData:[parameters objectAtIndex:2] encoding:[self encoding]]; 
     1869                NSString *rooms = [self _stringFromPossibleData:[parameters objectAtIndex:2]]; 
    18541870                NSArray *chanArray = [[rooms stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] componentsSeparatedByString:@" "]; 
    18551871                NSMutableArray *results = [[NSMutableArray allocWithZone:nil] initWithCapacity:[chanArray count]]; 
     
    18681884                } 
    18691885 
    1870                 [rooms release]; 
    18711886                [results release]; 
    18721887        } 
     
    18751890- (void) _handle320WithParameters:(NSArray *) parameters fromSender:(id) sender { // RPL_WHOISIDENTIFIED 
    18761891        if( [parameters count] == 3 ) { 
    1877                 NSString *comment = [[NSString allocWithZone:nil] initWithData:[parameters objectAtIndex:2] encoding:[self encoding]]; 
     1892                NSString *comment = [self _stringFromPossibleData:[parameters objectAtIndex:2]]; 
    18781893                if( [comment rangeOfString:@"identified" options:NSCaseInsensitiveSearch].location != NSNotFound ) { 
    18791894                        MVChatUser *user = [self chatUserWithUniqueIdentifier:[parameters objectAtIndex:1]]; 
    18801895                        [user _setIdentified:YES]; 
    18811896                } 
    1882                 [comment release]; 
    18831897        } 
    18841898} 
  • trunk/Chat Core/MVIRCFileTransfer.m

    r3172 r3174  
    273273        [_threadWaitLock unlockWithCondition:0]; 
    274274 
     275        if( ! _connectionThread ) return; 
     276 
    275277        if( ! [self isPassive] ) [self performSelector:@selector( _waitForConnection ) inThread:_connectionThread]; 
    276278        else [self performSelector:@selector( _connect ) inThread:_connectionThread]; 
     
    528530        [_threadWaitLock unlockWithCondition:0]; 
    529531 
     532        if( ! _connectionThread ) return; 
     533 
    530534        if( ! [self isPassive] ) [self performSelector:@selector( _connect ) inThread:_connectionThread]; 
    531535        else [self performSelector:@selector( _waitForConnection ) inThread:_connectionThread];