From ba9edaa568088900145bbd1004c864b7d408c38d Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Wed, 10 May 2006 19:34:46 +0200 Subject: Moved everything to the BitlBee event handling API. --- protocols/msn/msn.h | 4 ++-- protocols/msn/ns.c | 20 +++++++++++++------- protocols/msn/sb.c | 20 +++++++++++++------- 3 files changed, 28 insertions(+), 16 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.h b/protocols/msn/msn.h index 0cd174f2..dbbb6aa0 100644 --- a/protocols/msn/msn.h +++ b/protocols/msn/msn.h @@ -145,7 +145,7 @@ GSList *msn_connections; GSList *msn_switchboards; /* ns.c */ -void msn_ns_connected( gpointer data, gint source, GaimInputCondition cond ); +gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ); /* msn_util.c */ int msn_write( struct gaim_connection *gc, char *s, int len ); @@ -172,4 +172,4 @@ struct msn_switchboard *msn_sb_spare( struct gaim_connection *gc ); int msn_sb_sendmessage( struct msn_switchboard *sb, char *text ); void msn_sb_to_chat( struct msn_switchboard *sb ); void msn_sb_destroy( struct msn_switchboard *sb ); -void msn_sb_connected( gpointer data, gint source, GaimInputCondition cond ); +gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond ); diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index 90d525ef..af3793f2 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -29,26 +29,26 @@ #include "passport.h" #include "md5.h" -static void msn_ns_callback( gpointer data, gint source, GaimInputCondition cond ); +static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond ); 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 ); -void msn_ns_connected( gpointer data, gint source, GaimInputCondition cond ) +gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) { struct gaim_connection *gc = data; struct msn_data *md; char s[1024]; if( !g_slist_find( msn_connections, gc ) ) - return; + return FALSE; if( source == -1 ) { hide_login_progress( gc, "Could not connect to server" ); signoff( gc ); - return; + return FALSE; } md = gc->proto_data; @@ -74,12 +74,14 @@ void msn_ns_connected( gpointer data, gint source, GaimInputCondition cond ) g_snprintf( s, sizeof( s ), "VER %d MSNP8 CVR0\r\n", ++md->trId ); if( msn_write( gc, s, strlen( s ) ) ) { - gc->inpa = gaim_input_add( md->fd, GAIM_INPUT_READ, msn_ns_callback, gc ); + gc->inpa = b_input_add( md->fd, GAIM_INPUT_READ, msn_ns_callback, gc ); set_login_progress( gc, 1, "Connected to server, waiting for reply" ); } + + return FALSE; } -void msn_ns_callback( gpointer data, gint source, GaimInputCondition cond ) +static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond ) { struct gaim_connection *gc = data; struct msn_data *md = gc->proto_data; @@ -88,7 +90,11 @@ void msn_ns_callback( gpointer data, gint source, GaimInputCondition cond ) { hide_login_progress( gc, "Error while reading from server" ); signoff( gc ); + + return FALSE; } + else + return TRUE; } static int msn_ns_command( gpointer data, char **cmd, int num_parts ) @@ -129,7 +135,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts == 6 && strcmp( cmd[2], "NS" ) == 0 ) { - gaim_input_remove( gc->inpa ); + b_event_remove( gc->inpa ); gc->inpa = 0; closesocket( md->fd ); diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index 234be1d6..54e89043 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -29,7 +29,7 @@ #include "passport.h" #include "md5.h" -static void msn_sb_callback( gpointer data, gint source, GaimInputCondition cond ); +static gboolean msn_sb_callback( gpointer data, gint source, b_input_condition cond ); static int msn_sb_command( gpointer data, char **cmd, int num_parts ); static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts ); @@ -236,7 +236,7 @@ void msn_sb_destroy( struct msn_switchboard *sb ) g_free( sb->handler ); } - if( sb->inp ) gaim_input_remove( sb->inp ); + if( sb->inp ) b_event_remove( sb->inp ); closesocket( sb->fd ); msn_switchboards = g_slist_remove( msn_switchboards, sb ); @@ -244,7 +244,7 @@ void msn_sb_destroy( struct msn_switchboard *sb ) g_free( sb ); } -void msn_sb_connected( gpointer data, gint source, GaimInputCondition cond ) +gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond ) { struct msn_switchboard *sb = data; struct gaim_connection *gc; @@ -253,7 +253,7 @@ void msn_sb_connected( gpointer data, gint source, GaimInputCondition cond ) /* Are we still alive? */ if( !g_slist_find( msn_switchboards, sb ) ) - return; + return FALSE; gc = sb->gc; md = gc->proto_data; @@ -262,7 +262,7 @@ void msn_sb_connected( gpointer data, gint source, GaimInputCondition cond ) { debug( "ERROR %d while connecting to switchboard server", 1 ); msn_sb_destroy( sb ); - return; + return FALSE; } /* Prepare the callback */ @@ -279,12 +279,14 @@ void msn_sb_connected( gpointer data, gint source, GaimInputCondition cond ) g_snprintf( buf, sizeof( buf ), "ANS %d %s %s %d\r\n", ++sb->trId, gc->username, sb->key, sb->session ); if( msn_sb_write( sb, buf, strlen( buf ) ) ) - sb->inp = gaim_input_add( sb->fd, GAIM_INPUT_READ, msn_sb_callback, sb ); + sb->inp = b_input_add( sb->fd, GAIM_INPUT_READ, msn_sb_callback, sb ); else debug( "ERROR %d while connecting to switchboard server", 2 ); + + return FALSE; } -static void msn_sb_callback( gpointer data, gint source, GaimInputCondition cond ) +static gboolean msn_sb_callback( gpointer data, gint source, b_input_condition cond ) { struct msn_switchboard *sb = data; @@ -292,7 +294,11 @@ static void msn_sb_callback( gpointer data, gint source, GaimInputCondition cond { debug( "ERROR: Switchboard died" ); msn_sb_destroy( sb ); + + return FALSE; } + else + return TRUE; } static int msn_sb_command( gpointer data, char **cmd, int num_parts ) -- cgit v1.2.3 From a2582c84bda1ed8940c75bd842f9296cef3f50d4 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 27 May 2006 00:44:48 +0200 Subject: Added error_string variable to Passport client. --- protocols/msn/ns.c | 9 ++++++++- protocols/msn/passport.c | 29 ++++++++++++++++++++++++----- protocols/msn/passport.h | 1 + 3 files changed, 33 insertions(+), 6 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index 90d525ef..523de0ae 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -649,8 +649,15 @@ static void msn_auth_got_passport_id( struct passport_reply *rep ) if( key == NULL ) { - hide_login_progress( gc, "Error during Passport authentication" ); + char *err; + + err = g_strdup_printf( "Error during Passport authentication (%s)", + rep->error_string ? rep->error_string : "Unknown error" ); + + hide_login_progress( gc, err ); signoff( gc ); + + g_free( err ); } else { diff --git a/protocols/msn/passport.c b/protocols/msn/passport.c index 34703432..5ef4fa18 100644 --- a/protocols/msn/passport.c +++ b/protocols/msn/passport.c @@ -68,8 +68,7 @@ static int passport_get_id_real( gpointer func, gpointer data, char *header ) return( 0 ); } - reqs = g_malloc( strlen( header ) + strlen( dummy ) + 128 ); - sprintf( reqs, "GET %s HTTP/1.0\r\n%s\r\n\r\n", dummy, header ); + reqs = g_strdup_printf( "GET %s HTTP/1.0\r\n%s\r\n\r\n", dummy, header ); *dummy = 0; req = http_dorequest( server, 443, 1, reqs, passport_get_id_ready, rep ); @@ -87,13 +86,13 @@ static void passport_get_id_ready( struct http_request *req ) { struct passport_reply *rep = req->data; - if( !g_slist_find( msn_connections, rep->data ) || !req->finished || !req->reply_headers ) + if( !g_slist_find( msn_connections, rep->data ) ) { destroy_reply( rep ); return; } - if( req->status_code == 200 ) + if( req->finished && req->reply_headers && req->status_code == 200 ) { char *dummy; @@ -108,6 +107,15 @@ static void passport_get_id_ready( struct http_request *req ) rep->result = g_strdup( dummy ); } + else + { + rep->error_string = g_strdup( "Could not parse Passport server response" ); + } + } + else + { + rep->error_string = g_strdup_printf( "HTTP error: %s", + req->status_string ? req->status_string : "Unknown error" ); } rep->func( rep ); @@ -168,16 +176,26 @@ static void passport_retrieve_dalogin_ready( struct http_request *req ) char *dalogin; char *urlend; - if( !g_slist_find( msn_connections, rep->data ) || !req->finished || !req->reply_headers ) + if( !g_slist_find( msn_connections, rep->data ) ) { destroy_reply( rep ); return; } + if( !req->finished || !req->reply_headers || req->status_code != 200 ) + { + rep->error_string = g_strdup_printf( "HTTP error while fetching DALogin (%s)", + req->status_string ? req->status_string : "Unknown error" ); + goto failure; + } + dalogin = strstr( req->reply_headers, "DALogin=" ); if( !dalogin ) + { + rep->error_string = g_strdup( "Parse error while fetching DALogin" ); goto failure; + } dalogin += strlen( "DALogin=" ); urlend = strchr( dalogin, ',' ); @@ -207,5 +225,6 @@ static void destroy_reply( struct passport_reply *rep ) { g_free( rep->result ); g_free( rep->header ); + g_free( rep->error_string ); g_free( rep ); } diff --git a/protocols/msn/passport.h b/protocols/msn/passport.h index f7e6ebb6..9fd81a82 100644 --- a/protocols/msn/passport.h +++ b/protocols/msn/passport.h @@ -38,6 +38,7 @@ struct passport_reply void *data; char *result; char *header; + char *error_string; }; int passport_get_id( gpointer func, gpointer data, char *username, char *password, char *cookie ); -- cgit v1.2.3 From db28304aed1fbe47f0a4076f3c97850059f262e6 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 27 May 2006 00:49:28 +0200 Subject: Using http_dorequest_url() at one place in passport.c now. --- protocols/msn/passport.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/passport.c b/protocols/msn/passport.c index 5ef4fa18..dd1d9b6f 100644 --- a/protocols/msn/passport.c +++ b/protocols/msn/passport.c @@ -152,7 +152,6 @@ static char *passport_create_header( char *cookie, char *email, char *pwd ) return( buffer ); } -#define PPR_REQUEST "GET /rdr/pprdr.asp HTTP/1.0\r\n\r\n" static int passport_retrieve_dalogin( gpointer func, gpointer data, char *header ) { struct passport_reply *rep = g_new0( struct passport_reply, 1 ); @@ -162,7 +161,7 @@ static int passport_retrieve_dalogin( gpointer func, gpointer data, char *header rep->func = func; rep->header = header; - req = http_dorequest( "nexus.passport.com", 443, 1, PPR_REQUEST, passport_retrieve_dalogin_ready, rep ); + req = http_dorequest_url( "https://nexus.passport.com/rdr/pprdr.asp", passport_retrieve_dalogin_ready, rep ); if( !req ) destroy_reply( rep ); @@ -184,7 +183,7 @@ static void passport_retrieve_dalogin_ready( struct http_request *req ) if( !req->finished || !req->reply_headers || req->status_code != 200 ) { - rep->error_string = g_strdup_printf( "HTTP error while fetching DALogin (%s)", + rep->error_string = g_strdup_printf( "HTTP error while fetching DALogin: %s", req->status_string ? req->status_string : "Unknown error" ); goto failure; } -- cgit v1.2.3 From 5a5c926ec0dffa4b28895929c092089c2a9b9d9f Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Mon, 12 Jun 2006 08:58:20 +0200 Subject: Fixed a (very rare, AFAIK) NULL-pointer dereference. --- protocols/msn/msn.c | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index 3c7064f8..bac9c427 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -63,33 +63,38 @@ static void msn_close( struct gaim_connection *gc ) struct msn_data *md = gc->proto_data; GSList *l; - if( md->fd >= 0 ) - closesocket( md->fd ); - - if( md->handler ) - { - if( md->handler->rxq ) g_free( md->handler->rxq ); - if( md->handler->cmd_text ) g_free( md->handler->cmd_text ); - g_free( md->handler ); - } - - while( md->switchboards ) - msn_sb_destroy( md->switchboards->data ); - - if( md->msgq ) + if( md ) { - struct msn_message *m; + if( md->fd >= 0 ) + closesocket( md->fd ); - for( l = md->msgq; l; l = l->next ) + if( md->handler ) { - m = l->data; + if( md->handler->rxq ) g_free( md->handler->rxq ); + if( md->handler->cmd_text ) g_free( md->handler->cmd_text ); + g_free( md->handler ); + } - serv_got_crap( gc, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who ); - g_free( m->who ); - g_free( m->text ); - g_free( m ); + while( md->switchboards ) + msn_sb_destroy( md->switchboards->data ); + + if( md->msgq ) + { + struct msn_message *m; + + for( l = md->msgq; l; l = l->next ) + { + m = l->data; + + serv_got_crap( gc, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who ); + g_free( m->who ); + g_free( m->text ); + g_free( m ); + } + g_slist_free( md->msgq ); } - g_slist_free( md->msgq ); + + g_free( md ); } for( l = gc->permit; l; l = l->next ) @@ -100,8 +105,6 @@ static void msn_close( struct gaim_connection *gc ) g_free( l->data ); g_slist_free( gc->deny ); - g_free( md ); - msn_connections = g_slist_remove( msn_connections, gc ); } -- cgit v1.2.3 From 59f5c42a86fe73e95aaed0bfe455c7c816f39d2b Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Wed, 21 Jun 2006 18:56:16 +0200 Subject: Fixed md->grouplist memory leak. --- protocols/msn/msn.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index bac9c427..6393f31d 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -94,6 +94,8 @@ static void msn_close( struct gaim_connection *gc ) g_slist_free( md->msgq ); } + g_free( md->grouplist ); + g_free( md ); } -- cgit v1.2.3 From 0a3c243b6659dc10efb227e507f324c2711d6dcd Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 1 Jul 2006 01:18:56 +0200 Subject: Got rid of struct aim_user (now using account_t everywhere). Needs some more testing though. --- protocols/msn/msn.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index 6393f31d..b00354c9 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -26,9 +26,9 @@ #include "nogaim.h" #include "msn.h" -static void msn_login( struct aim_user *acct ) +static void msn_login( account_t *acc ) { - struct gaim_connection *gc = new_gaim_conn( acct ); + struct gaim_connection *gc = new_gaim_conn( acc ); struct msn_data *md = g_new0( struct msn_data, 1 ); set_login_progress( gc, 1, "Connecting" ); @@ -36,7 +36,7 @@ static void msn_login( struct aim_user *acct ) 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 ); -- cgit v1.2.3 From 911f2eb7060f6af6fe8e4e02144cfb7c4bb4cc8b Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Mon, 3 Jul 2006 01:20:27 +0200 Subject: Added display_name setting for MSN connections. (Should replace the nick command later.) --- protocols/msn/msn.c | 90 +++++++++++++++++++++++++++++++++++------------------ protocols/msn/ns.c | 16 ++++++++++ 2 files changed, 76 insertions(+), 30 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index b00354c9..790b372a 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -26,6 +26,16 @@ #include "nogaim.h" #include "msn.h" +static char *msn_set_display_name( set_t *set, char *value ); + +static void msn_acc_init( account_t *acc ) +{ + set_t *s; + + 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 ); @@ -209,36 +219,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) @@ -377,11 +358,60 @@ 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, *s; + int i; + + /* 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; + } + + /* 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( value ) * 3 + 1 ); + for( i = 0; value[i]; i ++ ) + if( value[i] & 128 ) + { + *s = value[i]; + s ++; + } + else + { + g_snprintf( s, 4, "%%%02X", value[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 ); + + /* 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; diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index e4c2b68c..9774f3e2 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -222,11 +222,19 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) } else if( num_parts == 7 && strcmp( cmd[2], "OK" ) == 0 ) { + set_t *s; + http_decode( cmd[4] ); strncpy( gc->displayname, cmd[4], sizeof( gc->displayname ) ); gc->displayname[sizeof(gc->displayname)-1] = 0; + if( ( s = set_find( &gc->acc->set, "display_name" ) ) ) + { + g_free( s->value ); + s->value = g_strdup( cmd[4] ); + } + set_login_progress( gc, 1, "Authenticated, getting buddy list" ); g_snprintf( buf, sizeof( buf ), "SYN %d 0\r\n", ++md->trId ); @@ -516,9 +524,17 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( g_strcasecmp( cmd[3], gc->username ) == 0 ) { + set_t *s; + http_decode( cmd[4] ); strncpy( gc->displayname, cmd[4], sizeof( gc->displayname ) ); gc->displayname[sizeof(gc->displayname)-1] = 0; + + if( ( s = set_find( &gc->acc->set, "display_name" ) ) ) + { + g_free( s->value ); + s->value = g_strdup( cmd[4] ); + } } else { -- cgit v1.2.3 From bf25fa3627c00f80bad624bb4549c46e4b084279 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Mon, 3 Jul 2006 23:16:35 +0200 Subject: Completed [167]. (Memory leak wasn't completely fixed yet.) --- protocols/msn/msn.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index 6393f31d..a8d85a66 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -94,6 +94,8 @@ static void msn_close( struct gaim_connection *gc ) g_slist_free( md->msgq ); } + while( md->groupcount > 0 ) + g_free( md->grouplist[--md->groupcount] ); g_free( md->grouplist ); g_free( md ); -- cgit v1.2.3 From 5b52a4895e5a59ff6509f7771f4d8665737688c3 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Mon, 3 Jul 2006 23:22:45 +0200 Subject: Implemented per-account nick lists instead of per-protocol nick lists. nick_t is dead, instead nicks are just saves in a per-account_t GLib hash table. While doing this, the import_buddies command finally died and text_save() disappeared, because the old file format can't handle most of the new features in this branch anyway. Still have to implement support for the new nick lists in text_load()! --- protocols/msn/msn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index 790b372a..db4563dc 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -431,7 +431,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); } -- cgit v1.2.3 From 66b9e86eafc3709c491f96c917069db8b6a0c895 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Jul 2006 15:33:31 +0200 Subject: Add support for checking test suite coverage using gcov. --- protocols/msn/Makefile | 3 +++ 1 file changed, 3 insertions(+) (limited to 'protocols/msn') diff --git a/protocols/msn/Makefile b/protocols/msn/Makefile index 873c831c..f53b34ba 100644 --- a/protocols/msn/Makefile +++ b/protocols/msn/Makefile @@ -16,6 +16,9 @@ LFLAGS += -r # [SH] Phony targets all: msn_mod.o +check: all +gcov: + gcov *.c .PHONY: all clean distclean -- cgit v1.2.3 From 2811940d678bd9340055e08a0462c21e710d5714 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 27 Jul 2006 16:55:53 +0200 Subject: Copy-paste considered harmful + Fixed double handling of gc->permit/deny which actually broke the block/allow commands. --- protocols/msn/msn_util.c | 35 ----------------------------------- 1 file changed, 35 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index c3bd73cc..4e748099 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -53,19 +53,8 @@ int msn_logged_in( struct gaim_connection *gc ) int msn_buddy_list_add( struct gaim_connection *gc, char *list, char *who, char *realname_ ) { struct msn_data *md = gc->proto_data; - GSList *l, **lp = NULL; char buf[1024], *realname; - if( strcmp( list, "AL" ) == 0 ) - lp = &gc->permit; - else if( strcmp( list, "BL" ) == 0 ) - lp = &gc->deny; - - if( lp ) - for( l = *lp; l; l = l->next ) - if( g_strcasecmp( l->data, who ) == 0 ) - return( 1 ); - realname = g_new0( char, strlen( realname_ ) * 3 + 1 ); strcpy( realname, realname_ ); http_encode( realname ); @@ -75,9 +64,6 @@ int msn_buddy_list_add( struct gaim_connection *gc, char *list, char *who, char { g_free( realname ); - if( lp ) - *lp = g_slist_append( *lp, g_strdup( who ) ); - return( 1 ); } @@ -89,32 +75,11 @@ int msn_buddy_list_add( struct gaim_connection *gc, char *list, char *who, char int msn_buddy_list_remove( struct gaim_connection *gc, char *list, char *who ) { struct msn_data *md = gc->proto_data; - GSList *l = NULL, **lp = NULL; char buf[1024]; - if( strcmp( list, "AL" ) == 0 ) - lp = &gc->permit; - else if( strcmp( list, "BL" ) == 0 ) - lp = &gc->deny; - - if( lp ) - { - for( l = *lp; l; l = l->next ) - if( g_strcasecmp( l->data, who ) == 0 ) - break; - - if( !l ) - return( 1 ); - } - g_snprintf( buf, sizeof( buf ), "REM %d %s %s\r\n", ++md->trId, list, who ); if( msn_write( gc, buf, strlen( buf ) ) ) - { - if( lp ) - *lp = g_slist_remove( *lp, l->data ); - return( 1 ); - } return( 0 ); } -- cgit v1.2.3 From 54794b8e01b5cce0675e9cfbd7282d011ebcb99e Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Fri, 25 Aug 2006 14:34:36 +0200 Subject: Added msn_http_encode() so it can be used in msn_buddy_list_add() too. Most likely fixes #198. --- protocols/msn/msn.c | 20 ++------------------ protocols/msn/msn.h | 1 + protocols/msn/msn_util.c | 30 +++++++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 21 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index a8d85a66..0d2d7283 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -211,8 +211,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; + char buf[1024], *fn; struct msn_data *md = gc->proto_data; if( strlen( info ) > 129 ) @@ -221,22 +220,7 @@ static void msn_set_info( struct gaim_connection *gc, char *info ) 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; - } + fn = msn_http_encode( info ); g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, gc->username, fn ); msn_write( gc, buf, strlen( buf ) ); diff --git a/protocols/msn/msn.h b/protocols/msn/msn.h index dbbb6aa0..b4777d41 100644 --- a/protocols/msn/msn.h +++ b/protocols/msn/msn.h @@ -156,6 +156,7 @@ void msn_buddy_ask( struct gaim_connection *gc, char *handle, char *realname ); char *msn_findheader( char *text, char *header, int len ); char **msn_linesplit( char *line ); int msn_handler( struct msn_handler_data *h ); +char *msn_http_encode( const char *input ); /* tables.c */ const struct msn_away_state *msn_away_state_by_number( int number ); diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index 4e748099..ff4c148c 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -55,9 +55,7 @@ int msn_buddy_list_add( struct gaim_connection *gc, char *list, char *who, char struct msn_data *md = gc->proto_data; char buf[1024], *realname; - realname = g_new0( char, strlen( realname_ ) * 3 + 1 ); - strcpy( realname, realname_ ); - http_encode( realname ); + realname = msn_http_encode( realname_ ); g_snprintf( buf, sizeof( buf ), "ADD %d %s %s %s\r\n", ++md->trId, list, who, realname ); if( msn_write( gc, buf, strlen( buf ) ) ) @@ -314,3 +312,29 @@ int msn_handler( struct msn_handler_data *h ) return( 1 ); } + +/* The difference between this function and the normal http_encode() function + is that this one escapes every 7-bit ASCII character because this is said + to avoid some lame server-side checks when setting a real-name. Also, + non-ASCII characters are not escaped because MSN servers don't seem to + appreciate that! */ +char *msn_http_encode( const char *input ) +{ + char *ret, *s; + int i; + + ret = s = g_new0( char, strlen( input ) * 3 + 1 ); + for( i = 0; input[i]; i ++ ) + if( input[i] & 128 ) + { + *s = input[i]; + s ++; + } + else + { + g_snprintf( s, 4, "%%%02X", input[i] ); + s += 3; + } + + return ret; +} -- cgit v1.2.3 From 5e202b09f2cd9faff5f316ae6804facb5342eace Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 23 Sep 2006 18:18:24 +0200 Subject: Implemented a list of away states, using this for a better set_away(), and got rid of the double tag sent because of presence_announce(). --- protocols/msn/msn.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index 01b011c7..d36d861f 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -182,13 +182,14 @@ static int msn_send_im( struct gaim_connection *gc, char *who, char *message, in static GList *msn_away_states( struct gaim_connection *gc ) { - GList *l = NULL; + static GList *l = NULL; int i; - for( i = 0; msn_away_state_list[i].number > -1; i ++ ) - l = g_list_append( l, (void*) msn_away_state_list[i].name ); + if( l == NULL ) + for( i = 0; msn_away_state_list[i].number > -1; i ++ ) + l = g_list_append( l, (void*) msn_away_state_list[i].name ); - return( l ); + return l; } static char *msn_get_status_string( struct gaim_connection *gc, int number ) -- cgit v1.2.3 From 695e39232324711816f1db8e25fdba59a0c6456f Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Fri, 13 Oct 2006 23:44:54 +0200 Subject: Fixed some memory leaking in the MSN Passport code. --- protocols/msn/passport.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/passport.c b/protocols/msn/passport.c index dd1d9b6f..42b6ea73 100644 --- a/protocols/msn/passport.c +++ b/protocols/msn/passport.c @@ -58,6 +58,7 @@ static int passport_get_id_real( gpointer func, gpointer data, char *header ) rep = g_new0( struct passport_reply, 1 ); rep->data = data; rep->func = func; + rep->header = header; server = g_strdup( prd_cached ); dummy = strchr( server, '/' ); @@ -124,10 +125,14 @@ static void passport_get_id_ready( struct http_request *req ) static char *passport_create_header( char *cookie, char *email, char *pwd ) { - char *buffer = g_new0( char, 2048 ); + char *buffer; char *currenttoken; char *email_enc, *pwd_enc; + currenttoken = strstr( cookie, "lc=" ); + if( currenttoken == NULL ) + return NULL; + email_enc = g_new0( char, strlen( email ) * 3 + 1 ); strcpy( email_enc, email ); http_encode( email_enc ); @@ -136,20 +141,15 @@ static char *passport_create_header( char *cookie, char *email, char *pwd ) strcpy( pwd_enc, pwd ); http_encode( pwd_enc ); - currenttoken = strstr( cookie, "lc=" ); - if( currenttoken == NULL ) - return( NULL ); - - g_snprintf( buffer, 2048, - "Authorization: Passport1.4 OrgVerb=GET," - "OrgURL=http%%3A%%2F%%2Fmessenger%%2Emsn%%2Ecom," - "sign-in=%s,pwd=%s,%s", email_enc, pwd_enc, - currenttoken ); + buffer = g_strdup_printf( "Authorization: Passport1.4 OrgVerb=GET," + "OrgURL=http%%3A%%2F%%2Fmessenger%%2Emsn%%2Ecom," + "sign-in=%s,pwd=%s,%s", email_enc, pwd_enc, + currenttoken ); g_free( email_enc ); g_free( pwd_enc ); - return( buffer ); + return buffer; } static int passport_retrieve_dalogin( gpointer func, gpointer data, char *header ) -- cgit v1.2.3 From 3dc9d46cc20d287c266fed97f92d298ed721f7b3 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 15 Oct 2006 17:32:46 +0200 Subject: Fixed a very interesting memory leak in the OSCAR module. --- protocols/msn/msn.c | 1 - 1 file changed, 1 deletion(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index 46049108..f7e57707 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -366,7 +366,6 @@ static char *msn_set_display_name( set_t *set, char *value ) struct gaim_connection *gc = acc->gc; struct msn_data *md; char buf[1024], *fn; - int i; /* Double-check. */ if( gc == NULL ) -- cgit v1.2.3 From a3265629451475df75a3cd1fbe1805bbb71b2365 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 15 Oct 2006 20:44:47 +0200 Subject: Fixing early free(). Memory management in the passport code is getting too messy, really... :-( --- protocols/msn/passport.c | 1 + 1 file changed, 1 insertion(+) (limited to 'protocols/msn') diff --git a/protocols/msn/passport.c b/protocols/msn/passport.c index 42b6ea73..9fe6a174 100644 --- a/protocols/msn/passport.c +++ b/protocols/msn/passport.c @@ -211,6 +211,7 @@ static void passport_retrieve_dalogin_ready( struct http_request *req ) if( passport_get_id_real( rep->func, rep->data, rep->header ) ) { + rep->header = NULL; destroy_reply( rep ); return; } -- cgit v1.2.3 From 2a29eac1dd6c9d5d2ed5083efc1c185cfd750fd7 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 21 Oct 2006 21:49:57 +0200 Subject: "Restructured" msn_login() a little bit. --- protocols/msn/msn.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index f7e57707..f8686835 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -41,8 +41,6 @@ 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 ); - set_login_progress( gc, 1, "Connecting" ); - gc->proto_data = md; md->fd = -1; @@ -53,19 +51,20 @@ static void msn_login( account_t *acc ) 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 ) -- cgit v1.2.3 From bd28e6a2eec0333a866ef2e380d32b1e6ad0c80b Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 24 Oct 2006 12:40:28 +0200 Subject: MSN message packets are now sent at once instead of separately. Probably the MSN servers don't care, but it looks a bit prettier in wireshark. ;-) --- protocols/msn/sb.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index 63744cd0..7ec340bd 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -121,9 +121,10 @@ int msn_sb_sendmessage( struct msn_switchboard *sb, char *text ) { if( sb->ready ) { - char cmd[1024], *buf; + char *packet, *buf; int i, j; + /* Build the message. Convert LF to CR-LF for normal messages. */ if( strcmp( text, TYPING_NOTIFICATION_MESSAGE ) != 0 ) { buf = g_new0( char, sizeof( MSN_MESSAGE_HEADERS ) + strlen( text ) * 2 ); @@ -141,19 +142,21 @@ int msn_sb_sendmessage( struct msn_switchboard *sb, char *text ) else { i = strlen( MSN_TYPING_HEADERS ) + strlen( sb->gc->username ); - buf = g_new0( char, strlen( MSN_TYPING_HEADERS ) + strlen( sb->gc->username ) ); + buf = g_new0( char, i ); i = g_snprintf( buf, i, MSN_TYPING_HEADERS, sb->gc->username ); } - g_snprintf( cmd, sizeof( cmd ), "MSG %d N %d\r\n", ++sb->trId, i ); - if( msn_sb_write( sb, cmd, strlen( cmd ) ) && msn_sb_write( sb, buf, i ) ) + /* Build the final packet (MSG command + the message). */ + packet = g_strdup_printf( "MSG %d N %d\r\n%s", ++sb->trId, i, buf ); + g_free( buf ); + if( msn_sb_write( sb, packet, strlen( packet ) ) ) { - g_free( buf ); + g_free( packet ); return( 1 ); } else { - g_free( buf ); + g_free( packet ); return( 0 ); } } -- cgit v1.2.3 From 348c11b16c156979ef2c7141ca7450af693b3713 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 22 Jan 2007 10:42:55 +0100 Subject: Add lcov target --- protocols/msn/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'protocols/msn') diff --git a/protocols/msn/Makefile b/protocols/msn/Makefile index f53b34ba..3440658d 100644 --- a/protocols/msn/Makefile +++ b/protocols/msn/Makefile @@ -17,6 +17,7 @@ LFLAGS += -r # [SH] Phony targets all: msn_mod.o check: all +lcov: gcov: gcov *.c -- cgit v1.2.3 From fa29d09342c79b886efacee4cfc3078be5f5a722 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 27 Mar 2007 22:53:11 -0700 Subject: Preparing for Jabber conference room support. --- protocols/msn/msn.c | 27 ++++++++++++--------------- protocols/msn/msn.h | 4 ++-- protocols/msn/sb.c | 20 +++++++++++--------- 3 files changed, 25 insertions(+), 26 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index 663bff8c..a73d85d4 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -240,9 +240,9 @@ static void msn_remove_buddy( struct gaim_connection *gc, char *who, char *group msn_buddy_list_remove( gc, "FL", who ); } -static int msn_chat_send( struct gaim_connection *gc, int id, char *message ) +static int msn_chat_send( struct conversation *c, char *message ) { - struct msn_switchboard *sb = msn_sb_by_id( gc, id ); + struct msn_switchboard *sb = msn_sb_by_chat( c ); if( sb ) return( msn_sb_sendmessage( sb, message ) ); @@ -250,9 +250,9 @@ static int msn_chat_send( struct gaim_connection *gc, int id, char *message ) return( 0 ); } -static void msn_chat_invite( struct gaim_connection *gc, int id, char *msg, char *who ) +static void msn_chat_invite( struct conversation *c, char *msg, char *who ) { - struct msn_switchboard *sb = msn_sb_by_id( gc, id ); + struct msn_switchboard *sb = msn_sb_by_chat( c ); char buf[1024]; if( sb ) @@ -262,15 +262,15 @@ static void msn_chat_invite( struct gaim_connection *gc, int id, char *msg, char } } -static void msn_chat_leave( struct gaim_connection *gc, int id ) +static void msn_chat_leave( struct conversation *c ) { - struct msn_switchboard *sb = msn_sb_by_id( gc, id ); + struct msn_switchboard *sb = msn_sb_by_chat( c ); if( sb ) msn_sb_write( sb, "OUT\r\n", 5 ); } -static int msn_chat_open( struct gaim_connection *gc, char *who ) +static struct conversation *msn_chat_open( struct gaim_connection *gc, char *who ) { struct msn_switchboard *sb; struct msn_data *md = gc->proto_data; @@ -279,8 +279,7 @@ static int msn_chat_open( struct gaim_connection *gc, char *who ) if( ( sb = msn_sb_by_handle( gc, who ) ) ) { debug( "Converting existing switchboard to %s to a groupchat", who ); - msn_sb_to_chat( sb ); - return( 1 ); + return msn_sb_to_chat( sb ); } else { @@ -291,10 +290,7 @@ static int msn_chat_open( struct gaim_connection *gc, char *who ) debug( "Trying to reuse an existing switchboard as a groupchat with %s", who ); g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, who ); if( msn_sb_write( sb, buf, strlen( buf ) ) ) - { - msn_sb_to_chat( sb ); - return( 1 ); - } + return msn_sb_to_chat( sb ); } /* If the stuff above failed for some reason: */ @@ -313,10 +309,11 @@ static int msn_chat_open( struct gaim_connection *gc, char *who ) /* Queue the magic message and cross your fingers. */ md->msgq = g_slist_append( md->msgq, m ); - return( 1 ); + /* FIXME: Can I try to return something here already? */ + return NULL; } - return( 0 ); + return NULL; } static void msn_keepalive( struct gaim_connection *gc ) diff --git a/protocols/msn/msn.h b/protocols/msn/msn.h index b4777d41..78cc3caf 100644 --- a/protocols/msn/msn.h +++ b/protocols/msn/msn.h @@ -168,9 +168,9 @@ const struct msn_status_code *msn_status_by_number( int number ); int msn_sb_write( struct msn_switchboard *sb, char *s, int len ); struct msn_switchboard *msn_sb_create( struct gaim_connection *gc, char *host, int port, char *key, int session ); struct msn_switchboard *msn_sb_by_handle( struct gaim_connection *gc, char *handle ); -struct msn_switchboard *msn_sb_by_id( struct gaim_connection *gc, int id ); +struct msn_switchboard *msn_sb_by_chat( struct conversation *c ); struct msn_switchboard *msn_sb_spare( struct gaim_connection *gc ); int msn_sb_sendmessage( struct msn_switchboard *sb, char *text ); -void msn_sb_to_chat( struct msn_switchboard *sb ); +struct conversation *msn_sb_to_chat( struct msn_switchboard *sb ); void msn_sb_destroy( struct msn_switchboard *sb ); gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond ); diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index 7ec340bd..8e912273 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -85,16 +85,16 @@ struct msn_switchboard *msn_sb_by_handle( struct gaim_connection *gc, char *hand return( NULL ); } -struct msn_switchboard *msn_sb_by_id( struct gaim_connection *gc, int id ) +struct msn_switchboard *msn_sb_by_chat( struct conversation *c ) { - struct msn_data *md = gc->proto_data; + struct msn_data *md = c->gc->proto_data; struct msn_switchboard *sb; GSList *l; for( l = md->switchboards; l; l = l->next ) { sb = l->data; - if( sb->chat && sb->chat->id == id ) + if( sb->chat == c ) return( sb ); } @@ -176,14 +176,14 @@ int msn_sb_sendmessage( struct msn_switchboard *sb, char *text ) } } -void msn_sb_to_chat( struct msn_switchboard *sb ) +struct conversation *msn_sb_to_chat( struct msn_switchboard *sb ) { struct gaim_connection *gc = sb->gc; char buf[1024]; /* Create the groupchat structure. */ g_snprintf( buf, sizeof( buf ), "MSN groupchat session %d", sb->session ); - sb->chat = serv_got_joined_chat( gc, ++msn_chat_id, buf ); + sb->chat = serv_got_joined_chat( gc, buf ); /* Populate the channel. */ if( sb->who ) add_chat_buddy( sb->chat, sb->who ); @@ -195,6 +195,8 @@ void msn_sb_to_chat( struct msn_switchboard *sb ) g_free( sb->who ); sb->who = NULL; } + + return sb->chat; } void msn_sb_destroy( struct msn_switchboard *sb ) @@ -229,7 +231,7 @@ void msn_sb_destroy( struct msn_switchboard *sb ) if( sb->chat ) { - serv_got_chat_left( gc, sb->chat->id ); + serv_got_chat_left( sb->chat ); } if( sb->handler ) @@ -371,7 +373,7 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) if( num == 1 ) { g_snprintf( buf, sizeof( buf ), "MSN groupchat session %d", sb->session ); - sb->chat = serv_got_joined_chat( gc, ++msn_chat_id, buf ); + sb->chat = serv_got_joined_chat( gc, buf ); g_free( sb->who ); sb->who = NULL; @@ -609,7 +611,7 @@ static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int } else if( sb->chat ) { - serv_got_chat_in( gc, sb->chat->id, cmd[1], 0, body, 0 ); + serv_got_chat_in( sb->chat, cmd[1], 0, body, 0 ); } else { @@ -668,7 +670,7 @@ static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int } else if( sb->chat ) { - serv_got_chat_in( gc, sb->chat->id, cmd[1], 0, buf, 0 ); + serv_got_chat_in( sb->chat, cmd[1], 0, buf, 0 ); } else { -- cgit v1.2.3 From 0da65d5fb37691ed4d31f7ab4058732f1440db6b Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Fri, 30 Mar 2007 22:40:45 -0700 Subject: s/gaim_connection/im_connection/ and some other minor API changes. The rest will come tomorrow. It compiles, I'll leave the real testing up to someone else. ;-) --- protocols/msn/msn.c | 144 +++++++++++++++--------------- protocols/msn/msn.h | 26 +++--- protocols/msn/msn_util.c | 40 ++++----- protocols/msn/ns.c | 224 +++++++++++++++++++++++------------------------ protocols/msn/sb.c | 68 +++++++------- 5 files changed, 251 insertions(+), 251 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index a73d85d4..afc90627 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -28,7 +28,7 @@ static char *msn_set_display_name( set_t *set, char *value ); -static void msn_acc_init( account_t *acc ) +static void msn_init( account_t *acc ) { set_t *s; @@ -38,38 +38,38 @@ static void msn_acc_init( account_t *acc ) static void msn_login( account_t *acc ) { - struct gaim_connection *gc = new_gaim_conn( acc ); + struct im_connection *ic = new_gaim_conn( acc ); struct msn_data *md = g_new0( struct msn_data, 1 ); - gc->proto_data = md; + ic->proto_data = md; md->fd = -1; if( strchr( acc->user, '@' ) == NULL ) { - hide_login_progress( gc, "Invalid account name" ); - signoff( gc ); + hide_login_progress( ic, "Invalid account name" ); + signoff( ic ); return; } - set_login_progress( gc, 1, "Connecting" ); + set_login_progress( ic, 1, "Connecting" ); - md->fd = proxy_connect( "messenger.hotmail.com", 1863, msn_ns_connected, gc ); + md->fd = proxy_connect( "messenger.hotmail.com", 1863, msn_ns_connected, ic ); if( md->fd < 0 ) { - hide_login_progress( gc, "Could not connect to server" ); - signoff( gc ); + hide_login_progress( ic, "Could not connect to server" ); + signoff( ic ); return; } - md->gc = gc; + md->ic = ic; md->away_state = msn_away_state_list; - msn_connections = g_slist_append( msn_connections, gc ); + msn_connections = g_slist_append( msn_connections, ic ); } -static void msn_close( struct gaim_connection *gc ) +static void msn_logout( struct im_connection *ic ) { - struct msn_data *md = gc->proto_data; + struct msn_data *md = ic->proto_data; GSList *l; if( md ) @@ -95,7 +95,7 @@ static void msn_close( struct gaim_connection *gc ) { m = l->data; - serv_got_crap( gc, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who ); + serv_got_crap( ic, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who ); g_free( m->who ); g_free( m->text ); g_free( m ); @@ -110,23 +110,23 @@ static void msn_close( struct gaim_connection *gc ) g_free( md ); } - for( l = gc->permit; l; l = l->next ) + for( l = ic->permit; l; l = l->next ) g_free( l->data ); - g_slist_free( gc->permit ); + g_slist_free( ic->permit ); - for( l = gc->deny; l; l = l->next ) + for( l = ic->deny; l; l = l->next ) g_free( l->data ); - g_slist_free( gc->deny ); + g_slist_free( ic->deny ); - msn_connections = g_slist_remove( msn_connections, gc ); + msn_connections = g_slist_remove( msn_connections, ic ); } -static int msn_send_im( struct gaim_connection *gc, char *who, char *message, int len, int away ) +static int msn_send_im( struct im_connection *ic, char *who, char *message, int away ) { struct msn_switchboard *sb; - struct msn_data *md = gc->proto_data; + struct msn_data *md = ic->proto_data; - if( ( sb = msn_sb_by_handle( gc, who ) ) ) + if( ( sb = msn_sb_by_handle( ic, who ) ) ) { return( msn_sb_sendmessage( sb, message ) ); } @@ -141,7 +141,7 @@ static int msn_send_im( struct gaim_connection *gc, char *who, char *message, in m->text = g_strdup( message ); /* FIXME: *CHECK* the reliability of using spare sb's! */ - if( ( sb = msn_sb_spare( gc ) ) ) + if( ( sb = msn_sb_spare( ic ) ) ) { debug( "Trying to use a spare switchboard to message %s", who ); @@ -159,7 +159,7 @@ static int msn_send_im( struct gaim_connection *gc, char *who, char *message, in /* If we reach this line, there was no spare switchboard, so let's make one. */ g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId ); - if( !msn_write( gc, buf, strlen( buf ) ) ) + if( !msn_write( ic, buf, strlen( buf ) ) ) { g_free( m->who ); g_free( m->text ); @@ -179,7 +179,7 @@ static int msn_send_im( struct gaim_connection *gc, char *who, char *message, in return( 0 ); } -static GList *msn_away_states( struct gaim_connection *gc ) +static GList *msn_away_states( struct im_connection *ic ) { static GList *l = NULL; int i; @@ -191,7 +191,7 @@ static GList *msn_away_states( struct gaim_connection *gc ) return l; } -static char *msn_get_status_string( struct gaim_connection *gc, int number ) +static char *msn_get_status_string( struct im_connection *ic, int number ) { const struct msn_away_state *st = msn_away_state_by_number( number ); @@ -201,10 +201,10 @@ static char *msn_get_status_string( struct gaim_connection *gc, int number ) return( "" ); } -static void msn_set_away( struct gaim_connection *gc, char *state, char *message ) +static void msn_set_away( struct im_connection *ic, char *state, char *message ) { char buf[1024]; - struct msn_data *md = gc->proto_data; + struct msn_data *md = ic->proto_data; const struct msn_away_state *st; if( strcmp( state, GAIM_AWAY_CUSTOM ) == 0 ) @@ -216,41 +216,41 @@ static void msn_set_away( struct gaim_connection *gc, char *state, char *message md->away_state = st; g_snprintf( buf, sizeof( buf ), "CHG %d %s\r\n", ++md->trId, st->code ); - msn_write( gc, buf, strlen( buf ) ); + msn_write( ic, buf, strlen( buf ) ); } -static void msn_set_info( struct gaim_connection *gc, char *info ) +static void msn_set_my_name( struct im_connection *ic, char *info ) { - msn_set_display_name( set_find( &gc->acc->set, "display_name" ), info ); + msn_set_display_name( set_find( &ic->acc->set, "display_name" ), info ); } -static void msn_get_info(struct gaim_connection *gc, char *who) +static void msn_get_info(struct im_connection *ic, char *who) { /* Just make an URL and let the user fetch the info */ - serv_got_crap( gc, "%s\n%s: %s%s", _("User Info"), _("For now, fetch yourself"), PROFILE_URL, who ); + serv_got_crap( ic, "%s\n%s: %s%s", _("User Info"), _("For now, fetch yourself"), PROFILE_URL, who ); } -static void msn_add_buddy( struct gaim_connection *gc, char *who ) +static void msn_add_buddy( struct im_connection *ic, char *who, char *group ) { - msn_buddy_list_add( gc, "FL", who, who ); + msn_buddy_list_add( ic, "FL", who, who ); } -static void msn_remove_buddy( struct gaim_connection *gc, char *who, char *group ) +static void msn_remove_buddy( struct im_connection *ic, char *who, char *group ) { - msn_buddy_list_remove( gc, "FL", who ); + msn_buddy_list_remove( ic, "FL", who ); } -static int msn_chat_send( struct conversation *c, char *message ) +static void msn_chat_send( struct groupchat *c, char *message, int flags ) { struct msn_switchboard *sb = msn_sb_by_chat( c ); if( sb ) - return( msn_sb_sendmessage( sb, message ) ); - else - return( 0 ); + msn_sb_sendmessage( sb, message ); + /* FIXME: Error handling (although this can't happen unless something's + already severely broken) disappeared here! */ } -static void msn_chat_invite( struct conversation *c, char *msg, char *who ) +static void msn_chat_invite( struct groupchat *c, char *msg, char *who ) { struct msn_switchboard *sb = msn_sb_by_chat( c ); char buf[1024]; @@ -262,7 +262,7 @@ static void msn_chat_invite( struct conversation *c, char *msg, char *who ) } } -static void msn_chat_leave( struct conversation *c ) +static void msn_chat_leave( struct groupchat *c ) { struct msn_switchboard *sb = msn_sb_by_chat( c ); @@ -270,13 +270,13 @@ static void msn_chat_leave( struct conversation *c ) msn_sb_write( sb, "OUT\r\n", 5 ); } -static struct conversation *msn_chat_open( struct gaim_connection *gc, char *who ) +static struct groupchat *msn_chat_with( struct im_connection *ic, char *who ) { struct msn_switchboard *sb; - struct msn_data *md = gc->proto_data; + struct msn_data *md = ic->proto_data; char buf[1024]; - if( ( sb = msn_sb_by_handle( gc, who ) ) ) + if( ( sb = msn_sb_by_handle( ic, who ) ) ) { debug( "Converting existing switchboard to %s to a groupchat", who ); return msn_sb_to_chat( sb ); @@ -285,7 +285,7 @@ static struct conversation *msn_chat_open( struct gaim_connection *gc, char *who { struct msn_message *m; - if( ( sb = msn_sb_spare( gc ) ) ) + if( ( sb = msn_sb_spare( ic ) ) ) { debug( "Trying to reuse an existing switchboard as a groupchat with %s", who ); g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, who ); @@ -298,7 +298,7 @@ static struct conversation *msn_chat_open( struct gaim_connection *gc, char *who /* Request a new switchboard. */ g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId ); - if( !msn_write( gc, buf, strlen( buf ) ) ) + if( !msn_write( ic, buf, strlen( buf ) ) ) return( 0 ); /* Create a magic message. This is quite hackish, but who cares? :-P */ @@ -316,43 +316,43 @@ static struct conversation *msn_chat_open( struct gaim_connection *gc, char *who return NULL; } -static void msn_keepalive( struct gaim_connection *gc ) +static void msn_keepalive( struct im_connection *ic ) { - msn_write( gc, "PNG\r\n", strlen( "PNG\r\n" ) ); + msn_write( ic, "PNG\r\n", strlen( "PNG\r\n" ) ); } -static void msn_add_permit( struct gaim_connection *gc, char *who ) +static void msn_add_permit( struct im_connection *ic, char *who ) { - msn_buddy_list_add( gc, "AL", who, who ); + msn_buddy_list_add( ic, "AL", who, who ); } -static void msn_rem_permit( struct gaim_connection *gc, char *who ) +static void msn_rem_permit( struct im_connection *ic, char *who ) { - msn_buddy_list_remove( gc, "AL", who ); + msn_buddy_list_remove( ic, "AL", who ); } -static void msn_add_deny( struct gaim_connection *gc, char *who ) +static void msn_add_deny( struct im_connection *ic, char *who ) { struct msn_switchboard *sb; - msn_buddy_list_add( gc, "BL", who, who ); + msn_buddy_list_add( ic, "BL", who, who ); /* If there's still a conversation with this person, close it. */ - if( ( sb = msn_sb_by_handle( gc, who ) ) ) + if( ( sb = msn_sb_by_handle( ic, who ) ) ) { msn_sb_destroy( sb ); } } -static void msn_rem_deny( struct gaim_connection *gc, char *who ) +static void msn_rem_deny( struct im_connection *ic, char *who ) { - msn_buddy_list_remove( gc, "BL", who ); + msn_buddy_list_remove( ic, "BL", who ); } -static int msn_send_typing( struct gaim_connection *gc, char *who, int typing ) +static int msn_send_typing( struct im_connection *ic, char *who, int typing ) { if( typing ) - return( msn_send_im( gc, who, TYPING_NOTIFICATION_MESSAGE, strlen( TYPING_NOTIFICATION_MESSAGE ), 0 ) ); + return( msn_send_im( ic, who, TYPING_NOTIFICATION_MESSAGE, 0 ) ); else return( 1 ); } @@ -360,26 +360,26 @@ static int msn_send_typing( struct gaim_connection *gc, char *who, int typing ) static char *msn_set_display_name( set_t *set, char *value ) { account_t *acc = set->data; - struct gaim_connection *gc = acc->gc; + struct im_connection *ic = acc->ic; struct msn_data *md; char buf[1024], *fn; /* Double-check. */ - if( gc == NULL ) + if( ic == NULL ) return NULL; - md = gc->proto_data; + md = ic->proto_data; if( strlen( value ) > 129 ) { - serv_got_crap( gc, "Maximum name length exceeded" ); + serv_got_crap( ic, "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_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, ic->username, fn ); + msn_write( ic, buf, strlen( buf ) ); g_free( fn ); /* Returning NULL would be better, because the server still has to @@ -388,26 +388,26 @@ static char *msn_set_display_name( set_t *set, char *value ) return value; } -void msn_init() +void msn_initmodule() { 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->init = msn_init; + ret->logout = msn_logout; ret->send_im = msn_send_im; ret->away_states = msn_away_states; ret->get_status_string = msn_get_status_string; ret->set_away = msn_set_away; - ret->set_info = msn_set_info; ret->get_info = msn_get_info; + ret->set_my_name = msn_set_my_name; ret->add_buddy = msn_add_buddy; ret->remove_buddy = msn_remove_buddy; ret->chat_send = msn_chat_send; ret->chat_invite = msn_chat_invite; ret->chat_leave = msn_chat_leave; - ret->chat_open = msn_chat_open; + ret->chat_with = msn_chat_with; ret->keepalive = msn_keepalive; ret->add_permit = msn_add_permit; ret->rem_permit = msn_rem_permit; diff --git a/protocols/msn/msn.h b/protocols/msn/msn.h index 78cc3caf..721466d6 100644 --- a/protocols/msn/msn.h +++ b/protocols/msn/msn.h @@ -56,7 +56,7 @@ struct msn_data { - struct gaim_connection *gc; + struct im_connection *ic; int fd; struct msn_handler_data *handler; @@ -74,7 +74,7 @@ struct msn_data struct msn_switchboard { - struct gaim_connection *gc; + struct im_connection *ic; int fd; gint inp; @@ -88,7 +88,7 @@ struct msn_switchboard GSList *msgq; char *who; - struct conversation *chat; + struct groupchat *chat; }; struct msn_away_state @@ -148,11 +148,11 @@ GSList *msn_switchboards; gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ); /* msn_util.c */ -int msn_write( struct gaim_connection *gc, char *s, int len ); -int msn_logged_in( struct gaim_connection *gc ); -int msn_buddy_list_add( struct gaim_connection *gc, char *list, char *who, char *realname ); -int msn_buddy_list_remove( struct gaim_connection *gc, char *list, char *who ); -void msn_buddy_ask( struct gaim_connection *gc, char *handle, char *realname ); +int msn_write( struct im_connection *ic, char *s, int len ); +int msn_logged_in( struct im_connection *ic ); +int msn_buddy_list_add( struct im_connection *ic, char *list, char *who, char *realname ); +int msn_buddy_list_remove( struct im_connection *ic, char *list, char *who ); +void msn_buddy_ask( struct im_connection *ic, char *handle, char *realname ); char *msn_findheader( char *text, char *header, int len ); char **msn_linesplit( char *line ); int msn_handler( struct msn_handler_data *h ); @@ -166,11 +166,11 @@ const struct msn_status_code *msn_status_by_number( int number ); /* sb.c */ int msn_sb_write( struct msn_switchboard *sb, char *s, int len ); -struct msn_switchboard *msn_sb_create( struct gaim_connection *gc, char *host, int port, char *key, int session ); -struct msn_switchboard *msn_sb_by_handle( struct gaim_connection *gc, char *handle ); -struct msn_switchboard *msn_sb_by_chat( struct conversation *c ); -struct msn_switchboard *msn_sb_spare( struct gaim_connection *gc ); +struct msn_switchboard *msn_sb_create( struct im_connection *ic, char *host, int port, char *key, int session ); +struct msn_switchboard *msn_sb_by_handle( struct im_connection *ic, char *handle ); +struct msn_switchboard *msn_sb_by_chat( struct groupchat *c ); +struct msn_switchboard *msn_sb_spare( struct im_connection *ic ); int msn_sb_sendmessage( struct msn_switchboard *sb, char *text ); -struct conversation *msn_sb_to_chat( struct msn_switchboard *sb ); +struct groupchat *msn_sb_to_chat( struct msn_switchboard *sb ); void msn_sb_destroy( struct msn_switchboard *sb ); gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond ); diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index ff4c148c..1be1586c 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -27,38 +27,38 @@ #include "msn.h" #include -int msn_write( struct gaim_connection *gc, char *s, int len ) +int msn_write( struct im_connection *ic, char *s, int len ) { - struct msn_data *md = gc->proto_data; + struct msn_data *md = ic->proto_data; int st; st = write( md->fd, s, len ); if( st != len ) { - hide_login_progress_error( gc, "Short write() to main server" ); - signoff( gc ); + hide_login_progress_error( ic, "Short write() to main server" ); + signoff( ic ); return( 0 ); } return( 1 ); } -int msn_logged_in( struct gaim_connection *gc ) +int msn_logged_in( struct im_connection *ic ) { - account_online( gc ); + account_online( ic ); return( 0 ); } -int msn_buddy_list_add( struct gaim_connection *gc, char *list, char *who, char *realname_ ) +int msn_buddy_list_add( struct im_connection *ic, char *list, char *who, char *realname_ ) { - struct msn_data *md = gc->proto_data; + struct msn_data *md = ic->proto_data; char buf[1024], *realname; realname = msn_http_encode( realname_ ); g_snprintf( buf, sizeof( buf ), "ADD %d %s %s %s\r\n", ++md->trId, list, who, realname ); - if( msn_write( gc, buf, strlen( buf ) ) ) + if( msn_write( ic, buf, strlen( buf ) ) ) { g_free( realname ); @@ -70,13 +70,13 @@ int msn_buddy_list_add( struct gaim_connection *gc, char *list, char *who, char return( 0 ); } -int msn_buddy_list_remove( struct gaim_connection *gc, char *list, char *who ) +int msn_buddy_list_remove( struct im_connection *ic, char *list, char *who ) { - struct msn_data *md = gc->proto_data; + struct msn_data *md = ic->proto_data; char buf[1024]; g_snprintf( buf, sizeof( buf ), "REM %d %s %s\r\n", ++md->trId, list, who ); - if( msn_write( gc, buf, strlen( buf ) ) ) + if( msn_write( ic, buf, strlen( buf ) ) ) return( 1 ); return( 0 ); @@ -84,17 +84,17 @@ int msn_buddy_list_remove( struct gaim_connection *gc, char *list, char *who ) struct msn_buddy_ask_data { - struct gaim_connection *gc; + struct im_connection *ic; char *handle; char *realname; }; static void msn_buddy_ask_yes( gpointer w, struct msn_buddy_ask_data *bla ) { - msn_buddy_list_add( bla->gc, "AL", bla->handle, bla->realname ); + msn_buddy_list_add( bla->ic, "AL", bla->handle, bla->realname ); - if( find_buddy( bla->gc, bla->handle ) == NULL ) - show_got_added( bla->gc, bla->handle, NULL ); + if( find_buddy( bla->ic, bla->handle ) == NULL ) + show_got_added( bla->ic, bla->handle, NULL ); g_free( bla->handle ); g_free( bla->realname ); @@ -103,26 +103,26 @@ static void msn_buddy_ask_yes( gpointer w, struct msn_buddy_ask_data *bla ) static void msn_buddy_ask_no( gpointer w, struct msn_buddy_ask_data *bla ) { - msn_buddy_list_add( bla->gc, "BL", bla->handle, bla->realname ); + msn_buddy_list_add( bla->ic, "BL", bla->handle, bla->realname ); g_free( bla->handle ); g_free( bla->realname ); g_free( bla ); } -void msn_buddy_ask( struct gaim_connection *gc, char *handle, char *realname ) +void msn_buddy_ask( struct im_connection *ic, char *handle, char *realname ) { struct msn_buddy_ask_data *bla = g_new0( struct msn_buddy_ask_data, 1 ); char buf[1024]; - bla->gc = gc; + bla->ic = ic; bla->handle = g_strdup( handle ); bla->realname = g_strdup( realname ); g_snprintf( buf, sizeof( buf ), "The user %s (%s) wants to add you to his/her buddy list.", handle, realname ); - do_ask_dialog( gc, buf, bla, msn_buddy_ask_yes, msn_buddy_ask_no ); + do_ask_dialog( ic, buf, bla, msn_buddy_ask_yes, msn_buddy_ask_no ); } char *msn_findheader( char *text, char *header, int len ) diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index 9774f3e2..9d86a68e 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -37,26 +37,26 @@ static void msn_auth_got_passport_id( struct passport_reply *rep ); gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) { - struct gaim_connection *gc = data; + struct im_connection *ic = data; struct msn_data *md; char s[1024]; - if( !g_slist_find( msn_connections, gc ) ) + if( !g_slist_find( msn_connections, ic ) ) return FALSE; if( source == -1 ) { - hide_login_progress( gc, "Could not connect to server" ); - signoff( gc ); + hide_login_progress( ic, "Could not connect to server" ); + signoff( ic ); return FALSE; } - md = gc->proto_data; + md = ic->proto_data; if( !md->handler ) { md->handler = g_new0( struct msn_handler_data, 1 ); - md->handler->data = gc; + md->handler->data = ic; md->handler->exec_command = msn_ns_command; md->handler->exec_message = msn_ns_message; } @@ -72,10 +72,10 @@ gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) md->handler->rxq = g_new0( char, 1 ); g_snprintf( s, sizeof( s ), "VER %d MSNP8 CVR0\r\n", ++md->trId ); - if( msn_write( gc, s, strlen( s ) ) ) + if( msn_write( ic, s, strlen( s ) ) ) { - gc->inpa = b_input_add( md->fd, GAIM_INPUT_READ, msn_ns_callback, gc ); - set_login_progress( gc, 1, "Connected to server, waiting for reply" ); + ic->inpa = b_input_add( md->fd, GAIM_INPUT_READ, msn_ns_callback, ic ); + set_login_progress( ic, 1, "Connected to server, waiting for reply" ); } return FALSE; @@ -83,13 +83,13 @@ gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond ) { - struct gaim_connection *gc = data; - struct msn_data *md = gc->proto_data; + struct im_connection *ic = data; + struct msn_data *md = ic->proto_data; if( msn_handler( md->handler ) == -1 ) /* Don't do this on ret == 0, it's already done then. */ { - hide_login_progress( gc, "Error while reading from server" ); - signoff( gc ); + hide_login_progress( ic, "Error while reading from server" ); + signoff( ic ); return FALSE; } @@ -99,8 +99,8 @@ 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 ) { - struct gaim_connection *gc = data; - struct msn_data *md = gc->proto_data; + struct im_connection *ic = data; + struct msn_data *md = ic->proto_data; char buf[1024]; if( num_parts == 0 ) @@ -113,20 +113,20 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) { if( cmd[2] && strncmp( cmd[2], "MSNP8", 5 ) != 0 ) { - hide_login_progress( gc, "Unsupported protocol" ); - signoff( gc ); + hide_login_progress( ic, "Unsupported protocol" ); + signoff( ic ); return( 0 ); } g_snprintf( buf, sizeof( buf ), "CVR %d 0x0409 mac 10.2.0 ppc macmsgs 3.5.1 macmsgs %s\r\n", - ++md->trId, gc->username ); - return( msn_write( gc, buf, strlen( buf ) ) ); + ++md->trId, ic->username ); + return( msn_write( ic, buf, strlen( buf ) ) ); } else if( strcmp( cmd[0], "CVR" ) == 0 ) { /* We don't give a damn about the information we just received */ - g_snprintf( buf, sizeof( buf ), "USR %d TWN I %s\r\n", ++md->trId, gc->username ); - return( msn_write( gc, buf, strlen( buf ) ) ); + g_snprintf( buf, sizeof( buf ), "USR %d TWN I %s\r\n", ++md->trId, ic->username ); + return( msn_write( ic, buf, strlen( buf ) ) ); } else if( strcmp( cmd[0], "XFR" ) == 0 ) { @@ -135,24 +135,24 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts == 6 && strcmp( cmd[2], "NS" ) == 0 ) { - b_event_remove( gc->inpa ); - gc->inpa = 0; + b_event_remove( ic->inpa ); + ic->inpa = 0; closesocket( md->fd ); server = strchr( cmd[3], ':' ); if( !server ) { - hide_login_progress_error( gc, "Syntax error" ); - signoff( gc ); + hide_login_progress_error( ic, "Syntax error" ); + signoff( ic ); return( 0 ); } *server = 0; port = atoi( server + 1 ); server = cmd[3]; - set_login_progress( gc, 1, "Transferring to other server" ); + set_login_progress( ic, 1, "Transferring to other server" ); - md->fd = proxy_connect( server, port, msn_ns_connected, gc ); + md->fd = proxy_connect( server, port, msn_ns_connected, ic ); } else if( num_parts == 6 && strcmp( cmd[2], "SB" ) == 0 ) { @@ -161,8 +161,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) server = strchr( cmd[3], ':' ); if( !server ) { - hide_login_progress_error( gc, "Syntax error" ); - signoff( gc ); + hide_login_progress_error( ic, "Syntax error" ); + signoff( ic ); return( 0 ); } *server = 0; @@ -171,13 +171,13 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( strcmp( cmd[4], "CKI" ) != 0 ) { - hide_login_progress_error( gc, "Unknown authentication method for switchboard" ); - signoff( gc ); + hide_login_progress_error( ic, "Unknown authentication method for switchboard" ); + signoff( ic ); return( 0 ); } debug( "Connecting to a new switchboard with key %s", cmd[5] ); - sb = msn_sb_create( gc, server, port, cmd[5], MSN_SB_NEW ); + sb = msn_sb_create( ic, server, port, cmd[5], MSN_SB_NEW ); if( md->msgq ) { @@ -203,8 +203,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) } else { - hide_login_progress_error( gc, "Syntax error" ); - signoff( gc ); + hide_login_progress_error( ic, "Syntax error" ); + signoff( ic ); return( 0 ); } } @@ -213,10 +213,10 @@ 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, gc, gc->username, gc->password, cmd[4] ) ) + if( !passport_get_id( msn_auth_got_passport_id, ic, ic->username, ic->password, cmd[4] ) ) { - hide_login_progress_error( gc, "Error while contacting Passport server" ); - signoff( gc ); + hide_login_progress_error( ic, "Error while contacting Passport server" ); + signoff( ic ); return( 0 ); } } @@ -226,24 +226,24 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) http_decode( cmd[4] ); - strncpy( gc->displayname, cmd[4], sizeof( gc->displayname ) ); - gc->displayname[sizeof(gc->displayname)-1] = 0; + strncpy( ic->displayname, cmd[4], sizeof( ic->displayname ) ); + ic->displayname[sizeof(ic->displayname)-1] = 0; - if( ( s = set_find( &gc->acc->set, "display_name" ) ) ) + if( ( s = set_find( &ic->acc->set, "display_name" ) ) ) { g_free( s->value ); s->value = g_strdup( cmd[4] ); } - set_login_progress( gc, 1, "Authenticated, getting buddy list" ); + set_login_progress( ic, 1, "Authenticated, getting buddy list" ); g_snprintf( buf, sizeof( buf ), "SYN %d 0\r\n", ++md->trId ); - return( msn_write( gc, buf, strlen( buf ) ) ); + return( msn_write( ic, buf, strlen( buf ) ) ); } else { - hide_login_progress( gc, "Unknown authentication type" ); - signoff( gc ); + hide_login_progress( ic, "Unknown authentication type" ); + signoff( ic ); return( 0 ); } } @@ -251,8 +251,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) { if( num_parts != 4 ) { - hide_login_progress_error( gc, "Syntax error" ); - signoff( gc ); + hide_login_progress_error( ic, "Syntax error" ); + signoff( ic ); return( 0 ); } @@ -260,8 +260,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( md->handler->msglen <= 0 ) { - hide_login_progress_error( gc, "Syntax error" ); - signoff( gc ); + hide_login_progress_error( ic, "Syntax error" ); + signoff( ic ); return( 0 ); } } @@ -275,14 +275,14 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) md->grouplist = g_new0( char *, md->groupcount ); if( !*cmd[3] || md->buddycount == 0 ) - msn_logged_in( gc ); + msn_logged_in( ic ); } else { /* Hrrm... This SYN reply doesn't really look like something we expected. Let's assume everything is okay. */ - msn_logged_in( gc ); + msn_logged_in( ic ); } } else if( strcmp( cmd[0], "LST" ) == 0 ) @@ -291,8 +291,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 4 && num_parts != 5 ) { - hide_login_progress( gc, "Syntax error" ); - signoff( gc ); + hide_login_progress( ic, "Syntax error" ); + signoff( ic ); return( 0 ); } @@ -307,33 +307,33 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( cmd[4] != NULL && sscanf( cmd[4], "%d", &num ) == 1 ) group = md->grouplist[num]; - add_buddy( gc, group, cmd[1], cmd[2] ); + add_buddy( ic, group, cmd[1], cmd[2] ); } if( list & 2 ) /* AL */ { - gc->permit = g_slist_append( gc->permit, g_strdup( cmd[1] ) ); + ic->permit = g_slist_append( ic->permit, g_strdup( cmd[1] ) ); } if( list & 4 ) /* BL */ { - gc->deny = g_slist_append( gc->deny, g_strdup( cmd[1] ) ); + ic->deny = g_slist_append( ic->deny, g_strdup( cmd[1] ) ); } if( list & 8 ) /* RL */ { if( ( list & 6 ) == 0 ) - msn_buddy_ask( gc, cmd[1], cmd[2] ); + msn_buddy_ask( ic, cmd[1], cmd[2] ); } if( --md->buddycount == 0 ) { - if( gc->flags & OPT_LOGGED_IN ) + if( ic->flags & OPT_LOGGED_IN ) { - serv_got_crap( gc, "Successfully transferred to different server" ); + serv_got_crap( ic, "Successfully transferred to different server" ); g_snprintf( buf, sizeof( buf ), "CHG %d %s %d\r\n", ++md->trId, md->away_state->code, 0 ); - return( msn_write( gc, buf, strlen( buf ) ) ); + return( msn_write( ic, buf, strlen( buf ) ) ); } else { - msn_logged_in( gc ); + msn_logged_in( ic ); } } } @@ -343,8 +343,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 4 ) { - hide_login_progress_error( gc, "Syntax error" ); - signoff( gc ); + hide_login_progress_error( ic, "Syntax error" ); + signoff( ic ); return( 0 ); } @@ -362,8 +362,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 3 ) { - hide_login_progress_error( gc, "Syntax error" ); - signoff( gc ); + hide_login_progress_error( ic, "Syntax error" ); + signoff( ic ); return( 0 ); } @@ -376,7 +376,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) for( i = 0; i < 16; i ++ ) g_snprintf( buf + strlen( buf ), 3, "%02x", digest[i] ); - return( msn_write( gc, buf, strlen( buf ) ) ); + return( msn_write( ic, buf, strlen( buf ) ) ); } else if( strcmp( cmd[0], "ILN" ) == 0 ) { @@ -384,13 +384,13 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 6 ) { - hide_login_progress_error( gc, "Syntax error" ); - signoff( gc ); + hide_login_progress_error( ic, "Syntax error" ); + signoff( ic ); return( 0 ); } http_decode( cmd[4] ); - serv_buddy_rename( gc, cmd[3], cmd[4] ); + serv_buddy_rename( ic, cmd[3], cmd[4] ); st = msn_away_state_by_code( cmd[2] ); if( !st ) @@ -399,12 +399,12 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) st = msn_away_state_list; } - serv_got_update( gc, cmd[3], 1, 0, 0, 0, st->number, 0 ); + serv_got_update( ic, cmd[3], 1, 0, 0, 0, st->number, 0 ); } else if( strcmp( cmd[0], "FLN" ) == 0 ) { if( cmd[1] ) - serv_got_update( gc, cmd[1], 0, 0, 0, 0, 0, 0 ); + serv_got_update( ic, cmd[1], 0, 0, 0, 0, 0, 0 ); } else if( strcmp( cmd[0], "NLN" ) == 0 ) { @@ -412,13 +412,13 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 5 ) { - hide_login_progress_error( gc, "Syntax error" ); - signoff( gc ); + hide_login_progress_error( ic, "Syntax error" ); + signoff( ic ); return( 0 ); } http_decode( cmd[3] ); - serv_buddy_rename( gc, cmd[2], cmd[3] ); + serv_buddy_rename( ic, cmd[2], cmd[3] ); st = msn_away_state_by_code( cmd[1] ); if( !st ) @@ -427,7 +427,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) st = msn_away_state_list; } - serv_got_update( gc, cmd[2], 1, 0, 0, 0, st->number, 0 ); + serv_got_update( ic, cmd[2], 1, 0, 0, 0, st->number, 0 ); } else if( strcmp( cmd[0], "RNG" ) == 0 ) { @@ -437,8 +437,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 7 ) { - hide_login_progress_error( gc, "Syntax error" ); - signoff( gc ); + hide_login_progress_error( ic, "Syntax error" ); + signoff( ic ); return( 0 ); } @@ -447,8 +447,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) server = strchr( cmd[2], ':' ); if( !server ) { - hide_login_progress_error( gc, "Syntax error" ); - signoff( gc ); + hide_login_progress_error( ic, "Syntax error" ); + signoff( ic ); return( 0 ); } *server = 0; @@ -457,14 +457,14 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( strcmp( cmd[3], "CKI" ) != 0 ) { - hide_login_progress_error( gc, "Unknown authentication method for switchboard" ); - signoff( gc ); + hide_login_progress_error( ic, "Unknown authentication method for switchboard" ); + signoff( ic ); return( 0 ); } debug( "Got a call from %s (session %d). Key = %s", cmd[5], session, cmd[4] ); - sb = msn_sb_create( gc, server, port, cmd[4], session ); + sb = msn_sb_create( ic, server, port, cmd[4], session ); sb->who = g_strdup( cmd[5] ); } else if( strcmp( cmd[0], "ADD" ) == 0 ) @@ -477,60 +477,60 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( strchr( cmd[4], '@' ) == NULL ) { - hide_login_progress_error( gc, "Syntax error" ); - signoff( gc ); + hide_login_progress_error( ic, "Syntax error" ); + signoff( ic ); return( 0 ); } /* We got added by someone. If we don't have this person in permit/deny yet, inform the user. */ - for( l = gc->permit; l; l = l->next ) + for( l = ic->permit; l; l = l->next ) if( g_strcasecmp( l->data, cmd[4] ) == 0 ) return( 1 ); - for( l = gc->deny; l; l = l->next ) + for( l = ic->deny; l; l = l->next ) if( g_strcasecmp( l->data, cmd[4] ) == 0 ) return( 1 ); - msn_buddy_ask( gc, cmd[4], cmd[5] ); + msn_buddy_ask( ic, cmd[4], cmd[5] ); } } else if( strcmp( cmd[0], "OUT" ) == 0 ) { if( cmd[1] && strcmp( cmd[1], "OTH" ) == 0 ) { - hide_login_progress_error( gc, "Someone else logged in with your account" ); - gc->wants_to_die = 1; + hide_login_progress_error( ic, "Someone else logged in with your account" ); + ic->wants_to_die = 1; } else if( cmd[1] && strcmp( cmd[1], "SSD" ) == 0 ) { - hide_login_progress_error( gc, "Terminating session because of server shutdown" ); + hide_login_progress_error( ic, "Terminating session because of server shutdown" ); } else { - hide_login_progress_error( gc, "Session terminated by remote server (reason unknown)" ); + hide_login_progress_error( ic, "Session terminated by remote server (reason unknown)" ); } - signoff( gc ); + signoff( ic ); return( 0 ); } else if( strcmp( cmd[0], "REA" ) == 0 ) { if( num_parts != 5 ) { - hide_login_progress_error( gc, "Syntax error" ); - signoff( gc ); + hide_login_progress_error( ic, "Syntax error" ); + signoff( ic ); return( 0 ); } - if( g_strcasecmp( cmd[3], gc->username ) == 0 ) + if( g_strcasecmp( cmd[3], ic->username ) == 0 ) { set_t *s; http_decode( cmd[4] ); - strncpy( gc->displayname, cmd[4], sizeof( gc->displayname ) ); - gc->displayname[sizeof(gc->displayname)-1] = 0; + strncpy( ic->displayname, cmd[4], sizeof( ic->displayname ) ); + ic->displayname[sizeof(ic->displayname)-1] = 0; - if( ( s = set_find( &gc->acc->set, "display_name" ) ) ) + if( ( s = set_find( &ic->acc->set, "display_name" ) ) ) { g_free( s->value ); s->value = g_strdup( cmd[4] ); @@ -540,19 +540,19 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) { /* This is not supposed to happen, but let's handle it anyway... */ http_decode( cmd[4] ); - serv_buddy_rename( gc, cmd[3], cmd[4] ); + serv_buddy_rename( ic, cmd[3], cmd[4] ); } } else if( strcmp( cmd[0], "IPG" ) == 0 ) { - do_error_dialog( gc, "Received IPG command, we don't handle them yet.", "MSN" ); + do_error_dialog( ic, "Received IPG command, we don't handle them yet.", "MSN" ); md->handler->msglen = atoi( cmd[1] ); if( md->handler->msglen <= 0 ) { - hide_login_progress_error( gc, "Syntax error" ); - signoff( gc ); + hide_login_progress_error( ic, "Syntax error" ); + signoff( ic ); return( 0 ); } } @@ -562,11 +562,11 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) const struct msn_status_code *err = msn_status_by_number( num ); g_snprintf( buf, sizeof( buf ), "Error reported by MSN server: %s", err->text ); - do_error_dialog( gc, buf, "MSN" ); + do_error_dialog( ic, buf, "MSN" ); if( err->flags & STATUS_FATAL ) { - signoff( gc ); + signoff( ic ); return( 0 ); } } @@ -580,7 +580,7 @@ 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 ) { - struct gaim_connection *gc = data; + struct im_connection *ic = data; char *body; int blen = 0; @@ -616,7 +616,7 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int if( mtype && strcmp( mtype, "1" ) == 0 ) { if( arg1 ) - serv_got_crap( gc, "The server is going down for maintenance in %s minutes.", arg1 ); + serv_got_crap( ic, "The server is going down for maintenance in %s minutes.", arg1 ); } if( arg1 ) g_free( arg1 ); @@ -633,7 +633,7 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int if( inbox && folders ) { - serv_got_crap( gc, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders ); + serv_got_crap( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders ); } } else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 ) @@ -643,7 +643,7 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int if( from && fromname ) { - serv_got_crap( gc, "Received an e-mail message from %s <%s>.", fromname, from ); + serv_got_crap( ic, "Received an e-mail message from %s <%s>.", fromname, from ); } } else if( g_strncasecmp( ct, "text/x-msmsgsactivemailnotification", 35 ) == 0 ) @@ -664,8 +664,8 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int static void msn_auth_got_passport_id( struct passport_reply *rep ) { - struct gaim_connection *gc = rep->data; - struct msn_data *md = gc->proto_data; + struct im_connection *ic = rep->data; + struct msn_data *md = ic->proto_data; char *key = rep->result; char buf[1024]; @@ -676,14 +676,14 @@ static void msn_auth_got_passport_id( struct passport_reply *rep ) err = g_strdup_printf( "Error during Passport authentication (%s)", rep->error_string ? rep->error_string : "Unknown error" ); - hide_login_progress( gc, err ); - signoff( gc ); + hide_login_progress( ic, err ); + signoff( ic ); g_free( err ); } else { g_snprintf( buf, sizeof( buf ), "USR %d TWN S %s\r\n", ++md->trId, key ); - msn_write( gc, buf, strlen( buf ) ); + msn_write( ic, buf, strlen( buf ) ); } } diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index 8e912273..f9c755a5 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -47,9 +47,9 @@ int msn_sb_write( struct msn_switchboard *sb, char *s, int len ) return( 1 ); } -struct msn_switchboard *msn_sb_create( struct gaim_connection *gc, char *host, int port, char *key, int session ) +struct msn_switchboard *msn_sb_create( struct im_connection *ic, char *host, int port, char *key, int session ) { - struct msn_data *md = gc->proto_data; + struct msn_data *md = ic->proto_data; struct msn_switchboard *sb = g_new0( struct msn_switchboard, 1 ); sb->fd = proxy_connect( host, port, msn_sb_connected, sb ); @@ -59,7 +59,7 @@ struct msn_switchboard *msn_sb_create( struct gaim_connection *gc, char *host, i return( NULL ); } - sb->gc = gc; + sb->ic = ic; sb->key = g_strdup( key ); sb->session = session; @@ -69,9 +69,9 @@ struct msn_switchboard *msn_sb_create( struct gaim_connection *gc, char *host, i return( sb ); } -struct msn_switchboard *msn_sb_by_handle( struct gaim_connection *gc, char *handle ) +struct msn_switchboard *msn_sb_by_handle( struct im_connection *ic, char *handle ) { - struct msn_data *md = gc->proto_data; + struct msn_data *md = ic->proto_data; struct msn_switchboard *sb; GSList *l; @@ -85,9 +85,9 @@ struct msn_switchboard *msn_sb_by_handle( struct gaim_connection *gc, char *hand return( NULL ); } -struct msn_switchboard *msn_sb_by_chat( struct conversation *c ) +struct msn_switchboard *msn_sb_by_chat( struct groupchat *c ) { - struct msn_data *md = c->gc->proto_data; + struct msn_data *md = c->ic->proto_data; struct msn_switchboard *sb; GSList *l; @@ -101,9 +101,9 @@ struct msn_switchboard *msn_sb_by_chat( struct conversation *c ) return( NULL ); } -struct msn_switchboard *msn_sb_spare( struct gaim_connection *gc ) +struct msn_switchboard *msn_sb_spare( struct im_connection *ic ) { - struct msn_data *md = gc->proto_data; + struct msn_data *md = ic->proto_data; struct msn_switchboard *sb; GSList *l; @@ -141,9 +141,9 @@ int msn_sb_sendmessage( struct msn_switchboard *sb, char *text ) } else { - i = strlen( MSN_TYPING_HEADERS ) + strlen( sb->gc->username ); + i = strlen( MSN_TYPING_HEADERS ) + strlen( sb->ic->username ); buf = g_new0( char, i ); - i = g_snprintf( buf, i, MSN_TYPING_HEADERS, sb->gc->username ); + i = g_snprintf( buf, i, MSN_TYPING_HEADERS, sb->ic->username ); } /* Build the final packet (MSG command + the message). */ @@ -176,18 +176,18 @@ int msn_sb_sendmessage( struct msn_switchboard *sb, char *text ) } } -struct conversation *msn_sb_to_chat( struct msn_switchboard *sb ) +struct groupchat *msn_sb_to_chat( struct msn_switchboard *sb ) { - struct gaim_connection *gc = sb->gc; + struct im_connection *ic = sb->ic; char buf[1024]; /* Create the groupchat structure. */ g_snprintf( buf, sizeof( buf ), "MSN groupchat session %d", sb->session ); - sb->chat = serv_got_joined_chat( gc, buf ); + sb->chat = serv_got_joined_chat( ic, buf ); /* Populate the channel. */ if( sb->who ) add_chat_buddy( sb->chat, sb->who ); - add_chat_buddy( sb->chat, gc->username ); + add_chat_buddy( sb->chat, ic->username ); /* And make sure the switchboard doesn't look like a regular chat anymore. */ if( sb->who ) @@ -201,8 +201,8 @@ struct conversation *msn_sb_to_chat( struct msn_switchboard *sb ) void msn_sb_destroy( struct msn_switchboard *sb ) { - struct gaim_connection *gc = sb->gc; - struct msn_data *md = gc->proto_data; + struct im_connection *ic = sb->ic; + struct msn_data *md = ic->proto_data; debug( "Destroying switchboard: %s", sb->who ? sb->who : sb->key ? sb->key : "" ); @@ -221,7 +221,7 @@ void msn_sb_destroy( struct msn_switchboard *sb ) } g_slist_free( sb->msgq ); - serv_got_crap( gc, "Warning: Closing down MSN switchboard connection with " + serv_got_crap( ic, "Warning: Closing down MSN switchboard connection with " "unsent message to %s, you'll have to resend it.", sb->who ? sb->who : "(unknown)" ); } @@ -252,7 +252,7 @@ void msn_sb_destroy( struct msn_switchboard *sb ) gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond ) { struct msn_switchboard *sb = data; - struct gaim_connection *gc; + struct im_connection *ic; struct msn_data *md; char buf[1024]; @@ -260,8 +260,8 @@ gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond ) if( !g_slist_find( msn_switchboards, sb ) ) return FALSE; - gc = sb->gc; - md = gc->proto_data; + ic = sb->ic; + md = ic->proto_data; if( source != sb->fd ) { @@ -279,9 +279,9 @@ gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond ) sb->handler->exec_message = msn_sb_message; if( sb->session == MSN_SB_NEW ) - g_snprintf( buf, sizeof( buf ), "USR %d %s %s\r\n", ++sb->trId, gc->username, sb->key ); + g_snprintf( buf, sizeof( buf ), "USR %d %s %s\r\n", ++sb->trId, ic->username, sb->key ); else - g_snprintf( buf, sizeof( buf ), "ANS %d %s %s %d\r\n", ++sb->trId, gc->username, sb->key, sb->session ); + g_snprintf( buf, sizeof( buf ), "ANS %d %s %s %d\r\n", ++sb->trId, ic->username, sb->key, sb->session ); if( msn_sb_write( sb, buf, strlen( buf ) ) ) sb->inp = b_input_add( sb->fd, GAIM_INPUT_READ, msn_sb_callback, sb ); @@ -309,7 +309,7 @@ static gboolean msn_sb_callback( gpointer data, gint source, b_input_condition c static int msn_sb_command( gpointer data, char **cmd, int num_parts ) { struct msn_switchboard *sb = data; - struct gaim_connection *gc = sb->gc; + struct im_connection *ic = sb->ic; char buf[1024]; if( !num_parts ) @@ -320,8 +320,8 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) if( strcmp( cmd[0], "XFR" ) == 0 ) { - hide_login_progress_error( gc, "Received an XFR from a switchboard server, unable to comply! This is likely to be a bug, please report it!" ); - signoff( gc ); + hide_login_progress_error( ic, "Received an XFR from a switchboard server, unable to comply! This is likely to be a bug, please report it!" ); + signoff( ic ); return( 0 ); } else if( strcmp( cmd[0], "USR" ) == 0 ) @@ -373,7 +373,7 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) if( num == 1 ) { g_snprintf( buf, sizeof( buf ), "MSN groupchat session %d", sb->session ); - sb->chat = serv_got_joined_chat( gc, buf ); + sb->chat = serv_got_joined_chat( ic, buf ); g_free( sb->who ); sb->who = NULL; @@ -383,7 +383,7 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) if( num == tot ) { - add_chat_buddy( sb->chat, gc->username ); + add_chat_buddy( sb->chat, ic->username ); } } } @@ -528,7 +528,7 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) const struct msn_status_code *err = msn_status_by_number( num ); g_snprintf( buf, sizeof( buf ), "Error reported by switchboard server: %s", err->text ); - do_error_dialog( gc, buf, "MSN" ); + do_error_dialog( ic, buf, "MSN" ); if( err->flags & STATUS_SB_FATAL ) { @@ -537,7 +537,7 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) } else if( err->flags & STATUS_FATAL ) { - signoff( gc ); + signoff( ic ); return 0; } else if( err->flags & STATUS_SB_IM_SPARE ) @@ -578,7 +578,7 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts ) { struct msn_switchboard *sb = data; - struct gaim_connection *gc = sb->gc; + struct im_connection *ic = sb->ic; char *body; int blen = 0; @@ -607,7 +607,7 @@ static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int if( sb->who ) { - serv_got_im( gc, cmd[1], body, 0, 0, blen ); + serv_got_im( ic, cmd[1], body, 0, 0, blen ); } else if( sb->chat ) { @@ -666,7 +666,7 @@ static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int if( sb->who ) { - serv_got_im( gc, cmd[1], buf, 0, 0, strlen( buf ) ); + serv_got_im( ic, cmd[1], buf, 0, 0, strlen( buf ) ); } else if( sb->chat ) { @@ -683,7 +683,7 @@ static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int if( who ) { - serv_got_typing( gc, who, 5, 1 ); + serv_got_typing( ic, who, 5, 1 ); g_free( who ); } -- cgit v1.2.3 From aef4828a1dc51de10a43bb7dd5d023de9971295b Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 5 Apr 2007 22:20:31 -0700 Subject: More cleanups, mainly in the callbacks. Replaced things like do_error_dialog() and (set|hide)_login_progress(_error)?() with things that hopefully make more sense. Although it's still not really great... --- protocols/msn/msn.c | 18 +++---- protocols/msn/msn_util.c | 6 +-- protocols/msn/ns.c | 121 +++++++++++++++++++++++------------------------ protocols/msn/sb.c | 11 ++--- 4 files changed, 77 insertions(+), 79 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index afc90627..860be01b 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -38,7 +38,7 @@ static void msn_init( account_t *acc ) static void msn_login( account_t *acc ) { - struct im_connection *ic = new_gaim_conn( acc ); + struct im_connection *ic = imc_new( acc ); struct msn_data *md = g_new0( struct msn_data, 1 ); ic->proto_data = md; @@ -46,18 +46,18 @@ static void msn_login( account_t *acc ) if( strchr( acc->user, '@' ) == NULL ) { - hide_login_progress( ic, "Invalid account name" ); - signoff( ic ); + imc_error( ic, "Invalid account name" ); + imc_logout( ic ); return; } - set_login_progress( ic, 1, "Connecting" ); + imc_log( ic, "Connecting" ); md->fd = proxy_connect( "messenger.hotmail.com", 1863, msn_ns_connected, ic ); if( md->fd < 0 ) { - hide_login_progress( ic, "Could not connect to server" ); - signoff( ic ); + imc_error( ic, "Could not connect to server" ); + imc_logout( ic ); return; } @@ -95,7 +95,7 @@ static void msn_logout( struct im_connection *ic ) { m = l->data; - serv_got_crap( ic, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who ); + imc_log( ic, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who ); g_free( m->who ); g_free( m->text ); g_free( m ); @@ -227,7 +227,7 @@ static void msn_set_my_name( struct im_connection *ic, char *info ) static void msn_get_info(struct im_connection *ic, char *who) { /* Just make an URL and let the user fetch the info */ - serv_got_crap( ic, "%s\n%s: %s%s", _("User Info"), _("For now, fetch yourself"), PROFILE_URL, who ); + imc_log( ic, "%s\n%s: %s%s", _("User Info"), _("For now, fetch yourself"), PROFILE_URL, who ); } static void msn_add_buddy( struct im_connection *ic, char *who, char *group ) @@ -372,7 +372,7 @@ static char *msn_set_display_name( set_t *set, char *value ) if( strlen( value ) > 129 ) { - serv_got_crap( ic, "Maximum name length exceeded" ); + imc_log( ic, "Maximum name length exceeded" ); return NULL; } diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index 1be1586c..72411095 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -35,8 +35,8 @@ int msn_write( struct im_connection *ic, char *s, int len ) st = write( md->fd, s, len ); if( st != len ) { - hide_login_progress_error( ic, "Short write() to main server" ); - signoff( ic ); + imc_error( ic, "Short write() to main server" ); + imc_logout( ic ); return( 0 ); } @@ -45,7 +45,7 @@ int msn_write( struct im_connection *ic, char *s, int len ) int msn_logged_in( struct im_connection *ic ) { - account_online( ic ); + imc_connected( ic ); return( 0 ); } diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index 9d86a68e..e4530b8f 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -46,8 +46,8 @@ gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) if( source == -1 ) { - hide_login_progress( ic, "Could not connect to server" ); - signoff( ic ); + imc_error( ic, "Could not connect to server" ); + imc_logout( ic ); return FALSE; } @@ -75,7 +75,7 @@ gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) if( msn_write( ic, s, strlen( s ) ) ) { ic->inpa = b_input_add( md->fd, GAIM_INPUT_READ, msn_ns_callback, ic ); - set_login_progress( ic, 1, "Connected to server, waiting for reply" ); + imc_log( ic, "Connected to server, waiting for reply" ); } return FALSE; @@ -88,8 +88,8 @@ static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition c if( msn_handler( md->handler ) == -1 ) /* Don't do this on ret == 0, it's already done then. */ { - hide_login_progress( ic, "Error while reading from server" ); - signoff( ic ); + imc_error( ic, "Error while reading from server" ); + imc_logout( ic ); return FALSE; } @@ -113,8 +113,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) { if( cmd[2] && strncmp( cmd[2], "MSNP8", 5 ) != 0 ) { - hide_login_progress( ic, "Unsupported protocol" ); - signoff( ic ); + imc_error( ic, "Unsupported protocol" ); + imc_logout( ic ); return( 0 ); } @@ -142,15 +142,15 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) server = strchr( cmd[3], ':' ); if( !server ) { - hide_login_progress_error( ic, "Syntax error" ); - signoff( ic ); + imc_error( ic, "Syntax error" ); + imc_logout( ic ); return( 0 ); } *server = 0; port = atoi( server + 1 ); server = cmd[3]; - set_login_progress( ic, 1, "Transferring to other server" ); + imc_log( ic, "Transferring to other server" ); md->fd = proxy_connect( server, port, msn_ns_connected, ic ); } @@ -161,8 +161,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) server = strchr( cmd[3], ':' ); if( !server ) { - hide_login_progress_error( ic, "Syntax error" ); - signoff( ic ); + imc_error( ic, "Syntax error" ); + imc_logout( ic ); return( 0 ); } *server = 0; @@ -171,8 +171,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( strcmp( cmd[4], "CKI" ) != 0 ) { - hide_login_progress_error( ic, "Unknown authentication method for switchboard" ); - signoff( ic ); + imc_error( ic, "Unknown authentication method for switchboard" ); + imc_logout( ic ); return( 0 ); } @@ -203,8 +203,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) } else { - hide_login_progress_error( ic, "Syntax error" ); - signoff( ic ); + imc_error( ic, "Syntax error" ); + imc_logout( ic ); return( 0 ); } } @@ -215,8 +215,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) /* Time for some Passport black magic... */ if( !passport_get_id( msn_auth_got_passport_id, ic, ic->username, ic->password, cmd[4] ) ) { - hide_login_progress_error( ic, "Error while contacting Passport server" ); - signoff( ic ); + imc_error( ic, "Error while contacting Passport server" ); + imc_logout( ic ); return( 0 ); } } @@ -235,15 +235,15 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) s->value = g_strdup( cmd[4] ); } - set_login_progress( ic, 1, "Authenticated, getting buddy list" ); + imc_log( ic, "Authenticated, getting buddy list" ); g_snprintf( buf, sizeof( buf ), "SYN %d 0\r\n", ++md->trId ); return( msn_write( ic, buf, strlen( buf ) ) ); } else { - hide_login_progress( ic, "Unknown authentication type" ); - signoff( ic ); + imc_error( ic, "Unknown authentication type" ); + imc_logout( ic ); return( 0 ); } } @@ -251,8 +251,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) { if( num_parts != 4 ) { - hide_login_progress_error( ic, "Syntax error" ); - signoff( ic ); + imc_error( ic, "Syntax error" ); + imc_logout( ic ); return( 0 ); } @@ -260,8 +260,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( md->handler->msglen <= 0 ) { - hide_login_progress_error( ic, "Syntax error" ); - signoff( ic ); + imc_error( ic, "Syntax error" ); + imc_logout( ic ); return( 0 ); } } @@ -291,8 +291,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 4 && num_parts != 5 ) { - hide_login_progress( ic, "Syntax error" ); - signoff( ic ); + imc_error( ic, "Syntax error" ); + imc_logout( ic ); return( 0 ); } @@ -327,7 +327,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) { if( ic->flags & OPT_LOGGED_IN ) { - serv_got_crap( ic, "Successfully transferred to different server" ); + imc_log( ic, "Successfully transferred to different server" ); g_snprintf( buf, sizeof( buf ), "CHG %d %s %d\r\n", ++md->trId, md->away_state->code, 0 ); return( msn_write( ic, buf, strlen( buf ) ) ); } @@ -343,8 +343,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 4 ) { - hide_login_progress_error( ic, "Syntax error" ); - signoff( ic ); + imc_error( ic, "Syntax error" ); + imc_logout( ic ); return( 0 ); } @@ -362,8 +362,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 3 ) { - hide_login_progress_error( ic, "Syntax error" ); - signoff( ic ); + imc_error( ic, "Syntax error" ); + imc_logout( ic ); return( 0 ); } @@ -384,8 +384,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 6 ) { - hide_login_progress_error( ic, "Syntax error" ); - signoff( ic ); + imc_error( ic, "Syntax error" ); + imc_logout( ic ); return( 0 ); } @@ -412,8 +412,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 5 ) { - hide_login_progress_error( ic, "Syntax error" ); - signoff( ic ); + imc_error( ic, "Syntax error" ); + imc_logout( ic ); return( 0 ); } @@ -437,8 +437,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 7 ) { - hide_login_progress_error( ic, "Syntax error" ); - signoff( ic ); + imc_error( ic, "Syntax error" ); + imc_logout( ic ); return( 0 ); } @@ -447,8 +447,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) server = strchr( cmd[2], ':' ); if( !server ) { - hide_login_progress_error( ic, "Syntax error" ); - signoff( ic ); + imc_error( ic, "Syntax error" ); + imc_logout( ic ); return( 0 ); } *server = 0; @@ -457,8 +457,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( strcmp( cmd[3], "CKI" ) != 0 ) { - hide_login_progress_error( ic, "Unknown authentication method for switchboard" ); - signoff( ic ); + imc_error( ic, "Unknown authentication method for switchboard" ); + imc_logout( ic ); return( 0 ); } @@ -477,8 +477,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( strchr( cmd[4], '@' ) == NULL ) { - hide_login_progress_error( ic, "Syntax error" ); - signoff( ic ); + imc_error( ic, "Syntax error" ); + imc_logout( ic ); return( 0 ); } @@ -498,27 +498,27 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) { if( cmd[1] && strcmp( cmd[1], "OTH" ) == 0 ) { - hide_login_progress_error( ic, "Someone else logged in with your account" ); + imc_error( ic, "Someone else logged in with your account" ); ic->wants_to_die = 1; } else if( cmd[1] && strcmp( cmd[1], "SSD" ) == 0 ) { - hide_login_progress_error( ic, "Terminating session because of server shutdown" ); + imc_error( ic, "Terminating session because of server shutdown" ); } else { - hide_login_progress_error( ic, "Session terminated by remote server (reason unknown)" ); + imc_error( ic, "Session terminated by remote server (reason unknown)" ); } - signoff( ic ); + imc_logout( ic ); return( 0 ); } else if( strcmp( cmd[0], "REA" ) == 0 ) { if( num_parts != 5 ) { - hide_login_progress_error( ic, "Syntax error" ); - signoff( ic ); + imc_error( ic, "Syntax error" ); + imc_logout( ic ); return( 0 ); } @@ -545,14 +545,14 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) } else if( strcmp( cmd[0], "IPG" ) == 0 ) { - do_error_dialog( ic, "Received IPG command, we don't handle them yet.", "MSN" ); + imc_error( ic, "Received IPG command, we don't handle them yet." ); md->handler->msglen = atoi( cmd[1] ); if( md->handler->msglen <= 0 ) { - hide_login_progress_error( ic, "Syntax error" ); - signoff( ic ); + imc_error( ic, "Syntax error" ); + imc_logout( ic ); return( 0 ); } } @@ -561,12 +561,11 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) int num = atoi( cmd[0] ); const struct msn_status_code *err = msn_status_by_number( num ); - g_snprintf( buf, sizeof( buf ), "Error reported by MSN server: %s", err->text ); - do_error_dialog( ic, buf, "MSN" ); + imc_error( ic, "Error reported by MSN server: %s", err->text ); if( err->flags & STATUS_FATAL ) { - signoff( ic ); + imc_logout( ic ); return( 0 ); } } @@ -616,7 +615,7 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int if( mtype && strcmp( mtype, "1" ) == 0 ) { if( arg1 ) - serv_got_crap( ic, "The server is going down for maintenance in %s minutes.", arg1 ); + imc_log( ic, "The server is going down for maintenance in %s minutes.", arg1 ); } if( arg1 ) g_free( arg1 ); @@ -633,7 +632,7 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int if( inbox && folders ) { - serv_got_crap( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders ); + imc_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders ); } } else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 ) @@ -643,7 +642,7 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int if( from && fromname ) { - serv_got_crap( ic, "Received an e-mail message from %s <%s>.", fromname, from ); + imc_log( ic, "Received an e-mail message from %s <%s>.", fromname, from ); } } else if( g_strncasecmp( ct, "text/x-msmsgsactivemailnotification", 35 ) == 0 ) @@ -676,8 +675,8 @@ static void msn_auth_got_passport_id( struct passport_reply *rep ) err = g_strdup_printf( "Error during Passport authentication (%s)", rep->error_string ? rep->error_string : "Unknown error" ); - hide_login_progress( ic, err ); - signoff( ic ); + imc_error( ic, err ); + imc_logout( ic ); g_free( err ); } diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index f9c755a5..f7007d32 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -221,7 +221,7 @@ void msn_sb_destroy( struct msn_switchboard *sb ) } g_slist_free( sb->msgq ); - serv_got_crap( ic, "Warning: Closing down MSN switchboard connection with " + imc_log( ic, "Warning: Closing down MSN switchboard connection with " "unsent message to %s, you'll have to resend it.", sb->who ? sb->who : "(unknown)" ); } @@ -320,8 +320,8 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) if( strcmp( cmd[0], "XFR" ) == 0 ) { - hide_login_progress_error( ic, "Received an XFR from a switchboard server, unable to comply! This is likely to be a bug, please report it!" ); - signoff( ic ); + imc_error( ic, "Received an XFR from a switchboard server, unable to comply! This is likely to be a bug, please report it!" ); + imc_logout( ic ); return( 0 ); } else if( strcmp( cmd[0], "USR" ) == 0 ) @@ -527,8 +527,7 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) int num = atoi( cmd[0] ); const struct msn_status_code *err = msn_status_by_number( num ); - g_snprintf( buf, sizeof( buf ), "Error reported by switchboard server: %s", err->text ); - do_error_dialog( ic, buf, "MSN" ); + imc_error( ic, "Error reported by switchboard server: %s", err->text ); if( err->flags & STATUS_SB_FATAL ) { @@ -537,7 +536,7 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) } else if( err->flags & STATUS_FATAL ) { - signoff( ic ); + imc_logout( ic ); return 0; } else if( err->flags & STATUS_SB_IM_SPARE ) -- cgit v1.2.3 From 552e641194147078c7858059df9916d5d548b7a1 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 5 Apr 2007 22:34:23 -0700 Subject: Now that all these functions take format strings, I have to make sure I use that and don't introduce vulnerabilities. :-) --- protocols/msn/ns.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index e4530b8f..81ad1941 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -670,15 +670,9 @@ static void msn_auth_got_passport_id( struct passport_reply *rep ) if( key == NULL ) { - char *err; - - err = g_strdup_printf( "Error during Passport authentication (%s)", - rep->error_string ? rep->error_string : "Unknown error" ); - - imc_error( ic, err ); + imc_error( ic, "Error during Passport authentication (%s)", + rep->error_string ? rep->error_string : "Unknown error" ); imc_logout( ic ); - - g_free( err ); } else { -- cgit v1.2.3 From c2fb38096ea4e75a680e57e103d4a4986aa84c75 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 15 Apr 2007 15:39:35 -0700 Subject: Cleaned up struct im_connection. No more username/password stuff since it's in acc too. wants_to_die is now an argument to imc_logout(). --- protocols/msn/msn.c | 6 ++--- protocols/msn/msn_util.c | 2 +- protocols/msn/ns.c | 62 +++++++++++++++++++++++++----------------------- protocols/msn/sb.c | 16 ++++++------- 4 files changed, 44 insertions(+), 42 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index 860be01b..74a41322 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -47,7 +47,7 @@ static void msn_login( account_t *acc ) if( strchr( acc->user, '@' ) == NULL ) { imc_error( ic, "Invalid account name" ); - imc_logout( ic ); + imc_logout( ic, FALSE ); return; } @@ -57,7 +57,7 @@ static void msn_login( account_t *acc ) if( md->fd < 0 ) { imc_error( ic, "Could not connect to server" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return; } @@ -378,7 +378,7 @@ static char *msn_set_display_name( set_t *set, char *value ) fn = msn_http_encode( value ); - g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, ic->username, fn ); + g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, ic->acc->user, fn ); msn_write( ic, buf, strlen( buf ) ); g_free( fn ); diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index 72411095..67e17b08 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -36,7 +36,7 @@ int msn_write( struct im_connection *ic, char *s, int len ) if( st != len ) { imc_error( ic, "Short write() to main server" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index 81ad1941..77bb4939 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -47,7 +47,7 @@ gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) if( source == -1 ) { imc_error( ic, "Could not connect to server" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return FALSE; } @@ -89,7 +89,7 @@ static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition c if( msn_handler( md->handler ) == -1 ) /* Don't do this on ret == 0, it's already done then. */ { imc_error( ic, "Error while reading from server" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return FALSE; } @@ -114,18 +114,18 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( cmd[2] && strncmp( cmd[2], "MSNP8", 5 ) != 0 ) { imc_error( ic, "Unsupported protocol" ); - imc_logout( ic ); + imc_logout( ic, FALSE ); return( 0 ); } g_snprintf( buf, sizeof( buf ), "CVR %d 0x0409 mac 10.2.0 ppc macmsgs 3.5.1 macmsgs %s\r\n", - ++md->trId, ic->username ); + ++md->trId, ic->acc->user ); return( msn_write( ic, buf, strlen( buf ) ) ); } else if( strcmp( cmd[0], "CVR" ) == 0 ) { /* We don't give a damn about the information we just received */ - g_snprintf( buf, sizeof( buf ), "USR %d TWN I %s\r\n", ++md->trId, ic->username ); + g_snprintf( buf, sizeof( buf ), "USR %d TWN I %s\r\n", ++md->trId, ic->acc->user ); return( msn_write( ic, buf, strlen( buf ) ) ); } else if( strcmp( cmd[0], "XFR" ) == 0 ) @@ -143,7 +143,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( !server ) { imc_error( ic, "Syntax error" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } *server = 0; @@ -162,7 +162,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( !server ) { imc_error( ic, "Syntax error" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } *server = 0; @@ -172,7 +172,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( strcmp( cmd[4], "CKI" ) != 0 ) { imc_error( ic, "Unknown authentication method for switchboard" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } @@ -204,7 +204,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) else { imc_error( ic, "Syntax error" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } } @@ -213,10 +213,10 @@ 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->username, ic->password, cmd[4] ) ) + if( !passport_get_id( msn_auth_got_passport_id, ic, ic->acc->user, ic->acc->pass, cmd[4] ) ) { imc_error( ic, "Error while contacting Passport server" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } } @@ -243,7 +243,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) else { imc_error( ic, "Unknown authentication type" ); - imc_logout( ic ); + imc_logout( ic, FALSE ); return( 0 ); } } @@ -252,7 +252,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 4 ) { imc_error( ic, "Syntax error" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } @@ -261,7 +261,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( md->handler->msglen <= 0 ) { imc_error( ic, "Syntax error" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } } @@ -292,7 +292,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 4 && num_parts != 5 ) { imc_error( ic, "Syntax error" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } @@ -344,7 +344,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 4 ) { imc_error( ic, "Syntax error" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } @@ -363,7 +363,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 3 ) { imc_error( ic, "Syntax error" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } @@ -385,7 +385,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 6 ) { imc_error( ic, "Syntax error" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } @@ -413,7 +413,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 5 ) { imc_error( ic, "Syntax error" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } @@ -438,7 +438,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 7 ) { imc_error( ic, "Syntax error" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } @@ -448,7 +448,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( !server ) { imc_error( ic, "Syntax error" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } *server = 0; @@ -458,7 +458,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( strcmp( cmd[3], "CKI" ) != 0 ) { imc_error( ic, "Unknown authentication method for switchboard" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } @@ -478,7 +478,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( strchr( cmd[4], '@' ) == NULL ) { imc_error( ic, "Syntax error" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } @@ -496,10 +496,12 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) } else if( strcmp( cmd[0], "OUT" ) == 0 ) { + int allow_reconnect = TRUE; + if( cmd[1] && strcmp( cmd[1], "OTH" ) == 0 ) { imc_error( ic, "Someone else logged in with your account" ); - ic->wants_to_die = 1; + allow_reconnect = FALSE; } else if( cmd[1] && strcmp( cmd[1], "SSD" ) == 0 ) { @@ -510,7 +512,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) imc_error( ic, "Session terminated by remote server (reason unknown)" ); } - imc_logout( ic ); + imc_logout( ic, allow_reconnect ); return( 0 ); } else if( strcmp( cmd[0], "REA" ) == 0 ) @@ -518,11 +520,11 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 5 ) { imc_error( ic, "Syntax error" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } - if( g_strcasecmp( cmd[3], ic->username ) == 0 ) + if( g_strcasecmp( cmd[3], ic->acc->user ) == 0 ) { set_t *s; @@ -552,7 +554,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( md->handler->msglen <= 0 ) { imc_error( ic, "Syntax error" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } } @@ -565,7 +567,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( err->flags & STATUS_FATAL ) { - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } } @@ -672,7 +674,7 @@ static void msn_auth_got_passport_id( struct passport_reply *rep ) { imc_error( ic, "Error during Passport authentication (%s)", rep->error_string ? rep->error_string : "Unknown error" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); } else { diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index f7007d32..f8413856 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -141,9 +141,9 @@ int msn_sb_sendmessage( struct msn_switchboard *sb, char *text ) } else { - i = strlen( MSN_TYPING_HEADERS ) + strlen( sb->ic->username ); + i = strlen( MSN_TYPING_HEADERS ) + strlen( sb->ic->acc->user ); buf = g_new0( char, i ); - i = g_snprintf( buf, i, MSN_TYPING_HEADERS, sb->ic->username ); + i = g_snprintf( buf, i, MSN_TYPING_HEADERS, sb->ic->acc->user ); } /* Build the final packet (MSG command + the message). */ @@ -187,7 +187,7 @@ struct groupchat *msn_sb_to_chat( struct msn_switchboard *sb ) /* Populate the channel. */ if( sb->who ) add_chat_buddy( sb->chat, sb->who ); - add_chat_buddy( sb->chat, ic->username ); + add_chat_buddy( sb->chat, ic->acc->user ); /* And make sure the switchboard doesn't look like a regular chat anymore. */ if( sb->who ) @@ -279,9 +279,9 @@ gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond ) sb->handler->exec_message = msn_sb_message; if( sb->session == MSN_SB_NEW ) - g_snprintf( buf, sizeof( buf ), "USR %d %s %s\r\n", ++sb->trId, ic->username, sb->key ); + g_snprintf( buf, sizeof( buf ), "USR %d %s %s\r\n", ++sb->trId, ic->acc->user, sb->key ); else - g_snprintf( buf, sizeof( buf ), "ANS %d %s %s %d\r\n", ++sb->trId, ic->username, sb->key, sb->session ); + g_snprintf( buf, sizeof( buf ), "ANS %d %s %s %d\r\n", ++sb->trId, ic->acc->user, sb->key, sb->session ); if( msn_sb_write( sb, buf, strlen( buf ) ) ) sb->inp = b_input_add( sb->fd, GAIM_INPUT_READ, msn_sb_callback, sb ); @@ -321,7 +321,7 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) if( strcmp( cmd[0], "XFR" ) == 0 ) { imc_error( ic, "Received an XFR from a switchboard server, unable to comply! This is likely to be a bug, please report it!" ); - imc_logout( ic ); + imc_logout( ic, TRUE ); return( 0 ); } else if( strcmp( cmd[0], "USR" ) == 0 ) @@ -383,7 +383,7 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) if( num == tot ) { - add_chat_buddy( sb->chat, ic->username ); + add_chat_buddy( sb->chat, ic->acc->user ); } } } @@ -536,7 +536,7 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) } else if( err->flags & STATUS_FATAL ) { - imc_logout( ic ); + imc_logout( ic, TRUE ); return 0; } else if( err->flags & STATUS_SB_IM_SPARE ) -- cgit v1.2.3 From 84b045d409f1e8da6d8bf379c6fef7236dcd9bcd Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 15 Apr 2007 18:03:08 -0700 Subject: s/imc/imcb/ for callback functions. Moved things aroundin nogaim.h a little bit, grouping things by category instead of original Gaim 0.58 filename. --- protocols/msn/msn.c | 14 +++++----- protocols/msn/msn_util.c | 8 +++--- protocols/msn/ns.c | 70 ++++++++++++++++++++++++------------------------ protocols/msn/sb.c | 6 ++--- 4 files changed, 49 insertions(+), 49 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index 74a41322..676a8ad7 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -38,7 +38,7 @@ static void msn_init( account_t *acc ) static void msn_login( account_t *acc ) { - struct im_connection *ic = imc_new( acc ); + struct im_connection *ic = imcb_new( acc ); struct msn_data *md = g_new0( struct msn_data, 1 ); ic->proto_data = md; @@ -46,17 +46,17 @@ static void msn_login( account_t *acc ) if( strchr( acc->user, '@' ) == NULL ) { - imc_error( ic, "Invalid account name" ); + imcb_error( ic, "Invalid account name" ); imc_logout( ic, FALSE ); return; } - imc_log( ic, "Connecting" ); + imcb_log( ic, "Connecting" ); md->fd = proxy_connect( "messenger.hotmail.com", 1863, msn_ns_connected, ic ); if( md->fd < 0 ) { - imc_error( ic, "Could not connect to server" ); + imcb_error( ic, "Could not connect to server" ); imc_logout( ic, TRUE ); return; } @@ -95,7 +95,7 @@ static void msn_logout( struct im_connection *ic ) { m = l->data; - imc_log( ic, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who ); + imcb_log( ic, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who ); g_free( m->who ); g_free( m->text ); g_free( m ); @@ -227,7 +227,7 @@ static void msn_set_my_name( struct im_connection *ic, char *info ) static void msn_get_info(struct im_connection *ic, char *who) { /* Just make an URL and let the user fetch the info */ - imc_log( ic, "%s\n%s: %s%s", _("User Info"), _("For now, fetch yourself"), PROFILE_URL, who ); + imcb_log( ic, "%s\n%s: %s%s", _("User Info"), _("For now, fetch yourself"), PROFILE_URL, who ); } static void msn_add_buddy( struct im_connection *ic, char *who, char *group ) @@ -372,7 +372,7 @@ static char *msn_set_display_name( set_t *set, char *value ) if( strlen( value ) > 129 ) { - imc_log( ic, "Maximum name length exceeded" ); + imcb_log( ic, "Maximum name length exceeded" ); return NULL; } diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index 67e17b08..80f351a2 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -35,7 +35,7 @@ int msn_write( struct im_connection *ic, char *s, int len ) st = write( md->fd, s, len ); if( st != len ) { - imc_error( ic, "Short write() to main server" ); + imcb_error( ic, "Short write() to main server" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -45,7 +45,7 @@ int msn_write( struct im_connection *ic, char *s, int len ) int msn_logged_in( struct im_connection *ic ) { - imc_connected( ic ); + imcb_connected( ic ); return( 0 ); } @@ -94,7 +94,7 @@ static void msn_buddy_ask_yes( gpointer w, struct msn_buddy_ask_data *bla ) msn_buddy_list_add( bla->ic, "AL", bla->handle, bla->realname ); if( find_buddy( bla->ic, bla->handle ) == NULL ) - show_got_added( bla->ic, bla->handle, NULL ); + imcb_ask_add( bla->ic, bla->handle, NULL ); g_free( bla->handle ); g_free( bla->realname ); @@ -122,7 +122,7 @@ void msn_buddy_ask( struct im_connection *ic, char *handle, char *realname ) g_snprintf( buf, sizeof( buf ), "The user %s (%s) wants to add you to his/her buddy list.", handle, realname ); - do_ask_dialog( ic, buf, bla, msn_buddy_ask_yes, msn_buddy_ask_no ); + imcb_ask( ic, buf, bla, msn_buddy_ask_yes, msn_buddy_ask_no ); } char *msn_findheader( char *text, char *header, int len ) diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index 77bb4939..ba428d82 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -46,7 +46,7 @@ gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) if( source == -1 ) { - imc_error( ic, "Could not connect to server" ); + imcb_error( ic, "Could not connect to server" ); imc_logout( ic, TRUE ); return FALSE; } @@ -75,7 +75,7 @@ gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) if( msn_write( ic, s, strlen( s ) ) ) { ic->inpa = b_input_add( md->fd, GAIM_INPUT_READ, msn_ns_callback, ic ); - imc_log( ic, "Connected to server, waiting for reply" ); + imcb_log( ic, "Connected to server, waiting for reply" ); } return FALSE; @@ -88,7 +88,7 @@ static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition c if( msn_handler( md->handler ) == -1 ) /* Don't do this on ret == 0, it's already done then. */ { - imc_error( ic, "Error while reading from server" ); + imcb_error( ic, "Error while reading from server" ); imc_logout( ic, TRUE ); return FALSE; @@ -113,7 +113,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) { if( cmd[2] && strncmp( cmd[2], "MSNP8", 5 ) != 0 ) { - imc_error( ic, "Unsupported protocol" ); + imcb_error( ic, "Unsupported protocol" ); imc_logout( ic, FALSE ); return( 0 ); } @@ -142,7 +142,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) server = strchr( cmd[3], ':' ); if( !server ) { - imc_error( ic, "Syntax error" ); + imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -150,7 +150,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) port = atoi( server + 1 ); server = cmd[3]; - imc_log( ic, "Transferring to other server" ); + imcb_log( ic, "Transferring to other server" ); md->fd = proxy_connect( server, port, msn_ns_connected, ic ); } @@ -161,7 +161,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) server = strchr( cmd[3], ':' ); if( !server ) { - imc_error( ic, "Syntax error" ); + imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -171,7 +171,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( strcmp( cmd[4], "CKI" ) != 0 ) { - imc_error( ic, "Unknown authentication method for switchboard" ); + imcb_error( ic, "Unknown authentication method for switchboard" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -203,7 +203,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) } else { - imc_error( ic, "Syntax error" ); + imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -215,7 +215,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) /* Time for some Passport black magic... */ if( !passport_get_id( msn_auth_got_passport_id, ic, ic->acc->user, ic->acc->pass, cmd[4] ) ) { - imc_error( ic, "Error while contacting Passport server" ); + imcb_error( ic, "Error while contacting Passport server" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -235,14 +235,14 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) s->value = g_strdup( cmd[4] ); } - imc_log( ic, "Authenticated, getting buddy list" ); + imcb_log( ic, "Authenticated, getting buddy list" ); g_snprintf( buf, sizeof( buf ), "SYN %d 0\r\n", ++md->trId ); return( msn_write( ic, buf, strlen( buf ) ) ); } else { - imc_error( ic, "Unknown authentication type" ); + imcb_error( ic, "Unknown authentication type" ); imc_logout( ic, FALSE ); return( 0 ); } @@ -251,7 +251,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) { if( num_parts != 4 ) { - imc_error( ic, "Syntax error" ); + imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -260,7 +260,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( md->handler->msglen <= 0 ) { - imc_error( ic, "Syntax error" ); + imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -291,7 +291,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 4 && num_parts != 5 ) { - imc_error( ic, "Syntax error" ); + imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -327,7 +327,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) { if( ic->flags & OPT_LOGGED_IN ) { - imc_log( ic, "Successfully transferred to different server" ); + imcb_log( ic, "Successfully transferred to different server" ); g_snprintf( buf, sizeof( buf ), "CHG %d %s %d\r\n", ++md->trId, md->away_state->code, 0 ); return( msn_write( ic, buf, strlen( buf ) ) ); } @@ -343,7 +343,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 4 ) { - imc_error( ic, "Syntax error" ); + imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -362,7 +362,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 3 ) { - imc_error( ic, "Syntax error" ); + imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -384,7 +384,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 6 ) { - imc_error( ic, "Syntax error" ); + imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -412,7 +412,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 5 ) { - imc_error( ic, "Syntax error" ); + imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -437,7 +437,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( num_parts != 7 ) { - imc_error( ic, "Syntax error" ); + imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -447,7 +447,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) server = strchr( cmd[2], ':' ); if( !server ) { - imc_error( ic, "Syntax error" ); + imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -457,7 +457,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( strcmp( cmd[3], "CKI" ) != 0 ) { - imc_error( ic, "Unknown authentication method for switchboard" ); + imcb_error( ic, "Unknown authentication method for switchboard" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -477,7 +477,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( strchr( cmd[4], '@' ) == NULL ) { - imc_error( ic, "Syntax error" ); + imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -500,16 +500,16 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) if( cmd[1] && strcmp( cmd[1], "OTH" ) == 0 ) { - imc_error( ic, "Someone else logged in with your account" ); + imcb_error( ic, "Someone else logged in with your account" ); allow_reconnect = FALSE; } else if( cmd[1] && strcmp( cmd[1], "SSD" ) == 0 ) { - imc_error( ic, "Terminating session because of server shutdown" ); + imcb_error( ic, "Terminating session because of server shutdown" ); } else { - imc_error( ic, "Session terminated by remote server (reason unknown)" ); + imcb_error( ic, "Session terminated by remote server (reason unknown)" ); } imc_logout( ic, allow_reconnect ); @@ -519,7 +519,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) { if( num_parts != 5 ) { - imc_error( ic, "Syntax error" ); + imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -547,13 +547,13 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) } else if( strcmp( cmd[0], "IPG" ) == 0 ) { - imc_error( ic, "Received IPG command, we don't handle them yet." ); + imcb_error( ic, "Received IPG command, we don't handle them yet." ); md->handler->msglen = atoi( cmd[1] ); if( md->handler->msglen <= 0 ) { - imc_error( ic, "Syntax error" ); + imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -563,7 +563,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) int num = atoi( cmd[0] ); const struct msn_status_code *err = msn_status_by_number( num ); - imc_error( ic, "Error reported by MSN server: %s", err->text ); + imcb_error( ic, "Error reported by MSN server: %s", err->text ); if( err->flags & STATUS_FATAL ) { @@ -617,7 +617,7 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int if( mtype && strcmp( mtype, "1" ) == 0 ) { if( arg1 ) - imc_log( ic, "The server is going down for maintenance in %s minutes.", arg1 ); + imcb_log( ic, "The server is going down for maintenance in %s minutes.", arg1 ); } if( arg1 ) g_free( arg1 ); @@ -634,7 +634,7 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int if( inbox && folders ) { - imc_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders ); + imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders ); } } else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 ) @@ -644,7 +644,7 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int if( from && fromname ) { - imc_log( ic, "Received an e-mail message from %s <%s>.", fromname, from ); + imcb_log( ic, "Received an e-mail message from %s <%s>.", fromname, from ); } } else if( g_strncasecmp( ct, "text/x-msmsgsactivemailnotification", 35 ) == 0 ) @@ -672,7 +672,7 @@ static void msn_auth_got_passport_id( struct passport_reply *rep ) if( key == NULL ) { - imc_error( ic, "Error during Passport authentication (%s)", + imcb_error( ic, "Error during Passport authentication (%s)", rep->error_string ? rep->error_string : "Unknown error" ); imc_logout( ic, TRUE ); } diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index f8413856..614fb79c 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -221,7 +221,7 @@ void msn_sb_destroy( struct msn_switchboard *sb ) } g_slist_free( sb->msgq ); - imc_log( ic, "Warning: Closing down MSN switchboard connection with " + imcb_log( ic, "Warning: Closing down MSN switchboard connection with " "unsent message to %s, you'll have to resend it.", sb->who ? sb->who : "(unknown)" ); } @@ -320,7 +320,7 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) if( strcmp( cmd[0], "XFR" ) == 0 ) { - imc_error( ic, "Received an XFR from a switchboard server, unable to comply! This is likely to be a bug, please report it!" ); + imcb_error( ic, "Received an XFR from a switchboard server, unable to comply! This is likely to be a bug, please report it!" ); imc_logout( ic, TRUE ); return( 0 ); } @@ -527,7 +527,7 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) int num = atoi( cmd[0] ); const struct msn_status_code *err = msn_status_by_number( num ); - imc_error( ic, "Error reported by switchboard server: %s", err->text ); + imcb_error( ic, "Error reported by switchboard server: %s", err->text ); if( err->flags & STATUS_SB_FATAL ) { -- cgit v1.2.3 From 6bbb939e953bbe1ca9ed3101a1569abe4521f543 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 15 Apr 2007 21:01:13 -0700 Subject: Split serv_got_update() into imcb_buddy_(status|times). (Well, the second one isn't implemented yet, but I'll do that later.) At last I got rid of the hack called get_status_string(). And now Yahoo seems to mess up away messages... --- protocols/msn/msn.c | 11 ----------- protocols/msn/ns.c | 8 +++++--- 2 files changed, 5 insertions(+), 14 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index 676a8ad7..5eea68af 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -191,16 +191,6 @@ static GList *msn_away_states( struct im_connection *ic ) return l; } -static char *msn_get_status_string( struct im_connection *ic, int number ) -{ - const struct msn_away_state *st = msn_away_state_by_number( number ); - - if( st ) - return( (char*) st->name ); - else - return( "" ); -} - static void msn_set_away( struct im_connection *ic, char *state, char *message ) { char buf[1024]; @@ -398,7 +388,6 @@ void msn_initmodule() ret->logout = msn_logout; ret->send_im = msn_send_im; ret->away_states = msn_away_states; - ret->get_status_string = msn_get_status_string; ret->set_away = msn_set_away; ret->get_info = msn_get_info; ret->set_my_name = msn_set_my_name; diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index ba428d82..c80fc177 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -399,12 +399,13 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) st = msn_away_state_list; } - serv_got_update( ic, cmd[3], 1, 0, 0, 0, st->number, 0 ); + imcb_buddy_status( ic, cmd[3], OPT_LOGGED_IN | + ( st->number ? OPT_AWAY : 0 ), st->name, NULL ); } else if( strcmp( cmd[0], "FLN" ) == 0 ) { if( cmd[1] ) - serv_got_update( ic, cmd[1], 0, 0, 0, 0, 0, 0 ); + imcb_buddy_status( ic, cmd[1], 0, NULL, NULL ); } else if( strcmp( cmd[0], "NLN" ) == 0 ) { @@ -427,7 +428,8 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) st = msn_away_state_list; } - serv_got_update( ic, cmd[2], 1, 0, 0, 0, st->number, 0 ); + imcb_buddy_status( ic, cmd[2], OPT_LOGGED_IN | + ( st->number ? OPT_AWAY : 0 ), st->name, NULL ); } else if( strcmp( cmd[0], "RNG" ) == 0 ) { -- cgit v1.2.3 From 9624fdf0d6f170d8caa7948fb1b3a138b05e1d8c Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Mon, 16 Apr 2007 21:49:17 -0700 Subject: API cleanup pretty much complete. Fixed pretty much everything except the buddy/groupchat related functions. --- protocols/msn/sb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index 614fb79c..c3eaef60 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -606,7 +606,7 @@ static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int if( sb->who ) { - serv_got_im( ic, cmd[1], body, 0, 0, blen ); + imcb_buddy_msg( ic, cmd[1], body, 0, 0 ); } else if( sb->chat ) { @@ -665,7 +665,7 @@ static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int if( sb->who ) { - serv_got_im( ic, cmd[1], buf, 0, 0, strlen( buf ) ); + imcb_buddy_msg( ic, cmd[1], buf, 0, 0 ); } else if( sb->chat ) { @@ -682,7 +682,7 @@ static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int if( who ) { - serv_got_typing( ic, who, 5, 1 ); + imcb_buddy_typing( ic, who, OPT_TYPING ); g_free( who ); } -- cgit v1.2.3 From f0cb961652cbd639e89dcd88a86f20a2414146c4 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Wed, 18 Apr 2007 23:03:43 -0700 Subject: More API changes: buddy list management. imcb_add_buddy() is now a *real* callback, it's only called from inside IM-modules. This makes sure a buddy only gets added to the BitlBee structures if the add was successful. This gets rid of the weirdness described in #55. Unfortunately for now this change breaks A) automatic renaming of ICQ contacts (if there are names stored in the contact list) B) add -tmp. --- protocols/msn/msn_util.c | 2 +- protocols/msn/ns.c | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index 80f351a2..c9eb5ee2 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -93,7 +93,7 @@ static void msn_buddy_ask_yes( gpointer w, struct msn_buddy_ask_data *bla ) { msn_buddy_list_add( bla->ic, "AL", bla->handle, bla->realname ); - if( find_buddy( bla->ic, bla->handle ) == NULL ) + if( imcb_find_buddy( bla->ic, bla->handle ) == NULL ) imcb_ask_add( bla->ic, bla->handle, NULL ); g_free( bla->handle ); diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index c80fc177..9bd7f152 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -304,10 +304,11 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) char *group = NULL; int num; - if( cmd[4] != NULL && sscanf( cmd[4], "%d", &num ) == 1 ) + if( cmd[4] != NULL && sscanf( cmd[4], "%d", &num ) == 1 && num < md->groupcount ) group = md->grouplist[num]; - add_buddy( ic, group, cmd[1], cmd[2] ); + imcb_add_buddy( ic, cmd[1], group ); + imcb_rename_buddy( ic, cmd[1], cmd[2] ); } if( list & 2 ) /* AL */ { @@ -390,7 +391,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) } http_decode( cmd[4] ); - serv_buddy_rename( ic, cmd[3], cmd[4] ); + imcb_rename_buddy( ic, cmd[3], cmd[4] ); st = msn_away_state_by_code( cmd[2] ); if( !st ) @@ -419,7 +420,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) } http_decode( cmd[3] ); - serv_buddy_rename( ic, cmd[2], cmd[3] ); + imcb_rename_buddy( ic, cmd[2], cmd[3] ); st = msn_away_state_by_code( cmd[1] ); if( !st ) @@ -481,20 +482,27 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) { imcb_error( ic, "Syntax error" ); imc_logout( ic, TRUE ); - return( 0 ); + return 0; } - /* We got added by someone. If we don't have this person in permit/deny yet, inform the user. */ + /* We got added by someone. If we don't have this + person in permit/deny yet, inform the user. */ for( l = ic->permit; l; l = l->next ) if( g_strcasecmp( l->data, cmd[4] ) == 0 ) - return( 1 ); + return 1; for( l = ic->deny; l; l = l->next ) if( g_strcasecmp( l->data, cmd[4] ) == 0 ) - return( 1 ); + return 1; msn_buddy_ask( ic, cmd[4], cmd[5] ); } + else if( num_parts >= 6 && strcmp( cmd[2], "FL" ) == 0 ) + { + http_decode( cmd[5] ); + imcb_add_buddy( ic, cmd[4], NULL ); + imcb_rename_buddy( ic, cmd[4], cmd[5] ); + } } else if( strcmp( cmd[0], "OUT" ) == 0 ) { @@ -544,7 +552,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) { /* This is not supposed to happen, but let's handle it anyway... */ http_decode( cmd[4] ); - serv_buddy_rename( ic, cmd[3], cmd[4] ); + imcb_rename_buddy( ic, cmd[3], cmd[4] ); } } else if( strcmp( cmd[0], "IPG" ) == 0 ) -- cgit v1.2.3 From 61ae52c5fbe8fbaf75adb148cd05c357590e8807 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 19 Apr 2007 22:19:06 -0700 Subject: Renamed/slightly changed syntax of groupchat callback functions. --- protocols/msn/sb.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index c3eaef60..1693cb95 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -183,11 +183,11 @@ struct groupchat *msn_sb_to_chat( struct msn_switchboard *sb ) /* Create the groupchat structure. */ g_snprintf( buf, sizeof( buf ), "MSN groupchat session %d", sb->session ); - sb->chat = serv_got_joined_chat( ic, buf ); + sb->chat = imcb_chat_new( ic, buf ); /* Populate the channel. */ - if( sb->who ) add_chat_buddy( sb->chat, sb->who ); - add_chat_buddy( sb->chat, ic->acc->user ); + if( sb->who ) imcb_chat_add_buddy( sb->chat, sb->who ); + imcb_chat_add_buddy( sb->chat, ic->acc->user ); /* And make sure the switchboard doesn't look like a regular chat anymore. */ if( sb->who ) @@ -231,7 +231,7 @@ void msn_sb_destroy( struct msn_switchboard *sb ) if( sb->chat ) { - serv_got_chat_left( sb->chat ); + imcb_chat_removed( sb->chat ); } if( sb->handler ) @@ -373,17 +373,17 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) if( num == 1 ) { g_snprintf( buf, sizeof( buf ), "MSN groupchat session %d", sb->session ); - sb->chat = serv_got_joined_chat( ic, buf ); + sb->chat = imcb_chat_new( ic, buf ); g_free( sb->who ); sb->who = NULL; } - add_chat_buddy( sb->chat, cmd[4] ); + imcb_chat_add_buddy( sb->chat, cmd[4] ); if( num == tot ) { - add_chat_buddy( sb->chat, ic->acc->user ); + imcb_chat_add_buddy( sb->chat, ic->acc->user ); } } } @@ -461,11 +461,11 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) /* This SB is a one-to-one chat right now, but someone else is joining. */ msn_sb_to_chat( sb ); - add_chat_buddy( sb->chat, cmd[1] ); + imcb_chat_add_buddy( sb->chat, cmd[1] ); } else if( sb->chat ) { - add_chat_buddy( sb->chat, cmd[1] ); + imcb_chat_add_buddy( sb->chat, cmd[1] ); sb->ready = 1; } else @@ -515,7 +515,7 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) } else if( sb->chat ) { - remove_chat_buddy( sb->chat, cmd[1], "" ); + imcb_chat_remove_buddy( sb->chat, cmd[1], "" ); } else { @@ -610,7 +610,7 @@ static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int } else if( sb->chat ) { - serv_got_chat_in( sb->chat, cmd[1], 0, body, 0 ); + imcb_chat_msg( sb->chat, cmd[1], body, 0, 0 ); } else { @@ -669,7 +669,7 @@ static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int } else if( sb->chat ) { - serv_got_chat_in( sb->chat, cmd[1], 0, buf, 0 ); + imcb_chat_msg( sb->chat, cmd[1], buf, 0, 0 ); } else { -- cgit v1.2.3 From f6c963b97d3f686ca5410f1896cf8e266b455c22 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Fri, 20 Apr 2007 21:13:21 -0700 Subject: Renamed some more prpl functions. --- protocols/msn/msn.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index 5eea68af..6d774806 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -121,7 +121,7 @@ static void msn_logout( struct im_connection *ic ) msn_connections = g_slist_remove( msn_connections, ic ); } -static int msn_send_im( struct im_connection *ic, char *who, char *message, int away ) +static int msn_buddy_msg( struct im_connection *ic, char *who, char *message, int away ) { struct msn_switchboard *sb; struct msn_data *md = ic->proto_data; @@ -230,7 +230,7 @@ static void msn_remove_buddy( struct im_connection *ic, char *who, char *group ) msn_buddy_list_remove( ic, "FL", who ); } -static void msn_chat_send( struct groupchat *c, char *message, int flags ) +static void msn_chat_msg( struct groupchat *c, char *message, int flags ) { struct msn_switchboard *sb = msn_sb_by_chat( c ); @@ -342,7 +342,7 @@ static void msn_rem_deny( struct im_connection *ic, char *who ) static int msn_send_typing( struct im_connection *ic, char *who, int typing ) { if( typing ) - return( msn_send_im( ic, who, TYPING_NOTIFICATION_MESSAGE, 0 ) ); + return( msn_buddy_msg( ic, who, TYPING_NOTIFICATION_MESSAGE, 0 ) ); else return( 1 ); } @@ -386,14 +386,14 @@ void msn_initmodule() ret->login = msn_login; ret->init = msn_init; ret->logout = msn_logout; - ret->send_im = msn_send_im; + ret->buddy_msg = msn_buddy_msg; ret->away_states = msn_away_states; ret->set_away = msn_set_away; ret->get_info = msn_get_info; ret->set_my_name = msn_set_my_name; ret->add_buddy = msn_add_buddy; ret->remove_buddy = msn_remove_buddy; - ret->chat_send = msn_chat_send; + ret->chat_msg = msn_chat_msg; ret->chat_invite = msn_chat_invite; ret->chat_leave = msn_chat_leave; ret->chat_with = msn_chat_with; -- cgit v1.2.3 From df1fb67d1dbf52d138f63e0d917dda2412d4fc0b Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Fri, 20 Apr 2007 22:18:40 -0700 Subject: Consistency; Using OPT_T(YP|HINK)ING for outgoing typing notfication crap too. --- protocols/msn/msn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index 6d774806..df04e30d 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -341,7 +341,7 @@ static void msn_rem_deny( struct im_connection *ic, char *who ) static int msn_send_typing( struct im_connection *ic, char *who, int typing ) { - if( typing ) + if( typing & OPT_TYPING ) return( msn_buddy_msg( ic, who, TYPING_NOTIFICATION_MESSAGE, 0 ) ); else return( 1 ); -- cgit v1.2.3 From e35d1a121d5fb2da3698fbe4a365fe38d0097665 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 22 Apr 2007 13:44:27 -0700 Subject: Read-only support for Jabber conferences (non-anonymous rooms only). Just don't use this, you're really not going to like it. :-) --- protocols/msn/sb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'protocols/msn') diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index 1693cb95..cb9e2cab 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -231,7 +231,7 @@ void msn_sb_destroy( struct msn_switchboard *sb ) if( sb->chat ) { - imcb_chat_removed( sb->chat ); + imcb_chat_free( sb->chat ); } if( sb->handler ) -- cgit v1.2.3 From c058ff976bbbbf43ef11c262f21440e61244f73e Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 9 Dec 2007 23:19:35 +0000 Subject: Added /invite support for Jabber chatrooms (and fixed the argument order to chat_invite). --- protocols/msn/msn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index df04e30d..aa05dbdd 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -240,7 +240,7 @@ static void msn_chat_msg( struct groupchat *c, char *message, int flags ) already severely broken) disappeared here! */ } -static void msn_chat_invite( struct groupchat *c, char *msg, char *who ) +static void msn_chat_invite( struct groupchat *c, char *who, char *message ) { struct msn_switchboard *sb = msn_sb_by_chat( c ); char buf[1024]; -- cgit v1.2.3 From 3585c5aa1770147dd4a75a5283793d7908573011 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 5 Jan 2008 19:03:02 +0000 Subject: Added handling of MSN switchboard NAK messages. Untested, but hey, it compiles! (And it's pretty trivial...) --- protocols/msn/sb.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'protocols/msn') diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index cb9e2cab..557f4f16 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -490,6 +490,17 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) return( 0 ); } } + else if( strcmp( cmd[0], "NAK" ) == 0 ) + { + if( sb->who ) + { + imcb_log( ic, "The MSN servers could not deliver one of your messages to %s.", sb->who ); + } + else + { + imcb_log( ic, "The MSN servers could not deliver one of your groupchat messages to all participants." ); + } + } else if( strcmp( cmd[0], "BYE" ) == 0 ) { if( num_parts < 2 ) -- cgit v1.2.3 From 1febf5c93b231942cd9cac8ac6a5a0d830c581cc Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 5 Jan 2008 21:15:32 +0000 Subject: Added "mail_notifications" setting. Who needs those notifications anyway? Closes: #338. --- protocols/msn/msn.c | 2 ++ protocols/msn/ns.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index aa05dbdd..192dda0a 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -34,6 +34,8 @@ static void msn_init( account_t *acc ) s = set_add( &acc->set, "display_name", NULL, msn_set_display_name, acc ); s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY; + + s = set_add( &acc->set, "mail_notifications", "false", set_eval_bool, acc ); } static void msn_login( account_t *acc ) diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index 9bd7f152..3735aad6 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -642,7 +642,7 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int char *inbox = msn_findheader( body, "Inbox-Unread:", blen ); char *folders = msn_findheader( body, "Folders-Unread:", blen ); - if( inbox && folders ) + if( inbox && folders && set_getbool( &ic->acc->set, "mail_notifications" ) ) { imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders ); } @@ -652,7 +652,7 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int char *from = msn_findheader( body, "From-Addr:", blen ); char *fromname = msn_findheader( body, "From:", blen ); - if( from && fromname ) + if( from && fromname && set_getbool( &ic->acc->set, "mail_notifications" ) ) { imcb_log( ic, "Received an e-mail message from %s <%s>.", fromname, from ); } -- cgit v1.2.3 From 46dca11bfad72bb9365b85b433f1e812733f31ec Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 6 Jan 2008 12:32:27 +0000 Subject: Changed warning message about unsent MSN messages. It should show the actual message(s) now. --- protocols/msn/msn.c | 16 +--------------- protocols/msn/msn.h | 1 + protocols/msn/msn_util.c | 34 ++++++++++++++++++++++++++++++++++ protocols/msn/sb.c | 41 ++++++----------------------------------- 4 files changed, 42 insertions(+), 50 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index 192dda0a..a2e8519a 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -89,21 +89,7 @@ static void msn_logout( struct im_connection *ic ) while( md->switchboards ) msn_sb_destroy( md->switchboards->data ); - if( md->msgq ) - { - struct msn_message *m; - - for( l = md->msgq; l; l = l->next ) - { - m = l->data; - - imcb_log( ic, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who ); - g_free( m->who ); - g_free( m->text ); - g_free( m ); - } - g_slist_free( md->msgq ); - } + msn_msgq_purge( ic, &md->msgq ); while( md->groupcount > 0 ) g_free( md->grouplist[--md->groupcount] ); diff --git a/protocols/msn/msn.h b/protocols/msn/msn.h index 721466d6..746606a0 100644 --- a/protocols/msn/msn.h +++ b/protocols/msn/msn.h @@ -157,6 +157,7 @@ char *msn_findheader( char *text, char *header, int len ); char **msn_linesplit( char *line ); int msn_handler( struct msn_handler_data *h ); char *msn_http_encode( const char *input ); +void msn_msgq_purge( struct im_connection *ic, GSList **list ); /* tables.c */ const struct msn_away_state *msn_away_state_by_number( int number ); diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index c9eb5ee2..04ee799d 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -338,3 +338,37 @@ char *msn_http_encode( const char *input ) return ret; } + +void msn_msgq_purge( struct im_connection *ic, GSList **list ) +{ + struct msn_message *m; + GString *ret; + GSList *l; + + l = *list; + if( l == NULL ) + return; + + m = l->data; + ret = g_string_sized_new( 1024 ); + g_string_printf( ret, "WARNING: Cleaning up MSN (switchboard) connection with unsent " + "messages to %s:", m->who ? m->who : "unknown recipient" ); + + while( l ) + { + m = l->data; + + g_string_append_printf( ret, "\n%s", m->text ); + + g_free( m->who ); + g_free( m->text ); + g_free( m ); + + l = l->next; + } + g_slist_free( *list ); + *list = NULL; + + imcb_log( ic, ret->str ); + g_string_free( ret, TRUE ); +} diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index 557f4f16..8c0afca6 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -127,7 +127,7 @@ int msn_sb_sendmessage( struct msn_switchboard *sb, char *text ) /* Build the message. Convert LF to CR-LF for normal messages. */ if( strcmp( text, TYPING_NOTIFICATION_MESSAGE ) != 0 ) { - buf = g_new0( char, sizeof( MSN_MESSAGE_HEADERS ) + strlen( text ) * 2 ); + buf = g_new0( char, sizeof( MSN_MESSAGE_HEADERS ) + strlen( text ) * 2 + 1 ); i = strlen( MSN_MESSAGE_HEADERS ); strcpy( buf, MSN_MESSAGE_HEADERS ); @@ -206,25 +206,7 @@ void msn_sb_destroy( struct msn_switchboard *sb ) debug( "Destroying switchboard: %s", sb->who ? sb->who : sb->key ? sb->key : "" ); - if( sb->msgq ) - { - struct msn_message *m; - GSList *l; - - for( l = sb->msgq; l; l = l->next ) - { - m = l->data; - - g_free( m->who ); - g_free( m->text ); - g_free( m ); - } - g_slist_free( sb->msgq ); - - imcb_log( ic, "Warning: Closing down MSN switchboard connection with " - "unsent message to %s, you'll have to resend it.", - sb->who ? sb->who : "(unknown)" ); - } + msn_msgq_purge( ic, &sb->msgq ); if( sb->key ) g_free( sb->key ); if( sb->who ) g_free( sb->who ); @@ -265,7 +247,7 @@ gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond ) if( source != sb->fd ) { - debug( "ERROR %d while connecting to switchboard server", 1 ); + debug( "Error %d while connecting to switchboard server", 1 ); msn_sb_destroy( sb ); return FALSE; } @@ -286,7 +268,7 @@ gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond ) if( msn_sb_write( sb, buf, strlen( buf ) ) ) sb->inp = b_input_add( sb->fd, GAIM_INPUT_READ, msn_sb_callback, sb ); else - debug( "ERROR %d while connecting to switchboard server", 2 ); + debug( "Error %d while connecting to switchboard server", 2 ); return FALSE; } @@ -297,7 +279,7 @@ static gboolean msn_sb_callback( gpointer data, gint source, b_input_condition c if( msn_handler( sb->handler ) == -1 ) { - debug( "ERROR: Switchboard died" ); + debug( "Error: Switchboard died" ); msn_sb_destroy( sb ); return FALSE; @@ -554,24 +536,13 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) { if( sb->who ) { - struct msn_message *m; - GSList *l; - /* Apparently some invitation failed. We might want to use this board later, so keep it as a spare. */ g_free( sb->who ); sb->who = NULL; /* Also clear the msgq, otherwise someone else might get them. */ - for( l = sb->msgq; l; l = l->next ) - { - m = l->data; - g_free( m->who ); - g_free( m->text ); - g_free( m ); - } - g_slist_free( sb->msgq ); - sb->msgq = NULL; + msn_msgq_purge( ic, &sb->msgq ); } /* Do NOT return 0 here, we want to keep this sb. */ -- cgit v1.2.3 From 434627083613f016d432462fce73f728dd77172e Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 6 Jan 2008 12:37:55 +0000 Subject: More consistency in error/warning errors. Until now "WARNING:" was usually in upper case while "Error:" wasn't .... that doesn't really make sense. --- protocols/msn/msn_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index 04ee799d..fae2877d 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -351,7 +351,7 @@ void msn_msgq_purge( struct im_connection *ic, GSList **list ) m = l->data; ret = g_string_sized_new( 1024 ); - g_string_printf( ret, "WARNING: Cleaning up MSN (switchboard) connection with unsent " + g_string_printf( ret, "Warning: Cleaning up MSN (switchboard) connection with unsent " "messages to %s:", m->who ? m->who : "unknown recipient" ); while( l ) -- cgit v1.2.3 From 59f527b6eefaae452533170f52a96903ef63a209 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 12 Jan 2008 17:24:38 +0000 Subject: When a switchboard connection dies (at the TCP level) and there are still queued messages, they will now be moved back to the main queue and a new sb will be created to try to send the messages again. I hope this will solve some/most/all of the "Closing switchboard with unsent messages" problems, but can't be sure since this problem isn't very easy to reproduce. At least it should solve the ones caused by keeping spare switchboards around. Also enabling switchboard debugging output if configured with --debug=1, at least for now this will be useful. --- protocols/msn/msn.h | 10 +++++----- protocols/msn/sb.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 5 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/msn.h b/protocols/msn/msn.h index 746606a0..c8f4f4c6 100644 --- a/protocols/msn/msn.h +++ b/protocols/msn/msn.h @@ -28,11 +28,9 @@ #define TYPING_NOTIFICATION_MESSAGE "\r\r\rBEWARE, ME R TYPINK MESSAGE!!!!\r\r\r" #define GROUPCHAT_SWITCHBOARD_MESSAGE "\r\r\rME WANT TALK TO MANY PEOPLE\r\r\r" -#ifdef _WIN32 -#define debug +#ifdef DEBUG +#define debug( text... ) imcb_log( ic, text ); #else -#define debug( text... ) irc_usermsg( IRC, text ); -#undef debug #define debug( text... ) #endif @@ -65,8 +63,10 @@ struct msn_data GSList *msgq; GSList *switchboards; - const struct msn_away_state *away_state; + int sb_failures; + time_t first_sb_failure; + const struct msn_away_state *away_state; int buddycount; int groupcount; char **grouplist; diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index 8c0afca6..cdf2e8ad 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -276,16 +276,59 @@ gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond ) static gboolean msn_sb_callback( gpointer data, gint source, b_input_condition cond ) { struct msn_switchboard *sb = data; + struct im_connection *ic = sb->ic; + struct msn_data *md = ic->proto_data; if( msn_handler( sb->handler ) == -1 ) { + time_t now = time( NULL ); + + if( now - md->first_sb_failure > 600 ) + { + /* It's not really the first one, but the start of this "series". + With this, the warning below will be shown only if this happens + at least three times in ten minutes. This algorithm isn't + perfect, but for this purpose it will do. */ + md->first_sb_failure = now; + md->sb_failures = 0; + } + debug( "Error: Switchboard died" ); + if( ++ md->sb_failures >= 3 ) + imcb_log( ic, "Warning: Many switchboard failures on MSN connection. " + "There might be problems delivering your messages." ); + + if( sb->msgq != NULL ) + { + char buf[1024]; + + if( md->msgq == NULL ) + { + md->msgq = sb->msgq; + } + else + { + GSList *l; + + for( l = md->msgq; l->next; l = l->next ); + l->next = sb->msgq; + } + sb->msgq = NULL; + + debug( "Moved queued messages back to the main queue, creating a new switchboard to retry." ); + g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId ); + if( !msn_write( ic, buf, strlen( buf ) ) ) + return FALSE; + } + msn_sb_destroy( sb ); return FALSE; } else + { return TRUE; + } } static int msn_sb_command( gpointer data, char **cmd, int num_parts ) -- cgit v1.2.3 From 8ff0a61e7389db201ff4534f267225af6f66736b Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 3 Feb 2008 17:11:15 +0000 Subject: Disabling "Unknown command" warnings since they're very noisy and pretty pointless. --- protocols/msn/ns.c | 2 +- protocols/msn/sb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index 3735aad6..0bb84a74 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -583,7 +583,7 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) } else { - debug( "Received unknown command from main server: %s", cmd[0] ); + /* debug( "Received unknown command from main server: %s", cmd[0] ); */ } return( 1 ); diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index cdf2e8ad..18c41ef5 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -593,7 +593,7 @@ static int msn_sb_command( gpointer data, char **cmd, int num_parts ) } else { - debug( "Received unknown command from switchboard server: %s", cmd[0] ); + /* debug( "Received unknown command from switchboard server: %s", cmd[0] ); */ } return( 1 ); -- cgit v1.2.3 From fc5cf88448d4337d1a5fde418df1c6206a9b0ea2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 16 Feb 2008 16:45:12 +0100 Subject: Fix lcov dependencies. --- protocols/msn/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'protocols/msn') diff --git a/protocols/msn/Makefile b/protocols/msn/Makefile index 3440658d..6a588613 100644 --- a/protocols/msn/Makefile +++ b/protocols/msn/Makefile @@ -17,7 +17,7 @@ LFLAGS += -r # [SH] Phony targets all: msn_mod.o check: all -lcov: +lcov: check gcov: gcov *.c -- cgit v1.2.3 From e6648bf3b821ae40c0640857aae069bc0f5d90c4 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 17 Feb 2008 11:16:01 +0000 Subject: Replaced old MSN Passport (v1.4) authentication code with what's described on http://msnpiki.msnfanatic.com/index.php/MSNP13:SOAPTweener . This was an attempt to fix bug #360, but it didn't. However, this change may make BitlBee a little bit more future-proof. Plus, the code is tidier and sometimes faster than the old mechanism. --- protocols/msn/ns.c | 30 +++--- protocols/msn/passport.c | 275 ++++++++++++++++++----------------------------- protocols/msn/passport.h | 91 +++++++++++++--- 3 files changed, 200 insertions(+), 196 deletions(-) (limited to 'protocols/msn') diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index 0bb84a74..ff7da6ed 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 ) { @@ -213,7 +213,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 ); @@ -673,22 +673,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 ); } } diff --git a/protocols/msn/passport.c b/protocols/msn/passport.c index 9fe6a174..7a15c3fe 100644 --- a/protocols/msn/passport.c +++ b/protocols/msn/passport.c @@ -1,8 +1,7 @@ -/* passport.c +/** passport.c * - * Functions to login to microsoft passport service for Messenger - * Copyright (C) 2004 Wouter Paesen - * Copyright (C) 2004 Wilmer van der Gaast + * Functions to login to Microsoft Passport service for Messenger + * Copyright (C) 2004-2008 Wilmer van der Gaast * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 @@ -23,208 +22,144 @@ #include "passport.h" #include "msn.h" #include "bitlbee.h" +#include "url.h" +#include "misc.h" +#include "xmltree.h" #include #include -#define MSN_BUF_LEN 8192 +static int passport_get_token_real( struct msn_auth_data *mad ); +static void passport_get_token_ready( struct http_request *req ); -static char *prd_cached = NULL; - -static int passport_get_id_real( gpointer func, gpointer data, char *header ); -static void passport_get_id_ready( struct http_request *req ); - -static int passport_retrieve_dalogin( gpointer data, gpointer func, char *header ); -static void passport_retrieve_dalogin_ready( struct http_request *req ); - -static char *passport_create_header( char *cookie, char *email, char *pwd ); -static void destroy_reply( struct passport_reply *rep ); - -int passport_get_id( gpointer func, gpointer data, char *username, char *password, char *cookie ) +int passport_get_token( gpointer func, gpointer data, char *username, char *password, char *cookie ) { - char *header = passport_create_header( cookie, username, password ); + struct msn_auth_data *mad = g_new0( struct msn_auth_data, 1 ); + int i; - if( prd_cached == NULL ) - return passport_retrieve_dalogin( func, data, header ); - else - return passport_get_id_real( func, data, header ); + mad->username = g_strdup( username ); + mad->password = g_strdup( password ); + mad->cookie = g_strdup( cookie ); + + mad->callback = func; + mad->data = data; + + mad->url = g_strdup( SOAP_AUTHENTICATION_URL ); + mad->ttl = 3; /* Max. # of redirects. */ + + /* HTTP-escape stuff and s/,/&/ */ + http_decode( mad->cookie ); + for( i = 0; mad->cookie[i]; i ++ ) + if( mad->cookie[i] == ',' ) + mad->cookie[i] = '&'; + + return passport_get_token_real( mad ); } -static int passport_get_id_real( gpointer func, gpointer data, char *header ) +static int passport_get_token_real( struct msn_auth_data *mad ) { - struct passport_reply *rep; - char *server, *dummy, *reqs; + char *post_payload, *post_request; struct http_request *req; + url_t url; - rep = g_new0( struct passport_reply, 1 ); - rep->data = data; - rep->func = func; - rep->header = header; - - server = g_strdup( prd_cached ); - dummy = strchr( server, '/' ); - - if( dummy == NULL ) - { - destroy_reply( rep ); - return( 0 ); - } - - reqs = g_strdup_printf( "GET %s HTTP/1.0\r\n%s\r\n\r\n", dummy, header ); + url_set( &url, mad->url ); - *dummy = 0; - req = http_dorequest( server, 443, 1, reqs, passport_get_id_ready, rep ); + post_payload = g_markup_printf_escaped( SOAP_AUTHENTICATION_PAYLOAD, + mad->username, + mad->password, + mad->cookie ); - g_free( server ); - g_free( reqs ); + post_request = g_strdup_printf( SOAP_AUTHENTICATION_REQUEST, + url.file, url.host, + (int) strlen( post_payload ), + post_payload ); + + req = http_dorequest( url.host, url.port, 1, post_request, + passport_get_token_ready, mad ); - if( req == NULL ) - destroy_reply( rep ); + g_free( post_request ); + g_free( post_payload ); - return( req != NULL ); + return req != NULL; } -static void passport_get_id_ready( struct http_request *req ) +static xt_status passport_xt_extract_token( struct xt_node *node, gpointer data ); +static xt_status passport_xt_handle_fault( struct xt_node *node, gpointer data ); + +static const struct xt_handler_entry passport_xt_handlers[] = { + { "wsse:BinarySecurityToken", "wst:RequestedSecurityToken", passport_xt_extract_token }, + { "S:Fault", "S:Envelope", passport_xt_handle_fault }, + { NULL, NULL, NULL } +}; + +static void passport_get_token_ready( struct http_request *req ) { - struct passport_reply *rep = req->data; + struct msn_auth_data *mad = req->data; + struct xt_parser *parser; - if( !g_slist_find( msn_connections, rep->data ) ) - { - destroy_reply( rep ); - return; - } + g_free( mad->url ); + g_free( mad->error ); + mad->url = mad->error = NULL; - if( req->finished && req->reply_headers && req->status_code == 200 ) + if( req->status_code == 200 ) { - char *dummy; - - if( ( dummy = strstr( req->reply_headers, "from-PP='" ) ) ) - { - char *responseend; - - dummy += strlen( "from-PP='" ); - responseend = strchr( dummy, '\'' ); - if( responseend ) - *responseend = 0; - - rep->result = g_strdup( dummy ); - } - else - { - rep->error_string = g_strdup( "Could not parse Passport server response" ); - } + parser = xt_new( passport_xt_handlers, mad ); + xt_feed( parser, req->reply_body, req->body_size ); + xt_handle( parser, NULL, -1 ); + xt_free( parser ); } else { - rep->error_string = g_strdup_printf( "HTTP error: %s", - req->status_string ? req->status_string : "Unknown error" ); + mad->error = g_strdup_printf( "HTTP error %d (%s)", req->status_code, + req->status_string ? req->status_string : "unknown" ); } - rep->func( rep ); - destroy_reply( rep ); -} - -static char *passport_create_header( char *cookie, char *email, char *pwd ) -{ - char *buffer; - char *currenttoken; - char *email_enc, *pwd_enc; - - currenttoken = strstr( cookie, "lc=" ); - if( currenttoken == NULL ) - return NULL; - - email_enc = g_new0( char, strlen( email ) * 3 + 1 ); - strcpy( email_enc, email ); - http_encode( email_enc ); - - pwd_enc = g_new0( char, strlen( pwd ) * 3 + 1 ); - strcpy( pwd_enc, pwd ); - http_encode( pwd_enc ); - - buffer = g_strdup_printf( "Authorization: Passport1.4 OrgVerb=GET," - "OrgURL=http%%3A%%2F%%2Fmessenger%%2Emsn%%2Ecom," - "sign-in=%s,pwd=%s,%s", email_enc, pwd_enc, - currenttoken ); - - g_free( email_enc ); - g_free( pwd_enc ); + if( mad->error == NULL && mad->token == NULL ) + mad->error = g_strdup( "Could not parse Passport server response" ); - return buffer; + if( mad->url && mad->token == NULL ) + { + passport_get_token_real( mad ); + } + else + { + mad->callback( mad ); + + g_free( mad->url ); + g_free( mad->username ); + g_free( mad->password ); + g_free( mad->cookie ); + g_free( mad->token ); + g_free( mad->error ); + g_free( mad ); + } } -static int passport_retrieve_dalogin( gpointer func, gpointer data, char *header ) +static xt_status passport_xt_extract_token( struct xt_node *node, gpointer data ) { - struct passport_reply *rep = g_new0( struct passport_reply, 1 ); - struct http_request *req; + struct msn_auth_data *mad = data; + char *s; - rep->data = data; - rep->func = func; - rep->header = header; + if( ( s = xt_find_attr( node, "Id" ) ) && strcmp( s, "PPToken1" ) == 0 ) + mad->token = g_memdup( node->text, node->text_len + 1 ); - req = http_dorequest_url( "https://nexus.passport.com/rdr/pprdr.asp", passport_retrieve_dalogin_ready, rep ); - - if( !req ) - destroy_reply( rep ); - - return( req != NULL ); + return XT_HANDLED; } -static void passport_retrieve_dalogin_ready( struct http_request *req ) +static xt_status passport_xt_handle_fault( struct xt_node *node, gpointer data ) { - struct passport_reply *rep = req->data; - char *dalogin; - char *urlend; + struct msn_auth_data *mad = data; + struct xt_node *code = xt_find_node( node->children, "faultcode" ); + struct xt_node *string = xt_find_node( node->children, "faultstring" ); + struct xt_node *redirect = xt_find_node( node->children, "psf:redirectUrl" ); - if( !g_slist_find( msn_connections, rep->data ) ) - { - destroy_reply( rep ); - return; - } - - if( !req->finished || !req->reply_headers || req->status_code != 200 ) - { - rep->error_string = g_strdup_printf( "HTTP error while fetching DALogin: %s", - req->status_string ? req->status_string : "Unknown error" ); - goto failure; - } + if( redirect && redirect->text_len && mad->ttl-- > 0 ) + mad->url = g_memdup( redirect->text, redirect->text_len + 1 ); - dalogin = strstr( req->reply_headers, "DALogin=" ); - - if( !dalogin ) - { - rep->error_string = g_strdup( "Parse error while fetching DALogin" ); - goto failure; - } - - dalogin += strlen( "DALogin=" ); - urlend = strchr( dalogin, ',' ); - if( urlend ) - *urlend = 0; - - /* strip the http(s):// part from the url */ - urlend = strstr( urlend, "://" ); - if( urlend ) - dalogin = urlend + strlen( "://" ); - - if( prd_cached == NULL ) - prd_cached = g_strdup( dalogin ); - - if( passport_get_id_real( rep->func, rep->data, rep->header ) ) - { - rep->header = NULL; - destroy_reply( rep ); - return; - } + if( code == NULL || code->text_len == 0 ) + mad->error = g_strdup( "Unknown error" ); + else + mad->error = g_strdup_printf( "%s (%s)", code->text, string && string->text_len ? + string->text : "no description available" ); -failure: - rep->func( rep ); - destroy_reply( rep ); -} - -static void destroy_reply( struct passport_reply *rep ) -{ - g_free( rep->result ); - g_free( rep->header ); - g_free( rep->error_string ); - g_free( rep ); + return XT_HANDLED; } diff --git a/protocols/msn/passport.h b/protocols/msn/passport.h index 9fd81a82..1d0c6edc 100644 --- a/protocols/msn/passport.h +++ b/protocols/msn/passport.h @@ -1,10 +1,7 @@ -#ifndef __PASSPORT_H__ -#define __PASSPORT_H__ /* passport.h * - * Functions to login to Microsoft Passport Service for Messenger - * Copyright (C) 2004 Wouter Paesen , - * Wilmer van der Gaast + * Functions to login to Microsoft Passport service for Messenger + * Copyright (C) 2004-2008 Wilmer van der Gaast * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 @@ -17,9 +14,15 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* Thanks to http://msnpiki.msnfanatic.com/index.php/MSNP13:SOAPTweener + for the specs! */ + +#ifndef __PASSPORT_H__ +#define __PASSPORT_H__ + #include #include #include @@ -32,15 +35,77 @@ #endif #include "nogaim.h" -struct passport_reply +struct msn_auth_data { - void (*func)( struct passport_reply * ); - void *data; - char *result; - char *header; - char *error_string; + char *url; + int ttl; + + char *username; + char *password; + char *cookie; + + /* The end result, the only thing we'll really be interested in + once finished. */ + char *token; + char *error; /* Yeah, or that... */ + + void (*callback)( struct msn_auth_data *mad ); + gpointer data; }; -int passport_get_id( gpointer func, gpointer data, char *username, char *password, char *cookie ); +#define SOAP_AUTHENTICATION_URL "https://loginnet.passport.com/RST.srf" + +#define SOAP_AUTHENTICATION_REQUEST \ +"POST %s HTTP/1.0\r\n" \ +"Accept: text/*\r\n" \ +"User-Agent: BitlBee " BITLBEE_VERSION "\r\n" \ +"Host: %s\r\n" \ +"Content-Length: %d\r\n" \ +"Cache-Control: no-cache\r\n" \ +"\r\n" \ +"%s" + +#define SOAP_AUTHENTICATION_PAYLOAD \ +"" \ +"" \ + "
" \ + "" \ + "{7108E71A-9926-4FCB-BCC9-9A9D3F32E423}" \ + "4" \ + "1" \ + "" \ + "AQAAAAIAAABsYwQAAAAzMDg0" \ + "" \ + "" \ + "" \ + "%s" \ + "%s" \ + "" \ + "" \ + "
" \ + "" \ + "" \ + "" \ + "http://schemas.xmlsoap.org/ws/2004/04/security/trust/Issue" \ + "" \ + "" \ + "http://Passport.NET/tb" \ + "" \ + "" \ + "" \ + "" \ + "http://schemas.xmlsoap.org/ws/2004/04/security/trust/Issue" \ + "" \ + "" \ + "messenger.msn.com" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ +"
" + +int passport_get_token( gpointer func, gpointer data, char *username, char *password, char *cookie ); #endif /* __PASSPORT_H__ */ -- cgit v1.2.3 From 9186d15356a46576fb5b306f49a6acdb64fb7622 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 17 Feb 2008 11:26:44 +0000 Subject: Automatically truncate MSN passports to 16 characters because that's the maximum supported by MSN and giving a longer password will make the authentication fail. --- protocols/msn/passport.c | 5 +++++ protocols/msn/passport.h | 2 ++ 2 files changed, 7 insertions(+) (limited to 'protocols/msn') diff --git a/protocols/msn/passport.c b/protocols/msn/passport.c index 7a15c3fe..565d15f3 100644 --- a/protocols/msn/passport.c +++ b/protocols/msn/passport.c @@ -52,6 +52,11 @@ int passport_get_token( gpointer func, gpointer data, char *username, char *pass if( mad->cookie[i] == ',' ) mad->cookie[i] = '&'; + /* Microsoft doesn't allow password longer than 16 chars and silently + fails authentication if you give the "full version" of your passwd. */ + if( strlen( mad->password ) > MAX_PASSPORT_PWLEN ) + mad->password[MAX_PASSPORT_PWLEN] = 0; + return passport_get_token_real( mad ); } diff --git a/protocols/msn/passport.h b/protocols/msn/passport.h index 1d0c6edc..517d2e91 100644 --- a/protocols/msn/passport.h +++ b/protocols/msn/passport.h @@ -35,6 +35,8 @@ #endif #include "nogaim.h" +#define MAX_PASSPORT_PWLEN 16 + struct msn_auth_data { char *url; -- cgit v1.2.3