Index: src/IRCConnection.h ================================================================== --- src/IRCConnection.h +++ src/IRCConnection.h @@ -87,10 +87,11 @@ @property (copy) OFString *nickname, *username, *realname; @property (assign) id 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; Index: src/IRCConnection.m ================================================================== --- src/IRCConnection.m +++ src/IRCConnection.m @@ -36,10 +36,15 @@ #import "IRCConnection.h" #import "IRCUser.h" @implementation IRCConnection ++ (instancetype)connection +{ + return [[[self alloc] init] autorelease]; +} + - init { self = [super init]; @try { @@ -65,16 +70,16 @@ [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; @@ -85,57 +90,60 @@ 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 )delegate { _delegate = delegate; } - (id )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]; @@ -566,11 +574,11 @@ [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]; @@ -578,30 +586,38 @@ 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; + } + + if ([_delegate respondsToSelector: @selector(connectionWasClosed:)]) { + [_delegate connectionWasClosed: self]; + [_socket release]; + _socket = nil; + } - return NO; + return false; } - (void)handleConnection { [_socket asyncReadLineWithTarget: self Index: src/IRCUser.h ================================================================== --- src/IRCUser.h +++ src/IRCUser.h @@ -29,11 +29,11 @@ #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 Index: src/IRCUser.m ================================================================== --- src/IRCUser.m +++ src/IRCUser.m @@ -31,11 +31,11 @@ #import #import "IRCUser.h" @implementation IRCUser -+ IRCUserWithString: (OFString*)string ++ (instancetype)IRCUserWithString: (OFString*)string { return [[[self alloc] initWithString: string] autorelease]; } - initWithString: (OFString*)string @@ -47,23 +47,21 @@ @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 - 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]; _nickname = [[OFString alloc] initWithUTF8String: tmp2]; @@ -87,21 +85,21 @@ [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];