From 0dd8cdc46a14d32861d7b030e8e5b21e22c1927a Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sun, 22 Jan 2017 20:49:44 +0000 Subject: [PATCH] IRCConnection: Make fallback encoding configurable FossilOrigin-Name: 0ca6e4f04d891d2bcc17cacb15ad6e17090624bf65efed09999a26e9c9998192 --- src/IRCConnection.h | 4 +++- src/IRCConnection.m | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/IRCConnection.h b/src/IRCConnection.h index 9484936..0ee023d 100644 --- a/src/IRCConnection.h +++ b/src/IRCConnection.h @@ -81,14 +81,16 @@ 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; diff --git a/src/IRCConnection.m b/src/IRCConnection.m index 61d3123..9b52980 100644 --- a/src/IRCConnection.m +++ b/src/IRCConnection.m @@ -42,6 +42,7 @@ @synthesize server = _server, port = _port; @synthesize nickname = _nickname, username = _username, realname = _realname; @synthesize delegate = _delegate, socket = _socket; +@synthesize fallbackEncoding = _fallbackEncoding; + (instancetype)connection { @@ -56,6 +57,7 @@ _socketClass = [OFTCPSocket class]; _channels = [[OFMutableDictionary alloc] init]; _port = 6667; + _fallbackEncoding = OF_STRING_ENCODING_ISO_8859_1; } @catch (id e) { [self release]; @throw e; @@ -534,9 +536,9 @@ 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]; @@ -559,11 +561,12 @@ } 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; }