source: irc_im.c @ 619dd18

Last change on this file since 619dd18 was 619dd18, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-06-07T18:40:08Z

Paste buffer functionality is back, now for users *and* rooms.

  • Property mode set to 100644
File size: 18.0 KB
Line 
1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2002-2010 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., 59 Temple Place,
23  Suite 330, Boston, MA  02111-1307  USA
24*/
25
26#include "bitlbee.h"
27#include "dcc.h"
28
29/* IM->IRC callbacks: Simple IM/buddy-related stuff. */
30
31static const struct irc_user_funcs irc_user_im_funcs;
32
33static gboolean bee_irc_user_new( bee_t *bee, bee_user_t *bu )
34{
35        irc_user_t *iu;
36        char nick[MAX_NICK_LENGTH+1], *s;
37       
38        memset( nick, 0, MAX_NICK_LENGTH + 1 );
39        strcpy( nick, nick_get( bu->ic->acc, bu->handle ) );
40       
41        bu->ui_data = iu = irc_user_new( (irc_t*) bee->ui_data, nick );
42        iu->bu = bu;
43       
44        if( ( s = strchr( bu->handle, '@' ) ) )
45        {
46                iu->host = g_strdup( s + 1 );
47                iu->user = g_strndup( bu->handle, s - bu->handle );
48        }
49        else if( bu->ic->acc->server )
50        {
51                iu->host = g_strdup( bu->ic->acc->server );
52                iu->user = g_strdup( bu->handle );
53               
54                /* s/ /_/ ... important for AOL screennames */
55                for( s = iu->user; *s; s ++ )
56                        if( *s == ' ' )
57                                *s = '_';
58        }
59        else
60        {
61                iu->host = g_strdup( bu->ic->acc->prpl->name );
62                iu->user = g_strdup( bu->handle );
63        }
64       
65        if( set_getbool( &bee->set, "private" ) )
66                iu->flags |= IRC_USER_PRIVATE;
67       
68        if( bu->flags & BEE_USER_LOCAL )
69        {
70                char *s = set_getstr( &bee->set, "handle_unknown" );
71               
72                if( strcmp( s, "add_private" ) == 0 )
73                        iu->flags |= IRC_USER_PRIVATE;
74                else if( strcmp( s, "add_channel" ) == 0 )
75                        iu->flags &= ~IRC_USER_PRIVATE;
76        }
77       
78        iu->f = &irc_user_im_funcs;
79        //iu->last_typing_notice = 0;
80       
81        return TRUE;
82}
83
84static gboolean bee_irc_user_free( bee_t *bee, bee_user_t *bu )
85{
86        return irc_user_free( bee->ui_data, (irc_user_t *) bu->ui_data );
87}
88
89static gboolean bee_irc_user_status( bee_t *bee, bee_user_t *bu, bee_user_t *old )
90{
91        irc_t *irc = bee->ui_data;
92        irc_user_t *iu = bu->ui_data;
93       
94        /* Do this outside the if below since away state can change without
95           the online state changing. */
96        iu->flags &= ~IRC_USER_AWAY;
97        if( bu->flags & BEE_USER_AWAY || !( bu->flags & BEE_USER_ONLINE ) )
98                iu->flags |= IRC_USER_AWAY;
99       
100        if( ( bu->flags & BEE_USER_ONLINE ) != ( old->flags & BEE_USER_ONLINE ) )
101        {
102                if( bu->flags & BEE_USER_ONLINE )
103                {
104                        if( g_hash_table_lookup( irc->watches, iu->key ) )
105                                irc_send_num( irc, 600, "%s %s %s %d :%s", iu->nick, iu->user,
106                                              iu->host, (int) time( NULL ), "logged online" );
107                }
108                else
109                {
110                        if( g_hash_table_lookup( irc->watches, iu->key ) )
111                                irc_send_num( irc, 601, "%s %s %s %d :%s", iu->nick, iu->user,
112                                              iu->host, (int) time( NULL ), "logged offline" );
113                }
114        }
115       
116        bee_irc_channel_update( irc, NULL, iu );
117       
118        return TRUE;
119}
120
121void bee_irc_channel_update( irc_t *irc, irc_channel_t *ic, irc_user_t *iu )
122{
123        struct irc_control_channel *icc;
124        GSList *l;
125        gboolean show;
126       
127        if( ic == NULL )
128        {
129                for( l = irc->channels; l; l = l->next )
130                {
131                        ic = l->data;
132                        /* TODO: Just add a type flag or so.. */
133                        if( ic->f == irc->default_channel->f )
134                                bee_irc_channel_update( irc, ic, iu );
135                }
136                return;
137        }
138        if( iu == NULL )
139        {
140                for( l = irc->users; l; l = l->next )
141                {
142                        iu = l->data;
143                        if( iu->bu )
144                                bee_irc_channel_update( irc, ic, l->data );
145                }
146                return;
147        }
148       
149        icc = ic->data;
150       
151        if( !( iu->bu->flags & BEE_USER_ONLINE ) )
152                show = FALSE;
153        else if( icc->type == IRC_CC_TYPE_DEFAULT )
154                show = TRUE;
155        else if( icc->type == IRC_CC_TYPE_GROUP )
156                show = iu->bu->group == icc->group;
157        else if( icc->type == IRC_CC_TYPE_ACCOUNT )
158                show = iu->bu->ic->acc == icc->account;
159       
160        if( !show )
161        {
162                irc_channel_del_user( ic, iu, FALSE, NULL );
163        }
164        else
165        {
166                irc_channel_add_user( ic, iu );
167               
168                if( set_getbool( &irc->b->set, "away_devoice" ) )
169                        irc_channel_user_set_mode( ic, iu, ( iu->bu->flags & BEE_USER_AWAY ) ?
170                                                   0 : IRC_CHANNEL_USER_VOICE );
171                else
172                        irc_channel_user_set_mode( ic, iu, 0 );
173        }
174}
175
176static gboolean bee_irc_user_msg( bee_t *bee, bee_user_t *bu, const char *msg, time_t sent_at )
177{
178        irc_t *irc = bee->ui_data;
179        irc_channel_t *ic = irc->default_channel;
180        irc_user_t *iu = (irc_user_t *) bu->ui_data;
181        char *dst, *prefix = NULL;
182        char *wrapped, *ts = NULL;
183       
184        if( sent_at > 0 && set_getbool( &irc->b->set, "display_timestamps" ) )
185                ts = irc_format_timestamp( irc, sent_at );
186       
187        if( iu->flags & IRC_USER_PRIVATE )
188        {
189                dst = irc->user->nick;
190                prefix = ts;
191                ts = NULL;
192        }
193        else
194        {
195                dst = ic->name;
196                prefix = g_strdup_printf( "%s%s%s", irc->user->nick, set_getstr( &bee->set, "to_char" ), ts ? : "" );
197        }
198       
199        wrapped = word_wrap( msg, 425 );
200        irc_send_msg( iu, "PRIVMSG", dst, wrapped, prefix );
201       
202        g_free( wrapped );
203        g_free( prefix );
204        g_free( ts );
205       
206        return TRUE;
207}
208
209static gboolean bee_irc_user_typing( bee_t *bee, bee_user_t *bu, uint32_t flags )
210{
211        irc_t *irc = (irc_t *) bee->ui_data;
212       
213        if( set_getbool( &bee->set, "typing_notice" ) )
214                irc_send_msg_f( (irc_user_t *) bu->ui_data, "PRIVMSG", irc->user->nick,
215                                "\001TYPING %d\001", ( flags >> 8 ) & 3 );
216        else
217                return FALSE;
218       
219        return TRUE;
220}
221
222static gboolean bee_irc_user_fullname( bee_t *bee, bee_user_t *bu )
223{
224        irc_user_t *iu = (irc_user_t *) bu->ui_data;
225        irc_t *irc = (irc_t *) bee->ui_data;
226        char *s;
227       
228        if( iu->fullname != iu->nick )
229                g_free( iu->fullname );
230        iu->fullname = g_strdup( bu->fullname );
231       
232        /* Strip newlines (unlikely, but IRC-unfriendly so they must go)
233           TODO(wilmer): Do the same with away msgs again! */
234        for( s = iu->fullname; *s; s ++ )
235                if( isspace( *s ) ) *s = ' ';
236       
237        if( ( bu->ic->flags & OPT_LOGGED_IN ) && set_getbool( &bee->set, "display_namechanges" ) )
238        {
239                char *msg = g_strdup_printf( "<< \002BitlBee\002 - Changed name to `%s' >>", iu->fullname );
240                irc_send_msg( iu, "NOTICE", irc->user->nick, msg, NULL );
241        }
242       
243        s = set_getstr( &bu->ic->acc->set, "nick_source" );
244        if( strcmp( s, "handle" ) != 0 )
245        {
246                char *name = g_strdup( bu->fullname );
247               
248                if( strcmp( s, "first_name" ) == 0 )
249                {
250                        int i;
251                        for( i = 0; name[i] && !isspace( name[i] ); i ++ ) {}
252                        name[i] = '\0';
253                }
254               
255                imcb_buddy_nick_hint( bu->ic, bu->handle, name );
256               
257                g_free( name );
258        }
259       
260        return TRUE;
261}
262
263static gboolean bee_irc_user_group( bee_t *bee, bee_user_t *bu )
264{
265        irc_user_t *iu = (irc_user_t *) bu->ui_data;
266        irc_t *irc = (irc_t *) bee->ui_data;
267       
268        bee_irc_channel_update( irc, NULL, iu );
269       
270        return TRUE;
271}
272
273/* IRC->IM calls */
274
275static gboolean bee_irc_user_privmsg_cb( gpointer data, gint fd, b_input_condition cond );
276
277static gboolean bee_irc_user_privmsg( irc_user_t *iu, const char *msg )
278{
279        if( iu->bu == NULL )
280                return FALSE;
281        else if( set_getbool( &iu->irc->b->set, "paste_buffer" ) )
282        {
283                int delay;
284               
285                if( iu->pastebuf == NULL )
286                        iu->pastebuf = g_string_new( msg );
287                else
288                {
289                        b_event_remove( iu->pastebuf_timer );
290                        g_string_append_printf( iu->pastebuf, "\n%s", msg );
291                }
292               
293                if( ( delay = set_getint( &iu->irc->b->set, "paste_buffer_delay" ) ) <= 5 )
294                        delay *= 1000;
295               
296                iu->pastebuf_timer = b_timeout_add( delay, bee_irc_user_privmsg_cb, iu );
297               
298                return TRUE;
299        }
300        else
301                return bee_user_msg( iu->irc->b, iu->bu, msg, 0 );
302}
303
304static gboolean bee_irc_user_privmsg_cb( gpointer data, gint fd, b_input_condition cond )
305{
306        irc_user_t *iu = data;
307       
308        bee_user_msg( iu->irc->b, iu->bu, iu->pastebuf->str, 0 );
309       
310        g_string_free( iu->pastebuf, TRUE );
311        iu->pastebuf = 0;
312        iu->pastebuf_timer = 0;
313       
314        return FALSE;
315}
316
317static gboolean bee_irc_user_ctcp( irc_user_t *iu, char *const *ctcp )
318{
319        if( ctcp[1] && g_strcasecmp( ctcp[0], "DCC" ) == 0
320                    && g_strcasecmp( ctcp[1], "SEND" ) == 0 )
321        {
322                if( iu->bu && iu->bu->ic && iu->bu->ic->acc->prpl->transfer_request )
323                {
324                        file_transfer_t *ft = dcc_request( iu->bu->ic, ctcp );
325                        if ( ft )
326                                iu->bu->ic->acc->prpl->transfer_request( iu->bu->ic, ft, iu->bu->handle );
327                       
328                        return TRUE;
329                }
330        }
331        else if( g_strcasecmp( ctcp[0], "TYPING" ) == 0 )
332        {
333                if( iu->bu && iu->bu->ic && iu->bu->ic->acc->prpl->send_typing && ctcp[1] )
334                {
335                        int st = ctcp[1][0];
336                        if( st >= '0' && st <= '2' )
337                        {
338                                st <<= 8;
339                                iu->bu->ic->acc->prpl->send_typing( iu->bu->ic, iu->bu->handle, st );
340                        }
341                       
342                        return TRUE;
343                }
344        }
345       
346        return FALSE;
347}
348
349static const struct irc_user_funcs irc_user_im_funcs = {
350        bee_irc_user_privmsg,
351        bee_irc_user_ctcp,
352};
353
354
355/* IM->IRC: Groupchats */
356const struct irc_channel_funcs irc_channel_im_chat_funcs;
357
358static gboolean bee_irc_chat_new( bee_t *bee, struct groupchat *c )
359{
360        irc_t *irc = bee->ui_data;
361        irc_channel_t *ic;
362        char *topic;
363        GSList *l;
364        int i;
365       
366        /* Try to find a channel that expects to receive a groupchat.
367           This flag is set by groupchat_stub_invite(). */
368        for( l = irc->channels; l; l = l->next )
369        {
370                ic = l->data;
371                if( ic->flags & IRC_CHANNEL_CHAT_PICKME )
372                        break;
373        }
374       
375        /* If we found none, just generate some stupid name. */
376        if( l == NULL ) for( i = 0; i <= 999; i ++ )
377        {
378                char name[16];
379                sprintf( name, "#chat_%03d", i );
380                if( ( ic = irc_channel_new( irc, name ) ) )
381                        break;
382        }
383       
384        if( ic == NULL )
385                return FALSE;
386       
387        c->ui_data = ic;
388        ic->data = c;
389       
390        topic = g_strdup_printf( "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", c->title );
391        irc_channel_set_topic( ic, topic, irc->root );
392        g_free( topic );
393       
394        return TRUE;
395}
396
397static gboolean bee_irc_chat_free( bee_t *bee, struct groupchat *c )
398{
399        irc_channel_t *ic = c->ui_data;
400       
401        if( ic->flags & IRC_CHANNEL_JOINED )
402                irc_channel_printf( ic, "Cleaning up channel, bye!" );
403       
404        /* irc_channel_free( ic ); */
405       
406        irc_channel_del_user( ic, ic->irc->user, FALSE, "Chatroom closed by server" );
407        ic->data = NULL;
408       
409        return TRUE;
410}
411
412static gboolean bee_irc_chat_log( bee_t *bee, struct groupchat *c, const char *text )
413{
414        irc_channel_t *ic = c->ui_data;
415       
416        irc_channel_printf( ic, "%s", text );
417       
418        return TRUE;
419}
420
421static gboolean bee_irc_chat_msg( bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *msg, time_t sent_at )
422{
423        irc_t *irc = bee->ui_data;
424        irc_user_t *iu = bu->ui_data;
425        irc_channel_t *ic = c->ui_data;
426        char *ts = NULL;
427       
428        if( sent_at > 0 && set_getbool( &bee->set, "display_timestamps" ) )
429                ts = irc_format_timestamp( irc, sent_at );
430       
431        irc_send_msg( iu, "PRIVMSG", ic->name, msg, ts );
432        g_free( ts );
433       
434        return TRUE;
435}
436
437static gboolean bee_irc_chat_add_user( bee_t *bee, struct groupchat *c, bee_user_t *bu )
438{
439        irc_t *irc = bee->ui_data;
440       
441        irc_channel_add_user( c->ui_data, bu == bee->user ? irc->user : bu->ui_data );
442       
443        return TRUE;
444}
445
446static gboolean bee_irc_chat_remove_user( bee_t *bee, struct groupchat *c, bee_user_t *bu )
447{
448        irc_t *irc = bee->ui_data;
449       
450        irc_channel_del_user( c->ui_data, bu == bee->user ? irc->user : bu->ui_data, FALSE, NULL );
451       
452        return TRUE;
453}
454
455static gboolean bee_irc_chat_topic( bee_t *bee, struct groupchat *c, const char *new, bee_user_t *bu )
456{
457        irc_t *irc = bee->ui_data;
458        irc_user_t *iu;
459       
460        if( bu == NULL )
461                iu = irc->root;
462        else if( bu == bee->user )
463                iu = irc->user;
464        else
465                iu = bu->ui_data;
466       
467        irc_channel_set_topic( c->ui_data, new, iu );
468       
469        return TRUE;
470}
471
472static gboolean bee_irc_chat_name_hint( bee_t *bee, struct groupchat *c, const char *name )
473{
474        irc_t *irc = bee->ui_data;
475        irc_channel_t *ic = c->ui_data;
476        char stripped[MAX_NICK_LENGTH+1], *full_name;
477       
478        /* Don't rename a channel if the user's in it already. */
479        if( ic->flags & IRC_CHANNEL_JOINED )
480                return FALSE;
481       
482        strncpy( stripped, name, MAX_NICK_LENGTH );
483        stripped[MAX_NICK_LENGTH] = '\0';
484        nick_strip( stripped );
485        if( set_getbool( &bee->set, "lcnicks" ) )
486                nick_lc( stripped );
487       
488        full_name = g_strdup_printf( "&%s", stripped );
489       
490        if( stripped[0] && irc_channel_by_name( irc, full_name ) == NULL )
491        {
492                g_free( ic->name );
493                ic->name = full_name;
494        }
495        else
496        {
497                g_free( full_name );
498        }
499       
500        return TRUE;
501}
502
503/* IRC->IM */
504static gboolean bee_irc_channel_chat_privmsg_cb( gpointer data, gint fd, b_input_condition cond );
505
506static gboolean bee_irc_channel_chat_privmsg( irc_channel_t *ic, const char *msg )
507{
508        struct groupchat *c = ic->data;
509       
510        if( c == NULL )
511                return FALSE;
512        else if( set_getbool( &ic->irc->b->set, "paste_buffer" ) )
513        {
514                int delay;
515               
516                if( ic->pastebuf == NULL )
517                        ic->pastebuf = g_string_new( msg );
518                else
519                {
520                        b_event_remove( ic->pastebuf_timer );
521                        g_string_append_printf( ic->pastebuf, "\n%s", msg );
522                }
523               
524                if( ( delay = set_getint( &ic->irc->b->set, "paste_buffer_delay" ) ) <= 5 )
525                        delay *= 1000;
526               
527                ic->pastebuf_timer = b_timeout_add( delay, bee_irc_channel_chat_privmsg_cb, ic );
528               
529                return TRUE;
530        }
531        else
532                bee_chat_msg( ic->irc->b, c, msg, 0 );
533       
534        return TRUE;
535}
536
537static gboolean bee_irc_channel_chat_privmsg_cb( gpointer data, gint fd, b_input_condition cond )
538{
539        irc_channel_t *ic = data;
540       
541        bee_chat_msg( ic->irc->b, ic->data, ic->pastebuf->str, 0 );
542       
543        g_string_free( ic->pastebuf, TRUE );
544        ic->pastebuf = 0;
545        ic->pastebuf_timer = 0;
546       
547        return FALSE;
548}
549
550static gboolean bee_irc_channel_chat_join( irc_channel_t *ic )
551{
552        char *acc_s, *room;
553        account_t *acc;
554       
555        if( strcmp( set_getstr( &ic->set, "chat_type" ), "room" ) != 0 )
556                return TRUE;
557       
558        if( ( acc_s = set_getstr( &ic->set, "account" ) ) &&
559            ( room = set_getstr( &ic->set, "room" ) ) &&
560            ( acc = account_get( ic->irc->b, acc_s ) ) &&
561            acc->ic && acc->prpl->chat_join )
562        {
563                char *nick;
564               
565                if( !( nick = set_getstr( &ic->set, "nick" ) ) )
566                        nick = ic->irc->user->nick;
567               
568                ic->flags |= IRC_CHANNEL_CHAT_PICKME;
569                acc->prpl->chat_join( acc->ic, room, nick, NULL );
570                ic->flags &= ~IRC_CHANNEL_CHAT_PICKME;
571               
572                return FALSE;
573        }
574        else
575        {
576                irc_send_num( ic->irc, 403, "%s :Can't join channel, account offline?", ic->name );
577                return FALSE;
578        }
579}
580
581static gboolean bee_irc_channel_chat_part( irc_channel_t *ic, const char *msg )
582{
583        struct groupchat *c = ic->data;
584       
585        if( c && c->ic->acc->prpl->chat_leave )
586                c->ic->acc->prpl->chat_leave( c );
587       
588        return TRUE;
589}
590
591static gboolean bee_irc_channel_chat_topic( irc_channel_t *ic, const char *new )
592{
593        struct groupchat *c = ic->data;
594       
595        if( c == NULL )
596                return FALSE;
597       
598        if( c->ic->acc->prpl->chat_topic == NULL )
599                irc_send_num( ic->irc, 482, "%s :IM network does not support channel topics", ic->name );
600        else
601        {
602                /* TODO: Need more const goodness here, sigh */
603                char *topic = g_strdup( new );
604                c->ic->acc->prpl->chat_topic( c, topic );
605                g_free( topic );
606                return TRUE;
607        }
608               
609        return FALSE;
610}
611
612static gboolean bee_irc_channel_chat_invite( irc_channel_t *ic, irc_user_t *iu )
613{
614        struct groupchat *c = ic->data;
615        bee_user_t *bu = iu->bu;
616       
617        if( bu == NULL )
618                return FALSE;
619       
620        if( c )
621        {
622                if( iu->bu->ic != c->ic )
623                        irc_send_num( ic->irc, 482, "%s :Can't mix different IM networks in one groupchat", ic->name );
624                else if( c->ic->acc->prpl->chat_invite )
625                        c->ic->acc->prpl->chat_invite( c, iu->bu->handle, NULL );
626                else
627                        irc_send_num( ic->irc, 482, "%s :IM protocol does not support room invitations", ic->name );
628        }
629        else if( bu->ic->acc->prpl->chat_with &&
630                 strcmp( set_getstr( &ic->set, "chat_type" ), "groupchat" ) == 0 )
631        {
632                ic->flags |= IRC_CHANNEL_CHAT_PICKME;
633                iu->bu->ic->acc->prpl->chat_with( bu->ic, bu->handle );
634                ic->flags &= ~IRC_CHANNEL_CHAT_PICKME;
635        }
636        else
637        {
638                irc_send_num( ic->irc, 482, "%s :IM protocol does not support room invitations", ic->name );
639        }
640       
641        return TRUE;
642}
643
644static char *set_eval_room_account( set_t *set, char *value );
645
646static gboolean bee_irc_channel_init( irc_channel_t *ic )
647{
648        set_add( &ic->set, "account", NULL, set_eval_room_account, ic );
649        set_add( &ic->set, "chat_type", "groupchat", NULL, ic );
650        set_add( &ic->set, "nick", NULL, NULL, ic );
651        set_add( &ic->set, "room", NULL, NULL, ic );
652       
653        return TRUE;
654}
655
656static char *set_eval_room_account( set_t *set, char *value )
657{
658        struct irc_channel *ic = set->data;
659        account_t *acc;
660       
661        if( !( acc = account_get( ic->irc->b, value ) ) )
662                return SET_INVALID;
663        else if( !acc->prpl->chat_join )
664        {
665                irc_usermsg( ic->irc, "Named chatrooms not supported on that account." );
666                return SET_INVALID;
667        }
668       
669        return g_strdup_printf( "%s(%s)", acc->prpl->name, acc->user );
670}
671
672static gboolean bee_irc_channel_free( irc_channel_t *ic )
673{
674        set_del( &ic->set, "account" );
675        set_del( &ic->set, "chat_type" );
676        set_del( &ic->set, "nick" );
677        set_del( &ic->set, "room" );
678       
679        return TRUE;
680}
681
682const struct irc_channel_funcs irc_channel_im_chat_funcs = {
683        bee_irc_channel_chat_privmsg,
684        bee_irc_channel_chat_join,
685        bee_irc_channel_chat_part,
686        bee_irc_channel_chat_topic,
687        bee_irc_channel_chat_invite,
688
689        bee_irc_channel_init,
690        bee_irc_channel_free,
691};
692
693
694/* IM->IRC: File transfers */
695static file_transfer_t *bee_irc_ft_in_start( bee_t *bee, bee_user_t *bu, const char *file_name, size_t file_size )
696{
697        return dccs_send_start( bu->ic, (irc_user_t *) bu->ui_data, file_name, file_size );
698}
699
700static gboolean bee_irc_ft_out_start( struct im_connection *ic, file_transfer_t *ft )
701{
702        return dccs_recv_start( ft );
703}
704
705static void bee_irc_ft_close( struct im_connection *ic, file_transfer_t *ft )
706{
707        return dcc_close( ft );
708}
709
710static void bee_irc_ft_finished( struct im_connection *ic, file_transfer_t *file )
711{
712        dcc_file_transfer_t *df = file->priv;
713
714        if( file->bytes_transferred >= file->file_size )
715                dcc_finish( file );
716        else
717                df->proto_finished = TRUE;
718}
719
720const struct bee_ui_funcs irc_ui_funcs = {
721        bee_irc_user_new,
722        bee_irc_user_free,
723        bee_irc_user_fullname,
724        bee_irc_user_group,
725        bee_irc_user_status,
726        bee_irc_user_msg,
727        bee_irc_user_typing,
728       
729        bee_irc_chat_new,
730        bee_irc_chat_free,
731        bee_irc_chat_log,
732        bee_irc_chat_msg,
733        bee_irc_chat_add_user,
734        bee_irc_chat_remove_user,
735        bee_irc_chat_topic,
736        bee_irc_chat_name_hint,
737       
738        bee_irc_ft_in_start,
739        bee_irc_ft_out_start,
740        bee_irc_ft_close,
741        bee_irc_ft_finished,
742};
Note: See TracBrowser for help on using the repository browser.