Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/nogaim.c

    rc6ca3ee r286b28e  
    22  * BitlBee -- An IRC to other IM-networks gateway                     *
    33  *                                                                    *
    4   * Copyright 2002-2006 Wilmer van der Gaast and others                *
     4  * Copyright 2002-2010 Wilmer van der Gaast and others                *
    55  \********************************************************************/
    66
     
    3333
    3434#define BITLBEE_CORE
     35#include <ctype.h>
     36
    3537#include "nogaim.h"
    36 #include <ctype.h>
     38#include "chat.h"
    3739
    3840static int remove_chat_buddy_silent( struct groupchat *b, const char *handle );
     
    249251void imcb_connected( struct im_connection *ic )
    250252{
     253        irc_t *irc = ic->irc;
     254        struct chat *c;
    251255        user_t *u;
    252256       
     
    264268        ic->flags |= OPT_LOGGED_IN;
    265269       
    266         /* Also necessary when we're not away, at least for some of the
    267            protocols. */
    268         imc_set_away( ic, u->away );
     270        /* Necessary to send initial presence status, even if we're not away. */
     271        imc_away_send_update( ic );
     272       
     273        /* Apparently we're connected successfully, so reset the
     274           exponential backoff timer. */
     275        ic->acc->auto_reconnect_delay = 0;
     276       
     277        for( c = irc->chatrooms; c; c = c->next )
     278        {
     279                if( c->acc != ic->acc )
     280                        continue;
     281               
     282                if( set_getbool( &c->set, "auto_join" ) )
     283                        chat_join( irc, c, NULL );
     284        }
    269285}
    270286
     
    290306        user_t *t, *u;
    291307        account_t *a;
     308        int delay;
    292309       
    293310        /* Nested calls might happen sometimes, this is probably the best
     
    305322        b_event_remove( ic->inpa );
    306323       
     324        g_free( ic->away );
     325        ic->away = NULL;
     326       
    307327        u = irc->users;
    308328        while( u )
     
    329349        }
    330350        else if( allow_reconnect && set_getbool( &irc->set, "auto_reconnect" ) &&
    331                  set_getbool( &a->set, "auto_reconnect" ) )
    332         {
    333                 int delay = set_getint( &irc->set, "auto_reconnect_delay" );
    334                
     351                 set_getbool( &a->set, "auto_reconnect" ) &&
     352                 ( delay = account_reconnect_delay( a ) ) > 0 )
     353        {
    335354                imcb_log( ic, "Reconnecting in %d seconds..", delay );
    336355                a->reconnect = b_timeout_add( delay * 1000, auto_reconnect, a );
     
    352371/* list.c */
    353372
    354 void imcb_add_buddy( struct im_connection *ic, const char *handle, const char *group )
     373void imcb_add_buddy( struct im_connection *ic, char *handle, char *group )
    355374{
    356375        user_t *u;
     
    426445}
    427446
    428 void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char *realname )
     447void imcb_rename_buddy( struct im_connection *ic, char *handle, char *realname )
    429448{
    430449        user_t *u = user_findhandle( ic, handle );
     450        char *set;
    431451       
    432452        if( !u || !realname ) return;
     
    441461                        imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname );
    442462        }
    443 }
    444 
    445 void imcb_remove_buddy( struct im_connection *ic, const char *handle, char *group )
     463       
     464        set = set_getstr( &ic->acc->set, "nick_source" );
     465        if( strcmp( set, "handle" ) != 0 )
     466        {
     467                char *name = g_strdup( realname );
     468               
     469                if( strcmp( set, "first_name" ) == 0 )
     470                {
     471                        int i;
     472                        for( i = 0; name[i] && !isspace( name[i] ); i ++ ) {}
     473                        name[i] = '\0';
     474                }
     475               
     476                imcb_buddy_nick_hint( ic, handle, name );
     477               
     478                g_free( name );
     479        }
     480}
     481
     482void imcb_remove_buddy( struct im_connection *ic, char *handle, char *group )
    446483{
    447484        user_t *u;
     
    488525}
    489526
    490 /* prpl.c */
    491 
    492 struct show_got_added_data
     527
     528struct imcb_ask_cb_data
    493529{
    494530        struct im_connection *ic;
     
    496532};
    497533
    498 void show_got_added_no( void *data )
    499 {
    500         g_free( ((struct show_got_added_data*)data)->handle );
     534static void imcb_ask_auth_cb_no( void *data )
     535{
     536        struct imcb_ask_cb_data *cbd = data;
     537       
     538        cbd->ic->acc->prpl->auth_deny( cbd->ic, cbd->handle );
     539       
     540        g_free( cbd->handle );
     541        g_free( cbd );
     542}
     543
     544static void imcb_ask_auth_cb_yes( void *data )
     545{
     546        struct imcb_ask_cb_data *cbd = data;
     547       
     548        cbd->ic->acc->prpl->auth_allow( cbd->ic, cbd->handle );
     549       
     550        g_free( cbd->handle );
     551        g_free( cbd );
     552}
     553
     554void imcb_ask_auth( struct im_connection *ic, const char *handle, const char *realname )
     555{
     556        struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 );
     557        char *s, *realname_ = NULL;
     558       
     559        if( realname != NULL )
     560                realname_ = g_strdup_printf( " (%s)", realname );
     561       
     562        s = g_strdup_printf( "The user %s%s wants to add you to his/her buddy list.",
     563                             handle, realname_ ?: "" );
     564       
     565        g_free( realname_ );
     566       
     567        data->ic = ic;
     568        data->handle = g_strdup( handle );
     569        query_add( ic->irc, ic, s, imcb_ask_auth_cb_yes, imcb_ask_auth_cb_no, data );
     570}
     571
     572
     573static void imcb_ask_add_cb_no( void *data )
     574{
     575        g_free( ((struct imcb_ask_cb_data*)data)->handle );
    501576        g_free( data );
    502577}
    503578
    504 void show_got_added_yes( void *data )
    505 {
    506         struct show_got_added_data *sga = data;
    507        
    508         sga->ic->acc->prpl->add_buddy( sga->ic, sga->handle, NULL );
    509         /* imcb_add_buddy( sga->ic, NULL, sga->handle, sga->handle ); */
    510        
    511         return show_got_added_no( data );
    512 }
    513 
    514 void imcb_ask_add( struct im_connection *ic, char *handle, const char *realname )
    515 {
    516         struct show_got_added_data *data = g_new0( struct show_got_added_data, 1 );
     579static void imcb_ask_add_cb_yes( void *data )
     580{
     581        struct imcb_ask_cb_data *cbd = data;
     582       
     583        cbd->ic->acc->prpl->add_buddy( cbd->ic, cbd->handle, NULL );
     584       
     585        return imcb_ask_add_cb_no( data );
     586}
     587
     588void imcb_ask_add( struct im_connection *ic, const char *handle, const char *realname )
     589{
     590        struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 );
    517591        char *s;
    518592       
     
    525599        data->ic = ic;
    526600        data->handle = g_strdup( handle );
    527         query_add( ic->irc, ic, s, show_got_added_yes, show_got_added_no, data );
     601        query_add( ic->irc, ic, s, imcb_ask_add_cb_yes, imcb_ask_add_cb_no, data );
    528602}
    529603
     
    628702}
    629703
    630 void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, uint32_t flags, time_t sent_at )
     704void imcb_buddy_msg( struct im_connection *ic, char *handle, char *msg, uint32_t flags, time_t sent_at )
    631705{
    632706        irc_t *irc = ic->irc;
     
    761835}
    762836
    763 void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t flags, time_t sent_at )
     837void imcb_chat_msg( struct groupchat *c, char *who, char *msg, uint32_t flags, time_t sent_at )
    764838{
    765839        struct im_connection *ic = c->ic;
     
    833907/* buddy_chat.c */
    834908
    835 void imcb_chat_add_buddy( struct groupchat *b, const char *handle )
     909void imcb_chat_add_buddy( struct groupchat *b, char *handle )
    836910{
    837911        user_t *u = user_findhandle( b->ic, handle );
     
    868942
    869943/* This function is one BIG hack... :-( EREWRITE */
    870 void imcb_chat_remove_buddy( struct groupchat *b, const char *handle, const char *reason )
     944void imcb_chat_remove_buddy( struct groupchat *b, char *handle, char *reason )
    871945{
    872946        user_t *u;
     
    924998        int st;
    925999       
    926         if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) )
    927                 st = 1;
    928         else if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) )
    929                 st = 0;
    930         else if( sscanf( value, "%d", &st ) != 1 )
    931                 return( NULL );
    932        
    933         st = st != 0;
     1000        if( !is_bool( value ) )
     1001                return SET_INVALID;
     1002       
     1003        st = bool2int( value );
    9341004       
    9351005        /* Horror.... */
     
    9751045        }
    9761046       
    977         return( set_eval_bool( set, value ) );
     1047        return value;
    9781048}
    9791049
     
    10171087}
    10181088
    1019 static char *imc_away_alias_find( GList *gcm, char *away );
    1020 
    1021 int imc_set_away( struct im_connection *ic, char *away )
    1022 {
    1023         GList *m, *ms;
    1024         char *s;
    1025        
    1026         if( !away ) away = "";
    1027         ms = m = ic->acc->prpl->away_states( ic );
    1028        
    1029         while( m )
    1030         {
    1031                 if( *away )
    1032                 {
    1033                         if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 )
    1034                                 break;
    1035                 }
    1036                 else
    1037                 {
    1038                         if( g_strcasecmp( m->data, "Available" ) == 0 )
    1039                                 break;
    1040                         if( g_strcasecmp( m->data, "Online" ) == 0 )
    1041                                 break;
    1042                 }
    1043                 m = m->next;
    1044         }
    1045        
    1046         if( m )
    1047         {
    1048                 ic->acc->prpl->set_away( ic, m->data, *away ? away : NULL );
    1049         }
    1050         else
    1051         {
    1052                 s = imc_away_alias_find( ms, away );
    1053                 if( s )
    1054                 {
    1055                         ic->acc->prpl->set_away( ic, s, away );
    1056                         if( set_getbool( &ic->irc->set, "debug" ) )
    1057                                 imcb_log( ic, "Setting away state to %s", s );
    1058                 }
    1059                 else
    1060                         ic->acc->prpl->set_away( ic, GAIM_AWAY_CUSTOM, away );
    1061         }
    1062        
    1063         return( 1 );
     1089static char *imc_away_state_find( GList *gcm, char *away, char **message );
     1090
     1091int imc_away_send_update( struct im_connection *ic )
     1092{
     1093        char *away, *msg = NULL;
     1094       
     1095        away = set_getstr( &ic->acc->set, "away" ) ?
     1096             : set_getstr( &ic->irc->set, "away" );
     1097        if( away && *away )
     1098        {
     1099                GList *m = ic->acc->prpl->away_states( ic );
     1100                msg = ic->acc->flags & ACC_FLAG_AWAY_MESSAGE ? away : NULL;
     1101                away = imc_away_state_find( m, away, &msg ) ? : m->data;
     1102        }
     1103        else if( ic->acc->flags & ACC_FLAG_STATUS_MESSAGE )
     1104        {
     1105                away = NULL;
     1106                msg = set_getstr( &ic->acc->set, "status" ) ?
     1107                    : set_getstr( &ic->irc->set, "status" );
     1108        }
     1109       
     1110        ic->acc->prpl->set_away( ic, away, msg );
     1111       
     1112        return 1;
    10641113}
    10651114
     
    10761125};
    10771126
    1078 static char *imc_away_alias_find( GList *gcm, char *away )
     1127static char *imc_away_state_find( GList *gcm, char *away, char **message )
    10791128{
    10801129        GList *m;
    10811130        int i, j;
    10821131       
     1132        for( m = gcm; m; m = m->next )
     1133                if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 )
     1134                {
     1135                        /* At least the Yahoo! module works better if message
     1136                           contains no data unless it adds something to what
     1137                           we have in state already. */
     1138                        if( strlen( m->data ) == strlen( away ) )
     1139                                *message = NULL;
     1140                       
     1141                        return m->data;
     1142                }
     1143       
    10831144        for( i = 0; *imc_away_alias_list[i]; i ++ )
    10841145        {
     1146                int keep_message;
     1147               
    10851148                for( j = 0; imc_away_alias_list[i][j]; j ++ )
    10861149                        if( g_strncasecmp( away, imc_away_alias_list[i][j], strlen( imc_away_alias_list[i][j] ) ) == 0 )
     1150                        {
     1151                                keep_message = strlen( away ) != strlen( imc_away_alias_list[i][j] );
    10871152                                break;
     1153                        }
    10881154               
    10891155                if( !imc_away_alias_list[i][j] )        /* If we reach the end, this row */
     
    10931159                for( j = 0; imc_away_alias_list[i][j]; j ++ )
    10941160                {
    1095                         m = gcm;
    1096                         while( m )
    1097                         {
     1161                        for( m = gcm; m; m = m->next )
    10981162                                if( g_strcasecmp( imc_away_alias_list[i][j], m->data ) == 0 )
    1099                                         return( imc_away_alias_list[i][j] );
    1100                                 m = m->next;
    1101                         }
    1102                 }
    1103         }
    1104        
    1105         return( NULL );
     1163                                {
     1164                                        if( !keep_message )
     1165                                                *message = NULL;
     1166                                       
     1167                                        return imc_away_alias_list[i][j];
     1168                                }
     1169                }
     1170               
     1171                /* No need to look further, apparently this state doesn't
     1172                   have any good alias for this protocol. */
     1173                break;
     1174        }
     1175       
     1176        return NULL;
    11061177}
    11071178
Note: See TracChangeset for help on using the changeset viewer.