- Timestamp:
- 2006-07-03T21:22:45Z (17 years ago)
- Branches:
- master
- Children:
- 7e3592e
- Parents:
- 911f2eb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
nick.c
r911f2eb r5b52a48 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-200 4Wilmer van der Gaast and others *4 * Copyright 2002-2006 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 27 27 #include "bitlbee.h" 28 28 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 ); 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 ) 56 { 57 static char nick[MAX_NICK_LENGTH+1]; 58 char *store_handle, *found_nick; 59 int inf_protection = 256; 60 61 memset( nick, 0, MAX_NICK_LENGTH + 1 ); 62 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 } 48 70 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 )59 {60 static char nick[MAX_NICK_LENGTH+1];61 nick_t *n = irc->nicks;62 int inf_protection = 256;63 64 memset( nick, 0, MAX_NICK_LENGTH + 1 );65 66 while( n && !*nick )67 if( ( n->proto == proto ) && ( g_strcasecmp( n->handle, handle ) == 0 ) )68 strcpy( nick, n->nick );69 else70 n = n->next;71 72 if( !n )73 71 { 74 72 char *s; … … 86 84 87 85 nick_strip( nick ); 88 if( set_get int( &irc->set, "lcnicks" ) )86 if( set_getbool( &acc->irc->set, "lcnicks" ) ) 89 87 nick_lc( nick ); 90 88 } 91 92 while( !nick_ok( nick ) || user_find( irc, nick ) ) 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 ) ) 93 94 { 94 95 if( strlen( nick ) < ( MAX_NICK_LENGTH - 1 ) ) … … 106 107 int i; 107 108 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 );109 irc_usermsg( acc->irc, "WARNING: Almost had an infinite loop in nick_get()! " 110 "This used to be a fatal BitlBee bug, but we tried to fix it. " 111 "This message should *never* appear anymore. " 112 "If it does, please *do* send us a bug report! " 113 "Please send all the following lines in your report:" ); 114 115 irc_usermsg( acc->irc, "Trying to get a sane nick for handle %s", handle ); 115 116 for( i = 0; i < MAX_NICK_LENGTH; i ++ ) 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" );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 "Good luck, and please don't forget to paste the lines up here " 121 "in #bitlbee on OFTC or in a mail to wilmer@gaast.net" ); 121 122 122 123 g_snprintf( nick, MAX_NICK_LENGTH + 1, "xx%x", rand() ); … … 126 127 } 127 128 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 } 129 return nick; 130 } 131 132 void nick_del( account_t *acc, const char *handle ) 133 { 134 g_hash_table_remove( acc->nicks, handle ); 152 135 } 153 136
Note: See TracChangeset
for help on using the changeset viewer.