Changes in protocols/msn/sb.c [f8cb76d:1c3008a]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/msn/sb.c
rf8cb76d r1c3008a 29 29 #include "passport.h" 30 30 #include "md5.h" 31 #include "invitation.h" 31 32 32 33 static gboolean msn_sb_callback( gpointer data, gint source, b_input_condition cond ); … … 174 175 i = g_snprintf( buf, i, MSN_TYPING_HEADERS, sb->ic->acc->user ); 175 176 } 176 else if( str cmp( text, SB_KEEPALIVE_MESSAGE ) == 0 )177 { 178 buf = g_strdup( SB_KEEPALIVE_HEADERS);177 else if( strncmp( text, MSN_INVITE_HEADERS, sizeof( MSN_INVITE_HEADERS ) - 1 ) == 0 ) 178 { 179 buf = g_strdup( text ); 179 180 i = strlen( buf ); 180 181 } … … 255 256 256 257 msn_msgq_purge( ic, &sb->msgq ); 257 msn_sb_stop_keepalives( sb );258 258 259 259 if( sb->key ) g_free( sb->key ); … … 328 328 struct msn_data *md = ic->proto_data; 329 329 330 if( msn_handler( sb->handler ) != -1 ) 331 return TRUE; 332 333 if( sb->msgq != NULL ) 330 if( msn_handler( sb->handler ) == -1 ) 334 331 { 335 332 time_t now = time( NULL ); 336 char buf[1024];337 333 338 334 if( now - md->first_sb_failure > 600 ) … … 351 347 "There might be problems delivering your messages." ); 352 348 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; 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 } 375 380 } 376 381 … … 472 477 473 478 sb->ready = 1; 474 475 msn_sb_start_keepalives( sb, FALSE );476 479 } 477 480 else if( strcmp( cmd[0], "CAL" ) == 0 ) … … 523 526 } 524 527 525 msn_sb_start_keepalives( sb, FALSE );526 527 528 return( st ); 528 529 } … … 586 587 if( sb->who ) 587 588 { 588 msn_sb_stop_keepalives( sb );589 590 589 /* This is a single-person chat, and the other person is leaving. */ 591 590 g_free( sb->who ); … … 694 693 else if( g_strncasecmp( ct, "text/x-msmsgsinvite", 19 ) == 0 ) 695 694 { 696 char *itype = msn_findheader( body, "Application-GUID:", blen ); 697 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; 698 698 699 699 g_free( ct ); 700 700 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 } 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 ); 752 730 } 753 731 else if( g_strncasecmp( ct, "text/x-msmsgscontrol", 20 ) == 0 ) … … 771 749 return( 1 ); 772 750 } 773 774 static 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 780 void 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 795 void 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.