Changeset f0cb961


Ignore:
Timestamp:
2007-04-19T06:03:43Z (17 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
d323394c
Parents:
33dc261
Message:

More API changes: buddy list management. imcb_add_buddy() is now a *real*
callback, it's only called from inside IM-modules. This makes sure a buddy
only gets added to the BitlBee structures if the add was successful. This
gets rid of the weirdness described in #55. Unfortunately for now this
change breaks A) automatic renaming of ICQ contacts (if there are names
stored in the contact list) B) add -tmp.

Files:
10 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/iq.c

    r33dc261 rf0cb961  
    360360        while( ( c = xt_find_node( c, "item" ) ) )
    361361        {
     362                struct xt_node *group = xt_find_node( node->children, "group" );
    362363                char *jid = xt_find_attr( c, "jid" );
    363364                char *name = xt_find_attr( c, "name" );
    364365                char *sub = xt_find_attr( c, "subscription" );
    365366               
    366                 if( !jid || !sub )
    367                 {
    368                         /* Maybe warn. But how likely is this to happen in the first place? */
    369                 }
    370                 else if( initial )
    371                 {
    372                         if( ( strcmp( sub, "both" ) == 0 || strcmp( sub, "to" ) == 0 ) )
    373                                 add_buddy( ic, NULL, jid, name );
    374                 }
    375                 else
    376                 {
    377                         /* This is a roster push item. Find out what changed exactly. */
     367                if( jid && sub )
     368                {
    378369                        if( ( strcmp( sub, "both" ) == 0 || strcmp( sub, "to" ) == 0 ) )
    379370                        {
    380                                 if( find_buddy( ic, jid ) == NULL )
    381                                         add_buddy( ic, NULL, jid, name );
    382                                 else if( name )
    383                                         serv_buddy_rename( ic, jid, name );
     371                                if( initial || imcb_find_buddy( ic, jid ) == NULL )
     372                                        imcb_add_buddy( ic, jid, ( group && group->text_len ) ?
     373                                                                   group->text : NULL );
     374                               
     375                                imcb_rename_buddy( ic, jid, name );
    384376                        }
    385377                        else if( strcmp( sub, "remove" ) == 0 )
  • protocols/jabber/jabber_util.c

    r33dc261 rf0cb961  
    223223        presence_send_request( bla->ic, bla->handle, "subscribed" );
    224224       
    225         if( find_buddy( bla->ic, bla->handle ) == NULL )
     225        if( imcb_find_buddy( bla->ic, bla->handle ) == NULL )
    226226                imcb_ask_add( bla->ic, bla->handle, NULL );
    227227       
     
    371371                }
    372372               
    373                 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && find_buddy( ic, jid ) )
     373                if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && imcb_find_buddy( ic, jid ) )
    374374                {
    375375                        *s = '/';
     
    391391                if( bud == NULL )
    392392                        /* No match. Create it now? */
    393                         return ( ( flags & GET_BUDDY_CREAT ) && find_buddy( ic, jid_ ) ) ?
     393                        return ( ( flags & GET_BUDDY_CREAT ) && imcb_find_buddy( ic, jid_ ) ) ?
    394394                                   jabber_buddy_add( ic, jid_ ) : NULL;
    395395                else if( bud->resource && ( flags & GET_BUDDY_EXACT ) )
  • protocols/msn/msn_util.c

    r33dc261 rf0cb961  
    9494        msn_buddy_list_add( bla->ic, "AL", bla->handle, bla->realname );
    9595       
    96         if( find_buddy( bla->ic, bla->handle ) == NULL )
     96        if( imcb_find_buddy( bla->ic, bla->handle ) == NULL )
    9797                imcb_ask_add( bla->ic, bla->handle, NULL );
    9898       
  • protocols/msn/ns.c

    r33dc261 rf0cb961  
    305305                        int num;
    306306                       
    307                         if( cmd[4] != NULL && sscanf( cmd[4], "%d", &num ) == 1 )
     307                        if( cmd[4] != NULL && sscanf( cmd[4], "%d", &num ) == 1 && num < md->groupcount )
    308308                                group = md->grouplist[num];
    309309                       
    310                         add_buddy( ic, group, cmd[1], cmd[2] );
     310                        imcb_add_buddy( ic, cmd[1], group );
     311                        imcb_rename_buddy( ic, cmd[1], cmd[2] );
    311312                }
    312313                if( list & 2 ) /* AL */
     
    391392               
    392393                http_decode( cmd[4] );
    393                 serv_buddy_rename( ic, cmd[3], cmd[4] );
     394                imcb_rename_buddy( ic, cmd[3], cmd[4] );
    394395               
    395396                st = msn_away_state_by_code( cmd[2] );
     
    420421               
    421422                http_decode( cmd[3] );
    422                 serv_buddy_rename( ic, cmd[2], cmd[3] );
     423                imcb_rename_buddy( ic, cmd[2], cmd[3] );
    423424               
    424425                st = msn_away_state_by_code( cmd[1] );
     
    482483                                imcb_error( ic, "Syntax error" );
    483484                                imc_logout( ic, TRUE );
    484                                 return( 0 );
    485                         }
    486                        
    487                         /* We got added by someone. If we don't have this person in permit/deny yet, inform the user. */
     485                                return 0;
     486                        }
     487                       
     488                        /* We got added by someone. If we don't have this
     489                           person in permit/deny yet, inform the user. */
    488490                        for( l = ic->permit; l; l = l->next )
    489491                                if( g_strcasecmp( l->data, cmd[4] ) == 0 )
    490                                         return( 1 );
     492                                        return 1;
    491493                       
    492494                        for( l = ic->deny; l; l = l->next )
    493495                                if( g_strcasecmp( l->data, cmd[4] ) == 0 )
    494                                         return( 1 );
     496                                        return 1;
    495497                       
    496498                        msn_buddy_ask( ic, cmd[4], cmd[5] );
     499                }
     500                else if( num_parts >= 6 && strcmp( cmd[2], "FL" ) == 0 )
     501                {
     502                        http_decode( cmd[5] );
     503                        imcb_add_buddy( ic, cmd[4], NULL );
     504                        imcb_rename_buddy( ic, cmd[4], cmd[5] );
    497505                }
    498506        }
     
    545553                        /* This is not supposed to happen, but let's handle it anyway... */
    546554                        http_decode( cmd[4] );
    547                         serv_buddy_rename( ic, cmd[3], cmd[4] );
     555                        imcb_rename_buddy( ic, cmd[3], cmd[4] );
    548556                }
    549557        }
  • protocols/nogaim.c

    r33dc261 rf0cb961  
    352352/* list.c */
    353353
    354 void add_buddy( struct im_connection *ic, char *group, char *handle, char *realname )
     354void imcb_add_buddy( struct im_connection *ic, char *handle, char *group )
    355355{
    356356        user_t *u;
    357         char nick[MAX_NICK_LENGTH+1];
    358         char *s;
     357        char nick[MAX_NICK_LENGTH+1], *s;
    359358        irc_t *irc = ic->irc;
    360        
    361         if( set_getbool( &irc->set, "debug" ) && 0 ) /* This message is too useless */
    362                 imcb_log( ic, "Receiving user add from handle: %s", handle );
    363359       
    364360        if( user_findhandle( ic, handle ) )
     
    369365                return;
    370366               
    371                 /* Buddy seems to exist already. Let's ignore this request then... */
     367                /* Buddy seems to exist already. Let's ignore this request then...
     368                   Eventually subsequent calls to this function *should* be possible
     369                   when a buddy is in multiple groups. But for now BitlBee doesn't
     370                   even support groups so let's silently ignore this for now. */
    372371        }
    373372       
    374373        memset( nick, 0, MAX_NICK_LENGTH + 1 );
    375         strcpy( nick, nick_get( ic->acc, handle, realname ) );
     374        strcpy( nick, nick_get( ic->acc, handle, NULL ) );
    376375       
    377376        u = user_add( ic->irc, nick );
    378377       
    379         if( !realname || !*realname ) realname = nick;
    380         u->realname = g_strdup( realname );
     378//      if( !realname || !*realname ) realname = nick;
     379//      u->realname = g_strdup( realname );
    381380       
    382381        if( ( s = strchr( handle, '@' ) ) )
     
    387386        else if( ic->acc->server )
    388387        {
    389                 char *colon;
    390                
    391                 if( ( colon = strchr( ic->acc->server, ':' ) ) )
    392                         u->host = g_strndup( ic->acc->server,
    393                                              colon - ic->acc->server );
    394                 else
    395                         u->host = g_strdup( ic->acc->server );
    396                
     388                u->host = g_strdup( ic->acc->server );
    397389                u->user = g_strdup( handle );
    398390               
     
    415407}
    416408
    417 struct buddy *find_buddy( struct im_connection *ic, char *handle )
     409struct buddy *imcb_find_buddy( struct im_connection *ic, char *handle )
    418410{
    419411        static struct buddy b[1];
     
    435427
    436428
    437 void serv_buddy_rename( struct im_connection *ic, char *handle, char *realname )
     429void imcb_rename_buddy( struct im_connection *ic, char *handle, char *realname )
    438430{
    439431        user_t *u = user_findhandle( ic, handle );
    440432       
    441         if( !u ) return;
     433        if( !u || !realname ) return;
    442434       
    443435        if( g_strcasecmp( u->realname, realname ) != 0 )
     
    470462{
    471463        data->ic->acc->prpl->add_buddy( data->ic, data->handle, NULL );
    472         add_buddy( data->ic, NULL, data->handle, data->handle );
     464        /* imcb_add_buddy( data->ic, NULL, data->handle, data->handle ); */
    473465       
    474466        return show_got_added_no( w, data );
     
    505497                if( g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "add" ) == 0 )
    506498                {
    507                         add_buddy( ic, NULL, (char*) handle, NULL );
     499                        imcb_add_buddy( ic, (char*) handle, NULL );
    508500                        u = user_findhandle( ic, (char*) handle );
    509501                }
     
    609601                        }
    610602                       
    611                         add_buddy( ic, NULL, handle, NULL );
     603                        imcb_add_buddy( ic, handle, NULL );
    612604                        u = user_findhandle( ic, handle );
    613605                        u->is_private = private;
     
    779771        if( !u )
    780772        {
    781                 add_buddy( b->ic, NULL, handle, NULL );
     773                imcb_add_buddy( b->ic, handle, NULL );
    782774                u = user_findhandle( b->ic, handle );
    783775        }
  • protocols/nogaim.h

    r33dc261 rf0cb961  
    201201
    202202/* Buddy management */
    203 G_MODULE_EXPORT void add_buddy( struct im_connection *ic, char *group, char *handle, char *realname );
    204 G_MODULE_EXPORT struct buddy *find_buddy( struct im_connection *ic, char *handle );
    205 G_MODULE_EXPORT void serv_buddy_rename( struct im_connection *ic, char *handle, char *realname );
     203G_MODULE_EXPORT void imcb_add_buddy( struct im_connection *ic, char *handle, char *group );
     204G_MODULE_EXPORT void imcb_remove_buddy( struct im_connection *ic, char *handle, char *group );
     205G_MODULE_EXPORT struct buddy *imcb_find_buddy( struct im_connection *ic, char *handle );
     206G_MODULE_EXPORT void imcb_rename_buddy( struct im_connection *ic, char *handle, char *realname );
    206207
    207208/* Buddy activity */
  • protocols/oscar/oscar.c

    r33dc261 rf0cb961  
    11191119        aim_ssi_auth_reply(od->sess, od->conn, uin, 1, "");
    11201120        // aim_send_im_ch4(od->sess, uin, AIM_ICQMSG_AUTHGRANTED, &message);
    1121         if(find_buddy(data->ic, uin) == NULL)
     1121        if(imcb_find_buddy(data->ic, uin) == NULL)
    11221122                imcb_ask_add(data->ic, uin, NULL);
    11231123       
     
    18751875        struct oscar_data *odata = (struct oscar_data *)g->proto_data;
    18761876        if (odata->icq) {
    1877                 struct buddy *budlight = find_buddy(g, who);
     1877                struct buddy *budlight = imcb_find_buddy(g, who);
    18781878                if (budlight)
    18791879                        if ((budlight->uc & 0xff80) >> 7)
     
    20132013                switch (curitem->type) {
    20142014                        case 0x0000: /* Buddy */
    2015                                 if ((curitem->name) && (!find_buddy(ic, curitem->name))) {
     2015                                if ((curitem->name) && (!imcb_find_buddy(ic, curitem->name))) {
    20162016                                        char *realname = NULL;
    20172017
     
    20192019                                                    realname = aim_gettlv_str(curitem->data, 0x0131, 1);
    20202020                                               
    2021                                         add_buddy(ic, NULL, curitem->name, realname);
     2021                                        imcb_add_buddy(ic, curitem->name, NULL);
    20222022                                       
    2023                                         if (realname)
    2024                                             g_free(realname);
     2023                                        if (realname) {
     2024                                                imcb_rename_buddy(ic, curitem->name, realname);
     2025                                                g_free(realname);
     2026                                        }
    20252027                                }
    20262028                                break;
     
    21052107                {
    21062108                        st = aimbs_get16( &fr->data );
    2107                         if( st == 0x0E )
     2109                        if( st == 0x00 )
     2110                        {
     2111                                imcb_add_buddy( sess->aux_data, list, NULL );
     2112                        }
     2113                        else if( st == 0x0E )
    21082114                        {
    21092115                                imcb_log( sess->aux_data, "Buddy %s can't be added without authorization, requesting authorization", list );
     
    21112117                                aim_ssi_auth_request( sess, fr->conn, list, "" );
    21122118                                aim_ssi_addbuddies( sess, fr->conn, OSCAR_GROUP, &list, 1, 1 );
     2119                        }
     2120                        else
     2121                        {
     2122                                imcb_error( sess->aux_data, "Error while adding buddy: 0x%04x", st );
    21132123                        }
    21142124                        list += strlen( list ) + 1;
  • protocols/yahoo/libyahoo2.c

    r33dc261 rf0cb961  
    24032403                where = "Unknown";
    24042404
    2405         bud = y_new0(struct yahoo_buddy, 1);
    2406         bud->id = strdup(who);
    2407         bud->group = strdup(where);
    2408         bud->real_name = NULL;
    2409 
    2410         yd->buddies = y_list_append(yd->buddies, bud);
     2405        /* status: 0 == Successful, 1 == Error (does not exist), 2 == Already in list */
     2406        if( status == 0 ) {
     2407                bud = y_new0(struct yahoo_buddy, 1);
     2408                bud->id = strdup(who);
     2409                bud->group = strdup(where);
     2410                bud->real_name = NULL;
     2411               
     2412                yd->buddies = y_list_append(yd->buddies, bud);
     2413               
     2414                /* Possibly called already, but at least the call above doesn't
     2415                   seem to happen every time (not anytime I tried). */
     2416                YAHOO_CALLBACK(ext_yahoo_contact_added)(yd->client_id, me, who, NULL);
     2417        }
    24112418
    24122419/*      YAHOO_CALLBACK(ext_yahoo_status_changed)(yd->client_id, who, status, NULL, (status==YAHOO_STATUS_AVAILABLE?0:1)); */
  • protocols/yahoo/yahoo.c

    r33dc261 rf0cb961  
    532532                }
    533533               
    534                 add_buddy( ic, b->group, b->id, b->real_name );
     534                imcb_add_buddy( ic, b->id, b->group );
     535                imcb_rename_buddy( ic, b->id, b->real_name );
     536               
    535537                bl = bl->next;
    536538        }
     
    904906void ext_yahoo_contact_added( int id, const char *myid, const char *who, const char *msg )
    905907{
     908        /* Groups schmoups. If I want to handle groups properly I can get the
     909           buddy data from some internal libyahoo2 structure. */
     910        imcb_add_buddy( byahoo_get_ic_by_id( id ), (char*) who, NULL );
    906911}
    907912
  • root_commands.c

    r33dc261 rf0cb961  
    437437{
    438438        account_t *a;
    439         int add_for_real = 1;
     439        int add_on_server = 1;
    440440       
    441441        if( g_strcasecmp( cmd[1], "-tmp" ) == 0 )
    442442        {
    443                 add_for_real = 0;
     443                add_on_server = 0;
    444444                cmd ++;         /* So evil... :-D */
    445445        }
     
    476476        /* By making this optional, you can talk to people without having to
    477477           add them to your *real* (server-side) contact list. */
    478         if( add_for_real )
     478        if( add_on_server )
    479479                a->ic->acc->prpl->add_buddy( a->ic, cmd[2], NULL );
    480                
    481         add_buddy( a->ic, NULL, cmd[2], cmd[2] );
    482        
    483         irc_usermsg( irc, "User `%s' added to your contact list as `%s'", cmd[2], user_findhandle( a->ic, cmd[2] )->nick );
     480       
     481        /* add_buddy( a->ic, NULL, cmd[2], cmd[2] ); */
     482       
     483        irc_usermsg( irc, "Adding `%s' to your contact list", cmd[2] );
    484484}
    485485
Note: See TracChangeset for help on using the changeset viewer.