source: irc_im.c @ 6ef9065

Last change on this file since 6ef9065 was 6ef9065, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-06-07T21:09:33Z

Restored nick_hint/nick_source functionality.

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