diff libpurple/protocols/irc/cmds.c @ 23628: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 f1dfc0d70d19
children bd0c0cffb644
line wrap: on
line diff
--- 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);