ObjIRC  Check-in [42243ac2f7]

Overview
Comment:Adjust to ObjFW changes
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 42243ac2f70297a6b48b7cd7d0a53b8ee49cc69a430c156d730a335af3bc3ed3
User & Date: js on 2018-12-17 21:04:49
Other Links: manifest | tags
Context
2021-04-29
00:48
Adjust to ObjFW changes check-in: 3bf621892c user: js tags: trunk
2018-12-17
21:04
Adjust to ObjFW changes check-in: 42243ac2f7 user: js tags: trunk
2018-11-11
10:47
Fix method signature mismatch check-in: 75e955fa17 user: js tags: trunk
Changes

Modified src/IRCConnection.h from [c619025088] to [a48a25139f].

33
34
35
36
37
38
39


40
41
42
43
44
45
46
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48







+
+







- (void)connection: (IRCConnection *)connection
   didCreateSocket: (OF_KINDOF(OFTCPSocket *))socket;
- (void)connection: (IRCConnection *)connection
    didReceiveLine: (OFString *)line;
- (void)connection: (IRCConnection *)connection
       didSendLine: (OFString *)line;
- (void)connectionWasEstablished: (IRCConnection *)connection;
-	       (void)connection: (IRCConnection *)connection
  didFailToConnectWithException: (id)exception;
- (void)connection: (IRCConnection *)connection
	didSeeUser: (IRCUser *)user
       joinChannel: (OFString *)channel;
- (void)connection: (IRCConnection *)connection
	didSeeUser: (IRCUser *)user
      leaveChannel: (OFString *)channel
	    reason: (nullable OFString *)reason;
84
85
86
87
88
89
90

91
92
93
94
95
96
97
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100







+







	OFString *_Nullable _realname;
	OFMutableDictionary OF_GENERIC(OFString *, OFMutableSet *) *_channels;
	id <IRCConnectionDelegate> _Nullable _delegate;
	of_string_encoding_t _fallbackEncoding;
	of_time_interval_t _pingInterval, _pingTimeout;
	OFString *_Nullable _pingData;
	OFTimer *_Nullable _pingTimer;
	bool _fallbackEncodingUsed;
}

@property (readonly, nonatomic) Class socketClass;
@property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *server;
@property (nonatomic) uint16_t port;
@property OF_NULLABLE_PROPERTY (copy, nonatomic)
    OFString *nickname, *username, *realname;
116
117
118
119
120
121
122
123
124
125
126
127
128
119
120
121
122
123
124
125


126
127
128
129







-
-




		 to: (OFString *)to;
- (void)sendNotice: (OFString *)notice
		to: (OFString *)to;
- (void)kickUser: (OFString *)user
	 channel: (OFString *)channel
	  reason: (nullable OFString *)reason;
- (void)changeNicknameTo: (OFString *)nickname;
- (void)processLine: (OFString *)line;
- (void)handleConnection;
- (nullable OFSet OF_GENERIC(OFString *) *)usersInChannel: (OFString *)channel;
@end

OF_ASSUME_NONNULL_END

Modified src/IRCConnection.m from [e49892a8ab] to [45ed4ab7ae].

32
33
34
35
36
37
38



39
40
41
42
43
44
45
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48







+
+
+








#import <ObjFW/OFInvalidEncodingException.h>

#import <ObjFW/macros.h>

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

@interface IRCConnection () <OFTCPSocketDelegate>
@end

@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;
87
88
89
90
91
92
93





















94
95
96
97
98
99
100
101
102
103
104
105

106
107
108
109
110
111
112
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122



123
124
125

126
127
128
129
130
131
132
133







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
-
-



-
+







{
	void *pool = objc_autoreleasePoolPush();

	if (_socket != nil)
		@throw [OFAlreadyConnectedException exception];

	_socket = [[_socketClass alloc] init];
	[_socket setDelegate: self];
	[_socket asyncConnectToHost: _server
			       port: _port];

	objc_autoreleasePoolPop(pool);
}

-     (void)socket: (OF_KINDOF(OFTCPSocket *))socket
  didConnectToHost: (OFString *)host
	      port: (uint16_t)port
	 exception: (id)exception
{
	if (exception != nil) {
		if ([_delegate respondsToSelector:
		    @selector(connection:didFailToConnectWithException:)])
			[_delegate	       connection: self
			    didFailToConnectWithException: exception];

		return;
	}

	if ([_delegate respondsToSelector:
	    @selector(connection:didCreateSocket:)])
		[_delegate connection: self
		      didCreateSocket: _socket];

	[_socket connectToHost: _server
			  port: _port];

	[self sendLineWithFormat: @"NICK %@", _nickname];
	[self sendLineWithFormat: @"USER %@ * 0 :%@", _username, _realname];

	objc_autoreleasePoolPop(pool);
	[socket asyncReadLine];
}

- (void)disconnect
{
	[self disconnectWithReason: nil];
}

571
572
573
574
575
576
577
578
579
580
581

582
583
584
585
586
587
588

589
590

591
592
593
594
595
596
597
598
599
600
601
602






603
604
605
606
607
608
609
610
611
612
613
614
615
616


617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
592
593
594
595
596
597
598




599







600


601
602
603
604









605
606
607
608
609
610
611







612
613
614
615


616
617





618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633








634
635
636
637
638







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



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

-
-
-
-
-
-
-




-
-
+
+
-
-
-
-
-
















-
-
-
-
-
-
-
-





		[_delegate connectionWasClosed: self];

	[_socket cancelAsyncRequests];
	[_socket release];
	_socket = nil;
}

- (void)processLine: (OFString *)line
{
	void *pool = objc_autoreleasePoolPush();

- (bool)stream: (OF_KINDOF(OFStream *))stream
	[self irc_processLine: line];

	objc_autoreleasePoolPop(pool);
}

-	      (bool)irc_socket: (OFTCPSocket *)socket
  didReceiveWronglyEncodedLine: (OFString *)line
   didReadLine: (OFString *)line
		       context: (id)context
		     exception: (OFException *)exception
     exception: (OFException *)exception
{
	if (line != nil) {
		[self irc_processLine: line];
		[socket asyncReadLineWithTarget: self
				       selector: @selector(irc_socket:
						     didReceiveLine:context:
						     exception:)
					context: nil];
	}

	return false;
}

		if (_fallbackEncodingUsed) {
			_fallbackEncodingUsed = false;
			[stream asyncReadLine];
			return false;
		}

- (bool)irc_socket: (OFTCPSocket *)socket
    didReceiveLine: (OFString *)line
	   context: (id)context
	 exception: (OFException *)exception
{
	if (line != nil) {
		[self irc_processLine: line];
		return true;
	}

	if ([exception isKindOfClass: [OFInvalidEncodingException class]]) {
		[socket
		    asyncReadLineWithEncoding: _fallbackEncoding
		_fallbackEncodingUsed = true;
		[stream asyncReadLineWithEncoding: _fallbackEncoding];
				       target: self
				     selector: @selector(irc_socket:
						   didReceiveWronglyEncodedLine:
						   context:exception:)
				      context: nil];
		return false;
	}

	if ([_delegate respondsToSelector: @selector(connectionWasClosed:)])
		[_delegate connectionWasClosed: self];

	[_pingTimer invalidate];

	[_socket performSelector: @selector(cancelAsyncRequests)
		      afterDelay: 0];
	[_socket release];
	_socket = nil;

	return false;
}

- (void)handleConnection
{
	[_socket asyncReadLineWithTarget: self
				selector: @selector(irc_socket:didReceiveLine:
					      context:exception:)
				 context: nil];
}

- (OFSet OF_GENERIC(OFString *) *)usersInChannel: (OFString *)channel
{
	return [[[_channels objectForKey: channel] copy] autorelease];
}
@end

Modified tests/tests.m from [ce0aa7ef08] to [e0efa0bc26].

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
68
69
70
71
72
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
68
69
70
71
72
73
74
75
76
77
78
79







-


















+
+
+
+
+
+
+
+







	[connection setServer: @"irc.freenode.net"];
	[connection setNickname: @"ObjIRC"];
	[connection setUsername: @"ObjIRC"];
	[connection setRealname: @"ObjIRC"];
	[connection setDelegate: self];

	[connection connect];
	[connection handleConnection];
}

- (void)connection: (IRCConnection*)connection
    didReceiveLine: (OFString*)line
{
	[of_stderr writeFormat: @"> %@\n", line];
}

- (void)connection: (IRCConnection*)connection
       didSendLine: (OFString*)line
{
	[of_stderr writeFormat: @"< %@\n", line];
}

- (void)connectionWasEstablished: (IRCConnection*)connection
{
	[connection joinChannel: @"#objfw"];
}

-	       (void)connection: (IRCConnection *)connection
  didFailToConnectWithException: (id)exception
{
	[of_stderr writeFormat: @"Failed to connect: %@\n", exception];

	[OFApplication terminateWithStatus: 1];
}

- (void)connection: (IRCConnection*)connection
	didSeeUser: (IRCUser*)user
       joinChannel: (OFString*)channel
{
	of_log(@"%@ joined %@.", user, channel);
}