Changes in protocols/msn/sb.c [bae0617:f8cb76d]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/msn/sb.c
rbae0617 rf8cb76d 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-20 10Wilmer van der Gaast and others *4 * Copyright 2002-2005 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 27 27 #include "nogaim.h" 28 28 #include "msn.h" 29 #include "passport.h" 29 30 #include "md5.h" 30 #include "soap.h"31 #include "invitation.h"32 31 33 32 static gboolean msn_sb_callback( gpointer data, gint source, b_input_condition cond ); 34 static int msn_sb_command( struct msn_handler_data *handler, char **cmd, int num_parts ); 35 static int msn_sb_message( struct msn_handler_data *handler, char *msg, int msglen, char **cmd, int num_parts ); 36 37 int msn_sb_write( struct msn_switchboard *sb, const char *fmt, ... ) 38 { 39 va_list params; 40 char *out; 41 size_t len; 33 static int msn_sb_command( gpointer data, char **cmd, int num_parts ); 34 static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts ); 35 36 int msn_sb_write( struct msn_switchboard *sb, char *s, int len ) 37 { 42 38 int st; 43 39 44 va_start( params, fmt ); 45 out = g_strdup_vprintf( fmt, params ); 46 va_end( params ); 47 48 if( getenv( "BITLBEE_DEBUG" ) ) 49 fprintf( stderr, "->SB%d:%s", sb->fd, out ); 50 51 len = strlen( out ); 52 st = write( sb->fd, out, len ); 53 g_free( out ); 40 st = write( sb->fd, s, len ); 54 41 if( st != len ) 55 42 { 56 43 msn_sb_destroy( sb ); 57 return 0;58 } 59 60 return 1;44 return( 0 ); 45 } 46 47 return( 1 ); 61 48 } 62 49 … … 65 52 struct msn_data *md = ic->proto_data; 66 53 struct msn_switchboard *sb; 54 char buf[1024]; 67 55 68 56 /* FIXME: *CHECK* the reliability of using spare sb's! */ … … 72 60 73 61 sb->who = g_strdup( m->who ); 74 if( msn_sb_write( sb, "CAL %d %s\r\n", ++sb->trId, m->who ) ) 62 g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, m->who ); 63 if( msn_sb_write( sb, buf, strlen( buf ) ) ) 75 64 { 76 65 /* He/She should join the switchboard soon, let's queue the message. */ … … 83 72 84 73 /* If we reach this line, there was no spare switchboard, so let's make one. */ 85 if( !msn_ns_write( ic, -1, "XFR %d SB\r\n", ++md->trId ) ) 74 g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId ); 75 if( !msn_write( ic, buf, strlen( buf ) ) ) 86 76 { 87 77 g_free( m->who ); … … 174 164 if( sb->ready ) 175 165 { 176 char * buf;166 char *packet, *buf; 177 167 int i, j; 178 168 … … 187 177 { 188 178 buf = g_strdup( SB_KEEPALIVE_HEADERS ); 189 i = strlen( buf );190 }191 else if( strncmp( text, MSN_INVITE_HEADERS, sizeof( MSN_INVITE_HEADERS ) - 1 ) == 0 )192 {193 buf = g_strdup( text );194 179 i = strlen( buf ); 195 180 } … … 210 195 211 196 /* Build the final packet (MSG command + the message). */ 212 if( msn_sb_write( sb, "MSG %d N %d\r\n%s", ++sb->trId, i, buf ) ) 213 { 214 g_free( buf ); 215 return 1; 197 packet = g_strdup_printf( "MSG %d N %d\r\n%s", ++sb->trId, i, buf ); 198 g_free( buf ); 199 if( msn_sb_write( sb, packet, strlen( packet ) ) ) 200 { 201 g_free( packet ); 202 return( 1 ); 216 203 } 217 204 else 218 205 { 219 g_free( buf);220 return 0;206 g_free( packet ); 207 return( 0 ); 221 208 } 222 209 } … … 240 227 { 241 228 struct im_connection *ic = sb->ic; 242 struct groupchat *c = NULL;243 229 char buf[1024]; 244 230 245 231 /* Create the groupchat structure. */ 246 232 g_snprintf( buf, sizeof( buf ), "MSN groupchat session %d", sb->session ); 247 if( sb->who ) 248 c = bee_chat_by_title( ic->bee, ic, sb->who ); 249 if( c && !msn_sb_by_chat( c ) ) 250 sb->chat = c; 251 else 252 sb->chat = imcb_chat_new( ic, buf ); 233 sb->chat = imcb_chat_new( ic, buf ); 253 234 254 235 /* Populate the channel. */ … … 333 314 g_snprintf( buf, sizeof( buf ), "ANS %d %s %s %d\r\n", ++sb->trId, ic->acc->user, sb->key, sb->session ); 334 315 335 if( msn_sb_write( sb, "%s", buf) )336 sb->inp = b_input_add( sb->fd, B_EV_IO_READ, msn_sb_callback, sb );316 if( msn_sb_write( sb, buf, strlen( buf ) ) ) 317 sb->inp = b_input_add( sb->fd, GAIM_INPUT_READ, msn_sb_callback, sb ); 337 318 else 338 319 debug( "Error %d while connecting to switchboard server", 2 ); … … 353 334 { 354 335 time_t now = time( NULL ); 336 char buf[1024]; 355 337 356 338 if( now - md->first_sb_failure > 600 ) … … 384 366 debug( "Moved queued messages back to the main queue, " 385 367 "creating a new switchboard to retry." ); 386 if( !msn_ns_write( ic, -1, "XFR %d SB\r\n", ++md->trId ) ) 368 g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId ); 369 if( !msn_write( ic, buf, strlen( buf ) ) ) 387 370 return FALSE; 388 371 } … … 392 375 } 393 376 394 static int msn_sb_command( struct msn_handler_data *handler, char **cmd, int num_parts )395 { 396 struct msn_switchboard *sb = handler->data;377 static int msn_sb_command( gpointer data, char **cmd, int num_parts ) 378 { 379 struct msn_switchboard *sb = data; 397 380 struct im_connection *ic = sb->ic; 381 char buf[1024]; 398 382 399 383 if( !num_parts ) … … 411 395 else if( strcmp( cmd[0], "USR" ) == 0 ) 412 396 { 413 if( num_parts <5 )397 if( num_parts != 5 ) 414 398 { 415 399 msn_sb_destroy( sb ); … … 424 408 425 409 if( sb->who ) 426 return msn_sb_write( sb, "CAL %d %s\r\n", ++sb->trId, sb->who ); 410 { 411 g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, sb->who ); 412 return( msn_sb_write( sb, buf, strlen( buf ) ) ); 413 } 427 414 else 415 { 428 416 debug( "Just created a switchboard, but I don't know what to do with it." ); 417 } 429 418 } 430 419 else if( strcmp( cmd[0], "IRO" ) == 0 ) … … 432 421 int num, tot; 433 422 434 if( num_parts <6 )423 if( num_parts != 6 ) 435 424 { 436 425 msn_sb_destroy( sb ); … … 469 458 else if( strcmp( cmd[0], "ANS" ) == 0 ) 470 459 { 471 if( num_parts <3 )460 if( num_parts != 3 ) 472 461 { 473 462 msn_sb_destroy( sb ); … … 488 477 else if( strcmp( cmd[0], "CAL" ) == 0 ) 489 478 { 490 if( num_parts <4 || !isdigit( cmd[3][0] ) )479 if( num_parts != 4 || !isdigit( cmd[3][0] ) ) 491 480 { 492 481 msn_sb_destroy( sb ); … … 498 487 else if( strcmp( cmd[0], "JOI" ) == 0 ) 499 488 { 500 if( num_parts <3 )489 if( num_parts != 3 ) 501 490 { 502 491 msn_sb_destroy( sb ); … … 559 548 else if( strcmp( cmd[0], "MSG" ) == 0 ) 560 549 { 561 if( num_parts <4 )550 if( num_parts != 4 ) 562 551 { 563 552 msn_sb_destroy( sb ); … … 624 613 const struct msn_status_code *err = msn_status_by_number( num ); 625 614 626 /* If the person is offline, send an offline message instead, 627 and don't report an error. */ 628 if( num == 217 ) 629 msn_soap_oim_send_queue( ic, &sb->msgq ); 630 else 631 imcb_error( ic, "Error reported by switchboard server: %s", err->text ); 615 imcb_error( ic, "Error reported by switchboard server: %s", err->text ); 632 616 633 617 if( err->flags & STATUS_SB_FATAL ) … … 665 649 } 666 650 667 static int msn_sb_message( struct msn_handler_data *handler, char *msg, int msglen, char **cmd, int num_parts )668 { 669 struct msn_switchboard *sb = handler->data;651 static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts ) 652 { 653 struct msn_switchboard *sb = data; 670 654 struct im_connection *ic = sb->ic; 671 655 char *body; … … 708 692 } 709 693 } 710 #if 0711 // Disable MSN ft support for now.712 694 else if( g_strncasecmp( ct, "text/x-msmsgsinvite", 19 ) == 0 ) 713 695 { 714 char *command = msn_findheader( body, "Invitation-Command:", blen ); 715 char *cookie = msn_findheader( body, "Invitation-Cookie:", blen ); 716 unsigned int icookie; 696 char *itype = msn_findheader( body, "Application-GUID:", blen ); 697 char buf[1024]; 717 698 718 699 g_free( ct ); 719 700 720 /* Every invite should have both a Command and Cookie header */ 721 if( !command || !cookie ) { 722 g_free( command ); 723 g_free( cookie ); 724 imcb_log( ic, "Warning: No command or cookie from %s", sb->who ); 725 return 1; 726 } 727 728 icookie = strtoul( cookie, NULL, 10 ); 729 g_free( cookie ); 730 731 if( g_strncasecmp( command, "INVITE", 6 ) == 0 ) { 732 msn_invitation_invite( sb, cmd[1], icookie, body, blen ); 733 } else if( g_strncasecmp( command, "ACCEPT", 6 ) == 0 ) { 734 msn_invitation_accept( sb, cmd[1], icookie, body, blen ); 735 } else if( g_strncasecmp( command, "CANCEL", 6 ) == 0 ) { 736 msn_invitation_cancel( sb, cmd[1], icookie, body, blen ); 737 } else { 738 imcb_log( ic, "Warning: Received invalid invitation with " 739 "command %s from %s", command, sb->who ); 740 } 741 742 g_free( command ); 743 } 744 #endif 745 else if( g_strncasecmp( ct, "application/x-msnmsgrp2p", 24 ) == 0 ) 746 { 747 /* Not currently implemented. Don't warn about it since 748 this seems to be used for avatars now. */ 749 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 } 750 752 } 751 753 else if( g_strncasecmp( ct, "text/x-msmsgscontrol", 20 ) == 0 ) … … 778 780 void msn_sb_start_keepalives( struct msn_switchboard *sb, gboolean initial ) 779 781 { 780 bee_user_t *bu;782 struct buddy *b; 781 783 782 784 if( sb && sb->who && sb->keepalive == 0 && 783 ( bu = bee_user_by_handle( sb->ic->bee, sb->ic, sb->who ) ) && 784 !( bu->flags & BEE_USER_ONLINE ) && 785 ( b = imcb_find_buddy( sb->ic, sb->who ) ) && !b->present && 785 786 set_getbool( &sb->ic->acc->set, "switchboard_keepalives" ) ) 786 787 {
Note: See TracChangeset
for help on using the changeset viewer.