Index: src/IRCConnection.h ================================================================== --- src/IRCConnection.h +++ src/IRCConnection.h @@ -79,18 +79,20 @@ OFString *_server; uint16_t _port; OFString *_nickname, *_username, *_realname; OFMutableDictionary *_channels; id _delegate; + of_string_encoding_t _fallbackEncoding; } @property (assign) Class socketClass; @property (copy) OFString *server; -@property (assign) uint16_t port; +@property uint16_t port; @property (copy) OFString *nickname, *username, *realname; @property (assign) id delegate; @property (readonly, retain) OFTCPSocket *socket; +@property of_string_encoding_t fallbackEncoding; + (instancetype)connection; - (void)sendLine: (OFString*)line; - (void)sendLineWithFormat: (OFConstantString*)line, ...; - (void)connect; Index: src/IRCConnection.m ================================================================== --- src/IRCConnection.m +++ src/IRCConnection.m @@ -40,10 +40,11 @@ @implementation IRCConnection @synthesize socketClass = _socketClass; @synthesize server = _server, port = _port; @synthesize nickname = _nickname, username = _username, realname = _realname; @synthesize delegate = _delegate, socket = _socket; +@synthesize fallbackEncoding = _fallbackEncoding; + (instancetype)connection { return [[[self alloc] init] autorelease]; } @@ -54,10 +55,11 @@ @try { _socketClass = [OFTCPSocket class]; _channels = [[OFMutableDictionary alloc] init]; _port = 6667; + _fallbackEncoding = OF_STRING_ENCODING_ISO_8859_1; } @catch (id e) { [self release]; @throw e; } @@ -532,13 +534,13 @@ [self IRC_processLine: line]; objc_autoreleasePoolPop(pool); } -- (bool)socket: (OFTCPSocket*)socket - didReceiveISO88591Line: (OFString*)line - exception: (OFException*)exception +- (bool)socket: (OFTCPSocket*)socket + didReceiveWronglyEncodedLine: (OFString*)line + exception: (OFException*)exception { if (line != nil) { [self IRC_processLine: line]; [socket asyncReadLineWithTarget: self selector: @selector(socket: @@ -557,15 +559,16 @@ [self IRC_processLine: line]; return true; } if ([exception isKindOfClass: [OFInvalidEncodingException class]]) { - [socket asyncReadLineWithEncoding: OF_STRING_ENCODING_ISO_8859_1 - target: self - selector: @selector(socket: - didReceiveISO88591Line: - exception:)]; + [socket + asyncReadLineWithEncoding: _fallbackEncoding + target: self + selector: @selector(socket: + didReceiveWronglyEncodedLine: + exception:)]; return false; } if ([_delegate respondsToSelector: @selector(connectionWasClosed:)]) { [_delegate connectionWasClosed: self];