Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/sb.c

    rf8cb76d re5abfd4  
    2929#include "passport.h"
    3030#include "md5.h"
     31#include "invitation.h"
    3132
    3233static gboolean msn_sb_callback( gpointer data, gint source, b_input_condition cond );
     
    177178                {
    178179                        buf = g_strdup( SB_KEEPALIVE_HEADERS );
     180                        i = strlen( buf );
     181                }
     182                else if( strncmp( text, MSN_INVITE_HEADERS, sizeof( MSN_INVITE_HEADERS ) - 1 ) == 0 )
     183                {
     184                        buf = g_strdup( text );
    179185                        i = strlen( buf );
    180186                }
     
    227233{
    228234        struct im_connection *ic = sb->ic;
     235        struct groupchat *c = NULL;
    229236        char buf[1024];
    230237       
    231238        /* Create the groupchat structure. */
    232239        g_snprintf( buf, sizeof( buf ), "MSN groupchat session %d", sb->session );
    233         sb->chat = imcb_chat_new( ic, buf );
     240        if( sb->who )
     241                c = bee_chat_by_title( ic->bee, ic, sb->who );
     242        if( c && !msn_sb_by_chat( c ) )
     243                sb->chat = c;
     244        else
     245                sb->chat = imcb_chat_new( ic, buf );
    234246       
    235247        /* Populate the channel. */
     
    328340        struct msn_data *md = ic->proto_data;
    329341       
    330         if( msn_handler( sb->handler ) != -1 )
    331                 return TRUE;
    332        
    333         if( sb->msgq != NULL )
     342        if( msn_handler( sb->handler ) == -1 )
    334343        {
    335344                time_t now = time( NULL );
    336                 char buf[1024];
    337345               
    338346                if( now - md->first_sb_failure > 600 )
     
    351359                                      "There might be problems delivering your messages." );
    352360               
    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;
     361                if( sb->msgq != NULL )
     362                {
     363                        char buf[1024];
     364                       
     365                        if( md->msgq == NULL )
     366                        {
     367                                md->msgq = sb->msgq;
     368                        }
     369                        else
     370                        {
     371                                GSList *l;
     372                               
     373                                for( l = md->msgq; l->next; l = l->next );
     374                                l->next = sb->msgq;
     375                        }
     376                        sb->msgq = NULL;
     377                       
     378                        debug( "Moved queued messages back to the main queue, creating a new switchboard to retry." );
     379                        g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
     380                        if( !msn_write( ic, buf, strlen( buf ) ) )
     381                                return FALSE;
     382                }
     383               
     384                msn_sb_destroy( sb );
     385               
     386                return FALSE;
     387        }
     388        else
     389        {
     390                return TRUE;
     391        }
    375392}
    376393
     
    692709                        }
    693710                }
     711#if 0
     712                // Disable MSN ft support for now.
    694713                else if( g_strncasecmp( ct, "text/x-msmsgsinvite", 19 ) == 0 )
    695714                {
    696                         char *itype = msn_findheader( body, "Application-GUID:", blen );
    697                         char buf[1024];
     715                        char *command = msn_findheader( body, "Invitation-Command:", blen );
     716                        char *cookie = msn_findheader( body, "Invitation-Cookie:", blen );
     717                        unsigned int icookie;
    698718                       
    699719                        g_free( ct );
    700720                       
    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                         }
     721                        /* Every invite should have both a Command and Cookie header */
     722                        if( !command || !cookie ) {
     723                                g_free( command );
     724                                g_free( cookie );
     725                                imcb_log( ic, "Warning: No command or cookie from %s", sb->who );
     726                                return 1;
     727                        }
     728                       
     729                        icookie = strtoul( cookie, NULL, 10 );
     730                        g_free( cookie );
     731                       
     732                        if( g_strncasecmp( command, "INVITE", 6 ) == 0 ) {
     733                                msn_invitation_invite( sb, cmd[1], icookie, body, blen );
     734                        } else if( g_strncasecmp( command, "ACCEPT", 6 ) == 0 ) {
     735                                msn_invitation_accept( sb, cmd[1], icookie, body, blen );
     736                        } else if( g_strncasecmp( command, "CANCEL", 6 ) == 0 ) {
     737                                msn_invitation_cancel( sb, cmd[1], icookie, body, blen );
     738                        } else {
     739                                imcb_log( ic, "Warning: Received invalid invitation with "
     740                                                "command %s from %s", command, sb->who );
     741                        }
     742                       
     743                        g_free( command );
     744                }
     745#endif
     746                else if( g_strncasecmp( ct, "application/x-msnmsgrp2p", 24 ) == 0 )
     747                {
     748                        imcb_error( sb->ic, "Cannot receive file from %s: BitlBee does not "
     749                                        "support msnmsgrp2p yet.", sb->who );
     750                        g_free( ct );
    752751                }
    753752                else if( g_strncasecmp( ct, "text/x-msmsgscontrol", 20 ) == 0 )
     
    780779void msn_sb_start_keepalives( struct msn_switchboard *sb, gboolean initial )
    781780{
    782         struct buddy *b;
     781        bee_user_t *bu;
    783782       
    784783        if( sb && sb->who && sb->keepalive == 0 &&
    785             ( b = imcb_find_buddy( sb->ic, sb->who ) ) && !b->present &&
     784            ( bu = bee_user_by_handle( sb->ic->bee, sb->ic, sb->who ) ) &&
     785            !( bu->flags & BEE_USER_ONLINE ) &&
    786786            set_getbool( &sb->ic->acc->set, "switchboard_keepalives" ) )
    787787        {
Note: See TracChangeset for help on using the changeset viewer.