Changeset 3174
- Timestamp:
- 03/25/06 16:20:12 (2 years ago)
- Files:
-
- trunk/Chat Core/MVIRCChatConnection.m (modified) (19 diffs)
- trunk/Chat Core/MVIRCFileTransfer.m (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Chat Core/MVIRCChatConnection.m
r3173 r3174 225 225 [_threadWaitLock unlockWithCondition:0]; 226 226 227 [self performSelector:@selector( _connect ) inThread:_connectionThread]; 227 if( _connectionThread ) 228 [self performSelector:@selector( _connect ) inThread:_connectionThread]; 228 229 } 229 230 230 231 - (void) disconnectWithReason:(NSAttributedString *) reason { 231 232 [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]; 233 235 234 236 if( _status == MVChatConnectionConnectedStatus ) { … … 239 241 } 240 242 241 [_chatConnection performSelector:@selector( disconnectAfterWriting ) inThread:_connectionThread]; 243 if( _connectionThread ) 244 [_chatConnection performSelector:@selector( disconnectAfterWriting ) inThread:_connectionThread]; 242 245 } 243 246 … … 363 366 364 367 if( now ) { 365 [self performSelector:@selector( _writeDataToServer: ) withObject:raw inThread:_connectionThread]; 368 if( _connectionThread ) 369 [self performSelector:@selector( _writeDataToServer: ) withObject:raw inThread:_connectionThread]; 366 370 367 371 id old = _lastCommand; … … 375 379 } 376 380 377 if( ! _sendQueueTimer )381 if( ! _sendQueueTimer && _connectionThread ) 378 382 [self performSelector:@selector( _startQueueTimer ) withObject:nil inThread:_connectionThread]; 379 383 } … … 682 686 - (void) socket:(AsyncSocket *) sock didReadData:(NSData *) data withTag:(long) tag { 683 687 NSString *rawString = [[NSString allocWithZone:nil] initWithData:data encoding:[self encoding]]; 688 if( ! rawString ) rawString = [[NSString allocWithZone:nil] initWithData:data encoding:NSISOLatin1StringEncoding]; 689 684 690 const char *line = (const char *)[data bytes]; 685 691 unsigned int len = [data length]; … … 758 764 while( notEndOfLine() && *line != ' ' ) line++; 759 765 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]; 760 767 checkAndMarkIfDone(); 761 768 if( ! done ) line++; … … 777 784 778 785 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]; 780 787 NSString *selectorString = [[NSString allocWithZone:nil] initWithFormat:@"_handle%@WithParameters:fromSender:", [commandString capitalizedString]]; 781 788 SEL selector = NSSelectorFromString( selectorString ); … … 785 792 if( [self respondsToSelector:selector] ) { 786 793 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 } 788 798 789 799 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 791 801 chatUser = [self chatUserWithUniqueIdentifier:senderString]; 792 802 if( ! [chatUser address] && host && hostLength ) { 793 803 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]; 794 805 [chatUser _setAddress:hostString]; 795 806 [hostString release]; … … 798 809 if( ! [chatUser username] ) { 799 810 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]; 800 812 [chatUser _setUsername:userString]; 801 813 [userString release]; … … 1010 1022 1011 1023 - (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 } 1014 1029 return input; 1015 1030 } … … 1124 1139 if( [[sender nickname] isEqualToString:@"NickServ"] ) { 1125 1140 NSString *msg = [[NSString allocWithZone:nil] initWithData:msgData encoding:[self encoding]]; 1141 if( ! msg ) msg = [[NSString allocWithZone:nil] initWithData:msgData encoding:NSISOLatin1StringEncoding]; 1126 1142 if( [msg rangeOfString:@"NickServ"].location != NSNotFound && [msg rangeOfString:@"IDENTIFY"].location != NSNotFound ) { 1127 1143 if( ! [self nicknamePassword] ) { … … 1152 1168 while( line != end && *line != ' ' ) line++; 1153 1169 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 1154 1172 NSMutableData *arguments = nil; 1155 1173 if( line != end ) arguments = [[NSMutableData allocWithZone:nil] initWithBytes:++line length:(end - line)]; … … 1207 1225 } else if( [command caseInsensitiveCompare:@"DCC"] == NSOrderedSame ) { 1208 1226 NSString *msg = [[NSString allocWithZone:nil] initWithData:arguments encoding:[self encoding]]; 1227 if( ! msg ) msg = [[NSString allocWithZone:nil] initWithData:arguments encoding:NSISOLatin1StringEncoding]; 1209 1228 1210 1229 NSString *subCommand = nil; … … 1662 1681 if( room && ! [room _namesSynced] ) { 1663 1682 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]]; 1665 1684 NSArray *members = [names componentsSeparatedByString:@" "]; 1666 1685 NSEnumerator *enumerator = [members objectEnumerator]; … … 1691 1710 } 1692 1711 1693 [names release];1694 1712 [pool drain]; 1695 1713 [pool release]; … … 1802 1820 [user _setUsername:[parameters objectAtIndex:2]]; 1803 1821 [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]]]; 1807 1823 } 1808 1824 } … … 1851 1867 - (void) _handle319WithParameters:(NSArray *) parameters fromSender:(id) sender { // RPL_WHOISCHANNELS 1852 1868 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]]; 1854 1870 NSArray *chanArray = [[rooms stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] componentsSeparatedByString:@" "]; 1855 1871 NSMutableArray *results = [[NSMutableArray allocWithZone:nil] initWithCapacity:[chanArray count]]; … … 1868 1884 } 1869 1885 1870 [rooms release];1871 1886 [results release]; 1872 1887 } … … 1875 1890 - (void) _handle320WithParameters:(NSArray *) parameters fromSender:(id) sender { // RPL_WHOISIDENTIFIED 1876 1891 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]]; 1878 1893 if( [comment rangeOfString:@"identified" options:NSCaseInsensitiveSearch].location != NSNotFound ) { 1879 1894 MVChatUser *user = [self chatUserWithUniqueIdentifier:[parameters objectAtIndex:1]]; 1880 1895 [user _setIdentified:YES]; 1881 1896 } 1882 [comment release];1883 1897 } 1884 1898 } trunk/Chat Core/MVIRCFileTransfer.m
r3172 r3174 273 273 [_threadWaitLock unlockWithCondition:0]; 274 274 275 if( ! _connectionThread ) return; 276 275 277 if( ! [self isPassive] ) [self performSelector:@selector( _waitForConnection ) inThread:_connectionThread]; 276 278 else [self performSelector:@selector( _connect ) inThread:_connectionThread]; … … 528 530 [_threadWaitLock unlockWithCondition:0]; 529 531 532 if( ! _connectionThread ) return; 533 530 534 if( ! [self isPassive] ) [self performSelector:@selector( _connect ) inThread:_connectionThread]; 531 535 else [self performSelector:@selector( _waitForConnection ) inThread:_connectionThread];
