aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2010-07-12 00:14:49 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2010-07-12 00:14:49 +0100
commit2e0eaac657b09f0698bd5779142fad5fe9db9eb6 (patch)
tree11a0a5624f9173f636ebf7229e07803f57e30a87
parentb1f818bcbd50eccd416127ed68346616295f54cd (diff)
First version of the nick_format setting.
-rw-r--r--irc.c1
-rw-r--r--nick.c86
-rw-r--r--protocols/account.c2
3 files changed, 82 insertions, 7 deletions
diff --git a/irc.c b/irc.c
index 10fbea23..e2486c10 100644
--- a/irc.c
+++ b/irc.c
@@ -108,6 +108,7 @@ irc_t *irc_new( int fd )
s = set_add( &b->set, "display_timestamps", "true", set_eval_bool, irc );
s = set_add( &b->set, "handle_unknown", "add_channel", NULL, irc );
s = set_add( &b->set, "lcnicks", "true", set_eval_bool, irc );
+ s = set_add( &b->set, "nick_format", "%-@handle", NULL, irc );
s = set_add( &b->set, "offline_user_quits", "true", set_eval_bool, irc );
s = set_add( &b->set, "ops", "both", set_eval_irc_channel_ops, irc );
s = set_add( &b->set, "paste_buffer", "false", set_eval_bool, irc );
diff --git a/nick.c b/nick.c
index b96c0b80..bc81d50e 100644
--- a/nick.c
+++ b/nick.c
@@ -26,6 +26,12 @@
#define BITLBEE_CORE
#include "bitlbee.h"
+/* Character maps, _lc_[x] == _uc_[x] (but uppercase), according to the RFC's.
+ With one difference, we allow dashes. These are used to do uc/lc conversions
+ and strip invalid chars. */
+static char *nick_lc_chars = "0123456789abcdefghijklmnopqrstuvwxyz{}^`-_|";
+static char *nick_uc_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ[]~`-_\\";
+
/* Store handles in lower case and strip spaces, because AIM is braindead. */
static char *clean_handle( const char *orig )
{
@@ -72,8 +78,14 @@ char *nick_get( bee_user_t *bu )
{
strncpy( nick, found_nick, MAX_NICK_LENGTH );
}
+ else if( ( found_nick = nick_gen( bu ) ) )
+ {
+ strncpy( nick, found_nick, MAX_NICK_LENGTH );
+ g_free( found_nick );
+ }
else
{
+ /* Keep this fallback since nick_gen() can return NULL in some cases. */
char *s;
g_snprintf( nick, MAX_NICK_LENGTH, "%s", bu->handle );
@@ -96,7 +108,73 @@ char *nick_get( bee_user_t *bu )
char *nick_gen( bee_user_t *bu )
{
- return NULL;
+ gboolean ok = FALSE; /* Set to true once the nick contains something unique. */
+ GString *ret = g_string_new( "" );
+ char *fmt = set_getstr( &bu->ic->acc->set, "nick_format" ) ? :
+ set_getstr( &bu->bee->set, "nick_format" );
+
+ while( fmt && *fmt && ret->len < MAX_NICK_LENGTH )
+ {
+ char *part, chop = '\0';
+
+ if( *fmt != '%' )
+ {
+ g_string_append_c( ret, *fmt );
+ fmt ++;
+ continue;
+ }
+
+ fmt ++;
+ while( *fmt )
+ {
+ /* -char means chop off everything from char */
+ if( *fmt == '-' )
+ {
+ chop = fmt[1];
+ if( chop == '\0' )
+ return NULL;
+ fmt += 2;
+ }
+ else if( g_strncasecmp( fmt, "handle", 6 ) == 0 )
+ {
+ part = bu->handle;
+ fmt += 6;
+ ok |= TRUE;
+ break;
+ }
+ else if( g_strncasecmp( fmt, "full_name", 9 ) == 0 )
+ {
+ part = bu->fullname;
+ fmt += 9;
+ ok |= part && *part;
+ break;
+ }
+ else if( g_strncasecmp( fmt, "first_name", 10 ) == 0 )
+ {
+ part = bu->fullname;
+ fmt += 10;
+ ok |= part && *part;
+ chop = ' ';
+ break;
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+
+ while( part && *part && *part != chop )
+ {
+ if( strchr( nick_lc_chars, *part ) ||
+ strchr( nick_uc_chars, *part ) )
+ g_string_append_c( ret, *part );
+
+ part ++;
+ }
+ }
+
+ /* This returns NULL if the nick is empty or otherwise not ok. */
+ return g_string_free( ret, ret->len == 0 || !ok );
}
void nick_dedupe( bee_user_t *bu, char nick[MAX_NICK_LENGTH+1] )
@@ -162,12 +240,6 @@ void nick_del( bee_user_t *bu )
}
-/* Character maps, _lc_[x] == _uc_[x] (but uppercase), according to the RFC's.
- With one difference, we allow dashes. */
-
-static char *nick_lc_chars = "0123456789abcdefghijklmnopqrstuvwxyz{}^`-_|";
-static char *nick_uc_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ[]~`-_\\";
-
void nick_strip( char *nick )
{
int i, j;
diff --git a/protocols/account.c b/protocols/account.c
index ba309b38..40cce2b8 100644
--- a/protocols/account.c
+++ b/protocols/account.c
@@ -53,6 +53,8 @@ account_t *account_add( bee_t *bee, struct prpl *prpl, char *user, char *pass )
s = set_add( &a->set, "auto_reconnect", "true", set_eval_bool, a );
+ s = set_add( &a->set, "nick_format", NULL, NULL, a );
+
s = set_add( &a->set, "nick_source", "handle", NULL, a );
s = set_add( &a->set, "password", NULL, set_eval_account, a );