diff options
| -rw-r--r-- | irc_im.c | 6 | ||||
| -rw-r--r-- | nick.c | 44 | ||||
| -rw-r--r-- | nick.h | 12 | ||||
| -rw-r--r-- | root_commands.c | 6 | ||||
| -rw-r--r-- | storage_xml.c | 2 | 
5 files changed, 41 insertions, 29 deletions
| @@ -49,7 +49,7 @@ static gboolean bee_irc_user_new( bee_t *bee, bee_user_t *bu )  	char nick[MAX_NICK_LENGTH+1], *s;  	memset( nick, 0, MAX_NICK_LENGTH + 1 ); -	strcpy( nick, nick_get( bu->ic->acc, bu->handle ) ); +	strcpy( nick, nick_get( bu ) );  	bu->ui_data = iu = irc_user_new( irc, nick );  	iu->bu = bu; @@ -293,7 +293,7 @@ static gboolean bee_irc_user_nick_hint( bee_t *bee, bee_user_t *bu, const char *  		/* Ignore if the user is visible already. */  		return TRUE; -	if( nick_saved( bu->ic->acc, bu->handle ) ) +	if( nick_saved( bu ) )  		/* The user already assigned a nickname to this person. */  		return TRUE; @@ -318,7 +318,7 @@ static gboolean bee_irc_user_nick_hint( bee_t *bee, bee_user_t *bu, const char *  		/* Only do this if newnick is different from the current one.  		   If rejoining a channel, maybe we got this nick already  		   (and dedupe would only add an underscore. */ -		nick_dedupe( bu->ic->acc, bu->handle, newnick ); +		nick_dedupe( bu, newnick );  		irc_user_set_nick( iu, newnick );  	} @@ -1,7 +1,7 @@    /********************************************************************\    * BitlBee -- An IRC to other IM-networks gateway                     *    *                                                                    * -  * Copyright 2002-2007 Wilmer van der Gaast and others                * +  * Copyright 2002-2010 Wilmer van der Gaast and others                *    \********************************************************************/  /* Some stuff to fetch, save and handle nicknames for your buddies      */ @@ -41,29 +41,34 @@ static char *clean_handle( const char *orig )  	return new;  } -void nick_set( account_t *acc, const char *handle, const char *nick ) +void nick_set_raw( account_t *acc, const char *handle, const char *nick )  {  	char *store_handle, *store_nick = g_malloc( MAX_NICK_LENGTH + 1 );  	store_handle = clean_handle( handle ); -	store_nick[MAX_NICK_LENGTH] = 0; +	store_nick[MAX_NICK_LENGTH] = '\0';  	strncpy( store_nick, nick, MAX_NICK_LENGTH );  	nick_strip( store_nick );  	g_hash_table_replace( acc->nicks, store_handle, store_nick );  } -char *nick_get( account_t *acc, const char *handle ) +void nick_set( bee_user_t *bu, const char *nick ) +{ +	nick_set_raw( bu->ic->acc, bu->handle, nick ); +} + +char *nick_get( bee_user_t *bu )  {  	static char nick[MAX_NICK_LENGTH+1];  	char *store_handle, *found_nick;  	memset( nick, 0, MAX_NICK_LENGTH + 1 ); -	store_handle = clean_handle( handle ); +	store_handle = clean_handle( bu->handle );  	/* Find out if we stored a nick for this person already. If not, try  	   to generate a sane nick automatically. */ -	if( ( found_nick = g_hash_table_lookup( acc->nicks, store_handle ) ) ) +	if( ( found_nick = g_hash_table_lookup( bu->ic->acc->nicks, store_handle ) ) )  	{  		strncpy( nick, found_nick, MAX_NICK_LENGTH );  	} @@ -71,27 +76,32 @@ char *nick_get( account_t *acc, const char *handle )  	{  		char *s; -		g_snprintf( nick, MAX_NICK_LENGTH, "%s", handle ); +		g_snprintf( nick, MAX_NICK_LENGTH, "%s", bu->handle );  		if( ( s = strchr( nick, '@' ) ) )  			while( *s )  				*(s++) = 0;  		nick_strip( nick ); -		if( set_getbool( &acc->bee->set, "lcnicks" ) ) +		if( set_getbool( &bu->bee->set, "lcnicks" ) )  			nick_lc( nick );  	}  	g_free( store_handle );  	/* Make sure the nick doesn't collide with an existing one by adding  	   underscores and that kind of stuff, if necessary. */ -	nick_dedupe( acc, handle, nick ); +	nick_dedupe( bu, nick );  	return nick;  } -void nick_dedupe( account_t *acc, const char *handle, char nick[MAX_NICK_LENGTH+1] ) +char *nick_gen( bee_user_t *bu )  { -	irc_t *irc = (irc_t*) acc->bee->ui_data; +	return NULL; +} + +void nick_dedupe( bee_user_t *bu, char nick[MAX_NICK_LENGTH+1] ) +{ +	irc_t *irc = (irc_t*) bu->bee->ui_data;  	int inf_protection = 256;  	/* Now, find out if the nick is already in use at the moment, and make @@ -118,7 +128,7 @@ void nick_dedupe( account_t *acc, const char *handle, char nick[MAX_NICK_LENGTH+  			                  "If it does, please *do* send us a bug report! "  			                  "Please send all the following lines in your report:" ); -			irc_usermsg( irc, "Trying to get a sane nick for handle %s", handle ); +			irc_usermsg( irc, "Trying to get a sane nick for handle %s", bu->handle );  			for( i = 0; i < MAX_NICK_LENGTH; i ++ )  				irc_usermsg( irc, "Char %d: %c/%d", i, nick[i], nick[i] ); @@ -135,20 +145,20 @@ void nick_dedupe( account_t *acc, const char *handle, char nick[MAX_NICK_LENGTH+  /* Just check if there is a nickname set for this buddy or if we'd have to     generate one. */ -int nick_saved( account_t *acc, const char *handle ) +int nick_saved( bee_user_t *bu )  {  	char *store_handle, *found; -	store_handle = clean_handle( handle ); -	found = g_hash_table_lookup( acc->nicks, store_handle ); +	store_handle = clean_handle( bu->handle ); +	found = g_hash_table_lookup( bu->ic->acc->nicks, store_handle );  	g_free( store_handle );  	return found != NULL;  } -void nick_del( account_t *acc, const char *handle ) +void nick_del( bee_user_t *bu )  { -	g_hash_table_remove( acc->nicks, handle ); +	g_hash_table_remove( bu->ic->acc->nicks, bu->handle );  } @@ -23,11 +23,13 @@    Suite 330, Boston, MA  02111-1307  USA  */ -void nick_set( account_t *acc, const char *handle, const char *nick ); -char *nick_get( account_t *acc, const char *handle ); -void nick_dedupe( account_t *acc, const char *handle, char nick[MAX_NICK_LENGTH+1] ); -int nick_saved( account_t *acc, const char *handle ); -void nick_del( account_t *acc, const char *handle ); +void nick_set_raw( account_t *acc, const char *handle, const char *nick ); +void nick_set( bee_user_t *bu, const char *nick ); +char *nick_get( bee_user_t *bu ); +char *nick_gen( bee_user_t *bu ); +void nick_dedupe( bee_user_t *bu, char nick[MAX_NICK_LENGTH+1] ); +int nick_saved( bee_user_t *bu ); +void nick_del( bee_user_t *bu );  void nick_strip( char *nick );  int nick_ok( const char *nick ); diff --git a/root_commands.c b/root_commands.c index d19feae0..f4bb4b82 100644 --- a/root_commands.c +++ b/root_commands.c @@ -614,7 +614,7 @@ static void cmd_add( irc_t *irc, char **cmd )  		}  		else  		{ -			nick_set( a, cmd[2], cmd[3] ); +			nick_set_raw( a, cmd[2], cmd[3] );  		}  	} @@ -642,7 +642,7 @@ static void cmd_remove( irc_t *irc, char **cmd )  	s = g_strdup( bu->handle );  	bu->ic->acc->prpl->remove_buddy( bu->ic, bu->handle, NULL ); -	nick_del( bu->ic->acc, bu->handle ); +	nick_del( bu );  	//TODO(wilmer): bee_user_free() and/or let the IM mod do it? irc_user_free( irc, cmd[1] );  	irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); @@ -727,7 +727,7 @@ static void cmd_rename( irc_t *irc, char **cmd )  		}  		else if( iu->bu )  		{ -			nick_set( iu->bu->ic->acc, iu->bu->handle, cmd[2] ); +			nick_set( iu->bu, cmd[2] );  		}  		irc_usermsg( irc, "Nick successfully changed" ); diff --git a/storage_xml.c b/storage_xml.c index a60769bb..7a10cea7 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -196,7 +196,7 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na  		if( xd->current_account && handle && nick )  		{ -			nick_set( xd->current_account, handle, nick ); +			nick_set_raw( xd->current_account, handle, nick );  		}  		else  		{ | 
