annotate src/cmds.c @ 12643:29c034547358

[gaim-migrate @ 14980] This allows sametime to compile if you have the libmeanwhile devel package. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Fri, 23 Dec 2005 18:33:52 +0000
parents bdf8081b1bc1
children 8bda65b88e49
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;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
74 c->prpl_id = prpl_id ? g_strdup(prpl_id) : NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
75 c->func = func;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
76 c->help = helpstr ? g_strdup(helpstr) : NULL;
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);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
88 if (c->prpl_id)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
89 g_free(c->prpl_id);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
90 if (c->help)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
91 g_free(c->help);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
92
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
93 g_free(c);
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
9343
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
96 void gaim_cmd_unregister(GaimCmdId id)
9130
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 GaimCmd *c;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
99 GList *l;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
100
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
101 for (l = cmds; l; l = l->next) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
102 c = l->data;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
103
9343
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
104 if (c->id == id) {
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
105 cmds = g_list_remove(cmds, c);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
106 gaim_cmd_free(c);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
107 return;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
108 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
109 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
110 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
111
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
112 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
113 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
114 int i;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
115 const char *end, *cur;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
116
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
117 *args = g_new0(char *, strlen(cmd->args) + 1);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
118
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
119 cur = s;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
120
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
121 for (i = 0; cmd->args[i]; i++) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
122 if (!*cur)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
123 return (cmd->flags & GAIM_CMD_FLAG_ALLOW_WRONG_ARGS);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
124
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
125 switch (cmd->args[i]) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
126 case 'w':
9428
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
127 if (!(end = strchr(cur, ' '))) {
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
128 end = cur + strlen(cur);
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
129 (*args)[i] = g_strndup(cur, end - cur);
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
130 cur = end;
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
131 } else {
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
132 (*args)[i] = g_strndup(cur, end - cur);
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
133 cur = end + 1;
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
134 }
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
135 break;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
136 case 'W':
9428
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
137 if (!(end = strchr(cur, ' '))) {
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
138 end = cur + strlen(cur);
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
139 (*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
140 cur = end;
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
141 } else {
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
142 (*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
143 cur = end +1;
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
144 }
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
145 break;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
146 case 's':
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
147 (*args)[i] = g_strdup(cur);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
148 cur = cur + strlen(cur);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
149 break;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
150 case 'S':
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
151 (*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
152 cur = cur + strlen(cur);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
153 break;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
154 }
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 if (*cur)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
158 return (cmd->flags & GAIM_CMD_FLAG_ALLOW_WRONG_ARGS);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
159
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
160 return TRUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
161 }
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 static void gaim_cmd_free_args(gchar **args)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
164 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
165 int i;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
166
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
167 for (i = 0; args[i]; i++)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
168 g_free(args[i]);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
169 g_free(args);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
170 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
171
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
172 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
173 {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
174 int bytes;
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
176 bytes = g_unichar_to_utf8(c, NULL);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
177 memmove(s, s + bytes, len + 1 - bytes);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
178 }
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 static void gaim_cmd_strip_cmd_from_markup(char *markup)
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
181 {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
182 guint len = strlen(markup);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
183 char *s = markup;
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
184
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
185 while (*s) {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
186 gunichar c = g_utf8_get_char(s);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
187
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
188 if (c == '<') {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
189 s = strchr(s, '>');
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
190 if (!s)
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
191 return;
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
192 } else if (g_unichar_isspace(c)) {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
193 gaim_cmd_strip_current_char(c, s, len - (s - markup));
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
194 return;
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
195 } else {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
196 gaim_cmd_strip_current_char(c, s, len - (s - markup));
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
197 continue;
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
198 }
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
199 s = g_utf8_next_char(s);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
200 }
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
201 }
9597
d6f398e80b32 [gaim-migrate @ 10440]
Tim Ringenbach <marv@pidgin.im>
parents: 9428
diff changeset
202
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
203 GaimCmdStatus gaim_cmd_do_command(GaimConversation *conv, const gchar *cmdline,
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
204 const gchar *markup, gchar **error)
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
205 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
206 GaimCmd *c;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
207 GList *l;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
208 gchar *err = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
209 gboolean is_im;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
210 gboolean found = FALSE, tried_cmd = FALSE, right_type = FALSE, right_prpl = FALSE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
211 const gchar *prpl_id;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212 gchar **args = NULL;
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
213 gchar *cmd, *rest, *mrest;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
214 GaimCmdRet ret = GAIM_CMD_RET_CONTINUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
215
9149
108a0300135d [gaim-migrate @ 9933]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
216 *error = NULL;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
217 prpl_id = gaim_account_get_protocol_id(gaim_conversation_get_account(conv));
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
218
11338
17142948653e [gaim-migrate @ 13551]
Mark Doliner <mark@kingant.net>
parents: 10504
diff changeset
219 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM)
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
220 is_im = TRUE;
11338
17142948653e [gaim-migrate @ 13551]
Mark Doliner <mark@kingant.net>
parents: 10504
diff changeset
221 else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT)
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
222 is_im = FALSE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
223 else
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
224 return GAIM_CMD_STATUS_FAILED;
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 rest = strchr(cmdline, ' ');
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
227 if (rest) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
228 cmd = g_strndup(cmdline, rest - cmdline);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
229 rest++;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
230 } else {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
231 cmd = g_strdup(cmdline);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
232 rest = "";
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
233 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
234
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
235 mrest = g_strdup(markup);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
236 gaim_cmd_strip_cmd_from_markup(mrest);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
237
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
238 for (l = cmds; l; l = l->next) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
239 c = l->data;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
240
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
241 if (strcmp(c->cmd, cmd) != 0)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
242 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
243
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
244 found = TRUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
245
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
246 if (is_im)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
247 if (!(c->flags & GAIM_CMD_FLAG_IM))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
248 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
249 if (!is_im)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
250 if (!(c->flags & GAIM_CMD_FLAG_CHAT))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
251 continue;
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 right_type = TRUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
254
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
255 if ((c->flags & GAIM_CMD_FLAG_PRPL_ONLY) && c->prpl_id &&
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
256 (strcmp(c->prpl_id, prpl_id) != 0))
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 right_prpl = TRUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
260
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
261 /* this checks the allow bad args flag for us */
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
262 if (!gaim_cmd_parse_args(c, rest, mrest, &args)) {
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
263 gaim_cmd_free_args(args);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
264 args = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
265 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
266 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
267
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
268 tried_cmd = TRUE;
9597
d6f398e80b32 [gaim-migrate @ 10440]
Tim Ringenbach <marv@pidgin.im>
parents: 9428
diff changeset
269 ret = c->func(conv, cmd, args, &err, c->data);
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
270 if (ret == GAIM_CMD_RET_CONTINUE) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
271 if (err)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
272 g_free(err);
9149
108a0300135d [gaim-migrate @ 9933]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
273 err = NULL;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
274 gaim_cmd_free_args(args);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
275 args = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
276 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
277 } else {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
278 break;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
279 }
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 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
282
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
283 if (args)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
284 gaim_cmd_free_args(args);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
285 g_free(cmd);
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
286 g_free(mrest);
9130
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 (!found)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
289 return GAIM_CMD_STATUS_NOT_FOUND;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
290
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
291 if (!right_type)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
292 return GAIM_CMD_STATUS_WRONG_TYPE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
293 if (!right_prpl)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
294 return GAIM_CMD_STATUS_WRONG_PRPL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
295 if (!tried_cmd)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
296 return GAIM_CMD_STATUS_WRONG_ARGS;
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 if (ret == GAIM_CMD_RET_OK) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
299 return GAIM_CMD_STATUS_OK;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
300 } else {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
301 *error = err;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
302 if (ret == GAIM_CMD_RET_CONTINUE)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
303 return GAIM_CMD_STATUS_NOT_FOUND;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
304 else
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
305 return GAIM_CMD_STATUS_FAILED;
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
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
308 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
309
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
310
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
311 GList *gaim_cmd_list(GaimConversation *conv)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
312 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
313 GList *ret = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
314 GaimCmd *c;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
315 GList *l;
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 for (l = cmds; l; l = l->next) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
318 c = l->data;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
319
11338
17142948653e [gaim-migrate @ 13551]
Mark Doliner <mark@kingant.net>
parents: 10504
diff changeset
320 if (conv && (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM))
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
321 if (!(c->flags & GAIM_CMD_FLAG_IM))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
322 continue;
11338
17142948653e [gaim-migrate @ 13551]
Mark Doliner <mark@kingant.net>
parents: 10504
diff changeset
323 if (conv && (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT))
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
324 if (!(c->flags & GAIM_CMD_FLAG_CHAT))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
325 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
326
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
327 if (conv && (c->flags & GAIM_CMD_FLAG_PRPL_ONLY) && c->prpl_id &&
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
328 (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
329 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
330
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
331 ret = g_list_append(ret, c->cmd);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
332 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
333
12014
bdf8081b1bc1 [gaim-migrate @ 14307]
Mark Doliner <mark@kingant.net>
parents: 11338
diff changeset
334 ret = g_list_sort(ret, (GCompareFunc)strcmp);
bdf8081b1bc1 [gaim-migrate @ 14307]
Mark Doliner <mark@kingant.net>
parents: 11338
diff changeset
335
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
336 return ret;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
337 }
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
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
340 GList *gaim_cmd_help(GaimConversation *conv, const gchar *cmd)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
341 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
342 GList *ret = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
343 GaimCmd *c;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
344 GList *l;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
345
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
346 for (l = cmds; l; l = l->next) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
347 c = l->data;
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 (cmd && (strcmp(cmd, c->cmd) != 0))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
350 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
351
11338
17142948653e [gaim-migrate @ 13551]
Mark Doliner <mark@kingant.net>
parents: 10504
diff changeset
352 if (conv && (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM))
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
353 if (!(c->flags & GAIM_CMD_FLAG_IM))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
354 continue;
11338
17142948653e [gaim-migrate @ 13551]
Mark Doliner <mark@kingant.net>
parents: 10504
diff changeset
355 if (conv && (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT))
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
356 if (!(c->flags & GAIM_CMD_FLAG_CHAT))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
357 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
358
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
359 if (conv && (c->flags & GAIM_CMD_FLAG_PRPL_ONLY) && c->prpl_id &&
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
360 (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
361 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
362
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
363 ret = g_list_append(ret, c->help);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
364 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
365
12014
bdf8081b1bc1 [gaim-migrate @ 14307]
Mark Doliner <mark@kingant.net>
parents: 11338
diff changeset
366 ret = g_list_sort(ret, (GCompareFunc)strcmp);
bdf8081b1bc1 [gaim-migrate @ 14307]
Mark Doliner <mark@kingant.net>
parents: 11338
diff changeset
367
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
368 return ret;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
369 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
370