author | Myhailo Danylenko <isbear@ukrpost.net> |
Sun, 10 Feb 2013 19:01:35 +0200 | |
changeset 33 | 5052c1200b68 |
parent 30 | b60076874691 |
child 34 | 5b818c7467ad |
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 |
|
30
b60076874691
Use slices, build-time api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
29
diff
changeset
|
48 |
module_info_t info_cmd = { |
b60076874691
Use slices, build-time api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
29
diff
changeset
|
49 |
.branch = MCABBER_BRANCH, |
b60076874691
Use slices, build-time api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
29
diff
changeset
|
50 |
.api = MCABBER_API_VERSION, |
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 |
|
0 | 59 |
typedef struct { |
60 |
gchar *jid; |
|
61 |
GString *input; |
|
5 | 62 |
gchar *subject; |
63 |
guint seq; |
|
0 | 64 |
guint source; |
65 |
GIOChannel *channel; |
|
66 |
} cmd_cb_t; |
|
67 |
||
24 | 68 |
#ifdef MCABBER_API_HAVE_CMD_ID |
20
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
69 |
static gpointer mcmd_cmid = NULL; |
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
70 |
#endif |
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
71 |
|
5 | 72 |
static GSList *cmd_channels = NULL; |
73 |
||
74 |
static gboolean is_room (const gchar *jid) |
|
75 |
{ |
|
76 |
return roster_find (jid, jidsearch, ROSTER_TYPE_ROOM) ? TRUE : FALSE; |
|
77 |
} |
|
78 |
||
79 |
static gboolean cmd_send_msg (const gchar *to, const gchar *subject, const gchar *body) |
|
80 |
{ |
|
81 |
gboolean room = is_room (to); |
|
82 |
gpointer xep184 = NULL; |
|
83 |
gint crypted; |
|
84 |
||
85 |
xmpp_send_msg (to, body, room ? ROSTER_TYPE_ROOM : ROSTER_TYPE_USER, room ? NULL : subject, FALSE /* ? */, &crypted, LM_MESSAGE_SUB_TYPE_NOT_SET, &xep184); |
|
86 |
||
87 |
if (crypted == -1) { |
|
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
88 |
scr_log_print (LPRINT_LOGNORM, "cmd: Encryption error. Message not sent."); |
5 | 89 |
return FALSE; |
90 |
} |
|
91 |
||
6
8e64b6d3302e
Fix outgoing message header displaying
Myhailo Danylenko <isbear@ukrpost.net>
parents:
5
diff
changeset
|
92 |
if (!room) { |
8e64b6d3302e
Fix outgoing message header displaying
Myhailo Danylenko <isbear@ukrpost.net>
parents:
5
diff
changeset
|
93 |
if (subject) { |
8e64b6d3302e
Fix outgoing message header displaying
Myhailo Danylenko <isbear@ukrpost.net>
parents:
5
diff
changeset
|
94 |
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
|
95 |
hk_message_out (to, NULL, 0, hbody, crypted, xep184); |
8e64b6d3302e
Fix outgoing message header displaying
Myhailo Danylenko <isbear@ukrpost.net>
parents:
5
diff
changeset
|
96 |
g_free (hbody); |
8e64b6d3302e
Fix outgoing message header displaying
Myhailo Danylenko <isbear@ukrpost.net>
parents:
5
diff
changeset
|
97 |
} else |
8e64b6d3302e
Fix outgoing message header displaying
Myhailo Danylenko <isbear@ukrpost.net>
parents:
5
diff
changeset
|
98 |
hk_message_out (to, NULL, 0, body, crypted, xep184); |
8e64b6d3302e
Fix outgoing message header displaying
Myhailo Danylenko <isbear@ukrpost.net>
parents:
5
diff
changeset
|
99 |
} |
5 | 100 |
|
101 |
return TRUE; |
|
102 |
} |
|
0 | 103 |
|
104 |
static gboolean cmd_reader (GIOChannel *channel, GIOCondition condition, gpointer data) |
|
105 |
{ |
|
106 |
cmd_cb_t *cb = (cmd_cb_t *) data; |
|
107 |
||
108 |
if (condition & (G_IO_IN|G_IO_PRI)) { |
|
5 | 109 |
GIOStatus chstat; |
110 |
static gchar buf[HBB_BLOCKSIZE]; |
|
111 |
gsize endpos; |
|
112 |
GError *error = NULL; |
|
0 | 113 |
|
5 | 114 |
chstat = g_io_channel_read_chars (channel, buf, HBB_BLOCKSIZE, &endpos, &error); |
115 |
||
116 |
if (error) { |
|
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
117 |
scr_log_print (LPRINT_DEBUG, "cmd: Reading error: %s.", error -> message); |
5 | 118 |
g_clear_error (&error); |
119 |
} |
|
0 | 120 |
|
121 |
if (chstat == G_IO_STATUS_ERROR || chstat == G_IO_STATUS_EOF) { |
|
33
5052c1200b68
Proper resource freeing
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
122 |
|
0 | 123 |
return FALSE; // XXX |
124 |
} |
|
125 |
||
126 |
if (endpos) { |
|
127 |
GString *input = cb->input; |
|
128 |
gsize bread = 0; |
|
129 |
gsize written = 0; |
|
130 |
gchar *utf8 = NULL; |
|
131 |
||
132 |
g_string_append_len (input, buf, endpos); |
|
133 |
||
11
fafc922963f5
Use xmpp_is_online if available
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
134 |
if (!xmpp_is_online ()) { |
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
135 |
scr_log_print (LPRINT_LOGNORM, "cmd: Connection is not ready, delaying data"); |
0 | 136 |
return TRUE; |
137 |
} |
|
138 |
||
139 |
// usual g_locale_to_utf8 seem to be unable to detect locale charset |
|
140 |
// maybe, proper solution will be to call setlocale on module loading, |
|
141 |
// but mcabber already does this, and I do not want to mess with it |
|
5 | 142 |
utf8 = g_convert (input->str, input->len, LocaleCharSet, "UTF-8", &bread, &written, &error); |
0 | 143 |
|
5 | 144 |
if (error && error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE && bread) { |
0 | 145 |
written = 0; |
5 | 146 |
g_clear_error (&error); |
147 |
utf8 = g_convert (input->str, bread, LocaleCharSet, "UTF-8", &bread, &written, &error); |
|
0 | 148 |
} |
149 |
||
150 |
if (written) { |
|
151 |
gsize sent = 0; |
|
152 |
||
153 |
while (sent < written) { |
|
154 |
gsize len = 0; |
|
155 |
gchar *bbuf = NULL; |
|
5 | 156 |
gchar *subject = NULL; |
0 | 157 |
|
158 |
if (written - sent > HBB_BLOCKSIZE) { |
|
159 |
gchar *c = utf8 + sent + HBB_BLOCKSIZE; |
|
160 |
c = g_utf8_find_prev_char (utf8 + sent, c); |
|
161 |
||
162 |
if (!c) { |
|
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
163 |
scr_log_print (LPRINT_LOGNORM, "cmd: Cannot determine utf8 character end! End of data chunk will be discarded!"); |
0 | 164 |
break; |
165 |
} |
|
166 |
||
167 |
len = c - utf8 - sent; |
|
168 |
bbuf = g_strndup (utf8 + sent, len); |
|
169 |
} |
|
170 |
||
5 | 171 |
cb -> seq += 1; |
0 | 172 |
|
5 | 173 |
if (cb -> subject) |
174 |
subject = g_strdup_printf (cb -> subject, cb -> seq); |
|
0 | 175 |
|
5 | 176 |
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
|
177 |
scr_log_print (LPRINT_LOGNORM, "cmd: Encryption error. Message not sent."); |
0 | 178 |
|
5 | 179 |
if (subject) |
180 |
g_free (subject); |
|
0 | 181 |
|
182 |
if (!len) |
|
183 |
break; |
|
184 |
||
185 |
g_free (bbuf); |
|
186 |
||
187 |
sent += len; |
|
188 |
} |
|
189 |
||
190 |
g_free (utf8); |
|
191 |
||
192 |
g_string_erase (input, 0, bread); |
|
193 |
||
194 |
} else { |
|
195 |
||
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
196 |
scr_log_print (LPRINT_LOGNORM, "cmd: Character conversion error: %s", error->message); |
5 | 197 |
g_error_free (error); |
33
5052c1200b68
Proper resource freeing
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
198 |
|
0 | 199 |
return FALSE; |
200 |
} |
|
201 |
} |
|
202 |
||
203 |
} else if (condition & (G_IO_ERR|G_IO_NVAL|G_IO_HUP)) { |
|
33
5052c1200b68
Proper resource freeing
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
204 |
|
0 | 205 |
return FALSE; // XXX |
206 |
} |
|
207 |
||
208 |
return TRUE; |
|
209 |
} |
|
210 |
||
211 |
static void cmd_destroy_data (gpointer data) |
|
212 |
{ |
|
213 |
cmd_cb_t *cb = (cmd_cb_t *) data; |
|
214 |
||
215 |
cmd_channels = g_slist_remove (cmd_channels, data); |
|
216 |
||
5 | 217 |
if (cb -> subject) |
218 |
g_free (cb -> subject); |
|
0 | 219 |
g_free (cb->jid); |
30
b60076874691
Use slices, build-time api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
29
diff
changeset
|
220 |
g_slice_free (cmd_cb_t, cb); |
0 | 221 |
} |
222 |
||
223 |
static void do_cmd (char *arg) |
|
224 |
{ |
|
225 |
int fd[2]; |
|
226 |
const char *jid = CURRENT_JID; |
|
227 |
||
228 |
if (!*arg) |
|
229 |
return; |
|
230 |
||
231 |
if (!jid) { |
|
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
232 |
scr_log_print (LPRINT_LOGNORM, "Unsuitable buddy selected."); |
0 | 233 |
return; |
234 |
} |
|
235 |
||
236 |
if (pipe (fd)) { |
|
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
237 |
scr_log_print (LPRINT_LOGNORM, "Cannot create pipe: %s.", strerror (errno)); |
0 | 238 |
return; |
239 |
} |
|
240 |
||
241 |
{ |
|
5 | 242 |
GIOChannel *channel; |
243 |
int res = fork (); |
|
0 | 244 |
|
245 |
if (!res) { |
|
246 |
||
247 |
close (fd[0]); |
|
248 |
dup2 (fd[1], STDOUT_FILENO); |
|
249 |
if (settings_opt_get_int ("cmd_redirect_stderr")) |
|
250 |
dup2 (fd[1], STDERR_FILENO); |
|
251 |
else |
|
252 |
close (STDERR_FILENO); |
|
253 |
close (STDIN_FILENO); |
|
254 |
close (fd[1]); |
|
255 |
||
256 |
{ |
|
257 |
const char *shell = settings_opt_get ("cmd_shell"); |
|
258 |
if (!shell) |
|
259 |
shell = getenv ("SHELL"); |
|
260 |
if (!shell) |
|
261 |
shell = "sh"; |
|
262 |
execl (shell, shell, "-c", arg, NULL); |
|
263 |
} |
|
264 |
} |
|
265 |
||
266 |
if (res == -1) { |
|
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
267 |
scr_log_print (LPRINT_NORMAL, "Cannot fork child: %s.", strerror (errno)); |
0 | 268 |
close (fd[0]); |
269 |
close (fd[1]); |
|
270 |
return; |
|
271 |
} |
|
272 |
||
273 |
close (fd[1]); |
|
274 |
||
5 | 275 |
{ |
276 |
GError *error = NULL; |
|
277 |
||
278 |
channel = g_io_channel_unix_new (fd[0]); |
|
0 | 279 |
|
5 | 280 |
g_io_channel_set_encoding (channel, NULL, &error); |
281 |
if (error) { |
|
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
282 |
scr_log_print (LPRINT_DEBUG, "cmd: Cannot unset channel encoding: %s.", error -> message); |
5 | 283 |
g_clear_error (&error); |
284 |
} |
|
285 |
g_io_channel_set_buffered (channel, FALSE); |
|
286 |
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, &error); |
|
287 |
if (error) { |
|
17
e26e6692b0d5
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
16
diff
changeset
|
288 |
scr_log_print (LPRINT_DEBUG, "cmd: Cannot set nonblocking flag on channel: %s.", error -> message); |
5 | 289 |
g_error_free (error); |
290 |
} |
|
291 |
g_io_channel_set_close_on_unref (channel, TRUE); |
|
292 |
} |
|
0 | 293 |
|
294 |
{ |
|
30
b60076874691
Use slices, build-time api
Myhailo Danylenko <isbear@ukrpost.net>
parents:
29
diff
changeset
|
295 |
cmd_cb_t *cb = g_slice_new (cmd_cb_t); |
0 | 296 |
|
5 | 297 |
if (settings_opt_get_int ("cmd_header")) { |
7 | 298 |
if (settings_opt_get_int ("cmd_header_inline") || is_room (jid)) { |
5 | 299 |
gchar *mesg = g_strdup_printf ("$ %s", arg); |
300 |
gchar *utf = to_utf8 (mesg); |
|
301 |
g_free (mesg); |
|
302 |
cmd_send_msg (jid, NULL, utf); |
|
303 |
g_free (utf); |
|
304 |
cb -> subject = NULL; |
|
305 |
} else { |
|
306 |
gchar *header = g_strdup_printf ("[%%02d] $ %s", arg); |
|
307 |
cb -> subject = to_utf8 (header); |
|
308 |
g_free (header); |
|
309 |
} |
|
310 |
} |
|
311 |
||
312 |
cb -> jid = g_strdup (jid); |
|
313 |
cb -> input = g_string_new (NULL); |
|
314 |
cb -> seq = 0; |
|
315 |
cb -> channel = channel; |
|
33
5052c1200b68
Proper resource freeing
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
316 |
|
5052c1200b68
Proper resource freeing
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
317 |
cmd_channels = g_slist_append (cmd_channels, cb); |
5052c1200b68
Proper resource freeing
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
318 |
|
5 | 319 |
cb -> source = g_io_add_watch_full (channel, 0, G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL, |
320 |
cmd_reader, (gpointer) cb, cmd_destroy_data); |
|
0 | 321 |
|
33
5052c1200b68
Proper resource freeing
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
322 |
g_io_channel_unref ( channel ); |
5052c1200b68
Proper resource freeing
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
323 |
|
0 | 324 |
} |
325 |
} |
|
326 |
} |
|
327 |
||
24 | 328 |
void mcmd_init (void) |
0 | 329 |
{ |
24 | 330 |
#ifndef MCABBER_API_HAVE_CMD_ID |
0 | 331 |
cmd_add ("cmd", "", 0, 0, do_cmd, NULL); |
20
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
332 |
#else |
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
333 |
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
|
334 |
#endif |
0 | 335 |
} |
336 |
||
24 | 337 |
void mcmd_uninit (void) |
0 | 338 |
{ |
339 |
GSList *sel; |
|
340 |
||
24 | 341 |
#ifndef MCABBER_API_HAVE_CMD_ID |
0 | 342 |
cmd_del ("cmd"); |
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 |
if (mcmd_cmid) |
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
345 |
cmd_del (mcmd_cmid); |
d5748ae53a17
Use id to delete command
Myhailo Danylenko <isbear@ukrpost.net>
parents:
19
diff
changeset
|
346 |
#endif |
0 | 347 |
|
33
5052c1200b68
Proper resource freeing
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
348 |
for (sel = cmd_channels; sel; ) { |
0 | 349 |
cmd_cb_t *cb = (cmd_cb_t *) sel->data; |
33
5052c1200b68
Proper resource freeing
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
350 |
sel = sel -> next; |
0 | 351 |
if (cb->source) |
352 |
g_source_remove (cb->source); |
|
353 |
} |
|
354 |
} |
|
355 |
||
356 |
/* vim: se ts=4 sw=4: */ |