Changeset 767a148 for protocols/msn/sb.c


Ignore:
Timestamp:
2010-03-21T16:06:31Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
1cc0df3, 85693e6
Parents:
545d7c0 (diff), a81d679 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merging in file transfer support. Most important points from my review
are fixed now, time to let it settle in and get people to try it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/sb.c

    r545d7c0 r767a148  
    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 );
     
    168169               
    169170                /* Build the message. Convert LF to CR-LF for normal messages. */
    170                 if( strcmp( text, TYPING_NOTIFICATION_MESSAGE ) != 0 )
     171                if( strcmp( text, TYPING_NOTIFICATION_MESSAGE ) == 0 )
     172                {
     173                        i = strlen( MSN_TYPING_HEADERS ) + strlen( sb->ic->acc->user );
     174                        buf = g_new0( char, i );
     175                        i = g_snprintf( buf, i, MSN_TYPING_HEADERS, sb->ic->acc->user );
     176                }
     177                else if( strncmp( text, MSN_INVITE_HEADERS, sizeof( MSN_INVITE_HEADERS ) - 1 ) == 0 )
     178                {
     179                        buf = g_strdup( text );
     180                        i = strlen( buf );
     181                }
     182                else
    171183                {
    172184                        buf = g_new0( char, sizeof( MSN_MESSAGE_HEADERS ) + strlen( text ) * 2 + 1 );
     
    181193                                buf[i++] = text[j];
    182194                        }
    183                 }
    184                 else
    185                 {
    186                         i = strlen( MSN_TYPING_HEADERS ) + strlen( sb->ic->acc->user );
    187                         buf = g_new0( char, i );
    188                         i = g_snprintf( buf, i, MSN_TYPING_HEADERS, sb->ic->acc->user );
    189195                }
    190196               
     
    687693                else if( g_strncasecmp( ct, "text/x-msmsgsinvite", 19 ) == 0 )
    688694                {
    689                         char *itype = msn_findheader( body, "Application-GUID:", blen );
    690                         char buf[1024];
     695                        char *command = msn_findheader( body, "Invitation-Command:", blen );
     696                        char *cookie = msn_findheader( body, "Invitation-Cookie:", blen );
     697                        unsigned int icookie;
    691698                       
    692699                        g_free( ct );
    693700                       
    694                         *buf = 0;
    695                        
    696                         if( !itype )
    697                                 return( 1 );
    698                        
    699                         /* File transfer. */
    700                         if( strcmp( itype, "{5D3E02AB-6190-11d3-BBBB-00C04F795683}" ) == 0 )
    701                         {
    702                                 char *name = msn_findheader( body, "Application-File:", blen );
    703                                 char *size = msn_findheader( body, "Application-FileSize:", blen );
    704                                
    705                                 if( name && size )
    706                                 {
    707                                         g_snprintf( buf, sizeof( buf ), "<< \x02""BitlBee\x02"" - Filetransfer: `%s', %s bytes >>\n"
    708                                                     "Filetransfers are not supported by BitlBee for now...", name, size );
    709                                 }
    710                                 else
    711                                 {
    712                                         strcpy( buf, "<< \x02""BitlBee\x02"" - Corrupted MSN filetransfer invitation message >>" );
    713                                 }
    714                                
    715                                 if( name ) g_free( name );
    716                                 if( size ) g_free( size );
    717                         }
    718                         else
    719                         {
    720                                 char *iname = msn_findheader( body, "Application-Name:", blen );
    721                                
    722                                 g_snprintf( buf, sizeof( buf ), "<< \x02""BitlBee\x02"" - Unknown MSN invitation - %s (%s) >>",
    723                                                                 itype, iname ? iname : "no name" );
    724                                
    725                                 if( iname ) g_free( iname );
    726                         }
    727                        
    728                         g_free( itype );
    729                        
    730                         if( !*buf )
    731                                 return( 1 );
    732                        
    733                         if( sb->who )
    734                         {
    735                                 imcb_buddy_msg( ic, cmd[1], buf, 0, 0 );
    736                         }
    737                         else if( sb->chat )
    738                         {
    739                                 imcb_chat_msg( sb->chat, cmd[1], buf, 0, 0 );
    740                         }
    741                         else
    742                         {
    743                                 /* PANIC! */
    744                         }
     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 );
    745730                }
    746731                else if( g_strncasecmp( ct, "text/x-msmsgscontrol", 20 ) == 0 )
Note: See TracChangeset for help on using the changeset viewer.