source: protocols/nogaim.c @ 3ab1d31

Last change on this file since 3ab1d31 was 449a51d, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-03-16T10:18:02Z

Include non-away status messages in blist and whois responses. The whois
change is a complete violation of the IRC protocol but that doesn't seem
to be an uncommon thing.

  • Property mode set to 100644
File size: 29.5 KB
RevLine 
[b7d3cc34]1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
[58adb7e]4  * Copyright 2002-2010 Wilmer van der Gaast and others                *
[b7d3cc34]5  \********************************************************************/
6
7/*
8 * nogaim
9 *
10 * Gaim without gaim - for BitlBee
11 *
12 * This file contains functions called by the Gaim IM-modules. It's written
13 * from scratch for BitlBee and doesn't contain any code from Gaim anymore
14 * (except for the function names).
15 */
16
17/*
18  This program is free software; you can redistribute it and/or modify
19  it under the terms of the GNU General Public License as published by
20  the Free Software Foundation; either version 2 of the License, or
21  (at your option) any later version.
22
23  This program is distributed in the hope that it will be useful,
24  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  GNU General Public License for more details.
27
28  You should have received a copy of the GNU General Public License with
29  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
30  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
31  Suite 330, Boston, MA  02111-1307  USA
32*/
33
34#define BITLBEE_CORE
35#include <ctype.h>
36
[4cf80bb]37#include "nogaim.h"
38#include "chat.h"
39
[764b163d]40static int remove_chat_buddy_silent( struct groupchat *b, const char *handle );
[b7d3cc34]41
42GSList *connections;
43
[65e2ce1]44#ifdef WITH_PLUGINS
[7b23afd]45gboolean load_plugin(char *path)
46{
47        void (*init_function) (void);
48       
49        GModule *mod = g_module_open(path, G_MODULE_BIND_LAZY);
50
51        if(!mod) {
[8ad90fb]52                log_message(LOGLVL_ERROR, "Can't find `%s', not loading (%s)\n", path, g_module_error());
[7b23afd]53                return FALSE;
54        }
55
56        if(!g_module_symbol(mod,"init_plugin",(gpointer *) &init_function)) {
57                log_message(LOGLVL_WARNING, "Can't find function `init_plugin' in `%s'\n", path);
58                return FALSE;
59        }
60
61        init_function();
62
63        return TRUE;
64}
[b7d3cc34]65
[65e2ce1]66void load_plugins(void)
67{
68        GDir *dir;
69        GError *error = NULL;
70
[4bfca70]71        dir = g_dir_open(global.conf->plugindir, 0, &error);
[65e2ce1]72
73        if (dir) {
74                const gchar *entry;
75                char *path;
76
77                while ((entry = g_dir_read_name(dir))) {
[4bfca70]78                        path = g_build_filename(global.conf->plugindir, entry, NULL);
[65e2ce1]79                        if(!path) {
80                                log_message(LOGLVL_WARNING, "Can't build path for %s\n", entry);
81                                continue;
82                        }
83
84                        load_plugin(path);
85
86                        g_free(path);
87                }
88
89                g_dir_close(dir);
90        }
91}
92#endif
[b7d3cc34]93
94/* nogaim.c */
95
[7b23afd]96GList *protocols = NULL;
97 
98void register_protocol (struct prpl *p)
99{
[90cd6c4]100        int i;
101        gboolean refused = global.conf->protocols != NULL;
102 
103        for (i = 0; global.conf->protocols && global.conf->protocols[i]; i++)
104        {
105                if (g_strcasecmp(p->name, global.conf->protocols[i]) == 0)
106                        refused = FALSE;
107        }
108
109        if (refused)
110                log_message(LOGLVL_WARNING, "Protocol %s disabled\n", p->name);
111        else
112                protocols = g_list_append(protocols, p);
[7b23afd]113}
114
115struct prpl *find_protocol(const char *name)
116{
117        GList *gl;
118        for (gl = protocols; gl; gl = gl->next) 
119        {
120                struct prpl *proto = gl->data;
121                if(!g_strcasecmp(proto->name, name)) 
122                        return proto;
123        }
124        return NULL;
125}
126
127/* nogaim.c */
[b7d3cc34]128void nogaim_init()
129{
[0da65d5]130        extern void msn_initmodule();
131        extern void oscar_initmodule();
132        extern void byahoo_initmodule();
133        extern void jabber_initmodule();
[7b23afd]134
[b7d3cc34]135#ifdef WITH_MSN
[0da65d5]136        msn_initmodule();
[b7d3cc34]137#endif
138
139#ifdef WITH_OSCAR
[0da65d5]140        oscar_initmodule();
[b7d3cc34]141#endif
142       
143#ifdef WITH_YAHOO
[0da65d5]144        byahoo_initmodule();
[b7d3cc34]145#endif
146       
147#ifdef WITH_JABBER
[0da65d5]148        jabber_initmodule();
[b7d3cc34]149#endif
[7b23afd]150
[65e2ce1]151#ifdef WITH_PLUGINS
152        load_plugins();
[b7d3cc34]153#endif
154}
155
156GSList *get_connections() { return connections; }
157
158/* multi.c */
159
[84b045d]160struct im_connection *imcb_new( account_t *acc )
[b7d3cc34]161{
[0da65d5]162        struct im_connection *ic;
[b7d3cc34]163       
[0da65d5]164        ic = g_new0( struct im_connection, 1 );
[b7d3cc34]165       
[0da65d5]166        ic->irc = acc->irc;
167        ic->acc = acc;
168        acc->ic = ic;
[b7d3cc34]169       
[0da65d5]170        connections = g_slist_append( connections, ic );
[b7d3cc34]171       
[0da65d5]172        return( ic );
[b7d3cc34]173}
174
[aef4828]175void imc_free( struct im_connection *ic )
[b7d3cc34]176{
177        account_t *a;
178       
179        /* Destroy the pointer to this connection from the account list */
[0da65d5]180        for( a = ic->irc->accounts; a; a = a->next )
181                if( a->ic == ic )
[b7d3cc34]182                {
[0da65d5]183                        a->ic = NULL;
[b7d3cc34]184                        break;
185                }
186       
[0da65d5]187        connections = g_slist_remove( connections, ic );
188        g_free( ic );
[b7d3cc34]189}
190
[aef4828]191static void serv_got_crap( struct im_connection *ic, char *format, ... )
[b7d3cc34]192{
193        va_list params;
[e27661d]194        char *text;
[dfde8e0]195        account_t *a;
[b7d3cc34]196       
197        va_start( params, format );
[e27661d]198        text = g_strdup_vprintf( format, params );
[b7d3cc34]199        va_end( params );
200
[0da65d5]201        if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
[6bbb939]202            ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
[e27661d]203                strip_html( text );
[b7d3cc34]204       
[dfde8e0]205        /* Try to find a different connection on the same protocol. */
[0da65d5]206        for( a = ic->irc->accounts; a; a = a->next )
207                if( a->prpl == ic->acc->prpl && a->ic != ic )
[dfde8e0]208                        break;
209       
[e27661d]210        /* If we found one, include the screenname in the message. */
[dfde8e0]211        if( a )
[c2fb3809]212                irc_usermsg( ic->irc, "%s(%s) - %s", ic->acc->prpl->name, ic->acc->user, text );
[dfde8e0]213        else
[0da65d5]214                irc_usermsg( ic->irc, "%s - %s", ic->acc->prpl->name, text );
[7b07dc6]215       
[e27661d]216        g_free( text );
[b7d3cc34]217}
218
[84b045d]219void imcb_log( struct im_connection *ic, char *format, ... )
[aef4828]220{
221        va_list params;
222        char *text;
223       
224        va_start( params, format );
225        text = g_strdup_vprintf( format, params );
226        va_end( params );
227       
228        if( ic->flags & OPT_LOGGED_IN )
229                serv_got_crap( ic, "%s", text );
230        else
231                serv_got_crap( ic, "Logging in: %s", text );
232       
233        g_free( text );
234}
235
[84b045d]236void imcb_error( struct im_connection *ic, char *format, ... )
[aef4828]237{
238        va_list params;
239        char *text;
240       
241        va_start( params, format );
242        text = g_strdup_vprintf( format, params );
243        va_end( params );
244       
245        if( ic->flags & OPT_LOGGED_IN )
246                serv_got_crap( ic, "Error: %s", text );
247        else
248                serv_got_crap( ic, "Couldn't log in: %s", text );
249       
250        g_free( text );
251}
252
[ba9edaa]253static gboolean send_keepalive( gpointer d, gint fd, b_input_condition cond )
[b7d3cc34]254{
[0da65d5]255        struct im_connection *ic = d;
[b7d3cc34]256       
[0da65d5]257        if( ic->acc->prpl->keepalive )
258                ic->acc->prpl->keepalive( ic );
[b7d3cc34]259       
260        return TRUE;
261}
262
[84b045d]263void imcb_connected( struct im_connection *ic )
[b7d3cc34]264{
[3611717]265        irc_t *irc = ic->irc;
266        struct chat *c;
[b7d3cc34]267        user_t *u;
268       
269        /* MSN servers sometimes redirect you to a different server and do
[84c1a0a]270           the whole login sequence again, so these "late" calls to this
[b7d3cc34]271           function should be handled correctly. (IOW, ignored) */
[0da65d5]272        if( ic->flags & OPT_LOGGED_IN )
[b7d3cc34]273                return;
274       
[0da65d5]275        u = user_find( ic->irc, ic->irc->nick );
[b7d3cc34]276       
[84b045d]277        imcb_log( ic, "Logged in" );
[b7d3cc34]278       
[0da65d5]279        ic->keepalive = b_timeout_add( 60000, send_keepalive, ic );
280        ic->flags |= OPT_LOGGED_IN;
[b7d3cc34]281       
[58adb7e]282        /* Necessary to send initial presence status, even if we're not away. */
283        imc_away_send_update( ic );
[280e655]284       
285        /* Apparently we're connected successfully, so reset the
286           exponential backoff timer. */
287        ic->acc->auto_reconnect_delay = 0;
[3611717]288       
289        for( c = irc->chatrooms; c; c = c->next )
290        {
291                if( c->acc != ic->acc )
292                        continue;
293               
294                if( set_getbool( &c->set, "auto_join" ) )
[94acdd0]295                        chat_join( irc, c, NULL );
[3611717]296        }
[b7d3cc34]297}
298
[ba9edaa]299gboolean auto_reconnect( gpointer data, gint fd, b_input_condition cond )
[b7d3cc34]300{
301        account_t *a = data;
302       
303        a->reconnect = 0;
304        account_on( a->irc, a );
305       
306        return( FALSE );        /* Only have to run the timeout once */
307}
308
309void cancel_auto_reconnect( account_t *a )
310{
[c98be00]311        b_event_remove( a->reconnect );
[b7d3cc34]312        a->reconnect = 0;
313}
314
[c2fb3809]315void imc_logout( struct im_connection *ic, int allow_reconnect )
[b7d3cc34]316{
[0da65d5]317        irc_t *irc = ic->irc;
[c9c7ca7]318        user_t *t, *u;
[b7d3cc34]319        account_t *a;
[4230221]320        int delay;
[b7d3cc34]321       
[8d74291]322        /* Nested calls might happen sometimes, this is probably the best
323           place to catch them. */
[0da65d5]324        if( ic->flags & OPT_LOGGING_OUT )
[8d74291]325                return;
[66f783f]326        else
[0da65d5]327                ic->flags |= OPT_LOGGING_OUT;
[8d74291]328       
[84b045d]329        imcb_log( ic, "Signing off.." );
[fb62f81f]330       
[0da65d5]331        b_event_remove( ic->keepalive );
332        ic->keepalive = 0;
333        ic->acc->prpl->logout( ic );
334        b_event_remove( ic->inpa );
[b7d3cc34]335       
[c0c43fb]336        g_free( ic->away );
337        ic->away = NULL;
338       
[c9c7ca7]339        u = irc->users;
[b7d3cc34]340        while( u )
341        {
[0da65d5]342                if( u->ic == ic )
[b7d3cc34]343                {
344                        t = u->next;
345                        user_del( irc, u->nick );
346                        u = t;
347                }
348                else
349                        u = u->next;
350        }
351       
[0da65d5]352        query_del_by_conn( ic->irc, ic );
[b7d3cc34]353       
354        for( a = irc->accounts; a; a = a->next )
[0da65d5]355                if( a->ic == ic )
[b7d3cc34]356                        break;
357       
358        if( !a )
359        {
360                /* Uhm... This is very sick. */
361        }
[c2fb3809]362        else if( allow_reconnect && set_getbool( &irc->set, "auto_reconnect" ) &&
[4230221]363                 set_getbool( &a->set, "auto_reconnect" ) &&
364                 ( delay = account_reconnect_delay( a ) ) > 0 )
[b7d3cc34]365        {
[84b045d]366                imcb_log( ic, "Reconnecting in %d seconds..", delay );
[c98be00]367                a->reconnect = b_timeout_add( delay * 1000, auto_reconnect, a );
[b7d3cc34]368        }
369       
[aef4828]370        imc_free( ic );
[b7d3cc34]371}
372
373
374/* dialogs.c */
375
[9143aeb]376void imcb_ask( struct im_connection *ic, char *msg, void *data,
377               query_callback doit, query_callback dont )
[b7d3cc34]378{
[0da65d5]379        query_add( ic->irc, ic, msg, doit, dont, data );
[b7d3cc34]380}
381
382
383/* list.c */
384
[c6ca3ee]385void imcb_add_buddy( struct im_connection *ic, const char *handle, const char *group )
[b7d3cc34]386{
387        user_t *u;
[f0cb961]388        char nick[MAX_NICK_LENGTH+1], *s;
[0da65d5]389        irc_t *irc = ic->irc;
[b7d3cc34]390       
[0da65d5]391        if( user_findhandle( ic, handle ) )
[b7d3cc34]392        {
[d5ccd83]393                if( set_getbool( &irc->set, "debug" ) )
[84b045d]394                        imcb_log( ic, "User already exists, ignoring add request: %s", handle );
[b7d3cc34]395               
396                return;
397               
[f0cb961]398                /* Buddy seems to exist already. Let's ignore this request then...
399                   Eventually subsequent calls to this function *should* be possible
400                   when a buddy is in multiple groups. But for now BitlBee doesn't
401                   even support groups so let's silently ignore this for now. */
[b7d3cc34]402        }
403       
404        memset( nick, 0, MAX_NICK_LENGTH + 1 );
[d323394c]405        strcpy( nick, nick_get( ic->acc, handle ) );
[b7d3cc34]406       
[0da65d5]407        u = user_add( ic->irc, nick );
[b7d3cc34]408       
[f0cb961]409//      if( !realname || !*realname ) realname = nick;
410//      u->realname = g_strdup( realname );
[b7d3cc34]411       
412        if( ( s = strchr( handle, '@' ) ) )
413        {
414                u->host = g_strdup( s + 1 );
415                u->user = g_strndup( handle, s - handle );
416        }
[0da65d5]417        else if( ic->acc->server )
[b7d3cc34]418        {
[f0cb961]419                u->host = g_strdup( ic->acc->server );
[b7d3cc34]420                u->user = g_strdup( handle );
421               
422                /* s/ /_/ ... important for AOL screennames */
423                for( s = u->user; *s; s ++ )
424                        if( *s == ' ' )
425                                *s = '_';
426        }
427        else
428        {
[0da65d5]429                u->host = g_strdup( ic->acc->prpl->name );
[b7d3cc34]430                u->user = g_strdup( handle );
431        }
432       
[0da65d5]433        u->ic = ic;
[b7d3cc34]434        u->handle = g_strdup( handle );
[9b8a38b]435        if( group ) u->group = g_strdup( group );
[b7d3cc34]436        u->send_handler = buddy_send_handler;
437        u->last_typing_notice = 0;
438}
439
[f0cb961]440struct buddy *imcb_find_buddy( struct im_connection *ic, char *handle )
[b7d3cc34]441{
442        static struct buddy b[1];
443        user_t *u;
444       
[0da65d5]445        u = user_findhandle( ic, handle );
[b7d3cc34]446       
447        if( !u )
448                return( NULL );
[9624fdf]449       
[b7d3cc34]450        memset( b, 0, sizeof( b ) );
451        strncpy( b->name, handle, 80 );
452        strncpy( b->show, u->realname, BUDDY_ALIAS_MAXLEN );
453        b->present = u->online;
[0da65d5]454        b->ic = u->ic;
[b7d3cc34]455       
456        return( b );
457}
458
[c6ca3ee]459void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char *realname )
[b7d3cc34]460{
[0da65d5]461        user_t *u = user_findhandle( ic, handle );
[286b28e]462        char *set;
[b7d3cc34]463       
[f0cb961]464        if( !u || !realname ) return;
[b7d3cc34]465       
[e27661d]466        if( g_strcasecmp( u->realname, realname ) != 0 )
[b7d3cc34]467        {
468                if( u->realname != u->nick ) g_free( u->realname );
469               
[e27661d]470                u->realname = g_strdup( realname );
[b7d3cc34]471               
[0da65d5]472                if( ( ic->flags & OPT_LOGGED_IN ) && set_getbool( &ic->irc->set, "display_namechanges" ) )
[84b045d]473                        imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname );
[b7d3cc34]474        }
[286b28e]475       
476        set = set_getstr( &ic->acc->set, "nick_source" );
477        if( strcmp( set, "handle" ) != 0 )
478        {
479                char *name = g_strdup( realname );
480               
481                if( strcmp( set, "first_name" ) == 0 )
482                {
483                        int i;
484                        for( i = 0; name[i] && !isspace( name[i] ); i ++ ) {}
485                        name[i] = '\0';
486                }
487               
488                imcb_buddy_nick_hint( ic, handle, name );
489               
490                g_free( name );
491        }
[b7d3cc34]492}
493
[c6ca3ee]494void imcb_remove_buddy( struct im_connection *ic, const char *handle, char *group )
[998b103]495{
496        user_t *u;
497       
498        if( ( u = user_findhandle( ic, handle ) ) )
499                user_del( ic->irc, u->nick );
500}
501
[d06eabf]502/* Mainly meant for ICQ (and now also for Jabber conferences) to allow IM
503   modules to suggest a nickname for a handle. */
[fb00989]504void imcb_buddy_nick_hint( struct im_connection *ic, const char *handle, const char *nick )
[d06eabf]505{
506        user_t *u = user_findhandle( ic, handle );
[43d8cc5]507        char newnick[MAX_NICK_LENGTH+1], *orig_nick;
[d06eabf]508       
[e0e2a71]509        if( u && !u->online && !nick_saved( ic->acc, handle ) )
[d06eabf]510        {
511                /* Only do this if the person isn't online yet (which should
512                   be the case if we just added it) and if the user hasn't
513                   assigned a nickname to this buddy already. */
514               
[e0e2a71]515                strncpy( newnick, nick, MAX_NICK_LENGTH );
516                newnick[MAX_NICK_LENGTH] = 0;
[d06eabf]517               
518                /* Some processing to make sure this string is a valid IRC nickname. */
519                nick_strip( newnick );
520                if( set_getbool( &ic->irc->set, "lcnicks" ) )
521                        nick_lc( newnick );
522               
[1962ac1]523                if( strcmp( u->nick, newnick ) != 0 )
524                {
525                        /* Only do this if newnick is different from the current one.
526                           If rejoining a channel, maybe we got this nick already
527                           (and dedupe would only add an underscore. */
528                        nick_dedupe( ic->acc, handle, newnick );
529                       
530                        /* u->nick will be freed halfway the process, so it can't be
531                           passed as an argument. */
532                        orig_nick = g_strdup( u->nick );
533                        user_rename( ic->irc, orig_nick, newnick );
534                        g_free( orig_nick );
535                }
[d06eabf]536        }
537}
[b7d3cc34]538
539
[fa295e36]540struct imcb_ask_cb_data
[7bf0f5f0]541{
[0da65d5]542        struct im_connection *ic;
[7bf0f5f0]543        char *handle;
544};
545
[fa295e36]546static void imcb_ask_auth_cb_no( void *data )
[7bf0f5f0]547{
[fa295e36]548        struct imcb_ask_cb_data *cbd = data;
549       
550        cbd->ic->acc->prpl->auth_deny( cbd->ic, cbd->handle );
551       
552        g_free( cbd->handle );
553        g_free( cbd );
554}
555
556static void imcb_ask_auth_cb_yes( void *data )
557{
558        struct imcb_ask_cb_data *cbd = data;
559       
560        cbd->ic->acc->prpl->auth_allow( cbd->ic, cbd->handle );
561       
562        g_free( cbd->handle );
563        g_free( cbd );
564}
565
566void imcb_ask_auth( struct im_connection *ic, const char *handle, const char *realname )
567{
568        struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 );
569        char *s, *realname_ = NULL;
570       
571        if( realname != NULL )
572                realname_ = g_strdup_printf( " (%s)", realname );
573       
574        s = g_strdup_printf( "The user %s%s wants to add you to his/her buddy list.",
575                             handle, realname_ ?: "" );
576       
577        g_free( realname_ );
578       
579        data->ic = ic;
580        data->handle = g_strdup( handle );
581        query_add( ic->irc, ic, s, imcb_ask_auth_cb_yes, imcb_ask_auth_cb_no, data );
582}
583
584
585static void imcb_ask_add_cb_no( void *data )
586{
587        g_free( ((struct imcb_ask_cb_data*)data)->handle );
[7bf0f5f0]588        g_free( data );
589}
590
[fa295e36]591static void imcb_ask_add_cb_yes( void *data )
[7bf0f5f0]592{
[fa295e36]593        struct imcb_ask_cb_data *cbd = data;
[7bf0f5f0]594       
[fa295e36]595        cbd->ic->acc->prpl->add_buddy( cbd->ic, cbd->handle, NULL );
[9143aeb]596       
[fa295e36]597        return imcb_ask_add_cb_no( data );
[7bf0f5f0]598}
599
[fa295e36]600void imcb_ask_add( struct im_connection *ic, const char *handle, const char *realname )
[b7d3cc34]601{
[fa295e36]602        struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 );
[7bf0f5f0]603        char *s;
604       
605        /* TODO: Make a setting for this! */
[0da65d5]606        if( user_findhandle( ic, handle ) != NULL )
[7bf0f5f0]607                return;
608       
609        s = g_strdup_printf( "The user %s is not in your buddy list yet. Do you want to add him/her now?", handle );
610       
[0da65d5]611        data->ic = ic;
[7bf0f5f0]612        data->handle = g_strdup( handle );
[fa295e36]613        query_add( ic->irc, ic, s, imcb_ask_add_cb_yes, imcb_ask_add_cb_no, data );
[b7d3cc34]614}
615
616
617/* server.c */                   
618
[6bbb939]619void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message )
[b7d3cc34]620{
621        user_t *u;
622        int oa, oo;
623       
[6bbb939]624        u = user_findhandle( ic, (char*) handle );
[b7d3cc34]625       
626        if( !u )
627        {
[0da65d5]628                if( g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "add" ) == 0 )
[b7d3cc34]629                {
[f0cb961]630                        imcb_add_buddy( ic, (char*) handle, NULL );
[6bbb939]631                        u = user_findhandle( ic, (char*) handle );
[b7d3cc34]632                }
633                else
634                {
[0da65d5]635                        if( set_getbool( &ic->irc->set, "debug" ) || g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "ignore" ) != 0 )
[b7d3cc34]636                        {
[6bbb939]637                                imcb_log( ic, "imcb_buddy_status() for unknown handle %s:", handle );
638                                imcb_log( ic, "flags = %d, state = %s, message = %s", flags,
639                                          state ? state : "NULL", message ? message : "NULL" );
[b7d3cc34]640                        }
641                       
642                        return;
643                }
644        }
645       
646        oa = u->away != NULL;
647        oo = u->online;
648       
[449a51d]649        g_free( u->away );
650        g_free( u->status_msg );
651        u->away = u->status_msg = NULL;
[b7d3cc34]652       
[6bbb939]653        if( ( flags & OPT_LOGGED_IN ) && !u->online )
[b7d3cc34]654        {
[0da65d5]655                irc_spawn( ic->irc, u );
[b7d3cc34]656                u->online = 1;
657        }
[6bbb939]658        else if( !( flags & OPT_LOGGED_IN ) && u->online )
[b7d3cc34]659        {
[0da65d5]660                struct groupchat *c;
[b7d3cc34]661               
[0da65d5]662                irc_kill( ic->irc, u );
[b7d3cc34]663                u->online = 0;
664               
[e35d1a1]665                /* Remove him/her from the groupchats to prevent PART messages after he/she QUIT already */
666                for( c = ic->groupchats; c; c = c->next )
[764b163d]667                        remove_chat_buddy_silent( c, handle );
[b7d3cc34]668        }
669       
[6bbb939]670        if( flags & OPT_AWAY )
[b7d3cc34]671        {
[6bbb939]672                if( state && message )
673                {
674                        u->away = g_strdup_printf( "%s (%s)", state, message );
675                }
676                else if( state )
677                {
678                        u->away = g_strdup( state );
679                }
680                else if( message )
681                {
682                        u->away = g_strdup( message );
683                }
684                else
685                {
686                        u->away = g_strdup( "Away" );
687                }
[b7d3cc34]688        }
[449a51d]689        else
690        {
691                u->status_msg = g_strdup( message );
692        }
[b7d3cc34]693       
694        /* LISPy... */
[0da65d5]695        if( ( set_getbool( &ic->irc->set, "away_devoice" ) ) &&         /* Don't do a thing when user doesn't want it */
[b7d3cc34]696            ( u->online ) &&                                            /* Don't touch offline people */
697            ( ( ( u->online != oo ) && !u->away ) ||                    /* Voice joining people */
698              ( ( u->online == oo ) && ( oa == !u->away ) ) ) )         /* (De)voice people changing state */
699        {
[1186382]700                char *from;
701               
702                if( set_getbool( &ic->irc->set, "simulate_netsplit" ) )
703                {
704                        from = g_strdup( ic->irc->myhost );
705                }
706                else
707                {
708                        from = g_strdup_printf( "%s!%s@%s", ic->irc->mynick, ic->irc->mynick,
709                                                            ic->irc->myhost );
710                }
711                irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel,
712                                                          u->away?'-':'+', u->nick );
713                g_free( from );
[b7d3cc34]714        }
715}
716
[c6ca3ee]717void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, uint32_t flags, time_t sent_at )
[b7d3cc34]718{
[0da65d5]719        irc_t *irc = ic->irc;
[d444c09]720        char *wrapped;
[b7d3cc34]721        user_t *u;
722       
[0da65d5]723        u = user_findhandle( ic, handle );
[b7d3cc34]724       
725        if( !u )
726        {
[5c9512f]727                char *h = set_getstr( &irc->set, "handle_unknown" );
[b7d3cc34]728               
729                if( g_strcasecmp( h, "ignore" ) == 0 )
730                {
[d5ccd83]731                        if( set_getbool( &irc->set, "debug" ) )
[84b045d]732                                imcb_log( ic, "Ignoring message from unknown handle %s", handle );
[b7d3cc34]733                       
734                        return;
735                }
736                else if( g_strncasecmp( h, "add", 3 ) == 0 )
737                {
[d5ccd83]738                        int private = set_getbool( &irc->set, "private" );
[b7d3cc34]739                       
740                        if( h[3] )
741                        {
742                                if( g_strcasecmp( h + 3, "_private" ) == 0 )
743                                        private = 1;
744                                else if( g_strcasecmp( h + 3, "_channel" ) == 0 )
745                                        private = 0;
746                        }
747                       
[f0cb961]748                        imcb_add_buddy( ic, handle, NULL );
[0da65d5]749                        u = user_findhandle( ic, handle );
[b7d3cc34]750                        u->is_private = private;
751                }
752                else
753                {
[84b045d]754                        imcb_log( ic, "Message from unknown handle %s:", handle );
[b7d3cc34]755                        u = user_find( irc, irc->mynick );
756                }
757        }
758       
[0da65d5]759        if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
[6bbb939]760            ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
[b7d3cc34]761                strip_html( msg );
762
[d444c09]763        wrapped = word_wrap( msg, 425 );
764        irc_msgfrom( irc, u->nick, wrapped );
765        g_free( wrapped );
[b7d3cc34]766}
767
[52744f8]768void imcb_buddy_typing( struct im_connection *ic, char *handle, uint32_t flags )
[b7d3cc34]769{
770        user_t *u;
771       
[0da65d5]772        if( !set_getbool( &ic->irc->set, "typing_notice" ) )
[b7d3cc34]773                return;
774       
[9624fdf]775        if( ( u = user_findhandle( ic, handle ) ) )
776        {
777                char buf[256]; 
778               
779                g_snprintf( buf, 256, "\1TYPING %d\1", ( flags >> 8 ) & 3 );
780                irc_privmsg( ic->irc, u, "PRIVMSG", ic->irc->nick, NULL, buf );
[e7f46c5]781        }
[b7d3cc34]782}
783
[94acdd0]784struct groupchat *imcb_chat_new( struct im_connection *ic, const char *handle )
[83ba3e5]785{
786        struct groupchat *c;
787       
788        /* This one just creates the conversation structure, user won't see anything yet */
789       
790        if( ic->groupchats )
791        {
792                for( c = ic->groupchats; c->next; c = c->next );
793                c = c->next = g_new0( struct groupchat, 1 );
794        }
795        else
796                ic->groupchats = c = g_new0( struct groupchat, 1 );
797       
798        c->ic = ic;
799        c->title = g_strdup( handle );
800        c->channel = g_strdup_printf( "&chat_%03d", ic->irc->c_id++ );
801        c->topic = g_strdup_printf( "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", c->title );
802       
803        if( set_getbool( &ic->irc->set, "debug" ) )
804                imcb_log( ic, "Creating new conversation: (id=%p,handle=%s)", c, handle );
805       
806        return c;
807}
808
[e35d1a1]809void imcb_chat_free( struct groupchat *c )
[b7d3cc34]810{
[0da65d5]811        struct im_connection *ic = c->ic;
[e35d1a1]812        struct groupchat *l;
[b7d3cc34]813        GList *ir;
814       
[0da65d5]815        if( set_getbool( &ic->irc->set, "debug" ) )
[56f260a]816                imcb_log( ic, "You were removed from conversation %p", c );
[b7d3cc34]817       
818        if( c )
819        {
820                if( c->joined )
821                {
822                        user_t *u, *r;
823                       
[0da65d5]824                        r = user_find( ic->irc, ic->irc->mynick );
825                        irc_privmsg( ic->irc, r, "PRIVMSG", c->channel, "", "Cleaning up channel, bye!" );
[b7d3cc34]826                       
[0da65d5]827                        u = user_find( ic->irc, ic->irc->nick );
828                        irc_kick( ic->irc, u, c->channel, r );
829                        /* irc_part( ic->irc, u, c->channel ); */
[b7d3cc34]830                }
831               
[e35d1a1]832                /* Find the previous chat in the linked list. */
833                for( l = ic->groupchats; l && l->next != c; l = l->next );
834               
[b7d3cc34]835                if( l )
836                        l->next = c->next;
837                else
[e35d1a1]838                        ic->groupchats = c->next;
[b7d3cc34]839               
840                for( ir = c->in_room; ir; ir = ir->next )
841                        g_free( ir->data );
842                g_list_free( c->in_room );
843                g_free( c->channel );
844                g_free( c->title );
[83ba3e5]845                g_free( c->topic );
[b7d3cc34]846                g_free( c );
847        }
848}
849
[c6ca3ee]850void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t flags, time_t sent_at )
[b7d3cc34]851{
[0da65d5]852        struct im_connection *ic = c->ic;
[d444c09]853        char *wrapped;
[b7d3cc34]854        user_t *u;
855       
856        /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */
[c2fb3809]857        if( g_strcasecmp( who, ic->acc->user ) == 0 )
[b7d3cc34]858                return;
859       
[0da65d5]860        u = user_findhandle( ic, who );
[b7d3cc34]861       
[0da65d5]862        if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
[6bbb939]863            ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
[b7d3cc34]864                strip_html( msg );
865       
[d444c09]866        wrapped = word_wrap( msg, 425 );
[b7d3cc34]867        if( c && u )
[d444c09]868        {
869                irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, "", wrapped );
870        }
[b7d3cc34]871        else
[d444c09]872        {
[56f260a]873                imcb_log( ic, "Message from/to conversation %s@%p (unknown conv/user): %s", who, c, wrapped );
[d444c09]874        }
875        g_free( wrapped );
[b7d3cc34]876}
877
[31e5846]878void imcb_chat_log( struct groupchat *c, char *format, ... )
879{
880        irc_t *irc = c->ic->irc;
881        va_list params;
882        char *text;
883        user_t *u;
884       
885        va_start( params, format );
886        text = g_strdup_vprintf( format, params );
887        va_end( params );
888       
889        u = user_find( irc, irc->mynick );
890       
891        irc_privmsg( irc, u, "PRIVMSG", c->channel, "System message: ", text );
892       
893        g_free( text );
894}
895
[ef5c185]896void imcb_chat_topic( struct groupchat *c, char *who, char *topic, time_t set_at )
[50e1776]897{
898        struct im_connection *ic = c->ic;
899        user_t *u = NULL;
900       
901        if( who == NULL)
[ef5c185]902                u = user_find( ic->irc, ic->irc->mynick );
[50e1776]903        else if( g_strcasecmp( who, ic->acc->user ) == 0 )
[ef5c185]904                u = user_find( ic->irc, ic->irc->nick );
[50e1776]905        else
906                u = user_findhandle( ic, who );
907       
908        if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
909            ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
910                strip_html( topic );
911       
912        g_free( c->topic );
913        c->topic = g_strdup( topic );
914       
915        if( c->joined && u )
916                irc_write( ic->irc, ":%s!%s@%s TOPIC %s :%s", u->nick, u->user, u->host, c->channel, topic );
917}
918
[b7d3cc34]919
920/* buddy_chat.c */
921
[c6ca3ee]922void imcb_chat_add_buddy( struct groupchat *b, const char *handle )
[b7d3cc34]923{
[0da65d5]924        user_t *u = user_findhandle( b->ic, handle );
[b7d3cc34]925        int me = 0;
926       
[0da65d5]927        if( set_getbool( &b->ic->irc->set, "debug" ) )
[56f260a]928                imcb_log( b->ic, "User %s added to conversation %p", handle, b );
[b7d3cc34]929       
930        /* It might be yourself! */
[c2fb3809]931        if( b->ic->acc->prpl->handle_cmp( handle, b->ic->acc->user ) == 0 )
[b7d3cc34]932        {
[0da65d5]933                u = user_find( b->ic->irc, b->ic->irc->nick );
[b7d3cc34]934                if( !b->joined )
[0da65d5]935                        irc_join( b->ic->irc, u, b->channel );
[b7d3cc34]936                b->joined = me = 1;
937        }
938       
939        /* Most protocols allow people to join, even when they're not in
940           your contact list. Try to handle that here */
941        if( !u )
942        {
[f0cb961]943                imcb_add_buddy( b->ic, handle, NULL );
[0da65d5]944                u = user_findhandle( b->ic, handle );
[b7d3cc34]945        }
946       
947        /* Add the handle to the room userlist, if it's not 'me' */
948        if( !me )
949        {
950                if( b->joined )
[0da65d5]951                        irc_join( b->ic->irc, u, b->channel );
[b7d3cc34]952                b->in_room = g_list_append( b->in_room, g_strdup( handle ) );
953        }
954}
955
[2d317bb]956/* This function is one BIG hack... :-( EREWRITE */
[c6ca3ee]957void imcb_chat_remove_buddy( struct groupchat *b, const char *handle, const char *reason )
[b7d3cc34]958{
959        user_t *u;
960        int me = 0;
961       
[0da65d5]962        if( set_getbool( &b->ic->irc->set, "debug" ) )
[56f260a]963                imcb_log( b->ic, "User %s removed from conversation %p (%s)", handle, b, reason ? reason : "" );
[b7d3cc34]964       
965        /* It might be yourself! */
[c2fb3809]966        if( g_strcasecmp( handle, b->ic->acc->user ) == 0 )
[b7d3cc34]967        {
[2d317bb]968                if( b->joined == 0 )
969                        return;
970               
[0da65d5]971                u = user_find( b->ic->irc, b->ic->irc->nick );
[b7d3cc34]972                b->joined = 0;
973                me = 1;
974        }
975        else
976        {
[0da65d5]977                u = user_findhandle( b->ic, handle );
[b7d3cc34]978        }
979       
[2d317bb]980        if( me || ( remove_chat_buddy_silent( b, handle ) && b->joined && u ) )
981                irc_part( b->ic->irc, u, b->channel );
[b7d3cc34]982}
983
[764b163d]984static int remove_chat_buddy_silent( struct groupchat *b, const char *handle )
[b7d3cc34]985{
986        GList *i;
987       
988        /* Find the handle in the room userlist and shoot it */
989        i = b->in_room;
990        while( i )
991        {
992                if( g_strcasecmp( handle, i->data ) == 0 )
993                {
994                        g_free( i->data );
995                        b->in_room = g_list_remove( b->in_room, i->data );
996                        return( 1 );
997                }
998               
999                i = i->next;
1000        }
1001       
1002        return( 0 );
1003}
1004
1005
1006/* Misc. BitlBee stuff which shouldn't really be here */
1007
[5c9512f]1008char *set_eval_away_devoice( set_t *set, char *value )
[b7d3cc34]1009{
[5c9512f]1010        irc_t *irc = set->data;
[b7d3cc34]1011        int st;
1012       
[7125cb3]1013        if( !is_bool( value ) )
1014                return SET_INVALID;
[b7d3cc34]1015       
[7125cb3]1016        st = bool2int( value );
[b7d3cc34]1017       
1018        /* Horror.... */
1019       
[d5ccd83]1020        if( st != set_getbool( &irc->set, "away_devoice" ) )
[b7d3cc34]1021        {
1022                char list[80] = "";
1023                user_t *u = irc->users;
1024                int i = 0, count = 0;
1025                char pm;
1026                char v[80];
1027               
1028                if( st )
1029                        pm = '+';
1030                else
1031                        pm = '-';
1032               
1033                while( u )
1034                {
[0da65d5]1035                        if( u->ic && u->online && !u->away )
[b7d3cc34]1036                        {
1037                                if( ( strlen( list ) + strlen( u->nick ) ) >= 79 )
1038                                {
1039                                        for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0;
[2087159]1040                                        irc_write( irc, ":%s MODE %s %c%s%s",
1041                                                   irc->myhost,
[b7d3cc34]1042                                                   irc->channel, pm, v, list );
1043                                       
1044                                        *list = 0;
1045                                        count = 0;
1046                                }
1047                               
1048                                sprintf( list + strlen( list ), " %s", u->nick );
1049                                count ++;
1050                        }
1051                        u = u->next;
1052                }
1053               
1054                /* $v = 'v' x $i */
1055                for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0;
[2087159]1056                irc_write( irc, ":%s MODE %s %c%s%s", irc->myhost,
[b7d3cc34]1057                                                            irc->channel, pm, v, list );
1058        }
1059       
[7125cb3]1060        return value;
[b7d3cc34]1061}
1062
[226fce1]1063
1064
1065
1066/* The plan is to not allow straight calls to prpl functions anymore, but do
1067   them all from some wrappers. We'll start to define some down here: */
1068
[84b045d]1069int imc_buddy_msg( struct im_connection *ic, char *handle, char *msg, int flags )
[b7d3cc34]1070{
[e27661d]1071        char *buf = NULL;
1072        int st;
[b7d3cc34]1073       
[6bbb939]1074        if( ( ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) )
[c572dd6]1075        {
[e27661d]1076                buf = escape_html( msg );
[c572dd6]1077                msg = buf;
[b7d3cc34]1078        }
1079       
[f6c963b]1080        st = ic->acc->prpl->buddy_msg( ic, handle, msg, flags );
[e27661d]1081        g_free( buf );
1082       
1083        return st;
[b7d3cc34]1084}
1085
[84b045d]1086int imc_chat_msg( struct groupchat *c, char *msg, int flags )
[b7d3cc34]1087{
[e27661d]1088        char *buf = NULL;
[b7d3cc34]1089       
[6bbb939]1090        if( ( c->ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) )
[e27661d]1091        {
1092                buf = escape_html( msg );
[b7d3cc34]1093                msg = buf;
1094        }
1095       
[f6c963b]1096        c->ic->acc->prpl->chat_msg( c, msg, flags );
[e27661d]1097        g_free( buf );
1098       
[0da65d5]1099        return 1;
[b7d3cc34]1100}
[226fce1]1101
[34fbbf9]1102static char *imc_away_state_find( GList *gcm, char *away, char **message );
[226fce1]1103
[58adb7e]1104int imc_away_send_update( struct im_connection *ic )
[226fce1]1105{
[3e1ef92c]1106        char *away, *msg = NULL;
[226fce1]1107       
[58adb7e]1108        away = set_getstr( &ic->acc->set, "away" ) ?
1109             : set_getstr( &ic->irc->set, "away" );
[34fbbf9]1110        if( away && *away )
[226fce1]1111        {
[34fbbf9]1112                GList *m = ic->acc->prpl->away_states( ic );
[58adb7e]1113                msg = ic->acc->flags & ACC_FLAG_AWAY_MESSAGE ? away : NULL;
1114                away = imc_away_state_find( m, away, &msg ) ? : m->data;
1115        }
1116        else if( ic->acc->flags & ACC_FLAG_STATUS_MESSAGE )
1117        {
1118                away = NULL;
1119                msg = set_getstr( &ic->acc->set, "status" ) ?
1120                    : set_getstr( &ic->irc->set, "status" );
[226fce1]1121        }
1122       
[58adb7e]1123        ic->acc->prpl->set_away( ic, away, msg );
[226fce1]1124       
[34fbbf9]1125        return 1;
[226fce1]1126}
1127
[84b045d]1128static char *imc_away_alias_list[8][5] =
[226fce1]1129{
1130        { "Away from computer", "Away", "Extended away", NULL },
1131        { "NA", "N/A", "Not available", NULL },
1132        { "Busy", "Do not disturb", "DND", "Occupied", NULL },
1133        { "Be right back", "BRB", NULL },
1134        { "On the phone", "Phone", "On phone", NULL },
1135        { "Out to lunch", "Lunch", "Food", NULL },
1136        { "Invisible", "Hidden" },
1137        { NULL }
1138};
1139
[34fbbf9]1140static char *imc_away_state_find( GList *gcm, char *away, char **message )
[226fce1]1141{
1142        GList *m;
1143        int i, j;
1144       
[34fbbf9]1145        for( m = gcm; m; m = m->next )
1146                if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 )
1147                {
1148                        /* At least the Yahoo! module works better if message
1149                           contains no data unless it adds something to what
1150                           we have in state already. */
1151                        if( strlen( m->data ) == strlen( away ) )
1152                                *message = NULL;
1153                       
1154                        return m->data;
1155                }
1156       
[84b045d]1157        for( i = 0; *imc_away_alias_list[i]; i ++ )
[226fce1]1158        {
[34fbbf9]1159                int keep_message;
1160               
[84b045d]1161                for( j = 0; imc_away_alias_list[i][j]; j ++ )
1162                        if( g_strncasecmp( away, imc_away_alias_list[i][j], strlen( imc_away_alias_list[i][j] ) ) == 0 )
[34fbbf9]1163                        {
1164                                keep_message = strlen( away ) != strlen( imc_away_alias_list[i][j] );
[226fce1]1165                                break;
[34fbbf9]1166                        }
[226fce1]1167               
[84b045d]1168                if( !imc_away_alias_list[i][j] )        /* If we reach the end, this row */
[226fce1]1169                        continue;                       /* is not what we want. Next!    */
1170               
1171                /* Now find an entry in this row which exists in gcm */
[84b045d]1172                for( j = 0; imc_away_alias_list[i][j]; j ++ )
[226fce1]1173                {
[34fbbf9]1174                        for( m = gcm; m; m = m->next )
[84b045d]1175                                if( g_strcasecmp( imc_away_alias_list[i][j], m->data ) == 0 )
[34fbbf9]1176                                {
1177                                        if( !keep_message )
1178                                                *message = NULL;
1179                                       
1180                                        return imc_away_alias_list[i][j];
1181                                }
[226fce1]1182                }
[34fbbf9]1183               
1184                /* No need to look further, apparently this state doesn't
1185                   have any good alias for this protocol. */
1186                break;
[226fce1]1187        }
1188       
[34fbbf9]1189        return NULL;
[226fce1]1190}
[da3b536]1191
[84b045d]1192void imc_add_allow( struct im_connection *ic, char *handle )
[da3b536]1193{
[0da65d5]1194        if( g_slist_find_custom( ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) == NULL )
[da3b536]1195        {
[0da65d5]1196                ic->permit = g_slist_prepend( ic->permit, g_strdup( handle ) );
[da3b536]1197        }
1198       
[0da65d5]1199        ic->acc->prpl->add_permit( ic, handle );
[da3b536]1200}
1201
[84b045d]1202void imc_rem_allow( struct im_connection *ic, char *handle )
[da3b536]1203{
1204        GSList *l;
1205       
[0da65d5]1206        if( ( l = g_slist_find_custom( ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) ) )
[da3b536]1207        {
1208                g_free( l->data );
[0da65d5]1209                ic->permit = g_slist_delete_link( ic->permit, l );
[da3b536]1210        }
1211       
[0da65d5]1212        ic->acc->prpl->rem_permit( ic, handle );
[da3b536]1213}
1214
[84b045d]1215void imc_add_block( struct im_connection *ic, char *handle )
[da3b536]1216{
[0da65d5]1217        if( g_slist_find_custom( ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) == NULL )
[da3b536]1218        {
[0da65d5]1219                ic->deny = g_slist_prepend( ic->deny, g_strdup( handle ) );
[da3b536]1220        }
1221       
[0da65d5]1222        ic->acc->prpl->add_deny( ic, handle );
[da3b536]1223}
1224
[84b045d]1225void imc_rem_block( struct im_connection *ic, char *handle )
[da3b536]1226{
1227        GSList *l;
1228       
[0da65d5]1229        if( ( l = g_slist_find_custom( ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) ) )
[da3b536]1230        {
1231                g_free( l->data );
[0da65d5]1232                ic->deny = g_slist_delete_link( ic->deny, l );
[da3b536]1233        }
1234       
[0da65d5]1235        ic->acc->prpl->rem_deny( ic, handle );
[da3b536]1236}
[85023c6]1237
1238void imcb_clean_handle( struct im_connection *ic, char *handle )
1239{
1240        /* Accepts a handle and does whatever is necessary to make it
1241           BitlBee-friendly. Currently this means removing everything
1242           outside 33-127 (ASCII printable excl spaces), @ (only one
1243           is allowed) and ! and : */
1244        char out[strlen(handle)+1];
1245        int s, d;
1246       
1247        s = d = 0;
1248        while( handle[s] )
1249        {
1250                if( handle[s] > ' ' && handle[s] != '!' && handle[s] != ':' &&
1251                    ( handle[s] & 0x80 ) == 0 )
1252                {
1253                        if( handle[s] == '@' )
1254                        {
1255                                /* See if we got an @ already? */
1256                                out[d] = 0;
1257                                if( strchr( out, '@' ) )
1258                                        continue;
1259                        }
1260                       
1261                        out[d++] = handle[s];
1262                }
1263                s ++;
1264        }
1265        out[d] = handle[s];
1266       
1267        strcpy( handle, out );
1268}
Note: See TracBrowser for help on using the repository browser.