diff --git a/IRCClient.xcodeproj/project.pbxproj b/IRCClient.xcodeproj/project.pbxproj index 21cb83b..b027a47 100644 --- a/IRCClient.xcodeproj/project.pbxproj +++ b/IRCClient.xcodeproj/project.pbxproj @@ -151,7 +151,7 @@ 86F2EFDD1C21F73600B033A4 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0710; + LastUpgradeCheck = 0720; ORGANIZATIONNAME = "Said Achmiz"; TargetAttributes = { 86F2EFE51C21F73600B033A4 = { @@ -204,17 +204,23 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES; + CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_ASSIGN_ENUM = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -231,15 +237,24 @@ "DEBUG=1", "$(inherited)", ); + GCC_TREAT_WARNINGS_AS_ERRORS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; + GCC_WARN_ABOUT_MISSING_NEWLINE = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; + GCC_WARN_SHADOW = YES; + GCC_WARN_SIGN_COMPARE = YES; + GCC_WARN_STRICT_SELECTOR_MATCH = NO; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.6; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; + RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = macosx; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -250,17 +265,23 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES; + CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_ASSIGN_ENUM = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -271,14 +292,23 @@ ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; + GCC_TREAT_WARNINGS_AS_ERRORS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; + GCC_WARN_ABOUT_MISSING_NEWLINE = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; + GCC_WARN_SHADOW = YES; + GCC_WARN_SIGN_COMPARE = YES; + GCC_WARN_STRICT_SELECTOR_MATCH = NO; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.6; MTL_ENABLE_DEBUG_INFO = NO; + RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = macosx; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -288,14 +318,20 @@ 86F2EFEF1C21F73600B033A4 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD)"; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 2.0; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 2.0; DYLIB_CURRENT_VERSION = 2.0; DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_VERSION = 2.0; + FRAMEWORK_VERSION = A; + GCC_TREAT_WARNINGS_AS_ERRORS = YES; + GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; + GCC_WARN_ABOUT_MISSING_NEWLINE = YES; + GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; + GCC_WARN_SHADOW = YES; + GCC_WARN_SIGN_COMPARE = YES; + GCC_WARN_UNUSED_LABEL = YES; HEADER_SEARCH_PATHS = ( libircclient/, "$(PROJECT_DIR)/", @@ -311,6 +347,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.6; PRODUCT_BUNDLE_IDENTIFIER = saidachmiz.IRCClient; PRODUCT_NAME = "$(TARGET_NAME)"; + RUN_CLANG_STATIC_ANALYZER = YES; SKIP_INSTALL = YES; STRINGS_FILE_OUTPUT_ENCODING = "UTF-8"; VALID_ARCHS = x86_64; @@ -320,14 +357,20 @@ 86F2EFF01C21F73600B033A4 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD)"; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 2.0; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 2.0; DYLIB_CURRENT_VERSION = 2.0; DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_VERSION = 2.0; + FRAMEWORK_VERSION = A; + GCC_TREAT_WARNINGS_AS_ERRORS = YES; + GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; + GCC_WARN_ABOUT_MISSING_NEWLINE = YES; + GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; + GCC_WARN_SHADOW = YES; + GCC_WARN_SIGN_COMPARE = YES; + GCC_WARN_UNUSED_LABEL = YES; HEADER_SEARCH_PATHS = ( libircclient/, "$(PROJECT_DIR)/", @@ -343,6 +386,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.6; PRODUCT_BUNDLE_IDENTIFIER = saidachmiz.IRCClient; PRODUCT_NAME = "$(TARGET_NAME)"; + RUN_CLANG_STATIC_ANALYZER = YES; SKIP_INSTALL = YES; STRINGS_FILE_OUTPUT_ENCODING = "UTF-8"; VALID_ARCHS = x86_64; diff --git a/IRCClient/IRCClientChannel.h b/IRCClient/IRCClientChannel.h index ada31a3..b30c5ec 100644 --- a/IRCClient/IRCClientChannel.h +++ b/IRCClient/IRCClientChannel.h @@ -27,8 +27,6 @@ * for a given session when the client joins an IRC channel. */ -@class IRCClientSession; - #pragma mark IRCClientChannel class declaration @interface IRCClientChannel : NSObject @@ -41,7 +39,7 @@ @property (assign) id delegate; /** Name of the channel */ -@property (nonatomic, retain) NSData *name; +@property (copy) NSData *name; /** Encoding used by, and in, this channel */ @property (assign) NSStringEncoding encoding; @@ -54,14 +52,14 @@ * topicSet:by: message (and the topic property of the channel object will be * updated automatically). */ -@property (nonatomic, readonly) NSData *topic; +@property (readonly) NSData *topic; /** Modes of the channel */ -@property (nonatomic, retain) NSString *modes; +@property (readonly) NSString *modes; /** An array of nicknames stored as NSStrings that list the connected users for the channel */ -@property (nonatomic, readonly) NSArray *nicks; +@property (readonly) NSArray *nicks; /**************************/ #pragma mark - IRC commands diff --git a/IRCClient/IRCClientChannel.m b/IRCClient/IRCClientChannel.m index 940f44a..73141f2 100644 --- a/IRCClient/IRCClientChannel.m +++ b/IRCClient/IRCClientChannel.m @@ -18,61 +18,70 @@ */ #import "IRCClientChannel.h" -#import "IRCClientSession.h" #import "IRCClientChannel_Private.h" +/*********************************************/ #pragma mark IRCClientChannel private category +/*********************************************/ @interface IRCClientChannel() { - NSData *name; - irc_session_t *irc_session; - NSStringEncoding encoding; - NSData *topic; - NSString *modes; - NSMutableArray *nicks; + irc_session_t *_irc_session; + + NSMutableArray *_nicks; } -@property (nonatomic, retain) NSMutableArray *nicks; +@property (readwrite) NSData *topic; +@property (readwrite) NSString *modes; +@property (readwrite) NSMutableArray *nicks; @end +/***************************************************/ #pragma mark - IRCClientChannel class implementation +/***************************************************/ @implementation IRCClientChannel +/********************************/ #pragma mark - Property synthesis +/********************************/ -@synthesize delegate; -@synthesize name; -@synthesize encoding; -@synthesize topic; -@synthesize modes; +@synthesize delegate = _delegate; +@synthesize name = _name; +@synthesize encoding = _encoding; +@synthesize topic = _topic; +@synthesize modes = _modes; +/******************************/ #pragma mark - Custom accessors +/******************************/ -(NSArray *)nicks { - NSArray* nicksCopy = [nicks copy]; + NSArray* nicksCopy = [_nicks copy]; return nicksCopy; } --(void)setNicks:(NSArray *)newNicks +-(void)setNicks:(NSArray *)nicks { - nicks = [newNicks mutableCopy]; + _nicks = [nicks mutableCopy]; } /**************************/ #pragma mark - Initializers /**************************/ --(instancetype)initWithName:(NSData *)aName andIRCSession:(irc_session_t *)session +-(instancetype)initWithName:(NSData *)name andIRCSession:(irc_session_t *)irc_session { - if ((self = [super init])) { - name = aName; - irc_session = session; - topic = [NSData dataWithBytes:@"".UTF8String length:1]; - encoding = NSUTF8StringEncoding; + if ((self = [super init])) + { + _irc_session = irc_session; + + _name = name; + _encoding = NSUTF8StringEncoding; + _topic = [NSData dataWithBytes:@"".UTF8String length:0]; + _modes = @""; } return self; @@ -84,22 +93,22 @@ - (int)part { - return irc_cmd_part(irc_session, name.bytes); + return irc_cmd_part(_irc_session, _name.bytes); } - (int)invite:(NSString *)nick { - return irc_cmd_invite(irc_session, nick.UTF8String, name.bytes); + return irc_cmd_invite(_irc_session, nick.UTF8String, _name.bytes); } - (int)refreshNames { - return irc_cmd_names(irc_session, name.bytes); + return irc_cmd_names(_irc_session, _name.bytes); } - (void)setChannelTopic:(NSString *)newTopic { - irc_cmd_topic(irc_session, name.bytes, [newTopic cStringUsingEncoding:encoding]); + irc_cmd_topic(_irc_session, _name.bytes, [newTopic cStringUsingEncoding:_encoding]); } - (int)setMode:(NSString *)mode params:(NSString *)params @@ -109,32 +118,32 @@ if(params != nil && params.length > 0) [modeString appendFormat:@" %@", params]; - return irc_cmd_channel_mode(irc_session, name.bytes, modeString.UTF8String); + return irc_cmd_channel_mode(_irc_session, _name.bytes, modeString.UTF8String); } - (int)message:(NSString *)message { - return irc_cmd_msg(irc_session, name.bytes, [message cStringUsingEncoding:encoding]); + return irc_cmd_msg(_irc_session, _name.bytes, [message cStringUsingEncoding:_encoding]); } - (int)action:(NSString *)action { - return irc_cmd_me(irc_session, name.bytes, [action cStringUsingEncoding:encoding]); + return irc_cmd_me(_irc_session, _name.bytes, [action cStringUsingEncoding:_encoding]); } - (int)notice:(NSString *)notice { - return irc_cmd_notice(irc_session, name.bytes, [notice cStringUsingEncoding:encoding]); + return irc_cmd_notice(_irc_session, _name.bytes, [notice cStringUsingEncoding:_encoding]); } - (int)kick:(NSString *)nick reason:(NSString *)reason { - return irc_cmd_kick(irc_session, nick.UTF8String, name.bytes, [reason cStringUsingEncoding:encoding]); + return irc_cmd_kick(_irc_session, nick.UTF8String, _name.bytes, [reason cStringUsingEncoding:_encoding]); } - (int)ctcpRequest:(NSData *)request { - return irc_cmd_ctcp_request(irc_session, name.bytes, request.bytes); + return irc_cmd_ctcp_request(_irc_session, _name.bytes, request.bytes); } /****************************/ @@ -143,50 +152,50 @@ - (void)userJoined:(NSString *)nick { - [delegate userJoined:nick]; + [_delegate userJoined:nick]; } - (void)userParted:(NSString *)nick withReason:(NSData *)reason us:(BOOL)wasItUs { - NSString* reasonString = [[NSString alloc] initWithData:reason encoding:encoding]; - [delegate userParted:nick withReason:reasonString us:wasItUs]; + NSString* reasonString = [[NSString alloc] initWithData:reason encoding:_encoding]; + [_delegate userParted:nick withReason:reasonString us:wasItUs]; } - (void)modeSet:(NSString *)mode withParams:(NSString *)params by:(NSString *)nick { - [delegate modeSet:mode withParams:params by:nick]; + [_delegate modeSet:mode withParams:params by:nick]; } -- (void)topicSet:(NSData *)newTopic by:(NSString *)nick +- (void)topicSet:(NSData *)topic by:(NSString *)nick { - topic = newTopic; + _topic = topic; - NSString* topicString = [[NSString alloc] initWithData:topic encoding:encoding]; - [delegate topicSet:topicString by:nick]; + NSString* topicString = [[NSString alloc] initWithData:_topic encoding:_encoding]; + [_delegate topicSet:topicString by:nick]; } - (void)userKicked:(NSString *)nick withReason:(NSData *)reason by:(NSString *)byNick us:(BOOL)wasItUs { - NSString* reasonString = [[NSString alloc] initWithData:reason encoding:encoding]; - [delegate userKicked:nick withReason:reasonString by:byNick us:wasItUs]; + NSString* reasonString = [[NSString alloc] initWithData:reason encoding:_encoding]; + [_delegate userKicked:nick withReason:reasonString by:byNick us:wasItUs]; } - (void)messageSent:(NSData *)message byUser:(NSString *)nick { - NSString* messageString = [[NSString alloc] initWithData:message encoding:encoding]; - [delegate messageSent:messageString byUser:nick]; + NSString* messageString = [[NSString alloc] initWithData:message encoding:_encoding]; + [_delegate messageSent:messageString byUser:nick]; } - (void)noticeSent:(NSData *)notice byUser:(NSString *)nick { - NSString* noticeString = [[NSString alloc] initWithData:notice encoding:encoding]; - [delegate noticeSent:noticeString byUser:nick]; + NSString* noticeString = [[NSString alloc] initWithData:notice encoding:_encoding]; + [_delegate noticeSent:noticeString byUser:nick]; } - (void)actionPerformed:(NSData *)action byUser:(NSString *)nick { - NSString* actionString = [[NSString alloc] initWithData:action encoding:encoding]; - [delegate actionPerformed:actionString byUser:nick]; + NSString* actionString = [[NSString alloc] initWithData:action encoding:_encoding]; + [_delegate actionPerformed:actionString byUser:nick]; } @end diff --git a/IRCClient/IRCClientSession.h b/IRCClient/IRCClientSession.h index 2c92aab..2a72362 100644 --- a/IRCClient/IRCClientSession.h +++ b/IRCClient/IRCClientSession.h @@ -74,7 +74,9 @@ @class IRCClientChannel; +/**********************************************/ #pragma mark IRCClientSession class declaration +/**********************************************/ @interface IRCClientSession : NSObject @@ -88,7 +90,7 @@ /** User-defined session ID (for one delegate to keep track of multiple sessions, if desired). */ -@property NSUInteger sessionID; +@property (assign) NSUInteger sessionID; /** The version string for the client to send back on CTCP VERSION requests */ @property (copy) NSString *version; @@ -97,7 +99,7 @@ @property (copy) NSString *server; /** IRC port to connect to */ -@property NSUInteger port; +@property (assign) NSUInteger port; /** Server password to provide on connect (may be left empty or nil) */ @property (copy) NSData *password; @@ -119,10 +121,7 @@ */ @property (copy) NSString *realname; -/** An NSDictionary of channels that the client is currently connected to. */ -@property (retain, readonly) NSDictionary *channels; - -/** The default text encoding for messages on this server. +/** The default text encoding for messages on this server. This concerns messages received via PRIVMSG and NOTICE, and TOPIC in a channel. It also affects what encoding reasons given for QUIT messages are assumed to be in. @@ -130,9 +129,12 @@ */ @property (assign) NSStringEncoding encoding; +/** An NSDictionary of channels that the client is currently connected to. */ +@property (readonly) NSDictionary *channels; + /** returns YES if the server is currently connected successfully, and NO if it is not. */ -@property (nonatomic, readonly) bool connected; +@property (readonly, getter=isConnected) bool connected; /***************************/ #pragma mark - Class methods diff --git a/IRCClient/IRCClientSession.m b/IRCClient/IRCClientSession.m index 0675eaa..427ec07 100644 --- a/IRCClient/IRCClientSession.m +++ b/IRCClient/IRCClientSession.m @@ -19,7 +19,7 @@ #pragma mark Defines and includes -#define IRCCLIENTVERSION "1.0" +#define IRCCLIENTVERSION "2.0" #import "IRCClientSession.h" #import "IRCClientChannel.h" @@ -52,24 +52,14 @@ static void onNumericEvent(irc_session_t *session, unsigned int event, const cha @interface IRCClientSession() { - irc_callbacks_t callbacks; - irc_session_t *irc_session; - NSThread *thread; + irc_callbacks_t _callbacks; + irc_session_t *_irc_session; + NSThread *_thread; - NSString *version; - NSString *server; - NSUInteger port; - NSData *password; - - NSString *nickname; - NSString *username; - NSString *realname; - - NSMutableDictionary *channels; - NSStringEncoding encoding; + NSMutableDictionary *_channels; } -@property (nonatomic, retain) NSMutableDictionary *channels; +@property (readwrite) NSMutableDictionary *channels; @end @@ -79,33 +69,37 @@ static void onNumericEvent(irc_session_t *session, unsigned int event, const cha #pragma mark - Property synthesis -@synthesize delegate; -@synthesize sessionID; -@synthesize version; -@synthesize server; -@synthesize port; -@synthesize password; -@synthesize nickname; -@synthesize username; -@synthesize realname; -@synthesize encoding; +@synthesize delegate = _delegate; +@synthesize sessionID = _sessionID; + +@synthesize version = _version; + +@synthesize server = _server; +@synthesize port = _port; +@synthesize password = _password; + +@synthesize nickname = _nickname; +@synthesize username = _username; +@synthesize realname = _realname; + +@synthesize encoding = _encoding; #pragma mark - Custom accessors -(NSDictionary*)channels { - NSDictionary* channelsCopy = [channels copy]; + NSDictionary* channelsCopy = [_channels copy]; return channelsCopy; } --(void)setChannels:(NSMutableDictionary *)newChannels +-(void)setChannels:(NSDictionary *)channels { - channels = newChannels; + _channels = [channels mutableCopy]; } -- (bool)connected +- (bool)isConnected { - return irc_is_connected(irc_session); + return irc_is_connected(_irc_session); } /************************************/ @@ -115,31 +109,31 @@ static void onNumericEvent(irc_session_t *session, unsigned int event, const cha -(instancetype)init { if ((self = [super init])) { - callbacks.event_connect = onConnect; - callbacks.event_nick = onNick; - callbacks.event_quit = onQuit; - callbacks.event_join = onJoinChannel; - callbacks.event_part = onPartChannel; - callbacks.event_mode = onMode; - callbacks.event_umode = onUserMode; - callbacks.event_topic = onTopic; - callbacks.event_kick = onKick; - callbacks.event_channel = onChannelPrvmsg; - callbacks.event_privmsg = onPrivmsg; - callbacks.event_notice = onNotice; - callbacks.event_channel_notice = onChannelNotice; - callbacks.event_invite = onInvite; - callbacks.event_ctcp_req = onCtcpRequest; - callbacks.event_ctcp_rep = onCtcpReply; - callbacks.event_ctcp_action = onCtcpAction; - callbacks.event_unknown = onUnknownEvent; - callbacks.event_numeric = onNumericEvent; - callbacks.event_dcc_chat_req = NULL; - callbacks.event_dcc_send_req = NULL; + _callbacks.event_connect = onConnect; + _callbacks.event_nick = onNick; + _callbacks.event_quit = onQuit; + _callbacks.event_join = onJoinChannel; + _callbacks.event_part = onPartChannel; + _callbacks.event_mode = onMode; + _callbacks.event_umode = onUserMode; + _callbacks.event_topic = onTopic; + _callbacks.event_kick = onKick; + _callbacks.event_channel = onChannelPrvmsg; + _callbacks.event_privmsg = onPrivmsg; + _callbacks.event_notice = onNotice; + _callbacks.event_channel_notice = onChannelNotice; + _callbacks.event_invite = onInvite; + _callbacks.event_ctcp_req = onCtcpRequest; + _callbacks.event_ctcp_rep = onCtcpReply; + _callbacks.event_ctcp_action = onCtcpAction; + _callbacks.event_unknown = onUnknownEvent; + _callbacks.event_numeric = onNumericEvent; + _callbacks.event_dcc_chat_req = NULL; + _callbacks.event_dcc_send_req = NULL; - irc_session = irc_create_session(&callbacks); + _irc_session = irc_create_session(&_callbacks); - if (!irc_session) { + if (!_irc_session) { NSLog(@"Could not create irc_session."); return nil; } @@ -147,54 +141,52 @@ static void onNumericEvent(irc_session_t *session, unsigned int event, const cha // Strip server info from nicks. // irc_option_set(irc_session, LIBIRC_OPTION_STRIPNICKS); - irc_set_ctx(irc_session, (__bridge void *)(self)); + irc_set_ctx(_irc_session, (__bridge void *)(self)); unsigned int high, low; irc_get_version (&high, &low); - version = [NSString stringWithFormat:@"IRCClient Framework v%s (Nathan Ollerenshaw) - libirc v%d.%d (Georgy Yunaev)", IRCCLIENTVERSION, high, low]; + _version = [NSString stringWithFormat:@"IRCClient Framework v%s (Said Achmiz) - libirc v%d.%d (George Yunaev)", IRCCLIENTVERSION, high, low]; - channels = [[NSMutableDictionary alloc] init]; + _channels = [[NSMutableDictionary alloc] init]; } return self; } -(void)dealloc { - if (irc_is_connected(irc_session)) + if (irc_is_connected(_irc_session)) NSLog(@"Warning: IRC Session is not disconnected on dealloc"); - irc_destroy_session(irc_session); + irc_destroy_session(_irc_session); } - (int)connect; { - unsigned short sPort = port; - - return irc_connect(irc_session, server.UTF8String, sPort, (password.length > 0 ? password.bytes : NULL), nickname.UTF8String, username.UTF8String, realname.UTF8String); + return irc_connect(_irc_session, _server.UTF8String, (unsigned short) _port, (_password.length > 0 ? _password.bytes : NULL), _nickname.UTF8String, _username.UTF8String, _realname.UTF8String); } - (void)disconnect { - irc_disconnect(irc_session); + irc_disconnect(_irc_session); } - (void)startThread { @autoreleasepool { - irc_run(irc_session); + irc_run(_irc_session); } } - (void)run { - if (thread) { + if (_thread) { NSLog(@"Thread already running!"); return; } - thread = [[NSThread alloc] initWithTarget:self selector:@selector(startThread) object:nil]; - [thread start]; + _thread = [[NSThread alloc] initWithTarget:self selector:@selector(startThread) object:nil]; + [_thread start]; } /**************************/ @@ -203,12 +195,12 @@ static void onNumericEvent(irc_session_t *session, unsigned int event, const cha - (int)sendRaw:(NSData *)message { - return irc_send_raw(irc_session, message.bytes); + return irc_send_raw(_irc_session, message.bytes); } - (int)quit:(NSData *)reason { - return irc_cmd_quit(irc_session, reason.bytes); + return irc_cmd_quit(_irc_session, reason.bytes); } - (int)join:(NSData *)channel key:(NSData *)key @@ -216,54 +208,54 @@ static void onNumericEvent(irc_session_t *session, unsigned int event, const cha NSLog(@"Joining %@", channel); if (!key || !key.length > 0) - return irc_cmd_join(irc_session, channel.bytes, NULL); + return irc_cmd_join(_irc_session, channel.bytes, NULL); - return irc_cmd_join(irc_session, channel.bytes, key.bytes); + return irc_cmd_join(_irc_session, channel.bytes, key.bytes); } - (int)list:(NSData *)channel { - return irc_cmd_list(irc_session, channel.bytes); + return irc_cmd_list(_irc_session, channel.bytes); } - (int)userMode:(NSString *)mode { - return irc_cmd_user_mode(irc_session, mode.UTF8String); + return irc_cmd_user_mode(_irc_session, mode.UTF8String); } - (int)nick:(NSString *)newnick { - return irc_cmd_nick(irc_session, newnick.UTF8String); + return irc_cmd_nick(_irc_session, newnick.UTF8String); } - (int)whois:(NSString *)nick { - return irc_cmd_whois(irc_session, nick.UTF8String); + return irc_cmd_whois(_irc_session, nick.UTF8String); } - (int)message:(NSData *)message to:(NSString *)target { - return irc_cmd_msg(irc_session, target.UTF8String, message.bytes); + return irc_cmd_msg(_irc_session, target.UTF8String, message.bytes); } - (int)action:(NSData *)action to:(NSString *)target { - return irc_cmd_me(irc_session, target.UTF8String, action.bytes); + return irc_cmd_me(_irc_session, target.UTF8String, action.bytes); } - (int)notice:(NSData *)notice to:(NSString *)target { - return irc_cmd_notice(irc_session, target.UTF8String, notice.bytes); + return irc_cmd_notice(_irc_session, target.UTF8String, notice.bytes); } - (int)ctcpRequest:(NSData *)request target:(NSString *)target { - return irc_cmd_ctcp_request(irc_session, target.UTF8String, request.bytes); + return irc_cmd_ctcp_request(_irc_session, target.UTF8String, request.bytes); } - (int)ctcpReply:(NSData *)reply target:(NSString *)target { - return irc_cmd_ctcp_reply(irc_session, target.UTF8String, reply.bytes); + return irc_cmd_ctcp_reply(_irc_session, target.UTF8String, reply.bytes); } /****************************/ @@ -272,19 +264,19 @@ static void onNumericEvent(irc_session_t *session, unsigned int event, const cha - (void)connectionSucceeded { - [delegate connectionSucceeded]; + [_delegate connectionSucceeded]; } - (void)nickChangedFrom:(NSString *)oldNick to:(NSString *)newNick { - if ([nickname isEqualToString:oldNick]) + if ([_nickname isEqualToString:oldNick]) { - nickname = newNick; - [delegate nickChangedFrom:oldNick to:newNick own:YES]; + _nickname = newNick; + [_delegate nickChangedFrom:oldNick to:newNick own:YES]; } else { - [delegate nickChangedFrom:oldNick to:newNick own:NO]; + [_delegate nickChangedFrom:oldNick to:newNick own:NO]; } } @@ -294,44 +286,44 @@ static void onNumericEvent(irc_session_t *session, unsigned int event, const cha if(reason) { - reasonString = [[NSString alloc] initWithData:reason encoding:encoding]; + reasonString = [[NSString alloc] initWithData:reason encoding:_encoding]; } - [delegate userQuit:nick withReason:reasonString]; + [_delegate userQuit:nick withReason:reasonString]; } - (void)userJoined:(NSString *)nick channel:(NSData *)channelName { NSString* nickOnly = getNickFromNickUserHost(nick); - if ([nickname isEqualToString:nickOnly]) + if ([_nickname isEqualToString:nickOnly]) { // We just joined a channel; allocate an IRCClientChannel object and send it // to the main thread. - IRCClientChannel* newChannel = [[IRCClientChannel alloc] initWithName:channelName andIRCSession:irc_session]; - channels[channelName] = newChannel; - [delegate joinedNewChannel:newChannel]; + IRCClientChannel* newChannel = [[IRCClientChannel alloc] initWithName:channelName andIRCSession:_irc_session]; + _channels[channelName] = newChannel; + [_delegate joinedNewChannel:newChannel]; } else { // Someone joined a channel we're on. - IRCClientChannel* channel = channels[channelName]; + IRCClientChannel* channel = _channels[channelName]; [channel userJoined:nick]; } } - (void)userParted:(NSString *)nick channel:(NSData *)channelName withReason:(NSData *)reason { - IRCClientChannel* channel = channels[channelName]; + IRCClientChannel* channel = _channels[channelName]; NSString* nickOnly = getNickFromNickUserHost(nick); - if ([nickname isEqualToString:nickOnly]) + if ([_nickname isEqualToString:nickOnly]) { // We just left a channel; remove it from the channels dict. - [channels removeObjectForKey:channelName]; + [_channels removeObjectForKey:channelName]; [channel userParted:nick withReason:reason us:YES]; } else @@ -342,32 +334,32 @@ static void onNumericEvent(irc_session_t *session, unsigned int event, const cha - (void)modeSet:(NSString* )mode withParams:(NSString *)params forChannel:(NSData *)channelName by:(NSString *)nick { - IRCClientChannel *channel = channels[channelName]; + IRCClientChannel *channel = _channels[channelName]; [channel modeSet:mode withParams:params by:nick]; } - (void)modeSet:(NSString *)mode by:(NSString *)nick { - [delegate modeSet:mode by:nick]; + [_delegate modeSet:mode by:nick]; } - (void)topicSet:(NSData *)newTopic forChannel:(NSData *)channelName by:(NSString *)nick { - IRCClientChannel *channel = channels[channelName]; + IRCClientChannel *channel = _channels[channelName]; [channel topicSet:newTopic by:nick]; } - (void)userKicked:(NSString *)nick fromChannel:(NSData *)channelName by:(NSString *)byNick withReason:(NSData *)reason { - IRCClientChannel* channel = channels[channelName]; + IRCClientChannel* channel = _channels[channelName]; if (nick == nil) { // we got kicked from a channel we're on - [channels removeObjectForKey:channelName]; - [channel userKicked:nickname withReason:reason by:byNick us:YES]; + [_channels removeObjectForKey:channelName]; + [channel userKicked:_nickname withReason:reason by:byNick us:YES]; } else { @@ -378,35 +370,35 @@ static void onNumericEvent(irc_session_t *session, unsigned int event, const cha - (void)messageSent:(NSData *)message toChannel:(NSData *)channelName byUser:(NSString *)nick { - IRCClientChannel *channel = channels[channelName]; + IRCClientChannel *channel = _channels[channelName]; [channel messageSent:message byUser:nick]; } - (void)privateMessageReceived:(NSData *)message fromUser:(NSString *)nick { - NSString* messageString = [[NSString alloc] initWithData:message encoding:encoding]; + NSString* messageString = [[NSString alloc] initWithData:message encoding:_encoding]; - [delegate privateMessageReceived:messageString fromUser:nick]; + [_delegate privateMessageReceived:messageString fromUser:nick]; } - (void)noticeSent:(NSData *)notice toChannel:(NSData *)channelName byUser:(NSString *)nick { - IRCClientChannel *channel = channels[channelName]; + IRCClientChannel *channel = _channels[channelName]; [channel noticeSent:notice byUser:nick]; } - (void)privateNoticeReceived:(NSData *)notice fromUser:(NSString *)nick { - NSString* noticeString = [[NSString alloc] initWithData:notice encoding:encoding]; + NSString* noticeString = [[NSString alloc] initWithData:notice encoding:_encoding]; - [delegate privateNoticeReceived:noticeString fromUser:nick]; + [_delegate privateNoticeReceived:noticeString fromUser:nick]; } - (void)invitedToChannel:(NSData *)channelName by:(NSString *)nick { - [delegate invitedToChannel:channelName by:nick]; + [_delegate invitedToChannel:channelName by:nick]; } - (void)CTCPRequestReceived:(NSData *)request fromUser:(NSString *)nick @@ -416,23 +408,23 @@ static void onNumericEvent(irc_session_t *session, unsigned int event, const cha if (strstr(the_request, "PING") == the_request) { - irc_cmd_ctcp_reply(irc_session, the_nick, the_request); + irc_cmd_ctcp_reply(_irc_session, the_nick, the_request); } else if (!strcmp (the_request, "VERSION")) { - irc_cmd_ctcp_reply (irc_session, the_nick, [NSString stringWithFormat:@"VERSION %@", version].UTF8String); + irc_cmd_ctcp_reply (_irc_session, the_nick, [NSString stringWithFormat:@"VERSION %@", _version].UTF8String); } else if (!strcmp (the_request, "FINGER")) { - irc_cmd_ctcp_reply (irc_session, the_nick, [NSString stringWithFormat:@"FINGER %@ (%@) Idle 0 seconds", username, realname].UTF8String); + irc_cmd_ctcp_reply (_irc_session, the_nick, [NSString stringWithFormat:@"FINGER %@ (%@) Idle 0 seconds", _username, _realname].UTF8String); } else if (!strcmp (the_request, "TIME")) { - irc_cmd_ctcp_reply(irc_session, the_nick, [[NSDate dateWithTimeIntervalSinceNow:0] descriptionWithCalendarFormat:@"TIME %a %b %e %H:%M:%S %Z %Y" timeZone:nil locale:[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]].UTF8String); + irc_cmd_ctcp_reply(_irc_session, the_nick, [[NSDate dateWithTimeIntervalSinceNow:0] descriptionWithCalendarFormat:@"TIME %a %b %e %H:%M:%S %Z %Y" timeZone:nil locale:[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]].UTF8String); } else { - if ([delegate respondsToSelector:@selector(CTCPRequestReceived:ofType:fromUser:)]) + if ([_delegate respondsToSelector:@selector(CTCPRequestReceived:ofType:fromUser:)]) { char* request_string = malloc(request.length); [request getBytes:request_string length:request.length]; @@ -440,19 +432,21 @@ static void onNumericEvent(irc_session_t *session, unsigned int event, const cha char* request_type = strtok(request_string, " "); char* request_body = strtok(NULL, " " ); - [delegate CTCPRequestReceived:[NSData dataWithBytes:request_body length:strlen(request_body)+1] ofType:[NSData dataWithBytes:request_type length:strlen(request_type)+1] fromUser:nick]; + [_delegate CTCPRequestReceived:[NSData dataWithBytes:request_body length:strlen(request_body)+1] ofType:[NSData dataWithBytes:request_type length:strlen(request_type)+1] fromUser:nick]; + + free(request_string); } } } - (void)CTCPReplyReceived:(NSData *)reply fromUser:(NSString *)nick { - [delegate CTCPReplyReceived:reply fromUser:nick]; + [_delegate CTCPReplyReceived:reply fromUser:nick]; } - (void)CTCPActionPerformed:(NSData *)action byUser:(NSString *)nick atTarget:(NSData *)target { - IRCClientChannel* channel = channels[target]; + IRCClientChannel* channel = _channels[target]; if(channel != nil) { @@ -462,19 +456,19 @@ static void onNumericEvent(irc_session_t *session, unsigned int event, const cha else { // An action in a private message - NSString* actionString = [[NSString alloc] initWithData:action encoding:encoding]; - [delegate privateCTCPActionReceived:actionString fromUser:nick]; + NSString* actionString = [[NSString alloc] initWithData:action encoding:_encoding]; + [_delegate privateCTCPActionReceived:actionString fromUser:nick]; } } - (void)unknownEventReceived:(NSData *)event from:(NSString *)origin params:(NSArray *)params { - [delegate unknownEventReceived:event from:origin params:params]; + [_delegate unknownEventReceived:event from:origin params:params]; } -(void)numericEventReceived:(NSUInteger)event from:(NSString *)origin params:(NSArray *)params { - [delegate numericEventReceived:event from:origin params:params]; + [_delegate numericEventReceived:event from:origin params:params]; } @end