Changeset 69cb623 for nick.c


Ignore:
Timestamp:
2006-10-15T09:41:12Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
2529faf
Parents:
695e392 (diff), e97827b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merging with storage-xml. It seems to be working pretty well, so maybe
this way more people will test it. :-)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nick.c

    r695e392 r69cb623  
    22  * BitlBee -- An IRC to other IM-networks gateway                     *
    33  *                                                                    *
    4   * Copyright 2002-2004 Wilmer van der Gaast and others                *
     4  * Copyright 2002-2006 Wilmer van der Gaast and others                *
    55  \********************************************************************/
    66
     
    2727#include "bitlbee.h"
    2828
    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. */
     30static 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
     44void 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
     55char *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        }
    4870        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                 else
    70                         n = n->next;
    71        
    72         if( !n )
    7371        {
    7472                char *s;
     
    8684               
    8785                nick_strip( nick );
    88                 if (set_getint(irc, "lcnicks"))
     86                if( set_getbool( &acc->irc->set, "lcnicks" ) )
    8987                        nick_lc( nick );
    9088        }
    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 ) )
    9394        {
    9495                if( strlen( nick ) < ( MAX_NICK_LENGTH - 1 ) )
     
    106107                        int i;
    107108                       
    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 );
    115116                        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" );
    121122                       
    122123                        g_snprintf( nick, MAX_NICK_LENGTH + 1, "xx%x", rand() );
     
    126127        }
    127128       
    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
     132void nick_del( account_t *acc, const char *handle )
     133{
     134        g_hash_table_remove( acc->nicks, handle );
    152135}
    153136
Note: See TracChangeset for help on using the changeset viewer.