ObjIRC  Check-in [0ca6e4f04d]

Overview
Comment:IRCConnection: Make fallback encoding configurable
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0ca6e4f04d891d2bcc17cacb15ad6e17090624bf65efed09999a26e9c9998192
User & Date: js on 2017-01-22 20:49:44
Other Links: manifest | tags
Context
2017-01-22
23:01
Add ping timeout check-in: c17c999968 user: js tags: trunk
20:49
IRCConnection: Make fallback encoding configurable check-in: 0ca6e4f04d user: js tags: trunk
17:24
IRCConnection: Make the socket class configurable check-in: 38de3de8ed user: js tags: trunk
Changes

Modified src/IRCConnection.h from [de62d2cefb] to [c6f6102a91].

77
78
79
80
81
82
83

84
85
86
87
88
89
90
91

92
93
94
95
96
97
98
	Class _socketClass;
	OF_KINDOF(OFTCPSocket) *_socket;
	OFString *_server;
	uint16_t _port;
	OFString *_nickname, *_username, *_realname;
	OFMutableDictionary *_channels;
	id <IRCConnectionDelegate> _delegate;

}

@property (assign) Class socketClass;
@property (copy) OFString *server;
@property (assign) uint16_t port;
@property (copy) OFString *nickname, *username, *realname;
@property (assign) id <IRCConnectionDelegate> delegate;
@property (readonly, retain) OFTCPSocket *socket;


+ (instancetype)connection;
- (void)sendLine: (OFString*)line;
- (void)sendLineWithFormat: (OFConstantString*)line, ...;
- (void)connect;
- (void)disconnect;
- (void)disconnectWithReason: (OFString*)reason;







>




|



>







77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
	Class _socketClass;
	OF_KINDOF(OFTCPSocket) *_socket;
	OFString *_server;
	uint16_t _port;
	OFString *_nickname, *_username, *_realname;
	OFMutableDictionary *_channels;
	id <IRCConnectionDelegate> _delegate;
	of_string_encoding_t _fallbackEncoding;
}

@property (assign) Class socketClass;
@property (copy) OFString *server;
@property uint16_t port;
@property (copy) OFString *nickname, *username, *realname;
@property (assign) id <IRCConnectionDelegate> delegate;
@property (readonly, retain) OFTCPSocket *socket;
@property of_string_encoding_t fallbackEncoding;

+ (instancetype)connection;
- (void)sendLine: (OFString*)line;
- (void)sendLineWithFormat: (OFConstantString*)line, ...;
- (void)connect;
- (void)disconnect;
- (void)disconnectWithReason: (OFString*)reason;

Modified src/IRCConnection.m from [6579a2f540] to [475d90a93d].

38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
#import "IRCUser.h"

@implementation IRCConnection
@synthesize socketClass = _socketClass;
@synthesize server = _server, port = _port;
@synthesize nickname = _nickname, username = _username, realname = _realname;
@synthesize delegate = _delegate, socket = _socket;


+ (instancetype)connection
{
	return [[[self alloc] init] autorelease];
}

- init
{
	self = [super init];

	@try {
		_socketClass = [OFTCPSocket class];
		_channels = [[OFMutableDictionary alloc] init];
		_port = 6667;

	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}







>














>







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#import "IRCUser.h"

@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];
}

- init
{
	self = [super init];

	@try {
		_socketClass = [OFTCPSocket class];
		_channels = [[OFMutableDictionary alloc] init];
		_port = 6667;
		_fallbackEncoding = OF_STRING_ENCODING_ISO_8859_1;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
	void *pool = objc_autoreleasePoolPush();

	[self IRC_processLine: line];

	objc_autoreleasePoolPop(pool);
}

-	    (bool)socket: (OFTCPSocket*)socket
  didReceiveISO88591Line: (OFString*)line
	       exception: (OFException*)exception
{
	if (line != nil) {
		[self IRC_processLine: line];
		[socket asyncReadLineWithTarget: self
				       selector: @selector(socket:
						     didReceiveLine:
						     exception:)];







|
|
|







532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
	void *pool = objc_autoreleasePoolPush();

	[self IRC_processLine: line];

	objc_autoreleasePoolPop(pool);
}

-		  (bool)socket: (OFTCPSocket*)socket
  didReceiveWronglyEncodedLine: (OFString*)line
		     exception: (OFException*)exception
{
	if (line != nil) {
		[self IRC_processLine: line];
		[socket asyncReadLineWithTarget: self
				       selector: @selector(socket:
						     didReceiveLine:
						     exception:)];
555
556
557
558
559
560
561

562
563
564
565
566
567
568
569
570
571
572
573
{
	if (line != nil) {
		[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:)];
		return false;
	}

	if ([_delegate respondsToSelector: @selector(connectionWasClosed:)]) {
		[_delegate connectionWasClosed: self];
		[_socket release];
		_socket = nil;







>
|
|
|
|
|







557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
{
	if (line != nil) {
		[self IRC_processLine: line];
		return true;
	}

	if ([exception isKindOfClass: [OFInvalidEncodingException class]]) {
		[socket
		    asyncReadLineWithEncoding: _fallbackEncoding
				       target: self
				     selector: @selector(socket:
						   didReceiveWronglyEncodedLine:
						   exception:)];
		return false;
	}

	if ([_delegate respondsToSelector: @selector(connectionWasClosed:)]) {
		[_delegate connectionWasClosed: self];
		[_socket release];
		_socket = nil;