annotate src/cmds.c @ 14100:85144ba7d726

[gaim-migrate @ 16730] Fix the documentation to indicate that the result of xmlnode_get_data() needs to be g_free'd committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Sun, 13 Aug 2006 02:18:28 +0000
parents 8bda65b88e49
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1 /**
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
2 * @file cmds.c Commands API
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
3 * @ingroup core
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
4 *
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
5 * Copyright (C) 2003-2004 Timothy Ringenbach <omarvo@hotmail.com
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
6 *
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
10 * (at your option) any later version.
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
11 *
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
15 * GNU General Public License for more details.
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
16 *
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
20 *
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
21 */
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
22
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
23 #include <string.h>
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
24
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
25 #include "account.h"
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
26 #include "util.h"
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
27 #include "cmds.h"
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
28
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29 static GList *cmds = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30 static guint next_id = 1;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
32 typedef struct _GaimCmd {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33 GaimCmdId id;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
34 gchar *cmd;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35 gchar *args;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36 GaimCmdPriority priority;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37 GaimCmdFlag flags;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38 gchar *prpl_id;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39 GaimCmdFunc func;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
40 gchar *help;
9597
d6f398e80b32 [gaim-migrate @ 10440]
Tim Ringenbach <marv@pidgin.im>
parents: 9428
diff changeset
41 void *data;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
42 } GaimCmd;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
43
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
44
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
45 static gint cmds_compare_func(const GaimCmd *a, const GaimCmd *b)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
46 {
10504
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9597
diff changeset
47 if (a->priority > b->priority)
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
48 return -1;
10504
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9597
diff changeset
49 else if (a->priority < b->priority)
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
50 return 1;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
51 else return 0;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
52 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
53
9597
d6f398e80b32 [gaim-migrate @ 10440]
Tim Ringenbach <marv@pidgin.im>
parents: 9428
diff changeset
54 GaimCmdId gaim_cmd_register(const gchar *cmd, const gchar *args,
d6f398e80b32 [gaim-migrate @ 10440]
Tim Ringenbach <marv@pidgin.im>
parents: 9428
diff changeset
55 GaimCmdPriority p, GaimCmdFlag f,
d6f398e80b32 [gaim-migrate @ 10440]
Tim Ringenbach <marv@pidgin.im>
parents: 9428
diff changeset
56 const gchar *prpl_id, GaimCmdFunc func,
d6f398e80b32 [gaim-migrate @ 10440]
Tim Ringenbach <marv@pidgin.im>
parents: 9428
diff changeset
57 const gchar *helpstr, void *data)
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
58 {
9343
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
59 GaimCmdId id;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
60 GaimCmd *c;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
61
9343
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
62 g_return_val_if_fail(cmd != NULL && *cmd != '\0', 0);
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
63 g_return_val_if_fail(args != NULL, 0);
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
64 g_return_val_if_fail(func != NULL, 0);
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
65
9343
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
66 id = next_id++;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
67
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68 c = g_new0(GaimCmd, 1);
9343
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
69 c->id = id;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70 c->cmd = g_strdup(cmd);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
71 c->args = g_strdup(args);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
72 c->priority = p;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
73 c->flags = f;
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 12014
diff changeset
74 c->prpl_id = g_strdup(prpl_id);
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
75 c->func = func;
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 12014
diff changeset
76 c->help = g_strdup(helpstr);
9597
d6f398e80b32 [gaim-migrate @ 10440]
Tim Ringenbach <marv@pidgin.im>
parents: 9428
diff changeset
77 c->data = data;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
78
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
79 cmds = g_list_insert_sorted(cmds, c, (GCompareFunc)cmds_compare_func);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
80
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
81 return id;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
82 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
83
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
84 static void gaim_cmd_free(GaimCmd *c)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
85 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
86 g_free(c->cmd);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
87 g_free(c->args);
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 12014
diff changeset
88 g_free(c->prpl_id);
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 12014
diff changeset
89 g_free(c->help);
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
90 g_free(c);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
91 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
92
9343
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
93 void gaim_cmd_unregister(GaimCmdId id)
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
94 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
95 GaimCmd *c;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
96 GList *l;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
97
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
98 for (l = cmds; l; l = l->next) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
99 c = l->data;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
100
9343
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
101 if (c->id == id) {
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
102 cmds = g_list_remove(cmds, c);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
103 gaim_cmd_free(c);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
104 return;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
105 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
106 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
107 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
108
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 12014
diff changeset
109 /**
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 12014
diff changeset
110 * This sets args to a NULL-terminated array of strings. It should
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 12014
diff changeset
111 * be freed using g_strfreev().
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 12014
diff changeset
112 */
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
113 static gboolean gaim_cmd_parse_args(GaimCmd *cmd, const gchar *s, const gchar *m, gchar ***args)
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
114 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
115 int i;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
116 const char *end, *cur;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
117
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
118 *args = g_new0(char *, strlen(cmd->args) + 1);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
119
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
120 cur = s;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
121
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
122 for (i = 0; cmd->args[i]; i++) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
123 if (!*cur)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
124 return (cmd->flags & GAIM_CMD_FLAG_ALLOW_WRONG_ARGS);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
125
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
126 switch (cmd->args[i]) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
127 case 'w':
9428
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
128 if (!(end = strchr(cur, ' '))) {
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
129 end = cur + strlen(cur);
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
130 (*args)[i] = g_strndup(cur, end - cur);
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
131 cur = end;
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
132 } else {
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
133 (*args)[i] = g_strndup(cur, end - cur);
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
134 cur = end + 1;
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
135 }
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
136 break;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
137 case 'W':
9428
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
138 if (!(end = strchr(cur, ' '))) {
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
139 end = cur + strlen(cur);
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
140 (*args)[i] = gaim_markup_slice(m, g_utf8_pointer_to_offset(s, cur), g_utf8_pointer_to_offset(s, end));
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
141 cur = end;
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
142 } else {
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
143 (*args)[i] = gaim_markup_slice(m, g_utf8_pointer_to_offset(s, cur), g_utf8_pointer_to_offset(s, end));
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
144 cur = end +1;
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
145 }
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 12014
diff changeset
146 break;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
147 case 's':
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
148 (*args)[i] = g_strdup(cur);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
149 cur = cur + strlen(cur);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
150 break;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
151 case 'S':
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
152 (*args)[i] = gaim_markup_slice(m, g_utf8_pointer_to_offset(s, cur), g_utf8_strlen(cur, -1) + 1);
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
153 cur = cur + strlen(cur);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
154 break;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
155 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
156 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
157
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
158 if (*cur)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
159 return (cmd->flags & GAIM_CMD_FLAG_ALLOW_WRONG_ARGS);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
160
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
161 return TRUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
162 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
163
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
164 static void gaim_cmd_strip_current_char(gunichar c, char *s, guint len)
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
165 {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
166 int bytes;
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
167
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
168 bytes = g_unichar_to_utf8(c, NULL);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
169 memmove(s, s + bytes, len + 1 - bytes);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
170 }
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
171
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
172 static void gaim_cmd_strip_cmd_from_markup(char *markup)
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
173 {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
174 guint len = strlen(markup);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
175 char *s = markup;
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
176
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
177 while (*s) {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
178 gunichar c = g_utf8_get_char(s);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
179
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
180 if (c == '<') {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
181 s = strchr(s, '>');
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
182 if (!s)
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
183 return;
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
184 } else if (g_unichar_isspace(c)) {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
185 gaim_cmd_strip_current_char(c, s, len - (s - markup));
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
186 return;
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
187 } else {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
188 gaim_cmd_strip_current_char(c, s, len - (s - markup));
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
189 continue;
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
190 }
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
191 s = g_utf8_next_char(s);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
192 }
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
193 }
9597
d6f398e80b32 [gaim-migrate @ 10440]
Tim Ringenbach <marv@pidgin.im>
parents: 9428
diff changeset
194
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
195 GaimCmdStatus gaim_cmd_do_command(GaimConversation *conv, const gchar *cmdline,
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
196 const gchar *markup, gchar **error)
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
197 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
198 GaimCmd *c;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
199 GList *l;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
200 gchar *err = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
201 gboolean is_im;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
202 gboolean found = FALSE, tried_cmd = FALSE, right_type = FALSE, right_prpl = FALSE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
203 const gchar *prpl_id;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
204 gchar **args = NULL;
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
205 gchar *cmd, *rest, *mrest;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
206 GaimCmdRet ret = GAIM_CMD_RET_CONTINUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
207
9149
108a0300135d [gaim-migrate @ 9933]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
208 *error = NULL;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
209 prpl_id = gaim_account_get_protocol_id(gaim_conversation_get_account(conv));
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
210
11338
17142948653e [gaim-migrate @ 13551]
Mark Doliner <mark@kingant.net>
parents: 10504
diff changeset
211 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM)
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212 is_im = TRUE;
11338
17142948653e [gaim-migrate @ 13551]
Mark Doliner <mark@kingant.net>
parents: 10504
diff changeset
213 else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT)
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
214 is_im = FALSE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
215 else
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
216 return GAIM_CMD_STATUS_FAILED;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
217
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
218 rest = strchr(cmdline, ' ');
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
219 if (rest) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
220 cmd = g_strndup(cmdline, rest - cmdline);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
221 rest++;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
222 } else {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
223 cmd = g_strdup(cmdline);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
224 rest = "";
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
225 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
226
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
227 mrest = g_strdup(markup);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
228 gaim_cmd_strip_cmd_from_markup(mrest);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
229
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
230 for (l = cmds; l; l = l->next) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
231 c = l->data;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
232
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
233 if (strcmp(c->cmd, cmd) != 0)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
234 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
235
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
236 found = TRUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
237
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
238 if (is_im)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
239 if (!(c->flags & GAIM_CMD_FLAG_IM))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
240 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
241 if (!is_im)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
242 if (!(c->flags & GAIM_CMD_FLAG_CHAT))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
243 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
244
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
245 right_type = TRUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
246
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
247 if ((c->flags & GAIM_CMD_FLAG_PRPL_ONLY) && c->prpl_id &&
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
248 (strcmp(c->prpl_id, prpl_id) != 0))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
249 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
250
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
251 right_prpl = TRUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
252
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
253 /* this checks the allow bad args flag for us */
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
254 if (!gaim_cmd_parse_args(c, rest, mrest, &args)) {
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 12014
diff changeset
255 g_strfreev(args);
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
256 args = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
257 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
258 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
259
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
260 tried_cmd = TRUE;
9597
d6f398e80b32 [gaim-migrate @ 10440]
Tim Ringenbach <marv@pidgin.im>
parents: 9428
diff changeset
261 ret = c->func(conv, cmd, args, &err, c->data);
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
262 if (ret == GAIM_CMD_RET_CONTINUE) {
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 12014
diff changeset
263 g_free(err);
9149
108a0300135d [gaim-migrate @ 9933]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
264 err = NULL;
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 12014
diff changeset
265 g_strfreev(args);
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
266 args = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
267 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
268 } else {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
269 break;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
270 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
271
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
272 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
273
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 12014
diff changeset
274 g_strfreev(args);
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
275 g_free(cmd);
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
276 g_free(mrest);
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
277
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
278 if (!found)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
279 return GAIM_CMD_STATUS_NOT_FOUND;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
280
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
281 if (!right_type)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
282 return GAIM_CMD_STATUS_WRONG_TYPE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
283 if (!right_prpl)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
284 return GAIM_CMD_STATUS_WRONG_PRPL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
285 if (!tried_cmd)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
286 return GAIM_CMD_STATUS_WRONG_ARGS;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
287
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
288 if (ret == GAIM_CMD_RET_OK) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
289 return GAIM_CMD_STATUS_OK;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
290 } else {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
291 *error = err;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
292 if (ret == GAIM_CMD_RET_CONTINUE)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
293 return GAIM_CMD_STATUS_NOT_FOUND;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
294 else
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
295 return GAIM_CMD_STATUS_FAILED;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
296 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
297
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
298 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
299
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
300
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
301 GList *gaim_cmd_list(GaimConversation *conv)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
302 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
303 GList *ret = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
304 GaimCmd *c;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
305 GList *l;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
306
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
307 for (l = cmds; l; l = l->next) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
308 c = l->data;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
309
11338
17142948653e [gaim-migrate @ 13551]
Mark Doliner <mark@kingant.net>
parents: 10504
diff changeset
310 if (conv && (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM))
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
311 if (!(c->flags & GAIM_CMD_FLAG_IM))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
312 continue;
11338
17142948653e [gaim-migrate @ 13551]
Mark Doliner <mark@kingant.net>
parents: 10504
diff changeset
313 if (conv && (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT))
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
314 if (!(c->flags & GAIM_CMD_FLAG_CHAT))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
315 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
316
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
317 if (conv && (c->flags & GAIM_CMD_FLAG_PRPL_ONLY) && c->prpl_id &&
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
318 (strcmp(c->prpl_id, gaim_account_get_protocol_id(gaim_conversation_get_account(conv))) != 0))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
319 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
320
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
321 ret = g_list_append(ret, c->cmd);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
322 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
323
12014
bdf8081b1bc1 [gaim-migrate @ 14307]
Mark Doliner <mark@kingant.net>
parents: 11338
diff changeset
324 ret = g_list_sort(ret, (GCompareFunc)strcmp);
bdf8081b1bc1 [gaim-migrate @ 14307]
Mark Doliner <mark@kingant.net>
parents: 11338
diff changeset
325
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
326 return ret;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
327 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
328
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
329
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
330 GList *gaim_cmd_help(GaimConversation *conv, const gchar *cmd)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
331 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
332 GList *ret = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
333 GaimCmd *c;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
334 GList *l;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
335
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
336 for (l = cmds; l; l = l->next) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
337 c = l->data;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
338
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
339 if (cmd && (strcmp(cmd, c->cmd) != 0))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
340 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
341
11338
17142948653e [gaim-migrate @ 13551]
Mark Doliner <mark@kingant.net>
parents: 10504
diff changeset
342 if (conv && (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM))
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
343 if (!(c->flags & GAIM_CMD_FLAG_IM))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
344 continue;
11338
17142948653e [gaim-migrate @ 13551]
Mark Doliner <mark@kingant.net>
parents: 10504
diff changeset
345 if (conv && (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT))
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
346 if (!(c->flags & GAIM_CMD_FLAG_CHAT))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
347 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
348
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
349 if (conv && (c->flags & GAIM_CMD_FLAG_PRPL_ONLY) && c->prpl_id &&
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
350 (strcmp(c->prpl_id, gaim_account_get_protocol_id(gaim_conversation_get_account(conv))) != 0))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
351 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
352
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
353 ret = g_list_append(ret, c->help);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
354 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
355
12014
bdf8081b1bc1 [gaim-migrate @ 14307]
Mark Doliner <mark@kingant.net>
parents: 11338
diff changeset
356 ret = g_list_sort(ret, (GCompareFunc)strcmp);
bdf8081b1bc1 [gaim-migrate @ 14307]
Mark Doliner <mark@kingant.net>
parents: 11338
diff changeset
357
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
358 return ret;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
359 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
360