Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/nogaim.c

    r573dab0 rcca0692  
    3838#include "chat.h"
    3939
     40static int remove_chat_buddy_silent( struct groupchat *b, const char *handle );
     41static char *format_timestamp( irc_t *irc, time_t msg_ts );
     42
    4043GSList *connections;
    4144
     
    8992}
    9093#endif
     94
     95/* nogaim.c */
    9196
    9297GList *protocols = NULL;
     
    121126}
    122127
     128/* nogaim.c */
    123129void nogaim_init()
    124130{
     
    127133        extern void byahoo_initmodule();
    128134        extern void jabber_initmodule();
     135        extern void twitter_initmodule();
    129136
    130137#ifdef WITH_MSN
     
    144151#endif
    145152
     153#ifdef WITH_TWITTER
     154        twitter_initmodule();
     155#endif
     156
    146157#ifdef WITH_PLUGINS
    147158        load_plugins();
     
    151162GSList *get_connections() { return connections; }
    152163
     164/* multi.c */
     165
    153166struct im_connection *imcb_new( account_t *acc )
    154167{
     
    157170        ic = g_new0( struct im_connection, 1 );
    158171       
    159         ic->bee = acc->bee;
     172        ic->irc = acc->irc;
    160173        ic->acc = acc;
    161174        acc->ic = ic;
     
    171184       
    172185        /* Destroy the pointer to this connection from the account list */
    173         for( a = ic->bee->accounts; a; a = a->next )
     186        for( a = ic->irc->accounts; a; a = a->next )
    174187                if( a->ic == ic )
    175188                {
     
    192205        va_end( params );
    193206
    194         if( ( g_strcasecmp( set_getstr( &ic->bee->set, "strip_html" ), "always" ) == 0 ) ||
    195             ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->bee->set, "strip_html" ) ) )
     207        if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
     208            ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
    196209                strip_html( text );
    197210       
    198211        /* Try to find a different connection on the same protocol. */
    199         for( a = ic->bee->accounts; a; a = a->next )
     212        for( a = ic->irc->accounts; a; a = a->next )
    200213                if( a->prpl == ic->acc->prpl && a->ic != ic )
    201214                        break;
     
    203216        /* If we found one, include the screenname in the message. */
    204217        if( a )
    205                 /* FIXME(wilmer): ui_log callback or so */
    206                 irc_usermsg( ic->bee->ui_data, "%s(%s) - %s", ic->acc->prpl->name, ic->acc->user, text );
     218                irc_usermsg( ic->irc, "%s(%s) - %s", ic->acc->prpl->name, ic->acc->user, text );
    207219        else
    208                 irc_usermsg( ic->bee->ui_data, "%s - %s", ic->acc->prpl->name, text );
     220                irc_usermsg( ic->irc, "%s - %s", ic->acc->prpl->name, text );
    209221       
    210222        g_free( text );
     
    257269void imcb_connected( struct im_connection *ic )
    258270{
     271        irc_t *irc = ic->irc;
     272        struct chat *c;
     273        user_t *u;
     274       
    259275        /* MSN servers sometimes redirect you to a different server and do
    260276           the whole login sequence again, so these "late" calls to this
     
    263279                return;
    264280       
     281        u = user_find( ic->irc, ic->irc->nick );
     282       
    265283        imcb_log( ic, "Logged in" );
    266284       
     
    275293        ic->acc->auto_reconnect_delay = 0;
    276294       
    277         /*
    278295        for( c = irc->chatrooms; c; c = c->next )
    279296        {
     
    284301                        chat_join( irc, c, NULL );
    285302        }
    286         */
    287303}
    288304
     
    292308       
    293309        a->reconnect = 0;
    294         account_on( a->bee, a );
     310        account_on( a->irc, a );
    295311       
    296312        return( FALSE );        /* Only have to run the timeout once */
     
    305321void imc_logout( struct im_connection *ic, int allow_reconnect )
    306322{
    307         bee_t *bee = ic->bee;
     323        irc_t *irc = ic->irc;
     324        user_t *t, *u;
    308325        account_t *a;
    309         GSList *l;
    310326        int delay;
    311327       
     
    327343        ic->away = NULL;
    328344       
    329         for( l = bee->users; l; )
    330         {
    331                 bee_user_t *bu = l->data;
    332                 GSList *next = l->next;
    333                
    334                 if( bu->ic == ic )
    335                         bee_user_free( bee, bu );
    336                
    337                 l = next;
    338         }
    339        
    340         //query_del_by_conn( ic->irc, ic );
    341        
    342         for( a = bee->accounts; a; a = a->next )
     345        u = irc->users;
     346        while( u )
     347        {
     348                if( u->ic == ic )
     349                {
     350                        t = u->next;
     351                        user_del( irc, u->nick );
     352                        u = t;
     353                }
     354                else
     355                        u = u->next;
     356        }
     357       
     358        query_del_by_conn( ic->irc, ic );
     359       
     360        for( a = irc->accounts; a; a = a->next )
    343361                if( a->ic == ic )
    344362                        break;
     
    348366                /* Uhm... This is very sick. */
    349367        }
    350         else if( allow_reconnect && set_getbool( &bee->set, "auto_reconnect" ) &&
     368        else if( allow_reconnect && set_getbool( &irc->set, "auto_reconnect" ) &&
    351369                 set_getbool( &a->set, "auto_reconnect" ) &&
    352370                 ( delay = account_reconnect_delay( a ) ) > 0 )
     
    359377}
    360378
     379
     380/* dialogs.c */
     381
    361382void imcb_ask( struct im_connection *ic, char *msg, void *data,
    362383               query_callback doit, query_callback dont )
    363384{
    364         query_add( (irc_t *) ic->bee->ui_data, ic, msg, doit, dont, data );
    365 }
     385        query_add( ic->irc, ic, msg, doit, dont, data );
     386}
     387
     388
     389/* list.c */
    366390
    367391void imcb_add_buddy( struct im_connection *ic, const char *handle, const char *group )
    368392{
    369         bee_user_t *bu;
    370         bee_t *bee = ic->bee;
    371        
    372         if( bee_user_by_handle( bee, ic, handle ) )
    373         {
    374                 if( set_getbool( &bee->set, "debug" ) )
     393        user_t *u;
     394        char nick[MAX_NICK_LENGTH+1], *s;
     395        irc_t *irc = ic->irc;
     396       
     397        if( user_findhandle( ic, handle ) )
     398        {
     399                if( set_getbool( &irc->set, "debug" ) )
    375400                        imcb_log( ic, "User already exists, ignoring add request: %s", handle );
    376401               
     
    383408        }
    384409       
    385         bu = bee_user_new( bee, ic, handle );
    386         bu->group = g_strdup( group );
    387 }
    388 
    389 void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char *fullname )
    390 {
    391         bee_t *bee = ic->bee;
    392         bee_user_t *bu = bee_user_by_handle( bee, ic, handle );
    393        
    394         if( !bu || !fullname ) return;
    395        
    396         if( !bu->fullname || strcmp( bu->fullname, fullname ) != 0 )
    397         {
    398                 g_free( bu->fullname );
    399                 bu->fullname = g_strdup( fullname );
    400                
    401                 if( bee->ui->user_fullname )
    402                         bee->ui->user_fullname( bee, bu );
     410        memset( nick, 0, MAX_NICK_LENGTH + 1 );
     411        strcpy( nick, nick_get( ic->acc, handle ) );
     412       
     413        u = user_add( ic->irc, nick );
     414       
     415//      if( !realname || !*realname ) realname = nick;
     416//      u->realname = g_strdup( realname );
     417       
     418        if( ( s = strchr( handle, '@' ) ) )
     419        {
     420                u->host = g_strdup( s + 1 );
     421                u->user = g_strndup( handle, s - handle );
     422        }
     423        else if( ic->acc->server )
     424        {
     425                u->host = g_strdup( ic->acc->server );
     426                u->user = g_strdup( handle );
     427               
     428                /* s/ /_/ ... important for AOL screennames */
     429                for( s = u->user; *s; s ++ )
     430                        if( *s == ' ' )
     431                                *s = '_';
     432        }
     433        else
     434        {
     435                u->host = g_strdup( ic->acc->prpl->name );
     436                u->user = g_strdup( handle );
     437        }
     438       
     439        u->ic = ic;
     440        u->handle = g_strdup( handle );
     441        if( group ) u->group = g_strdup( group );
     442        u->send_handler = buddy_send_handler;
     443        u->last_typing_notice = 0;
     444}
     445
     446struct buddy *imcb_find_buddy( struct im_connection *ic, char *handle )
     447{
     448        static struct buddy b[1];
     449        user_t *u;
     450       
     451        u = user_findhandle( ic, handle );
     452       
     453        if( !u )
     454                return( NULL );
     455       
     456        memset( b, 0, sizeof( b ) );
     457        strncpy( b->name, handle, 80 );
     458        strncpy( b->show, u->realname, BUDDY_ALIAS_MAXLEN );
     459        b->present = u->online;
     460        b->ic = u->ic;
     461       
     462        return( b );
     463}
     464
     465void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char *realname )
     466{
     467        user_t *u = user_findhandle( ic, handle );
     468        char *set;
     469       
     470        if( !u || !realname ) return;
     471       
     472        if( g_strcasecmp( u->realname, realname ) != 0 )
     473        {
     474                if( u->realname != u->nick ) g_free( u->realname );
     475               
     476                u->realname = g_strdup( realname );
     477               
     478                if( ( ic->flags & OPT_LOGGED_IN ) && set_getbool( &ic->irc->set, "display_namechanges" ) )
     479                        imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname );
     480        }
     481       
     482        set = set_getstr( &ic->acc->set, "nick_source" );
     483        if( strcmp( set, "handle" ) != 0 )
     484        {
     485                char *name = g_strdup( realname );
     486               
     487                if( strcmp( set, "first_name" ) == 0 )
     488                {
     489                        int i;
     490                        for( i = 0; name[i] && !isspace( name[i] ); i ++ ) {}
     491                        name[i] = '\0';
     492                }
     493               
     494                imcb_buddy_nick_hint( ic, handle, name );
     495               
     496                g_free( name );
    403497        }
    404498}
     
    406500void imcb_remove_buddy( struct im_connection *ic, const char *handle, char *group )
    407501{
    408         bee_user_free( ic->bee, bee_user_by_handle( ic->bee, ic, handle ) );
     502        user_t *u;
     503       
     504        if( ( u = user_findhandle( ic, handle ) ) )
     505                user_del( ic->irc, u->nick );
    409506}
    410507
     
    413510void imcb_buddy_nick_hint( struct im_connection *ic, const char *handle, const char *nick )
    414511{
    415 #if 0
    416512        user_t *u = user_findhandle( ic, handle );
    417513        char newnick[MAX_NICK_LENGTH+1], *orig_nick;
     
    428524                /* Some processing to make sure this string is a valid IRC nickname. */
    429525                nick_strip( newnick );
    430                 if( set_getbool( &ic->bee->set, "lcnicks" ) )
     526                if( set_getbool( &ic->irc->set, "lcnicks" ) )
    431527                        nick_lc( newnick );
    432528               
     
    445541                }
    446542        }
    447 #endif
    448543}
    449544
     
    490585        data->ic = ic;
    491586        data->handle = g_strdup( handle );
    492         query_add( (irc_t *) ic->bee->ui_data, ic, s,
    493                    imcb_ask_auth_cb_yes, imcb_ask_auth_cb_no, data );
     587        query_add( ic->irc, ic, s, imcb_ask_auth_cb_yes, imcb_ask_auth_cb_no, data );
    494588}
    495589
     
    516610       
    517611        /* TODO: Make a setting for this! */
    518         if( bee_user_by_handle( ic->bee, ic, handle ) != NULL )
     612        if( user_findhandle( ic, handle ) != NULL )
    519613                return;
    520614       
     
    523617        data->ic = ic;
    524618        data->handle = g_strdup( handle );
    525         query_add( (irc_t *) ic->bee->ui_data, ic, s,
    526                    imcb_ask_add_cb_yes, imcb_ask_add_cb_no, data );
    527 }
    528 
    529 struct bee_user *imcb_buddy_by_handle( struct im_connection *ic, const char *handle )
    530 {
    531         return bee_user_by_handle( ic->bee, ic, handle );
     619        query_add( ic->irc, ic, s, imcb_ask_add_cb_yes, imcb_ask_add_cb_no, data );
     620}
     621
     622
     623/* server.c */                   
     624
     625void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message )
     626{
     627        user_t *u;
     628        int oa, oo;
     629       
     630        u = user_findhandle( ic, (char*) handle );
     631       
     632        if( !u )
     633        {
     634                if( g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "add" ) == 0 )
     635                {
     636                        imcb_add_buddy( ic, (char*) handle, NULL );
     637                        u = user_findhandle( ic, (char*) handle );
     638                }
     639                else
     640                {
     641                        if( set_getbool( &ic->irc->set, "debug" ) || g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "ignore" ) != 0 )
     642                        {
     643                                imcb_log( ic, "imcb_buddy_status() for unknown handle %s:", handle );
     644                                imcb_log( ic, "flags = %d, state = %s, message = %s", flags,
     645                                          state ? state : "NULL", message ? message : "NULL" );
     646                        }
     647                       
     648                        return;
     649                }
     650        }
     651       
     652        oa = u->away != NULL;
     653        oo = u->online;
     654       
     655        g_free( u->away );
     656        g_free( u->status_msg );
     657        u->away = u->status_msg = NULL;
     658       
     659        if( ( flags & OPT_LOGGED_IN ) && !u->online )
     660        {
     661                irc_spawn( ic->irc, u );
     662                u->online = 1;
     663        }
     664        else if( !( flags & OPT_LOGGED_IN ) && u->online )
     665        {
     666                struct groupchat *c;
     667               
     668                irc_kill( ic->irc, u );
     669                u->online = 0;
     670               
     671                /* Remove him/her from the groupchats to prevent PART messages after he/she QUIT already */
     672                for( c = ic->groupchats; c; c = c->next )
     673                        remove_chat_buddy_silent( c, handle );
     674        }
     675       
     676        if( flags & OPT_AWAY )
     677        {
     678                if( state && message )
     679                {
     680                        u->away = g_strdup_printf( "%s (%s)", state, message );
     681                }
     682                else if( state )
     683                {
     684                        u->away = g_strdup( state );
     685                }
     686                else if( message )
     687                {
     688                        u->away = g_strdup( message );
     689                }
     690                else
     691                {
     692                        u->away = g_strdup( "Away" );
     693                }
     694        }
     695        else
     696        {
     697                u->status_msg = g_strdup( message );
     698        }
     699       
     700        /* LISPy... */
     701        if( ( set_getbool( &ic->irc->set, "away_devoice" ) ) &&         /* Don't do a thing when user doesn't want it */
     702            ( u->online ) &&                                            /* Don't touch offline people */
     703            ( ( ( u->online != oo ) && !u->away ) ||                    /* Voice joining people */
     704              ( ( u->online == oo ) && ( oa == !u->away ) ) ) )         /* (De)voice people changing state */
     705        {
     706                char *from;
     707               
     708                if( set_getbool( &ic->irc->set, "simulate_netsplit" ) )
     709                {
     710                        from = g_strdup( ic->irc->myhost );
     711                }
     712                else
     713                {
     714                        from = g_strdup_printf( "%s!%s@%s", ic->irc->mynick, ic->irc->mynick,
     715                                                            ic->irc->myhost );
     716                }
     717                irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel,
     718                                                          u->away?'-':'+', u->nick );
     719                g_free( from );
     720        }
     721}
     722
     723void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, uint32_t flags, time_t sent_at )
     724{
     725        irc_t *irc = ic->irc;
     726        char *wrapped, *ts = NULL;
     727        user_t *u;
     728       
     729        u = user_findhandle( ic, handle );
     730       
     731        if( !u )
     732        {
     733                char *h = set_getstr( &irc->set, "handle_unknown" );
     734               
     735                if( g_strcasecmp( h, "ignore" ) == 0 )
     736                {
     737                        if( set_getbool( &irc->set, "debug" ) )
     738                                imcb_log( ic, "Ignoring message from unknown handle %s", handle );
     739                       
     740                        return;
     741                }
     742                else if( g_strncasecmp( h, "add", 3 ) == 0 )
     743                {
     744                        int private = set_getbool( &irc->set, "private" );
     745                       
     746                        if( h[3] )
     747                        {
     748                                if( g_strcasecmp( h + 3, "_private" ) == 0 )
     749                                        private = 1;
     750                                else if( g_strcasecmp( h + 3, "_channel" ) == 0 )
     751                                        private = 0;
     752                        }
     753                       
     754                        imcb_add_buddy( ic, handle, NULL );
     755                        u = user_findhandle( ic, handle );
     756                        u->is_private = private;
     757                }
     758                else
     759                {
     760                        imcb_log( ic, "Message from unknown handle %s:", handle );
     761                        u = user_find( irc, irc->mynick );
     762                }
     763        }
     764       
     765        if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
     766            ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
     767                strip_html( msg );
     768       
     769        if( set_getbool( &ic->irc->set, "display_timestamps" ) &&
     770            ( ts = format_timestamp( irc, sent_at ) ) )
     771        {
     772                char *new = g_strconcat( ts, msg, NULL );
     773                g_free( ts );
     774                ts = msg = new;
     775        }
     776       
     777        wrapped = word_wrap( msg, 425 );
     778        irc_msgfrom( irc, u->nick, wrapped );
     779        g_free( wrapped );
     780        g_free( ts );
     781}
     782
     783void imcb_buddy_typing( struct im_connection *ic, char *handle, uint32_t flags )
     784{
     785        user_t *u;
     786       
     787        if( !set_getbool( &ic->irc->set, "typing_notice" ) )
     788                return;
     789       
     790        if( ( u = user_findhandle( ic, handle ) ) )
     791        {
     792                char buf[256];
     793               
     794                g_snprintf( buf, 256, "\1TYPING %d\1", ( flags >> 8 ) & 3 );
     795                irc_privmsg( ic->irc, u, "PRIVMSG", ic->irc->nick, NULL, buf );
     796        }
    532797}
    533798
    534799struct groupchat *imcb_chat_new( struct im_connection *ic, const char *handle )
    535800{
    536 #if 0
    537801        struct groupchat *c;
    538802       
     
    552816        c->topic = g_strdup_printf( "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", c->title );
    553817       
    554         if( set_getbool( &ic->bee->set, "debug" ) )
     818        if( set_getbool( &ic->irc->set, "debug" ) )
    555819                imcb_log( ic, "Creating new conversation: (id=%p,handle=%s)", c, handle );
    556820       
    557821        return c;
    558 #endif
    559         return NULL;
     822}
     823
     824void imcb_chat_name_hint( struct groupchat *c, const char *name )
     825{
     826        if( !c->joined )
     827        {
     828                struct im_connection *ic = c->ic;
     829                char stripped[MAX_NICK_LENGTH+1], *full_name;
     830               
     831                strncpy( stripped, name, MAX_NICK_LENGTH );
     832                stripped[MAX_NICK_LENGTH] = '\0';
     833                nick_strip( stripped );
     834                if( set_getbool( &ic->irc->set, "lcnicks" ) )
     835                        nick_lc( stripped );
     836               
     837                full_name = g_strdup_printf( "&%s", stripped );
     838               
     839                if( stripped[0] &&
     840                    nick_cmp( stripped, ic->irc->channel + 1 ) != 0 &&
     841                    irc_chat_by_channel( ic->irc, full_name ) == NULL )
     842                {
     843                        g_free( c->channel );
     844                        c->channel = full_name;
     845                }
     846                else
     847                {
     848                        g_free( full_name );
     849                }
     850        }
    560851}
    561852
    562853void imcb_chat_free( struct groupchat *c )
    563854{
    564 #if 0
    565855        struct im_connection *ic = c->ic;
    566856        struct groupchat *l;
    567857        GList *ir;
    568858       
    569         if( set_getbool( &ic->bee->set, "debug" ) )
     859        if( set_getbool( &ic->irc->set, "debug" ) )
    570860                imcb_log( ic, "You were removed from conversation %p", c );
    571861       
     
    600890                g_free( c );
    601891        }
    602 #endif
    603892}
    604893
    605894void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t flags, time_t sent_at )
    606895{
    607 #if 0
    608896        struct im_connection *ic = c->ic;
    609897        char *wrapped;
     
    616904        u = user_findhandle( ic, who );
    617905       
    618         if( ( g_strcasecmp( set_getstr( &ic->bee->set, "strip_html" ), "always" ) == 0 ) ||
    619             ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->bee->set, "strip_html" ) ) )
     906        if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
     907            ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
    620908                strip_html( msg );
    621909       
     
    623911        if( c && u )
    624912        {
    625                 irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, "", wrapped );
     913                char *ts = NULL;
     914                if( set_getbool( &ic->irc->set, "display_timestamps" ) )
     915                        ts = format_timestamp( ic->irc, sent_at );
     916                irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, ts ? : "", wrapped );
     917                g_free( ts );
    626918        }
    627919        else
     
    630922        }
    631923        g_free( wrapped );
    632 #endif
    633924}
    634925
    635926void imcb_chat_log( struct groupchat *c, char *format, ... )
    636927{
    637 #if 0
    638928        irc_t *irc = c->ic->irc;
    639929        va_list params;
     
    650940       
    651941        g_free( text );
    652 #endif
    653942}
    654943
    655944void imcb_chat_topic( struct groupchat *c, char *who, char *topic, time_t set_at )
    656945{
    657 #if 0
    658946        struct im_connection *ic = c->ic;
    659947        user_t *u = NULL;
     
    666954                u = user_findhandle( ic, who );
    667955       
    668         if( ( g_strcasecmp( set_getstr( &ic->bee->set, "strip_html" ), "always" ) == 0 ) ||
    669             ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->bee->set, "strip_html" ) ) )
     956        if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
     957            ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
    670958                strip_html( topic );
    671959       
     
    675963        if( c->joined && u )
    676964                irc_write( ic->irc, ":%s!%s@%s TOPIC %s :%s", u->nick, u->user, u->host, c->channel, topic );
    677 #endif
    678 }
     965}
     966
     967
     968/* buddy_chat.c */
    679969
    680970void imcb_chat_add_buddy( struct groupchat *b, const char *handle )
    681971{
    682 #if 0
    683972        user_t *u = user_findhandle( b->ic, handle );
    684973        int me = 0;
    685974       
    686         if( set_getbool( &b->ic->bee->set, "debug" ) )
     975        if( set_getbool( &b->ic->irc->set, "debug" ) )
    687976                imcb_log( b->ic, "User %s added to conversation %p", handle, b );
    688977       
     
    7111000                b->in_room = g_list_append( b->in_room, g_strdup( handle ) );
    7121001        }
    713 #endif
    7141002}
    7151003
     
    7171005void imcb_chat_remove_buddy( struct groupchat *b, const char *handle, const char *reason )
    7181006{
    719 #if 0
    7201007        user_t *u;
    7211008        int me = 0;
    7221009       
    723         if( set_getbool( &b->ic->bee->set, "debug" ) )
     1010        if( set_getbool( &b->ic->irc->set, "debug" ) )
    7241011                imcb_log( b->ic, "User %s removed from conversation %p (%s)", handle, b, reason ? reason : "" );
    7251012       
     
    7411028        if( me || ( remove_chat_buddy_silent( b, handle ) && b->joined && u ) )
    7421029                irc_part( b->ic->irc, u, b->channel );
    743 #endif
    744 }
    745 
    746 #if 0
     1030}
     1031
    7471032static int remove_chat_buddy_silent( struct groupchat *b, const char *handle )
    7481033{
     
    7631048        }
    7641049       
    765         return 0;
    766 }
    767 #endif
     1050        return( 0 );
     1051}
    7681052
    7691053
    7701054/* Misc. BitlBee stuff which shouldn't really be here */
    771 #if 0
     1055
    7721056char *set_eval_away_devoice( set_t *set, char *value )
    7731057{
     
    7821066        /* Horror.... */
    7831067       
    784         if( st != set_getbool( &irc->b->set, "away_devoice" ) )
     1068        if( st != set_getbool( &irc->set, "away_devoice" ) )
    7851069        {
    7861070                char list[80] = "";
     
    8241108        return value;
    8251109}
    826 #endif
    827 
    828 
     1110
     1111char *set_eval_timezone( set_t *set, char *value )
     1112{
     1113        char *s;
     1114       
     1115        if( strcmp( value, "local" ) == 0 ||
     1116            strcmp( value, "gmt" ) == 0 || strcmp( value, "utc" ) == 0 )
     1117                return value;
     1118       
     1119        /* Otherwise: +/- at the beginning optional, then one or more numbers,
     1120           possibly followed by a colon and more numbers. Don't bother bound-
     1121           checking them since users are free to shoot themselves in the foot. */
     1122        s = value;
     1123        if( *s == '+' || *s == '-' )
     1124                s ++;
     1125       
     1126        /* \d+ */
     1127        if( !isdigit( *s ) )
     1128                return SET_INVALID;
     1129        while( *s && isdigit( *s ) ) s ++;
     1130       
     1131        /* EOS? */
     1132        if( *s == '\0' )
     1133                return value;
     1134       
     1135        /* Otherwise, colon */
     1136        if( *s != ':' )
     1137                return SET_INVALID;
     1138        s ++;
     1139       
     1140        /* \d+ */
     1141        if( !isdigit( *s ) )
     1142                return SET_INVALID;
     1143        while( *s && isdigit( *s ) ) s ++;
     1144       
     1145        /* EOS */
     1146        return *s == '\0' ? value : SET_INVALID;
     1147}
     1148
     1149static char *format_timestamp( irc_t *irc, time_t msg_ts )
     1150{
     1151        time_t now_ts = time( NULL );
     1152        struct tm now, msg;
     1153        char *set;
     1154       
     1155        /* If the timestamp is <= 0 or less than a minute ago, discard it as
     1156           it doesn't seem to add to much useful info and/or might be noise. */
     1157        if( msg_ts <= 0 || msg_ts > now_ts - 60 )
     1158                return NULL;
     1159       
     1160        set = set_getstr( &irc->set, "timezone" );
     1161        if( strcmp( set, "local" ) == 0 )
     1162        {
     1163                localtime_r( &now_ts, &now );
     1164                localtime_r( &msg_ts, &msg );
     1165        }
     1166        else
     1167        {
     1168                int hr, min = 0, sign = 60;
     1169               
     1170                if( set[0] == '-' )
     1171                {
     1172                        sign *= -1;
     1173                        set ++;
     1174                }
     1175                else if( set[0] == '+' )
     1176                {
     1177                        set ++;
     1178                }
     1179               
     1180                if( sscanf( set, "%d:%d", &hr, &min ) >= 1 )
     1181                {
     1182                        msg_ts += sign * ( hr * 60 + min );
     1183                        now_ts += sign * ( hr * 60 + min );
     1184                }
     1185               
     1186                gmtime_r( &now_ts, &now );
     1187                gmtime_r( &msg_ts, &msg );
     1188        }
     1189       
     1190        if( msg.tm_year == now.tm_year && msg.tm_yday == now.tm_yday )
     1191                return g_strdup_printf( "\x02[\x02\x02\x02%02d:%02d:%02d\x02]\x02 ",
     1192                                        msg.tm_hour, msg.tm_min, msg.tm_sec );
     1193        else
     1194                return g_strdup_printf( "\x02[\x02\x02\x02%04d-%02d-%02d "
     1195                                        "%02d:%02d:%02d\x02]\x02 ",
     1196                                        msg.tm_year + 1900, msg.tm_mon, msg.tm_mday,
     1197                                        msg.tm_hour, msg.tm_min, msg.tm_sec );
     1198}
    8291199
    8301200/* The plan is to not allow straight calls to prpl functions anymore, but do
    8311201   them all from some wrappers. We'll start to define some down here: */
    8321202
    833 int imc_chat_msg( struct groupchat *c, char *msg, int flags )
     1203int imc_buddy_msg( struct im_connection *ic, char *handle, char *msg, int flags )
    8341204{
    8351205        char *buf = NULL;
    836        
    837         if( ( c->ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) )
     1206        int st;
     1207       
     1208        if( ( ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) )
    8381209        {
    8391210                buf = escape_html( msg );
     
    8411212        }
    8421213       
     1214        st = ic->acc->prpl->buddy_msg( ic, handle, msg, flags );
     1215        g_free( buf );
     1216       
     1217        return st;
     1218}
     1219
     1220int imc_chat_msg( struct groupchat *c, char *msg, int flags )
     1221{
     1222        char *buf = NULL;
     1223       
     1224        if( ( c->ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) )
     1225        {
     1226                buf = escape_html( msg );
     1227                msg = buf;
     1228        }
     1229       
    8431230        c->ic->acc->prpl->chat_msg( c, msg, flags );
    8441231        g_free( buf );
     
    8531240        char *away, *msg = NULL;
    8541241       
     1242        if( ic->acc->prpl->away_states == NULL ||
     1243            ic->acc->prpl->set_away == NULL )
     1244                return 0;
     1245       
    8551246        away = set_getstr( &ic->acc->set, "away" ) ?
    856              : set_getstr( &ic->bee->set, "away" );
     1247             : set_getstr( &ic->irc->set, "away" );
    8571248        if( away && *away )
    8581249        {
     
    8651256                away = NULL;
    8661257                msg = set_getstr( &ic->acc->set, "status" ) ?
    867                     : set_getstr( &ic->bee->set, "status" );
     1258                    : set_getstr( &ic->irc->set, "status" );
    8681259        }
    8691260       
Note: See TracChangeset for help on using the changeset viewer.