- Timestamp:
- 2010-09-02T09:15:44Z (14 years ago)
- Branches:
- master
- Children:
- bae0617
- Parents:
- 02bb9db
- Location:
- protocols/msn
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/msn/msn.c
r02bb9db r64768d4 154 154 if( strcmp( who, "raw" ) == 0 ) 155 155 { 156 msn_write( ic, message, strlen( message ) ); 157 msn_write( ic, "\r\n", 2 ); 156 msn_ns_write( ic, -1, "%s\r\n", message ); 158 157 } 159 158 else … … 193 192 static void msn_set_away( struct im_connection *ic, char *state, char *message ) 194 193 { 195 char buf[1024];196 194 char *uux; 197 195 struct msn_data *md = ic->proto_data; … … 202 200 md->away_state = msn_away_state_list + 1; 203 201 204 g_snprintf( buf, sizeof( buf ), "CHG %d %s\r\n", ++md->trId, md->away_state->code ); 205 if( !msn_write( ic, buf, strlen( buf ) ) ) 202 if( !msn_ns_write( ic, -1, "CHG %d %s\r\n", ++md->trId, md->away_state->code ) ) 206 203 return; 207 204 208 205 uux = g_markup_printf_escaped( "<Data><PSM>%s</PSM><CurrentMedia></CurrentMedia>" 209 206 "</Data>", message ? message : "" ); 210 g_snprintf( buf, sizeof( buf ), "UUX %d %zd\r\n%s", ++md->trId, strlen( uux ), uux ); 211 if( !msn_write( ic, buf, strlen( buf ) ) ) 212 return; 207 msn_ns_write( ic, -1, "UUX %d %zd\r\n%s", ++md->trId, strlen( uux ), uux ); 208 g_free( uux ); 213 209 } 214 210 … … 290 286 static void msn_keepalive( struct im_connection *ic ) 291 287 { 292 msn_ write( ic, "PNG\r\n", strlen( "PNG\r\n" ));288 msn_ns_write( ic, -1, "PNG\r\n" ); 293 289 } 294 290 -
protocols/msn/msn.h
r02bb9db r64768d4 208 208 209 209 /* ns.c */ 210 int msn_ns_write( struct im_connection *ic, int fd, const char *fmt, ... ); 210 211 gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ); 211 212 void msn_auth_got_passport_token( struct im_connection *ic, const char *token, const char *error ); … … 214 215 215 216 /* msn_util.c */ 216 int msn_write( struct im_connection *ic, char *s, int len );217 217 int msn_logged_in( struct im_connection *ic ); 218 218 int msn_buddy_list_add( struct im_connection *ic, msn_buddy_flags_t list, const char *who, const char *realname_, const char *group ); … … 236 236 237 237 /* sb.c */ 238 int msn_sb_write( struct msn_switchboard *sb, c har *s, int len);238 int msn_sb_write( struct msn_switchboard *sb, const char *fmt, ... ); 239 239 struct msn_switchboard *msn_sb_create( struct im_connection *ic, char *host, int port, char *key, int session ); 240 240 struct msn_switchboard *msn_sb_by_handle( struct im_connection *ic, char *handle ); -
protocols/msn/msn_util.c
r02bb9db r64768d4 30 30 #include <ctype.h> 31 31 32 int msn_write( struct im_connection *ic, char *s, int len )33 {34 struct msn_data *md = ic->proto_data;35 int st;36 37 if( getenv( "BITLBEE_DEBUG" ) )38 {39 write( 2, "->NS:", 5 );40 write( 2, s, len );41 }42 43 st = write( md->fd, s, len );44 if( st != len )45 {46 imcb_error( ic, "Short write() to main server" );47 imc_logout( ic, TRUE );48 return 0;49 }50 51 return 1;52 }53 54 32 int msn_logged_in( struct im_connection *ic ) 55 33 { … … 76 54 { 77 55 struct msn_data *md = ic->proto_data; 78 char buf[1024],groupid[8];56 char groupid[8]; 79 57 bee_user_t *bu; 80 58 struct msn_buddy_data *bd; … … 144 122 if( ( adl = adlrml_entry( who, list ) ) ) 145 123 { 146 g_snprintf( buf, sizeof( buf ), "ADL %d %zd\r\n%s",147 ++md->trId, strlen( adl ), adl );124 int st = msn_ns_write( ic, -1, "ADL %d %zd\r\n%s", 125 ++md->trId, strlen( adl ), adl ); 148 126 g_free( adl ); 149 127 150 return msn_write( ic, buf, strlen( buf ) );128 return st; 151 129 } 152 130 … … 157 135 { 158 136 struct msn_data *md = ic->proto_data; 159 char buf[1024],groupid[8];137 char groupid[8]; 160 138 bee_user_t *bu; 161 139 struct msn_buddy_data *bd; … … 189 167 if( ( adl = adlrml_entry( who, list ) ) ) 190 168 { 191 g_snprintf( buf, sizeof( buf ), "RML %d %zd\r\n%s",192 ++md->trId, strlen( adl ), adl );169 int st = msn_ns_write( ic, -1, "RML %d %zd\r\n%s", 170 ++md->trId, strlen( adl ), adl ); 193 171 g_free( adl ); 194 172 195 return msn_write( ic, buf, strlen( buf ) );173 return st; 196 174 } 197 175 … … 603 581 struct msn_data *md = ic->proto_data; 604 582 char fn[strlen(value)*3+1]; 605 char buf[512];606 583 607 584 strcpy( fn, value ); 608 585 http_encode( fn ); 609 g_snprintf( buf, sizeof( buf ), "PRP %d MFN %s\r\n",610 ++md->trId, fn );611 586 612 587 /* Note: We don't actually know if the server accepted the new name, 613 588 and won't give proper feedback yet if it doesn't. */ 614 return msn_ write( ic, buf, strlen( buf ));615 } 589 return msn_ns_write( ic, -1, "PRP %d MFN %s\r\n", ++md->trId, fn ); 590 } -
protocols/msn/ns.c
r02bb9db r64768d4 38 38 static void msn_ns_send_adl( struct im_connection *ic ); 39 39 40 int msn_ns_write( struct im_connection *ic, int fd, const char *fmt, ... ) 41 { 42 struct msn_data *md = ic->proto_data; 43 va_list params; 44 char *out; 45 size_t len; 46 int st; 47 48 va_start( params, fmt ); 49 out = g_strdup_vprintf( fmt, params ); 50 va_end( params ); 51 52 if( fd < 0 ) 53 fd = md->fd; 54 55 if( getenv( "BITLBEE_DEBUG" ) ) 56 fprintf( stderr, "->NS%d:%s", fd, out ); 57 58 len = strlen( out ); 59 st = write( fd, out, len ); 60 g_free( out ); 61 if( st != len ) 62 { 63 imcb_error( ic, "Short write() to main server" ); 64 imc_logout( ic, TRUE ); 65 return 0; 66 } 67 68 return 1; 69 } 70 40 71 gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) 41 72 { 42 73 struct im_connection *ic = data; 43 74 struct msn_data *md; 44 char s[1024];45 75 46 76 if( !g_slist_find( msn_connections, ic ) ) … … 74 104 md->handler->rxq = g_new0( char, 1 ); 75 105 76 g_snprintf( s, sizeof( s ), "VER %d %s CVR0\r\n", ++md->trId, MSNP_VER ); 77 if( msn_write( ic, s, strlen( s ) ) ) 106 if( msn_ns_write( ic, -1, "VER %d %s CVR0\r\n", ++md->trId, MSNP_VER ) ) 78 107 { 79 108 ic->inpa = b_input_add( md->fd, B_EV_IO_READ, msn_ns_callback, ic ); … … 104 133 struct im_connection *ic = data; 105 134 struct msn_data *md = ic->proto_data; 106 char buf[1024];107 135 108 136 if( num_parts == 0 ) … … 121 149 } 122 150 123 g_snprintf( buf, sizeof( buf ), "CVR %d 0x0409 mac 10.2.0 ppc macmsgs 3.5.1 macmsgs %s\r\n", 124 ++md->trId, ic->acc->user ); 125 return( msn_write( ic, buf, strlen( buf ) ) ); 151 return( msn_ns_write( ic, -1, "CVR %d 0x0409 mac 10.2.0 ppc macmsgs 3.5.1 macmsgs %s\r\n", 152 ++md->trId, ic->acc->user ) ); 126 153 } 127 154 else if( strcmp( cmd[0], "CVR" ) == 0 ) 128 155 { 129 156 /* We don't give a damn about the information we just received */ 130 g_snprintf( buf, sizeof( buf ), "USR %d SSO I %s\r\n", ++md->trId, ic->acc->user ); 131 return( msn_write( ic, buf, strlen( buf ) ) ); 157 return msn_ns_write( ic, -1, "USR %d SSO I %s\r\n", ++md->trId, ic->acc->user ); 132 158 } 133 159 else if( strcmp( cmd[0], "XFR" ) == 0 ) … … 280 306 { 281 307 char *resp; 308 int st; 282 309 283 310 if( num_parts < 3 ) … … 289 316 290 317 resp = msn_p11_challenge( cmd[2] ); 291 g_snprintf( buf, sizeof( buf ), "QRY %d %s %zd\r\n%s", 292 ++md->trId, MSNP11_PROD_ID, 293 strlen( resp ), resp ); 318 319 st = msn_ns_write( ic, -1, "QRY %d %s %zd\r\n%s", 320 ++md->trId, MSNP11_PROD_ID, 321 strlen( resp ), resp ); 294 322 g_free( resp ); 295 296 return( msn_write( ic, buf, strlen( buf ) ) ); 323 return st; 297 324 } 298 325 else if( strcmp( cmd[0], "ILN" ) == 0 ) … … 699 726 if( token ) 700 727 { 701 char buf[1536]; 702 703 g_snprintf( buf, sizeof( buf ), "USR %d SSO S %s %s\r\n", ++md->trId, md->tokens[0], token ); 704 msn_write( ic, buf, strlen( buf ) ); 728 msn_ns_write( ic, -1, "USR %d SSO S %s %s\r\n", ++md->trId, md->tokens[0], token ); 705 729 } 706 730 else … … 713 737 void msn_auth_got_contact_list( struct im_connection *ic ) 714 738 { 715 char buf[64];716 739 struct msn_data *md; 717 740 … … 721 744 722 745 md = ic->proto_data; 723 724 725 g_snprintf( buf, sizeof( buf ), "BLP %d %s\r\n", ++md->trId, "BL" ); 726 msn_write( ic, buf, strlen( buf ) ); 746 msn_ns_write( ic, -1, "BLP %d %s\r\n", ++md->trId, "BL" ); 727 747 } 728 748 … … 770 790 struct xt_node *adl; 771 791 struct msn_data *md = ic->proto_data; 772 char *adls , buf[64];792 char *adls; 773 793 774 794 adl = xt_new_node( "ml", NULL, NULL ); … … 782 802 return; 783 803 } 804 784 805 adls = xt_to_string( adl ); 785 786 g_snprintf( buf, sizeof( buf ), "ADL %d %zd\r\n", ++md->trId, strlen( adls ) ); 787 if( msn_write( ic, buf, strlen( buf ) ) ) 788 msn_write( ic, adls, strlen( adls ) ); 789 806 msn_ns_write( ic, -1, "ADL %d %zd\r\n%s", ++md->trId, strlen( adls ), adls ); 790 807 g_free( adls ); 791 808 } -
protocols/msn/sb.c
r02bb9db r64768d4 35 35 static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts ); 36 36 37 int msn_sb_write( struct msn_switchboard *sb, char *s, int len ) 38 { 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 44 va_start( params, fmt ); 45 out = g_strdup_vprintf( fmt, params ); 46 va_end( params ); 47 41 48 if( getenv( "BITLBEE_DEBUG" ) ) 42 { 43 write( 2, "->SB:", 5 ); 44 write( 2, s, len ); 45 } 46 47 st = write( sb->fd, s, len ); 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 ); 48 54 if( st != len ) 49 55 { 50 56 msn_sb_destroy( sb ); 51 return ( 0 );52 } 53 54 return ( 1 );57 return 0; 58 } 59 60 return 1; 55 61 } 56 62 … … 59 65 struct msn_data *md = ic->proto_data; 60 66 struct msn_switchboard *sb; 61 char buf[1024];62 67 63 68 /* FIXME: *CHECK* the reliability of using spare sb's! */ … … 67 72 68 73 sb->who = g_strdup( m->who ); 69 g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, m->who ); 70 if( msn_sb_write( sb, buf, strlen( buf ) ) ) 74 if( msn_sb_write( sb, "CAL %d %s\r\n", ++sb->trId, m->who ) ) 71 75 { 72 76 /* He/She should join the switchboard soon, let's queue the message. */ … … 79 83 80 84 /* If we reach this line, there was no spare switchboard, so let's make one. */ 81 g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId ); 82 if( !msn_write( ic, buf, strlen( buf ) ) ) 85 if( !msn_ns_write( ic, -1, "XFR %d SB\r\n", ++md->trId ) ) 83 86 { 84 87 g_free( m->who ); … … 171 174 if( sb->ready ) 172 175 { 173 char * packet, *buf;176 char *buf; 174 177 int i, j; 175 178 … … 207 210 208 211 /* Build the final packet (MSG command + the message). */ 209 packet = g_strdup_printf( "MSG %d N %d\r\n%s", ++sb->trId, i, buf ); 210 g_free( buf ); 211 if( msn_sb_write( sb, packet, strlen( packet ) ) ) 212 { 213 g_free( packet ); 214 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; 215 216 } 216 217 else 217 218 { 218 g_free( packet);219 return ( 0 );219 g_free( buf ); 220 return 0; 220 221 } 221 222 } … … 332 333 g_snprintf( buf, sizeof( buf ), "ANS %d %s %s %d\r\n", ++sb->trId, ic->acc->user, sb->key, sb->session ); 333 334 334 if( msn_sb_write( sb, buf, strlen( buf )) )335 if( msn_sb_write( sb, "%s", buf ) ) 335 336 sb->inp = b_input_add( sb->fd, B_EV_IO_READ, msn_sb_callback, sb ); 336 337 else … … 352 353 { 353 354 time_t now = time( NULL ); 354 char buf[1024];355 355 356 356 if( now - md->first_sb_failure > 600 ) … … 384 384 debug( "Moved queued messages back to the main queue, " 385 385 "creating a new switchboard to retry." ); 386 g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId ); 387 if( !msn_write( ic, buf, strlen( buf ) ) ) 386 if( !msn_ns_write( ic, -1, "XFR %d SB\r\n", ++md->trId ) ) 388 387 return FALSE; 389 388 } … … 397 396 struct msn_switchboard *sb = data; 398 397 struct im_connection *ic = sb->ic; 399 char buf[1024];400 398 401 399 if( !num_parts ) … … 426 424 427 425 if( sb->who ) 428 { 429 g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, sb->who ); 430 return( msn_sb_write( sb, buf, strlen( buf ) ) ); 431 } 426 return msn_sb_write( sb, "CAL %d %s\r\n", ++sb->trId, sb->who ); 432 427 else 433 {434 428 debug( "Just created a switchboard, but I don't know what to do with it." ); 435 }436 429 } 437 430 else if( strcmp( cmd[0], "IRO" ) == 0 )
Note: See TracChangeset
for help on using the changeset viewer.