aboutsummaryrefslogtreecommitdiffstats
path: root/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'protocols')
-rw-r--r--protocols/msn/msn.c16
-rw-r--r--protocols/msn/msn.h1
-rw-r--r--protocols/msn/msn_util.c34
-rw-r--r--protocols/msn/sb.c41
4 files changed, 42 insertions, 50 deletions
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. */