Index: src/IRCConnection.h ================================================================== --- src/IRCConnection.h +++ src/IRCConnection.h @@ -21,10 +21,12 @@ * POSSIBILITY OF SUCH DAMAGE. */ #import +OF_ASSUME_NONNULL_BEGIN + @class IRCConnection; @class IRCUser; @protocol IRCConnectionDelegate @optional @@ -39,22 +41,22 @@ didSeeUser: (IRCUser *)user joinChannel: (OFString *)channel; - (void)connection: (IRCConnection *)connection didSeeUser: (IRCUser *)user leaveChannel: (OFString *)channel - reason: (OFString *)reason; + reason: (nullable OFString *)reason; - (void)connection: (IRCConnection *)connection didSeeUser: (IRCUser *)user changeNicknameTo: (OFString *)nickname; - (void)connection: (IRCConnection *)connection didSeeUser: (IRCUser *)user kickUser: (OFString *)kickedUser channel: (OFString *)channel - reason: (OFString *)reason; + reason: (nullable OFString *)reason; - (void)connection: (IRCConnection *)connection didSeeUserQuit: (IRCUser *)user - reason: (OFString *)reason; + reason: (nullable OFString *)reason; - (void)connection: (IRCConnection *)connection didReceiveMessage: (OFString *)msg channel: (OFString *)channel user: (IRCUser *)user; - (void)connection: (IRCConnection *)connection @@ -73,48 +75,54 @@ @end @interface IRCConnection: OFObject { Class _socketClass; - OF_KINDOF(OFTCPSocket) *_socket; - OFString *_server; - uint16_t _port; - OFString *_nickname, *_username, *_realname; - OFMutableDictionary OF_GENERIC(OFString *, OFMutableSet *) *_channels; - id _delegate; - of_string_encoding_t _fallbackEncoding; - of_time_interval_t _pingInterval, _pingTimeout; - OFString *_pingData; - OFTimer *_pingTimer; -} - -@property (assign) Class socketClass; -@property (nonatomic, copy) OFString *server; -@property uint16_t port; -@property (nonatomic, copy) OFString *nickname, *username, *realname; -@property (assign) id delegate; -@property (readonly, nonatomic) OFTCPSocket *socket; -@property of_string_encoding_t fallbackEncoding; -@property of_time_interval_t pingInterval, pingTimeout; + OF_KINDOF(OFTCPSocket) *_Nullable _socket; + OFString *_Nullable _server; + uint16_t _port; + OFString *_Nullable _nickname, *_Nullable _username; + OFString *_Nullable _realname; + OFMutableDictionary OF_GENERIC(OFString *, OFMutableSet *) *_channels; + id _Nullable _delegate; + of_string_encoding_t _fallbackEncoding; + of_time_interval_t _pingInterval, _pingTimeout; + OFString *_Nullable _pingData; + OFTimer *_Nullable _pingTimer; +} + +@property (readonly, nonatomic) Class socketClass; +@property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *server; +@property (nonatomic) uint16_t port; +@property OF_NULLABLE_PROPERTY (copy, nonatomic) + OFString *nickname, *username, *realname; +@property OF_NULLABLE_PROPERTY (assign, nonatomic) + id delegate; +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) + OF_KINDOF(OFTCPSocket *) socket; +@property (nonatomic) of_string_encoding_t fallbackEncoding; +@property (nonatomic) of_time_interval_t pingInterval, pingTimeout; + (instancetype)connection; - (void)sendLine: (OFString *)line; - (void)sendLineWithFormat: (OFConstantString *)line, ...; - (void)connect; - (void)disconnect; -- (void)disconnectWithReason: (OFString *)reason; +- (void)disconnectWithReason: (nullable OFString *)reason; - (void)joinChannel: (OFString *)channelName; - (void)leaveChannel: (OFString *)channel; - (void)leaveChannel: (OFString *)channel - reason: (OFString *)reason; -- (void)sendMessage: (OFString *)msg + reason: (nullable OFString *)reason; +- (void)sendMessage: (OFString *)message to: (OFString *)to; - (void)sendNotice: (OFString *)notice to: (OFString *)to; - (void)kickUser: (OFString *)user channel: (OFString *)channel - reason: (OFString *)reason; + reason: (nullable OFString *)reason; - (void)changeNicknameTo: (OFString *)nickname; - (void)processLine: (OFString *)line; - (void)handleConnection; -- (OFSet OF_GENERIC(OFString *) *)usersInChannel: (OFString *)channel; +- (nullable OFSet OF_GENERIC(OFString *) *)usersInChannel: (OFString *)channel; @end + +OF_ASSUME_NONNULL_END Index: src/IRCConnection.m ================================================================== --- src/IRCConnection.m +++ src/IRCConnection.m @@ -182,16 +182,16 @@ [self sendLine: line]; objc_autoreleasePoolPop(pool); } -- (void)sendMessage: (OFString *)msg +- (void)sendMessage: (OFString *)message to: (OFString *)to { void *pool = objc_autoreleasePoolPush(); - for (OFString *line in [msg componentsSeparatedByString: @"\n"]) + for (OFString *line in [message componentsSeparatedByString: @"\n"]) [self sendLineWithFormat: @"PRIVMSG %@ :%@", to, line]; objc_autoreleasePoolPop(pool); } @@ -480,32 +480,32 @@ /* PRIVMSG */ if ([action isEqual: @"PRIVMSG"] && [components count] >= 4) { OFString *from = [components objectAtIndex: 0]; OFString *to = [components objectAtIndex: 2]; IRCUser *user; - OFString *msg; + OFString *message; size_t pos = [from length] + 1 + [[components objectAtIndex: 1] length] + 1 + [to length]; from = [from substringWithRange: of_range(1, [from length] - 1)]; - msg = [line substringWithRange: + message = [line substringWithRange: of_range(pos + 2, [line length] - pos - 2)]; user = [IRCUser IRCUserWithString: from]; if (![to isEqual: _nickname]) { if ([_delegate respondsToSelector: @selector(connection: didReceiveMessage:channel:user:)]) [_delegate connection: self - didReceiveMessage: msg + didReceiveMessage: message channel: to user: user]; } else { if ([_delegate respondsToSelector: @selector(connection: didReceivePrivateMessage:user:)]) [_delegate connection: self - didReceivePrivateMessage: msg + didReceivePrivateMessage: message user: user]; } return; } @@ -591,11 +591,12 @@ if (line != nil) { [self IRC_processLine: line]; [socket asyncReadLineWithTarget: self selector: @selector(socket: didReceiveLine: - exception:)]; + exception:) + context: nil]; } return false; } @@ -612,11 +613,12 @@ [socket asyncReadLineWithEncoding: _fallbackEncoding target: self selector: @selector(socket: didReceiveWronglyEncodedLine: - exception:)]; + exception:) + context: nil]; return false; } if ([_delegate respondsToSelector: @selector(connectionWasClosed:)]) [_delegate connectionWasClosed: self]; @@ -633,13 +635,14 @@ - (void)handleConnection { [_socket asyncReadLineWithTarget: self selector: @selector(socket:didReceiveLine: - exception:)]; + exception:) + context: nil]; } - (OFSet OF_GENERIC(OFString *) *)usersInChannel: (OFString *)channel { return [[[_channels objectForKey: channel] copy] autorelease]; } @end Index: src/IRCUser.h ================================================================== --- src/IRCUser.h +++ src/IRCUser.h @@ -20,16 +20,20 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #import + +OF_ASSUME_NONNULL_BEGIN @interface IRCUser: OFObject { OFString *_nickname, *_username, *_hostname; } @property (readonly, nonatomic) OFString *nickname, *username, *hostname; + (instancetype)IRCUserWithString: (OFString *)string; -- initWithString: (OFString *)string; +- (instancetype)initWithString: (OFString *)string OF_DESIGNATED_INITIALIZER; @end + +OF_ASSUME_NONNULL_END Index: src/IRCUser.m ================================================================== --- src/IRCUser.m +++ src/IRCUser.m @@ -39,11 +39,11 @@ + (instancetype)IRCUserWithString: (OFString *)string { return [[[self alloc] initWithString: string] autorelease]; } -- initWithString: (OFString *)string +- (instancetype)initWithString: (OFString *)string { char *tmp2 = NULL; self = [super init]; @@ -86,11 +86,11 @@ [_hostname release]; [super dealloc]; } -- copy +- (id)copy { return [self retain]; } - (OFString *)description