aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/msn/ns.c
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/msn/ns.c')
-rw-r--r--protocols/msn/ns.c77
1 files changed, 58 insertions, 19 deletions
diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c
index 0bb84a74..fe48f96d 100644
--- a/protocols/msn/ns.c
+++ b/protocols/msn/ns.c
@@ -33,7 +33,7 @@ static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition c
static int msn_ns_command( gpointer data, char **cmd, int num_parts );
static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts );
-static void msn_auth_got_passport_id( struct passport_reply *rep );
+static void msn_auth_got_passport_token( struct msn_auth_data *mad );
gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond )
{
@@ -177,7 +177,15 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts )
}
debug( "Connecting to a new switchboard with key %s", cmd[5] );
- sb = msn_sb_create( ic, server, port, cmd[5], MSN_SB_NEW );
+
+ if( ( sb = msn_sb_create( ic, server, port, cmd[5], MSN_SB_NEW ) ) == NULL )
+ {
+ /* Although this isn't strictly fatal for the NS connection, it's
+ definitely something serious (we ran out of file descriptors?). */
+ imcb_error( ic, "Could not create new switchboard" );
+ imc_logout( ic, TRUE );
+ return( 0 );
+ }
if( md->msgq )
{
@@ -213,7 +221,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts )
if( num_parts == 5 && strcmp( cmd[2], "TWN" ) == 0 && strcmp( cmd[3], "S" ) == 0 )
{
/* Time for some Passport black magic... */
- if( !passport_get_id( msn_auth_got_passport_id, ic, ic->acc->user, ic->acc->pass, cmd[4] ) )
+ if( !passport_get_token( msn_auth_got_passport_token, ic, ic->acc->user, ic->acc->pass, cmd[4] ) )
{
imcb_error( ic, "Error while contacting Passport server" );
imc_logout( ic, TRUE );
@@ -269,11 +277,25 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts )
{
if( num_parts == 5 )
{
- md->buddycount = atoi( cmd[3] );
- md->groupcount = atoi( cmd[4] );
- if( md->groupcount > 0 )
+ int i, groupcount;
+
+ groupcount = atoi( cmd[4] );
+ if( groupcount > 0 )
+ {
+ /* valgrind says this is leaking memory, I'm guessing
+ that this happens during server redirects. */
+ if( md->grouplist )
+ {
+ for( i = 0; i < md->groupcount; i ++ )
+ g_free( md->grouplist[i] );
+ g_free( md->grouplist );
+ }
+
+ md->groupcount = groupcount;
md->grouplist = g_new0( char *, md->groupcount );
+ }
+ md->buddycount = atoi( cmd[3] );
if( !*cmd[3] || md->buddycount == 0 )
msn_logged_in( ic );
}
@@ -467,8 +489,18 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts )
debug( "Got a call from %s (session %d). Key = %s", cmd[5], session, cmd[4] );
- sb = msn_sb_create( ic, server, port, cmd[4], session );
- sb->who = g_strdup( cmd[5] );
+ if( ( sb = msn_sb_create( ic, server, port, cmd[4], session ) ) == NULL )
+ {
+ /* Although this isn't strictly fatal for the NS connection, it's
+ definitely something serious (we ran out of file descriptors?). */
+ imcb_error( ic, "Could not create new switchboard" );
+ imc_logout( ic, TRUE );
+ return( 0 );
+ }
+ else
+ {
+ sb->who = g_strdup( cmd[5] );
+ }
}
else if( strcmp( cmd[0], "ADD" ) == 0 )
{
@@ -646,6 +678,9 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int
{
imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders );
}
+
+ g_free( inbox );
+ g_free( folders );
}
else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 )
{
@@ -673,22 +708,26 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int
return( 1 );
}
-static void msn_auth_got_passport_id( struct passport_reply *rep )
+static void msn_auth_got_passport_token( struct msn_auth_data *mad )
{
- struct im_connection *ic = rep->data;
- struct msn_data *md = ic->proto_data;
- char *key = rep->result;
- char buf[1024];
+ struct im_connection *ic = mad->data;
+ struct msn_data *md;
- if( key == NULL )
+ /* Dead connection? */
+ if( g_slist_find( msn_connections, ic ) == NULL )
+ return;
+
+ md = ic->proto_data;
+ if( mad->token )
{
- imcb_error( ic, "Error during Passport authentication (%s)",
- rep->error_string ? rep->error_string : "Unknown error" );
- imc_logout( ic, TRUE );
+ char buf[1024];
+
+ g_snprintf( buf, sizeof( buf ), "USR %d TWN S %s\r\n", ++md->trId, mad->token );
+ msn_write( ic, buf, strlen( buf ) );
}
else
{
- g_snprintf( buf, sizeof( buf ), "USR %d TWN S %s\r\n", ++md->trId, key );
- msn_write( ic, buf, strlen( buf ) );
+ imcb_error( ic, "Error during Passport authentication: %s", mad->error );
+ imc_logout( ic, TRUE );
}
}