Adjust to ObjFW API and fix a disconnect bug.

FossilOrigin-Name: 18137016905f0581bc493e61961522356acab11c15d53f561447045acc6e202c
This commit is contained in:
Jonathan Schleifer 2013-07-12 14:12:16 +00:00
parent 52fcf8b32d
commit 9e71cf9de7
4 changed files with 42 additions and 27 deletions

View file

@ -89,6 +89,7 @@
@property (readonly, retain) OFTCPSocket *socket;
#endif
+ (instancetype)connection;
- (void)setServer: (OFString*)server;
- (OFString*)server;
- (void)setPort: (uint16_t)port;

View file

@ -38,6 +38,11 @@
#import "IRCUser.h"
@implementation IRCConnection
+ (instancetype)connection
{
return [[[self alloc] init] autorelease];
}
- init
{
self = [super init];
@ -67,12 +72,12 @@
- (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
@ -87,32 +92,32 @@
- (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
@ -122,18 +127,21 @@
- (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];
@ -568,7 +576,7 @@
[pool release];
}
- (BOOL)socket: (OFTCPSocket*)socket
- (bool)socket: (OFTCPSocket*)socket
didReceiveISO88591Line: (OFString*)line
exception: (OFException*)exception
{
@ -580,26 +588,34 @@
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

View file

@ -31,7 +31,7 @@
@property (copy, readonly) OFString *nickname, *username, *hostname;
#endif
+ IRCUserWithString: (OFString*)string;
+ (instancetype)IRCUserWithString: (OFString*)string;
- initWithString: (OFString*)string;
- (OFString*)nickname;
- (OFString*)username;

View file

@ -33,7 +33,7 @@
#import "IRCUser.h"
@implementation IRCUser
+ IRCUserWithString: (OFString*)string
+ (instancetype)IRCUserWithString: (OFString*)string
{
return [[[self alloc] initWithString: string] autorelease];
}
@ -49,19 +49,17 @@
if ((tmp2 = strdup([string UTF8String])) == NULL)
@throw [OFOutOfMemoryException
exceptionWithClass: [self class]
requestedSize: [string UTF8StringLength]];
exceptionWithRequestedSize:
[string UTF8StringLength]];
if ((tmp = strchr(tmp2, '@')) == NULL)
@throw [OFInvalidFormatException
exceptionWithClass: [self class]];
@throw [OFInvalidFormatException exception];
*tmp = '\0';
_hostname = [[OFString alloc] initWithUTF8String: tmp + 1];
if ((tmp = strchr(tmp2, '!')) == NULL)
@throw [OFInvalidFormatException
exceptionWithClass: [self class]];
@throw [OFInvalidFormatException exception];
*tmp = '\0';
_username = [[OFString alloc] initWithUTF8String: tmp + 1];
@ -89,17 +87,17 @@
- (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