Changeset 814aa52 for protocols/msn
- Timestamp:
- 2010-06-03T11:00:45Z (14 years ago)
- Branches:
- master
- Children:
- a6b2f13
- Parents:
- 5f8ab6a9 (diff), f4bcc22 (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. - Location:
- protocols/msn
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/msn/msn.c
r5f8ab6a9 r814aa52 31 31 GSList *msn_switchboards; 32 32 33 static char * msn_set_display_name( set_t *set, char *value );33 static char *set_eval_display_name( set_t *set, char *value ); 34 34 35 35 static void msn_init( account_t *acc ) 36 36 { 37 set_t *s; 38 39 s = set_add( &acc->set, "display_name", NULL, msn_set_display_name, acc ); 40 s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY; 41 42 s = set_add( &acc->set, "mail_notifications", "false", set_eval_bool, acc ); 37 set_add( &acc->set, "display_name", NULL, set_eval_display_name, acc ); 38 set_add( &acc->set, "local_display_name", "false", set_eval_bool, acc ); 39 set_add( &acc->set, "mail_notifications", "false", set_eval_bool, acc ); 40 set_add( &acc->set, "switchboard_keepalives", "false", set_eval_bool, acc ); 43 41 } 44 42 … … 167 165 static void msn_set_my_name( struct im_connection *ic, char *info ) 168 166 { 169 msn_set_display_name( set_find( &ic->acc->set, "display_name" ), info );167 msn_set_display_name( ic, info ); 170 168 } 171 169 … … 283 281 } 284 282 285 static char * msn_set_display_name( set_t *set, char *value )283 static char *set_eval_display_name( set_t *set, char *value ) 286 284 { 287 285 account_t *acc = set->data; 288 286 struct im_connection *ic = acc->ic; 289 struct msn_data *md; 290 char buf[1024], *fn; 291 292 /* Double-check. */ 287 288 /* Allow any name if we're offline. */ 293 289 if( ic == NULL ) 294 return NULL; 295 296 md = ic->proto_data; 290 return value; 297 291 298 292 if( strlen( value ) > 129 ) … … 301 295 return NULL; 302 296 } 303 304 fn = msn_http_encode( value );305 306 g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, ic->acc->user, fn );307 msn_write( ic, buf, strlen( buf ) );308 g_free( fn );309 297 310 298 /* Returning NULL would be better, because the server still has to 311 299 confirm the name change. However, it looks a bit confusing to the 312 300 user. */ 313 return value;301 return msn_set_display_name( ic, value ) ? value : NULL; 314 302 } 315 303 -
protocols/msn/msn.h
r5f8ab6a9 r814aa52 31 31 #define TYPING_NOTIFICATION_MESSAGE "\r\r\rBEWARE, ME R TYPINK MESSAGE!!!!\r\r\r" 32 32 #define GROUPCHAT_SWITCHBOARD_MESSAGE "\r\r\rME WANT TALK TO MANY PEOPLE\r\r\r" 33 #define SB_KEEPALIVE_MESSAGE "\r\r\rDONT HANG UP ON ME!\r\r\r" 33 34 34 35 #ifdef DEBUG_MSN … … 53 54 "TypingUser: %s\r\n" \ 54 55 "\r\n\r\n" 56 57 #define SB_KEEPALIVE_HEADERS "MIME-Version: 1.0\r\n" \ 58 "Content-Type: text/x-ping\r\n" \ 59 "\r\n\r\n" 55 60 56 61 #define PROFILE_URL "http://members.msn.com/" … … 83 88 gint inp; 84 89 struct msn_handler_data *handler; 90 gint keepalive; 85 91 86 92 int trId; … … 161 167 char *msn_http_encode( const char *input ); 162 168 void msn_msgq_purge( struct im_connection *ic, GSList **list ); 169 gboolean msn_set_display_name( struct im_connection *ic, const char *rawname ); 163 170 164 171 /* tables.c */ … … 179 186 gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond ); 180 187 int msn_sb_write_msg( struct im_connection *ic, struct msn_message *m ); 188 void msn_sb_start_keepalives( struct msn_switchboard *sb, gboolean initial ); 189 void msn_sb_stop_keepalives( struct msn_switchboard *sb ); 181 190 182 191 #endif //_MSN_H -
protocols/msn/msn_util.c
r5f8ab6a9 r814aa52 38 38 imcb_error( ic, "Short write() to main server" ); 39 39 imc_logout( ic, TRUE ); 40 return ( 0 );41 } 42 43 return ( 1 );40 return 0; 41 } 42 43 return 1; 44 44 } 45 45 … … 377 377 g_string_free( ret, TRUE ); 378 378 } 379 380 gboolean msn_set_display_name( struct im_connection *ic, const char *rawname ) 381 { 382 char *fn = msn_http_encode( rawname ); 383 struct msn_data *md = ic->proto_data; 384 char buf[1024]; 385 386 g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, ic->acc->user, fn ); 387 g_free( fn ); 388 389 return msn_write( ic, buf, strlen( buf ) ) != 0; 390 } -
protocols/msn/ns.c
r5f8ab6a9 r814aa52 35 35 36 36 static void msn_auth_got_passport_token( struct msn_auth_data *mad ); 37 static gboolean msn_ns_got_display_name( struct im_connection *ic, char *name ); 37 38 38 39 gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) … … 231 232 else if( num_parts >= 7 && strcmp( cmd[2], "OK" ) == 0 ) 232 233 { 233 set_t *s;234 235 234 if( num_parts == 7 ) 236 { 237 http_decode( cmd[4] ); 238 239 strncpy( ic->displayname, cmd[4], sizeof( ic->displayname ) ); 240 ic->displayname[sizeof(ic->displayname)-1] = 0; 241 242 if( ( s = set_find( &ic->acc->set, "display_name" ) ) ) 243 { 244 g_free( s->value ); 245 s->value = g_strdup( cmd[4] ); 246 } 247 } 235 msn_ns_got_display_name( ic, cmd[4] ); 248 236 else 249 {250 237 imcb_log( ic, "Warning: Friendly name in server response was corrupted" ); 251 }252 238 253 239 imcb_log( ic, "Authenticated, getting buddy list" ); … … 422 408 else if( strcmp( cmd[0], "FLN" ) == 0 ) 423 409 { 424 if( cmd[1] ) 425 imcb_buddy_status( ic, cmd[1], 0, NULL, NULL ); 410 if( cmd[1] == NULL ) 411 return 1; 412 413 imcb_buddy_status( ic, cmd[1], 0, NULL, NULL ); 414 415 msn_sb_start_keepalives( msn_sb_by_handle( ic, cmd[1] ), TRUE ); 426 416 } 427 417 else if( strcmp( cmd[0], "NLN" ) == 0 ) … … 449 439 ( st != msn_away_state_list ? OPT_AWAY : 0 ), 450 440 st->name, NULL ); 441 442 msn_sb_stop_keepalives( msn_sb_by_handle( ic, cmd[2] ) ); 451 443 } 452 444 else if( strcmp( cmd[0], "RNG" ) == 0 ) … … 553 545 return( 0 ); 554 546 } 547 #if 0 548 /* Discard this one completely for now since I don't care about the ack 549 and since MSN servers can apparently screw up the formatting. */ 555 550 else if( strcmp( cmd[0], "REA" ) == 0 ) 556 551 { … … 583 578 } 584 579 } 580 #endif 585 581 else if( strcmp( cmd[0], "IPG" ) == 0 ) 586 582 { … … 732 728 } 733 729 } 730 731 static gboolean msn_ns_got_display_name( struct im_connection *ic, char *name ) 732 { 733 set_t *s; 734 735 if( ( s = set_find( &ic->acc->set, "display_name" ) ) == NULL ) 736 return FALSE; /* Shouldn't happen.. */ 737 738 http_decode( name ); 739 740 if( s->value && strcmp( s->value, name ) == 0 ) 741 { 742 return TRUE; 743 /* The names match, nothing to worry about. */ 744 } 745 else if( s->value != NULL && 746 ( strcmp( name, ic->acc->user ) == 0 || 747 set_getbool( &ic->acc->set, "local_display_name" ) ) ) 748 { 749 /* The server thinks our display name is our e-mail address 750 which is probably wrong, or the user *wants* us to do this: 751 Always use the locally set display_name. */ 752 return msn_set_display_name( ic, s->value ); 753 } 754 else 755 { 756 if( s->value && *s->value ) 757 imcb_log( ic, "BitlBee thinks your display name is `%s' but " 758 "the MSN server says it's `%s'. Using the MSN " 759 "server's name. Set local_display_name to true " 760 "to use the local name.", s->value, name ); 761 762 if( g_utf8_validate( name, -1, NULL ) ) 763 { 764 g_free( s->value ); 765 s->value = g_strdup( name ); 766 } 767 else 768 { 769 imcb_log( ic, "Warning: Friendly name in server response was corrupted" ); 770 } 771 772 return TRUE; 773 } 774 } -
protocols/msn/sb.c
r5f8ab6a9 r814aa52 168 168 169 169 /* Build the message. Convert LF to CR-LF for normal messages. */ 170 if( strcmp( text, TYPING_NOTIFICATION_MESSAGE ) != 0 ) 170 if( strcmp( text, TYPING_NOTIFICATION_MESSAGE ) == 0 ) 171 { 172 i = strlen( MSN_TYPING_HEADERS ) + strlen( sb->ic->acc->user ); 173 buf = g_new0( char, i ); 174 i = g_snprintf( buf, i, MSN_TYPING_HEADERS, sb->ic->acc->user ); 175 } 176 else if( strcmp( text, SB_KEEPALIVE_MESSAGE ) == 0 ) 177 { 178 buf = g_strdup( SB_KEEPALIVE_HEADERS ); 179 i = strlen( buf ); 180 } 181 else 171 182 { 172 183 buf = g_new0( char, sizeof( MSN_MESSAGE_HEADERS ) + strlen( text ) * 2 + 1 ); … … 182 193 } 183 194 } 184 else185 {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 );189 }190 195 191 196 /* Build the final packet (MSG command + the message). */ … … 250 255 251 256 msn_msgq_purge( ic, &sb->msgq ); 257 msn_sb_stop_keepalives( sb ); 252 258 253 259 if( sb->key ) g_free( sb->key ); … … 471 477 472 478 sb->ready = 1; 479 480 msn_sb_start_keepalives( sb, FALSE ); 473 481 } 474 482 else if( strcmp( cmd[0], "CAL" ) == 0 ) … … 520 528 } 521 529 530 msn_sb_start_keepalives( sb, FALSE ); 531 522 532 return( st ); 523 533 } … … 581 591 if( sb->who ) 582 592 { 593 msn_sb_stop_keepalives( sb ); 594 583 595 /* This is a single-person chat, and the other person is leaving. */ 584 596 g_free( sb->who ); … … 764 776 return( 1 ); 765 777 } 778 779 static gboolean msn_sb_keepalive( gpointer data, gint source, b_input_condition cond ) 780 { 781 struct msn_switchboard *sb = data; 782 return sb->ready && msn_sb_sendmessage( sb, SB_KEEPALIVE_MESSAGE ); 783 } 784 785 void msn_sb_start_keepalives( struct msn_switchboard *sb, gboolean initial ) 786 { 787 struct buddy *b; 788 789 if( sb && sb->who && sb->keepalive == 0 && 790 ( b = imcb_find_buddy( sb->ic, sb->who ) ) && !b->present && 791 set_getbool( &sb->ic->acc->set, "switchboard_keepalives" ) ) 792 { 793 if( initial ) 794 msn_sb_keepalive( sb, 0, 0 ); 795 796 sb->keepalive = b_timeout_add( 20000, msn_sb_keepalive, sb ); 797 } 798 } 799 800 void msn_sb_stop_keepalives( struct msn_switchboard *sb ) 801 { 802 if( sb && sb->keepalive > 0 ) 803 { 804 b_event_remove( sb->keepalive ); 805 sb->keepalive = 0; 806 } 807 }
Note: See TracChangeset
for help on using the changeset viewer.