Changes in nick.c [5b52a48:1fc2958]
Legend:
- Unmodified
- Added
- Removed
-
nick.c
r5b52a48 r1fc2958 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-200 6Wilmer van der Gaast and others *4 * Copyright 2002-2004 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 27 27 #include "bitlbee.h" 28 28 29 /* Store handles in lower case and strip spaces, because AIM is braindead. */ 30 static char *clean_handle( const char *orig ) 31 { 32 char *new = g_malloc( strlen( orig ) + 1 ); 33 int i = 0; 34 35 do { 36 if (*orig != ' ') 37 new[i++] = tolower( *orig ); 38 } 39 while (*(orig++)); 40 41 return new; 42 } 43 44 void nick_set( account_t *acc, const char *handle, const char *nick ) 45 { 46 char *store_handle, *store_nick = g_malloc( MAX_NICK_LENGTH + 1 ); 47 48 store_handle = clean_handle( handle ); 49 strncpy( store_nick, nick, MAX_NICK_LENGTH ); 50 nick_strip( store_nick ); 51 52 g_hash_table_replace( acc->nicks, store_handle, store_nick ); 53 } 54 55 char *nick_get( account_t *acc, const char *handle, const char *realname ) 29 void nick_set( irc_t *irc, const char *handle, struct prpl *proto, const char *nick ) 30 { 31 nick_t *m = NULL, *n = irc->nicks; 32 33 while( n ) 34 { 35 if( ( g_strcasecmp( n->handle, handle ) == 0 ) && n->proto == proto ) 36 { 37 g_free( n->nick ); 38 n->nick = nick_dup( nick ); 39 nick_strip( n->nick ); 40 41 return; 42 } 43 n = ( m = n )->next; // :-P 44 } 45 46 if( m ) 47 n = m->next = g_new0( nick_t, 1 ); 48 else 49 n = irc->nicks = g_new0( nick_t, 1 ); 50 51 n->handle = g_strdup( handle ); 52 n->proto = proto; 53 n->nick = nick_dup( nick ); 54 55 nick_strip( n->nick ); 56 } 57 58 char *nick_get( irc_t *irc, const char *handle, struct prpl *proto, const char *realname ) 56 59 { 57 60 static char nick[MAX_NICK_LENGTH+1]; 58 char *store_handle, *found_nick;61 nick_t *n = irc->nicks; 59 62 int inf_protection = 256; 60 63 61 64 memset( nick, 0, MAX_NICK_LENGTH + 1 ); 62 65 63 store_handle = clean_handle( handle ); 64 /* Find out if we stored a nick for this person already. If not, try 65 to generate a sane nick automatically. */ 66 if( ( found_nick = g_hash_table_lookup( acc->nicks, store_handle ) ) ) 67 { 68 strncpy( nick, found_nick, MAX_NICK_LENGTH ); 69 } 70 else 66 while( n && !*nick ) 67 if( ( n->proto == proto ) && ( g_strcasecmp( n->handle, handle ) == 0 ) ) 68 strcpy( nick, n->nick ); 69 else 70 n = n->next; 71 72 if( !n ) 71 73 { 72 74 char *s; … … 84 86 85 87 nick_strip( nick ); 86 if ( set_getbool( &acc->irc->set, "lcnicks" ) )88 if (set_getint(irc, "lcnicks")) 87 89 nick_lc( nick ); 88 90 } 89 g_free( store_handle ); 90 91 /* Now, find out if the nick is already in use at the moment, and make 92 subtle changes to make it unique. */ 93 while( !nick_ok( nick ) || user_find( acc->irc, nick ) ) 91 92 while( !nick_ok( nick ) || user_find( irc, nick ) ) 94 93 { 95 94 if( strlen( nick ) < ( MAX_NICK_LENGTH - 1 ) ) … … 107 106 int i; 108 107 109 irc_usermsg( acc->irc, "WARNING: Almost had an infinite loop in nick_get()! "110 111 112 113 114 115 irc_usermsg( acc->irc, "Trying to get a sane nick for handle %s", handle );108 irc_usermsg( irc, "WARNING: Almost had an infinite loop in nick_get()! " 109 "This used to be a fatal BitlBee bug, but we tried to fix it. " 110 "This message should *never* appear anymore. " 111 "If it does, please *do* send us a bug report! " 112 "Please send all the following lines in your report:" ); 113 114 irc_usermsg( irc, "Trying to get a sane nick for handle %s", handle ); 116 115 for( i = 0; i < MAX_NICK_LENGTH; i ++ ) 117 irc_usermsg( acc->irc, "Char %d: %c/%d", i, nick[i], nick[i] );118 119 irc_usermsg( acc->irc, "FAILED. Returning an insane nick now. Things might break. "120 121 116 irc_usermsg( irc, "Char %d: %c/%d", i, nick[i], nick[i] ); 117 118 irc_usermsg( irc, "FAILED. Returning an insane nick now. Things might break. " 119 "Good luck, and please don't forget to paste the lines up here " 120 "in #bitlbee on OFTC or in a mail to wilmer@gaast.net" ); 122 121 123 122 g_snprintf( nick, MAX_NICK_LENGTH + 1, "xx%x", rand() ); … … 127 126 } 128 127 129 return nick; 130 } 131 132 void nick_del( account_t *acc, const char *handle ) 133 { 134 g_hash_table_remove( acc->nicks, handle ); 128 return( nick ); 129 } 130 131 void nick_del( irc_t *irc, const char *nick ) 132 { 133 nick_t *l = NULL, *n = irc->nicks; 134 135 while( n ) 136 { 137 if( g_strcasecmp( n->nick, nick ) == 0 ) 138 { 139 if( l ) 140 l->next = n->next; 141 else 142 irc->nicks = n->next; 143 144 g_free( n->handle ); 145 g_free( n->nick ); 146 g_free( n ); 147 148 break; 149 } 150 n = (l=n)->next; 151 } 135 152 } 136 153
Note: See TracChangeset
for help on using the changeset viewer.