changeset 18030:62a71bb085ef

Mostly taken from the patch on ticket #410, don't send unknown slash commands as messages on protocols where slash commands are "native". This is determined by using a new OPT_PROTO_SLASH_COMMAND_NATIVE protocol option, so this only goes in the 2.1.0 branch. Fixes #410.
author Stu Tomlinson <stu@nosnilmot.com>
date Sat, 02 Jun 2007 12:05:50 +0000
parents 9e648622bf72
children 23a65f460e34 fbebe15c91a7
files libpurple/protocols/irc/irc.c libpurple/protocols/jabber/libxmpp.c libpurple/protocols/silc/silc.c libpurple/prpl.h pidgin/gtkconv.c
diffstat 5 files changed, 52 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/irc/irc.c	Sat Jun 02 11:41:18 2007 +0000
+++ b/libpurple/protocols/irc/irc.c	Sat Jun 02 12:05:50 2007 +0000
@@ -814,7 +814,8 @@
 
 static PurplePluginProtocolInfo prpl_info =
 {
-	OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL,
+	OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL |
+	OPT_PROTO_SLASH_COMMANDS_NATIVE,
 	NULL,					/* user_splits */
 	NULL,					/* protocol_options */
 	NO_BUDDY_ICONS,		/* icon_spec */
--- a/libpurple/protocols/jabber/libxmpp.c	Sat Jun 02 11:41:18 2007 +0000
+++ b/libpurple/protocols/jabber/libxmpp.c	Sat Jun 02 12:05:50 2007 +0000
@@ -43,9 +43,11 @@
 {
 #ifdef HAVE_CYRUS_SASL
 	OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME |
-	OPT_PROTO_MAIL_CHECK | OPT_PROTO_PASSWORD_OPTIONAL,
+	OPT_PROTO_MAIL_CHECK | OPT_PROTO_PASSWORD_OPTIONAL |
+	OPT_PROTO_SLASH_COMMANDS_NATIVE,
 #else
-	OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME | OPT_PROTO_MAIL_CHECK,
+	OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME | OPT_PROTO_MAIL_CHECK |
+	OPT_PROTO_SLASH_COMMANDS_NATIVE,
 #endif
 	NULL,							/* user_splits */
 	NULL,							/* protocol_options */
--- a/libpurple/protocols/silc/silc.c	Sat Jun 02 11:41:18 2007 +0000
+++ b/libpurple/protocols/silc/silc.c	Sat Jun 02 12:05:50 2007 +0000
@@ -1728,10 +1728,11 @@
 {
 #ifdef HAVE_SILCMIME_H
 	OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME |
-	OPT_PROTO_PASSWORD_OPTIONAL | OPT_PROTO_IM_IMAGE,
+	OPT_PROTO_PASSWORD_OPTIONAL | OPT_PROTO_IM_IMAGE |
+	OPT_PROTO_SLASH_COMMANDS_NATIVE,
 #else
 	OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME |
-	OPT_PROTO_PASSWORD_OPTIONAL,
+	OPT_PROTO_PASSWORD_OPTIONAL | OPT_PROTO_SLASH_COMMANDS_NATIVE,
 #endif
 	NULL,						/* user_splits */
 	NULL,						/* protocol_options */
--- a/libpurple/prpl.h	Sat Jun 02 11:41:18 2007 +0000
+++ b/libpurple/prpl.h	Sat Jun 02 12:05:50 2007 +0000
@@ -158,6 +158,12 @@
 	 */
 	OPT_PROTO_REGISTER_NOSCREENNAME = 0x00000200,
 
+	/**
+	 * Indicates that slash commands are native to this protocol.
+	 * Used as a hint that unknown commands should not be sent as messages.
+	 */
+	OPT_PROTO_SLASH_COMMANDS_NATIVE = 0x00000400,
+
 } PurpleProtocolOptions;
 
 /**
--- a/pidgin/gtkconv.c	Sat Jun 02 11:41:18 2007 +0000
+++ b/pidgin/gtkconv.c	Sat Jun 02 12:05:50 2007 +0000
@@ -473,6 +473,7 @@
 	char *cmd;
 	const char *prefix;
 	GtkTextIter start;
+	gboolean retval = FALSE;
 
 	gtkconv = PIDGIN_CONVERSATION(conv);
 	prefix = pidgin_get_cmd_prefix();
@@ -496,24 +497,50 @@
 		gtk_text_buffer_get_end_iter(GTK_IMHTML(gtkconv->entry)->text_buffer, &end);
 		markup = gtk_imhtml_get_markup_range(GTK_IMHTML(gtkconv->entry), &start, &end);
 		status = purple_cmd_do_command(conv, cmdline, markup, &error);
-		g_free(cmd);
 		g_free(markup);
 
 		switch (status) {
 			case PURPLE_CMD_STATUS_OK:
-				return TRUE;
+				retval = TRUE;
+				break;
 			case PURPLE_CMD_STATUS_NOT_FOUND:
-				return FALSE;
+				{
+					PurplePluginProtocolInfo *prpl_info = NULL;
+					PurpleConnection *gc;
+
+					if ((gc = purple_conversation_get_gc(conv)))
+						prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl);
+
+					if ((prpl_info != NULL) && (prpl_info->options & OPT_PROTO_SLASH_COMMANDS_NATIVE)) {
+						char *firstspace;
+						char *slash;
+
+						firstspace = strchr(cmdline, ' ');
+						if (firstspace != NULL) {
+							slash = strrchr(firstspace, '/');
+						} else {
+							slash = strchr(cmdline, '/');
+						}
+
+						if (slash == NULL) {
+							purple_conversation_write(conv, "", _("Unknown command."), PURPLE_MESSAGE_NO_LOG, time(NULL));
+							retval = TRUE;
+						}
+					}
+					break;
+				}
 			case PURPLE_CMD_STATUS_WRONG_ARGS:
 				purple_conversation_write(conv, "", _("Syntax Error:  You typed the wrong number of arguments "
 								    "to that command."),
 						PURPLE_MESSAGE_NO_LOG, time(NULL));
-				return TRUE;
+				retval = TRUE;
+				break;
 			case PURPLE_CMD_STATUS_FAILED:
 				purple_conversation_write(conv, "", error ? error : _("Your command failed for an unknown reason."),
 						PURPLE_MESSAGE_NO_LOG, time(NULL));
 				g_free(error);
-				return TRUE;
+				retval = TRUE;
+				break;
 			case PURPLE_CMD_STATUS_WRONG_TYPE:
 				if(purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM)
 					purple_conversation_write(conv, "", _("That command only works in chats, not IMs."),
@@ -521,16 +548,18 @@
 				else
 					purple_conversation_write(conv, "", _("That command only works in IMs, not chats."),
 							PURPLE_MESSAGE_NO_LOG, time(NULL));
-				return TRUE;
+				retval = TRUE;
+				break;
 			case PURPLE_CMD_STATUS_WRONG_PRPL:
 				purple_conversation_write(conv, "", _("That command doesn't work on this protocol."),
 						PURPLE_MESSAGE_NO_LOG, time(NULL));
-				return TRUE;
+				retval = TRUE;
+				break;
 		}
 	}
 
 	g_free(cmd);
-	return FALSE;
+	return retval;
 }
 
 static void