|
|
|
|
|
|
|
|
#import "IRCClientSession.h" |
|
|
#import "IRCClientSession.h" |
|
|
#import "IRCClientChannel.h" |
|
|
#import "IRCClientChannel.h" |
|
|
#import "IRCClientChannel_Private.h" |
|
|
#import "IRCClientChannel_Private.h" |
|
|
|
|
|
#import "NSData+SA_NSDataExtensions.h" |
|
|
#include "string.h" |
|
|
#include "string.h" |
|
|
|
|
|
|
|
|
#pragma mark - Callback function declarations |
|
|
#pragma mark - Callback function declarations |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (int)connect; |
|
|
- (int)connect; |
|
|
{ |
|
|
{ |
|
|
return irc_connect(_irc_session, _server.UTF8String, (unsigned short) _port, (_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.SA_terminatedCString : NULL), _nickname.UTF8String, _username.UTF8String, _realname.UTF8String); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (void)disconnect |
|
|
- (void)disconnect |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (int)sendRaw:(NSData *)message |
|
|
- (int)sendRaw:(NSData *)message |
|
|
{ |
|
|
{ |
|
|
return irc_send_raw(_irc_session, message.bytes); |
|
|
|
|
|
|
|
|
return irc_send_raw(_irc_session, message.SA_terminatedCString); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (int)quit:(NSData *)reason |
|
|
- (int)quit:(NSData *)reason |
|
|
{ |
|
|
{ |
|
|
return irc_cmd_quit(_irc_session, reason.bytes); |
|
|
|
|
|
|
|
|
return irc_cmd_quit(_irc_session, reason.SA_terminatedCString); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (int)join:(NSData *)channel key:(NSData *)key |
|
|
- (int)join:(NSData *)channel key:(NSData *)key |
|
|
|
|
|
|
|
|
NSLog(@"Joining %@", channel); |
|
|
NSLog(@"Joining %@", channel); |
|
|
|
|
|
|
|
|
if (!key || !key.length > 0) |
|
|
if (!key || !key.length > 0) |
|
|
return irc_cmd_join(_irc_session, channel.bytes, NULL); |
|
|
|
|
|
|
|
|
return irc_cmd_join(_irc_session, channel.SA_terminatedCString, NULL); |
|
|
|
|
|
|
|
|
return irc_cmd_join(_irc_session, channel.bytes, key.bytes); |
|
|
|
|
|
|
|
|
return irc_cmd_join(_irc_session, channel.SA_terminatedCString, key.SA_terminatedCString); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (int)list:(NSData *)channel |
|
|
- (int)list:(NSData *)channel |
|
|
{ |
|
|
{ |
|
|
return irc_cmd_list(_irc_session, channel.bytes); |
|
|
|
|
|
|
|
|
return irc_cmd_list(_irc_session, channel.SA_terminatedCString); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (int)userMode:(NSString *)mode |
|
|
- (int)userMode:(NSString *)mode |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (int)message:(NSData *)message to:(NSString *)target |
|
|
- (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.SA_terminatedCString); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (int)action:(NSData *)action to:(NSString *)target |
|
|
- (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.SA_terminatedCString); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (int)notice:(NSData *)notice to:(NSString *)target |
|
|
- (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.SA_terminatedCString); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (int)ctcpRequest:(NSData *)request target:(NSString *)target |
|
|
- (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.SA_terminatedCString); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (int)ctcpReply:(NSData *)reply target:(NSString *)target |
|
|
- (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.SA_terminatedCString); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/****************************/ |
|
|
/****************************/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(reason) |
|
|
if(reason) |
|
|
{ |
|
|
{ |
|
|
reasonString = [[NSString alloc] initWithData:reason encoding:_encoding]; |
|
|
|
|
|
|
|
|
reasonString = [NSString stringWithCString:reason.SA_terminatedCString encoding:_encoding]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[_delegate userQuit:nick withReason:reasonString]; |
|
|
[_delegate userQuit:nick withReason:reasonString]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)privateMessageReceived:(NSData *)message fromUser:(NSString *)nick |
|
|
- (void)privateMessageReceived:(NSData *)message fromUser:(NSString *)nick |
|
|
{ |
|
|
{ |
|
|
NSString* messageString = [[NSString alloc] initWithData:message encoding:_encoding]; |
|
|
|
|
|
|
|
|
NSString* messageString = [NSString stringWithCString:message.SA_terminatedCString encoding:_encoding]; |
|
|
|
|
|
|
|
|
[_delegate privateMessageReceived:messageString fromUser:nick]; |
|
|
[_delegate privateMessageReceived:messageString fromUser:nick]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)privateNoticeReceived:(NSData *)notice fromUser:(NSString *)nick |
|
|
- (void)privateNoticeReceived:(NSData *)notice fromUser:(NSString *)nick |
|
|
{ |
|
|
{ |
|
|
NSString* noticeString = [[NSString alloc] initWithData:notice encoding:_encoding]; |
|
|
|
|
|
|
|
|
NSString* noticeString = [NSString stringWithCString:notice.SA_terminatedCString encoding:_encoding]; |
|
|
|
|
|
|
|
|
[_delegate privateNoticeReceived:noticeString fromUser:nick]; |
|
|
[_delegate privateNoticeReceived:noticeString fromUser:nick]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (void)CTCPRequestReceived:(NSData *)request fromUser:(NSString *)nick |
|
|
- (void)CTCPRequestReceived:(NSData *)request fromUser:(NSString *)nick |
|
|
{ |
|
|
{ |
|
|
const char* the_nick = getNickFromNickUserHost(nick).UTF8String; |
|
|
const char* the_nick = getNickFromNickUserHost(nick).UTF8String; |
|
|
const char* the_request = request.bytes; |
|
|
|
|
|
|
|
|
const char* the_request = request.SA_terminatedCString; |
|
|
|
|
|
|
|
|
if (strstr(the_request, "PING") == the_request) |
|
|
if (strstr(the_request, "PING") == the_request) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
char* request_type = strtok(request_string, " "); |
|
|
char* request_type = strtok(request_string, " "); |
|
|
char* request_body = strtok(NULL, " " ); |
|
|
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); |
|
|
free(request_string); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
// An action in a private message |
|
|
// An action in a private message |
|
|
NSString* actionString = [[NSString alloc] initWithData:action encoding:_encoding]; |
|
|
|
|
|
|
|
|
NSString* actionString = [NSString stringWithCString:action.SA_terminatedCString encoding:_encoding]; |
|
|
[_delegate privateCTCPActionReceived:actionString fromUser:nick]; |
|
|
[_delegate privateCTCPActionReceived:actionString fromUser:nick]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
NSData *reason = nil; |
|
|
NSData *reason = nil; |
|
|
if(count > 0) |
|
|
if(count > 0) |
|
|
{ |
|
|
{ |
|
|
reason = [[NSData alloc] initWithBytes:params[0] length:strlen(params[0])]; |
|
|
|
|
|
|
|
|
reason = [[NSData alloc] initWithBytes:params[0] length:strlen(params[0]) + 1]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[clientSession userQuit:nick withReason:reason]; |
|
|
[clientSession userQuit:nick withReason:reason]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (count > 1) |
|
|
if (count > 1) |
|
|
{ |
|
|
{ |
|
|
reason = [NSData dataWithBytes:params[1] length:strlen(params[1])+1]; |
|
|
|
|
|
|
|
|
reason = [NSData dataWithBytes:params[1] length:strlen(params[1])]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[clientSession userParted:nick channel:channelName withReason:reason]; |
|
|
[clientSession userParted:nick channel:channelName withReason:reason]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (count > 1) |
|
|
if (count > 1) |
|
|
{ |
|
|
{ |
|
|
topic = [NSData dataWithBytes:params[1] length:strlen(params[1])]; |
|
|
|
|
|
|
|
|
topic = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[clientSession topicSet:topic forChannel:channelName by:nick]; |
|
|
[clientSession topicSet:topic forChannel:channelName by:nick]; |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session); |
|
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session); |
|
|
NSString *byNick = @(origin); |
|
|
NSString *byNick = @(origin); |
|
|
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0])]; |
|
|
|
|
|
|
|
|
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1]; |
|
|
NSString *nick = nil; |
|
|
NSString *nick = nil; |
|
|
NSData *reason = nil; |
|
|
NSData *reason = nil; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (count > 2) |
|
|
if (count > 2) |
|
|
{ |
|
|
{ |
|
|
reason = [NSData dataWithBytes:params[2] length:strlen(params[2])]; |
|
|
|
|
|
|
|
|
reason = [NSData dataWithBytes:params[2] length:strlen(params[2]) + 1]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[clientSession userKicked:nick fromChannel:channelName by:byNick withReason:reason]; |
|
|
[clientSession userKicked:nick fromChannel:channelName by:byNick withReason:reason]; |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session); |
|
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session); |
|
|
NSString *nick = @(origin); |
|
|
NSString *nick = @(origin); |
|
|
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0])]; |
|
|
|
|
|
|
|
|
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1]; |
|
|
NSData *message = nil; |
|
|
NSData *message = nil; |
|
|
|
|
|
|
|
|
if (count > 1) |
|
|
if (count > 1) |
|
|
{ |
|
|
{ |
|
|
message = [NSData dataWithBytes:params[1] length:strlen(params[1])]; |
|
|
|
|
|
|
|
|
message = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[clientSession messageSent:message toChannel:channelName byUser:nick]; |
|
|
[clientSession messageSent:message toChannel:channelName byUser:nick]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (count > 1) |
|
|
if (count > 1) |
|
|
{ |
|
|
{ |
|
|
message = [NSData dataWithBytes:params[1] length:strlen(params[1])]; |
|
|
|
|
|
|
|
|
message = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[clientSession privateMessageReceived:message fromUser:nick]; |
|
|
[clientSession privateMessageReceived:message fromUser:nick]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (count > 1) |
|
|
if (count > 1) |
|
|
{ |
|
|
{ |
|
|
notice = [NSData dataWithBytes:params[1] length:strlen(params[1])]; |
|
|
|
|
|
|
|
|
notice = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[clientSession privateNoticeReceived:notice fromUser:nick]; |
|
|
[clientSession privateNoticeReceived:notice fromUser:nick]; |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session); |
|
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session); |
|
|
NSString *nick = @(origin); |
|
|
NSString *nick = @(origin); |
|
|
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0])]; |
|
|
|
|
|
|
|
|
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1]; |
|
|
NSData *notice = nil; |
|
|
NSData *notice = nil; |
|
|
|
|
|
|
|
|
if (count > 1) |
|
|
if (count > 1) |
|
|
{ |
|
|
{ |
|
|
notice = [NSData dataWithBytes:params[1] length:strlen(params[1])]; |
|
|
|
|
|
|
|
|
notice = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[clientSession noticeSent:notice toChannel:channelName byUser:nick]; |
|
|
[clientSession noticeSent:notice toChannel:channelName byUser:nick]; |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session); |
|
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session); |
|
|
NSString *nick = @(origin); |
|
|
NSString *nick = @(origin); |
|
|
NSData *channelName = [NSData dataWithBytes:params[1] length:strlen(params[1])]; |
|
|
|
|
|
|
|
|
NSData *channelName = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1]; |
|
|
|
|
|
|
|
|
[clientSession invitedToChannel:channelName by:nick]; |
|
|
[clientSession invitedToChannel:channelName by:nick]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session); |
|
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session); |
|
|
NSString *nick = @(origin); |
|
|
NSString *nick = @(origin); |
|
|
NSData* request = [NSData dataWithBytes:params[0] length:strlen(params[0])]; |
|
|
|
|
|
|
|
|
NSData* request = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1]; |
|
|
|
|
|
|
|
|
[clientSession CTCPRequestReceived:request fromUser:nick]; |
|
|
[clientSession CTCPRequestReceived:request fromUser:nick]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session); |
|
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session); |
|
|
|
|
|
|
|
|
NSString *nick = @(origin); |
|
|
NSString *nick = @(origin); |
|
|
NSData *reply = [NSData dataWithBytes:params[0] length:strlen(params[0])]; |
|
|
|
|
|
|
|
|
NSData *reply = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1]; |
|
|
|
|
|
|
|
|
[clientSession CTCPReplyReceived:reply fromUser:nick]; |
|
|
[clientSession CTCPReplyReceived:reply fromUser:nick]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session); |
|
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session); |
|
|
|
|
|
|
|
|
NSString *nick = @(origin); |
|
|
NSString *nick = @(origin); |
|
|
NSData *target = [NSData dataWithBytes:params[0] length:strlen(params[0])]; |
|
|
|
|
|
NSData *action = [NSData dataWithBytes:params[1] length:strlen(params[1])]; |
|
|
|
|
|
|
|
|
NSData *target = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1]; |
|
|
|
|
|
NSData *action = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1]; |
|
|
|
|
|
|
|
|
[clientSession CTCPActionPerformed:action byUser:nick atTarget:target]; |
|
|
[clientSession CTCPActionPerformed:action byUser:nick atTarget:target]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static void onUnknownEvent(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count) |
|
|
static void onUnknownEvent(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count) |
|
|
{ |
|
|
{ |
|
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session); |
|
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session); |
|
|
NSData *eventString = [NSData dataWithBytes:event length:strlen(event)]; |
|
|
|
|
|
|
|
|
NSData *eventString = [NSData dataWithBytes:event length:strlen(event) + 1]; |
|
|
NSString *sender = nil; |
|
|
NSString *sender = nil; |
|
|
|
|
|
|
|
|
if (origin != NULL) |
|
|
if (origin != NULL) |
|
|
|
|
|
|
|
|
NSMutableArray *paramsArray = [[NSMutableArray alloc] init]; |
|
|
NSMutableArray *paramsArray = [[NSMutableArray alloc] init]; |
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < count; i++) |
|
|
for (unsigned int i = 0; i < count; i++) |
|
|
[paramsArray addObject:[NSData dataWithBytes:params[i] length:strlen(params[i])]]; |
|
|
|
|
|
|
|
|
[paramsArray addObject:[NSData dataWithBytes:params[i] length:strlen(params[i]) + 1]]; |
|
|
|
|
|
|
|
|
[clientSession unknownEventReceived:eventString from:sender params:[paramsArray copy]]; |
|
|
[clientSession unknownEventReceived:eventString from:sender params:[paramsArray copy]]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
NSMutableArray *paramsArray = [[NSMutableArray alloc] init]; |
|
|
NSMutableArray *paramsArray = [[NSMutableArray alloc] init]; |
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < count; i++) |
|
|
for (unsigned int i = 0; i < count; i++) |
|
|
[paramsArray addObject:[NSData dataWithBytes:params[i] length:strlen(params[i])]]; |
|
|
|
|
|
|
|
|
[paramsArray addObject:[NSData dataWithBytes:params[i] length:strlen(params[i]) + 1]]; |
|
|
|
|
|
|
|
|
[clientSession numericEventReceived:eventNumber from:sender params:[paramsArray copy]]; |
|
|
[clientSession numericEventReceived:eventNumber from:sender params:[paramsArray copy]]; |
|
|
} |
|
|
} |