Prefix all ivars with an underscore.

FossilOrigin-Name: 8845b8b00bf7ce1cd68b70864335380038bc0a254060ff49d49429aabf69e34a
This commit is contained in:
Jonathan Schleifer 2013-02-14 00:20:48 +00:00
parent fcc1c03101
commit 97b6edeb00
4 changed files with 134 additions and 135 deletions

View file

@ -77,12 +77,12 @@
@interface IRCConnection: OFObject @interface IRCConnection: OFObject
{ {
OFTCPSocket *sock; OFTCPSocket *_socket;
OFString *server; OFString *_server;
uint16_t port; uint16_t _port;
OFString *nickname, *username, *realname; OFString *_nickname, *_username, *_realname;
OFMutableDictionary *channels; OFMutableDictionary *_channels;
id <IRCConnectionDelegate> delegate; id <IRCConnectionDelegate> _delegate;
} }
#ifdef OF_HAVE_PROPERTIES #ifdef OF_HAVE_PROPERTIES

View file

@ -43,8 +43,8 @@
self = [super init]; self = [super init];
@try { @try {
channels = [[OFMutableDictionary alloc] init]; _channels = [[OFMutableDictionary alloc] init];
port = 6667; _port = 6667;
} @catch (id e) { } @catch (id e) {
[self release]; [self release];
@throw e; @throw e;
@ -53,81 +53,93 @@
return self; return self;
} }
- (void)setServer: (OFString*)server_ - (void)dealloc
{ {
OF_SETTER(server, server_, YES, YES) [_socket release];
[_server release];
[_nickname release];
[_username release];
[_realname release];
[_channels release];
[super dealloc];
}
- (void)setServer: (OFString*)server
{
OF_SETTER(_server, server, YES, YES)
} }
- (OFString*)server - (OFString*)server
{ {
OF_GETTER(server, YES) OF_GETTER(_server, YES)
} }
- (void)setPort: (uint16_t)port_ - (void)setPort: (uint16_t)port
{ {
port = port_; _port = port;
} }
- (uint16_t)port - (uint16_t)port
{ {
return port; return _port;
} }
- (void)setNickname: (OFString*)nickname_ - (void)setNickname: (OFString*)nickname
{ {
OF_SETTER(nickname, nickname_, YES, YES) OF_SETTER(_nickname, nickname, YES, YES)
} }
- (OFString*)nickname - (OFString*)nickname
{ {
OF_GETTER(nickname, YES) OF_GETTER(_nickname, YES)
} }
- (void)setUsername: (OFString*)username_ - (void)setUsername: (OFString*)username
{ {
OF_SETTER(username, username_, YES, YES) OF_SETTER(_username, username, YES, YES)
} }
- (OFString*)username - (OFString*)username
{ {
OF_GETTER(username, YES) OF_GETTER(_username, YES)
} }
- (void)setRealname: (OFString*)realname_ - (void)setRealname: (OFString*)realname
{ {
OF_SETTER(realname, realname_, YES, YES) OF_SETTER(_realname, realname, YES, YES)
} }
- (OFString*)realname - (OFString*)realname
{ {
OF_GETTER(realname, YES) OF_GETTER(_realname, YES)
} }
- (void)setDelegate: (id <IRCConnectionDelegate>)delegate_ - (void)setDelegate: (id <IRCConnectionDelegate>)delegate
{ {
delegate = delegate_; _delegate = delegate;
} }
- (id <IRCConnectionDelegate>)delegate - (id <IRCConnectionDelegate>)delegate
{ {
return delegate; OF_GETTER(_delegate, NO)
} }
- (OFTCPSocket*)socket - (OFTCPSocket*)socket
{ {
OF_GETTER(sock, YES) OF_GETTER(_socket, YES)
} }
- (void)connect - (void)connect
{ {
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
sock = [[OFTCPSocket alloc] init]; _socket = [[OFTCPSocket alloc] init];
[sock connectToHost: server [_socket connectToHost: _server
port: port]; port: _port];
[self sendLineWithFormat: @"NICK %@", nickname]; [self sendLineWithFormat: @"NICK %@", _nickname];
[self sendLineWithFormat: @"USER %@ * 0 :%@", username, realname]; [self sendLineWithFormat: @"USER %@ * 0 :%@", _username, _realname];
[pool release]; [pool release];
} }
@ -171,15 +183,15 @@
else else
[self sendLineWithFormat: @"PART %@ :%@", channel, reason]; [self sendLineWithFormat: @"PART %@ :%@", channel, reason];
[channels removeObjectForKey: channel]; [_channels removeObjectForKey: channel];
} }
- (void)sendLine: (OFString*)line - (void)sendLine: (OFString*)line
{ {
[delegate connection: self [_delegate connection: self
didSendLine: line]; didSendLine: line];
[sock writeLine: line]; [_socket writeLine: line];
} }
- (void)sendLineWithFormat: (OFConstantString*)format, ... - (void)sendLineWithFormat: (OFConstantString*)format, ...
@ -229,12 +241,12 @@
[self sendLineWithFormat: @"KICK %@ %@ :%@", channel, user, reason]; [self sendLineWithFormat: @"KICK %@ %@ :%@", channel, user, reason];
} }
- (void)changeNicknameTo: (OFString*)nickname_ - (void)changeNicknameTo: (OFString*)nickname
{ {
nickname_ = [[nickname_ componentsSeparatedByString: @"\n"] nickname = [[nickname componentsSeparatedByString: @"\n"]
firstObject]; firstObject];
[self sendLineWithFormat: @"NICK %@", nickname_]; [self sendLineWithFormat: @"NICK %@", nickname];
} }
- (void)IRC_processLine: (OFString*)line - (void)IRC_processLine: (OFString*)line
@ -242,7 +254,7 @@
OFArray *components; OFArray *components;
OFString *action = nil; OFString *action = nil;
[delegate connection: self [_delegate connection: self
didReceiveLine: line]; didReceiveLine: line];
components = [line componentsSeparatedByString: @" "]; components = [line componentsSeparatedByString: @" "];
@ -262,7 +274,7 @@
/* Connected */ /* Connected */
if ([action isEqual: @"001"] && [components count] >= 4) { if ([action isEqual: @"001"] && [components count] >= 4) {
[delegate connectionWasEstablished: self]; [_delegate connectionWasEstablished: self];
return; return;
} }
@ -276,16 +288,17 @@
who = [who substringWithRange: of_range(1, [who length] - 1)]; who = [who substringWithRange: of_range(1, [who length] - 1)];
user = [IRCUser IRCUserWithString: who]; user = [IRCUser IRCUserWithString: who];
if ([who hasPrefix: [nickname stringByAppendingString: @"!"]]) { if ([who hasPrefix:
[_nickname stringByAppendingString: @"!"]]) {
channel = [OFMutableSet set]; channel = [OFMutableSet set];
[channels setObject: channel [_channels setObject: channel
forKey: where]; forKey: where];
} else } else
channel = [channels objectForKey: where]; channel = [_channels objectForKey: where];
[channel addObject: [user nickname]]; [channel addObject: [user nickname]];
[delegate connection: self [_delegate connection: self
didSeeUser: user didSeeUser: user
joinChannel: where]; joinChannel: where];
@ -303,7 +316,7 @@
where = [components objectAtIndex: 4]; where = [components objectAtIndex: 4];
if ((channel = [channels objectForKey: where]) == nil) { if ((channel = [_channels objectForKey: where]) == nil) {
/* We did not request that */ /* We did not request that */
return; return;
} }
@ -328,7 +341,7 @@
[channel addObject: user]; [channel addObject: user];
} }
[delegate connection: self [_delegate connection: self
didReceiveNamesForChannel: where]; didReceiveNamesForChannel: where];
return; return;
@ -346,7 +359,7 @@
who = [who substringWithRange: of_range(1, [who length] - 1)]; who = [who substringWithRange: of_range(1, [who length] - 1)];
user = [IRCUser IRCUserWithString: who]; user = [IRCUser IRCUserWithString: who];
channel = [channels objectForKey: where]; channel = [_channels objectForKey: where];
if ([components count] > 3) if ([components count] > 3)
reason = [line substringWithRange: reason = [line substringWithRange:
@ -354,7 +367,7 @@
[channel removeObject: [user nickname]]; [channel removeObject: [user nickname]];
[delegate connection: self [_delegate connection: self
didSeeUser: user didSeeUser: user
leaveChannel: where leaveChannel: where
reason: reason]; reason: reason];
@ -376,7 +389,7 @@
who = [who substringWithRange: of_range(1, [who length] - 1)]; who = [who substringWithRange: of_range(1, [who length] - 1)];
user = [IRCUser IRCUserWithString: who]; user = [IRCUser IRCUserWithString: who];
channel = [channels objectForKey: where]; channel = [_channels objectForKey: where];
if ([components count] > 4) if ([components count] > 4)
reason = [line substringWithRange: reason = [line substringWithRange:
@ -384,7 +397,7 @@
[channel removeObject: [user nickname]]; [channel removeObject: [user nickname]];
[delegate connection: self [_delegate connection: self
didSeeUser: user didSeeUser: user
kickUser: whom kickUser: whom
channel: where channel: where
@ -410,11 +423,11 @@
reason = [line substringWithRange: reason = [line substringWithRange:
of_range(pos + 2, [line length] - pos - 2)]; of_range(pos + 2, [line length] - pos - 2)];
enumerator = [channels objectEnumerator]; enumerator = [_channels objectEnumerator];
while ((channel = [enumerator nextObject]) != nil) while ((channel = [enumerator nextObject]) != nil)
[channel removeObject: [user nickname]]; [channel removeObject: [user nickname]];
[delegate connection: self [_delegate connection: self
didSeeUserQuit: user didSeeUserQuit: user
reason: reason]; reason: reason];
@ -424,33 +437,33 @@
/* NICK */ /* NICK */
if ([action isEqual: @"NICK"] && [components count] == 3) { if ([action isEqual: @"NICK"] && [components count] == 3) {
OFString *who = [components objectAtIndex: 0]; OFString *who = [components objectAtIndex: 0];
OFString *newNickname = [components objectAtIndex: 2]; OFString *nickname = [components objectAtIndex: 2];
IRCUser *user; IRCUser *user;
OFEnumerator *enumerator; OFEnumerator *enumerator;
OFMutableSet *channel; OFMutableSet *channel;
who = [who substringWithRange: of_range(1, [who length] - 1)]; who = [who substringWithRange: of_range(1, [who length] - 1)];
newNickname = [newNickname substringWithRange: nickname = [nickname substringWithRange:
of_range(1, [newNickname length] - 1)]; of_range(1, [nickname length] - 1)];
user = [IRCUser IRCUserWithString: who]; user = [IRCUser IRCUserWithString: who];
if ([[user nickname] isEqual: nickname]) { if ([[user nickname] isEqual: _nickname]) {
[nickname release]; [_nickname release];
nickname = [[user nickname] copy]; _nickname = [nickname copy];
} }
enumerator = [channels keyEnumerator]; enumerator = [_channels keyEnumerator];
while ((channel = [enumerator nextObject]) != nil) { while ((channel = [enumerator nextObject]) != nil) {
if ([channel containsObject: [user nickname]]) { if ([channel containsObject: [user nickname]]) {
[channel removeObject: [user nickname]]; [channel removeObject: [user nickname]];
[channel addObject: newNickname]; [channel addObject: nickname];
} }
} }
[delegate connection: self [_delegate connection: self
didSeeUser: user didSeeUser: user
changeNicknameTo: newNickname]; changeNicknameTo: nickname];
return; return;
} }
@ -470,13 +483,13 @@
of_range(pos + 2, [line length] - pos - 2)]; of_range(pos + 2, [line length] - pos - 2)];
user = [IRCUser IRCUserWithString: from]; user = [IRCUser IRCUserWithString: from];
if (![to isEqual: nickname]) if (![to isEqual: _nickname])
[delegate connection: self [_delegate connection: self
didReceiveMessage: msg didReceiveMessage: msg
channel: to channel: to
user: user]; user: user];
else else
[delegate connection: self [_delegate connection: self
didReceivePrivateMessage: msg didReceivePrivateMessage: msg
user: user]; user: user];
@ -504,13 +517,13 @@
user = [IRCUser IRCUserWithString: from]; user = [IRCUser IRCUserWithString: from];
if (![to isEqual: nickname]) if (![to isEqual: _nickname])
[delegate connection: self [_delegate connection: self
didReceiveNotice: notice didReceiveNotice: notice
channel: to channel: to
user: user]; user: user];
else else
[delegate connection: self [_delegate connection: self
didReceiveNotice: notice didReceiveNotice: notice
user: user]; user: user];
@ -527,13 +540,13 @@
[pool release]; [pool release];
} }
- (BOOL)connection: (OFTCPSocket*)connection - (BOOL)socket: (OFTCPSocket*)socket
didReceiveISO88591Line: (OFString*)line didReceiveISO88591Line: (OFString*)line
exception: (OFException*)exception exception: (OFException*)exception
{ {
if (line != nil) { if (line != nil) {
[self IRC_processLine: line]; [self IRC_processLine: line];
[sock asyncReadLineWithTarget: self [socket asyncReadLineWithTarget: self
selector: @selector(connection: selector: @selector(connection:
didReceiveLine: didReceiveLine:
exception:)]; exception:)];
@ -542,7 +555,7 @@
return NO; return NO;
} }
- (BOOL)connection: (OFTCPSocket*)connection - (BOOL)socket: (OFTCPSocket*)socket
didReceiveLine: (OFString*)line didReceiveLine: (OFString*)line
exception: (OFException*)exception exception: (OFException*)exception
{ {
@ -552,9 +565,9 @@
} }
if ([exception isKindOfClass: [OFInvalidEncodingException class]]) if ([exception isKindOfClass: [OFInvalidEncodingException class]])
[sock asyncReadLineWithEncoding: OF_STRING_ENCODING_ISO_8859_1 [socket asyncReadLineWithEncoding: OF_STRING_ENCODING_ISO_8859_1
target: self target: self
selector: @selector(connection: selector: @selector(socket:
didReceiveISO88591Line: didReceiveISO88591Line:
exception:)]; exception:)];
@ -563,26 +576,14 @@
- (void)handleConnection - (void)handleConnection
{ {
[sock asyncReadLineWithTarget: self [_socket asyncReadLineWithTarget: self
selector: @selector(connection:didReceiveLine: selector: @selector(socket:didReceiveLine:
exception:)]; exception:)];
} }
- (OFSet*)usersInChannel: (OFString*)channel - (OFSet*)usersInChannel: (OFString*)channel
{ {
return [[[channels objectForKey: channel] copy] autorelease]; return [[[_channels objectForKey: channel] copy] autorelease];
}
- (void)dealloc
{
[sock release];
[server release];
[nickname release];
[username release];
[realname release];
[channels release];
[super dealloc];
} }
@end @end

View file

@ -24,9 +24,7 @@
@interface IRCUser: OFObject <OFCopying> @interface IRCUser: OFObject <OFCopying>
{ {
OFString *nickname; OFString *_nickname, *_username, *_hostname;
OFString *username;
OFString *hostname;
} }
#ifdef OF_HAVE_PROPERTIES #ifdef OF_HAVE_PROPERTIES

View file

@ -57,16 +57,16 @@
exceptionWithClass: [self class]]; exceptionWithClass: [self class]];
*tmp = '\0'; *tmp = '\0';
hostname = [[OFString alloc] initWithUTF8String: tmp + 1]; _hostname = [[OFString alloc] initWithUTF8String: tmp + 1];
if ((tmp = strchr(tmp2, '!')) == NULL) if ((tmp = strchr(tmp2, '!')) == NULL)
@throw [OFInvalidFormatException @throw [OFInvalidFormatException
exceptionWithClass: [self class]]; exceptionWithClass: [self class]];
*tmp = '\0'; *tmp = '\0';
username = [[OFString alloc] initWithUTF8String: tmp + 1]; _username = [[OFString alloc] initWithUTF8String: tmp + 1];
nickname = [[OFString alloc] initWithUTF8String: tmp2]; _nickname = [[OFString alloc] initWithUTF8String: tmp2];
} @catch (id e) { } @catch (id e) {
[self release]; [self release];
@throw e; @throw e;
@ -80,26 +80,26 @@
- (void)dealloc - (void)dealloc
{ {
[nickname release]; [_nickname release];
[username release]; [_username release];
[hostname release]; [_hostname release];
[super dealloc]; [super dealloc];
} }
- (OFString*)username - (OFString*)username
{ {
OF_GETTER(username, YES) OF_GETTER(_username, YES)
} }
- (OFString*)nickname - (OFString*)nickname
{ {
OF_GETTER(nickname, YES) OF_GETTER(_nickname, YES)
} }
- (OFString*)hostname - (OFString*)hostname
{ {
OF_GETTER(hostname, YES) OF_GETTER(_hostname, YES)
} }
- copy - copy
@ -110,6 +110,6 @@
- (OFString*)description - (OFString*)description
{ {
return [OFString stringWithFormat: @"%@!%@@%@", return [OFString stringWithFormat: @"%@!%@@%@",
nickname, username, hostname]; _nickname, _username, _hostname];
} }
@end @end