IRCConnection: Make fallback encoding configurable
FossilOrigin-Name: 0ca6e4f04d891d2bcc17cacb15ad6e17090624bf65efed09999a26e9c9998192
This commit is contained in:
parent
21784a8d30
commit
0dd8cdc46a
2 changed files with 14 additions and 9 deletions
|
@ -81,14 +81,16 @@
|
||||||
OFString *_nickname, *_username, *_realname;
|
OFString *_nickname, *_username, *_realname;
|
||||||
OFMutableDictionary *_channels;
|
OFMutableDictionary *_channels;
|
||||||
id <IRCConnectionDelegate> _delegate;
|
id <IRCConnectionDelegate> _delegate;
|
||||||
|
of_string_encoding_t _fallbackEncoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (assign) Class socketClass;
|
@property (assign) Class socketClass;
|
||||||
@property (copy) OFString *server;
|
@property (copy) OFString *server;
|
||||||
@property (assign) uint16_t port;
|
@property uint16_t port;
|
||||||
@property (copy) OFString *nickname, *username, *realname;
|
@property (copy) OFString *nickname, *username, *realname;
|
||||||
@property (assign) id <IRCConnectionDelegate> delegate;
|
@property (assign) id <IRCConnectionDelegate> delegate;
|
||||||
@property (readonly, retain) OFTCPSocket *socket;
|
@property (readonly, retain) OFTCPSocket *socket;
|
||||||
|
@property of_string_encoding_t fallbackEncoding;
|
||||||
|
|
||||||
+ (instancetype)connection;
|
+ (instancetype)connection;
|
||||||
- (void)sendLine: (OFString*)line;
|
- (void)sendLine: (OFString*)line;
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
@synthesize server = _server, port = _port;
|
@synthesize server = _server, port = _port;
|
||||||
@synthesize nickname = _nickname, username = _username, realname = _realname;
|
@synthesize nickname = _nickname, username = _username, realname = _realname;
|
||||||
@synthesize delegate = _delegate, socket = _socket;
|
@synthesize delegate = _delegate, socket = _socket;
|
||||||
|
@synthesize fallbackEncoding = _fallbackEncoding;
|
||||||
|
|
||||||
+ (instancetype)connection
|
+ (instancetype)connection
|
||||||
{
|
{
|
||||||
|
@ -56,6 +57,7 @@
|
||||||
_socketClass = [OFTCPSocket class];
|
_socketClass = [OFTCPSocket class];
|
||||||
_channels = [[OFMutableDictionary alloc] init];
|
_channels = [[OFMutableDictionary alloc] init];
|
||||||
_port = 6667;
|
_port = 6667;
|
||||||
|
_fallbackEncoding = OF_STRING_ENCODING_ISO_8859_1;
|
||||||
} @catch (id e) {
|
} @catch (id e) {
|
||||||
[self release];
|
[self release];
|
||||||
@throw e;
|
@throw e;
|
||||||
|
@ -534,9 +536,9 @@
|
||||||
objc_autoreleasePoolPop(pool);
|
objc_autoreleasePoolPop(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (bool)socket: (OFTCPSocket*)socket
|
- (bool)socket: (OFTCPSocket*)socket
|
||||||
didReceiveISO88591Line: (OFString*)line
|
didReceiveWronglyEncodedLine: (OFString*)line
|
||||||
exception: (OFException*)exception
|
exception: (OFException*)exception
|
||||||
{
|
{
|
||||||
if (line != nil) {
|
if (line != nil) {
|
||||||
[self IRC_processLine: line];
|
[self IRC_processLine: line];
|
||||||
|
@ -559,11 +561,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([exception isKindOfClass: [OFInvalidEncodingException class]]) {
|
if ([exception isKindOfClass: [OFInvalidEncodingException class]]) {
|
||||||
[socket asyncReadLineWithEncoding: OF_STRING_ENCODING_ISO_8859_1
|
[socket
|
||||||
target: self
|
asyncReadLineWithEncoding: _fallbackEncoding
|
||||||
selector: @selector(socket:
|
target: self
|
||||||
didReceiveISO88591Line:
|
selector: @selector(socket:
|
||||||
exception:)];
|
didReceiveWronglyEncodedLine:
|
||||||
|
exception:)];
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue