Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/sb.c

    re35d1a1 r8ff0a61  
    128128                if( strcmp( text, TYPING_NOTIFICATION_MESSAGE ) != 0 )
    129129                {
    130                         buf = g_new0( char, sizeof( MSN_MESSAGE_HEADERS ) + strlen( text ) * 2 );
     130                        buf = g_new0( char, sizeof( MSN_MESSAGE_HEADERS ) + strlen( text ) * 2 + 1 );
    131131                        i = strlen( MSN_MESSAGE_HEADERS );
    132132                       
     
    207207        debug( "Destroying switchboard: %s", sb->who ? sb->who : sb->key ? sb->key : "" );
    208208       
    209         if( sb->msgq )
    210         {
    211                 struct msn_message *m;
    212                 GSList *l;
    213                
    214                 for( l = sb->msgq; l; l = l->next )
    215                 {
    216                         m = l->data;
    217 
    218                         g_free( m->who );
    219                         g_free( m->text );
    220                         g_free( m );
    221                 }
    222                 g_slist_free( sb->msgq );
    223                
    224                 imcb_log( ic, "Warning: Closing down MSN switchboard connection with "
    225                                    "unsent message to %s, you'll have to resend it.",
    226                                    sb->who ? sb->who : "(unknown)" );
    227         }
     209        msn_msgq_purge( ic, &sb->msgq );
    228210       
    229211        if( sb->key ) g_free( sb->key );
     
    266248        if( source != sb->fd )
    267249        {
    268                 debug( "ERROR %d while connecting to switchboard server", 1 );
     250                debug( "Error %d while connecting to switchboard server", 1 );
    269251                msn_sb_destroy( sb );
    270252                return FALSE;
     
    287269                sb->inp = b_input_add( sb->fd, GAIM_INPUT_READ, msn_sb_callback, sb );
    288270        else
    289                 debug( "ERROR %d while connecting to switchboard server", 2 );
     271                debug( "Error %d while connecting to switchboard server", 2 );
    290272       
    291273        return FALSE;
     
    295277{
    296278        struct msn_switchboard *sb = data;
     279        struct im_connection *ic = sb->ic;
     280        struct msn_data *md = ic->proto_data;
    297281       
    298282        if( msn_handler( sb->handler ) == -1 )
    299283        {
    300                 debug( "ERROR: Switchboard died" );
     284                time_t now = time( NULL );
     285               
     286                if( now - md->first_sb_failure > 600 )
     287                {
     288                        /* It's not really the first one, but the start of this "series".
     289                           With this, the warning below will be shown only if this happens
     290                           at least three times in ten minutes. This algorithm isn't
     291                           perfect, but for this purpose it will do. */
     292                        md->first_sb_failure = now;
     293                        md->sb_failures = 0;
     294                }
     295               
     296                debug( "Error: Switchboard died" );
     297                if( ++ md->sb_failures >= 3 )
     298                        imcb_log( ic, "Warning: Many switchboard failures on MSN connection. "
     299                                      "There might be problems delivering your messages." );
     300               
     301                if( sb->msgq != NULL )
     302                {
     303                        char buf[1024];
     304                       
     305                        if( md->msgq == NULL )
     306                        {
     307                                md->msgq = sb->msgq;
     308                        }
     309                        else
     310                        {
     311                                GSList *l;
     312                               
     313                                for( l = md->msgq; l->next; l = l->next );
     314                                l->next = sb->msgq;
     315                        }
     316                        sb->msgq = NULL;
     317                       
     318                        debug( "Moved queued messages back to the main queue, creating a new switchboard to retry." );
     319                        g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
     320                        if( !msn_write( ic, buf, strlen( buf ) ) )
     321                                return FALSE;
     322                }
     323               
    301324                msn_sb_destroy( sb );
    302325               
     
    304327        }
    305328        else
     329        {
    306330                return TRUE;
     331        }
    307332}
    308333
     
    491516                }
    492517        }
     518        else if( strcmp( cmd[0], "NAK" ) == 0 )
     519        {
     520                if( sb->who )
     521                {
     522                        imcb_log( ic, "The MSN servers could not deliver one of your messages to %s.", sb->who );
     523                }
     524                else
     525                {
     526                        imcb_log( ic, "The MSN servers could not deliver one of your groupchat messages to all participants." );
     527                }
     528        }
    493529        else if( strcmp( cmd[0], "BYE" ) == 0 )
    494530        {
     
    544580                        if( sb->who )
    545581                        {
    546                                 struct msn_message *m;
    547                                 GSList *l;
    548                                
    549582                                /* Apparently some invitation failed. We might want to use this
    550583                                   board later, so keep it as a spare. */
     
    553586                               
    554587                                /* Also clear the msgq, otherwise someone else might get them. */
    555                                 for( l = sb->msgq; l; l = l->next )
    556                                 {
    557                                         m = l->data;
    558                                         g_free( m->who );
    559                                         g_free( m->text );
    560                                         g_free( m );
    561                                 }
    562                                 g_slist_free( sb->msgq );
    563                                 sb->msgq = NULL;
     588                                msn_msgq_purge( ic, &sb->msgq );
    564589                        }
    565590                       
     
    569594        else
    570595        {
    571                 debug( "Received unknown command from switchboard server: %s", cmd[0] );
     596                /* debug( "Received unknown command from switchboard server: %s", cmd[0] ); */
    572597        }
    573598       
Note: See TracChangeset for help on using the changeset viewer.