Changeset 5a7af1b


Ignore:
Timestamp:
2010-08-15T13:02:52Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
660cb00
Parents:
ff27648
Message:

The ADL command doesn't support >150 contacts. Split it up.

Location:
protocols/msn
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/msn.h

    rff27648 r5a7af1b  
    9494        const struct msn_away_state *away_state;
    9595        GSList *groups;
     96       
     97        /* Mostly used for sending the ADL command; since MSNP13 the client
     98           is responsible for downloading the contact list and then sending
     99           it to the MSNP server. */
    96100        GTree *domaintree;
     101        int adl_todo;
    97102};
    98103
     
    164169        MSN_BUDDY_RL = 8,
    165170        MSN_BUDDY_PL = 16,
     171        MSN_BUDDY_ADL_SYNCED = 256,
    166172} msn_buddy_flags_t;
    167173
  • protocols/msn/ns.c

    rff27648 r5a7af1b  
    3535static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts );
    3636
     37static void msn_ns_send_adl_start( struct im_connection *ic );
    3738static void msn_ns_send_adl( struct im_connection *ic );
    3839
     
    257258        else if( strcmp( cmd[0], "BLP" ) == 0 )
    258259        {
    259                 msn_ns_send_adl( ic );
     260                msn_ns_send_adl_start( ic );
    260261        }
    261262        else if( strcmp( cmd[0], "ADL" ) == 0 )
     
    263264                if( num_parts >= 3 && strcmp( cmd[2], "OK" ) == 0 )
    264265                {
    265                         char buf[1024];
    266                         char *fn_raw;
    267                         char *fn;
    268                        
    269                         if( ic->flags & OPT_LOGGED_IN )
    270                                 return 1;
    271                        
    272                         if( ( fn_raw = set_getstr( &ic->acc->set, "display_name" ) ) == NULL )
    273                                 fn_raw = ic->acc->user;
    274                         fn = g_malloc( strlen( fn_raw ) * 3 + 1 );
    275                         strcpy( fn, fn_raw );
    276                         http_encode( fn );
    277                        
    278                         g_snprintf( buf, sizeof( buf ), "PRP %d MFN %s\r\n",
    279                                     ++md->trId, fn );
    280                         g_free( fn );
    281                        
    282                         msn_write( ic, buf, strlen( buf ) );
     266                        msn_ns_send_adl( ic );
     267                       
     268                        if( md->adl_todo < 0 && !( ic->flags & OPT_LOGGED_IN ) )
     269                        {
     270                                char buf[1024];
     271                                char *fn_raw;
     272                                char *fn;
     273                               
     274                                if( ( fn_raw = set_getstr( &ic->acc->set, "display_name" ) ) == NULL )
     275                                        fn_raw = ic->acc->user;
     276                                fn = g_malloc( strlen( fn_raw ) * 3 + 1 );
     277                                strcpy( fn, fn_raw );
     278                                http_encode( fn );
     279                               
     280                                g_snprintf( buf, sizeof( buf ), "PRP %d MFN %s\r\n",
     281                                            ++md->trId, fn );
     282                                g_free( fn );
     283                               
     284                                msn_write( ic, buf, strlen( buf ) );
     285                        }
    283286                }
    284287                else if( num_parts >= 3 )
     
    733736        struct bee_user *bu = value;
    734737        struct msn_buddy_data *bd = bu->data;
     738        struct msn_data *md = bu->ic->proto_data;
    735739        char handle[strlen(bu->handle)];
    736740        char *domain;
    737741        char l[4];
    738742       
    739         if( ( bd->flags & 7 ) == 0 )
     743        if( ( bd->flags & 7 ) == 0 || ( bd->flags & MSN_BUDDY_ADL_SYNCED ) )
    740744                return FALSE;
    741745       
     
    761765        xt_insert_child( d, c );
    762766       
    763         return FALSE;
     767        /* Do this in batches of 100. */
     768        bd->flags |= MSN_BUDDY_ADL_SYNCED;
     769        return (--md->adl_todo % 140) == 0;
    764770}
    765771
     
    767773{
    768774        struct xt_node *adl;
     775        struct msn_data *md = ic->proto_data;
     776        char *adls, buf[64];
     777       
     778        adl = xt_new_node( "ml", NULL, NULL );
     779        xt_add_attr( adl, "l", "1" );
     780        g_tree_foreach( md->domaintree, msn_ns_send_adl_1, adl );
     781        if( adl->children == NULL )
     782        {
     783                /* This tells the caller that we're done now. */
     784                md->adl_todo = -1;
     785                xt_free_node( adl );
     786                return;
     787        }
     788        adls = xt_to_string( adl );
     789       
     790        g_snprintf( buf, sizeof( buf ), "ADL %d %zd\r\n", ++md->trId, strlen( adls ) );
     791        if( msn_write( ic, buf, strlen( buf ) ) )
     792                msn_write( ic, adls, strlen( adls ) );
     793       
     794        g_free( adls );
     795}
     796
     797static void msn_ns_send_adl_start( struct im_connection *ic )
     798{
    769799        struct msn_data *md;
    770         char *adls, buf[64];
     800        GSList *l;
    771801       
    772802        /* Dead connection? */
     
    775805       
    776806        md = ic->proto_data;
    777        
    778         adl = xt_new_node( "ml", NULL, NULL );
    779         xt_add_attr( adl, "l", "1" );
    780         g_tree_foreach( md->domaintree, msn_ns_send_adl_1, adl );
    781         adls = xt_to_string( adl );
    782        
    783         g_snprintf( buf, sizeof( buf ), "ADL %d %zd\r\n", ++md->trId, strlen( adls ) );
    784         if( msn_write( ic, buf, strlen( buf ) ) )
    785                 msn_write( ic, adls, strlen( adls ) );
    786        
    787         g_free( adls );
    788         xt_free_node( adl );
     807        md->adl_todo = 0;
     808        for( l = ic->bee->users; l; l = l->next )
     809        {
     810                bee_user_t *bu = l->data;
     811                struct msn_buddy_data *bd = bu->data;
     812               
     813                if( bu->ic != ic || ( bd->flags & 7 ) == 0 )
     814                        continue;
     815               
     816                bd->flags &= ~MSN_BUDDY_ADL_SYNCED;
     817                md->adl_todo++;
     818        }
     819       
     820        msn_ns_send_adl( ic );
    789821}
Note: See TracChangeset for help on using the changeset viewer.