Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/sb.c

    r1c3008a rf8cb76d  
    2929#include "passport.h"
    3030#include "md5.h"
    31 #include "invitation.h"
    3231
    3332static gboolean msn_sb_callback( gpointer data, gint source, b_input_condition cond );
     
    175174                        i = g_snprintf( buf, i, MSN_TYPING_HEADERS, sb->ic->acc->user );
    176175                }
    177                 else if( strncmp( text, MSN_INVITE_HEADERS, sizeof( MSN_INVITE_HEADERS ) - 1 ) == 0 )
    178                 {
    179                         buf = g_strdup( text );
     176                else if( strcmp( text, SB_KEEPALIVE_MESSAGE ) == 0 )
     177                {
     178                        buf = g_strdup( SB_KEEPALIVE_HEADERS );
    180179                        i = strlen( buf );
    181180                }
     
    256255       
    257256        msn_msgq_purge( ic, &sb->msgq );
     257        msn_sb_stop_keepalives( sb );
    258258       
    259259        if( sb->key ) g_free( sb->key );
     
    328328        struct msn_data *md = ic->proto_data;
    329329       
    330         if( msn_handler( sb->handler ) == -1 )
     330        if( msn_handler( sb->handler ) != -1 )
     331                return TRUE;
     332       
     333        if( sb->msgq != NULL )
    331334        {
    332335                time_t now = time( NULL );
     336                char buf[1024];
    333337               
    334338                if( now - md->first_sb_failure > 600 )
     
    347351                                      "There might be problems delivering your messages." );
    348352               
    349                 if( sb->msgq != NULL )
    350                 {
    351                         char buf[1024];
    352                        
    353                         if( md->msgq == NULL )
    354                         {
    355                                 md->msgq = sb->msgq;
    356                         }
    357                         else
    358                         {
    359                                 GSList *l;
    360                                
    361                                 for( l = md->msgq; l->next; l = l->next );
    362                                 l->next = sb->msgq;
    363                         }
    364                         sb->msgq = NULL;
    365                        
    366                         debug( "Moved queued messages back to the main queue, creating a new switchboard to retry." );
    367                         g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
    368                         if( !msn_write( ic, buf, strlen( buf ) ) )
    369                                 return FALSE;
    370                 }
    371                
    372                 msn_sb_destroy( sb );
    373                
    374                 return FALSE;
    375         }
    376         else
    377         {
    378                 return TRUE;
    379         }
     353                if( md->msgq == NULL )
     354                {
     355                        md->msgq = sb->msgq;
     356                }
     357                else
     358                {
     359                        GSList *l;
     360                       
     361                        for( l = md->msgq; l->next; l = l->next );
     362                        l->next = sb->msgq;
     363                }
     364                sb->msgq = NULL;
     365               
     366                debug( "Moved queued messages back to the main queue, "
     367                       "creating a new switchboard to retry." );
     368                g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
     369                if( !msn_write( ic, buf, strlen( buf ) ) )
     370                        return FALSE;
     371        }
     372       
     373        msn_sb_destroy( sb );
     374        return FALSE;
    380375}
    381376
     
    477472               
    478473                sb->ready = 1;
     474               
     475                msn_sb_start_keepalives( sb, FALSE );
    479476        }
    480477        else if( strcmp( cmd[0], "CAL" ) == 0 )
     
    526523                        }
    527524                       
     525                        msn_sb_start_keepalives( sb, FALSE );
     526                       
    528527                        return( st );
    529528                }
     
    587586                if( sb->who )
    588587                {
     588                        msn_sb_stop_keepalives( sb );
     589                       
    589590                        /* This is a single-person chat, and the other person is leaving. */
    590591                        g_free( sb->who );
     
    693694                else if( g_strncasecmp( ct, "text/x-msmsgsinvite", 19 ) == 0 )
    694695                {
    695                         char *command = msn_findheader( body, "Invitation-Command:", blen );
    696                         char *cookie = msn_findheader( body, "Invitation-Cookie:", blen );
    697                         unsigned int icookie;
     696                        char *itype = msn_findheader( body, "Application-GUID:", blen );
     697                        char buf[1024];
    698698                       
    699699                        g_free( ct );
    700700                       
    701                         /* Every invite should have both a Command and Cookie header */
    702                         if( !command || !cookie ) {
    703                                 g_free( command );
    704                                 g_free( cookie );
    705                                 imcb_log( ic, "Warning: No command or cookie from %s", sb->who );
    706                                 return 1;
    707                         }
    708                        
    709                         icookie = strtoul( cookie, NULL, 10 );
    710                         g_free( cookie );
    711                        
    712                         if( g_strncasecmp( command, "INVITE", 6 ) == 0 ) {
    713                                 msn_invitation_invite( sb, cmd[1], icookie, body, blen );
    714                         } else if( g_strncasecmp( command, "ACCEPT", 6 ) == 0 ) {
    715                                 msn_invitation_accept( sb, cmd[1], icookie, body, blen );
    716                         } else if( g_strncasecmp( command, "CANCEL", 6 ) == 0 ) {
    717                                 msn_invitation_cancel( sb, cmd[1], icookie, body, blen );
    718                         } else {
    719                                 imcb_log( ic, "Warning: Received invalid invitation with "
    720                                                 "command %s from %s", command, sb->who );
    721                         }
    722                        
    723                         g_free( command );
    724                 }
    725                 else if( g_strncasecmp( ct, "application/x-msnmsgrp2p", 24 ) == 0 )
    726                 {
    727                         imcb_error( sb->ic, "Cannot receive file from %s: BitlBee does not "
    728                                         "support msnmsgrp2p yet.", sb->who );
    729                         g_free( ct );
     701                        *buf = 0;
     702                       
     703                        if( !itype )
     704                                return( 1 );
     705                       
     706                        /* File transfer. */
     707                        if( strcmp( itype, "{5D3E02AB-6190-11d3-BBBB-00C04F795683}" ) == 0 )
     708                        {
     709                                char *name = msn_findheader( body, "Application-File:", blen );
     710                                char *size = msn_findheader( body, "Application-FileSize:", blen );
     711                               
     712                                if( name && size )
     713                                {
     714                                        g_snprintf( buf, sizeof( buf ), "<< \x02""BitlBee\x02"" - Filetransfer: `%s', %s bytes >>\n"
     715                                                    "Filetransfers are not supported by BitlBee for now...", name, size );
     716                                }
     717                                else
     718                                {
     719                                        strcpy( buf, "<< \x02""BitlBee\x02"" - Corrupted MSN filetransfer invitation message >>" );
     720                                }
     721                               
     722                                if( name ) g_free( name );
     723                                if( size ) g_free( size );
     724                        }
     725                        else
     726                        {
     727                                char *iname = msn_findheader( body, "Application-Name:", blen );
     728                               
     729                                g_snprintf( buf, sizeof( buf ), "<< \x02""BitlBee\x02"" - Unknown MSN invitation - %s (%s) >>",
     730                                                                itype, iname ? iname : "no name" );
     731                               
     732                                if( iname ) g_free( iname );
     733                        }
     734                       
     735                        g_free( itype );
     736                       
     737                        if( !*buf )
     738                                return( 1 );
     739                       
     740                        if( sb->who )
     741                        {
     742                                imcb_buddy_msg( ic, cmd[1], buf, 0, 0 );
     743                        }
     744                        else if( sb->chat )
     745                        {
     746                                imcb_chat_msg( sb->chat, cmd[1], buf, 0, 0 );
     747                        }
     748                        else
     749                        {
     750                                /* PANIC! */
     751                        }
    730752                }
    731753                else if( g_strncasecmp( ct, "text/x-msmsgscontrol", 20 ) == 0 )
     
    749771        return( 1 );
    750772}
     773
     774static gboolean msn_sb_keepalive( gpointer data, gint source, b_input_condition cond )
     775{
     776        struct msn_switchboard *sb = data;
     777        return sb->ready && msn_sb_sendmessage( sb, SB_KEEPALIVE_MESSAGE );
     778}
     779
     780void msn_sb_start_keepalives( struct msn_switchboard *sb, gboolean initial )
     781{
     782        struct buddy *b;
     783       
     784        if( sb && sb->who && sb->keepalive == 0 &&
     785            ( b = imcb_find_buddy( sb->ic, sb->who ) ) && !b->present &&
     786            set_getbool( &sb->ic->acc->set, "switchboard_keepalives" ) )
     787        {
     788                if( initial )
     789                        msn_sb_keepalive( sb, 0, 0 );
     790               
     791                sb->keepalive = b_timeout_add( 20000, msn_sb_keepalive, sb );
     792        }
     793}
     794
     795void msn_sb_stop_keepalives( struct msn_switchboard *sb )
     796{
     797        if( sb && sb->keepalive > 0 )
     798        {
     799                b_event_remove( sb->keepalive );
     800                sb->keepalive = 0;
     801        }
     802}
Note: See TracChangeset for help on using the changeset viewer.