ObjIRC  Check-in [7a7f60e3e6]

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: 7a7f60e3e63b1d8bd67b43effb98703320fa689801e4fd575aae26f5354882c9
User & Date: js on 2018-11-06 22:20:12
Other Links: manifest | tags
Context
2018-11-06
22:26
Readd autogen.sh check-in: 92aea1ca90 user: js tags: trunk
22:20
Adjust to ObjFW changes check-in: 7a7f60e3e6 user: js tags: trunk
2017-05-08
00:54
Adjust to recent ObjFW changes check-in: 5dbb32c633 user: js tags: trunk
Changes

Modified src/IRCConnection.h from [161d77c9d0] to [dc79d3b924].

19
20
21
22
23
24
25


26
27
28
29
30
31
32
33
34
35
36
37
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
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import <ObjFW/ObjFW.h>



@class IRCConnection;
@class IRCUser;

@protocol IRCConnectionDelegate <OFObject>
@optional
- (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
	didSeeUser: (IRCUser *)user
       joinChannel: (OFString *)channel;
- (void)connection: (IRCConnection *)connection
	didSeeUser: (IRCUser *)user
      leaveChannel: (OFString *)channel
	    reason: (OFString *)reason;
- (void)connection: (IRCConnection *)connection
        didSeeUser: (IRCUser *)user
  changeNicknameTo: (OFString *)nickname;
- (void)connection: (IRCConnection *)connection
	didSeeUser: (IRCUser *)user
	  kickUser: (OFString *)kickedUser
	   channel: (OFString *)channel
	    reason: (OFString *)reason;
- (void)connection: (IRCConnection *)connection
    didSeeUserQuit: (IRCUser *)user
	    reason: (OFString *)reason;
-  (void)connection: (IRCConnection *)connection
  didReceiveMessage: (OFString *)msg
	    channel: (OFString *)channel
	       user: (IRCUser *)user;
-	  (void)connection: (IRCConnection *)connection
  didReceivePrivateMessage: (OFString *)msg
		      user: (IRCUser *)user;







>
>


















|







|


|







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import <ObjFW/ObjFW.h>

OF_ASSUME_NONNULL_BEGIN

@class IRCConnection;
@class IRCUser;

@protocol IRCConnectionDelegate <OFObject>
@optional
- (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
	didSeeUser: (IRCUser *)user
       joinChannel: (OFString *)channel;
- (void)connection: (IRCConnection *)connection
	didSeeUser: (IRCUser *)user
      leaveChannel: (OFString *)channel
	    reason: (nullable OFString *)reason;
- (void)connection: (IRCConnection *)connection
        didSeeUser: (IRCUser *)user
  changeNicknameTo: (OFString *)nickname;
- (void)connection: (IRCConnection *)connection
	didSeeUser: (IRCUser *)user
	  kickUser: (OFString *)kickedUser
	   channel: (OFString *)channel
	    reason: (nullable OFString *)reason;
- (void)connection: (IRCConnection *)connection
    didSeeUserQuit: (IRCUser *)user
	    reason: (nullable OFString *)reason;
-  (void)connection: (IRCConnection *)connection
  didReceiveMessage: (OFString *)msg
	    channel: (OFString *)channel
	       user: (IRCUser *)user;
-	  (void)connection: (IRCConnection *)connection
  didReceivePrivateMessage: (OFString *)msg
		      user: (IRCUser *)user;
71
72
73
74
75
76
77
78
79
80

81
82
83
84
85
86
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
113
114
115
116
117
118
119
120


  didReceiveNamesForChannel: (OFString *)channel;
- (void)connectionWasClosed: (IRCConnection *)connection;
@end

@interface IRCConnection: OFObject
{
	Class _socketClass;
	OF_KINDOF(OFTCPSocket) *_socket;
	OFString *_server;
	uint16_t _port;

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

@property (assign) Class socketClass;

@property (nonatomic, copy) OFString *server;
@property uint16_t port;
@property (nonatomic, copy) OFString *nickname, *username, *realname;

@property (assign) id <IRCConnectionDelegate> delegate;
@property (readonly, nonatomic) OFTCPSocket *socket;

@property of_string_encoding_t fallbackEncoding;
@property of_time_interval_t pingInterval, pingTimeout;

+ (instancetype)connection;
- (void)sendLine: (OFString *)line;
- (void)sendLineWithFormat: (OFConstantString *)line, ...;
- (void)connect;
- (void)disconnect;
- (void)disconnectWithReason: (OFString *)reason;
- (void)joinChannel: (OFString *)channelName;
- (void)leaveChannel: (OFString *)channel;
- (void)leaveChannel: (OFString *)channel
	      reason: (OFString *)reason;
- (void)sendMessage: (OFString *)msg
		 to: (OFString *)to;
- (void)sendNotice: (OFString *)notice
		to: (OFString *)to;
- (void)kickUser: (OFString *)user
	 channel: (OFString *)channel
	  reason: (OFString *)reason;
- (void)changeNicknameTo: (OFString *)nickname;
- (void)processLine: (OFString *)line;
- (void)handleConnection;
- (OFSet OF_GENERIC(OFString *) *)usersInChannel: (OFString *)channel;
@end









|
|

>
|

|


|
|


|
>
|
|
|
>
|
|
>
|
|






|



|
|





|



|

>
>
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
  didReceiveNamesForChannel: (OFString *)channel;
- (void)connectionWasClosed: (IRCConnection *)connection;
@end

@interface IRCConnection: OFObject
{
	Class _socketClass;
	OF_KINDOF(OFTCPSocket) *_Nullable _socket;
	OFString *_Nullable _server;
	uint16_t _port;
	OFString *_Nullable _nickname, *_Nullable _username;
	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;
}

@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;
@property OF_NULLABLE_PROPERTY (assign, nonatomic)
    id <IRCConnectionDelegate> delegate;
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    OF_KINDOF(OFTCPSocket *) socket;
@property (nonatomic) of_string_encoding_t fallbackEncoding;
@property (nonatomic) of_time_interval_t pingInterval, pingTimeout;

+ (instancetype)connection;
- (void)sendLine: (OFString *)line;
- (void)sendLineWithFormat: (OFConstantString *)line, ...;
- (void)connect;
- (void)disconnect;
- (void)disconnectWithReason: (nullable OFString *)reason;
- (void)joinChannel: (OFString *)channelName;
- (void)leaveChannel: (OFString *)channel;
- (void)leaveChannel: (OFString *)channel
	      reason: (nullable OFString *)reason;
- (void)sendMessage: (OFString *)message
		 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 [40d21b42ac] to [688cb09cde].

180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
	va_end(args);

	[self sendLine: line];

	objc_autoreleasePoolPop(pool);
}

- (void)sendMessage: (OFString *)msg
		 to: (OFString *)to
{
	void *pool = objc_autoreleasePoolPush();

	for (OFString *line in [msg componentsSeparatedByString: @"\n"])
		[self sendLineWithFormat: @"PRIVMSG %@ :%@", to, line];

	objc_autoreleasePoolPop(pool);
}

- (void)sendNotice: (OFString *)notice
		to: (OFString *)to







|




|







180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
	va_end(args);

	[self sendLine: line];

	objc_autoreleasePoolPop(pool);
}

- (void)sendMessage: (OFString *)message
		 to: (OFString *)to
{
	void *pool = objc_autoreleasePoolPush();

	for (OFString *line in [message componentsSeparatedByString: @"\n"])
		[self sendLineWithFormat: @"PRIVMSG %@ :%@", to, line];

	objc_autoreleasePoolPop(pool);
}

- (void)sendNotice: (OFString *)notice
		to: (OFString *)to
478
479
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
	}

	/* PRIVMSG */
	if ([action isEqual: @"PRIVMSG"] && [components count] >= 4) {
		OFString *from = [components objectAtIndex: 0];
		OFString *to = [components objectAtIndex: 2];
		IRCUser *user;
		OFString *msg;
		size_t pos = [from length] + 1 +
		    [[components objectAtIndex: 1] length] + 1 + [to length];

		from = [from substringWithRange:
		    of_range(1, [from length] - 1)];
		msg = [line substringWithRange:
		    of_range(pos + 2, [line length] - pos - 2)];
		user = [IRCUser IRCUserWithString: from];

		if (![to isEqual: _nickname]) {
			if ([_delegate respondsToSelector: @selector(connection:
			    didReceiveMessage:channel:user:)])
				[_delegate connection: self
				    didReceiveMessage: msg
					      channel: to
						 user: user];
		} else {
			if ([_delegate respondsToSelector: @selector(connection:
			    didReceivePrivateMessage:user:)])
				[_delegate	  connection: self
				    didReceivePrivateMessage: msg
							user: user];
		}

		return;
	}

	/* NOTICE */







|





|







|






|







478
479
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
	}

	/* PRIVMSG */
	if ([action isEqual: @"PRIVMSG"] && [components count] >= 4) {
		OFString *from = [components objectAtIndex: 0];
		OFString *to = [components objectAtIndex: 2];
		IRCUser *user;
		OFString *message;
		size_t pos = [from length] + 1 +
		    [[components objectAtIndex: 1] length] + 1 + [to length];

		from = [from substringWithRange:
		    of_range(1, [from length] - 1)];
		message = [line substringWithRange:
		    of_range(pos + 2, [line length] - pos - 2)];
		user = [IRCUser IRCUserWithString: from];

		if (![to isEqual: _nickname]) {
			if ([_delegate respondsToSelector: @selector(connection:
			    didReceiveMessage:channel:user:)])
				[_delegate connection: self
				    didReceiveMessage: message
					      channel: to
						 user: user];
		} else {
			if ([_delegate respondsToSelector: @selector(connection:
			    didReceivePrivateMessage:user:)])
				[_delegate	  connection: self
				    didReceivePrivateMessage: message
							user: user];
		}

		return;
	}

	/* NOTICE */
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
		     exception: (OFException *)exception
{
	if (line != nil) {
		[self IRC_processLine: line];
		[socket asyncReadLineWithTarget: self
				       selector: @selector(socket:
						     didReceiveLine:
						     exception:)];

	}

	return false;
}

-   (bool)socket: (OFTCPSocket *)socket
  didReceiveLine: (OFString *)line
       exception: (OFException *)exception
{
	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];

	[_pingTimer invalidate];

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

	return false;
}

- (void)handleConnection
{
	[_socket asyncReadLineWithTarget: self
				selector: @selector(socket:didReceiveLine:
					      exception:)];

}

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







|
>




















|
>




















|
>







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
		     exception: (OFException *)exception
{
	if (line != nil) {
		[self IRC_processLine: line];
		[socket asyncReadLineWithTarget: self
				       selector: @selector(socket:
						     didReceiveLine:
						     exception:)
					context: nil];
	}

	return false;
}

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

	if ([exception isKindOfClass: [OFInvalidEncodingException class]]) {
		[socket
		    asyncReadLineWithEncoding: _fallbackEncoding
				       target: self
				     selector: @selector(socket:
						   didReceiveWronglyEncodedLine:
						   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(socket:didReceiveLine:
					      exception:)
				 context: nil];
}

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

Modified src/IRCUser.h from [0435690016] to [cded263823].

18
19
20
21
22
23
24


25
26
27
28
29
30
31
32
33
34
35


 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import <ObjFW/OFObject.h>



@interface IRCUser: OFObject <OFCopying>
{
	OFString *_nickname, *_username, *_hostname;
}

@property (readonly, nonatomic) OFString *nickname, *username, *hostname;

+ (instancetype)IRCUserWithString: (OFString *)string;
- initWithString: (OFString *)string;
@end









>
>









|

>
>
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import <ObjFW/OFObject.h>

OF_ASSUME_NONNULL_BEGIN

@interface IRCUser: OFObject <OFCopying>
{
	OFString *_nickname, *_username, *_hostname;
}

@property (readonly, nonatomic) OFString *nickname, *username, *hostname;

+ (instancetype)IRCUserWithString: (OFString *)string;
- (instancetype)initWithString: (OFString *)string OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Modified src/IRCUser.m from [3d00fb209b] to [61a450e638].

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@synthesize username = _username, nickname = _nickname, hostname = _hostname;

+ (instancetype)IRCUserWithString: (OFString *)string
{
	return [[[self alloc] initWithString: string] autorelease];
}

- initWithString: (OFString *)string
{
	char *tmp2 = NULL;

	self = [super init];

	@try {
		char *tmp;







|







37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@synthesize username = _username, nickname = _nickname, hostname = _hostname;

+ (instancetype)IRCUserWithString: (OFString *)string
{
	return [[[self alloc] initWithString: string] autorelease];
}

- (instancetype)initWithString: (OFString *)string
{
	char *tmp2 = NULL;

	self = [super init];

	@try {
		char *tmp;
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
	[_nickname release];
	[_username release];
	[_hostname release];

	[super dealloc];
}

- copy
{
	return [self retain];
}

- (OFString *)description
{
	return [OFString stringWithFormat: @"%@!%@@%@",
					   _nickname, _username, _hostname];
}
@end







|










84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
	[_nickname release];
	[_username release];
	[_hostname release];

	[super dealloc];
}

- (id)copy
{
	return [self retain];
}

- (OFString *)description
{
	return [OFString stringWithFormat: @"%@!%@@%@",
					   _nickname, _username, _hostname];
}
@end