diff options
Diffstat (limited to 'protocols/nogaim.c')
| -rw-r--r-- | protocols/nogaim.c | 219 | 
1 files changed, 145 insertions, 74 deletions
| diff --git a/protocols/nogaim.c b/protocols/nogaim.c index 62669aaf..75c2139b 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -1,7 +1,7 @@    /********************************************************************\    * BitlBee -- An IRC to other IM-networks gateway                     *    *                                                                    * -  * Copyright 2002-2006 Wilmer van der Gaast and others                * +  * Copyright 2002-2010 Wilmer van der Gaast and others                *    \********************************************************************/  /* @@ -32,9 +32,11 @@  */  #define BITLBEE_CORE -#include "nogaim.h"  #include <ctype.h> +#include "nogaim.h" +#include "chat.h" +  static int remove_chat_buddy_silent( struct groupchat *b, const char *handle );  GSList *connections; @@ -248,6 +250,8 @@ static gboolean send_keepalive( gpointer d, gint fd, b_input_condition cond )  void imcb_connected( struct im_connection *ic )  { +	irc_t *irc = ic->irc; +	struct chat *c;  	user_t *u;  	/* MSN servers sometimes redirect you to a different server and do @@ -263,9 +267,21 @@ void imcb_connected( struct im_connection *ic )  	ic->keepalive = b_timeout_add( 60000, send_keepalive, ic );  	ic->flags |= OPT_LOGGED_IN; -	/* Also necessary when we're not away, at least for some of the -	   protocols. */ -	imc_set_away( ic, u->away ); +	/* Necessary to send initial presence status, even if we're not away. */ +	imc_away_send_update( ic ); +	 +	/* Apparently we're connected successfully, so reset the +	   exponential backoff timer. */ +	ic->acc->auto_reconnect_delay = 0; +	 +	for( c = irc->chatrooms; c; c = c->next ) +	{ +		if( c->acc != ic->acc ) +			continue; +		 +		if( set_getbool( &c->set, "auto_join" ) ) +			chat_join( irc, c, NULL ); +	}  }  gboolean auto_reconnect( gpointer data, gint fd, b_input_condition cond ) @@ -289,6 +305,7 @@ void imc_logout( struct im_connection *ic, int allow_reconnect )  	irc_t *irc = ic->irc;  	user_t *t, *u;  	account_t *a; +	int delay;  	/* Nested calls might happen sometimes, this is probably the best  	   place to catch them. */ @@ -304,6 +321,9 @@ void imc_logout( struct im_connection *ic, int allow_reconnect )  	ic->acc->prpl->logout( ic );  	b_event_remove( ic->inpa ); +	g_free( ic->away ); +	ic->away = NULL; +	  	u = irc->users;  	while( u )  	{ @@ -328,10 +348,9 @@ void imc_logout( struct im_connection *ic, int allow_reconnect )  		/* Uhm... This is very sick. */  	}  	else if( allow_reconnect && set_getbool( &irc->set, "auto_reconnect" ) && -	         set_getbool( &a->set, "auto_reconnect" ) ) +	         set_getbool( &a->set, "auto_reconnect" ) && +	         ( delay = account_reconnect_delay( a ) ) > 0 )  	{ -		int delay = set_getint( &irc->set, "auto_reconnect_delay" ); -		  		imcb_log( ic, "Reconnecting in %d seconds..", delay );  		a->reconnect = b_timeout_add( delay * 1000, auto_reconnect, a );  	} @@ -428,6 +447,7 @@ struct buddy *imcb_find_buddy( struct im_connection *ic, char *handle )  void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char *realname )  {  	user_t *u = user_findhandle( ic, handle ); +	char *set;  	if( !u || !realname ) return; @@ -440,6 +460,23 @@ void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char  		if( ( ic->flags & OPT_LOGGED_IN ) && set_getbool( &ic->irc->set, "display_namechanges" ) )  			imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname );  	} +	 +	set = set_getstr( &ic->acc->set, "nick_source" ); +	if( strcmp( set, "handle" ) != 0 ) +	{ +		char *name = g_strdup( realname ); +		 +		if( strcmp( set, "first_name" ) == 0 ) +		{ +			int i; +			for( i = 0; name[i] && !isspace( name[i] ); i ++ ) {} +			name[i] = '\0'; +		} +		 +		imcb_buddy_nick_hint( ic, handle, name ); +		 +		g_free( name ); +	}  }  void imcb_remove_buddy( struct im_connection *ic, const char *handle, char *group ) @@ -452,7 +489,7 @@ void imcb_remove_buddy( struct im_connection *ic, const char *handle, char *grou  /* Mainly meant for ICQ (and now also for Jabber conferences) to allow IM     modules to suggest a nickname for a handle. */ -void imcb_buddy_nick_hint( struct im_connection *ic, char *handle, char *nick ) +void imcb_buddy_nick_hint( struct im_connection *ic, const char *handle, const char *nick )  {  	user_t *u = user_findhandle( ic, handle );  	char newnick[MAX_NICK_LENGTH+1], *orig_nick; @@ -487,33 +524,70 @@ void imcb_buddy_nick_hint( struct im_connection *ic, char *handle, char *nick )  	}  } -/* prpl.c */ -struct show_got_added_data +struct imcb_ask_cb_data  {  	struct im_connection *ic;  	char *handle;  }; -void show_got_added_no( void *data ) +static void imcb_ask_auth_cb_no( void *data ) +{ +	struct imcb_ask_cb_data *cbd = data; +	 +	cbd->ic->acc->prpl->auth_deny( cbd->ic, cbd->handle ); +	 +	g_free( cbd->handle ); +	g_free( cbd ); +} + +static void imcb_ask_auth_cb_yes( void *data ) +{ +	struct imcb_ask_cb_data *cbd = data; +	 +	cbd->ic->acc->prpl->auth_allow( cbd->ic, cbd->handle ); +	 +	g_free( cbd->handle ); +	g_free( cbd ); +} + +void imcb_ask_auth( struct im_connection *ic, const char *handle, const char *realname ) +{ +	struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 ); +	char *s, *realname_ = NULL; +	 +	if( realname != NULL ) +		realname_ = g_strdup_printf( " (%s)", realname ); +	 +	s = g_strdup_printf( "The user %s%s wants to add you to his/her buddy list.", +	                     handle, realname_ ?: "" ); +	 +	g_free( realname_ ); +	 +	data->ic = ic; +	data->handle = g_strdup( handle ); +	query_add( ic->irc, ic, s, imcb_ask_auth_cb_yes, imcb_ask_auth_cb_no, data ); +} + + +static void imcb_ask_add_cb_no( void *data )  { -	g_free( ((struct show_got_added_data*)data)->handle ); +	g_free( ((struct imcb_ask_cb_data*)data)->handle );  	g_free( data );  } -void show_got_added_yes( void *data ) +static void imcb_ask_add_cb_yes( void *data )  { -	struct show_got_added_data *sga = data; +	struct imcb_ask_cb_data *cbd = data; -	sga->ic->acc->prpl->add_buddy( sga->ic, sga->handle, NULL ); -	/* imcb_add_buddy( sga->ic, NULL, sga->handle, sga->handle ); */ +	cbd->ic->acc->prpl->add_buddy( cbd->ic, cbd->handle, NULL ); -	return show_got_added_no( data ); +	return imcb_ask_add_cb_no( data );  } -void imcb_ask_add( struct im_connection *ic, char *handle, const char *realname ) +void imcb_ask_add( struct im_connection *ic, const char *handle, const char *realname )  { -	struct show_got_added_data *data = g_new0( struct show_got_added_data, 1 ); +	struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 );  	char *s;  	/* TODO: Make a setting for this! */ @@ -524,7 +598,7 @@ void imcb_ask_add( struct im_connection *ic, char *handle, const char *realname  	data->ic = ic;  	data->handle = g_strdup( handle ); -	query_add( ic->irc, ic, s, show_got_added_yes, show_got_added_no, data ); +	query_add( ic->irc, ic, s, imcb_ask_add_cb_yes, imcb_ask_add_cb_no, data );  } @@ -923,14 +997,10 @@ char *set_eval_away_devoice( set_t *set, char *value )  	irc_t *irc = set->data;  	int st; -	if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) ) -		st = 1; -	else if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) ) -		st = 0; -	else if( sscanf( value, "%d", &st ) != 1 ) -		return( NULL ); +	if( !is_bool( value ) ) +		return SET_INVALID; -	st = st != 0; +	st = bool2int( value );  	/* Horror.... */ @@ -974,7 +1044,7 @@ char *set_eval_away_devoice( set_t *set, char *value )  		                                            irc->channel, pm, v, list );  	} -	return( set_eval_bool( set, value ) ); +	return value;  } @@ -1016,51 +1086,30 @@ int imc_chat_msg( struct groupchat *c, char *msg, int flags )  	return 1;  } -static char *imc_away_alias_find( GList *gcm, char *away ); +static char *imc_away_state_find( GList *gcm, char *away, char **message ); -int imc_set_away( struct im_connection *ic, char *away ) +int imc_away_send_update( struct im_connection *ic )  { -	GList *m, *ms; -	char *s; -	 -	if( !away ) away = ""; -	ms = m = ic->acc->prpl->away_states( ic ); -	 -	while( m ) -	{ -		if( *away ) -		{ -			if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) -				break; -		} -		else -		{ -			if( g_strcasecmp( m->data, "Available" ) == 0 ) -				break; -			if( g_strcasecmp( m->data, "Online" ) == 0 ) -				break; -		} -		m = m->next; -	} +	char *away, *msg = NULL; -	if( m ) +	away = set_getstr( &ic->acc->set, "away" ) ? +	     : set_getstr( &ic->irc->set, "away" ); +	if( away && *away )  	{ -		ic->acc->prpl->set_away( ic, m->data, *away ? away : NULL ); +		GList *m = ic->acc->prpl->away_states( ic ); +		msg = ic->acc->flags & ACC_FLAG_AWAY_MESSAGE ? away : NULL; +		away = imc_away_state_find( m, away, &msg ) ? : m->data;  	} -	else +	else if( ic->acc->flags & ACC_FLAG_STATUS_MESSAGE )  	{ -		s = imc_away_alias_find( ms, away ); -		if( s ) -		{ -			ic->acc->prpl->set_away( ic, s, away ); -			if( set_getbool( &ic->irc->set, "debug" ) ) -				imcb_log( ic, "Setting away state to %s", s ); -		} -		else -			ic->acc->prpl->set_away( ic, GAIM_AWAY_CUSTOM, away ); +		away = NULL; +		msg = set_getstr( &ic->acc->set, "status" ) ? +		    : set_getstr( &ic->irc->set, "status" );  	} -	return( 1 ); +	ic->acc->prpl->set_away( ic, away, msg ); +	 +	return 1;  }  static char *imc_away_alias_list[8][5] = @@ -1075,16 +1124,33 @@ static char *imc_away_alias_list[8][5] =  	{ NULL }  }; -static char *imc_away_alias_find( GList *gcm, char *away ) +static char *imc_away_state_find( GList *gcm, char *away, char **message )  {  	GList *m;  	int i, j; +	for( m = gcm; m; m = m->next ) +		if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) +		{ +			/* At least the Yahoo! module works better if message +			   contains no data unless it adds something to what +			   we have in state already. */ +			if( strlen( m->data ) == strlen( away ) ) +				*message = NULL; +			 +			return m->data; +		} +	  	for( i = 0; *imc_away_alias_list[i]; i ++ )  	{ +		int keep_message; +		  		for( j = 0; imc_away_alias_list[i][j]; j ++ )  			if( g_strncasecmp( away, imc_away_alias_list[i][j], strlen( imc_away_alias_list[i][j] ) ) == 0 ) +			{ +				keep_message = strlen( away ) != strlen( imc_away_alias_list[i][j] );  				break; +			}  		if( !imc_away_alias_list[i][j] )	/* If we reach the end, this row */  			continue;			/* is not what we want. Next!    */ @@ -1092,17 +1158,22 @@ static char *imc_away_alias_find( GList *gcm, char *away )  		/* Now find an entry in this row which exists in gcm */  		for( j = 0; imc_away_alias_list[i][j]; j ++ )  		{ -			m = gcm; -			while( m ) -			{ +			for( m = gcm; m; m = m->next )  				if( g_strcasecmp( imc_away_alias_list[i][j], m->data ) == 0 ) -					return( imc_away_alias_list[i][j] ); -				m = m->next; -			} +				{ +					if( !keep_message ) +						*message = NULL; +					 +					return imc_away_alias_list[i][j]; +				}  		} +		 +		/* No need to look further, apparently this state doesn't +		   have any good alias for this protocol. */ +		break;  	} -	return( NULL ); +	return NULL;  }  void imc_add_allow( struct im_connection *ic, char *handle ) | 
