source: protocols/nogaim.c @ 81e04e1

Last change on this file since 81e04e1 was 81e04e1, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-04-01T02:32:25Z

nogaim.c is close to doing something useful again without speaking any IRC
itself.

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