Changeset e54112f for irc_channel.c


Ignore:
Timestamp:
2010-05-02T23:44:33Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
6a9d068
Parents:
bce78c8
Message:

Put a channel userlist in irc_channel_user elements so we can save flags
(i.e. modes).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc_channel.c

    rbce78c8 re54112f  
    2626#include "bitlbee.h"
    2727
     28static gint irc_channel_user_cmp( gconstpointer a_, gconstpointer b_ );
    2829static const struct irc_channel_funcs control_channel_funcs;
    2930
     
    7172       
    7273        irc->channels = g_slist_remove( irc->channels, ic );
    73         g_slist_free( ic->users );
     74        while( ic->users )
     75        {
     76                g_free( ic->users->data );
     77                ic->users = g_slist_remove( ic->users, ic->users->data );
     78        }
    7479       
    7580        g_free( ic->name );
     
    8287int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu )
    8388{
     89        irc_channel_user_t *icu;
     90       
    8491        if( irc_channel_has_user( ic, iu ) )
    8592                return 0;
    8693       
    87         ic->users = g_slist_insert_sorted( ic->users, iu, irc_user_cmp );
     94        icu = g_new0( irc_channel_user_t, 1 );
     95        icu->iu = iu;
     96       
     97        ic->users = g_slist_insert_sorted( ic->users, icu, irc_channel_user_cmp );
    8898       
    8999        if( iu == ic->irc->user || ic->flags & IRC_CHANNEL_JOINED )
     
    98108int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu )
    99109{
    100         if( !irc_channel_has_user( ic, iu ) )
     110        irc_channel_user_t *icu;
     111       
     112        if( !( icu = irc_channel_has_user( ic, iu ) ) )
    101113                return 0;
    102114       
    103         ic->users = g_slist_remove( ic->users, iu );
     115        ic->users = g_slist_remove( ic->users, icu );
     116        g_free( icu );
    104117       
    105118        if( ic->flags & IRC_CHANNEL_JOINED )
     
    112125}
    113126
    114 /* Currently a fairly stupid one-liner but I fear it's going to get worse. :-) */
    115 gboolean irc_channel_has_user( irc_channel_t *ic, irc_user_t *iu )
    116 {
    117         return g_slist_find( ic->users, iu ) != NULL;
     127irc_channel_user_t *irc_channel_has_user( irc_channel_t *ic, irc_user_t *iu )
     128{
     129        GSList *l;
     130       
     131        for( l = ic->users; l; l = l->next )
     132        {
     133                irc_channel_user_t *icu = l->data;
     134               
     135                if( icu->iu == iu )
     136                        return icu;
     137        }
     138       
     139        return NULL;
    118140}
    119141
     
    140162{
    141163        return strchr( CTYPES, name[0] ) != NULL && nick_ok( name + 1 );
     164}
     165
     166static gint irc_channel_user_cmp( gconstpointer a_, gconstpointer b_ )
     167{
     168        const irc_channel_user_t *a = a_, *b = b_;
     169       
     170        return irc_user_cmp( a->iu, b->iu );
    142171}
    143172
Note: See TracChangeset for help on using the changeset viewer.