Changeset b1f818b


Ignore:
Timestamp:
2010-07-11T12:21:59Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
2e0eaac
Parents:
133cdff
Message:

Use bee_user structs in all nick_* functions. Prepare for a nick_get() with
more flexible nickname generation.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • irc_im.c

    r133cdff rb1f818b  
    5050       
    5151        memset( nick, 0, MAX_NICK_LENGTH + 1 );
    52         strcpy( nick, nick_get( bu->ic->acc, bu->handle ) );
     52        strcpy( nick, nick_get( bu ) );
    5353       
    5454        bu->ui_data = iu = irc_user_new( irc, nick );
     
    294294                return TRUE;
    295295       
    296         if( nick_saved( bu->ic->acc, bu->handle ) )
     296        if( nick_saved( bu ) )
    297297                /* The user already assigned a nickname to this person. */
    298298                return TRUE;
     
    319319                   If rejoining a channel, maybe we got this nick already
    320320                   (and dedupe would only add an underscore. */
    321                 nick_dedupe( bu->ic->acc, bu->handle, newnick );
     321                nick_dedupe( bu, newnick );
    322322                irc_user_set_nick( iu, newnick );
    323323        }
  • nick.c

    r133cdff rb1f818b  
    22  * BitlBee -- An IRC to other IM-networks gateway                     *
    33  *                                                                    *
    4   * Copyright 2002-2007 Wilmer van der Gaast and others                *
     4  * Copyright 2002-2010 Wilmer van der Gaast and others                *
    55  \********************************************************************/
    66
     
    4242}
    4343
    44 void nick_set( account_t *acc, const char *handle, const char *nick )
     44void nick_set_raw( account_t *acc, const char *handle, const char *nick )
    4545{
    4646        char *store_handle, *store_nick = g_malloc( MAX_NICK_LENGTH + 1 );
    4747       
    4848        store_handle = clean_handle( handle );
    49         store_nick[MAX_NICK_LENGTH] = 0;
     49        store_nick[MAX_NICK_LENGTH] = '\0';
    5050        strncpy( store_nick, nick, MAX_NICK_LENGTH );
    5151        nick_strip( store_nick );
     
    5454}
    5555
    56 char *nick_get( account_t *acc, const char *handle )
     56void nick_set( bee_user_t *bu, const char *nick )
     57{
     58        nick_set_raw( bu->ic->acc, bu->handle, nick );
     59}
     60
     61char *nick_get( bee_user_t *bu )
    5762{
    5863        static char nick[MAX_NICK_LENGTH+1];
     
    6166        memset( nick, 0, MAX_NICK_LENGTH + 1 );
    6267       
    63         store_handle = clean_handle( handle );
     68        store_handle = clean_handle( bu->handle );
    6469        /* Find out if we stored a nick for this person already. If not, try
    6570           to generate a sane nick automatically. */
    66         if( ( found_nick = g_hash_table_lookup( acc->nicks, store_handle ) ) )
     71        if( ( found_nick = g_hash_table_lookup( bu->ic->acc->nicks, store_handle ) ) )
    6772        {
    6873                strncpy( nick, found_nick, MAX_NICK_LENGTH );
     
    7277                char *s;
    7378               
    74                 g_snprintf( nick, MAX_NICK_LENGTH, "%s", handle );
     79                g_snprintf( nick, MAX_NICK_LENGTH, "%s", bu->handle );
    7580                if( ( s = strchr( nick, '@' ) ) )
    7681                        while( *s )
     
    7883               
    7984                nick_strip( nick );
    80                 if( set_getbool( &acc->bee->set, "lcnicks" ) )
     85                if( set_getbool( &bu->bee->set, "lcnicks" ) )
    8186                        nick_lc( nick );
    8287        }
     
    8590        /* Make sure the nick doesn't collide with an existing one by adding
    8691           underscores and that kind of stuff, if necessary. */
    87         nick_dedupe( acc, handle, nick );
     92        nick_dedupe( bu, nick );
    8893       
    8994        return nick;
    9095}
    9196
    92 void nick_dedupe( account_t *acc, const char *handle, char nick[MAX_NICK_LENGTH+1] )
    93 {
    94         irc_t *irc = (irc_t*) acc->bee->ui_data;
     97char *nick_gen( bee_user_t *bu )
     98{
     99        return NULL;
     100}
     101
     102void nick_dedupe( bee_user_t *bu, char nick[MAX_NICK_LENGTH+1] )
     103{
     104        irc_t *irc = (irc_t*) bu->bee->ui_data;
    95105        int inf_protection = 256;
    96106       
     
    119129                                          "Please send all the following lines in your report:" );
    120130                       
    121                         irc_usermsg( irc, "Trying to get a sane nick for handle %s", handle );
     131                        irc_usermsg( irc, "Trying to get a sane nick for handle %s", bu->handle );
    122132                        for( i = 0; i < MAX_NICK_LENGTH; i ++ )
    123133                                irc_usermsg( irc, "Char %d: %c/%d", i, nick[i], nick[i] );
     
    136146/* Just check if there is a nickname set for this buddy or if we'd have to
    137147   generate one. */
    138 int nick_saved( account_t *acc, const char *handle )
     148int nick_saved( bee_user_t *bu )
    139149{
    140150        char *store_handle, *found;
    141151       
    142         store_handle = clean_handle( handle );
    143         found = g_hash_table_lookup( acc->nicks, store_handle );
     152        store_handle = clean_handle( bu->handle );
     153        found = g_hash_table_lookup( bu->ic->acc->nicks, store_handle );
    144154        g_free( store_handle );
    145155       
     
    147157}
    148158
    149 void nick_del( account_t *acc, const char *handle )
    150 {
    151         g_hash_table_remove( acc->nicks, handle );
     159void nick_del( bee_user_t *bu )
     160{
     161        g_hash_table_remove( bu->ic->acc->nicks, bu->handle );
    152162}
    153163
  • nick.h

    r133cdff rb1f818b  
    2424*/
    2525
    26 void nick_set( account_t *acc, const char *handle, const char *nick );
    27 char *nick_get( account_t *acc, const char *handle );
    28 void nick_dedupe( account_t *acc, const char *handle, char nick[MAX_NICK_LENGTH+1] );
    29 int nick_saved( account_t *acc, const char *handle );
    30 void nick_del( account_t *acc, const char *handle );
     26void nick_set_raw( account_t *acc, const char *handle, const char *nick );
     27void nick_set( bee_user_t *bu, const char *nick );
     28char *nick_get( bee_user_t *bu );
     29char *nick_gen( bee_user_t *bu );
     30void nick_dedupe( bee_user_t *bu, char nick[MAX_NICK_LENGTH+1] );
     31int nick_saved( bee_user_t *bu );
     32void nick_del( bee_user_t *bu );
    3133void nick_strip( char *nick );
    3234
  • root_commands.c

    r133cdff rb1f818b  
    615615                else
    616616                {
    617                         nick_set( a, cmd[2], cmd[3] );
     617                        nick_set_raw( a, cmd[2], cmd[3] );
    618618                }
    619619        }
     
    643643       
    644644        bu->ic->acc->prpl->remove_buddy( bu->ic, bu->handle, NULL );
    645         nick_del( bu->ic->acc, bu->handle );
     645        nick_del( bu );
    646646        //TODO(wilmer): bee_user_free() and/or let the IM mod do it? irc_user_free( irc, cmd[1] );
    647647       
     
    728728                else if( iu->bu )
    729729                {
    730                         nick_set( iu->bu->ic->acc, iu->bu->handle, cmd[2] );
     730                        nick_set( iu->bu, cmd[2] );
    731731                }
    732732               
  • storage_xml.c

    r133cdff rb1f818b  
    197197                if( xd->current_account && handle && nick )
    198198                {
    199                         nick_set( xd->current_account, handle, nick );
     199                        nick_set_raw( xd->current_account, handle, nick );
    200200                }
    201201                else
Note: See TracChangeset for help on using the changeset viewer.