Banish NSString to the depths of oblivion (encoding fix)
IRCClient is now entirely text-encoding-agnostic[1]. It takes values for messages, nicks, channels, etc. as NSData objects which should contain null-terminated C strings, and returns values likewise. The 'encoding' property of IRCClientSession and IRCClientChannel is no longer used for any[1] internal functions. It is the responsibility of the framework's user to select an appropriate encoding for display of received C-strings (storing this encoding with session and channel objects is the function of the 'encoding' property). [1] The one exception is the reply string to CTCP TIME requests, which uses the specified encoding for the session.
This commit is contained in:
parent
8b8a11af25
commit
554522c5ce
@ -55,9 +55,9 @@
|
|||||||
@property (readonly) NSData *topic;
|
@property (readonly) NSData *topic;
|
||||||
|
|
||||||
/** Modes of the channel */
|
/** Modes of the channel */
|
||||||
@property (readonly) NSString *modes;
|
@property (readonly) NSData *modes;
|
||||||
|
|
||||||
/** An array of nicknames stored as NSStrings that list the connected users
|
/** An array of nicknames stored as NSData objects that list the connected users
|
||||||
for the channel */
|
for the channel */
|
||||||
@property (readonly) NSArray *nicks;
|
@property (readonly) NSArray *nicks;
|
||||||
|
|
||||||
@ -72,7 +72,7 @@
|
|||||||
*
|
*
|
||||||
* @param nick the nickname of the client to invite.
|
* @param nick the nickname of the client to invite.
|
||||||
*/
|
*/
|
||||||
- (int)invite:(NSString *)nick;
|
- (int)invite:(NSData *)nick;
|
||||||
|
|
||||||
/** Sets the topic of the channel.
|
/** Sets the topic of the channel.
|
||||||
*
|
*
|
||||||
@ -81,7 +81,7 @@
|
|||||||
*
|
*
|
||||||
* @param aTopic the topic the client wishes to set for the channel.
|
* @param aTopic the topic the client wishes to set for the channel.
|
||||||
*/
|
*/
|
||||||
- (void)setChannelTopic:(NSString *)newTopic;
|
- (void)setChannelTopic:(NSData *)newTopic;
|
||||||
|
|
||||||
/** Sets the mode of the channel.
|
/** Sets the mode of the channel.
|
||||||
*
|
*
|
||||||
@ -90,33 +90,33 @@
|
|||||||
*
|
*
|
||||||
* @param mode the mode to set the channel to
|
* @param mode the mode to set the channel to
|
||||||
*/
|
*/
|
||||||
- (int)setMode:(NSString *)mode params:(NSString *)params;
|
- (int)setMode:(NSData *)mode params:(NSData *)params;
|
||||||
|
|
||||||
/** Sends a public PRIVMSG to the channel. If you try to send more than can fit on an IRC
|
/** Sends a public PRIVMSG to the channel. If you try to send more than can fit on an IRC
|
||||||
buffer, it will be truncated.
|
buffer, it will be truncated.
|
||||||
|
|
||||||
@param message the message to send to the channel.
|
@param message the message to send to the channel.
|
||||||
*/
|
*/
|
||||||
- (int)message:(NSString *)message;
|
- (int)message:(NSData *)message;
|
||||||
|
|
||||||
/** Sends a public CTCP ACTION to the channel.
|
/** Sends a public CTCP ACTION to the channel.
|
||||||
*
|
*
|
||||||
* @param action action to send to the channel.
|
* @param action action to send to the channel.
|
||||||
*/
|
*/
|
||||||
- (int)action:(NSString *)action;
|
- (int)action:(NSData *)action;
|
||||||
|
|
||||||
/** Sends a public NOTICE to the channel.
|
/** Sends a public NOTICE to the channel.
|
||||||
*
|
*
|
||||||
* @param notice message to send to the channel.
|
* @param notice message to send to the channel.
|
||||||
*/
|
*/
|
||||||
- (int)notice:(NSString *)notice;
|
- (int)notice:(NSData *)notice;
|
||||||
|
|
||||||
/** Kicks someone from a channel.
|
/** Kicks someone from a channel.
|
||||||
*
|
*
|
||||||
* @param nick the IRC client to kick from the channel.
|
* @param nick the IRC client to kick from the channel.
|
||||||
* @param reason the message to give to the channel and the IRC client for the kick.
|
* @param reason the message to give to the channel and the IRC client for the kick.
|
||||||
*/
|
*/
|
||||||
- (int)kick:(NSString *)nick reason:(NSString *)reason;
|
- (int)kick:(NSData *)nick reason:(NSData *)reason;
|
||||||
|
|
||||||
/** Sends a CTCP request to the channel.
|
/** Sends a CTCP request to the channel.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -33,7 +33,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@property (readwrite) NSData *topic;
|
@property (readwrite) NSData *topic;
|
||||||
@property (readwrite) NSString *modes;
|
@property (readwrite) NSData *modes;
|
||||||
@property (readwrite) NSMutableArray *nicks;
|
@property (readwrite) NSMutableArray *nicks;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@ -81,8 +81,8 @@
|
|||||||
|
|
||||||
_name = name;
|
_name = name;
|
||||||
_encoding = NSUTF8StringEncoding;
|
_encoding = NSUTF8StringEncoding;
|
||||||
_topic = [NSData dataWithBytes:@"".UTF8String length:1];
|
_topic = [NSData dataWithBytes:"\0" length:1];
|
||||||
_modes = @"";
|
_modes = [NSData dataWithBytes:"\0" length:1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
@ -97,9 +97,9 @@
|
|||||||
return irc_cmd_part(_irc_session, _name.SA_terminatedCString);
|
return irc_cmd_part(_irc_session, _name.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)invite:(NSString *)nick
|
- (int)invite:(NSData *)nick
|
||||||
{
|
{
|
||||||
return irc_cmd_invite(_irc_session, nick.UTF8String, _name.SA_terminatedCString);
|
return irc_cmd_invite(_irc_session, nick.SA_terminatedCString, _name.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)refreshNames
|
- (int)refreshNames
|
||||||
@ -107,39 +107,44 @@
|
|||||||
return irc_cmd_names(_irc_session, _name.SA_terminatedCString);
|
return irc_cmd_names(_irc_session, _name.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setChannelTopic:(NSString *)newTopic
|
- (void)setChannelTopic:(NSData *)newTopic
|
||||||
{
|
{
|
||||||
irc_cmd_topic(_irc_session, _name.SA_terminatedCString, [newTopic cStringUsingEncoding:_encoding]);
|
irc_cmd_topic(_irc_session, _name.SA_terminatedCString, newTopic.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)setMode:(NSString *)mode params:(NSString *)params
|
- (int)setMode:(NSData *)mode params:(NSData *)params
|
||||||
{
|
{
|
||||||
NSMutableString* modeString = [mode mutableCopy];
|
if(params != nil)
|
||||||
|
{
|
||||||
if(params != nil && params.length > 0)
|
NSMutableData *fullModeString = (params != nil) ? [NSMutableData dataWithLength:mode.length + 1 + params.length] : [NSMutableData dataWithLength:mode.length];
|
||||||
[modeString appendFormat:@" %@", params];
|
sprintf(fullModeString.mutableBytes, "%s %s", mode.bytes, params.bytes);
|
||||||
|
|
||||||
return irc_cmd_channel_mode(_irc_session, _name.SA_terminatedCString, modeString.UTF8String);
|
return irc_cmd_channel_mode(_irc_session, _name.SA_terminatedCString, fullModeString.SA_terminatedCString);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return irc_cmd_channel_mode(_irc_session, _name.SA_terminatedCString, mode.SA_terminatedCString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)message:(NSString *)message
|
- (int)message:(NSData *)message
|
||||||
{
|
{
|
||||||
return irc_cmd_msg(_irc_session, _name.SA_terminatedCString, [message cStringUsingEncoding:_encoding]);
|
return irc_cmd_msg(_irc_session, _name.SA_terminatedCString, message.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)action:(NSString *)action
|
- (int)action:(NSData *)action
|
||||||
{
|
{
|
||||||
return irc_cmd_me(_irc_session, _name.SA_terminatedCString, [action cStringUsingEncoding:_encoding]);
|
return irc_cmd_me(_irc_session, _name.SA_terminatedCString, action.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)notice:(NSString *)notice
|
- (int)notice:(NSData *)notice
|
||||||
{
|
{
|
||||||
return irc_cmd_notice(_irc_session, _name.SA_terminatedCString, [notice cStringUsingEncoding:_encoding]);
|
return irc_cmd_notice(_irc_session, _name.SA_terminatedCString, notice.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)kick:(NSString *)nick reason:(NSString *)reason
|
- (int)kick:(NSData *)nick reason:(NSData *)reason
|
||||||
{
|
{
|
||||||
return irc_cmd_kick(_irc_session, nick.UTF8String, _name.SA_terminatedCString, [reason cStringUsingEncoding:_encoding]);
|
return irc_cmd_kick(_irc_session, nick.SA_terminatedCString, _name.SA_terminatedCString, reason.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)ctcpRequest:(NSData *)request
|
- (int)ctcpRequest:(NSData *)request
|
||||||
@ -151,52 +156,46 @@
|
|||||||
#pragma mark - Event handlers
|
#pragma mark - Event handlers
|
||||||
/****************************/
|
/****************************/
|
||||||
|
|
||||||
- (void)userJoined:(NSString *)nick
|
- (void)userJoined:(NSData *)nick
|
||||||
{
|
{
|
||||||
[_delegate userJoined:nick];
|
[_delegate userJoined:nick];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)userParted:(NSString *)nick withReason:(NSData *)reason us:(BOOL)wasItUs
|
- (void)userParted:(NSData *)nick withReason:(NSData *)reason us:(BOOL)wasItUs
|
||||||
{
|
{
|
||||||
NSString* reasonString = [NSString stringWithCString:reason.SA_terminatedCString encoding:_encoding];
|
[_delegate userParted:nick withReason:reason us:wasItUs];
|
||||||
[_delegate userParted:nick withReason:reasonString us:wasItUs];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)modeSet:(NSString *)mode withParams:(NSString *)params by:(NSString *)nick
|
- (void)modeSet:(NSData *)mode withParams:(NSData *)params by:(NSData *)nick
|
||||||
{
|
{
|
||||||
[_delegate modeSet:mode withParams:params by:nick];
|
[_delegate modeSet:mode withParams:params by:nick];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)topicSet:(NSData *)topic by:(NSString *)nick
|
- (void)topicSet:(NSData *)topic by:(NSData *)nick
|
||||||
{
|
{
|
||||||
_topic = topic;
|
_topic = topic;
|
||||||
|
|
||||||
NSString* topicString = [NSString stringWithCString:topic.SA_terminatedCString encoding:_encoding];
|
[_delegate topicSet:topic by:nick];
|
||||||
[_delegate topicSet:topicString by:nick];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)userKicked:(NSString *)nick withReason:(NSData *)reason by:(NSString *)byNick us:(BOOL)wasItUs
|
- (void)userKicked:(NSData *)nick withReason:(NSData *)reason by:(NSData *)byNick us:(BOOL)wasItUs
|
||||||
{
|
{
|
||||||
NSString* reasonString = [NSString stringWithCString:reason.SA_terminatedCString encoding:_encoding];
|
[_delegate userKicked:nick withReason:reason by:byNick us:wasItUs];
|
||||||
[_delegate userKicked:nick withReason:reasonString by:byNick us:wasItUs];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)messageSent:(NSData *)message byUser:(NSString *)nick
|
- (void)messageSent:(NSData *)message byUser:(NSData *)nick
|
||||||
{
|
{
|
||||||
NSString* messageString = [NSString stringWithCString:message.SA_terminatedCString encoding:_encoding];
|
[_delegate messageSent:message byUser:nick];
|
||||||
[_delegate messageSent:messageString byUser:nick];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)noticeSent:(NSData *)notice byUser:(NSString *)nick
|
- (void)noticeSent:(NSData *)notice byUser:(NSData *)nick
|
||||||
{
|
{
|
||||||
NSString* noticeString = [NSString stringWithCString:notice.SA_terminatedCString encoding:_encoding];
|
[_delegate noticeSent:notice byUser:nick];
|
||||||
[_delegate noticeSent:noticeString byUser:nick];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)actionPerformed:(NSData *)action byUser:(NSString *)nick
|
- (void)actionPerformed:(NSData *)action byUser:(NSData *)nick
|
||||||
{
|
{
|
||||||
NSString* actionString = [NSString stringWithCString:action.SA_terminatedCString encoding:_encoding];
|
[_delegate actionPerformed:action byUser:nick];
|
||||||
[_delegate actionPerformed:actionString byUser:nick];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -39,7 +39,7 @@
|
|||||||
*
|
*
|
||||||
* @param nick The nickname of the user that joined the channel.
|
* @param nick The nickname of the user that joined the channel.
|
||||||
*/
|
*/
|
||||||
- (void)userJoined:(NSString *)nick;
|
- (void)userJoined:(NSData *)nick;
|
||||||
|
|
||||||
/** When an IRC client parts a channel you are connect to, you will see
|
/** When an IRC client parts a channel you are connect to, you will see
|
||||||
* an onPart event. You will also see this event when you part a channel.
|
* an onPart event. You will also see this event when you part a channel.
|
||||||
@ -48,7 +48,7 @@
|
|||||||
* @param reason (optional) The reason, if any, that the user gave for leaving.
|
* @param reason (optional) The reason, if any, that the user gave for leaving.
|
||||||
* @param wasItUs (required) Was it us who parted, or another user?
|
* @param wasItUs (required) Was it us who parted, or another user?
|
||||||
*/
|
*/
|
||||||
- (void)userParted:(NSString *)nick withReason:(NSString *)reason us:(BOOL)wasItUs;
|
- (void)userParted:(NSData *)nick withReason:(NSData *)reason us:(BOOL)wasItUs;
|
||||||
|
|
||||||
/** Received when an IRC client changes the channel mode. What modes are available
|
/** Received when an IRC client changes the channel mode. What modes are available
|
||||||
* for a given channel is an implementation detail for each server.
|
* for a given channel is an implementation detail for each server.
|
||||||
@ -57,14 +57,14 @@
|
|||||||
* @param params any parameters with the mode (such as channel key).
|
* @param params any parameters with the mode (such as channel key).
|
||||||
* @param nick the nickname of the IRC client that changed the mode.
|
* @param nick the nickname of the IRC client that changed the mode.
|
||||||
*/
|
*/
|
||||||
- (void)modeSet:(NSString *)mode withParams:(NSString *)params by:(NSString *)nick;
|
- (void)modeSet:(NSData *)mode withParams:(NSData *)params by:(NSData *)nick;
|
||||||
|
|
||||||
/** Received when the topic is changed for the channel.
|
/** Received when the topic is changed for the channel.
|
||||||
*
|
*
|
||||||
* @param aTopic The new topic of the channel.
|
* @param aTopic The new topic of the channel.
|
||||||
* @param nick Nickname of the IRC client that changed the topic.
|
* @param nick Nickname of the IRC client that changed the topic.
|
||||||
*/
|
*/
|
||||||
- (void)topicSet:(NSString *)newTopic by:(NSString *)nick;
|
- (void)topicSet:(NSData *)topic by:(NSData *)nick;
|
||||||
|
|
||||||
/** Received when an IRC client is kicked from a channel.
|
/** Received when an IRC client is kicked from a channel.
|
||||||
*
|
*
|
||||||
@ -73,7 +73,7 @@
|
|||||||
* @param byNick nickname of the client that performed the kick command
|
* @param byNick nickname of the client that performed the kick command
|
||||||
* @param wasItUs Was it us who got kicked, or another user?
|
* @param wasItUs Was it us who got kicked, or another user?
|
||||||
*/
|
*/
|
||||||
- (void)userKicked:(NSString *)nick withReason:(NSString *)reason by:(NSString *)byNick us:(BOOL)wasItUs;
|
- (void)userKicked:(NSData *)nick withReason:(NSData *)reason by:(NSData *)byNick us:(BOOL)wasItUs;
|
||||||
|
|
||||||
/** Received when an IRC client sends a public PRIVMSG to the channel. Note that the
|
/** Received when an IRC client sends a public PRIVMSG to the channel. Note that the
|
||||||
* user may not necessarily be required to be on the channel to send a message
|
* user may not necessarily be required to be on the channel to send a message
|
||||||
@ -82,7 +82,7 @@
|
|||||||
* @param message the message sent to the channel.
|
* @param message the message sent to the channel.
|
||||||
* @param nick the nickname of the IRC client that sent the message.
|
* @param nick the nickname of the IRC client that sent the message.
|
||||||
*/
|
*/
|
||||||
- (void)messageSent:(NSString *)message byUser:(NSString *)nick;
|
- (void)messageSent:(NSData *)message byUser:(NSData *)nick;
|
||||||
|
|
||||||
/** Received when an IRC client sends a public NOTICE to the channel. Note that
|
/** Received when an IRC client sends a public NOTICE to the channel. Note that
|
||||||
* the user may not necessarily be required to be on the channel to send a notice to
|
* the user may not necessarily be required to be on the channel to send a notice to
|
||||||
@ -92,13 +92,13 @@
|
|||||||
* @param notice the notice sent to the channel.
|
* @param notice the notice sent to the channel.
|
||||||
* @param nick the nickname of the IRC client that sent the notice.
|
* @param nick the nickname of the IRC client that sent the notice.
|
||||||
*/
|
*/
|
||||||
- (void)noticeSent:(NSString *)notice byUser:(NSString *)nick;
|
- (void)noticeSent:(NSData *)notice byUser:(NSData *)nick;
|
||||||
|
|
||||||
/** Received when an IRC client sends a CTCP ACTION message to the channel.
|
/** Received when an IRC client sends a CTCP ACTION message to the channel.
|
||||||
*
|
*
|
||||||
* @param action the action message sent to the channel.
|
* @param action the action message sent to the channel.
|
||||||
* @param nick the nickname of the IRC client that sent the message.
|
* @param nick the nickname of the IRC client that sent the message.
|
||||||
*/
|
*/
|
||||||
- (void)actionPerformed:(NSString *)action byUser:(NSString *)nick;
|
- (void)actionPerformed:(NSData *)action byUser:(NSData *)nick;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -40,20 +40,20 @@
|
|||||||
* in files that make use of the IRCClientChannel class.
|
* in files that make use of the IRCClientChannel class.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
- (void)userJoined:(NSString *)nick;
|
- (void)userJoined:(NSData *)nick;
|
||||||
|
|
||||||
- (void)userParted:(NSString *)nick withReason:(NSData *)reason us:(BOOL)wasItUs;
|
- (void)userParted:(NSData *)nick withReason:(NSData *)reason us:(BOOL)wasItUs;
|
||||||
|
|
||||||
- (void)modeSet:(NSString *)mode withParams:(NSString *)params by:(NSString *)nick;
|
- (void)modeSet:(NSData *)mode withParams:(NSData *)params by:(NSData *)nick;
|
||||||
|
|
||||||
- (void)topicSet:(NSData *)newTopic by:(NSString *)nick;
|
- (void)topicSet:(NSData *)newTopic by:(NSData *)nick;
|
||||||
|
|
||||||
- (void)userKicked:(NSString *)nick withReason:(NSData *)reason by:(NSString *)byNick us:(BOOL)wasItUs;
|
- (void)userKicked:(NSData *)nick withReason:(NSData *)reason by:(NSData *)byNick us:(BOOL)wasItUs;
|
||||||
|
|
||||||
- (void)messageSent:(NSData *)message byUser:(NSString *)nick;
|
- (void)messageSent:(NSData *)message byUser:(NSData *)nick;
|
||||||
|
|
||||||
- (void)noticeSent:(NSData *)notice byUser:(NSString *)nick;
|
- (void)noticeSent:(NSData *)notice byUser:(NSData *)nick;
|
||||||
|
|
||||||
- (void)actionPerformed:(NSData *)action byUser:(NSString *)nick;
|
- (void)actionPerformed:(NSData *)action byUser:(NSData *)nick;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -91,10 +91,10 @@
|
|||||||
@property (assign) NSUInteger sessionID;
|
@property (assign) NSUInteger sessionID;
|
||||||
|
|
||||||
/** The version string for the client to send back on CTCP VERSION requests */
|
/** The version string for the client to send back on CTCP VERSION requests */
|
||||||
@property (copy) NSString *version;
|
@property (copy) NSData *version;
|
||||||
|
|
||||||
/** IRC server to connect to */
|
/** IRC server to connect to */
|
||||||
@property (copy) NSString *server;
|
@property (copy) NSData *server;
|
||||||
|
|
||||||
/** IRC port to connect to */
|
/** IRC port to connect to */
|
||||||
@property (assign) NSUInteger port;
|
@property (assign) NSUInteger port;
|
||||||
@ -104,17 +104,17 @@
|
|||||||
|
|
||||||
/** Nickname of the connected client.
|
/** Nickname of the connected client.
|
||||||
*/
|
*/
|
||||||
@property (readonly) NSString *nickname;
|
@property (readonly) NSData *nickname;
|
||||||
|
|
||||||
/** Username of the connected client. Also known as the ident.
|
/** Username of the connected client. Also known as the ident.
|
||||||
*/
|
*/
|
||||||
@property (readonly) NSString *username;
|
@property (readonly) NSData *username;
|
||||||
|
|
||||||
/** Realname of the connected client.
|
/** Realname of the connected client.
|
||||||
*/
|
*/
|
||||||
@property (readonly) NSString *realname;
|
@property (readonly) NSData *realname;
|
||||||
|
|
||||||
/** The default text encoding for messages on this server.
|
/** The suggested text encoding for messages on this server.
|
||||||
|
|
||||||
This concerns messages received via PRIVMSG and NOTICE, and TOPIC in a channel.
|
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.
|
It also affects what encoding reasons given for QUIT messages are assumed to be in.
|
||||||
@ -155,7 +155,7 @@
|
|||||||
already connected; use the nick: method to attempt a nick change while
|
already connected; use the nick: method to attempt a nick change while
|
||||||
connected.)
|
connected.)
|
||||||
*/
|
*/
|
||||||
-(int)setNickname:(NSString *)nickname username:(NSString *)username realname:(NSString *)realname;
|
-(int)setNickname:(NSData *)nickname username:(NSData *)username realname:(NSData *)realname;
|
||||||
|
|
||||||
/** Connect to the IRC server.
|
/** Connect to the IRC server.
|
||||||
|
|
||||||
@ -216,7 +216,7 @@
|
|||||||
|
|
||||||
@param mode string to set
|
@param mode string to set
|
||||||
*/
|
*/
|
||||||
- (int)userMode:(NSString *)mode;
|
- (int)userMode:(NSData *)mode;
|
||||||
|
|
||||||
/** sets the IRC client nickname.
|
/** sets the IRC client nickname.
|
||||||
|
|
||||||
@ -226,53 +226,53 @@
|
|||||||
|
|
||||||
@param newnick new nickname to set.
|
@param newnick new nickname to set.
|
||||||
*/
|
*/
|
||||||
- (int)nick:(NSString *)newnick;
|
- (int)nick:(NSData *)newnick;
|
||||||
|
|
||||||
/** sends a WHOIS request to the IRC server
|
/** sends a WHOIS request to the IRC server
|
||||||
|
|
||||||
@param nick nickname of the irc client to whois.
|
@param nick nickname of the irc client to whois.
|
||||||
*/
|
*/
|
||||||
- (int)whois:(NSString *)nick;
|
- (int)whois:(NSData *)nick;
|
||||||
|
|
||||||
/** send a PRIVMSG to another IRC client
|
/** send a PRIVMSG to another IRC client
|
||||||
|
|
||||||
@param message message to send
|
@param message message to send
|
||||||
@param target the other IRC client to send the message to.
|
@param target the other IRC client to send the message to.
|
||||||
*/
|
*/
|
||||||
- (int)message:(NSData *)message to:(NSString *)target;
|
- (int)message:(NSData *)message to:(NSData *)target;
|
||||||
|
|
||||||
/** send a CTCP ACTION to another IRC client
|
/** send a CTCP ACTION to another IRC client
|
||||||
|
|
||||||
@param action the action message to send
|
@param action the action message to send
|
||||||
@param target the nickname of the irc client to send the message to.
|
@param target the nickname of the irc client to send the message to.
|
||||||
*/
|
*/
|
||||||
- (int)action:(NSData *)action to:(NSString *)target;
|
- (int)action:(NSData *)action to:(NSData *)target;
|
||||||
|
|
||||||
/** send a NOTICE to another IRC client
|
/** send a NOTICE to another IRC client
|
||||||
|
|
||||||
@param notice the message text to send
|
@param notice the message text to send
|
||||||
@param target the nickname of the irc client to send the notice to.
|
@param target the nickname of the irc client to send the notice to.
|
||||||
*/
|
*/
|
||||||
- (int)notice:(NSData *)notice to:(NSString *)target;
|
- (int)notice:(NSData *)notice to:(NSData *)target;
|
||||||
|
|
||||||
/** send a CTCP request to another IRC client
|
/** send a CTCP request to another IRC client
|
||||||
|
|
||||||
@param request the CTCP request string to send
|
@param request the CTCP request string to send
|
||||||
@param target the nickname of the IRC client to send the request to.
|
@param target the nickname of the IRC client to send the request to.
|
||||||
*/
|
*/
|
||||||
- (int)ctcpRequest:(NSData *)request target:(NSString *)target;
|
- (int)ctcpRequest:(NSData *)request target:(NSData *)target;
|
||||||
|
|
||||||
/** send a CTCP reply to another IRC client
|
/** send a CTCP reply to another IRC client
|
||||||
|
|
||||||
@param reply the CTCP reply string to send
|
@param reply the CTCP reply string to send
|
||||||
@param target the nickname of the IRC client to send the reply to.
|
@param target the nickname of the IRC client to send the reply to.
|
||||||
*/
|
*/
|
||||||
- (int)ctcpReply:(NSData *)reply target:(NSString *)target;
|
- (int)ctcpReply:(NSData *)reply target:(NSData *)target;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NSString* getNickFromNickUserHost(NSString *nuh);
|
NSData* getNickFromNickUserHost(NSData *nuh);
|
||||||
|
|
||||||
NSString* getUserFromNickUserHost(NSString *nuh);
|
NSData* getUserFromNickUserHost(NSData *nuh);
|
||||||
|
|
||||||
NSString* getHostFromNickUserHost(NSString *nuh);
|
NSData* getHostFromNickUserHost(NSData *nuh);
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#pragma mark Defines and includes
|
#pragma mark Defines and includes
|
||||||
|
|
||||||
#define IRCCLIENTVERSION "2.0a2"
|
#define IRCCLIENTVERSION "2.0a3"
|
||||||
|
|
||||||
#import "IRCClientSession.h"
|
#import "IRCClientSession.h"
|
||||||
#import "IRCClientChannel.h"
|
#import "IRCClientChannel.h"
|
||||||
@ -77,7 +77,6 @@ static NSDictionary* ircNumericCodeList;
|
|||||||
|
|
||||||
@synthesize delegate = _delegate;
|
@synthesize delegate = _delegate;
|
||||||
@synthesize sessionID = _sessionID;
|
@synthesize sessionID = _sessionID;
|
||||||
|
|
||||||
@synthesize version = _version;
|
@synthesize version = _version;
|
||||||
|
|
||||||
@synthesize server = _server;
|
@synthesize server = _server;
|
||||||
@ -150,14 +149,15 @@ static NSDictionary* ircNumericCodeList;
|
|||||||
// irc_option_set(_irc_session, LIBIRC_OPTION_STRIPNICKS);
|
// irc_option_set(_irc_session, LIBIRC_OPTION_STRIPNICKS);
|
||||||
|
|
||||||
// Set debug mode.
|
// Set debug mode.
|
||||||
irc_option_set(_irc_session, LIBIRC_OPTION_DEBUG);
|
// irc_option_set(_irc_session, LIBIRC_OPTION_DEBUG);
|
||||||
|
|
||||||
irc_set_ctx(_irc_session, (__bridge void *)(self));
|
irc_set_ctx(_irc_session, (__bridge void *)(self));
|
||||||
|
|
||||||
unsigned int high, low;
|
unsigned int high, low;
|
||||||
irc_get_version (&high, &low);
|
irc_get_version (&high, &low);
|
||||||
|
|
||||||
_version = [NSString stringWithFormat:@"IRCClient Framework v%s (Said Achmiz) - libirc v%d.%d (George Yunaev)", IRCCLIENTVERSION, high, low];
|
NSString* versionString = [NSString stringWithFormat:@"IRCClient Framework v%s (Said Achmiz) - libirc v%d.%d (George Yunaev)", IRCCLIENTVERSION, high, low];
|
||||||
|
_version = [NSData dataWithBytes:versionString.UTF8String length:versionString.length];
|
||||||
|
|
||||||
_channels = [[NSMutableDictionary alloc] init];
|
_channels = [[NSMutableDictionary alloc] init];
|
||||||
_encoding = NSUTF8StringEncoding;
|
_encoding = NSUTF8StringEncoding;
|
||||||
@ -200,7 +200,7 @@ static NSDictionary* ircNumericCodeList;
|
|||||||
|
|
||||||
- (int)connect;
|
- (int)connect;
|
||||||
{
|
{
|
||||||
return irc_connect(_irc_session, _server.UTF8String, (unsigned short) _port, (_password.length > 0 ? _password.SA_terminatedCString : NULL), _nickname.UTF8String, _username.UTF8String, _realname.UTF8String);
|
return irc_connect(_irc_session, _server.SA_terminatedCString, (unsigned short) _port, (_password.length > 0 ? _password.SA_terminatedCString : NULL), _nickname.SA_terminatedCString, _username.SA_terminatedCString, _realname.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)disconnect
|
- (void)disconnect
|
||||||
@ -226,7 +226,7 @@ static NSDictionary* ircNumericCodeList;
|
|||||||
[_thread start];
|
[_thread start];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(int)setNickname:(NSString *)nickname username:(NSString *)username realname:(NSString *)realname
|
-(int)setNickname:(NSData *)nickname username:(NSData *)username realname:(NSData *)realname
|
||||||
{
|
{
|
||||||
if(self.isConnected)
|
if(self.isConnected)
|
||||||
{
|
{
|
||||||
@ -234,9 +234,9 @@ static NSDictionary* ircNumericCodeList;
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_nickname = nickname;
|
_nickname = nickname.SA_dataWithTerminatedCString;
|
||||||
_username = username;
|
_username = username.SA_dataWithTerminatedCString;
|
||||||
_realname = realname;
|
_realname = realname.SA_dataWithTerminatedCString;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -258,10 +258,10 @@ static NSDictionary* ircNumericCodeList;
|
|||||||
|
|
||||||
- (int)join:(NSData *)channel key:(NSData *)key
|
- (int)join:(NSData *)channel key:(NSData *)key
|
||||||
{
|
{
|
||||||
NSLog(@"Joining %@", channel);
|
|
||||||
|
|
||||||
if (!key || !key.length > 0)
|
if (!key || !key.length > 0)
|
||||||
|
{
|
||||||
return irc_cmd_join(_irc_session, channel.SA_terminatedCString, NULL);
|
return irc_cmd_join(_irc_session, channel.SA_terminatedCString, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
return irc_cmd_join(_irc_session, channel.SA_terminatedCString, key.SA_terminatedCString);
|
return irc_cmd_join(_irc_session, channel.SA_terminatedCString, key.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
@ -271,44 +271,44 @@ static NSDictionary* ircNumericCodeList;
|
|||||||
return irc_cmd_list(_irc_session, channel.SA_terminatedCString);
|
return irc_cmd_list(_irc_session, channel.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)userMode:(NSString *)mode
|
- (int)userMode:(NSData *)mode
|
||||||
{
|
{
|
||||||
return irc_cmd_user_mode(_irc_session, mode.UTF8String);
|
return irc_cmd_user_mode(_irc_session, mode.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)nick:(NSString *)newnick
|
- (int)nick:(NSData *)newnick
|
||||||
{
|
{
|
||||||
return irc_cmd_nick(_irc_session, newnick.UTF8String);
|
return irc_cmd_nick(_irc_session, newnick.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)whois:(NSString *)nick
|
- (int)whois:(NSData *)nick
|
||||||
{
|
{
|
||||||
return irc_cmd_whois(_irc_session, nick.UTF8String);
|
return irc_cmd_whois(_irc_session, nick.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)message:(NSData *)message to:(NSString *)target
|
- (int)message:(NSData *)message to:(NSData *)target
|
||||||
{
|
{
|
||||||
return irc_cmd_msg(_irc_session, target.UTF8String, message.SA_terminatedCString);
|
return irc_cmd_msg(_irc_session, target.SA_terminatedCString, message.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)action:(NSData *)action to:(NSString *)target
|
- (int)action:(NSData *)action to:(NSData *)target
|
||||||
{
|
{
|
||||||
return irc_cmd_me(_irc_session, target.UTF8String, action.SA_terminatedCString);
|
return irc_cmd_me(_irc_session, target.SA_terminatedCString, action.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)notice:(NSData *)notice to:(NSString *)target
|
- (int)notice:(NSData *)notice to:(NSData *)target
|
||||||
{
|
{
|
||||||
return irc_cmd_notice(_irc_session, target.UTF8String, notice.SA_terminatedCString);
|
return irc_cmd_notice(_irc_session, target.SA_terminatedCString, notice.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)ctcpRequest:(NSData *)request target:(NSString *)target
|
- (int)ctcpRequest:(NSData *)request target:(NSData *)target
|
||||||
{
|
{
|
||||||
return irc_cmd_ctcp_request(_irc_session, target.UTF8String, request.SA_terminatedCString);
|
return irc_cmd_ctcp_request(_irc_session, target.SA_terminatedCString, request.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)ctcpReply:(NSData *)reply target:(NSString *)target
|
- (int)ctcpReply:(NSData *)reply target:(NSData *)target
|
||||||
{
|
{
|
||||||
return irc_cmd_ctcp_reply(_irc_session, target.UTF8String, reply.SA_terminatedCString);
|
return irc_cmd_ctcp_reply(_irc_session, target.SA_terminatedCString, reply.SA_terminatedCString);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************/
|
/****************************/
|
||||||
@ -320,9 +320,9 @@ static NSDictionary* ircNumericCodeList;
|
|||||||
[_delegate connectionSucceeded];
|
[_delegate connectionSucceeded];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)nickChangedFrom:(NSString *)oldNick to:(NSString *)newNick
|
- (void)nickChangedFrom:(NSData *)oldNick to:(NSData *)newNick
|
||||||
{
|
{
|
||||||
if ([_nickname isEqualToString:oldNick])
|
if ([_nickname isEqualToData:oldNick])
|
||||||
{
|
{
|
||||||
_nickname = newNick;
|
_nickname = newNick;
|
||||||
[_delegate nickChangedFrom:oldNick to:newNick own:YES];
|
[_delegate nickChangedFrom:oldNick to:newNick own:YES];
|
||||||
@ -333,23 +333,16 @@ static NSDictionary* ircNumericCodeList;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)userQuit:(NSString *)nick withReason:(NSData *)reason
|
- (void)userQuit:(NSData *)nick withReason:(NSData *)reason
|
||||||
{
|
{
|
||||||
NSString* reasonString;
|
[_delegate userQuit:nick withReason:reason];
|
||||||
|
|
||||||
if(reason)
|
|
||||||
{
|
|
||||||
reasonString = [NSString stringWithCString:reason.SA_terminatedCString encoding:_encoding];
|
|
||||||
}
|
|
||||||
|
|
||||||
[_delegate userQuit:nick withReason:reasonString];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)userJoined:(NSString *)nick channel:(NSData *)channelName
|
- (void)userJoined:(NSData *)nick channel:(NSData *)channelName
|
||||||
{
|
{
|
||||||
NSString* nickOnly = getNickFromNickUserHost(nick);
|
NSData* nickOnly = getNickFromNickUserHost(nick);
|
||||||
|
|
||||||
if ([_nickname isEqualToString:nickOnly])
|
if ([_nickname isEqualToData:nickOnly])
|
||||||
{
|
{
|
||||||
// We just joined a channel; allocate an IRCClientChannel object and send it
|
// We just joined a channel; allocate an IRCClientChannel object and send it
|
||||||
// to the main thread.
|
// to the main thread.
|
||||||
@ -367,13 +360,13 @@ static NSDictionary* ircNumericCodeList;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)userParted:(NSString *)nick channel:(NSData *)channelName withReason:(NSData *)reason
|
- (void)userParted:(NSData *)nick channel:(NSData *)channelName withReason:(NSData *)reason
|
||||||
{
|
{
|
||||||
IRCClientChannel* channel = _channels[channelName];
|
IRCClientChannel* channel = _channels[channelName];
|
||||||
|
|
||||||
NSString* nickOnly = getNickFromNickUserHost(nick);
|
NSData* nickOnly = getNickFromNickUserHost(nick);
|
||||||
|
|
||||||
if ([_nickname isEqualToString:nickOnly])
|
if ([_nickname isEqualToData:nickOnly])
|
||||||
{
|
{
|
||||||
// We just left a channel; remove it from the channels dict.
|
// We just left a channel; remove it from the channels dict.
|
||||||
[_channels removeObjectForKey:channelName];
|
[_channels removeObjectForKey:channelName];
|
||||||
@ -385,26 +378,26 @@ static NSDictionary* ircNumericCodeList;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)modeSet:(NSString* )mode withParams:(NSString *)params forChannel:(NSData *)channelName by:(NSString *)nick
|
- (void)modeSet:(NSData* )mode withParams:(NSData *)params forChannel:(NSData *)channelName by:(NSData *)nick
|
||||||
{
|
{
|
||||||
IRCClientChannel *channel = _channels[channelName];
|
IRCClientChannel *channel = _channels[channelName];
|
||||||
|
|
||||||
[channel modeSet:mode withParams:params by:nick];
|
[channel modeSet:mode withParams:params by:nick];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)modeSet:(NSString *)mode by:(NSString *)nick
|
- (void)modeSet:(NSData *)mode by:(NSData *)nick
|
||||||
{
|
{
|
||||||
[_delegate modeSet:mode by:nick];
|
[_delegate modeSet:mode by:nick];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)topicSet:(NSData *)newTopic forChannel:(NSData *)channelName by:(NSString *)nick
|
- (void)topicSet:(NSData *)newTopic forChannel:(NSData *)channelName by:(NSData *)nick
|
||||||
{
|
{
|
||||||
IRCClientChannel *channel = _channels[channelName];
|
IRCClientChannel *channel = _channels[channelName];
|
||||||
|
|
||||||
[channel topicSet:newTopic by:nick];
|
[channel topicSet:newTopic by:nick];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)userKicked:(NSString *)nick fromChannel:(NSData *)channelName by:(NSString *)byNick withReason:(NSData *)reason
|
- (void)userKicked:(NSData *)nick fromChannel:(NSData *)channelName by:(NSData *)byNick withReason:(NSData *)reason
|
||||||
{
|
{
|
||||||
IRCClientChannel* channel = _channels[channelName];
|
IRCClientChannel* channel = _channels[channelName];
|
||||||
|
|
||||||
@ -421,53 +414,49 @@ static NSDictionary* ircNumericCodeList;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)messageSent:(NSData *)message toChannel:(NSData *)channelName byUser:(NSString *)nick
|
- (void)messageSent:(NSData *)message toChannel:(NSData *)channelName byUser:(NSData *)nick
|
||||||
{
|
{
|
||||||
IRCClientChannel *channel = _channels[channelName];
|
IRCClientChannel *channel = _channels[channelName];
|
||||||
|
|
||||||
[channel messageSent:message byUser:nick];
|
[channel messageSent:message byUser:nick];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)privateMessageReceived:(NSData *)message fromUser:(NSString *)nick
|
- (void)privateMessageReceived:(NSData *)message fromUser:(NSData *)nick
|
||||||
{
|
{
|
||||||
NSString* messageString = [NSString stringWithCString:message.SA_terminatedCString encoding:_encoding];
|
[_delegate privateMessageReceived:message fromUser:nick];
|
||||||
|
|
||||||
[_delegate privateMessageReceived:messageString fromUser:nick];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)serverMessageReceivedFrom:(NSString *)origin params:(NSArray *)params
|
- (void)serverMessageReceivedFrom:(NSData *)origin params:(NSArray *)params
|
||||||
{
|
{
|
||||||
[_delegate serverMessageReceivedFrom:origin params:params];
|
[_delegate serverMessageReceivedFrom:origin params:params];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)privateNoticeReceived:(NSData *)notice fromUser:(NSString *)nick
|
- (void)privateNoticeReceived:(NSData *)notice fromUser:(NSData *)nick
|
||||||
{
|
{
|
||||||
NSString* noticeString = [NSString stringWithCString:notice.SA_terminatedCString encoding:_encoding];
|
[_delegate privateNoticeReceived:notice fromUser:nick];
|
||||||
|
|
||||||
[_delegate privateNoticeReceived:noticeString fromUser:nick];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)noticeSent:(NSData *)notice toChannel:(NSData *)channelName byUser:(NSString *)nick
|
- (void)noticeSent:(NSData *)notice toChannel:(NSData *)channelName byUser:(NSData *)nick
|
||||||
{
|
{
|
||||||
IRCClientChannel *channel = _channels[channelName];
|
IRCClientChannel *channel = _channels[channelName];
|
||||||
|
|
||||||
[channel noticeSent:notice byUser:nick];
|
[channel noticeSent:notice byUser:nick];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)serverNoticeReceivedFrom:(NSString *)origin params:(NSArray *)params
|
- (void)serverNoticeReceivedFrom:(NSData *)origin params:(NSArray *)params
|
||||||
{
|
{
|
||||||
[_delegate serverNoticeReceivedFrom:origin params:params];
|
[_delegate serverNoticeReceivedFrom:origin params:params];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)invitedToChannel:(NSData *)channelName by:(NSString *)nick
|
- (void)invitedToChannel:(NSData *)channelName by:(NSData *)nick
|
||||||
{
|
{
|
||||||
[_delegate invitedToChannel:channelName.SA_dataWithTerminatedCString by:nick];
|
[_delegate invitedToChannel:channelName by:nick];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)CTCPRequestReceived:(NSData *)request fromUser:(NSString *)nick
|
- (void)CTCPRequestReceived:(NSData *)request fromUser:(NSData *)nick
|
||||||
{
|
{
|
||||||
const char* the_nick = getNickFromNickUserHost(nick).UTF8String;
|
const char* the_nick = getNickFromNickUserHost(nick).bytes;
|
||||||
const char* the_request = request.SA_terminatedCString;
|
const char* the_request = request.bytes;
|
||||||
|
|
||||||
if (strstr(the_request, "PING") == the_request)
|
if (strstr(the_request, "PING") == the_request)
|
||||||
{
|
{
|
||||||
@ -475,11 +464,17 @@ static NSDictionary* ircNumericCodeList;
|
|||||||
}
|
}
|
||||||
else if (!strcmp (the_request, "VERSION"))
|
else if (!strcmp (the_request, "VERSION"))
|
||||||
{
|
{
|
||||||
irc_cmd_ctcp_reply (_irc_session, the_nick, [[NSString stringWithFormat:@"VERSION %@", _version] cStringUsingEncoding:_encoding]);
|
NSMutableData* versionReply = [NSMutableData dataWithLength:8 + _version.length];
|
||||||
|
sprintf(versionReply.mutableBytes, "VERSION %s", _version.bytes);
|
||||||
|
|
||||||
|
irc_cmd_ctcp_reply (_irc_session, the_nick, versionReply.bytes);
|
||||||
}
|
}
|
||||||
else if (!strcmp (the_request, "FINGER"))
|
else if (!strcmp (the_request, "FINGER"))
|
||||||
{
|
{
|
||||||
irc_cmd_ctcp_reply (_irc_session, the_nick, [[NSString stringWithFormat:@"FINGER %@ (%@) Idle 0 seconds", _username, _realname] cStringUsingEncoding:_encoding]);
|
NSMutableData* fingerReply = [NSMutableData dataWithLength:25 + _username.length + _realname.length];
|
||||||
|
sprintf(fingerReply.mutableBytes, "FINGER %s (%s) Idle 0 seconds)", _username.bytes, _realname.bytes);
|
||||||
|
|
||||||
|
irc_cmd_ctcp_reply (_irc_session, the_nick, fingerReply.bytes);
|
||||||
}
|
}
|
||||||
else if (!strcmp (the_request, "TIME"))
|
else if (!strcmp (the_request, "TIME"))
|
||||||
{
|
{
|
||||||
@ -498,19 +493,19 @@ static NSDictionary* ircNumericCodeList;
|
|||||||
NSData* requestTypeData = [NSData dataWithBytes:request_body length:strlen(request_body) + 1];
|
NSData* requestTypeData = [NSData dataWithBytes:request_body length:strlen(request_body) + 1];
|
||||||
NSData* requestBodyData = [NSData dataWithBytes:request_type length:strlen(request_type) + 1];
|
NSData* requestBodyData = [NSData dataWithBytes:request_type length:strlen(request_type) + 1];
|
||||||
|
|
||||||
[_delegate CTCPRequestReceived:requestBodyData.SA_dataWithTerminatedCString ofType:requestTypeData.SA_dataWithTerminatedCString fromUser:nick];
|
[_delegate CTCPRequestReceived:requestBodyData ofType:requestTypeData fromUser:nick];
|
||||||
|
|
||||||
free(request_string);
|
free(request_string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)CTCPReplyReceived:(NSData *)reply fromUser:(NSString *)nick
|
- (void)CTCPReplyReceived:(NSData *)reply fromUser:(NSData *)nick
|
||||||
{
|
{
|
||||||
[_delegate CTCPReplyReceived:reply.SA_dataWithTerminatedCString fromUser:nick];
|
[_delegate CTCPReplyReceived:reply fromUser:nick];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)CTCPActionPerformed:(NSData *)action byUser:(NSString *)nick atTarget:(NSData *)target
|
- (void)CTCPActionPerformed:(NSData *)action byUser:(NSData *)nick atTarget:(NSData *)target
|
||||||
{
|
{
|
||||||
IRCClientChannel* channel = _channels[target];
|
IRCClientChannel* channel = _channels[target];
|
||||||
|
|
||||||
@ -522,65 +517,72 @@ static NSDictionary* ircNumericCodeList;
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// An action in a private message
|
// An action in a private message
|
||||||
NSString* actionString = [NSString stringWithCString:action.SA_terminatedCString encoding:_encoding];
|
[_delegate privateCTCPActionReceived:action fromUser:nick];
|
||||||
[_delegate privateCTCPActionReceived:actionString fromUser:nick];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)unknownEventReceived:(NSData *)event from:(NSString *)origin params:(NSArray *)params
|
- (void)unknownEventReceived:(NSData *)event from:(NSData *)origin params:(NSArray *)params
|
||||||
{
|
{
|
||||||
[_delegate unknownEventReceived:event.SA_dataWithTerminatedCString from:origin params:params];
|
[_delegate unknownEventReceived:event from:origin params:params];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)numericEventReceived:(NSUInteger)event from:(NSString *)origin params:(NSArray *)params
|
-(void)numericEventReceived:(NSUInteger)event from:(NSData *)origin params:(NSArray *)params
|
||||||
{
|
{
|
||||||
[_delegate numericEventReceived:event from:origin params:params];
|
[_delegate numericEventReceived:event from:origin params:params];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
/*************************************/
|
||||||
#pragma mark - Useful helper functions
|
#pragma mark - Useful helper functions
|
||||||
|
/*************************************/
|
||||||
|
|
||||||
NSString* getNickFromNickUserHost(NSString *nuh)
|
NSData* getNickFromNickUserHost(NSData *nuh)
|
||||||
{
|
{
|
||||||
NSArray *nuhArray = [nuh componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"!@"]];
|
char* nick_user_host_buf = malloc(nuh.length);
|
||||||
|
[nuh getBytes:nick_user_host_buf];
|
||||||
|
|
||||||
if (nuhArray.count == 3)
|
char *nick_buf;
|
||||||
{
|
nick_buf = strtok(nick_user_host_buf, "!@");
|
||||||
return [NSString stringWithString:nuhArray[0]];
|
|
||||||
}
|
NSData* nick = (nick_buf != NULL) ? [NSData dataWithBytes:nick_buf length:strlen(nick_buf) + 1] : nil;
|
||||||
else
|
|
||||||
{
|
free(nick_user_host_buf);
|
||||||
return [NSString stringWithString:nuh];
|
|
||||||
}
|
return nick;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString* getUserFromNickUserHost(NSString *nuh)
|
NSData* getUserFromNickUserHost(NSData *nuh)
|
||||||
{
|
{
|
||||||
NSArray *nuhArray = [nuh componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"!@"]];
|
char* nick_user_host_buf = malloc(nuh.length);
|
||||||
|
[nuh getBytes:nick_user_host_buf];
|
||||||
|
|
||||||
if (nuhArray.count == 3)
|
char *nick_buf, *user_buf;
|
||||||
{
|
nick_buf = strtok(nick_user_host_buf, "!@");
|
||||||
return [NSString stringWithString:nuhArray[1]];
|
user_buf = strtok(NULL, "!@");
|
||||||
}
|
|
||||||
else
|
NSData* user = (user_buf != NULL) ? [NSData dataWithBytes:user_buf length:strlen(user_buf) + 1] : nil;
|
||||||
{
|
|
||||||
return nil;
|
free(nick_user_host_buf);
|
||||||
}
|
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString* getHostFromNickUserHost(NSString *nuh)
|
NSData* getHostFromNickUserHost(NSData *nuh)
|
||||||
{
|
{
|
||||||
NSArray *nuhArray = [nuh componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"!@"]];
|
char* nick_user_host_buf = malloc(nuh.length);
|
||||||
|
[nuh getBytes:nick_user_host_buf];
|
||||||
|
|
||||||
if (nuhArray.count == 3)
|
char *nick_buf, *user_buf, *host_buf;
|
||||||
{
|
nick_buf = strtok(nick_user_host_buf, "!@");
|
||||||
return [NSString stringWithString:nuhArray[2]];
|
user_buf = strtok(NULL, "!@");
|
||||||
}
|
host_buf = strtok(NULL, "!@");
|
||||||
else
|
|
||||||
{
|
NSData* host = (host_buf != NULL) ? [NSData dataWithBytes:host_buf length:strlen(host_buf) + 1] : nil;
|
||||||
return nil;
|
|
||||||
}
|
free(nick_user_host_buf);
|
||||||
|
|
||||||
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************/
|
/***********************************************/
|
||||||
@ -594,7 +596,7 @@ NSString* getHostFromNickUserHost(NSString *nuh)
|
|||||||
*/
|
*/
|
||||||
static void onConnect(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onConnect(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);
|
||||||
|
|
||||||
[clientSession connectionSucceeded];
|
[clientSession connectionSucceeded];
|
||||||
}
|
}
|
||||||
@ -609,9 +611,10 @@ static void onConnect(irc_session_t *session, const char *event, const char *ori
|
|||||||
*/
|
*/
|
||||||
static void onNick(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onNick(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);
|
||||||
NSString *oldNick = @(origin);
|
|
||||||
NSString *newNick = @(params[0]);
|
NSData *oldNick = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
|
NSData *newNick = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
||||||
|
|
||||||
[clientSession nickChangedFrom:oldNick to:newNick];
|
[clientSession nickChangedFrom:oldNick to:newNick];
|
||||||
}
|
}
|
||||||
@ -626,17 +629,9 @@ static void onNick(irc_session_t *session, const char *event, const char *origin
|
|||||||
static void onQuit(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onQuit(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);
|
||||||
NSString *nick = @(origin);
|
|
||||||
|
|
||||||
NSData *reason = nil;
|
NSData *nick = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
if(count > 0)
|
NSData *reason = (count > 0) ? [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1] : [NSData dataWithBytes:"\0" length:1];
|
||||||
{
|
|
||||||
reason = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
reason = [NSData dataWithBytes:"\0" length:1];
|
|
||||||
}
|
|
||||||
|
|
||||||
[clientSession userQuit:nick withReason:reason];
|
[clientSession userQuit:nick withReason:reason];
|
||||||
}
|
}
|
||||||
@ -652,8 +647,9 @@ static void onQuit(irc_session_t *session, const char *event, const char *origin
|
|||||||
*/
|
*/
|
||||||
static void onJoinChannel(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onJoinChannel(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);
|
||||||
NSString *nick = @(origin);
|
|
||||||
|
NSData *nick = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
||||||
|
|
||||||
[clientSession userJoined:nick channel:channelName];
|
[clientSession userJoined:nick channel:channelName];
|
||||||
@ -672,18 +668,10 @@ static void onJoinChannel(irc_session_t *session, const char *event, const char
|
|||||||
static void onPartChannel(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onPartChannel(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);
|
||||||
NSString *nick = @(origin);
|
|
||||||
|
NSData *nick = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
||||||
|
NSData *reason = (count > 1) ? [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1] : [NSData dataWithBytes:"\0" length:1];
|
||||||
NSData *reason = nil;
|
|
||||||
if (count > 1)
|
|
||||||
{
|
|
||||||
reason = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
reason = [NSData dataWithBytes:"\0" length:1];
|
|
||||||
}
|
|
||||||
|
|
||||||
[clientSession userParted:nick channel:channelName withReason:reason];
|
[clientSession userParted:nick channel:channelName withReason:reason];
|
||||||
}
|
}
|
||||||
@ -704,19 +692,11 @@ static void onPartChannel(irc_session_t *session, const char *event, const char
|
|||||||
static void onMode(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onMode(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);
|
||||||
NSString *nick = @(origin);
|
|
||||||
|
NSData *nick = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
||||||
NSString *mode = @(params[1]);
|
NSData *mode = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1];
|
||||||
|
NSData *modeParams = (count > 2) ? [NSData dataWithBytes:params[2] length:strlen(params[2]) + 1] : [NSData dataWithBytes:"\0" length:1];
|
||||||
NSString *modeParams = nil;
|
|
||||||
if (count > 2)
|
|
||||||
{
|
|
||||||
modeParams = @(params[2]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
modeParams = @"";
|
|
||||||
}
|
|
||||||
|
|
||||||
[clientSession modeSet:mode withParams:modeParams forChannel:channelName by:nick];
|
[clientSession modeSet:mode withParams:modeParams forChannel:channelName by:nick];
|
||||||
}
|
}
|
||||||
@ -732,8 +712,9 @@ static void onMode(irc_session_t *session, const char *event, const char *origin
|
|||||||
static void onUserMode(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onUserMode(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);
|
||||||
NSString* nick = @(origin);
|
|
||||||
NSString *mode = @(params[0]);
|
NSData *nick = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
|
NSData *mode = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
||||||
|
|
||||||
[clientSession modeSet:mode by:nick];
|
[clientSession modeSet:mode by:nick];
|
||||||
}
|
}
|
||||||
@ -750,18 +731,10 @@ static void onUserMode(irc_session_t *session, const char *event, const char *or
|
|||||||
static void onTopic(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onTopic(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);
|
||||||
NSString *nick = @(origin);
|
|
||||||
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
|
||||||
NSData *topic = nil;
|
|
||||||
|
|
||||||
if (count > 1)
|
NSData *nick = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
{
|
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
||||||
topic = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1];
|
NSData *topic = (count > 1) ? [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1] : [NSData dataWithBytes:"\0" length:1];
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
topic = [NSData dataWithBytes:"\0" length:1];
|
|
||||||
}
|
|
||||||
|
|
||||||
[clientSession topicSet:topic forChannel:channelName by:nick];
|
[clientSession topicSet:topic forChannel:channelName by:nick];
|
||||||
}
|
}
|
||||||
@ -779,24 +752,11 @@ static void onTopic(irc_session_t *session, const char *event, const char *origi
|
|||||||
static void onKick(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onKick(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);
|
||||||
NSString *byNick = @(origin);
|
|
||||||
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
|
||||||
|
|
||||||
NSString *nick = nil;
|
|
||||||
if (count > 1)
|
|
||||||
{
|
|
||||||
nick = @(params[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
NSData *reason = nil;
|
NSData *byNick = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
if (count > 2)
|
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
||||||
{
|
NSData *nick = (count > 1) ? [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1] : nil;
|
||||||
reason = [NSData dataWithBytes:params[2] length:strlen(params[2]) + 1];
|
NSData *reason = (count > 2) ? [NSData dataWithBytes:params[2] length:strlen(params[2]) + 1] : [NSData dataWithBytes:"\0" length:1];
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
reason = [NSData dataWithBytes:"\0" length:1];
|
|
||||||
}
|
|
||||||
|
|
||||||
[clientSession userKicked:nick fromChannel:channelName by:byNick withReason:reason];
|
[clientSession userKicked:nick fromChannel:channelName by:byNick withReason:reason];
|
||||||
}
|
}
|
||||||
@ -814,18 +774,10 @@ static void onKick(irc_session_t *session, const char *event, const char *origin
|
|||||||
static void onChannelPrvmsg(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onChannelPrvmsg(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);
|
||||||
NSString *nick = @(origin);
|
|
||||||
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
|
||||||
|
|
||||||
NSData *message = nil;
|
NSData *nick = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
if (count > 1)
|
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
||||||
{
|
NSData *message = (count > 1) ? [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1] : [NSData dataWithBytes:"\0" length:1];
|
||||||
message = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
message = [NSData dataWithBytes:"\0" length:1];
|
|
||||||
}
|
|
||||||
|
|
||||||
[clientSession messageSent:message toChannel:channelName byUser:nick];
|
[clientSession messageSent:message toChannel:channelName byUser:nick];
|
||||||
}
|
}
|
||||||
@ -842,17 +794,9 @@ static void onChannelPrvmsg(irc_session_t *session, const char *event, const cha
|
|||||||
static void onPrivmsg(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onPrivmsg(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);
|
||||||
NSString *nick = @(origin);
|
|
||||||
|
|
||||||
NSData *message = nil;
|
NSData *nick = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
if (count > 1)
|
NSData *message = (count > 1) ? [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1] : [NSData dataWithBytes:"\0" length:1];
|
||||||
{
|
|
||||||
message = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
message = [NSData dataWithBytes:"\0" length:1];
|
|
||||||
}
|
|
||||||
|
|
||||||
[clientSession privateMessageReceived:message fromUser:nick];
|
[clientSession privateMessageReceived:message fromUser:nick];
|
||||||
}
|
}
|
||||||
@ -868,9 +812,9 @@ static void onPrivmsg(irc_session_t *session, const char *event, const char *ori
|
|||||||
static void onServerMsg(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onServerMsg(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);
|
||||||
NSString *sender = @(origin);
|
|
||||||
|
|
||||||
NSMutableArray *paramsArray = [[NSMutableArray alloc] init];
|
NSData *sender = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
|
NSMutableArray *paramsArray = [NSMutableArray arrayWithCapacity:count];
|
||||||
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]) + 1]];
|
[paramsArray addObject:[NSData dataWithBytes:params[i] length:strlen(params[i]) + 1]];
|
||||||
@ -895,17 +839,9 @@ static void onServerMsg(irc_session_t *session, const char *event, const char *o
|
|||||||
static void onNotice(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onNotice(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);
|
||||||
NSString *nick = @(origin);
|
|
||||||
|
|
||||||
NSData *notice = nil;
|
NSData *nick = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
if (count > 1)
|
NSData *notice = (count > 1) ? [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1] : [NSData dataWithBytes:"\0" length:1];
|
||||||
{
|
|
||||||
notice = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
notice = [NSData dataWithBytes:"\0" length:1];
|
|
||||||
}
|
|
||||||
|
|
||||||
[clientSession privateNoticeReceived:notice fromUser:nick];
|
[clientSession privateNoticeReceived:notice fromUser:nick];
|
||||||
}
|
}
|
||||||
@ -926,18 +862,10 @@ static void onNotice(irc_session_t *session, const char *event, const char *orig
|
|||||||
static void onChannelNotice(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onChannelNotice(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);
|
||||||
NSString *nick = @(origin);
|
|
||||||
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
|
||||||
|
|
||||||
NSData *notice = nil;
|
NSData *nick = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
if (count > 1)
|
NSData *channelName = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
||||||
{
|
NSData *notice = (count > 1) ? [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1] : [NSData dataWithBytes:"\0" length:1];
|
||||||
notice = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
notice = [NSData dataWithBytes:"\0" length:1];
|
|
||||||
}
|
|
||||||
|
|
||||||
[clientSession noticeSent:notice toChannel:channelName byUser:nick];
|
[clientSession noticeSent:notice toChannel:channelName byUser:nick];
|
||||||
}
|
}
|
||||||
@ -959,9 +887,9 @@ static void onChannelNotice(irc_session_t *session, const char *event, const cha
|
|||||||
static void onServerNotice(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onServerNotice(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);
|
||||||
NSString *sender = @(origin);
|
|
||||||
|
|
||||||
NSMutableArray *paramsArray = [[NSMutableArray alloc] init];
|
NSData *sender = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
|
NSMutableArray *paramsArray = [NSMutableArray arrayWithCapacity:count];
|
||||||
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]) + 1]];
|
[paramsArray addObject:[NSData dataWithBytes:params[i] length:strlen(params[i]) + 1]];
|
||||||
@ -984,7 +912,8 @@ static void onServerNotice(irc_session_t *session, const char *event, const char
|
|||||||
static void onInvite(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onInvite(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);
|
||||||
NSString *nick = @(origin);
|
|
||||||
|
NSData *nick = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
NSData *channelName = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1];
|
NSData *channelName = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1];
|
||||||
|
|
||||||
[clientSession invitedToChannel:channelName by:nick];
|
[clientSession invitedToChannel:channelName by:nick];
|
||||||
@ -1008,8 +937,9 @@ static void onInvite(irc_session_t *session, const char *event, const char *orig
|
|||||||
static void onCtcpRequest(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
static void onCtcpRequest(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);
|
||||||
NSString *nick = @(origin);
|
|
||||||
NSData* request = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
NSData *nick = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
|
NSData *request = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
||||||
|
|
||||||
[clientSession CTCPRequestReceived:request fromUser:nick];
|
[clientSession CTCPRequestReceived:request fromUser:nick];
|
||||||
}
|
}
|
||||||
@ -1024,7 +954,7 @@ static void onCtcpReply(irc_session_t *session, const char *event, const char *o
|
|||||||
{
|
{
|
||||||
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session);
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session);
|
||||||
|
|
||||||
NSString *nick = @(origin);
|
NSData *nick = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
NSData *reply = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
NSData *reply = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
||||||
|
|
||||||
[clientSession CTCPReplyReceived:reply fromUser:nick];
|
[clientSession CTCPReplyReceived:reply fromUser:nick];
|
||||||
@ -1045,7 +975,7 @@ static void onCtcpAction(irc_session_t *session, const char *event, const char *
|
|||||||
{
|
{
|
||||||
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session);
|
IRCClientSession *clientSession = (__bridge IRCClientSession *) irc_get_ctx(session);
|
||||||
|
|
||||||
NSString *nick = @(origin);
|
NSData *nick = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
NSData *target = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
NSData *target = [NSData dataWithBytes:params[0] length:strlen(params[0]) + 1];
|
||||||
NSData *action = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1];
|
NSData *action = [NSData dataWithBytes:params[1] length:strlen(params[1]) + 1];
|
||||||
|
|
||||||
@ -1060,21 +990,16 @@ static void onCtcpAction(irc_session_t *session, const char *event, const char *
|
|||||||
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 *eventData = [NSData dataWithBytes:event length:strlen(event) + 1];
|
|
||||||
|
|
||||||
NSString *originString = nil;
|
|
||||||
if (origin != NULL)
|
|
||||||
{
|
|
||||||
originString = @(origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
NSMutableArray *paramsArray = [[NSMutableArray alloc] init];
|
NSData *eventType = [NSData dataWithBytes:event length:strlen(event) + 1];
|
||||||
|
NSData *sender = (origin != NULL) ? [NSData dataWithBytes:origin length:strlen(origin) + 1] : [NSData dataWithBytes:"\0" length:1];
|
||||||
|
NSMutableArray *paramsArray = [NSMutableArray arrayWithCapacity:count];
|
||||||
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]) + 1]];
|
[paramsArray addObject:[NSData dataWithBytes:params[i] length:strlen(params[i]) + 1]];
|
||||||
}
|
}
|
||||||
|
|
||||||
[clientSession unknownEventReceived:eventData from:originString params:paramsArray];
|
[clientSession unknownEventReceived:eventType from:sender params:paramsArray];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -1087,10 +1012,10 @@ static void onUnknownEvent(irc_session_t *session, const char *event, const char
|
|||||||
static void onNumericEvent(irc_session_t * session, unsigned int event, const char * origin, const char ** params, unsigned int count)
|
static void onNumericEvent(irc_session_t * session, unsigned int 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);
|
||||||
NSUInteger eventNumber = event;
|
|
||||||
NSString *sender = @(origin);
|
|
||||||
|
|
||||||
NSMutableArray *paramsArray = [[NSMutableArray alloc] init];
|
NSUInteger eventNumber = event;
|
||||||
|
NSData *sender = [NSData dataWithBytes:origin length:strlen(origin) + 1];
|
||||||
|
NSMutableArray *paramsArray = [NSMutableArray arrayWithCapacity:count];
|
||||||
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]) + 1]];
|
[paramsArray addObject:[NSData dataWithBytes:params[i] length:strlen(params[i]) + 1]];
|
||||||
|
|||||||
@ -42,14 +42,14 @@
|
|||||||
* @param oldNick the old nickname
|
* @param oldNick the old nickname
|
||||||
* @param wasItUs did our nick change, or someone else's?
|
* @param wasItUs did our nick change, or someone else's?
|
||||||
*/
|
*/
|
||||||
- (void)nickChangedFrom:(NSString *)oldNick to:(NSString *)newNick own:(BOOL)wasItUs;
|
- (void)nickChangedFrom:(NSData *)oldNick to:(NSData *)newNick own:(BOOL)wasItUs;
|
||||||
|
|
||||||
/** An IRC client on a channel that this client is connected to has quit IRC.
|
/** An IRC client on a channel that this client is connected to has quit IRC.
|
||||||
*
|
*
|
||||||
* @param nick the nickname of the client that quit.
|
* @param nick the nickname of the client that quit.
|
||||||
* @param reason (optional) the quit message, if any.
|
* @param reason (optional) the quit message, if any.
|
||||||
*/
|
*/
|
||||||
- (void)userQuit:(NSString *)nick withReason:(NSString *)reason;
|
- (void)userQuit:(NSData *)nick withReason:(NSData *)reason;
|
||||||
|
|
||||||
/** The IRC client has joined (connected) successfully to a new channel. This
|
/** The IRC client has joined (connected) successfully to a new channel. This
|
||||||
* event creates an IRCClientChannel object, which you are expected to assign a
|
* event creates an IRCClientChannel object, which you are expected to assign a
|
||||||
@ -69,52 +69,42 @@
|
|||||||
*
|
*
|
||||||
* @param mode the new mode.
|
* @param mode the new mode.
|
||||||
*/
|
*/
|
||||||
- (void)modeSet:(NSString *)mode by:(NSString *)nick;
|
- (void)modeSet:(NSData *)mode by:(NSData *)nick;
|
||||||
|
|
||||||
/** The client has received a private PRIVMSG from another IRC client.
|
/** The client has received a private PRIVMSG from another IRC client.
|
||||||
*
|
*
|
||||||
* @param message the text of the message
|
* @param message the text of the message
|
||||||
* @param nick the other IRC Client that sent the message.
|
* @param nick the other IRC Client that sent the message.
|
||||||
*/
|
*/
|
||||||
- (void)privateMessageReceived:(NSString *)message fromUser:(NSString *)nick;
|
- (void)privateMessageReceived:(NSData *)message fromUser:(NSData *)nick;
|
||||||
|
|
||||||
/** The client has received a private NOTICE from another client.
|
/** The client has received a private NOTICE from another client.
|
||||||
*
|
*
|
||||||
* @param notice the text of the message
|
* @param notice the text of the message
|
||||||
* @param nick the nickname of the other IRC client that sent the message.
|
* @param nick the nickname of the other IRC client that sent the message.
|
||||||
*/
|
*/
|
||||||
- (void)privateNoticeReceived:(NSString *)notice fromUser:(NSString *)nick;
|
- (void)privateNoticeReceived:(NSData *)notice fromUser:(NSData *)nick;
|
||||||
|
|
||||||
/** The client has received a private PRIVMSG from the server.
|
/** The client has received a private PRIVMSG from the server.
|
||||||
*
|
*
|
||||||
* @param origin the sender of the message
|
* @param origin the sender of the message
|
||||||
* @param params the parameters of the message
|
* @param params the parameters of the message
|
||||||
*/
|
*/
|
||||||
- (void)serverMessageReceivedFrom:(NSString *)origin params:(NSArray *)params;
|
- (void)serverMessageReceivedFrom:(NSData *)origin params:(NSArray *)params;
|
||||||
|
|
||||||
/** The client has received a private NOTICE from the server.
|
/** The client has received a private NOTICE from the server.
|
||||||
*
|
*
|
||||||
* @param origin the sender of the notice
|
* @param origin the sender of the notice
|
||||||
* @param params the parameters of the notice
|
* @param params the parameters of the notice
|
||||||
*/
|
*/
|
||||||
- (void)serverNoticeReceivedFrom:(NSString *)origin params:(NSArray *)params;
|
- (void)serverNoticeReceivedFrom:(NSData *)origin params:(NSArray *)params;
|
||||||
|
|
||||||
/** The IRC client has been invited to a channel.
|
/** The IRC client has been invited to a channel.
|
||||||
*
|
|
||||||
* Note that the name is provided as an NSData object, because we have no idea
|
|
||||||
* what encoding the channel name is in (it needn't be the same as used by e.g.
|
|
||||||
* server messages, etc.), and it's important to attempt to join *exactly* the
|
|
||||||
* channel you're being invited to, byte for byte, otherwise you might end up
|
|
||||||
* joining the wrong channel. You should convert the name to an NSString for
|
|
||||||
* display (using the encoding set for the server is probably a sane default)
|
|
||||||
* but be aware that you might be displaying entirely wrong characters and are
|
|
||||||
* not gauranteed that the channel name will look right - only that it will be
|
|
||||||
* actually be the right name, internally.
|
|
||||||
*
|
*
|
||||||
* @param channel the channel for the invitation.
|
* @param channel the channel for the invitation.
|
||||||
* @param nick the nickname of the user that sent the invitation.
|
* @param nick the nickname of the user that sent the invitation.
|
||||||
*/
|
*/
|
||||||
- (void)invitedToChannel:(NSData *)channelName by:(NSString *)nick;
|
- (void)invitedToChannel:(NSData *)channelName by:(NSData *)nick;
|
||||||
|
|
||||||
/** A private CTCP request was sent to the IRC client.
|
/** A private CTCP request was sent to the IRC client.
|
||||||
*
|
*
|
||||||
@ -122,14 +112,14 @@
|
|||||||
* @param type the CTCP request type
|
* @param type the CTCP request type
|
||||||
* @param nick the nickname of the user that sent the request.
|
* @param nick the nickname of the user that sent the request.
|
||||||
*/
|
*/
|
||||||
- (void)CTCPRequestReceived:(NSData *)request ofType:(NSData *)type fromUser:(NSString *)nick;
|
- (void)CTCPRequestReceived:(NSData *)request ofType:(NSData *)type fromUser:(NSData *)nick;
|
||||||
|
|
||||||
/** A private CTCP reply was sent to the IRC client.
|
/** A private CTCP reply was sent to the IRC client.
|
||||||
*
|
*
|
||||||
* @param reply an NSData containing the raw C string of the reply.
|
* @param reply an NSData containing the raw C string of the reply.
|
||||||
* @param nick the nickname of the user that sent the reply.
|
* @param nick the nickname of the user that sent the reply.
|
||||||
*/
|
*/
|
||||||
- (void)CTCPReplyReceived:(NSData *)reply fromUser:(NSString *)nick;
|
- (void)CTCPReplyReceived:(NSData *)reply fromUser:(NSData *)nick;
|
||||||
|
|
||||||
/** A private CTCP ACTION was sent to the IRC client.
|
/** A private CTCP ACTION was sent to the IRC client.
|
||||||
*
|
*
|
||||||
@ -138,7 +128,7 @@
|
|||||||
* @param action the action message text.
|
* @param action the action message text.
|
||||||
* @param nick the nickname of the client that sent the action.
|
* @param nick the nickname of the client that sent the action.
|
||||||
*/
|
*/
|
||||||
- (void)privateCTCPActionReceived:(NSString *)action fromUser:(NSString *)nick;
|
- (void)privateCTCPActionReceived:(NSData *)action fromUser:(NSData *)nick;
|
||||||
|
|
||||||
/** An unhandled event was received from the IRC server.
|
/** An unhandled event was received from the IRC server.
|
||||||
*
|
*
|
||||||
@ -146,7 +136,7 @@
|
|||||||
* @param origin the sender of the event
|
* @param origin the sender of the event
|
||||||
* @param params an NSArray of NSData objects that are the raw C strings of the event.
|
* @param params an NSArray of NSData objects that are the raw C strings of the event.
|
||||||
*/
|
*/
|
||||||
- (void)unknownEventReceived:(NSData *)event from:(NSString *)origin params:(NSArray *)params;
|
- (void)unknownEventReceived:(NSData *)event from:(NSData *)origin params:(NSArray *)params;
|
||||||
|
|
||||||
/** An unhandled numeric was received from the IRC server
|
/** An unhandled numeric was received from the IRC server
|
||||||
*
|
*
|
||||||
@ -154,6 +144,6 @@
|
|||||||
* @param origin the sender of the event
|
* @param origin the sender of the event
|
||||||
* @param params an NSArray of NSData objects that are the raw C strings of the event.
|
* @param params an NSArray of NSData objects that are the raw C strings of the event.
|
||||||
*/
|
*/
|
||||||
- (void)numericEventReceived:(NSUInteger)event from:(NSString *)origin params:(NSArray *)params;
|
- (void)numericEventReceived:(NSUInteger)event from:(NSData *)origin params:(NSArray *)params;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user