summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Kramlich <grim@reaperworld.com>2016-08-19 23:38:43 -0500
committerGary Kramlich <grim@reaperworld.com>2016-08-19 23:38:43 -0500
commit3f871f44e7d153d8be3be86fe50bee43438a8e94 (patch)
treed5257aed5df2e3f47afb700e38443a68fbed8671
parentf79aacdc1eb4d551c2fa6723488efe129a57f8f2 (diff)
downloadpidgin-3f871f44e7d153d8be3be86fe50bee43438a8e94.tar.gz
Fix up the commands execute stuff
-rw-r--r--libpurple/cmds.c38
-rw-r--r--libpurple/cmds.h21
2 files changed, 45 insertions, 14 deletions
diff --git a/libpurple/cmds.c b/libpurple/cmds.c
index 6daf9f7b02..b312a36f29 100644
--- a/libpurple/cmds.c
+++ b/libpurple/cmds.c
@@ -26,7 +26,7 @@ static PurpleCommandsUiOps *cmds_ui_ops = NULL;
static GList *cmds = NULL;
static guint next_id = 1;
-struct _PurpleCmd {
+typedef struct _PurpleCmd {
PurpleCmdId id;
gchar *cmd;
gchar *args;
@@ -36,7 +36,7 @@ struct _PurpleCmd {
PurpleCmdFunc func;
gchar *help;
void *data;
-};
+} PurpleCmd;
static gint cmds_compare_func(const PurpleCmd *a, const PurpleCmd *b)
@@ -78,7 +78,7 @@ PurpleCmdId purple_cmd_register(const gchar *cmd, const gchar *args,
ops = purple_cmds_get_ui_ops();
if (ops && ops->register_command)
- ops->register_command(cmd, p, f, prpl_id, helpstr, c);
+ ops->register_command(cmd, p, f, protocol_id, helpstr, c->id);
purple_signal_emit(purple_cmds_get_handle(), "cmd-added", cmd, p, f);
@@ -105,7 +105,7 @@ void purple_cmd_unregister(PurpleCmdId id)
if (c->id == id) {
PurpleCommandsUiOps *ops = purple_cmds_get_ui_ops();
if (ops && ops->unregister_command)
- ops->unregister_command(c->cmd, c->prpl_id);
+ ops->unregister_command(c->cmd, c->protocol_id);
cmds = g_list_remove(cmds, c);
purple_signal_emit(purple_cmds_get_handle(), "cmd-removed", c->cmd);
@@ -302,19 +302,33 @@ PurpleCmdStatus purple_cmd_do_command(PurpleConversation *conv, const gchar *cmd
}
-gboolean purple_cmd_execute(PurpleCmd *c, PurpleConversation *conv,
+gboolean purple_cmd_execute(PurpleCmdId id, PurpleConversation *conv,
const gchar *cmdline)
{
+ PurpleCmd *cmd = NULL;
+ PurpleCmdRet ret = PURPLE_CMD_RET_CONTINUE;
+ GList *l = NULL;
gchar *err = NULL;
gchar **args = NULL;
- PurpleCmdRet ret = PURPLE_CMD_RET_CONTINUE;
- if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) {
- if (!(c->flags & PURPLE_CMD_FLAG_IM))
+ for(l = cmds; l; l = l->next) {
+ cmd = (PurpleCmd*)l->data;
+
+ if(cmd->id == id) {
+ break;
+ }
+ cmd = NULL;
+ }
+ if(cmd == NULL) {
+ return FALSE;
+ }
+
+ if (PURPLE_IS_IM_CONVERSATION(conv)) {
+ if (!(cmd->flags & PURPLE_CMD_FLAG_IM))
return FALSE;
}
- else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) {
- if (!(c->flags & PURPLE_CMD_FLAG_CHAT))
+ else if (PURPLE_IS_CHAT_CONVERSATION(conv)) {
+ if (!(cmd->flags & PURPLE_CMD_FLAG_CHAT))
return FALSE;
}
else
@@ -323,12 +337,12 @@ gboolean purple_cmd_execute(PurpleCmd *c, PurpleConversation *conv,
/* XXX: Don't worry much about the markup version of the command
line, there's not a single use case... */
/* this checks the allow bad args flag for us */
- if (!purple_cmd_parse_args(c, cmdline, cmdline, &args)) {
+ if (!purple_cmd_parse_args(cmd, cmdline, cmdline, &args)) {
g_strfreev(args);
return FALSE;
}
- ret = c->func(conv, c->cmd, args, &err, c->data);
+ ret = cmd->func(conv, cmd->cmd, args, &err, cmd->data);
g_free(err);
g_strfreev(args);
diff --git a/libpurple/cmds.h b/libpurple/cmds.h
index 173fe73098..925b35b0d3 100644
--- a/libpurple/cmds.h
+++ b/libpurple/cmds.h
@@ -131,7 +131,7 @@ typedef struct
/* @see purple_cmd_register for the argument values. */
void (*register_command)(const gchar *name, PurpleCmdPriority priority,
PurpleCmdFlag flags, const gchar *prpl_id,
- const gchar *help, PurpleCmd *cmd);
+ const gchar *help, PurpleCmdId id);
/** Should be implemented if register_command is implemented.
* name and prpl_id will have the same value that were used
@@ -259,7 +259,7 @@ PurpleCmdStatus purple_cmd_do_command(PurpleConversation *conv, const gchar *cmd
* in plain text (no HTML entities).
* @return TRUE if the command handled the @a cmdline, FALSE otherwise.
*/
-gboolean purple_cmd_execute(PurpleCmd *c, PurpleConversation *conv,
+gboolean purple_cmd_execute(PurpleCmdId id, PurpleConversation *conv,
const gchar *cmdline);
/**
@@ -305,6 +305,23 @@ GList *purple_cmd_help(PurpleConversation *conv, const gchar *cmd);
gpointer purple_cmds_get_handle(void);
/**
+ * Sets the UI operations structure to be used when registering and
+ * unregistering commands. The UI operations need only be set if the
+ * UI wants to handle the commands itself; otherwise, leave it as NULL.
+ *
+ * @param ops The UI operations structure.
+ */
+void purple_cmds_set_ui_ops(PurpleCommandsUiOps *ops);
+
+/**
+ * Returns the UI operations structure to be used when registering and
+ * unregistering commands.
+ *
+ * @return The UI operations structure.
+ */
+PurpleCommandsUiOps *purple_cmds_get_ui_ops(void);
+
+/**
* purple_cmds_init:
*
* Initialize the commands subsystem.