source: irc_im.c @ ab6006c

Last change on this file since ab6006c was 1c40aa7, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-06-28T00:07:46Z

Mark nameless groupchat channels as temporary so they don't stick around
forever.

  • Property mode set to 100644
File size: 20.3 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        ic->data = NULL;
458        irc_channel_del_user( ic, ic->irc->user, FALSE, "Chatroom closed by server" );
459       
460        return TRUE;
461}
462
463static gboolean bee_irc_chat_log( bee_t *bee, struct groupchat *c, const char *text )
464{
465        irc_channel_t *ic = c->ui_data;
466       
467        irc_channel_printf( ic, "%s", text );
468       
469        return TRUE;
470}
471
472static gboolean bee_irc_chat_msg( bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *msg, time_t sent_at )
473{
474        irc_t *irc = bee->ui_data;
475        irc_user_t *iu = bu->ui_data;
476        irc_channel_t *ic = c->ui_data;
477        char *ts = NULL;
478       
479        if( sent_at > 0 && set_getbool( &bee->set, "display_timestamps" ) )
480                ts = irc_format_timestamp( irc, sent_at );
481       
482        irc_send_msg( iu, "PRIVMSG", ic->name, msg, ts );
483        g_free( ts );
484       
485        return TRUE;
486}
487
488static gboolean bee_irc_chat_add_user( bee_t *bee, struct groupchat *c, bee_user_t *bu )
489{
490        irc_t *irc = bee->ui_data;
491       
492        irc_channel_add_user( c->ui_data, bu == bee->user ? irc->user : bu->ui_data );
493       
494        return TRUE;
495}
496
497static gboolean bee_irc_chat_remove_user( bee_t *bee, struct groupchat *c, bee_user_t *bu )
498{
499        irc_t *irc = bee->ui_data;
500       
501        /* TODO: Possible bug here: If a module removes $user here instead of just
502           using imcb_chat_free() and the channel was IRC_CHANNEL_TEMP, we get into
503           a broken state around here. */
504        irc_channel_del_user( c->ui_data, bu == bee->user ? irc->user : bu->ui_data, FALSE, NULL );
505       
506        return TRUE;
507}
508
509static gboolean bee_irc_chat_topic( bee_t *bee, struct groupchat *c, const char *new, bee_user_t *bu )
510{
511        irc_t *irc = bee->ui_data;
512        irc_user_t *iu;
513       
514        if( bu == NULL )
515                iu = irc->root;
516        else if( bu == bee->user )
517                iu = irc->user;
518        else
519                iu = bu->ui_data;
520       
521        irc_channel_set_topic( c->ui_data, new, iu );
522       
523        return TRUE;
524}
525
526static gboolean bee_irc_chat_name_hint( bee_t *bee, struct groupchat *c, const char *name )
527{
528        irc_t *irc = bee->ui_data;
529        irc_channel_t *ic = c->ui_data;
530        char stripped[MAX_NICK_LENGTH+1], *full_name;
531       
532        /* Don't rename a channel if the user's in it already. */
533        if( ic->flags & IRC_CHANNEL_JOINED )
534                return FALSE;
535       
536        strncpy( stripped, name, MAX_NICK_LENGTH );
537        stripped[MAX_NICK_LENGTH] = '\0';
538        irc_channel_name_strip( stripped );
539        if( set_getbool( &bee->set, "lcnicks" ) )
540                nick_lc( stripped );
541       
542        full_name = g_strdup_printf( "#%s", stripped );
543       
544        if( stripped[0] && irc_channel_by_name( irc, full_name ) == NULL )
545        {
546                g_free( ic->name );
547                ic->name = full_name;
548        }
549        else
550        {
551                g_free( full_name );
552        }
553       
554        return TRUE;
555}
556
557/* IRC->IM */
558static gboolean bee_irc_channel_chat_privmsg_cb( gpointer data, gint fd, b_input_condition cond );
559
560static gboolean bee_irc_channel_chat_privmsg( irc_channel_t *ic, const char *msg )
561{
562        struct groupchat *c = ic->data;
563       
564        if( c == NULL )
565                return FALSE;
566        else if( set_getbool( &ic->irc->b->set, "paste_buffer" ) )
567        {
568                int delay;
569               
570                if( ic->pastebuf == NULL )
571                        ic->pastebuf = g_string_new( msg );
572                else
573                {
574                        b_event_remove( ic->pastebuf_timer );
575                        g_string_append_printf( ic->pastebuf, "\n%s", msg );
576                }
577               
578                if( ( delay = set_getint( &ic->irc->b->set, "paste_buffer_delay" ) ) <= 5 )
579                        delay *= 1000;
580               
581                ic->pastebuf_timer = b_timeout_add( delay, bee_irc_channel_chat_privmsg_cb, ic );
582               
583                return TRUE;
584        }
585        else
586                bee_chat_msg( ic->irc->b, c, msg, 0 );
587       
588        return TRUE;
589}
590
591static gboolean bee_irc_channel_chat_privmsg_cb( gpointer data, gint fd, b_input_condition cond )
592{
593        irc_channel_t *ic = data;
594       
595        bee_chat_msg( ic->irc->b, ic->data, ic->pastebuf->str, 0 );
596       
597        g_string_free( ic->pastebuf, TRUE );
598        ic->pastebuf = 0;
599        ic->pastebuf_timer = 0;
600       
601        return FALSE;
602}
603
604static gboolean bee_irc_channel_chat_join( irc_channel_t *ic )
605{
606        char *acc_s, *room;
607        account_t *acc;
608       
609        if( strcmp( set_getstr( &ic->set, "chat_type" ), "room" ) != 0 )
610                return TRUE;
611       
612        if( ( acc_s = set_getstr( &ic->set, "account" ) ) &&
613            ( room = set_getstr( &ic->set, "room" ) ) &&
614            ( acc = account_get( ic->irc->b, acc_s ) ) &&
615            acc->ic && acc->prpl->chat_join )
616        {
617                char *nick;
618               
619                if( !( nick = set_getstr( &ic->set, "nick" ) ) )
620                        nick = ic->irc->user->nick;
621               
622                ic->flags |= IRC_CHANNEL_CHAT_PICKME;
623                acc->prpl->chat_join( acc->ic, room, nick, NULL );
624                ic->flags &= ~IRC_CHANNEL_CHAT_PICKME;
625               
626                return FALSE;
627        }
628        else
629        {
630                irc_send_num( ic->irc, 403, "%s :Can't join channel, account offline?", ic->name );
631                return FALSE;
632        }
633}
634
635static gboolean bee_irc_channel_chat_part( irc_channel_t *ic, const char *msg )
636{
637        struct groupchat *c = ic->data;
638       
639        if( c && c->ic->acc->prpl->chat_leave )
640                c->ic->acc->prpl->chat_leave( c );
641       
642        return TRUE;
643}
644
645static gboolean bee_irc_channel_chat_topic( irc_channel_t *ic, const char *new )
646{
647        struct groupchat *c = ic->data;
648       
649        if( c == NULL )
650                return FALSE;
651       
652        if( c->ic->acc->prpl->chat_topic == NULL )
653                irc_send_num( ic->irc, 482, "%s :IM network does not support channel topics", ic->name );
654        else
655        {
656                /* TODO: Need more const goodness here, sigh */
657                char *topic = g_strdup( new );
658                c->ic->acc->prpl->chat_topic( c, topic );
659                g_free( topic );
660                return TRUE;
661        }
662               
663        return FALSE;
664}
665
666static gboolean bee_irc_channel_chat_invite( irc_channel_t *ic, irc_user_t *iu )
667{
668        struct groupchat *c = ic->data;
669        bee_user_t *bu = iu->bu;
670       
671        if( bu == NULL )
672                return FALSE;
673       
674        if( c )
675        {
676                if( iu->bu->ic != c->ic )
677                        irc_send_num( ic->irc, 482, "%s :Can't mix different IM networks in one groupchat", ic->name );
678                else if( c->ic->acc->prpl->chat_invite )
679                        c->ic->acc->prpl->chat_invite( c, iu->bu->handle, NULL );
680                else
681                        irc_send_num( ic->irc, 482, "%s :IM protocol does not support room invitations", ic->name );
682        }
683        else if( bu->ic->acc->prpl->chat_with &&
684                 strcmp( set_getstr( &ic->set, "chat_type" ), "groupchat" ) == 0 )
685        {
686                ic->flags |= IRC_CHANNEL_CHAT_PICKME;
687                iu->bu->ic->acc->prpl->chat_with( bu->ic, bu->handle );
688                ic->flags &= ~IRC_CHANNEL_CHAT_PICKME;
689        }
690        else
691        {
692                irc_send_num( ic->irc, 482, "%s :IM protocol does not support room invitations", ic->name );
693        }
694       
695        return TRUE;
696}
697
698static char *set_eval_room_account( set_t *set, char *value );
699static char *set_eval_chat_type( set_t *set, char *value );
700
701static gboolean bee_irc_channel_init( irc_channel_t *ic )
702{
703        set_add( &ic->set, "account", NULL, set_eval_room_account, ic );
704        set_add( &ic->set, "chat_type", "groupchat", set_eval_chat_type, ic );
705        set_add( &ic->set, "nick", NULL, NULL, ic );
706        set_add( &ic->set, "room", NULL, NULL, ic );
707       
708        /* chat_type == groupchat */
709        ic->flags |= IRC_CHANNEL_TEMP;
710       
711        return TRUE;
712}
713
714static char *set_eval_room_account( set_t *set, char *value )
715{
716        struct irc_channel *ic = set->data;
717        account_t *acc;
718       
719        if( !( acc = account_get( ic->irc->b, value ) ) )
720                return SET_INVALID;
721        else if( !acc->prpl->chat_join )
722        {
723                irc_usermsg( ic->irc, "Named chatrooms not supported on that account." );
724                return SET_INVALID;
725        }
726       
727        return g_strdup_printf( "%s(%s)", acc->prpl->name, acc->user );
728}
729
730static char *set_eval_chat_type( set_t *set, char *value )
731{
732        struct irc_channel *ic = set->data;
733       
734        if( strcmp( value, "groupchat" ) == 0 )
735                ic->flags |= IRC_CHANNEL_TEMP;
736        else if( strcmp( value, "room" ) == 0 )
737                ic->flags &= ~IRC_CHANNEL_TEMP;
738        else
739                return NULL;
740       
741        return value;
742}
743
744static gboolean bee_irc_channel_free( irc_channel_t *ic )
745{
746        set_del( &ic->set, "account" );
747        set_del( &ic->set, "chat_type" );
748        set_del( &ic->set, "nick" );
749        set_del( &ic->set, "room" );
750       
751        ic->flags &= ~IRC_CHANNEL_TEMP;
752       
753        return TRUE;
754}
755
756const struct irc_channel_funcs irc_channel_im_chat_funcs = {
757        bee_irc_channel_chat_privmsg,
758        bee_irc_channel_chat_join,
759        bee_irc_channel_chat_part,
760        bee_irc_channel_chat_topic,
761        bee_irc_channel_chat_invite,
762
763        bee_irc_channel_init,
764        bee_irc_channel_free,
765};
766
767
768/* IM->IRC: File transfers */
769static file_transfer_t *bee_irc_ft_in_start( bee_t *bee, bee_user_t *bu, const char *file_name, size_t file_size )
770{
771        return dccs_send_start( bu->ic, (irc_user_t *) bu->ui_data, file_name, file_size );
772}
773
774static gboolean bee_irc_ft_out_start( struct im_connection *ic, file_transfer_t *ft )
775{
776        return dccs_recv_start( ft );
777}
778
779static void bee_irc_ft_close( struct im_connection *ic, file_transfer_t *ft )
780{
781        return dcc_close( ft );
782}
783
784static void bee_irc_ft_finished( struct im_connection *ic, file_transfer_t *file )
785{
786        dcc_file_transfer_t *df = file->priv;
787
788        if( file->bytes_transferred >= file->file_size )
789                dcc_finish( file );
790        else
791                df->proto_finished = TRUE;
792}
793
794const struct bee_ui_funcs irc_ui_funcs = {
795        bee_irc_user_new,
796        bee_irc_user_free,
797        bee_irc_user_fullname,
798        bee_irc_user_nick_hint,
799        bee_irc_user_group,
800        bee_irc_user_status,
801        bee_irc_user_msg,
802        bee_irc_user_typing,
803       
804        bee_irc_chat_new,
805        bee_irc_chat_free,
806        bee_irc_chat_log,
807        bee_irc_chat_msg,
808        bee_irc_chat_add_user,
809        bee_irc_chat_remove_user,
810        bee_irc_chat_topic,
811        bee_irc_chat_name_hint,
812       
813        bee_irc_ft_in_start,
814        bee_irc_ft_out_start,
815        bee_irc_ft_close,
816        bee_irc_ft_finished,
817};
Note: See TracBrowser for help on using the repository browser.