ObjIRC  Check-in [1813701690]

Overview
Comment:Adjust to ObjFW API and fix a disconnect bug.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 18137016905f0581bc493e61961522356acab11c15d53f561447045acc6e202c
User & Date: js on 2013-07-12 14:12:16
Other Links: manifest | tags
Context
2016-05-07
11:21
Adjust to ObjFW changes check-in: e7f0831117 user: js tags: trunk
2013-07-12
14:12
Adjust to ObjFW API and fix a disconnect bug. check-in: 1813701690 user: js tags: trunk
2013-02-16
22:42
Fix wrong selector name. check-in: 09ffe6e374 user: js tags: trunk
Changes

Modified src/IRCConnection.h from [940ece26d9] to [aec6e61116].

85
86
87
88
89
90
91

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







+







@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;
#endif

+ (instancetype)connection;
- (void)setServer: (OFString*)server;
- (OFString*)server;
- (void)setPort: (uint16_t)port;
- (uint16_t)port;
- (void)setNickname: (OFString*)nickname;
- (OFString*)nickname;
- (void)setUsername: (OFString*)username;

Modified src/IRCConnection.m from [db72e704d4] to [adb245b3eb].

34
35
36
37
38
39
40





41
42
43
44
45
46
47
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52







+
+
+
+
+








#import <ObjFW/macros.h>

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

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

- init
{
	self = [super init];

	@try {
		_channels = [[OFMutableDictionary alloc] init];
		_port = 6667;
63
64
65
66
67
68
69
70

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
121
122
123
124
125

126
127
128
129
130

131
132
133
134
135
136



137
138
139
140
141
142
143
68
69
70
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
121
122
123
124
125
126
127
128
129

130
131
132
133
134

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151







-
+




-
+














-
+




-
+




-
+




-
+




-
+




-
+









-
+




-
+






+
+
+







	[_channels release];

	[super dealloc];
}

- (void)setServer: (OFString*)server
{
	OF_SETTER(_server, server, YES, YES)
	OF_SETTER(_server, server, true, 1)
}

- (OFString*)server
{
	OF_GETTER(_server, YES)
	OF_GETTER(_server, true)
}

- (void)setPort: (uint16_t)port
{
	_port = port;
}

- (uint16_t)port
{
	return _port;
}

- (void)setNickname: (OFString*)nickname
{
	OF_SETTER(_nickname, nickname, YES, YES)
	OF_SETTER(_nickname, nickname, true, 1)
}

- (OFString*)nickname
{
	OF_GETTER(_nickname, YES)
	OF_GETTER(_nickname, true)
}

- (void)setUsername: (OFString*)username
{
	OF_SETTER(_username, username, YES, YES)
	OF_SETTER(_username, username, true, 1)
}

- (OFString*)username
{
	OF_GETTER(_username, YES)
	OF_GETTER(_username, true)
}

- (void)setRealname: (OFString*)realname
{
	OF_SETTER(_realname, realname, YES, YES)
	OF_SETTER(_realname, realname, true, 1)
}

- (OFString*)realname
{
	OF_GETTER(_realname, YES)
	OF_GETTER(_realname, true)
}

- (void)setDelegate: (id <IRCConnectionDelegate>)delegate
{
	_delegate = delegate;
}

- (id <IRCConnectionDelegate>)delegate
{
	OF_GETTER(_delegate, NO)
	OF_GETTER(_delegate, false)
}

- (OFTCPSocket*)socket
{
	OF_GETTER(_socket, YES)
	OF_GETTER(_socket, true)
}

- (void)connect
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

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

	_socket = [[OFTCPSocket alloc] init];
	[_socket connectToHost: _server
			  port: _port];

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

564
565
566
567
568
569
570
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
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







-
+











-
+


-
+





-
+


-
+





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







	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	[self IRC_processLine: line];

	[pool release];
}

-	    (BOOL)socket: (OFTCPSocket*)socket
-	    (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:)];
	}

	return NO;
	return false;
}

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

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

	return NO;
	}

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

	return false;
}

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

Modified src/IRCUser.h from [f35fb4156a] to [b31edf76a9].

27
28
29
30
31
32
33
34

35
36
37
38
39
27
28
29
30
31
32
33

34
35
36
37
38
39







-
+





	OFString *_nickname, *_username, *_hostname;
}

#ifdef OF_HAVE_PROPERTIES
@property (copy, readonly) OFString *nickname, *username, *hostname;
#endif

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

Modified src/IRCUser.m from [ee7005bbec] to [1fa74637a1].

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
65
66
67
68
69
70
71
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
65
66
67
68
69







-
+















-
-
+
+


-
+
-





-
+
-







#import <ObjFW/OFOutOfMemoryException.h>

#import <ObjFW/macros.h>

#import "IRCUser.h"

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

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

	self = [super init];

	@try {
		char *tmp;

		if ((tmp2 = strdup([string UTF8String])) == NULL)
			@throw [OFOutOfMemoryException
			     exceptionWithClass: [self class]
				  requestedSize: [string UTF8StringLength]];
			     exceptionWithRequestedSize:
			     [string UTF8StringLength]];

		if ((tmp = strchr(tmp2, '@')) == NULL)
			@throw [OFInvalidFormatException
			@throw [OFInvalidFormatException exception];
			    exceptionWithClass: [self class]];

		*tmp = '\0';
		_hostname = [[OFString alloc] initWithUTF8String: tmp + 1];

		if ((tmp = strchr(tmp2, '!')) == NULL)
			@throw [OFInvalidFormatException
			@throw [OFInvalidFormatException exception];
			    exceptionWithClass: [self class]];

		*tmp = '\0';
		_username = [[OFString alloc] initWithUTF8String: tmp + 1];

		_nickname = [[OFString alloc] initWithUTF8String: tmp2];
	} @catch (id e) {
		[self release];
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
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







-
+




-
+




-
+













	[_hostname release];

	[super dealloc];
}

- (OFString*)username
{
	OF_GETTER(_username, YES)
	OF_GETTER(_username, true)
}

- (OFString*)nickname
{
	OF_GETTER(_nickname, YES)
	OF_GETTER(_nickname, true)
}

- (OFString*)hostname
{
	OF_GETTER(_hostname, YES)
	OF_GETTER(_hostname, true)
}

- copy
{
	return [self retain];
}

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