Changeset 62f53b50 for protocols/msn/sb.c
- Timestamp:
- 2010-10-02T05:34:53Z (14 years ago)
- Branches:
- master
- Children:
- 2af3e23
- Parents:
- 05bf2a0 (diff), 04cd284 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/msn/sb.c
r05bf2a0 r62f53b50 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-20 05Wilmer van der Gaast and others *4 * Copyright 2002-2010 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 27 27 #include "nogaim.h" 28 28 #include "msn.h" 29 #include "passport.h"30 29 #include "md5.h" 30 #include "soap.h" 31 31 #include "invitation.h" 32 32 33 33 static gboolean msn_sb_callback( gpointer data, gint source, b_input_condition cond ); 34 static int msn_sb_command( gpointer data, char **cmd, int num_parts ); 35 static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts ); 36 37 int msn_sb_write( struct msn_switchboard *sb, char *s, int len ) 38 { 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; 39 42 int st; 40 43 41 st = write( sb->fd, s, len ); 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 ); 42 54 if( st != len ) 43 55 { 44 56 msn_sb_destroy( sb ); 45 return ( 0 );46 } 47 48 return ( 1 );57 return 0; 58 } 59 60 return 1; 49 61 } 50 62 … … 53 65 struct msn_data *md = ic->proto_data; 54 66 struct msn_switchboard *sb; 55 char buf[1024];56 67 57 68 /* FIXME: *CHECK* the reliability of using spare sb's! */ … … 61 72 62 73 sb->who = g_strdup( m->who ); 63 g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, m->who ); 64 if( msn_sb_write( sb, buf, strlen( buf ) ) ) 74 if( msn_sb_write( sb, "CAL %d %s\r\n", ++sb->trId, m->who ) ) 65 75 { 66 76 /* He/She should join the switchboard soon, let's queue the message. */ … … 73 83 74 84 /* If we reach this line, there was no spare switchboard, so let's make one. */ 75 g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId ); 76 if( !msn_write( ic, buf, strlen( buf ) ) ) 85 if( !msn_ns_write( ic, -1, "XFR %d SB\r\n", ++md->trId ) ) 77 86 { 78 87 g_free( m->who ); … … 165 174 if( sb->ready ) 166 175 { 167 char * packet, *buf;176 char *buf; 168 177 int i, j; 169 178 … … 201 210 202 211 /* Build the final packet (MSG command + the message). */ 203 packet = g_strdup_printf( "MSG %d N %d\r\n%s", ++sb->trId, i, buf ); 204 g_free( buf ); 205 if( msn_sb_write( sb, packet, strlen( packet ) ) ) 206 { 207 g_free( packet ); 208 return( 1 ); 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; 209 216 } 210 217 else 211 218 { 212 g_free( packet);213 return ( 0 );219 g_free( buf ); 220 return 0; 214 221 } 215 222 } … … 326 333 g_snprintf( buf, sizeof( buf ), "ANS %d %s %s %d\r\n", ++sb->trId, ic->acc->user, sb->key, sb->session ); 327 334 328 if( msn_sb_write( sb, buf, strlen( buf )) )335 if( msn_sb_write( sb, "%s", buf ) ) 329 336 sb->inp = b_input_add( sb->fd, B_EV_IO_READ, msn_sb_callback, sb ); 330 337 else … … 346 353 { 347 354 time_t now = time( NULL ); 348 char buf[1024];349 355 350 356 if( now - md->first_sb_failure > 600 ) … … 378 384 debug( "Moved queued messages back to the main queue, " 379 385 "creating a new switchboard to retry." ); 380 g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId ); 381 if( !msn_write( ic, buf, strlen( buf ) ) ) 386 if( !msn_ns_write( ic, -1, "XFR %d SB\r\n", ++md->trId ) ) 382 387 return FALSE; 383 388 } … … 387 392 } 388 393 389 static int msn_sb_command( gpointer data, char **cmd, int num_parts )390 { 391 struct msn_switchboard *sb = data;394 static int msn_sb_command( struct msn_handler_data *handler, char **cmd, int num_parts ) 395 { 396 struct msn_switchboard *sb = handler->data; 392 397 struct im_connection *ic = sb->ic; 393 char buf[1024];394 398 395 399 if( !num_parts ) … … 407 411 else if( strcmp( cmd[0], "USR" ) == 0 ) 408 412 { 409 if( num_parts !=5 )413 if( num_parts < 5 ) 410 414 { 411 415 msn_sb_destroy( sb ); … … 420 424 421 425 if( sb->who ) 422 { 423 g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, sb->who ); 424 return( msn_sb_write( sb, buf, strlen( buf ) ) ); 425 } 426 return msn_sb_write( sb, "CAL %d %s\r\n", ++sb->trId, sb->who ); 426 427 else 427 {428 428 debug( "Just created a switchboard, but I don't know what to do with it." ); 429 }430 429 } 431 430 else if( strcmp( cmd[0], "IRO" ) == 0 ) … … 433 432 int num, tot; 434 433 435 if( num_parts !=6 )434 if( num_parts < 6 ) 436 435 { 437 436 msn_sb_destroy( sb ); … … 470 469 else if( strcmp( cmd[0], "ANS" ) == 0 ) 471 470 { 472 if( num_parts !=3 )471 if( num_parts < 3 ) 473 472 { 474 473 msn_sb_destroy( sb ); … … 489 488 else if( strcmp( cmd[0], "CAL" ) == 0 ) 490 489 { 491 if( num_parts !=4 || !isdigit( cmd[3][0] ) )490 if( num_parts < 4 || !isdigit( cmd[3][0] ) ) 492 491 { 493 492 msn_sb_destroy( sb ); … … 499 498 else if( strcmp( cmd[0], "JOI" ) == 0 ) 500 499 { 501 if( num_parts !=3 )500 if( num_parts < 3 ) 502 501 { 503 502 msn_sb_destroy( sb ); … … 560 559 else if( strcmp( cmd[0], "MSG" ) == 0 ) 561 560 { 562 if( num_parts !=4 )561 if( num_parts < 4 ) 563 562 { 564 563 msn_sb_destroy( sb ); … … 625 624 const struct msn_status_code *err = msn_status_by_number( num ); 626 625 627 imcb_error( ic, "Error reported by switchboard server: %s", err->text ); 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 ); 628 632 629 633 if( err->flags & STATUS_SB_FATAL ) … … 661 665 } 662 666 663 static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts )664 { 665 struct msn_switchboard *sb = data;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; 666 670 struct im_connection *ic = sb->ic; 667 671 char *body; … … 741 745 else if( g_strncasecmp( ct, "application/x-msnmsgrp2p", 24 ) == 0 ) 742 746 { 743 imcb_error( sb->ic, "Cannot receive file from %s: BitlBee does not "744 "support msnmsgrp2p yet.", sb->who );747 /* Not currently implemented. Don't warn about it since 748 this seems to be used for avatars now. */ 745 749 g_free( ct ); 746 750 }
Note: See TracChangeset
for help on using the changeset viewer.