diff options
Diffstat (limited to 'protocols/msn')
| -rw-r--r-- | protocols/msn/msn.c | 22 | ||||
| -rw-r--r-- | protocols/msn/msn.h | 7 | ||||
| -rw-r--r-- | protocols/msn/msn_util.c | 8 | ||||
| -rw-r--r-- | protocols/msn/ns.c | 74 | ||||
| -rw-r--r-- | protocols/msn/tables.c | 37 | 
5 files changed, 76 insertions, 72 deletions
diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index b17a0bfa..3a8b8f7b 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -26,6 +26,10 @@  #include "nogaim.h"  #include "msn.h" +int msn_chat_id; +GSList *msn_connections; +GSList *msn_switchboards; +  static char *msn_set_display_name( set_t *set, char *value );  static void msn_init( account_t *acc ) @@ -142,8 +146,9 @@ static GList *msn_away_states( struct im_connection *ic )  	int i;  	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 ); +		for( i = 0; *msn_away_state_list[i].code; i ++ ) +			if( *msn_away_state_list[i].name ) +				l = g_list_append( l, (void*) msn_away_state_list[i].name );  	return l;  } @@ -152,17 +157,14 @@ static void msn_set_away( struct im_connection *ic, char *state, char *message )  {  	char buf[1024];  	struct msn_data *md = ic->proto_data; -	const struct msn_away_state *st; -	if( strcmp( state, GAIM_AWAY_CUSTOM ) == 0 ) -		st = msn_away_state_by_name( "Away" ); +	if( state ) +		md->away_state = msn_away_state_by_name( state ) ? : +		                 msn_away_state_list + 1;  	else -		st = msn_away_state_by_name( state ); -	 -	if( !st ) st = msn_away_state_list; -	md->away_state = st; +		md->away_state = msn_away_state_list; -	g_snprintf( buf, sizeof( buf ), "CHG %d %s\r\n", ++md->trId, st->code ); +	g_snprintf( buf, sizeof( buf ), "CHG %d %s\r\n", ++md->trId, md->away_state->code );  	msn_write( ic, buf, strlen( buf ) );  } diff --git a/protocols/msn/msn.h b/protocols/msn/msn.h index e2badbf9..50f273ad 100644 --- a/protocols/msn/msn.h +++ b/protocols/msn/msn.h @@ -97,7 +97,6 @@ struct msn_switchboard  struct msn_away_state  { -	int number;  	char code[4];  	char name[16];  }; @@ -136,7 +135,7 @@ struct msn_handler_data  #define STATUS_SB_IM_SPARE	4	/* Make one-to-one conversation switchboard available again, invite failed. */  #define STATUS_SB_CHAT_SPARE	8	/* Same, but also for groupchats (not used yet). */ -int msn_chat_id; +extern int msn_chat_id;  extern const struct msn_away_state msn_away_state_list[];  extern const struct msn_status_code msn_status_code_list[]; @@ -145,8 +144,8 @@ extern const struct msn_status_code msn_status_code_list[];     is down already (for example, when an impatient user disabled the     connection), the callback should check whether it's still listed here     before doing *anything* else. */ -GSList *msn_connections; -GSList *msn_switchboards; +extern GSList *msn_connections; +extern GSList *msn_switchboards;  /* ns.c */  gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ); diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index 58ad22f8..668a8b8a 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -170,9 +170,9 @@ char *msn_findheader( char *text, char *header, int len )  		while( i < len && ( text[i] == '\r' || text[i] == '\n' ) ) i ++;  		/* End of headers? */ -		if( strncmp( text + i - 2, "\n\n", 2 ) == 0 || -		    strncmp( text + i - 4, "\r\n\r\n", 4 ) == 0 || -		    strncmp( text + i - 2, "\r\r", 2 ) == 0 ) +		if( ( i >= 4 && strncmp( text + i - 4, "\r\n\r\n", 4 ) == 0 ) || +		    ( i >= 2 && ( strncmp( text + i - 2, "\n\n", 2 ) == 0 ||    +		                  strncmp( text + i - 2, "\r\r", 2 ) == 0 ) ) )  		{  			break;  		} @@ -373,6 +373,6 @@ void msn_msgq_purge( struct im_connection *ic, GSList **list )  	g_slist_free( *list );  	*list = NULL; -	imcb_log( ic, ret->str ); +	imcb_log( ic, "%s", ret->str );  	g_string_free( ret, TRUE );  } diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index fe48f96d..d78d753a 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -228,19 +228,26 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts )  				return( 0 );  			}  		} -		else if( num_parts == 7 && strcmp( cmd[2], "OK" ) == 0 ) +		else if( num_parts >= 7 && strcmp( cmd[2], "OK" ) == 0 )  		{  			set_t *s; -			http_decode( cmd[4] ); -			 -			strncpy( ic->displayname, cmd[4], sizeof( ic->displayname ) ); -			ic->displayname[sizeof(ic->displayname)-1] = 0; -			 -			if( ( s = set_find( &ic->acc->set, "display_name" ) ) ) +			if( num_parts == 7 )  			{ -				g_free( s->value ); -				s->value = g_strdup( cmd[4] ); +				http_decode( cmd[4] ); +				 +				strncpy( ic->displayname, cmd[4], sizeof( ic->displayname ) ); +				ic->displayname[sizeof(ic->displayname)-1] = 0; +				 +				if( ( s = set_find( &ic->acc->set, "display_name" ) ) ) +				{ +					g_free( s->value ); +					s->value = g_strdup( cmd[4] ); +				} +			} +			else +			{ +				imcb_log( ic, "Warning: Friendly name in server response was corrupted" );  			}  			imcb_log( ic, "Authenticated, getting buddy list" ); @@ -419,11 +426,12 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts )  		if( !st )  		{  			/* FIXME: Warn/Bomb about unknown away state? */ -			st = msn_away_state_list; +			st = msn_away_state_list + 1;  		} -		imcb_buddy_status( ic, cmd[3], OPT_LOGGED_IN | -		                   ( st->number ? OPT_AWAY : 0 ), st->name, NULL ); +		imcb_buddy_status( ic, cmd[3], OPT_LOGGED_IN |  +		                   ( st != msn_away_state_list ? OPT_AWAY : 0 ), +		                   st->name, NULL );  	}  	else if( strcmp( cmd[0], "FLN" ) == 0 )  	{ @@ -448,11 +456,12 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts )  		if( !st )  		{  			/* FIXME: Warn/Bomb about unknown away state? */ -			st = msn_away_state_list; +			st = msn_away_state_list + 1;  		} -		imcb_buddy_status( ic, cmd[2], OPT_LOGGED_IN | -		                   ( st->number ? OPT_AWAY : 0 ), st->name, NULL ); +		imcb_buddy_status( ic, cmd[2], OPT_LOGGED_IN |  +		                   ( st != msn_away_state_list ? OPT_AWAY : 0 ), +		                   st->name, NULL );  	}  	else if( strcmp( cmd[0], "RNG" ) == 0 )  	{ @@ -662,8 +671,8 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int  						imcb_log( ic, "The server is going down for maintenance in %s minutes.", arg1 );  				} -				if( arg1 ) g_free( arg1 ); -				if( mtype ) g_free( mtype ); +				g_free( arg1 ); +				g_free( mtype );  			}  			else if( g_strncasecmp( ct, "text/x-msmsgsprofile", 20 ) == 0 )  			{ @@ -671,25 +680,30 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int  			}  			else if( g_strncasecmp( ct, "text/x-msmsgsinitialemailnotification", 37 ) == 0 )  			{ -				char *inbox = msn_findheader( body, "Inbox-Unread:", blen ); -				char *folders = msn_findheader( body, "Folders-Unread:", blen ); -				 -				if( inbox && folders && set_getbool( &ic->acc->set, "mail_notifications" ) ) +				if( set_getbool( &ic->acc->set, "mail_notifications" ) )  				{ -					imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders ); +					char *inbox = msn_findheader( body, "Inbox-Unread:", blen ); +					char *folders = msn_findheader( body, "Folders-Unread:", blen ); + +					if( inbox && folders ) +						imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders ); +					 +					g_free( inbox ); +					g_free( folders );  				} -				 -				g_free( inbox ); -				g_free( folders );  			}  			else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 )  			{ -				char *from = msn_findheader( body, "From-Addr:", blen ); -				char *fromname = msn_findheader( body, "From:", blen ); -				 -				if( from && fromname && set_getbool( &ic->acc->set, "mail_notifications" ) ) +				if( set_getbool( &ic->acc->set, "mail_notifications" ) )  				{ -					imcb_log( ic, "Received an e-mail message from %s <%s>.", fromname, from ); +					char *from = msn_findheader( body, "From-Addr:", blen ); +					char *fromname = msn_findheader( body, "From:", blen ); +					 +					if( from && fromname ) +						imcb_log( ic, "Received an e-mail message from %s <%s>.", fromname, from ); + +					g_free( from ); +					g_free( fromname );  				}  			}  			else if( g_strncasecmp( ct, "text/x-msmsgsactivemailnotification", 35 ) == 0 ) diff --git a/protocols/msn/tables.c b/protocols/msn/tables.c index 5ba9ea73..42b12aa9 100644 --- a/protocols/msn/tables.c +++ b/protocols/msn/tables.c @@ -28,48 +28,37 @@  const struct msn_away_state msn_away_state_list[] =  { -	{  0, "NLN", "Available" }, -	{  1, "BSY", "Busy" }, -	{  3, "IDL", "Idle" }, -	{  5, "BRB", "Be Right Back" }, -	{  7, "AWY", "Away" }, -	{  9, "PHN", "On the Phone" }, -	{ 11, "LUN", "Out to Lunch" }, -	{ 13, "HDN", "Hidden" }, -	{ -1, "",    "" } +	{ "NLN", "" }, +	{ "AWY", "Away" }, +	{ "BSY", "Busy" }, +	{ "IDL", "Idle" }, +	{ "BRB", "Be Right Back" }, +	{ "PHN", "On the Phone" }, +	{ "LUN", "Out to Lunch" }, +	{ "HDN", "Hidden" }, +	{ "",    "" }  }; -const struct msn_away_state *msn_away_state_by_number( int number ) -{ -	int i; -	 -	for( i = 0; msn_away_state_list[i].number > -1; i ++ ) -		if( msn_away_state_list[i].number == number ) -			return( msn_away_state_list + i ); -	 -	return( NULL ); -} -  const struct msn_away_state *msn_away_state_by_code( char *code )  {  	int i; -	for( i = 0; msn_away_state_list[i].number > -1; i ++ ) +	for( i = 0; *msn_away_state_list[i].code; i ++ )  		if( g_strcasecmp( msn_away_state_list[i].code, code ) == 0 )  			return( msn_away_state_list + i ); -	return( NULL ); +	return NULL;  }  const struct msn_away_state *msn_away_state_by_name( char *name )  {  	int i; -	for( i = 0; msn_away_state_list[i].number > -1; i ++ ) +	for( i = 0; *msn_away_state_list[i].code; i ++ )  		if( g_strcasecmp( msn_away_state_list[i].name, name ) == 0 )  			return( msn_away_state_list + i ); -	return( NULL ); +	return NULL;  }  const struct msn_status_code msn_status_code_list[] =  | 
