1 | /********************************************************************\ |
---|
2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
3 | * * |
---|
4 | * Copyright 2002-2012 Wilmer van der Gaast and others * |
---|
5 | \********************************************************************/ |
---|
6 | |
---|
7 | /* Some glue to put the IRC and the IM stuff together. */ |
---|
8 | |
---|
9 | /* |
---|
10 | This program is free software; you can redistribute it and/or modify |
---|
11 | it under the terms of the GNU General Public License as published by |
---|
12 | the Free Software Foundation; either version 2 of the License, or |
---|
13 | (at your option) any later version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, |
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | GNU General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License with |
---|
21 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
22 | if not, write to the Free Software Foundation, Inc., 51 Franklin St., |
---|
23 | Fifth Floor, Boston, MA 02110-1301 USA |
---|
24 | */ |
---|
25 | |
---|
26 | #include "bitlbee.h" |
---|
27 | #include "dcc.h" |
---|
28 | |
---|
29 | /* IM->IRC callbacks: Simple IM/buddy-related stuff. */ |
---|
30 | |
---|
31 | static const struct irc_user_funcs irc_user_im_funcs; |
---|
32 | |
---|
33 | static void bee_irc_imc_connected(struct im_connection *ic) |
---|
34 | { |
---|
35 | irc_t *irc = (irc_t *) ic->bee->ui_data; |
---|
36 | |
---|
37 | irc_channel_auto_joins(irc, ic->acc); |
---|
38 | } |
---|
39 | |
---|
40 | static void bee_irc_imc_disconnected(struct im_connection *ic) |
---|
41 | { |
---|
42 | /* Maybe try to send /QUITs here instead of later on. */ |
---|
43 | } |
---|
44 | |
---|
45 | static gboolean bee_irc_user_new(bee_t *bee, bee_user_t *bu) |
---|
46 | { |
---|
47 | irc_user_t *iu; |
---|
48 | irc_t *irc = (irc_t *) bee->ui_data; |
---|
49 | char nick[MAX_NICK_LENGTH + 1], *s; |
---|
50 | |
---|
51 | memset(nick, 0, MAX_NICK_LENGTH + 1); |
---|
52 | strcpy(nick, nick_get(bu)); |
---|
53 | |
---|
54 | bu->ui_data = iu = irc_user_new(irc, nick); |
---|
55 | iu->bu = bu; |
---|
56 | |
---|
57 | if (set_getbool(&irc->b->set, "private")) { |
---|
58 | iu->last_channel = NULL; |
---|
59 | } else { |
---|
60 | iu->last_channel = irc_channel_with_user(irc, iu); |
---|
61 | } |
---|
62 | |
---|
63 | if ((s = strchr(bu->handle, '@'))) { |
---|
64 | iu->host = g_strdup(s + 1); |
---|
65 | iu->user = g_strndup(bu->handle, s - bu->handle); |
---|
66 | } else { |
---|
67 | iu->user = g_strdup(bu->handle); |
---|
68 | if (bu->ic->acc->server) { |
---|
69 | iu->host = g_strdup(bu->ic->acc->server); |
---|
70 | } else { |
---|
71 | char *s; |
---|
72 | for (s = bu->ic->acc->tag; g_ascii_isalnum(*s); s++) { |
---|
73 | ; |
---|
74 | } |
---|
75 | /* Only use the tag if we got to the end of the string. |
---|
76 | (So allow alphanumerics only. Hopefully not too |
---|
77 | restrictive.) */ |
---|
78 | if (*s) { |
---|
79 | iu->host = g_strdup(bu->ic->acc->prpl->name); |
---|
80 | } else { |
---|
81 | iu->host = g_strdup(bu->ic->acc->tag); |
---|
82 | } |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | while ((s = strchr(iu->user, ' '))) { |
---|
87 | *s = '_'; |
---|
88 | } |
---|
89 | |
---|
90 | if (bu->flags & BEE_USER_LOCAL) { |
---|
91 | char *s = set_getstr(&bee->set, "handle_unknown"); |
---|
92 | |
---|
93 | if (strcmp(s, "add_private") == 0) { |
---|
94 | iu->last_channel = NULL; |
---|
95 | } else if (strcmp(s, "add_channel") == 0) { |
---|
96 | iu->last_channel = irc->default_channel; |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | iu->f = &irc_user_im_funcs; |
---|
101 | |
---|
102 | return TRUE; |
---|
103 | } |
---|
104 | |
---|
105 | static gboolean bee_irc_user_free(bee_t *bee, bee_user_t *bu) |
---|
106 | { |
---|
107 | return irc_user_free(bee->ui_data, (irc_user_t *) bu->ui_data); |
---|
108 | } |
---|
109 | |
---|
110 | static gboolean bee_irc_user_status(bee_t *bee, bee_user_t *bu, bee_user_t *old) |
---|
111 | { |
---|
112 | irc_t *irc = bee->ui_data; |
---|
113 | irc_user_t *iu = bu->ui_data; |
---|
114 | |
---|
115 | /* Do this outside the if below since away state can change without |
---|
116 | the online state changing. */ |
---|
117 | iu->flags &= ~IRC_USER_AWAY; |
---|
118 | if (bu->flags & BEE_USER_AWAY || !(bu->flags & BEE_USER_ONLINE)) { |
---|
119 | iu->flags |= IRC_USER_AWAY; |
---|
120 | } |
---|
121 | |
---|
122 | if ((bu->flags & BEE_USER_ONLINE) != (old->flags & BEE_USER_ONLINE)) { |
---|
123 | if (bu->flags & BEE_USER_ONLINE) { |
---|
124 | if (g_hash_table_lookup(irc->watches, iu->key)) { |
---|
125 | irc_send_num(irc, 600, "%s %s %s %d :%s", iu->nick, iu->user, |
---|
126 | iu->host, (int) time(NULL), "logged online"); |
---|
127 | } |
---|
128 | } else { |
---|
129 | if (g_hash_table_lookup(irc->watches, iu->key)) { |
---|
130 | irc_send_num(irc, 601, "%s %s %s %d :%s", iu->nick, iu->user, |
---|
131 | iu->host, (int) time(NULL), "logged offline"); |
---|
132 | } |
---|
133 | |
---|
134 | /* Send a QUIT since those will also show up in any |
---|
135 | query windows the user may have, plus it's only |
---|
136 | one QUIT instead of possibly many (in case of |
---|
137 | multiple control chans). If there's a channel that |
---|
138 | shows offline people, a JOIN will follow. */ |
---|
139 | if (set_getbool(&bee->set, "offline_user_quits")) { |
---|
140 | irc_user_quit(iu, "Leaving..."); |
---|
141 | } |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | /* Reset this one since the info may have changed. */ |
---|
146 | iu->away_reply_timeout = 0; |
---|
147 | |
---|
148 | bee_irc_channel_update(irc, NULL, iu); |
---|
149 | |
---|
150 | return TRUE; |
---|
151 | } |
---|
152 | |
---|
153 | void bee_irc_channel_update(irc_t *irc, irc_channel_t *ic, irc_user_t *iu) |
---|
154 | { |
---|
155 | GSList *l; |
---|
156 | |
---|
157 | if (ic == NULL) { |
---|
158 | for (l = irc->channels; l; l = l->next) { |
---|
159 | ic = l->data; |
---|
160 | /* TODO: Just add a type flag or so.. */ |
---|
161 | if (ic->f == irc->default_channel->f && |
---|
162 | (ic->flags & IRC_CHANNEL_JOINED)) { |
---|
163 | bee_irc_channel_update(irc, ic, iu); |
---|
164 | } |
---|
165 | } |
---|
166 | return; |
---|
167 | } |
---|
168 | if (iu == NULL) { |
---|
169 | for (l = irc->users; l; l = l->next) { |
---|
170 | iu = l->data; |
---|
171 | if (iu->bu) { |
---|
172 | bee_irc_channel_update(irc, ic, l->data); |
---|
173 | } |
---|
174 | } |
---|
175 | return; |
---|
176 | } |
---|
177 | |
---|
178 | if (!irc_channel_wants_user(ic, iu)) { |
---|
179 | irc_channel_del_user(ic, iu, IRC_CDU_PART, NULL); |
---|
180 | } else { |
---|
181 | struct irc_control_channel *icc = ic->data; |
---|
182 | int mode = 0; |
---|
183 | |
---|
184 | if (!(iu->bu->flags & BEE_USER_ONLINE)) { |
---|
185 | mode = icc->modes[0]; |
---|
186 | } else if (iu->bu->flags & BEE_USER_AWAY) { |
---|
187 | mode = icc->modes[1]; |
---|
188 | } else if (iu->bu->flags & BEE_USER_SPECIAL) { |
---|
189 | mode = icc->modes[2]; |
---|
190 | } else { |
---|
191 | mode = icc->modes[3]; |
---|
192 | } |
---|
193 | |
---|
194 | if (!mode) { |
---|
195 | irc_channel_del_user(ic, iu, IRC_CDU_PART, NULL); |
---|
196 | } else { |
---|
197 | irc_channel_add_user(ic, iu); |
---|
198 | irc_channel_user_set_mode(ic, iu, mode); |
---|
199 | } |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | static gboolean bee_irc_user_msg(bee_t *bee, bee_user_t *bu, const char *msg_, time_t sent_at) |
---|
204 | { |
---|
205 | irc_t *irc = bee->ui_data; |
---|
206 | irc_user_t *iu = (irc_user_t *) bu->ui_data; |
---|
207 | const char *dst; |
---|
208 | char *prefix = NULL; |
---|
209 | char *wrapped, *ts = NULL; |
---|
210 | char *msg = g_strdup(msg_); |
---|
211 | GSList *l; |
---|
212 | |
---|
213 | if (sent_at > 0 && set_getbool(&irc->b->set, "display_timestamps")) { |
---|
214 | ts = irc_format_timestamp(irc, sent_at); |
---|
215 | } |
---|
216 | |
---|
217 | dst = irc_user_msgdest(iu); |
---|
218 | if (dst != irc->user->nick) { |
---|
219 | /* if not messaging directly, call user by name */ |
---|
220 | prefix = g_strdup_printf("%s%s%s", irc->user->nick, set_getstr(&bee->set, "to_char"), ts ? : ""); |
---|
221 | } else { |
---|
222 | prefix = ts; |
---|
223 | ts = NULL; /* don't double-free */ |
---|
224 | } |
---|
225 | |
---|
226 | for (l = irc_plugins; l; l = l->next) { |
---|
227 | irc_plugin_t *p = l->data; |
---|
228 | if (p->filter_msg_in) { |
---|
229 | char *s = p->filter_msg_in(iu, msg, 0); |
---|
230 | if (s) { |
---|
231 | if (s != msg) { |
---|
232 | g_free(msg); |
---|
233 | } |
---|
234 | msg = s; |
---|
235 | } else { |
---|
236 | /* Modules can swallow messages. */ |
---|
237 | goto cleanup; |
---|
238 | } |
---|
239 | } |
---|
240 | } |
---|
241 | |
---|
242 | if ((g_strcasecmp(set_getstr(&bee->set, "strip_html"), "always") == 0) || |
---|
243 | ((bu->ic->flags & OPT_DOES_HTML) && set_getbool(&bee->set, "strip_html"))) { |
---|
244 | char *s = g_strdup(msg); |
---|
245 | strip_html(s); |
---|
246 | g_free(msg); |
---|
247 | msg = s; |
---|
248 | } |
---|
249 | |
---|
250 | wrapped = word_wrap(msg, 425); |
---|
251 | irc_send_msg(iu, "PRIVMSG", dst, wrapped, prefix); |
---|
252 | g_free(wrapped); |
---|
253 | |
---|
254 | cleanup: |
---|
255 | g_free(prefix); |
---|
256 | g_free(msg); |
---|
257 | g_free(ts); |
---|
258 | |
---|
259 | return TRUE; |
---|
260 | } |
---|
261 | |
---|
262 | static gboolean bee_irc_user_typing(bee_t *bee, bee_user_t *bu, uint32_t flags) |
---|
263 | { |
---|
264 | irc_t *irc = (irc_t *) bee->ui_data; |
---|
265 | |
---|
266 | if (set_getbool(&bee->set, "typing_notice")) { |
---|
267 | irc_send_msg_f((irc_user_t *) bu->ui_data, "PRIVMSG", irc->user->nick, |
---|
268 | "\001TYPING %d\001", (flags >> 8) & 3); |
---|
269 | } else { |
---|
270 | return FALSE; |
---|
271 | } |
---|
272 | |
---|
273 | return TRUE; |
---|
274 | } |
---|
275 | |
---|
276 | static gboolean bee_irc_user_action_response(bee_t *bee, bee_user_t *bu, const char *action, char * const args[], |
---|
277 | void *data) |
---|
278 | { |
---|
279 | irc_t *irc = (irc_t *) bee->ui_data; |
---|
280 | GString *msg = g_string_new("\001"); |
---|
281 | |
---|
282 | g_string_append(msg, action); |
---|
283 | while (*args) { |
---|
284 | if (strchr(*args, ' ')) { |
---|
285 | g_string_append_printf(msg, " \"%s\"", *args); |
---|
286 | } else { |
---|
287 | g_string_append_printf(msg, " %s", *args); |
---|
288 | } |
---|
289 | args++; |
---|
290 | } |
---|
291 | g_string_append_c(msg, '\001'); |
---|
292 | |
---|
293 | irc_send_msg((irc_user_t *) bu->ui_data, "NOTICE", irc->user->nick, msg->str, NULL); |
---|
294 | |
---|
295 | g_string_free(msg, TRUE); |
---|
296 | |
---|
297 | return TRUE; |
---|
298 | } |
---|
299 | |
---|
300 | static gboolean bee_irc_user_nick_update(irc_user_t *iu); |
---|
301 | |
---|
302 | static gboolean bee_irc_user_fullname(bee_t *bee, bee_user_t *bu) |
---|
303 | { |
---|
304 | irc_user_t *iu = (irc_user_t *) bu->ui_data; |
---|
305 | char *s; |
---|
306 | |
---|
307 | if (iu->fullname != iu->nick) { |
---|
308 | g_free(iu->fullname); |
---|
309 | } |
---|
310 | iu->fullname = g_strdup(bu->fullname); |
---|
311 | |
---|
312 | /* Strip newlines (unlikely, but IRC-unfriendly so they must go) |
---|
313 | TODO(wilmer): Do the same with away msgs again! */ |
---|
314 | for (s = iu->fullname; *s; s++) { |
---|
315 | if (g_ascii_isspace(*s)) { |
---|
316 | *s = ' '; |
---|
317 | } |
---|
318 | } |
---|
319 | |
---|
320 | if ((bu->ic->flags & OPT_LOGGED_IN) && set_getbool(&bee->set, "display_namechanges")) { |
---|
321 | /* People don't like this /NOTICE. Meh, let's go back to the old one. |
---|
322 | char *msg = g_strdup_printf( "<< \002BitlBee\002 - Changed name to `%s' >>", iu->fullname ); |
---|
323 | irc_send_msg( iu, "NOTICE", irc->user->nick, msg, NULL ); |
---|
324 | */ |
---|
325 | imcb_log(bu->ic, "User `%s' changed name to `%s'", iu->nick, iu->fullname); |
---|
326 | } |
---|
327 | |
---|
328 | bee_irc_user_nick_update(iu); |
---|
329 | |
---|
330 | return TRUE; |
---|
331 | } |
---|
332 | |
---|
333 | static gboolean bee_irc_user_nick_hint(bee_t *bee, bee_user_t *bu, const char *hint) |
---|
334 | { |
---|
335 | bee_irc_user_nick_update((irc_user_t *) bu->ui_data); |
---|
336 | |
---|
337 | return TRUE; |
---|
338 | } |
---|
339 | |
---|
340 | static gboolean bee_irc_user_group(bee_t *bee, bee_user_t *bu) |
---|
341 | { |
---|
342 | irc_user_t *iu = (irc_user_t *) bu->ui_data; |
---|
343 | irc_t *irc = (irc_t *) bee->ui_data; |
---|
344 | bee_user_flags_t online; |
---|
345 | |
---|
346 | /* Take the user offline temporarily so we can change the nick (if necessary). */ |
---|
347 | if ((online = bu->flags & BEE_USER_ONLINE)) { |
---|
348 | bu->flags &= ~BEE_USER_ONLINE; |
---|
349 | } |
---|
350 | |
---|
351 | bee_irc_channel_update(irc, NULL, iu); |
---|
352 | bee_irc_user_nick_update(iu); |
---|
353 | |
---|
354 | if (online) { |
---|
355 | bu->flags |= online; |
---|
356 | bee_irc_channel_update(irc, NULL, iu); |
---|
357 | } |
---|
358 | |
---|
359 | return TRUE; |
---|
360 | } |
---|
361 | |
---|
362 | static gboolean bee_irc_user_nick_update(irc_user_t *iu) |
---|
363 | { |
---|
364 | bee_user_t *bu = iu->bu; |
---|
365 | char *newnick; |
---|
366 | |
---|
367 | if (bu->flags & BEE_USER_ONLINE) { |
---|
368 | /* Ignore if the user is visible already. */ |
---|
369 | return TRUE; |
---|
370 | } |
---|
371 | |
---|
372 | if (nick_saved(bu)) { |
---|
373 | /* The user already assigned a nickname to this person. */ |
---|
374 | return TRUE; |
---|
375 | } |
---|
376 | |
---|
377 | newnick = nick_get(bu); |
---|
378 | |
---|
379 | if (strcmp(iu->nick, newnick) != 0) { |
---|
380 | nick_dedupe(bu, newnick); |
---|
381 | irc_user_set_nick(iu, newnick); |
---|
382 | } |
---|
383 | |
---|
384 | return TRUE; |
---|
385 | } |
---|
386 | |
---|
387 | void bee_irc_user_nick_reset(irc_user_t *iu) |
---|
388 | { |
---|
389 | bee_user_t *bu = iu->bu; |
---|
390 | bee_user_flags_t online; |
---|
391 | |
---|
392 | if (bu == FALSE) { |
---|
393 | return; |
---|
394 | } |
---|
395 | |
---|
396 | /* In this case, pretend the user is offline. */ |
---|
397 | if ((online = bu->flags & BEE_USER_ONLINE)) { |
---|
398 | bu->flags &= ~BEE_USER_ONLINE; |
---|
399 | } |
---|
400 | |
---|
401 | nick_del(bu); |
---|
402 | bee_irc_user_nick_update(iu); |
---|
403 | |
---|
404 | bu->flags |= online; |
---|
405 | } |
---|
406 | |
---|
407 | /* IRC->IM calls */ |
---|
408 | |
---|
409 | static gboolean bee_irc_user_privmsg_cb(gpointer data, gint fd, b_input_condition cond); |
---|
410 | |
---|
411 | static gboolean bee_irc_user_privmsg(irc_user_t *iu, const char *msg) |
---|
412 | { |
---|
413 | const char *away; |
---|
414 | |
---|
415 | if (iu->bu == NULL) { |
---|
416 | return FALSE; |
---|
417 | } |
---|
418 | |
---|
419 | if ((away = irc_user_get_away(iu)) && |
---|
420 | time(NULL) >= iu->away_reply_timeout) { |
---|
421 | irc_send_num(iu->irc, 301, "%s :%s", iu->nick, away); |
---|
422 | iu->away_reply_timeout = time(NULL) + |
---|
423 | set_getint(&iu->irc->b->set, "away_reply_timeout"); |
---|
424 | } |
---|
425 | |
---|
426 | if (iu->pastebuf == NULL) { |
---|
427 | iu->pastebuf = g_string_new(msg); |
---|
428 | } else { |
---|
429 | b_event_remove(iu->pastebuf_timer); |
---|
430 | g_string_append_printf(iu->pastebuf, "\n%s", msg); |
---|
431 | } |
---|
432 | |
---|
433 | if (set_getbool(&iu->irc->b->set, "paste_buffer")) { |
---|
434 | int delay; |
---|
435 | |
---|
436 | if ((delay = set_getint(&iu->irc->b->set, "paste_buffer_delay")) <= 5) { |
---|
437 | delay *= 1000; |
---|
438 | } |
---|
439 | |
---|
440 | iu->pastebuf_timer = b_timeout_add(delay, bee_irc_user_privmsg_cb, iu); |
---|
441 | |
---|
442 | return TRUE; |
---|
443 | } else { |
---|
444 | bee_irc_user_privmsg_cb(iu, 0, 0); |
---|
445 | |
---|
446 | return TRUE; |
---|
447 | } |
---|
448 | } |
---|
449 | |
---|
450 | static gboolean bee_irc_user_privmsg_cb(gpointer data, gint fd, b_input_condition cond) |
---|
451 | { |
---|
452 | irc_user_t *iu = data; |
---|
453 | char *msg; |
---|
454 | GSList *l; |
---|
455 | |
---|
456 | msg = g_string_free(iu->pastebuf, FALSE); |
---|
457 | iu->pastebuf = NULL; |
---|
458 | iu->pastebuf_timer = 0; |
---|
459 | |
---|
460 | for (l = irc_plugins; l; l = l->next) { |
---|
461 | irc_plugin_t *p = l->data; |
---|
462 | if (p->filter_msg_out) { |
---|
463 | char *s = p->filter_msg_out(iu, msg, 0); |
---|
464 | if (s) { |
---|
465 | if (s != msg) { |
---|
466 | g_free(msg); |
---|
467 | } |
---|
468 | msg = s; |
---|
469 | } else { |
---|
470 | /* Modules can swallow messages. */ |
---|
471 | iu->pastebuf = NULL; |
---|
472 | g_free(msg); |
---|
473 | return FALSE; |
---|
474 | } |
---|
475 | } |
---|
476 | } |
---|
477 | |
---|
478 | bee_user_msg(iu->irc->b, iu->bu, msg, 0); |
---|
479 | |
---|
480 | g_free(msg); |
---|
481 | |
---|
482 | return FALSE; |
---|
483 | } |
---|
484 | |
---|
485 | static gboolean bee_irc_user_ctcp(irc_user_t *iu, char *const *ctcp) |
---|
486 | { |
---|
487 | if (ctcp[1] && g_strcasecmp(ctcp[0], "DCC") == 0 |
---|
488 | && g_strcasecmp(ctcp[1], "SEND") == 0) { |
---|
489 | if (iu->bu && iu->bu->ic && iu->bu->ic->acc->prpl->transfer_request) { |
---|
490 | file_transfer_t *ft = dcc_request(iu->bu->ic, ctcp); |
---|
491 | if (ft) { |
---|
492 | iu->bu->ic->acc->prpl->transfer_request(iu->bu->ic, ft, iu->bu->handle); |
---|
493 | } |
---|
494 | |
---|
495 | return TRUE; |
---|
496 | } |
---|
497 | } else if (g_strcasecmp(ctcp[0], "TYPING") == 0) { |
---|
498 | if (iu->bu && iu->bu->ic && iu->bu->ic->acc->prpl->send_typing && ctcp[1]) { |
---|
499 | int st = ctcp[1][0]; |
---|
500 | if (st >= '0' && st <= '2') { |
---|
501 | st <<= 8; |
---|
502 | iu->bu->ic->acc->prpl->send_typing(iu->bu->ic, iu->bu->handle, st); |
---|
503 | } |
---|
504 | |
---|
505 | return TRUE; |
---|
506 | } |
---|
507 | } else if (g_strcasecmp(ctcp[0], "HELP") == 0 && iu->bu) { |
---|
508 | GString *supp = g_string_new("Supported CTCPs:"); |
---|
509 | GList *l; |
---|
510 | |
---|
511 | if (iu->bu->ic && iu->bu->ic->acc->prpl->transfer_request) { |
---|
512 | g_string_append(supp, " DCC SEND,"); |
---|
513 | } |
---|
514 | if (iu->bu->ic && iu->bu->ic->acc->prpl->send_typing) { |
---|
515 | g_string_append(supp, " TYPING,"); |
---|
516 | } |
---|
517 | if (iu->bu->ic->acc->prpl->buddy_action_list) { |
---|
518 | for (l = iu->bu->ic->acc->prpl->buddy_action_list(iu->bu); l; l = l->next) { |
---|
519 | struct buddy_action *ba = l->data; |
---|
520 | g_string_append_printf(supp, " %s (%s),", |
---|
521 | ba->name, ba->description); |
---|
522 | } |
---|
523 | } |
---|
524 | g_string_truncate(supp, supp->len - 1); |
---|
525 | irc_send_msg_f(iu, "NOTICE", iu->irc->user->nick, "\001HELP %s\001", supp->str); |
---|
526 | g_string_free(supp, TRUE); |
---|
527 | } else if (iu->bu && iu->bu->ic && iu->bu->ic->acc->prpl->buddy_action) { |
---|
528 | iu->bu->ic->acc->prpl->buddy_action(iu->bu, ctcp[0], ctcp + 1, NULL); |
---|
529 | } |
---|
530 | |
---|
531 | return FALSE; |
---|
532 | } |
---|
533 | |
---|
534 | static const struct irc_user_funcs irc_user_im_funcs = { |
---|
535 | bee_irc_user_privmsg, |
---|
536 | bee_irc_user_ctcp, |
---|
537 | }; |
---|
538 | |
---|
539 | |
---|
540 | /* IM->IRC: Groupchats */ |
---|
541 | const struct irc_channel_funcs irc_channel_im_chat_funcs; |
---|
542 | |
---|
543 | static gboolean bee_irc_chat_new(bee_t *bee, struct groupchat *c) |
---|
544 | { |
---|
545 | irc_t *irc = bee->ui_data; |
---|
546 | irc_channel_t *ic; |
---|
547 | char *topic; |
---|
548 | GSList *l; |
---|
549 | int i; |
---|
550 | |
---|
551 | /* Try to find a channel that expects to receive a groupchat. |
---|
552 | This flag is set earlier in our current call trace. */ |
---|
553 | for (l = irc->channels; l; l = l->next) { |
---|
554 | ic = l->data; |
---|
555 | if (ic->flags & IRC_CHANNEL_CHAT_PICKME) { |
---|
556 | break; |
---|
557 | } |
---|
558 | } |
---|
559 | |
---|
560 | /* If we found none, just generate some stupid name. */ |
---|
561 | if (l == NULL) { |
---|
562 | for (i = 0; i <= 999; i++) { |
---|
563 | char name[16]; |
---|
564 | sprintf(name, "#chat_%03d", i); |
---|
565 | if ((ic = irc_channel_new(irc, name))) { |
---|
566 | break; |
---|
567 | } |
---|
568 | } |
---|
569 | } |
---|
570 | |
---|
571 | if (ic == NULL) { |
---|
572 | return FALSE; |
---|
573 | } |
---|
574 | |
---|
575 | c->ui_data = ic; |
---|
576 | ic->data = c; |
---|
577 | |
---|
578 | topic = g_strdup_printf( |
---|
579 | "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", |
---|
580 | c->title); |
---|
581 | irc_channel_set_topic(ic, topic, irc->root); |
---|
582 | g_free(topic); |
---|
583 | |
---|
584 | return TRUE; |
---|
585 | } |
---|
586 | |
---|
587 | static gboolean bee_irc_chat_free(bee_t *bee, struct groupchat *c) |
---|
588 | { |
---|
589 | irc_channel_t *ic = c->ui_data; |
---|
590 | |
---|
591 | if (ic == NULL) { |
---|
592 | return FALSE; |
---|
593 | } |
---|
594 | |
---|
595 | if (ic->flags & IRC_CHANNEL_JOINED) { |
---|
596 | irc_channel_printf(ic, "Cleaning up channel, bye!"); |
---|
597 | } |
---|
598 | |
---|
599 | ic->data = NULL; |
---|
600 | c->ui_data = NULL; |
---|
601 | irc_channel_del_user(ic, ic->irc->user, IRC_CDU_KICK, "Chatroom closed by server"); |
---|
602 | |
---|
603 | return TRUE; |
---|
604 | } |
---|
605 | |
---|
606 | static gboolean bee_irc_chat_log(bee_t *bee, struct groupchat *c, const char *text) |
---|
607 | { |
---|
608 | irc_channel_t *ic = c->ui_data; |
---|
609 | |
---|
610 | if (ic == NULL) { |
---|
611 | return FALSE; |
---|
612 | } |
---|
613 | |
---|
614 | irc_channel_printf(ic, "%s", text); |
---|
615 | |
---|
616 | return TRUE; |
---|
617 | } |
---|
618 | |
---|
619 | static gboolean bee_irc_chat_msg(bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *msg, time_t sent_at) |
---|
620 | { |
---|
621 | irc_t *irc = bee->ui_data; |
---|
622 | irc_user_t *iu = bu->ui_data; |
---|
623 | irc_channel_t *ic = c->ui_data; |
---|
624 | char *wrapped, *ts = NULL; |
---|
625 | |
---|
626 | if (ic == NULL) { |
---|
627 | return FALSE; |
---|
628 | } |
---|
629 | |
---|
630 | if (sent_at > 0 && set_getbool(&bee->set, "display_timestamps")) { |
---|
631 | ts = irc_format_timestamp(irc, sent_at); |
---|
632 | } |
---|
633 | |
---|
634 | wrapped = word_wrap(msg, 425); |
---|
635 | irc_send_msg(iu, "PRIVMSG", ic->name, wrapped, ts); |
---|
636 | g_free(ts); |
---|
637 | g_free(wrapped); |
---|
638 | |
---|
639 | return TRUE; |
---|
640 | } |
---|
641 | |
---|
642 | static gboolean bee_irc_chat_add_user(bee_t *bee, struct groupchat *c, bee_user_t *bu) |
---|
643 | { |
---|
644 | irc_t *irc = bee->ui_data; |
---|
645 | irc_channel_t *ic = c->ui_data; |
---|
646 | |
---|
647 | if (ic == NULL) { |
---|
648 | return FALSE; |
---|
649 | } |
---|
650 | |
---|
651 | irc_channel_add_user(ic, bu == bee->user ? irc->user : bu->ui_data); |
---|
652 | |
---|
653 | return TRUE; |
---|
654 | } |
---|
655 | |
---|
656 | static gboolean bee_irc_chat_remove_user(bee_t *bee, struct groupchat *c, bee_user_t *bu) |
---|
657 | { |
---|
658 | irc_t *irc = bee->ui_data; |
---|
659 | irc_channel_t *ic = c->ui_data; |
---|
660 | |
---|
661 | if (ic == NULL || bu == NULL) { |
---|
662 | return FALSE; |
---|
663 | } |
---|
664 | |
---|
665 | /* TODO: Possible bug here: If a module removes $user here instead of just |
---|
666 | using imcb_chat_free() and the channel was IRC_CHANNEL_TEMP, we get into |
---|
667 | a broken state around here. */ |
---|
668 | irc_channel_del_user(ic, bu == bee->user ? irc->user : bu->ui_data, IRC_CDU_PART, NULL); |
---|
669 | |
---|
670 | return TRUE; |
---|
671 | } |
---|
672 | |
---|
673 | static gboolean bee_irc_chat_topic(bee_t *bee, struct groupchat *c, const char *new, bee_user_t *bu) |
---|
674 | { |
---|
675 | irc_channel_t *ic = c->ui_data; |
---|
676 | irc_t *irc = bee->ui_data; |
---|
677 | irc_user_t *iu; |
---|
678 | |
---|
679 | if (ic == NULL) { |
---|
680 | return FALSE; |
---|
681 | } |
---|
682 | |
---|
683 | if (bu == NULL) { |
---|
684 | iu = irc->root; |
---|
685 | } else if (bu == bee->user) { |
---|
686 | iu = irc->user; |
---|
687 | } else { |
---|
688 | iu = bu->ui_data; |
---|
689 | } |
---|
690 | |
---|
691 | irc_channel_set_topic(ic, new, iu); |
---|
692 | |
---|
693 | return TRUE; |
---|
694 | } |
---|
695 | |
---|
696 | static gboolean bee_irc_chat_name_hint(bee_t *bee, struct groupchat *c, const char *name) |
---|
697 | { |
---|
698 | return irc_channel_name_hint(c->ui_data, name); |
---|
699 | } |
---|
700 | |
---|
701 | static gboolean bee_irc_chat_invite(bee_t *bee, bee_user_t *bu, const char *name, const char *msg) |
---|
702 | { |
---|
703 | char *channel, *s; |
---|
704 | irc_t *irc = bee->ui_data; |
---|
705 | irc_user_t *iu = bu->ui_data; |
---|
706 | irc_channel_t *chan; |
---|
707 | |
---|
708 | if (strchr(CTYPES, name[0])) { |
---|
709 | channel = g_strdup(name); |
---|
710 | } else { |
---|
711 | channel = g_strdup_printf("#%s", name); |
---|
712 | } |
---|
713 | |
---|
714 | if ((s = strchr(channel, '@'))) { |
---|
715 | *s = '\0'; |
---|
716 | } |
---|
717 | |
---|
718 | if (strlen(channel) > MAX_NICK_LENGTH) { |
---|
719 | /* If the channel name is very long (like those insane GTalk |
---|
720 | UUID names), try if we can use the inviter's nick. */ |
---|
721 | s = g_strdup_printf("#%s", iu->nick); |
---|
722 | if (irc_channel_by_name(irc, s) == NULL) { |
---|
723 | g_free(channel); |
---|
724 | channel = s; |
---|
725 | } |
---|
726 | } |
---|
727 | |
---|
728 | if ((chan = irc_channel_new(irc, channel)) && |
---|
729 | set_setstr(&chan->set, "type", "chat") && |
---|
730 | set_setstr(&chan->set, "chat_type", "room") && |
---|
731 | set_setstr(&chan->set, "account", bu->ic->acc->tag) && |
---|
732 | set_setstr(&chan->set, "room", (char *) name)) { |
---|
733 | /* I'm assuming that if the user didn't "chat add" the room |
---|
734 | himself but got invited, it's temporary, so make this a |
---|
735 | temporary mapping that is removed as soon as we /PART. */ |
---|
736 | chan->flags |= IRC_CHANNEL_TEMP; |
---|
737 | } else { |
---|
738 | irc_channel_free(chan); |
---|
739 | chan = NULL; |
---|
740 | } |
---|
741 | g_free(channel); |
---|
742 | |
---|
743 | irc_send_msg_f(iu, "PRIVMSG", irc->user->nick, "<< \002BitlBee\002 - Invitation to chatroom %s >>", name); |
---|
744 | if (msg) { |
---|
745 | irc_send_msg(iu, "PRIVMSG", irc->user->nick, msg, NULL); |
---|
746 | } |
---|
747 | if (chan) { |
---|
748 | irc_send_msg_f(iu, "PRIVMSG", irc->user->nick, "To join the room, just /join %s", chan->name); |
---|
749 | irc_send_invite(iu, chan); |
---|
750 | } |
---|
751 | |
---|
752 | return TRUE; |
---|
753 | } |
---|
754 | |
---|
755 | /* IRC->IM */ |
---|
756 | static gboolean bee_irc_channel_chat_privmsg_cb(gpointer data, gint fd, b_input_condition cond); |
---|
757 | |
---|
758 | static gboolean bee_irc_channel_chat_privmsg(irc_channel_t *ic, const char *msg) |
---|
759 | { |
---|
760 | struct groupchat *c = ic->data; |
---|
761 | char *trans = NULL, *s; |
---|
762 | |
---|
763 | if (c == NULL) { |
---|
764 | return FALSE; |
---|
765 | } |
---|
766 | |
---|
767 | if (set_getbool(&ic->set, "translate_to_nicks")) { |
---|
768 | char nick[MAX_NICK_LENGTH + 1]; |
---|
769 | irc_user_t *iu; |
---|
770 | |
---|
771 | strncpy(nick, msg, MAX_NICK_LENGTH); |
---|
772 | nick[MAX_NICK_LENGTH] = '\0'; |
---|
773 | if ((s = strchr(nick, ':')) || (s = strchr(nick, ','))) { |
---|
774 | *s = '\0'; |
---|
775 | if ((iu = irc_user_by_name(ic->irc, nick)) && iu->bu && |
---|
776 | iu->bu->nick && irc_channel_has_user(ic, iu)) { |
---|
777 | trans = g_strconcat(iu->bu->nick, msg + (s - nick), NULL); |
---|
778 | msg = trans; |
---|
779 | } |
---|
780 | } |
---|
781 | } |
---|
782 | |
---|
783 | if (set_getbool(&ic->irc->b->set, "paste_buffer")) { |
---|
784 | int delay; |
---|
785 | |
---|
786 | if (ic->pastebuf == NULL) { |
---|
787 | ic->pastebuf = g_string_new(msg); |
---|
788 | } else { |
---|
789 | b_event_remove(ic->pastebuf_timer); |
---|
790 | g_string_append_printf(ic->pastebuf, "\n%s", msg); |
---|
791 | } |
---|
792 | |
---|
793 | if ((delay = set_getint(&ic->irc->b->set, "paste_buffer_delay")) <= 5) { |
---|
794 | delay *= 1000; |
---|
795 | } |
---|
796 | |
---|
797 | ic->pastebuf_timer = b_timeout_add(delay, bee_irc_channel_chat_privmsg_cb, ic); |
---|
798 | |
---|
799 | g_free(trans); |
---|
800 | return TRUE; |
---|
801 | } else { |
---|
802 | bee_chat_msg(ic->irc->b, c, msg, 0); |
---|
803 | } |
---|
804 | |
---|
805 | g_free(trans); |
---|
806 | return TRUE; |
---|
807 | } |
---|
808 | |
---|
809 | static gboolean bee_irc_channel_chat_privmsg_cb(gpointer data, gint fd, b_input_condition cond) |
---|
810 | { |
---|
811 | irc_channel_t *ic = data; |
---|
812 | |
---|
813 | if (ic->data) { |
---|
814 | bee_chat_msg(ic->irc->b, ic->data, ic->pastebuf->str, 0); |
---|
815 | } |
---|
816 | |
---|
817 | g_string_free(ic->pastebuf, TRUE); |
---|
818 | ic->pastebuf = 0; |
---|
819 | ic->pastebuf_timer = 0; |
---|
820 | |
---|
821 | return FALSE; |
---|
822 | } |
---|
823 | |
---|
824 | static gboolean bee_irc_channel_chat_join(irc_channel_t *ic) |
---|
825 | { |
---|
826 | char *acc_s, *room; |
---|
827 | account_t *acc; |
---|
828 | |
---|
829 | if (strcmp(set_getstr(&ic->set, "chat_type"), "room") != 0) { |
---|
830 | return TRUE; |
---|
831 | } |
---|
832 | |
---|
833 | if ((acc_s = set_getstr(&ic->set, "account")) && |
---|
834 | (room = set_getstr(&ic->set, "room")) && |
---|
835 | (acc = account_get(ic->irc->b, acc_s)) && |
---|
836 | acc->ic && acc->prpl->chat_join) { |
---|
837 | char *nick; |
---|
838 | |
---|
839 | if (!(nick = set_getstr(&ic->set, "nick"))) { |
---|
840 | nick = ic->irc->user->nick; |
---|
841 | } |
---|
842 | |
---|
843 | ic->flags |= IRC_CHANNEL_CHAT_PICKME; |
---|
844 | acc->prpl->chat_join(acc->ic, room, nick, NULL, &ic->set); |
---|
845 | ic->flags &= ~IRC_CHANNEL_CHAT_PICKME; |
---|
846 | |
---|
847 | return FALSE; |
---|
848 | } else { |
---|
849 | irc_send_num(ic->irc, 403, "%s :Can't join channel, account offline?", ic->name); |
---|
850 | return FALSE; |
---|
851 | } |
---|
852 | } |
---|
853 | |
---|
854 | static gboolean bee_irc_channel_chat_part(irc_channel_t *ic, const char *msg) |
---|
855 | { |
---|
856 | struct groupchat *c = ic->data; |
---|
857 | |
---|
858 | if (c && c->ic->acc->prpl->chat_leave) { |
---|
859 | c->ic->acc->prpl->chat_leave(c); |
---|
860 | } |
---|
861 | |
---|
862 | /* Remove the reference. We don't need it anymore. */ |
---|
863 | ic->data = NULL; |
---|
864 | |
---|
865 | return TRUE; |
---|
866 | } |
---|
867 | |
---|
868 | static gboolean bee_irc_channel_chat_topic(irc_channel_t *ic, const char *new) |
---|
869 | { |
---|
870 | struct groupchat *c = ic->data; |
---|
871 | |
---|
872 | if (c == NULL) { |
---|
873 | return FALSE; |
---|
874 | } |
---|
875 | |
---|
876 | if (c->ic->acc->prpl->chat_topic == NULL) { |
---|
877 | irc_send_num(ic->irc, 482, "%s :IM network does not support channel topics", ic->name); |
---|
878 | } else { |
---|
879 | /* TODO: Need more const goodness here, sigh */ |
---|
880 | char *topic = g_strdup(new); |
---|
881 | c->ic->acc->prpl->chat_topic(c, topic); |
---|
882 | g_free(topic); |
---|
883 | } |
---|
884 | |
---|
885 | /* Whatever happened, the IM module should ack the topic change. */ |
---|
886 | return FALSE; |
---|
887 | } |
---|
888 | |
---|
889 | static gboolean bee_irc_channel_chat_invite(irc_channel_t *ic, irc_user_t *iu) |
---|
890 | { |
---|
891 | struct groupchat *c = ic->data; |
---|
892 | bee_user_t *bu = iu->bu; |
---|
893 | |
---|
894 | if (bu == NULL) { |
---|
895 | return FALSE; |
---|
896 | } |
---|
897 | |
---|
898 | if (c) { |
---|
899 | if (iu->bu->ic != c->ic) { |
---|
900 | irc_send_num(ic->irc, 482, "%s :Can't mix different IM networks in one groupchat", ic->name); |
---|
901 | } else if (c->ic->acc->prpl->chat_invite) { |
---|
902 | c->ic->acc->prpl->chat_invite(c, iu->bu->handle, NULL); |
---|
903 | } else { |
---|
904 | irc_send_num(ic->irc, 482, "%s :IM protocol does not support room invitations", ic->name); |
---|
905 | } |
---|
906 | } else if (bu->ic->acc->prpl->chat_with && |
---|
907 | strcmp(set_getstr(&ic->set, "chat_type"), "groupchat") == 0) { |
---|
908 | ic->flags |= IRC_CHANNEL_CHAT_PICKME; |
---|
909 | iu->bu->ic->acc->prpl->chat_with(bu->ic, bu->handle); |
---|
910 | ic->flags &= ~IRC_CHANNEL_CHAT_PICKME; |
---|
911 | } else { |
---|
912 | irc_send_num(ic->irc, 482, "%s :IM protocol does not support room invitations", ic->name); |
---|
913 | } |
---|
914 | |
---|
915 | return TRUE; |
---|
916 | } |
---|
917 | |
---|
918 | static void bee_irc_channel_chat_kick(irc_channel_t *ic, irc_user_t *iu, const char *msg) |
---|
919 | { |
---|
920 | struct groupchat *c = ic->data; |
---|
921 | bee_user_t *bu = iu->bu; |
---|
922 | |
---|
923 | if ((c == NULL) || (bu == NULL)) { |
---|
924 | return; |
---|
925 | } |
---|
926 | |
---|
927 | if (!c->ic->acc->prpl->chat_kick) { |
---|
928 | irc_send_num(ic->irc, 482, "%s :IM protocol does not support room kicking", ic->name); |
---|
929 | return; |
---|
930 | } |
---|
931 | |
---|
932 | c->ic->acc->prpl->chat_kick(c, iu->bu->handle, msg); |
---|
933 | } |
---|
934 | |
---|
935 | static char *set_eval_room_account(set_t *set, char *value); |
---|
936 | static char *set_eval_chat_type(set_t *set, char *value); |
---|
937 | |
---|
938 | static gboolean bee_irc_channel_init(irc_channel_t *ic) |
---|
939 | { |
---|
940 | set_t *s; |
---|
941 | |
---|
942 | set_add(&ic->set, "account", NULL, set_eval_room_account, ic); |
---|
943 | set_add(&ic->set, "chat_type", "groupchat", set_eval_chat_type, ic); |
---|
944 | |
---|
945 | s = set_add(&ic->set, "nick", NULL, NULL, ic); |
---|
946 | s->flags |= SET_NULL_OK; |
---|
947 | |
---|
948 | set_add(&ic->set, "room", NULL, NULL, ic); |
---|
949 | set_add(&ic->set, "translate_to_nicks", "true", set_eval_bool, ic); |
---|
950 | |
---|
951 | /* chat_type == groupchat */ |
---|
952 | ic->flags |= IRC_CHANNEL_TEMP; |
---|
953 | |
---|
954 | return TRUE; |
---|
955 | } |
---|
956 | |
---|
957 | static char *set_eval_room_account(set_t *set, char *value) |
---|
958 | { |
---|
959 | struct irc_channel *ic = set->data; |
---|
960 | account_t *acc, *oa; |
---|
961 | |
---|
962 | if (!(acc = account_get(ic->irc->b, value))) { |
---|
963 | return SET_INVALID; |
---|
964 | } else if (!acc->prpl->chat_join) { |
---|
965 | irc_rootmsg(ic->irc, "Named chatrooms not supported on that account."); |
---|
966 | return SET_INVALID; |
---|
967 | } |
---|
968 | |
---|
969 | if (set->value && (oa = account_get(ic->irc->b, set->value)) && |
---|
970 | oa->prpl->chat_free_settings) { |
---|
971 | oa->prpl->chat_free_settings(oa, &ic->set); |
---|
972 | } |
---|
973 | |
---|
974 | if (acc->prpl->chat_add_settings) { |
---|
975 | acc->prpl->chat_add_settings(acc, &ic->set); |
---|
976 | } |
---|
977 | |
---|
978 | return g_strdup(acc->tag); |
---|
979 | } |
---|
980 | |
---|
981 | static char *set_eval_chat_type(set_t *set, char *value) |
---|
982 | { |
---|
983 | struct irc_channel *ic = set->data; |
---|
984 | |
---|
985 | if (strcmp(value, "groupchat") == 0) { |
---|
986 | ic->flags |= IRC_CHANNEL_TEMP; |
---|
987 | } else if (strcmp(value, "room") == 0) { |
---|
988 | ic->flags &= ~IRC_CHANNEL_TEMP; |
---|
989 | } else { |
---|
990 | return NULL; |
---|
991 | } |
---|
992 | |
---|
993 | return value; |
---|
994 | } |
---|
995 | |
---|
996 | static gboolean bee_irc_channel_free(irc_channel_t *ic) |
---|
997 | { |
---|
998 | struct groupchat *c = ic->data; |
---|
999 | |
---|
1000 | set_del(&ic->set, "account"); |
---|
1001 | set_del(&ic->set, "chat_type"); |
---|
1002 | set_del(&ic->set, "nick"); |
---|
1003 | set_del(&ic->set, "room"); |
---|
1004 | set_del(&ic->set, "translate_to_nicks"); |
---|
1005 | |
---|
1006 | ic->flags &= ~IRC_CHANNEL_TEMP; |
---|
1007 | |
---|
1008 | /* That one still points at this channel. Don't. */ |
---|
1009 | if (c) { |
---|
1010 | c->ui_data = NULL; |
---|
1011 | } |
---|
1012 | |
---|
1013 | return TRUE; |
---|
1014 | } |
---|
1015 | |
---|
1016 | const struct irc_channel_funcs irc_channel_im_chat_funcs = { |
---|
1017 | bee_irc_channel_chat_privmsg, |
---|
1018 | bee_irc_channel_chat_join, |
---|
1019 | bee_irc_channel_chat_part, |
---|
1020 | bee_irc_channel_chat_topic, |
---|
1021 | bee_irc_channel_chat_invite, |
---|
1022 | bee_irc_channel_chat_kick, |
---|
1023 | |
---|
1024 | bee_irc_channel_init, |
---|
1025 | bee_irc_channel_free, |
---|
1026 | }; |
---|
1027 | |
---|
1028 | |
---|
1029 | /* IM->IRC: File transfers */ |
---|
1030 | static file_transfer_t *bee_irc_ft_in_start(bee_t *bee, bee_user_t *bu, const char *file_name, size_t file_size) |
---|
1031 | { |
---|
1032 | return dccs_send_start(bu->ic, (irc_user_t *) bu->ui_data, file_name, file_size); |
---|
1033 | } |
---|
1034 | |
---|
1035 | static gboolean bee_irc_ft_out_start(struct im_connection *ic, file_transfer_t *ft) |
---|
1036 | { |
---|
1037 | return dccs_recv_start(ft); |
---|
1038 | } |
---|
1039 | |
---|
1040 | static void bee_irc_ft_close(struct im_connection *ic, file_transfer_t *ft) |
---|
1041 | { |
---|
1042 | return dcc_close(ft); |
---|
1043 | } |
---|
1044 | |
---|
1045 | static void bee_irc_ft_finished(struct im_connection *ic, file_transfer_t *file) |
---|
1046 | { |
---|
1047 | dcc_file_transfer_t *df = file->priv; |
---|
1048 | |
---|
1049 | if (file->bytes_transferred >= file->file_size) { |
---|
1050 | dcc_finish(file); |
---|
1051 | } else { |
---|
1052 | df->proto_finished = TRUE; |
---|
1053 | } |
---|
1054 | } |
---|
1055 | |
---|
1056 | const struct bee_ui_funcs irc_ui_funcs = { |
---|
1057 | bee_irc_imc_connected, |
---|
1058 | bee_irc_imc_disconnected, |
---|
1059 | |
---|
1060 | bee_irc_user_new, |
---|
1061 | bee_irc_user_free, |
---|
1062 | bee_irc_user_fullname, |
---|
1063 | bee_irc_user_nick_hint, |
---|
1064 | bee_irc_user_group, |
---|
1065 | bee_irc_user_status, |
---|
1066 | bee_irc_user_msg, |
---|
1067 | bee_irc_user_typing, |
---|
1068 | bee_irc_user_action_response, |
---|
1069 | |
---|
1070 | bee_irc_chat_new, |
---|
1071 | bee_irc_chat_free, |
---|
1072 | bee_irc_chat_log, |
---|
1073 | bee_irc_chat_msg, |
---|
1074 | bee_irc_chat_add_user, |
---|
1075 | bee_irc_chat_remove_user, |
---|
1076 | bee_irc_chat_topic, |
---|
1077 | bee_irc_chat_name_hint, |
---|
1078 | bee_irc_chat_invite, |
---|
1079 | |
---|
1080 | bee_irc_ft_in_start, |
---|
1081 | bee_irc_ft_out_start, |
---|
1082 | bee_irc_ft_close, |
---|
1083 | bee_irc_ft_finished, |
---|
1084 | }; |
---|