Sat, 19 Oct 2019 13:04:53 +0300
Set GList to NULL after free
|
20147
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
1 | /* Copyright (C) 2003-2004 Timothy Ringenbach <omarvo@hotmail.com |
| 9130 | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify | |
| 4 | * it under the terms of the GNU General Public License as published by | |
| 5 | * the Free Software Foundation; either version 2 of the License, or | |
| 6 | * (at your option) any later version. | |
| 7 | * | |
| 8 | * This program is distributed in the hope that it will be useful, | |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11 | * GNU General Public License for more details. | |
| 12 | * | |
| 13 | * You should have received a copy of the GNU General Public License | |
| 14 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18265
diff
changeset
|
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 9130 | 16 | * |
| 17 | */ | |
| 18 | ||
|
18265
9f26190d7f46
Move the define in internal.h instead.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15884
diff
changeset
|
19 | #include "internal.h" |
|
9f26190d7f46
Move the define in internal.h instead.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15884
diff
changeset
|
20 | |
| 9130 | 21 | #include "account.h" |
| 9175 | 22 | #include "util.h" |
| 9130 | 23 | #include "cmds.h" |
| 24 | ||
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
25 | static PurpleCommandsUiOps *cmds_ui_ops = NULL; |
| 9130 | 26 | static GList *cmds = NULL; |
| 27 | static guint next_id = 1; | |
| 28 | ||
|
39556
622bf98df0ac
Remove unnecessary struct tags.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37903
diff
changeset
|
29 | typedef struct { |
| 15884 | 30 | PurpleCmdId id; |
| 9130 | 31 | gchar *cmd; |
| 32 | gchar *args; | |
| 15884 | 33 | PurpleCmdPriority priority; |
| 34 | PurpleCmdFlag flags; | |
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
35 | gchar *protocol_id; |
| 15884 | 36 | PurpleCmdFunc func; |
| 9130 | 37 | gchar *help; |
| 9597 | 38 | void *data; |
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
39 | } PurpleCmd; |
| 9130 | 40 | |
| 41 | ||
| 15884 | 42 | static gint cmds_compare_func(const PurpleCmd *a, const PurpleCmd *b) |
| 9130 | 43 | { |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9597
diff
changeset
|
44 | if (a->priority > b->priority) |
| 9130 | 45 | return -1; |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9597
diff
changeset
|
46 | else if (a->priority < b->priority) |
| 9130 | 47 | return 1; |
| 48 | else return 0; | |
| 49 | } | |
| 50 | ||
| 15884 | 51 | PurpleCmdId purple_cmd_register(const gchar *cmd, const gchar *args, |
| 52 | PurpleCmdPriority p, PurpleCmdFlag f, | |
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
53 | const gchar *protocol_id, PurpleCmdFunc func, |
| 9597 | 54 | const gchar *helpstr, void *data) |
| 9130 | 55 | { |
| 15884 | 56 | PurpleCmdId id; |
| 57 | PurpleCmd *c; | |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
58 | PurpleCommandsUiOps *ops; |
| 9130 | 59 | |
| 9343 | 60 | g_return_val_if_fail(cmd != NULL && *cmd != '\0', 0); |
| 61 | g_return_val_if_fail(args != NULL, 0); | |
| 62 | g_return_val_if_fail(func != NULL, 0); | |
| 9130 | 63 | |
| 9343 | 64 | id = next_id++; |
| 9130 | 65 | |
| 15884 | 66 | c = g_new0(PurpleCmd, 1); |
| 9343 | 67 | c->id = id; |
| 9130 | 68 | c->cmd = g_strdup(cmd); |
| 69 | c->args = g_strdup(args); | |
| 70 | c->priority = p; | |
| 71 | c->flags = f; | |
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
72 | c->protocol_id = g_strdup(protocol_id); |
| 9130 | 73 | c->func = func; |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
74 | c->help = g_strdup(helpstr); |
| 9597 | 75 | c->data = data; |
| 9130 | 76 | |
| 77 | cmds = g_list_insert_sorted(cmds, c, (GCompareFunc)cmds_compare_func); | |
| 78 | ||
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
79 | ops = purple_cmds_get_ui_ops(); |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
80 | if (ops && ops->register_command) |
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
81 | ops->register_command(cmd, p, f, protocol_id, helpstr, c->id); |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
82 | |
|
23555
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
83 | purple_signal_emit(purple_cmds_get_handle(), "cmd-added", cmd, p, f); |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
84 | |
| 9130 | 85 | return id; |
| 86 | } | |
| 87 | ||
| 15884 | 88 | static void purple_cmd_free(PurpleCmd *c) |
| 9130 | 89 | { |
| 90 | g_free(c->cmd); | |
| 91 | g_free(c->args); | |
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
92 | g_free(c->protocol_id); |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
93 | g_free(c->help); |
| 9130 | 94 | g_free(c); |
| 95 | } | |
| 96 | ||
| 15884 | 97 | void purple_cmd_unregister(PurpleCmdId id) |
| 9130 | 98 | { |
| 15884 | 99 | PurpleCmd *c; |
| 9130 | 100 | GList *l; |
| 101 | ||
| 102 | for (l = cmds; l; l = l->next) { | |
| 103 | c = l->data; | |
| 104 | ||
| 9343 | 105 | if (c->id == id) { |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
106 | PurpleCommandsUiOps *ops = purple_cmds_get_ui_ops(); |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
107 | if (ops && ops->unregister_command) |
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
108 | ops->unregister_command(c->cmd, c->protocol_id); |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
109 | |
| 9130 | 110 | cmds = g_list_remove(cmds, c); |
|
23555
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
111 | purple_signal_emit(purple_cmds_get_handle(), "cmd-removed", c->cmd); |
| 15884 | 112 | purple_cmd_free(c); |
| 9130 | 113 | return; |
| 114 | } | |
| 115 | } | |
| 116 | } | |
| 117 | ||
|
35458
385156e1b493
Fix some gtk-doc warnings from account to connection
Ankit Vani <a@nevitus.org>
parents:
35454
diff
changeset
|
118 | /* |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
119 | * This sets args to a NULL-terminated array of strings. It should |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
120 | * be freed using g_strfreev(). |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
121 | */ |
| 15884 | 122 | static gboolean purple_cmd_parse_args(PurpleCmd *cmd, const gchar *s, const gchar *m, gchar ***args) |
| 9130 | 123 | { |
| 124 | int i; | |
| 125 | const char *end, *cur; | |
| 126 | ||
| 127 | *args = g_new0(char *, strlen(cmd->args) + 1); | |
| 128 | ||
| 129 | cur = s; | |
| 130 | ||
| 131 | for (i = 0; cmd->args[i]; i++) { | |
| 132 | if (!*cur) | |
| 15884 | 133 | return (cmd->flags & PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS); |
| 9130 | 134 | |
| 135 | switch (cmd->args[i]) { | |
| 136 | case 'w': | |
| 9428 | 137 | if (!(end = strchr(cur, ' '))) { |
| 138 | end = cur + strlen(cur); | |
| 139 | (*args)[i] = g_strndup(cur, end - cur); | |
| 140 | cur = end; | |
| 141 | } else { | |
| 142 | (*args)[i] = g_strndup(cur, end - cur); | |
| 143 | cur = end + 1; | |
| 144 | } | |
| 9130 | 145 | break; |
| 146 | case 'W': | |
| 9428 | 147 | if (!(end = strchr(cur, ' '))) { |
| 148 | end = cur + strlen(cur); | |
| 15884 | 149 | (*args)[i] = purple_markup_slice(m, g_utf8_pointer_to_offset(s, cur), g_utf8_pointer_to_offset(s, end)); |
| 9428 | 150 | cur = end; |
| 151 | } else { | |
| 15884 | 152 | (*args)[i] = purple_markup_slice(m, g_utf8_pointer_to_offset(s, cur), g_utf8_pointer_to_offset(s, end)); |
| 9428 | 153 | cur = end +1; |
| 154 | } | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
155 | break; |
| 9130 | 156 | case 's': |
| 157 | (*args)[i] = g_strdup(cur); | |
| 158 | cur = cur + strlen(cur); | |
| 159 | break; | |
| 160 | case 'S': | |
| 15884 | 161 | (*args)[i] = purple_markup_slice(m, g_utf8_pointer_to_offset(s, cur), g_utf8_strlen(cur, -1) + 1); |
| 9130 | 162 | cur = cur + strlen(cur); |
| 163 | break; | |
| 164 | } | |
| 165 | } | |
| 166 | ||
| 167 | if (*cur) | |
| 15884 | 168 | return (cmd->flags & PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS); |
| 9130 | 169 | |
| 170 | return TRUE; | |
| 171 | } | |
| 172 | ||
| 15884 | 173 | static void purple_cmd_strip_current_char(gunichar c, char *s, guint len) |
| 9175 | 174 | { |
| 175 | int bytes; | |
| 176 | ||
| 177 | bytes = g_unichar_to_utf8(c, NULL); | |
| 178 | memmove(s, s + bytes, len + 1 - bytes); | |
| 179 | } | |
| 180 | ||
| 15884 | 181 | static void purple_cmd_strip_cmd_from_markup(char *markup) |
| 9175 | 182 | { |
| 183 | guint len = strlen(markup); | |
| 184 | char *s = markup; | |
| 185 | ||
| 186 | while (*s) { | |
| 187 | gunichar c = g_utf8_get_char(s); | |
| 188 | ||
| 189 | if (c == '<') { | |
| 190 | s = strchr(s, '>'); | |
| 191 | if (!s) | |
| 192 | return; | |
| 193 | } else if (g_unichar_isspace(c)) { | |
| 15884 | 194 | purple_cmd_strip_current_char(c, s, len - (s - markup)); |
| 9175 | 195 | return; |
| 196 | } else { | |
| 15884 | 197 | purple_cmd_strip_current_char(c, s, len - (s - markup)); |
| 9175 | 198 | continue; |
| 199 | } | |
| 200 | s = g_utf8_next_char(s); | |
| 201 | } | |
| 202 | } | |
| 9597 | 203 | |
| 15884 | 204 | PurpleCmdStatus purple_cmd_do_command(PurpleConversation *conv, const gchar *cmdline, |
| 9175 | 205 | const gchar *markup, gchar **error) |
| 9130 | 206 | { |
| 15884 | 207 | PurpleCmd *c; |
| 9130 | 208 | GList *l; |
| 209 | gchar *err = NULL; | |
|
34645
a04c721bebf1
Refactored accounts, blist, cmds and connection to use the GObject conversation API
Ankit Vani <a@nevitus.org>
parents:
32438
diff
changeset
|
210 | gboolean is_im = TRUE; |
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
211 | gboolean found = FALSE, tried_cmd = FALSE, right_type = FALSE, right_protocol = FALSE; |
|
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
212 | const gchar *protocol_id; |
| 9130 | 213 | gchar **args = NULL; |
| 9175 | 214 | gchar *cmd, *rest, *mrest; |
| 15884 | 215 | PurpleCmdRet ret = PURPLE_CMD_RET_CONTINUE; |
| 9130 | 216 | |
| 9149 | 217 | *error = NULL; |
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
218 | protocol_id = purple_account_get_protocol_id(purple_conversation_get_account(conv)); |
| 9130 | 219 | |
|
34645
a04c721bebf1
Refactored accounts, blist, cmds and connection to use the GObject conversation API
Ankit Vani <a@nevitus.org>
parents:
32438
diff
changeset
|
220 | if (PURPLE_IS_CHAT_CONVERSATION(conv)) |
| 9130 | 221 | is_im = FALSE; |
| 222 | ||
| 223 | rest = strchr(cmdline, ' '); | |
| 224 | if (rest) { | |
| 225 | cmd = g_strndup(cmdline, rest - cmdline); | |
| 226 | rest++; | |
| 227 | } else { | |
| 228 | cmd = g_strdup(cmdline); | |
| 229 | rest = ""; | |
| 230 | } | |
| 231 | ||
| 9175 | 232 | mrest = g_strdup(markup); |
| 15884 | 233 | purple_cmd_strip_cmd_from_markup(mrest); |
| 9175 | 234 | |
| 9130 | 235 | for (l = cmds; l; l = l->next) { |
| 236 | c = l->data; | |
| 237 | ||
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
23555
diff
changeset
|
238 | if (!purple_strequal(c->cmd, cmd)) |
| 9130 | 239 | continue; |
| 240 | ||
| 241 | found = TRUE; | |
| 242 | ||
| 243 | if (is_im) | |
| 15884 | 244 | if (!(c->flags & PURPLE_CMD_FLAG_IM)) |
| 9130 | 245 | continue; |
| 246 | if (!is_im) | |
| 15884 | 247 | if (!(c->flags & PURPLE_CMD_FLAG_CHAT)) |
| 9130 | 248 | continue; |
| 249 | ||
| 250 | right_type = TRUE; | |
| 251 | ||
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
252 | if ((c->flags & PURPLE_CMD_FLAG_PROTOCOL_ONLY) && |
|
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
253 | !purple_strequal(c->protocol_id, protocol_id)) |
| 9130 | 254 | continue; |
| 255 | ||
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
256 | right_protocol = TRUE; |
| 9130 | 257 | |
| 258 | /* this checks the allow bad args flag for us */ | |
| 15884 | 259 | if (!purple_cmd_parse_args(c, rest, mrest, &args)) { |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
260 | g_strfreev(args); |
| 9130 | 261 | args = NULL; |
| 262 | continue; | |
| 263 | } | |
| 264 | ||
| 265 | tried_cmd = TRUE; | |
| 9597 | 266 | ret = c->func(conv, cmd, args, &err, c->data); |
| 15884 | 267 | if (ret == PURPLE_CMD_RET_CONTINUE) { |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
268 | g_free(err); |
| 9149 | 269 | err = NULL; |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
270 | g_strfreev(args); |
| 9130 | 271 | args = NULL; |
| 272 | continue; | |
| 273 | } else { | |
| 274 | break; | |
| 275 | } | |
| 276 | ||
| 277 | } | |
| 278 | ||
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12014
diff
changeset
|
279 | g_strfreev(args); |
| 9130 | 280 | g_free(cmd); |
| 9175 | 281 | g_free(mrest); |
| 9130 | 282 | |
| 283 | if (!found) | |
| 15884 | 284 | return PURPLE_CMD_STATUS_NOT_FOUND; |
| 9130 | 285 | |
| 286 | if (!right_type) | |
| 15884 | 287 | return PURPLE_CMD_STATUS_WRONG_TYPE; |
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
288 | if (!right_protocol) |
|
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
289 | return PURPLE_CMD_STATUS_WRONG_PROTOCOL; |
| 9130 | 290 | if (!tried_cmd) |
| 15884 | 291 | return PURPLE_CMD_STATUS_WRONG_ARGS; |
| 9130 | 292 | |
| 15884 | 293 | if (ret == PURPLE_CMD_RET_OK) { |
| 294 | return PURPLE_CMD_STATUS_OK; | |
| 9130 | 295 | } else { |
| 296 | *error = err; | |
| 15884 | 297 | if (ret == PURPLE_CMD_RET_CONTINUE) |
| 298 | return PURPLE_CMD_STATUS_NOT_FOUND; | |
| 9130 | 299 | else |
| 15884 | 300 | return PURPLE_CMD_STATUS_FAILED; |
| 9130 | 301 | } |
| 302 | ||
| 303 | } | |
| 304 | ||
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
305 | gboolean purple_cmd_execute(PurpleCmdId id, PurpleConversation *conv, |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
306 | const gchar *cmdline) |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
307 | { |
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
308 | PurpleCmd *cmd = NULL; |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
309 | PurpleCmdRet ret = PURPLE_CMD_RET_CONTINUE; |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
310 | GList *l = NULL; |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
311 | gchar *err = NULL; |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
312 | gchar **args = NULL; |
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
313 | |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
314 | for(l = cmds; l; l = l->next) { |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
315 | cmd = (PurpleCmd*)l->data; |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
316 | |
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
317 | if(cmd->id == id) { |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
318 | break; |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
319 | } |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
320 | cmd = NULL; |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
321 | } |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
322 | if(cmd == NULL) { |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
323 | return FALSE; |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
324 | } |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
325 | |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
326 | if (PURPLE_IS_IM_CONVERSATION(conv)) { |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
327 | if (!(cmd->flags & PURPLE_CMD_FLAG_IM)) |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
328 | return FALSE; |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
329 | } |
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
330 | else if (PURPLE_IS_CHAT_CONVERSATION(conv)) { |
|
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
331 | if (!(cmd->flags & PURPLE_CMD_FLAG_CHAT)) |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
332 | return FALSE; |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
333 | } |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
334 | else |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
335 | return FALSE; |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
336 | |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
337 | /* XXX: Don't worry much about the markup version of the command |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
338 | line, there's not a single use case... */ |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
339 | /* this checks the allow bad args flag for us */ |
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
340 | if (!purple_cmd_parse_args(cmd, cmdline, cmdline, &args)) { |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
341 | g_strfreev(args); |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
342 | return FALSE; |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
343 | } |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
344 | |
|
37903
caf372ae8882
Fix up the commands execute stuff
Gary Kramlich <grim@reaperworld.com>
parents:
37901
diff
changeset
|
345 | ret = cmd->func(conv, cmd->cmd, args, &err, cmd->data); |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
346 | |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
347 | g_free(err); |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
348 | g_strfreev(args); |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
349 | |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
350 | return ret == PURPLE_CMD_RET_OK; |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
351 | } |
| 9130 | 352 | |
| 15884 | 353 | GList *purple_cmd_list(PurpleConversation *conv) |
| 9130 | 354 | { |
| 355 | GList *ret = NULL; | |
| 15884 | 356 | PurpleCmd *c; |
| 9130 | 357 | GList *l; |
| 358 | ||
| 359 | for (l = cmds; l; l = l->next) { | |
| 360 | c = l->data; | |
| 361 | ||
|
34645
a04c721bebf1
Refactored accounts, blist, cmds and connection to use the GObject conversation API
Ankit Vani <a@nevitus.org>
parents:
32438
diff
changeset
|
362 | if (conv && PURPLE_IS_IM_CONVERSATION(conv)) |
| 15884 | 363 | if (!(c->flags & PURPLE_CMD_FLAG_IM)) |
| 9130 | 364 | continue; |
|
34645
a04c721bebf1
Refactored accounts, blist, cmds and connection to use the GObject conversation API
Ankit Vani <a@nevitus.org>
parents:
32438
diff
changeset
|
365 | if (conv && PURPLE_IS_CHAT_CONVERSATION(conv)) |
| 15884 | 366 | if (!(c->flags & PURPLE_CMD_FLAG_CHAT)) |
| 9130 | 367 | continue; |
| 368 | ||
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
369 | if (conv && (c->flags & PURPLE_CMD_FLAG_PROTOCOL_ONLY) && |
|
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
370 | !purple_strequal(c->protocol_id, purple_account_get_protocol_id(purple_conversation_get_account(conv)))) |
| 9130 | 371 | continue; |
| 372 | ||
| 373 | ret = g_list_append(ret, c->cmd); | |
| 374 | } | |
| 375 | ||
|
12014
8a45c4f43021
[gaim-migrate @ 14307]
Mark Doliner <markdoliner@pidgin.im>
parents:
11338
diff
changeset
|
376 | ret = g_list_sort(ret, (GCompareFunc)strcmp); |
|
8a45c4f43021
[gaim-migrate @ 14307]
Mark Doliner <markdoliner@pidgin.im>
parents:
11338
diff
changeset
|
377 | |
| 9130 | 378 | return ret; |
| 379 | } | |
| 380 | ||
| 381 | ||
| 15884 | 382 | GList *purple_cmd_help(PurpleConversation *conv, const gchar *cmd) |
| 9130 | 383 | { |
| 384 | GList *ret = NULL; | |
| 15884 | 385 | PurpleCmd *c; |
| 9130 | 386 | GList *l; |
| 387 | ||
| 388 | for (l = cmds; l; l = l->next) { | |
| 389 | c = l->data; | |
| 390 | ||
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
23555
diff
changeset
|
391 | if (cmd && !purple_strequal(cmd, c->cmd)) |
| 9130 | 392 | continue; |
| 393 | ||
|
34645
a04c721bebf1
Refactored accounts, blist, cmds and connection to use the GObject conversation API
Ankit Vani <a@nevitus.org>
parents:
32438
diff
changeset
|
394 | if (conv && PURPLE_IS_IM_CONVERSATION(conv)) |
| 15884 | 395 | if (!(c->flags & PURPLE_CMD_FLAG_IM)) |
| 9130 | 396 | continue; |
|
34645
a04c721bebf1
Refactored accounts, blist, cmds and connection to use the GObject conversation API
Ankit Vani <a@nevitus.org>
parents:
32438
diff
changeset
|
397 | if (conv && PURPLE_IS_CHAT_CONVERSATION(conv)) |
| 15884 | 398 | if (!(c->flags & PURPLE_CMD_FLAG_CHAT)) |
| 9130 | 399 | continue; |
| 400 | ||
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
401 | if (conv && (c->flags & PURPLE_CMD_FLAG_PROTOCOL_ONLY) && |
|
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
34814
diff
changeset
|
402 | !purple_strequal(c->protocol_id, purple_account_get_protocol_id(purple_conversation_get_account(conv)))) |
| 9130 | 403 | continue; |
| 404 | ||
| 405 | ret = g_list_append(ret, c->help); | |
| 406 | } | |
| 407 | ||
|
12014
8a45c4f43021
[gaim-migrate @ 14307]
Mark Doliner <markdoliner@pidgin.im>
parents:
11338
diff
changeset
|
408 | ret = g_list_sort(ret, (GCompareFunc)strcmp); |
|
8a45c4f43021
[gaim-migrate @ 14307]
Mark Doliner <markdoliner@pidgin.im>
parents:
11338
diff
changeset
|
409 | |
| 9130 | 410 | return ret; |
| 411 | } | |
| 412 | ||
|
23555
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
413 | gpointer purple_cmds_get_handle(void) |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
414 | { |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
415 | static int handle; |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
416 | return &handle; |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
417 | } |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
418 | |
|
37685
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
419 | void |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
420 | purple_cmds_set_ui_ops(PurpleCommandsUiOps *ops) |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
421 | { |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
422 | cmds_ui_ops = ops; |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
423 | } |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
424 | |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
425 | PurpleCommandsUiOps * |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
426 | purple_cmds_get_ui_ops(void) |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
427 | { |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
428 | /* It is perfectly acceptable for cmds_ui_ops to be NULL; this just |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
429 | * means that the default libpurple implementation will be used. |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
430 | */ |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
431 | return cmds_ui_ops; |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
432 | } |
|
ef161f30f8bc
Add PurpleCommandsUiOps API from instantbird
Florian Quèze <florian@instantbird.org>
parents:
28981
diff
changeset
|
433 | |
|
23555
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
434 | void purple_cmds_init(void) |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
435 | { |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
436 | gpointer handle = purple_cmds_get_handle(); |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
437 | |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
438 | purple_signal_register(handle, "cmd-added", |
|
34814
759ea31715dd
Refactored cmds and connection to use GType instead of PurpleValue
Ankit Vani <a@nevitus.org>
parents:
34645
diff
changeset
|
439 | purple_marshal_VOID__POINTER_INT_INT, G_TYPE_NONE, 3, |
|
759ea31715dd
Refactored cmds and connection to use GType instead of PurpleValue
Ankit Vani <a@nevitus.org>
parents:
34645
diff
changeset
|
440 | G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT); |
|
23555
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
441 | purple_signal_register(handle, "cmd-removed", |
|
34814
759ea31715dd
Refactored cmds and connection to use GType instead of PurpleValue
Ankit Vani <a@nevitus.org>
parents:
34645
diff
changeset
|
442 | purple_marshal_VOID__POINTER, G_TYPE_NONE, 1, |
|
759ea31715dd
Refactored cmds and connection to use GType instead of PurpleValue
Ankit Vani <a@nevitus.org>
parents:
34645
diff
changeset
|
443 | G_TYPE_STRING); |
|
23555
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
444 | } |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
445 | |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
446 | void purple_cmds_uninit(void) |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
447 | { |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
448 | purple_signals_unregister_by_instance(purple_cmds_get_handle()); |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
28981
diff
changeset
|
449 | |
|
40062
d25228fc7b8e
Use g_list_free_full instead of manual iterations
qarkai <qarkai@gmail.com>
parents:
39556
diff
changeset
|
450 | g_list_free_full(cmds, (GDestroyNotify)purple_cmd_free); |
| 40064 | 451 | cmds = NULL; |
|
23555
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
452 | } |
|
82dab41b4163
cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
453 |