diff options
Diffstat (limited to 'protocols/msn/msn.c')
-rw-r--r-- | protocols/msn/msn.c | 99 |
1 files changed, 56 insertions, 43 deletions
diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index a8d85a66..f8686835 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -26,36 +26,45 @@ #include "nogaim.h" #include "msn.h" -static void msn_login( struct aim_user *acct ) +static char *msn_set_display_name( set_t *set, char *value ); + +static void msn_acc_init( account_t *acc ) { - struct gaim_connection *gc = new_gaim_conn( acct ); - struct msn_data *md = g_new0( struct msn_data, 1 ); + set_t *s; - set_login_progress( gc, 1, "Connecting" ); + s = set_add( &acc->set, "display_name", NULL, msn_set_display_name, acc ); + s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY; +} + +static void msn_login( account_t *acc ) +{ + struct gaim_connection *gc = new_gaim_conn( acc ); + struct msn_data *md = g_new0( struct msn_data, 1 ); gc->proto_data = md; md->fd = -1; - if( strchr( acct->username, '@' ) == NULL ) + if( strchr( acc->user, '@' ) == NULL ) { hide_login_progress( gc, "Invalid account name" ); signoff( gc ); return; } + set_login_progress( gc, 1, "Connecting" ); + md->fd = proxy_connect( "messenger.hotmail.com", 1863, msn_ns_connected, gc ); if( md->fd < 0 ) { hide_login_progress( gc, "Could not connect to server" ); signoff( gc ); + return; } - else - { - md->gc = gc; - md->away_state = msn_away_state_list; - - msn_connections = g_slist_append( msn_connections, gc ); - } + + md->gc = gc; + md->away_state = msn_away_state_list; + + msn_connections = g_slist_append( msn_connections, gc ); } static void msn_close( struct gaim_connection *gc ) @@ -211,36 +220,7 @@ static void msn_set_away( struct gaim_connection *gc, char *state, char *message static void msn_set_info( struct gaim_connection *gc, char *info ) { - int i; - char buf[1024], *fn, *s; - struct msn_data *md = gc->proto_data; - - if( strlen( info ) > 129 ) - { - do_error_dialog( gc, "Maximum name length exceeded", "MSN" ); - return; - } - - /* Of course we could use http_encode() here, but when we encode - every character, the server is less likely to complain about the - chosen name. However, the MSN server doesn't seem to like escaped - non-ASCII chars, so we keep those unescaped. */ - s = fn = g_new0( char, strlen( info ) * 3 + 1 ); - for( i = 0; info[i]; i ++ ) - if( info[i] & 128 ) - { - *s = info[i]; - s ++; - } - else - { - g_snprintf( s, 4, "%%%02X", info[i] ); - s += 3; - } - - g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, gc->username, fn ); - msn_write( gc, buf, strlen( buf ) ); - g_free( fn ); + msn_set_display_name( set_find( &gc->acc->set, "display_name" ), info ); } static void msn_get_info(struct gaim_connection *gc, char *who) @@ -379,11 +359,44 @@ static int msn_send_typing( struct gaim_connection *gc, char *who, int typing ) return( 1 ); } +static char *msn_set_display_name( set_t *set, char *value ) +{ + account_t *acc = set->data; + struct gaim_connection *gc = acc->gc; + struct msn_data *md; + char buf[1024], *fn; + + /* Double-check. */ + if( gc == NULL ) + return NULL; + + md = gc->proto_data; + + if( strlen( value ) > 129 ) + { + serv_got_crap( gc, "Maximum name length exceeded" ); + return NULL; + } + + fn = msn_http_encode( value ); + + g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, gc->username, fn ); + msn_write( gc, buf, strlen( buf ) ); + g_free( fn ); + + /* Returning NULL would be better, because the server still has to + confirm the name change. However, it looks a bit confusing to the + user. */ + return value; +} + void msn_init() { struct prpl *ret = g_new0(struct prpl, 1); + ret->name = "msn"; ret->login = msn_login; + ret->acc_init = msn_acc_init; ret->close = msn_close; ret->send_im = msn_send_im; ret->away_states = msn_away_states; @@ -403,7 +416,7 @@ void msn_init() ret->add_deny = msn_add_deny; ret->rem_deny = msn_rem_deny; ret->send_typing = msn_send_typing; - ret->cmp_buddynames = g_strcasecmp; + ret->handle_cmp = g_strcasecmp; register_protocol(ret); } |