ObjIRC  Diff

Differences From Artifact [e5ee986697]:

To Artifact [2f7ac026cf]:


25
26
27
28
29
30
31


32
33
34
35
36
37
38
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40







+
+







#import <ObjFW/OFString.h>
#import <ObjFW/OFArray.h>
#import <ObjFW/OFMutableDictionary.h>
#import <ObjFW/OFTCPSocket.h>
#import <ObjFW/OFAutoreleasePool.h>

#import <ObjFW/OFInvalidEncodingException.h>

#import <ObjFW/macros.h>

#import "IRCConnection.h"
#import "IRCUser.h"
#import "IRCChannel.h"

@implementation IRCConnection
@synthesize server, port, nickname, username, realname, delegate, sock;
159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
161
162
163
164
165
166
167

168
169
170

171
172
173


















174
175
176
177
178
179
180







-
+


-



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







}

- (void)changeNicknameTo: (OFString*)nickname_
{
	[self sendLineWithFormat: @"NICK %@", nickname_];
}

- (void)process
- (void)processLine: (OFString*)line
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFString *line;
	OFArray *split;
	OFString *action = nil;

	if (sock.atEndOfStream) {
		if ([delegate respondsToSelector:
		    @selector(connectionWasClosed:)])
			[delegate connectionWasClosed: self];

		return;
	}

	@try {
		line = [sock tryReadLine];
	} @catch (OFInvalidEncodingException *e) {
		line = [sock tryReadLineWithEncoding:
		    OF_STRING_ENCODING_WINDOWS_1252];
	}

	if (line == nil)
		return;

	if ([delegate respondsToSelector:
	    @selector(connection:didReceiveLine:)])
		[delegate connection: self
		      didReceiveLine: line];

	split = [line componentsSeparatedByString: @" "];

497
498
499
500
501
502
503
504







505
506
507
508
































509
510
511
512
513
514
515
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494




495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533








+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







					    fromUser: user];
		}

		[pool release];
		return;
	}
}

-	  (BOOL)connection: (OFTCPSocket*)connection
    didReceiveISO88591Line: (OFString*)line
		 exception: (OFException*)exception
{
	if (line != nil) {
		[self processLine: line];
		[sock asyncReadLineWithTarget: self
- (void)handleConnection
{
	while (![sock isAtEndOfStream])
		[self process];
				     selector: @selector(connection:
						   didReceiveLine:
						   exception:)];
	}

	return NO;
}

- (BOOL)connection: (OFTCPSocket*)connection
    didReceiveLine: (OFString*)line
	 exception: (OFException*)exception
{
	if (line != nil) {
		[self processLine: line];
		return YES;
	}

	if ([exception isKindOfClass: [OFInvalidEncodingException class]])
		[sock asyncReadLineWithEncoding: OF_STRING_ENCODING_ISO_8859_1
					 target: self
				       selector: @selector(connection:
						     didReceiveISO88591Line:
						     exception:)];

	return NO;
}

- (void)handleConnection
{
	[sock asyncReadLineWithTarget: self
			     selector: @selector(connection:didReceiveLine:
					   exception:)];
}

- (void)dealloc
{
	[sock release];
	[server release];
	[nickname release];