changeset 23583:dc359ea9eb9a

/ctcp command for IRC committer: Ethan Blanton <elb@pidgin.im>
author Vladislav Guberinic <neosisani@gmail.com>
date Mon, 21 Jul 2008 20:33:29 +0000
parents a270bd4b5298
children bd0c0cffb644
files COPYRIGHT ChangeLog libpurple/protocols/irc/cmds.c libpurple/protocols/irc/irc.h libpurple/protocols/irc/parse.c
diffstat 5 files changed, 39 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/COPYRIGHT	Mon Jul 21 07:46:23 2008 +0000
+++ b/COPYRIGHT	Mon Jul 21 20:33:29 2008 +0000
@@ -157,6 +157,7 @@
 Konrad Gräfe
 Miah Gregory
 David Grohmann
+Vladislav Guberinić
 Gideon N. Guillen
 Christian Hammond
 Erick Hamness
--- a/ChangeLog	Mon Jul 21 07:46:23 2008 +0000
+++ b/ChangeLog	Mon Jul 21 20:33:29 2008 +0000
@@ -10,6 +10,9 @@
 	  we don't install our SSL CA certs, so it's important that the
 	  libpurple package depend on the CA certificates.
 
+	IRC:
+	* /ctcp command (Vladislav Guberinić)
+
 	MSN:
 	* Update MSN support to protocol 15 (Elliott Sales de Andrade, Jorge
 	  Villaseñor, Mike Ruprecht, Carlos Silva, Ma Yuan, Daniel Ljungborg
--- a/libpurple/protocols/irc/cmds.c	Mon Jul 21 07:46:23 2008 +0000
+++ b/libpurple/protocols/irc/cmds.c	Mon Jul 21 20:33:29 2008 +0000
@@ -68,6 +68,39 @@
 	return 0;
 }
 
+int irc_cmd_ctcp(struct irc_conn *irc, const char *cmd, const char *target, const char **args)
+{
+	/* we have defined args as args[0] is target and args[1] is ctcp command */
+        char *buf;
+	GString *string;
+	
+	/* check if we have args */
+	if (!args || !args[0] || !args[1])
+		return 0;
+
+	/* TODO:strip newlines or send each line as separate ctcp or something
+	 * actually, this shouldn't be done here but somewhere else since irc should support escaping newlines
+	 * utf8 could pose additional problems here since it allows some of weird chars (NULL) to be part of bigger chars */ 
+
+	string = g_string_new(args[1]);
+	g_string_prepend_c (string,'\001');
+	g_string_append_c (string,'\001');
+	buf = irc_format(irc, "vn:", "PRIVMSG", args[0], string->str);
+	g_string_free(string,TRUE);
+
+	/* check if line is small enough to send
+	 * XXX: strlen will prolly not work for UTF-8 */
+	if (strlen(buf) >= 512)
+		return 0;
+
+	irc_send(irc, buf);
+	g_free(buf);
+	
+
+	return 1;
+	
+}
+
 int irc_cmd_ctcp_action(struct irc_conn *irc, const char *cmd, const char *target, const char **args)
 {
 	PurpleConnection *gc = purple_account_get_connection(irc->account);
--- a/libpurple/protocols/irc/irc.h	Mon Jul 21 07:46:23 2008 +0000
+++ b/libpurple/protocols/irc/irc.h	Mon Jul 21 20:33:29 2008 +0000
@@ -164,6 +164,7 @@
 
 int irc_cmd_default(struct irc_conn *irc, const char *cmd, const char *target, const char **args);
 int irc_cmd_away(struct irc_conn *irc, const char *cmd, const char *target, const char **args);
+int irc_cmd_ctcp(struct irc_conn *irc, const char *cmd, const char *target, const char **args);
 int irc_cmd_ctcp_action(struct irc_conn *irc, const char *cmd, const char *target, const char **args);
 int irc_cmd_ctcp_version(struct irc_conn *irc, const char *cmd, const char *target, const char **args);
 int irc_cmd_invite(struct irc_conn *irc, const char *cmd, const char *target, const char **args);
--- a/libpurple/protocols/irc/parse.c	Mon Jul 21 07:46:23 2008 +0000
+++ b/libpurple/protocols/irc/parse.c	Mon Jul 21 20:33:29 2008 +0000
@@ -123,6 +123,7 @@
 } _irc_cmds[] = {
 	{ "action", ":", irc_cmd_ctcp_action, N_("action &lt;action to perform&gt;:  Perform an action.") },
 	{ "away", ":", irc_cmd_away, N_("away [message]:  Set an away message, or use no message to return from being away.") },
+	{ "ctcp", "t:", irc_cmd_ctcp, N_("ctcp <nick> <msg>: sends ctcp msg to nick.") },
 	{ "chanserv", ":", irc_cmd_service, N_("chanserv: Send a command to chanserv") },
 	{ "deop", ":", irc_cmd_op, N_("deop &lt;nick1&gt; [nick2] ...:  Remove channel operator status from someone. You must be a channel operator to do this.") },
 	{ "devoice", ":", irc_cmd_op, N_("devoice &lt;nick1&gt; [nick2] ...:  Remove channel voice status from someone, preventing them from speaking if the channel is moderated (+m). You must be a channel operator to do this.") },