source: irc_im.c @ 92c8d41

Last change on this file since 92c8d41 was 92c8d41, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-06-26T21:26:41Z

Remember in which channel the user talked to someone and show responses in
that same channel.

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