Changeset 75554d0 for protocols/nogaim.c


Ignore:
Timestamp:
2010-03-17T13:56:52Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
b788246
Parents:
e5e795d (diff), f9928cb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merging in 1.2.5.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/nogaim.c

    re5e795d r75554d0  
    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
     
    9898void register_protocol (struct prpl *p)
    9999{
    100         protocols = g_list_append(protocols, p);
     100        int i;
     101        gboolean refused = global.conf->protocols != NULL;
     102 
     103        for (i = 0; global.conf->protocols && global.conf->protocols[i]; i++)
     104        {
     105                if (g_strcasecmp(p->name, global.conf->protocols[i]) == 0)
     106                        refused = FALSE;
     107        }
     108
     109        if (refused)
     110                log_message(LOGLVL_WARNING, "Protocol %s disabled\n", p->name);
     111        else
     112                protocols = g_list_append(protocols, p);
    101113}
    102114
     
    268280        ic->flags |= OPT_LOGGED_IN;
    269281       
    270         /* Also necessary when we're not away, at least for some of the
    271            protocols. */
    272         imc_set_away( ic, u->away );
     282        /* Necessary to send initial presence status, even if we're not away. */
     283        imc_away_send_update( ic );
    273284       
    274285        /* Apparently we're connected successfully, so reset the
     
    372383/* list.c */
    373384
    374 void imcb_add_buddy( struct im_connection *ic, char *handle, char *group )
     385void imcb_add_buddy( struct im_connection *ic, const char *handle, const char *group )
    375386{
    376387        user_t *u;
     
    446457}
    447458
    448 void imcb_rename_buddy( struct im_connection *ic, char *handle, char *realname )
     459void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char *realname )
    449460{
    450461        user_t *u = user_findhandle( ic, handle );
     462        char *set;
    451463       
    452464        if( !u || !realname ) return;
     
    461473                        imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname );
    462474        }
    463 }
    464 
    465 void imcb_remove_buddy( struct im_connection *ic, char *handle, char *group )
     475       
     476        set = set_getstr( &ic->acc->set, "nick_source" );
     477        if( strcmp( set, "handle" ) != 0 )
     478        {
     479                char *name = g_strdup( realname );
     480               
     481                if( strcmp( set, "first_name" ) == 0 )
     482                {
     483                        int i;
     484                        for( i = 0; name[i] && !isspace( name[i] ); i ++ ) {}
     485                        name[i] = '\0';
     486                }
     487               
     488                imcb_buddy_nick_hint( ic, handle, name );
     489               
     490                g_free( name );
     491        }
     492}
     493
     494void imcb_remove_buddy( struct im_connection *ic, const char *handle, char *group )
    466495{
    467496        user_t *u;
     
    473502/* Mainly meant for ICQ (and now also for Jabber conferences) to allow IM
    474503   modules to suggest a nickname for a handle. */
    475 void imcb_buddy_nick_hint( struct im_connection *ic, char *handle, char *nick )
     504void imcb_buddy_nick_hint( struct im_connection *ic, const char *handle, const char *nick )
    476505{
    477506        user_t *u = user_findhandle( ic, handle );
     
    618647        oo = u->online;
    619648       
    620         if( u->away )
    621         {
    622                 g_free( u->away );
    623                 u->away = NULL;
    624         }
     649        g_free( u->away );
     650        g_free( u->status_msg );
     651        u->away = u->status_msg = NULL;
    625652       
    626653        if( ( flags & OPT_LOGGED_IN ) && !u->online )
     
    660687                }
    661688        }
    662         /* else waste_any_state_information_for_now(); */
     689        else
     690        {
     691                u->status_msg = g_strdup( message );
     692        }
    663693       
    664694        /* LISPy... */
     
    685715}
    686716
    687 void imcb_buddy_msg( struct im_connection *ic, char *handle, char *msg, uint32_t flags, time_t sent_at )
     717void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, uint32_t flags, time_t sent_at )
    688718{
    689719        irc_t *irc = ic->irc;
     
    818848}
    819849
    820 void imcb_chat_msg( struct groupchat *c, char *who, char *msg, uint32_t flags, time_t sent_at )
     850void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t flags, time_t sent_at )
    821851{
    822852        struct im_connection *ic = c->ic;
     
    890920/* buddy_chat.c */
    891921
    892 void imcb_chat_add_buddy( struct groupchat *b, char *handle )
     922void imcb_chat_add_buddy( struct groupchat *b, const char *handle )
    893923{
    894924        user_t *u = user_findhandle( b->ic, handle );
     
    925955
    926956/* This function is one BIG hack... :-( EREWRITE */
    927 void imcb_chat_remove_buddy( struct groupchat *b, char *handle, char *reason )
     957void imcb_chat_remove_buddy( struct groupchat *b, const char *handle, const char *reason )
    928958{
    929959        user_t *u;
     
    10701100}
    10711101
    1072 static char *imc_away_alias_find( GList *gcm, char *away );
    1073 
    1074 int imc_set_away( struct im_connection *ic, char *away )
    1075 {
    1076         GList *m, *ms;
    1077         char *s;
    1078        
    1079         if( !away ) away = "";
    1080         ms = m = ic->acc->prpl->away_states( ic );
    1081        
    1082         while( m )
    1083         {
    1084                 if( *away )
    1085                 {
    1086                         if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 )
    1087                                 break;
    1088                 }
    1089                 else
    1090                 {
    1091                         if( g_strcasecmp( m->data, "Available" ) == 0 )
    1092                                 break;
    1093                         if( g_strcasecmp( m->data, "Online" ) == 0 )
    1094                                 break;
    1095                 }
    1096                 m = m->next;
    1097         }
    1098        
    1099         if( m )
    1100         {
    1101                 ic->acc->prpl->set_away( ic, m->data, *away ? away : NULL );
    1102         }
    1103         else
    1104         {
    1105                 s = imc_away_alias_find( ms, away );
    1106                 if( s )
    1107                 {
    1108                         ic->acc->prpl->set_away( ic, s, away );
    1109                         if( set_getbool( &ic->irc->set, "debug" ) )
    1110                                 imcb_log( ic, "Setting away state to %s", s );
    1111                 }
    1112                 else
    1113                         ic->acc->prpl->set_away( ic, GAIM_AWAY_CUSTOM, away );
    1114         }
    1115        
    1116         return( 1 );
     1102static char *imc_away_state_find( GList *gcm, char *away, char **message );
     1103
     1104int imc_away_send_update( struct im_connection *ic )
     1105{
     1106        char *away, *msg = NULL;
     1107       
     1108        away = set_getstr( &ic->acc->set, "away" ) ?
     1109             : set_getstr( &ic->irc->set, "away" );
     1110        if( away && *away )
     1111        {
     1112                GList *m = ic->acc->prpl->away_states( ic );
     1113                msg = ic->acc->flags & ACC_FLAG_AWAY_MESSAGE ? away : NULL;
     1114                away = imc_away_state_find( m, away, &msg ) ? : m->data;
     1115        }
     1116        else if( ic->acc->flags & ACC_FLAG_STATUS_MESSAGE )
     1117        {
     1118                away = NULL;
     1119                msg = set_getstr( &ic->acc->set, "status" ) ?
     1120                    : set_getstr( &ic->irc->set, "status" );
     1121        }
     1122       
     1123        ic->acc->prpl->set_away( ic, away, msg );
     1124       
     1125        return 1;
    11171126}
    11181127
     
    11291138};
    11301139
    1131 static char *imc_away_alias_find( GList *gcm, char *away )
     1140static char *imc_away_state_find( GList *gcm, char *away, char **message )
    11321141{
    11331142        GList *m;
    11341143        int i, j;
    11351144       
     1145        for( m = gcm; m; m = m->next )
     1146                if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 )
     1147                {
     1148                        /* At least the Yahoo! module works better if message
     1149                           contains no data unless it adds something to what
     1150                           we have in state already. */
     1151                        if( strlen( m->data ) == strlen( away ) )
     1152                                *message = NULL;
     1153                       
     1154                        return m->data;
     1155                }
     1156       
    11361157        for( i = 0; *imc_away_alias_list[i]; i ++ )
    11371158        {
     1159                int keep_message;
     1160               
    11381161                for( j = 0; imc_away_alias_list[i][j]; j ++ )
    11391162                        if( g_strncasecmp( away, imc_away_alias_list[i][j], strlen( imc_away_alias_list[i][j] ) ) == 0 )
     1163                        {
     1164                                keep_message = strlen( away ) != strlen( imc_away_alias_list[i][j] );
    11401165                                break;
     1166                        }
    11411167               
    11421168                if( !imc_away_alias_list[i][j] )        /* If we reach the end, this row */
     
    11461172                for( j = 0; imc_away_alias_list[i][j]; j ++ )
    11471173                {
    1148                         m = gcm;
    1149                         while( m )
    1150                         {
     1174                        for( m = gcm; m; m = m->next )
    11511175                                if( g_strcasecmp( imc_away_alias_list[i][j], m->data ) == 0 )
    1152                                         return( imc_away_alias_list[i][j] );
    1153                                 m = m->next;
    1154                         }
    1155                 }
    1156         }
    1157        
    1158         return( NULL );
     1176                                {
     1177                                        if( !keep_message )
     1178                                                *message = NULL;
     1179                                       
     1180                                        return imc_away_alias_list[i][j];
     1181                                }
     1182                }
     1183               
     1184                /* No need to look further, apparently this state doesn't
     1185                   have any good alias for this protocol. */
     1186                break;
     1187        }
     1188       
     1189        return NULL;
    11591190}
    11601191
Note: See TracChangeset for help on using the changeset viewer.