author | Myhailo Danylenko <isbear@ukrpost.net> |
Thu, 30 Jun 2011 16:10:03 +0300 | |
changeset 29 | 5b0349cbc6a7 |
parent 24 | 592b7f42ba54 |
child 30 | b60076874691 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* cmd.c -- Send shell command output as messages |
|
3 |
* |
|
4 |
* Copyrigth (C) 2009 Myhailo Danylenko <isbear@ukrpost.net> |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU General Public License as published by |
|
8 |
* the Free Software Foundation; either version 2 of the License, or (at |
|
9 |
* your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but |
|
12 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
* General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
19 |
* USA |
|
20 |
*/ |
|
21 |
||
22 |
#include <stdlib.h> |
|
23 |
#include <glib.h> |
|
24 |
#include <unistd.h> |
|
25 |
#include <errno.h> |
|
18
887d772326a0
Fix compilation warnings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
17
diff
changeset
|
26 |
#include <string.h> |
0 | 27 |
|
8
5771827a4976
Change mcabber headers naming convention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
7
diff
changeset
|
28 |
#include <mcabber/commands.h> |
5771827a4976
Change mcabber headers naming convention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
7
diff
changeset
|
29 |
#include <mcabber/logprint.h> |
5771827a4976
Change mcabber headers naming convention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
7
diff
changeset
|
30 |
#include <mcabber/utils.h> |
5771827a4976
Change mcabber headers naming convention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
7
diff
changeset
|
31 |
#include <mcabber/settings.h> |
5771827a4976
Change mcabber headers naming convention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
7
diff
changeset
|
32 |
#include <mcabber/hbuf.h> |
5771827a4976
Change mcabber headers naming convention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
7
diff
changeset
|
33 |
#include <mcabber/xmpp.h> |
5771827a4976
Change mcabber headers naming convention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
7
diff
changeset
|
34 |
#include <mcabber/roster.h> |
15
891fc0779d50
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
35 |
#include <mcabber/modules.h> |
18
887d772326a0
Fix compilation warnings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
17
diff
changeset
|
36 |
#include <mcabber/hooks.h> |
15
891fc0779d50
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
37 |
|
16
19d13d97b3a1
Use new module struct with api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
38 |
#include "config.h" |
19d13d97b3a1
Use new module struct with api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
39 |
|
24 | 40 |
void mcmd_init (void); |
41 |
void mcmd_uninit (void); |
|
15
891fc0779d50
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
42 |
|
16
19d13d97b3a1
Use new module struct with api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
43 |
#define DESCRIPTION ( \ |
19d13d97b3a1
Use new module struct with api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
44 |
"Sends output of command to buddy\n" \ |
19d13d97b3a1
Use new module struct with api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
45 |
"Recognizes options cmd_shell, cmd_redirect_stderr, cmd_header and cmd_header_inline\n" \ |
19d13d97b3a1
Use new module struct with api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
46 |
"Provides command /cmd" ) |
19d13d97b3a1
Use new module struct with api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
47 |
|
24 | 48 |
static module_info_t info_cmd_dev = { |
49 |
.branch = "dev", |
|
50 |
.api = 20, |
|
16
19d13d97b3a1
Use new module struct with api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
51 |
.version = PROJECT_VERSION, |
19d13d97b3a1
Use new module struct with api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
52 |
.description = DESCRIPTION, |
15
891fc0779d50
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
53 |
.requires = NULL, |
891fc0779d50
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
54 |
.init = mcmd_init, |
891fc0779d50
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
55 |
.uninit = mcmd_uninit, |
16
19d13d97b3a1
Use new module struct with api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
56 |
.next = NULL, |
19d13d97b3a1
Use new module struct with api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
57 |
}; |
19d13d97b3a1
Use new module struct with api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
58 |
|
21
29491118c0dd
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
20
diff
changeset
|
59 |
module_info_t info_cmd = { |
24 | 60 |
.branch = "0.10.1", |
21
29491118c0dd
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
20
diff
changeset
|
61 |
.api = 1, |
29491118c0dd
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
20
diff
changeset
|
62 |
.version = PROJECT_VERSION, |
29491118c0dd
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
20
diff
changeset
|
63 |
.description = DESCRIPTION, |
29491118c0dd
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
20
diff
changeset
|
64 |
.requires = NULL, |
29491118c0dd
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
20
diff
changeset
|
65 |
.init = mcmd_init, |
29491118c0dd
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
20
diff
changeset
|
66 |
.uninit = mcmd_uninit, |
29491118c0dd
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
20
diff
changeset
|
67 |
.next = &info_cmd_dev, |
29491118c0dd
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
20
diff
changeset
|
68 |
}; |
29491118c0dd
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
20
diff
changeset
|
69 |
|
0 | 70 |
typedef struct { |
71 |
gchar *jid; |
|
72 |
GString *input; |
|
5 | 73 |
gchar *subject; |
74 |
guint seq; |
|
0 | 75 |
guint source; |
76 |
GIOChannel *channel; |
|
77 |
} cmd_cb_t; |
|
78 |
||
24 | 79 |
#ifdef MCABBER_API_HAVE_CMD_ID |
20
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
80 |
static gpointer mcmd_cmid = NULL; |
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
81 |
#endif |
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
82 |
|
5 | 83 |
static GSList *cmd_channels = NULL; |
84 |
||
85 |
static gboolean is_room (const gchar *jid) |
|
86 |
{ |
|
87 |
return roster_find (jid, jidsearch, ROSTER_TYPE_ROOM) ? TRUE : FALSE; |
|
88 |
} |
|
89 |
||
90 |
static gboolean cmd_send_msg (const gchar *to, const gchar *subject, const gchar *body) |
|
91 |
{ |
|
92 |
gboolean room = is_room (to); |
|
93 |
gpointer xep184 = NULL; |
|
94 |
gint crypted; |
|
95 |
||
96 |
xmpp_send_msg (to, body, room ? ROSTER_TYPE_ROOM : ROSTER_TYPE_USER, room ? NULL : subject, FALSE /* ? */, &crypted, LM_MESSAGE_SUB_TYPE_NOT_SET, &xep184); |
|
97 |
||
98 |
if (crypted == -1) { |
|
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
99 |
scr_log_print (LPRINT_LOGNORM, "cmd: Encryption error. Message not sent."); |
5 | 100 |
return FALSE; |
101 |
} |
|
102 |
||
6
8e64b6d3302e
Fix outgoing message header displaying
Myhailo Danylenko <isbear@ukrpost.net>
parents:
5
diff
changeset
|
103 |
if (!room) { |
8e64b6d3302e
Fix outgoing message header displaying
Myhailo Danylenko <isbear@ukrpost.net>
parents:
5
diff
changeset
|
104 |
if (subject) { |
8e64b6d3302e
Fix outgoing message header displaying
Myhailo Danylenko <isbear@ukrpost.net>
parents:
5
diff
changeset
|
105 |
gchar *hbody = g_strdup_printf ("[%s]\n%s", subject, body); |
8e64b6d3302e
Fix outgoing message header displaying
Myhailo Danylenko <isbear@ukrpost.net>
parents:
5
diff
changeset
|
106 |
hk_message_out (to, NULL, 0, hbody, crypted, xep184); |
8e64b6d3302e
Fix outgoing message header displaying
Myhailo Danylenko <isbear@ukrpost.net>
parents:
5
diff
changeset
|
107 |
g_free (hbody); |
8e64b6d3302e
Fix outgoing message header displaying
Myhailo Danylenko <isbear@ukrpost.net>
parents:
5
diff
changeset
|
108 |
} else |
8e64b6d3302e
Fix outgoing message header displaying
Myhailo Danylenko <isbear@ukrpost.net>
parents:
5
diff
changeset
|
109 |
hk_message_out (to, NULL, 0, body, crypted, xep184); |
8e64b6d3302e
Fix outgoing message header displaying
Myhailo Danylenko <isbear@ukrpost.net>
parents:
5
diff
changeset
|
110 |
} |
5 | 111 |
|
112 |
return TRUE; |
|
113 |
} |
|
0 | 114 |
|
115 |
static gboolean cmd_reader (GIOChannel *channel, GIOCondition condition, gpointer data) |
|
116 |
{ |
|
117 |
cmd_cb_t *cb = (cmd_cb_t *) data; |
|
118 |
||
119 |
if (condition & (G_IO_IN|G_IO_PRI)) { |
|
5 | 120 |
GIOStatus chstat; |
121 |
static gchar buf[HBB_BLOCKSIZE]; |
|
122 |
gsize endpos; |
|
123 |
GError *error = NULL; |
|
0 | 124 |
|
5 | 125 |
chstat = g_io_channel_read_chars (channel, buf, HBB_BLOCKSIZE, &endpos, &error); |
126 |
||
127 |
if (error) { |
|
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
128 |
scr_log_print (LPRINT_DEBUG, "cmd: Reading error: %s.", error -> message); |
5 | 129 |
g_clear_error (&error); |
130 |
} |
|
0 | 131 |
|
132 |
if (chstat == G_IO_STATUS_ERROR || chstat == G_IO_STATUS_EOF) { |
|
133 |
cb->source = 0; |
|
134 |
return FALSE; // XXX |
|
135 |
} |
|
136 |
||
137 |
if (endpos) { |
|
138 |
GString *input = cb->input; |
|
139 |
gsize bread = 0; |
|
140 |
gsize written = 0; |
|
141 |
gchar *utf8 = NULL; |
|
142 |
||
143 |
g_string_append_len (input, buf, endpos); |
|
144 |
||
11
fafc922963f5
Use xmpp_is_online if available
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
145 |
if (!xmpp_is_online ()) { |
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
146 |
scr_log_print (LPRINT_LOGNORM, "cmd: Connection is not ready, delaying data"); |
0 | 147 |
return TRUE; |
148 |
} |
|
149 |
||
150 |
// usual g_locale_to_utf8 seem to be unable to detect locale charset |
|
151 |
// maybe, proper solution will be to call setlocale on module loading, |
|
152 |
// but mcabber already does this, and I do not want to mess with it |
|
5 | 153 |
utf8 = g_convert (input->str, input->len, LocaleCharSet, "UTF-8", &bread, &written, &error); |
0 | 154 |
|
5 | 155 |
if (error && error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE && bread) { |
0 | 156 |
written = 0; |
5 | 157 |
g_clear_error (&error); |
158 |
utf8 = g_convert (input->str, bread, LocaleCharSet, "UTF-8", &bread, &written, &error); |
|
0 | 159 |
} |
160 |
||
161 |
if (written) { |
|
162 |
gsize sent = 0; |
|
163 |
||
164 |
while (sent < written) { |
|
165 |
gsize len = 0; |
|
166 |
gchar *bbuf = NULL; |
|
5 | 167 |
gchar *subject = NULL; |
0 | 168 |
|
169 |
if (written - sent > HBB_BLOCKSIZE) { |
|
170 |
gchar *c = utf8 + sent + HBB_BLOCKSIZE; |
|
171 |
c = g_utf8_find_prev_char (utf8 + sent, c); |
|
172 |
||
173 |
if (!c) { |
|
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
174 |
scr_log_print (LPRINT_LOGNORM, "cmd: Cannot determine utf8 character end! End of data chunk will be discarded!"); |
0 | 175 |
break; |
176 |
} |
|
177 |
||
178 |
len = c - utf8 - sent; |
|
179 |
bbuf = g_strndup (utf8 + sent, len); |
|
180 |
} |
|
181 |
||
5 | 182 |
cb -> seq += 1; |
0 | 183 |
|
5 | 184 |
if (cb -> subject) |
185 |
subject = g_strdup_printf (cb -> subject, cb -> seq); |
|
0 | 186 |
|
5 | 187 |
if (!cmd_send_msg (cb->jid, subject, len ? bbuf : (utf8 + sent))) |
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
188 |
scr_log_print (LPRINT_LOGNORM, "cmd: Encryption error. Message not sent."); |
0 | 189 |
|
5 | 190 |
if (subject) |
191 |
g_free (subject); |
|
0 | 192 |
|
193 |
if (!len) |
|
194 |
break; |
|
195 |
||
196 |
g_free (bbuf); |
|
197 |
||
198 |
sent += len; |
|
199 |
} |
|
200 |
||
201 |
g_free (utf8); |
|
202 |
||
203 |
g_string_erase (input, 0, bread); |
|
204 |
||
205 |
} else { |
|
206 |
||
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
207 |
scr_log_print (LPRINT_LOGNORM, "cmd: Character conversion error: %s", error->message); |
5 | 208 |
g_error_free (error); |
0 | 209 |
cb->source = 0; |
210 |
return FALSE; |
|
211 |
} |
|
212 |
} |
|
213 |
||
214 |
} else if (condition & (G_IO_ERR|G_IO_NVAL|G_IO_HUP)) { |
|
215 |
cb->source = 0; |
|
216 |
return FALSE; // XXX |
|
217 |
} |
|
218 |
||
219 |
return TRUE; |
|
220 |
} |
|
221 |
||
222 |
static void cmd_destroy_data (gpointer data) |
|
223 |
{ |
|
224 |
cmd_cb_t *cb = (cmd_cb_t *) data; |
|
225 |
||
226 |
cmd_channels = g_slist_remove (cmd_channels, data); |
|
227 |
||
5 | 228 |
if (cb->source) |
229 |
g_source_remove (cb->source); |
|
0 | 230 |
if (cb->channel) |
231 |
g_io_channel_unref (cb->channel); |
|
5 | 232 |
if (cb -> subject) |
233 |
g_free (cb -> subject); |
|
0 | 234 |
g_free (cb->jid); |
235 |
g_free (cb); |
|
236 |
} |
|
237 |
||
238 |
static void do_cmd (char *arg) |
|
239 |
{ |
|
240 |
int fd[2]; |
|
241 |
const char *jid = CURRENT_JID; |
|
242 |
||
243 |
if (!*arg) |
|
244 |
return; |
|
245 |
||
246 |
if (!jid) { |
|
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
247 |
scr_log_print (LPRINT_LOGNORM, "Unsuitable buddy selected."); |
0 | 248 |
return; |
249 |
} |
|
250 |
||
251 |
if (pipe (fd)) { |
|
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
252 |
scr_log_print (LPRINT_LOGNORM, "Cannot create pipe: %s.", strerror (errno)); |
0 | 253 |
return; |
254 |
} |
|
255 |
||
256 |
{ |
|
5 | 257 |
GIOChannel *channel; |
258 |
int res = fork (); |
|
0 | 259 |
|
260 |
if (!res) { |
|
261 |
||
262 |
close (fd[0]); |
|
263 |
dup2 (fd[1], STDOUT_FILENO); |
|
264 |
if (settings_opt_get_int ("cmd_redirect_stderr")) |
|
265 |
dup2 (fd[1], STDERR_FILENO); |
|
266 |
else |
|
267 |
close (STDERR_FILENO); |
|
268 |
close (STDIN_FILENO); |
|
269 |
close (fd[1]); |
|
270 |
||
271 |
{ |
|
272 |
const char *shell = settings_opt_get ("cmd_shell"); |
|
273 |
if (!shell) |
|
274 |
shell = getenv ("SHELL"); |
|
275 |
if (!shell) |
|
276 |
shell = "sh"; |
|
277 |
execl (shell, shell, "-c", arg, NULL); |
|
278 |
} |
|
279 |
} |
|
280 |
||
281 |
if (res == -1) { |
|
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
282 |
scr_log_print (LPRINT_NORMAL, "Cannot fork child: %s.", strerror (errno)); |
0 | 283 |
close (fd[0]); |
284 |
close (fd[1]); |
|
285 |
return; |
|
286 |
} |
|
287 |
||
288 |
close (fd[1]); |
|
289 |
||
5 | 290 |
{ |
291 |
GError *error = NULL; |
|
292 |
||
293 |
channel = g_io_channel_unix_new (fd[0]); |
|
0 | 294 |
|
5 | 295 |
g_io_channel_set_encoding (channel, NULL, &error); |
296 |
if (error) { |
|
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
297 |
scr_log_print (LPRINT_DEBUG, "cmd: Cannot unset channel encoding: %s.", error -> message); |
5 | 298 |
g_clear_error (&error); |
299 |
} |
|
300 |
g_io_channel_set_buffered (channel, FALSE); |
|
301 |
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, &error); |
|
302 |
if (error) { |
|
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
303 |
scr_log_print (LPRINT_DEBUG, "cmd: Cannot set nonblocking flag on channel: %s.", error -> message); |
5 | 304 |
g_error_free (error); |
305 |
} |
|
306 |
g_io_channel_set_close_on_unref (channel, TRUE); |
|
307 |
} |
|
0 | 308 |
|
309 |
{ |
|
310 |
cmd_cb_t *cb = g_new (cmd_cb_t, 1); |
|
311 |
||
5 | 312 |
if (settings_opt_get_int ("cmd_header")) { |
7 | 313 |
if (settings_opt_get_int ("cmd_header_inline") || is_room (jid)) { |
5 | 314 |
gchar *mesg = g_strdup_printf ("$ %s", arg); |
315 |
gchar *utf = to_utf8 (mesg); |
|
316 |
g_free (mesg); |
|
317 |
cmd_send_msg (jid, NULL, utf); |
|
318 |
g_free (utf); |
|
319 |
cb -> subject = NULL; |
|
320 |
} else { |
|
321 |
gchar *header = g_strdup_printf ("[%%02d] $ %s", arg); |
|
322 |
cb -> subject = to_utf8 (header); |
|
323 |
g_free (header); |
|
324 |
} |
|
325 |
} |
|
326 |
||
327 |
cb -> jid = g_strdup (jid); |
|
328 |
cb -> input = g_string_new (NULL); |
|
329 |
cb -> seq = 0; |
|
330 |
cb -> channel = channel; |
|
331 |
cb -> source = g_io_add_watch_full (channel, 0, G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL, |
|
332 |
cmd_reader, (gpointer) cb, cmd_destroy_data); |
|
0 | 333 |
|
334 |
cmd_channels = g_slist_append (cmd_channels, cb); |
|
335 |
} |
|
336 |
} |
|
337 |
} |
|
338 |
||
24 | 339 |
void mcmd_init (void) |
0 | 340 |
{ |
24 | 341 |
#ifndef MCABBER_API_HAVE_CMD_ID |
0 | 342 |
cmd_add ("cmd", "", 0, 0, do_cmd, NULL); |
20
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
343 |
#else |
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
344 |
mcmd_cmid = cmd_add ("cmd", "", 0, 0, do_cmd, NULL); |
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
345 |
#endif |
0 | 346 |
} |
347 |
||
24 | 348 |
void mcmd_uninit (void) |
0 | 349 |
{ |
350 |
GSList *sel; |
|
351 |
||
24 | 352 |
#ifndef MCABBER_API_HAVE_CMD_ID |
0 | 353 |
cmd_del ("cmd"); |
20
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
354 |
#else |
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
355 |
if (mcmd_cmid) |
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
356 |
cmd_del (mcmd_cmid); |
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
357 |
#endif |
0 | 358 |
|
359 |
for (sel = cmd_channels; sel; sel = sel->next) { |
|
360 |
cmd_cb_t *cb = (cmd_cb_t *) sel->data; |
|
361 |
if (cb->source) |
|
362 |
g_source_remove (cb->source); |
|
363 |
if (cb->channel) |
|
364 |
g_io_channel_unref (cb->channel); |
|
365 |
g_free (cb->jid); |
|
366 |
g_free (cb); |
|
367 |
} |
|
368 |
||
369 |
g_slist_free (cmd_channels); |
|
370 |
} |
|
371 |
||
372 |
/* vim: se ts=4 sw=4: */ |