Adjust to ObjFW changes

FossilOrigin-Name: e7f0831117b1cb0f56658ca9130df2f12dff6c49dfaf261d3b842c1f2b0265ca
This commit is contained in:
Jonathan Schleifer 2016-05-07 11:21:37 +00:00
parent 9e71cf9de7
commit 533177729a
5 changed files with 44 additions and 133 deletions

View file

@ -26,9 +26,7 @@
@class IRCUser; @class IRCUser;
@protocol IRCConnectionDelegate <OFObject> @protocol IRCConnectionDelegate <OFObject>
#ifdef OF_HAVE_OPTIONAL_PROTOCOLS
@optional @optional
#endif
- (void)connection: (IRCConnection*)connection - (void)connection: (IRCConnection*)connection
didReceiveLine: (OFString*)line; didReceiveLine: (OFString*)line;
- (void)connection: (IRCConnection*)connection - (void)connection: (IRCConnection*)connection
@ -81,28 +79,13 @@
id <IRCConnectionDelegate> _delegate; id <IRCConnectionDelegate> _delegate;
} }
#ifdef OF_HAVE_PROPERTIES
@property (copy) OFString *server; @property (copy) OFString *server;
@property (assign) uint16_t port; @property (assign) uint16_t port;
@property (copy) OFString *nickname, *username, *realname; @property (copy) OFString *nickname, *username, *realname;
@property (assign) id <IRCConnectionDelegate> delegate; @property (assign) id <IRCConnectionDelegate> delegate;
@property (readonly, retain) OFTCPSocket *socket; @property (readonly, retain) OFTCPSocket *socket;
#endif
+ (instancetype)connection; + (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;
- (OFString*)username;
- (void)setRealname: (OFString*)realname;
- (OFString*)realname;
- (void)setDelegate: (id <IRCConnectionDelegate>)delegate;
- (id <IRCConnectionDelegate>)delegate;
- (OFTCPSocket*)socket;
- (void)sendLine: (OFString*)line; - (void)sendLine: (OFString*)line;
- (void)sendLineWithFormat: (OFConstantString*)line, ...; - (void)sendLineWithFormat: (OFConstantString*)line, ...;
- (void)connect; - (void)connect;
@ -124,6 +107,3 @@
- (void)handleConnection; - (void)handleConnection;
- (OFSet*)usersInChannel: (OFString*)channel; - (OFSet*)usersInChannel: (OFString*)channel;
@end @end
@interface OFObject (IRCConnectionDelegate) <IRCConnectionDelegate>
@end

View file

@ -28,7 +28,6 @@
#import <ObjFW/OFArray.h> #import <ObjFW/OFArray.h>
#import <ObjFW/OFMutableDictionary.h> #import <ObjFW/OFMutableDictionary.h>
#import <ObjFW/OFTCPSocket.h> #import <ObjFW/OFTCPSocket.h>
#import <ObjFW/OFAutoreleasePool.h>
#import <ObjFW/OFInvalidEncodingException.h> #import <ObjFW/OFInvalidEncodingException.h>
@ -38,6 +37,10 @@
#import "IRCUser.h" #import "IRCUser.h"
@implementation IRCConnection @implementation IRCConnection
@synthesize server = _server, port = _port;
@synthesize nickname = _nickname, username = _username, realname = _realname;
@synthesize delegate = _delegate, socket = _socket;
+ (instancetype)connection + (instancetype)connection
{ {
return [[[self alloc] init] autorelease]; return [[[self alloc] init] autorelease];
@ -70,74 +73,9 @@
[super dealloc]; [super dealloc];
} }
- (void)setServer: (OFString*)server
{
OF_SETTER(_server, server, true, 1)
}
- (OFString*)server
{
OF_GETTER(_server, true)
}
- (void)setPort: (uint16_t)port
{
_port = port;
}
- (uint16_t)port
{
return _port;
}
- (void)setNickname: (OFString*)nickname
{
OF_SETTER(_nickname, nickname, true, 1)
}
- (OFString*)nickname
{
OF_GETTER(_nickname, true)
}
- (void)setUsername: (OFString*)username
{
OF_SETTER(_username, username, true, 1)
}
- (OFString*)username
{
OF_GETTER(_username, true)
}
- (void)setRealname: (OFString*)realname
{
OF_SETTER(_realname, realname, true, 1)
}
- (OFString*)realname
{
OF_GETTER(_realname, true)
}
- (void)setDelegate: (id <IRCConnectionDelegate>)delegate
{
_delegate = delegate;
}
- (id <IRCConnectionDelegate>)delegate
{
OF_GETTER(_delegate, false)
}
- (OFTCPSocket*)socket
{
OF_GETTER(_socket, true)
}
- (void)connect - (void)connect
{ {
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; void *pool = objc_autoreleasePoolPush();
if (_socket != nil) if (_socket != nil)
@throw [OFAlreadyConnectedException exception]; @throw [OFAlreadyConnectedException exception];
@ -149,7 +87,7 @@
[self sendLineWithFormat: @"NICK %@", _nickname]; [self sendLineWithFormat: @"NICK %@", _nickname];
[self sendLineWithFormat: @"USER %@ * 0 :%@", _username, _realname]; [self sendLineWithFormat: @"USER %@ * 0 :%@", _username, _realname];
[pool release]; objc_autoreleasePoolPop(pool);
} }
- (void)disconnect - (void)disconnect
@ -159,19 +97,27 @@
- (void)disconnectWithReason: (OFString*)reason - (void)disconnectWithReason: (OFString*)reason
{ {
void *pool = objc_autoreleasePoolPush();
reason = [[reason componentsSeparatedByString: @"\n"] firstObject]; reason = [[reason componentsSeparatedByString: @"\n"] firstObject];
if (reason == nil) if (reason == nil)
[self sendLine: @"QUIT"]; [self sendLine: @"QUIT"];
else else
[self sendLineWithFormat: @"QUIT :%@", reason]; [self sendLineWithFormat: @"QUIT :%@", reason];
objc_autoreleasePoolPop(pool);
} }
- (void)joinChannel: (OFString*)channel - (void)joinChannel: (OFString*)channel
{ {
void *pool = objc_autoreleasePoolPush();
channel = [[channel componentsSeparatedByString: @"\n"] firstObject]; channel = [[channel componentsSeparatedByString: @"\n"] firstObject];
[self sendLineWithFormat: @"JOIN %@", channel]; [self sendLineWithFormat: @"JOIN %@", channel];
objc_autoreleasePoolPop(pool);
} }
- (void)leaveChannel: (OFString*)channel - (void)leaveChannel: (OFString*)channel
@ -183,6 +129,8 @@
- (void)leaveChannel: (OFString*)channel - (void)leaveChannel: (OFString*)channel
reason: (OFString*)reason reason: (OFString*)reason
{ {
void *pool = objc_autoreleasePoolPush();
channel = [[channel componentsSeparatedByString: @"\n"] firstObject]; channel = [[channel componentsSeparatedByString: @"\n"] firstObject];
reason = [[reason componentsSeparatedByString: @"\n"] firstObject]; reason = [[reason componentsSeparatedByString: @"\n"] firstObject];
@ -192,6 +140,8 @@
[self sendLineWithFormat: @"PART %@ :%@", channel, reason]; [self sendLineWithFormat: @"PART %@ :%@", channel, reason];
[_channels removeObjectForKey: channel]; [_channels removeObjectForKey: channel];
objc_autoreleasePoolPop(pool);
} }
- (void)sendLine: (OFString*)line - (void)sendLine: (OFString*)line
@ -205,7 +155,7 @@
- (void)sendLineWithFormat: (OFConstantString*)format, ... - (void)sendLineWithFormat: (OFConstantString*)format, ...
{ {
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; void *pool = objc_autoreleasePoolPush();
OFString *line; OFString *line;
va_list args; va_list args;
@ -216,46 +166,54 @@
[self sendLine: line]; [self sendLine: line];
[pool release]; objc_autoreleasePoolPop(pool);
} }
- (void)sendMessage: (OFString*)msg - (void)sendMessage: (OFString*)msg
to: (OFString*)to to: (OFString*)to
{ {
OFArray *lines = [msg componentsSeparatedByString: @"\n"]; void *pool = objc_autoreleasePoolPush();
OFEnumerator *enumerator = [lines objectEnumerator];
OFString *line;
while ((line = [enumerator nextObject]) != nil) for (OFString *line in [msg componentsSeparatedByString: @"\n"])
[self sendLineWithFormat: @"PRIVMSG %@ :%@", to, line]; [self sendLineWithFormat: @"PRIVMSG %@ :%@", to, line];
objc_autoreleasePoolPop(pool);
} }
- (void)sendNotice: (OFString*)notice - (void)sendNotice: (OFString*)notice
to: (OFString*)to to: (OFString*)to
{ {
OFArray *lines = [notice componentsSeparatedByString: @"\n"]; void *pool = objc_autoreleasePoolPush();
OFEnumerator *enumerator = [lines objectEnumerator];
OFString *line;
while ((line = [enumerator nextObject]) != nil) for (OFString *line in [notice componentsSeparatedByString: @"\n"])
[self sendLineWithFormat: @"NOTICE %@ :%@", to, line]; [self sendLineWithFormat: @"NOTICE %@ :%@", to, line];
objc_autoreleasePoolPop(pool);
} }
- (void)kickUser: (OFString*)user - (void)kickUser: (OFString*)user
channel: (OFString*)channel channel: (OFString*)channel
reason: (OFString*)reason reason: (OFString*)reason
{ {
void *pool = objc_autoreleasePoolPush();
reason = [[reason componentsSeparatedByString: @"\n"] firstObject]; reason = [[reason componentsSeparatedByString: @"\n"] firstObject];
[self sendLineWithFormat: @"KICK %@ %@ :%@", channel, user, reason]; [self sendLineWithFormat: @"KICK %@ %@ :%@", channel, user, reason];
objc_autoreleasePoolPop(pool);
} }
- (void)changeNicknameTo: (OFString*)nickname - (void)changeNicknameTo: (OFString*)nickname
{ {
void *pool = objc_autoreleasePoolPush();
nickname = [[nickname componentsSeparatedByString: @"\n"] nickname = [[nickname componentsSeparatedByString: @"\n"]
firstObject]; firstObject];
[self sendLineWithFormat: @"NICK %@", nickname]; [self sendLineWithFormat: @"NICK %@", nickname];
objc_autoreleasePoolPop(pool);
} }
- (void)IRC_processLine: (OFString*)line - (void)IRC_processLine: (OFString*)line
@ -327,8 +285,6 @@
OFMutableSet *channel; OFMutableSet *channel;
OFArray *users; OFArray *users;
size_t pos; size_t pos;
OFEnumerator *enumerator;
OFString *user;
where = [components objectAtIndex: 4]; where = [components objectAtIndex: 4];
@ -347,8 +303,7 @@
of_range(pos, [line length] - pos)] of_range(pos, [line length] - pos)]
componentsSeparatedByString: @" "]; componentsSeparatedByString: @" "];
enumerator = [users objectEnumerator]; for (OFString *user in users) {
while ((user = [enumerator nextObject]) != nil) {
if ([user hasPrefix: @"@"] || [user hasPrefix: @"+"] || if ([user hasPrefix: @"@"] || [user hasPrefix: @"+"] ||
[user hasPrefix: @"%"] || [user hasPrefix: @"*"]) [user hasPrefix: @"%"] || [user hasPrefix: @"*"])
user = [user substringWithRange: user = [user substringWithRange:
@ -435,8 +390,6 @@
OFString *reason = nil; OFString *reason = nil;
size_t pos = [who length] + 1 + size_t pos = [who length] + 1 +
[[components objectAtIndex: 1] length]; [[components objectAtIndex: 1] length];
OFEnumerator *enumerator;
OFMutableSet *channel;
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];
@ -445,8 +398,7 @@
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]; for (OFMutableSet *channel in _channels)
while ((channel = [enumerator nextObject]) != nil)
[channel removeObject: [user nickname]]; [channel removeObject: [user nickname]];
if ([_delegate respondsToSelector: if ([_delegate respondsToSelector:
@ -463,8 +415,6 @@
OFString *who = [components objectAtIndex: 0]; OFString *who = [components objectAtIndex: 0];
OFString *nickname = [components objectAtIndex: 2]; OFString *nickname = [components objectAtIndex: 2];
IRCUser *user; IRCUser *user;
OFEnumerator *enumerator;
OFMutableSet *channel;
who = [who substringWithRange: of_range(1, [who length] - 1)]; who = [who substringWithRange: of_range(1, [who length] - 1)];
nickname = [nickname substringWithRange: nickname = [nickname substringWithRange:
@ -477,8 +427,7 @@
_nickname = [nickname copy]; _nickname = [nickname copy];
} }
enumerator = [_channels objectEnumerator]; for (OFMutableSet *channel in _channels) {
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: nickname]; [channel addObject: nickname];
@ -569,11 +518,11 @@
- (void)processLine: (OFString*)line - (void)processLine: (OFString*)line
{ {
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; void *pool = objc_autoreleasePoolPush();
[self IRC_processLine: line]; [self IRC_processLine: line];
[pool release]; objc_autoreleasePoolPop(pool);
} }
- (bool)socket: (OFTCPSocket*)socket - (bool)socket: (OFTCPSocket*)socket

View file

@ -27,13 +27,8 @@
OFString *_nickname, *_username, *_hostname; OFString *_nickname, *_username, *_hostname;
} }
#ifdef OF_HAVE_PROPERTIES
@property (copy, readonly) OFString *nickname, *username, *hostname; @property (copy, readonly) OFString *nickname, *username, *hostname;
#endif
+ (instancetype)IRCUserWithString: (OFString*)string; + (instancetype)IRCUserWithString: (OFString*)string;
- initWithString: (OFString*)string; - initWithString: (OFString*)string;
- (OFString*)nickname;
- (OFString*)username;
- (OFString*)hostname;
@end @end

View file

@ -33,6 +33,8 @@
#import "IRCUser.h" #import "IRCUser.h"
@implementation IRCUser @implementation IRCUser
@synthesize username = _username, nickname = _nickname, hostname = _hostname;
+ (instancetype)IRCUserWithString: (OFString*)string + (instancetype)IRCUserWithString: (OFString*)string
{ {
return [[[self alloc] initWithString: string] autorelease]; return [[[self alloc] initWithString: string] autorelease];
@ -85,21 +87,6 @@
[super dealloc]; [super dealloc];
} }
- (OFString*)username
{
OF_GETTER(_username, true)
}
- (OFString*)nickname
{
OF_GETTER(_nickname, true)
}
- (OFString*)hostname
{
OF_GETTER(_hostname, true)
}
- copy - copy
{ {
return [self retain]; return [self retain];

View file

@ -27,7 +27,7 @@
#import "IRCConnection.h" #import "IRCConnection.h"
#import "IRCUser.h" #import "IRCUser.h"
@interface TestApp: OFObject @interface TestApp: OFObject <OFApplicationDelegate, IRCConnectionDelegate>
@end @end
OF_APPLICATION_DELEGATE(TestApp) OF_APPLICATION_DELEGATE(TestApp)