Changeset 5ebff60 for irc_user.c


Ignore:
Timestamp:
2015-02-20T22:50:54Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
0b9daac, 3d45471, 7733b8c
Parents:
af359b4
git-author:
Indent <please@…> (19-02-15 05:47:20)
git-committer:
dequis <dx@…> (20-02-15 22:50:54)
Message:

Reindent everything to K&R style with tabs

Used uncrustify, with the configuration file in ./doc/uncrustify.cfg

Commit author set to "Indent <please@…>" so that it's easier to
skip while doing git blame.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc_user.c

    raf359b4 r5ebff60  
    1   /********************************************************************\
     1/********************************************************************\
    22  * BitlBee -- An IRC to other IM-networks gateway                     *
    33  *                                                                    *
     
    2727#include "ipc.h"
    2828
    29 irc_user_t *irc_user_new( irc_t *irc, const char *nick )
    30 {
    31         irc_user_t *iu = g_new0( irc_user_t, 1 );
    32        
     29irc_user_t *irc_user_new(irc_t *irc, const char *nick)
     30{
     31        irc_user_t *iu = g_new0(irc_user_t, 1);
     32
    3333        iu->irc = irc;
    34         iu->nick = g_strdup( nick );
     34        iu->nick = g_strdup(nick);
    3535        iu->user = iu->host = iu->fullname = iu->nick;
    36        
    37         iu->key = g_strdup( nick );
    38         nick_lc( irc, iu->key );
     36
     37        iu->key = g_strdup(nick);
     38        nick_lc(irc, iu->key);
    3939        /* Using the hash table for speed and irc->users for easy iteration
    4040           through the list (since the GLib API doesn't have anything sane
    4141           for that.) */
    42         g_hash_table_insert( irc->nick_user_hash, iu->key, iu );
    43         irc->users = g_slist_insert_sorted( irc->users, iu, irc_user_cmp );
    44        
     42        g_hash_table_insert(irc->nick_user_hash, iu->key, iu);
     43        irc->users = g_slist_insert_sorted(irc->users, iu, irc_user_cmp);
     44
    4545        return iu;
    4646}
    4747
    48 int irc_user_free( irc_t *irc, irc_user_t *iu )
     48int irc_user_free(irc_t *irc, irc_user_t *iu)
    4949{
    5050        static struct im_connection *last_ic;
    5151        static char *msg;
    52        
    53         if( !iu )
     52
     53        if (!iu) {
    5454                return 0;
    55        
    56         if( iu->bu &&
    57             ( iu->bu->ic->flags & OPT_LOGGING_OUT ) &&
    58             iu->bu->ic != last_ic )
    59         {
     55        }
     56
     57        if (iu->bu &&
     58            (iu->bu->ic->flags & OPT_LOGGING_OUT) &&
     59            iu->bu->ic != last_ic) {
    6060                char host_prefix[] = "bitlbee.";
    6161                char *s;
    62                
     62
    6363                /* Irssi recognises netsplits by quitmsgs with two
    6464                   hostnames, where a hostname is a "word" with one
    6565                   of more dots. Mangle no-dot hostnames a bit. */
    66                 if( strchr( irc->root->host, '.' ) )
     66                if (strchr(irc->root->host, '.')) {
    6767                        *host_prefix = '\0';
    68                
     68                }
     69
    6970                last_ic = iu->bu->ic;
    70                 g_free( msg );
    71                 if( !set_getbool( &irc->b->set, "simulate_netsplit" ) )
    72                         msg = g_strdup( "Account off-line" );
    73                 else if( ( s = strchr( iu->bu->ic->acc->user, '@' ) ) )
    74                         msg = g_strdup_printf( "%s%s %s", host_prefix,
    75                                 irc->root->host, s + 1 );
    76                 else
    77                         msg = g_strdup_printf( "%s%s %s.%s",
    78                                 host_prefix, irc->root->host,
    79                                 iu->bu->ic->acc->prpl->name, irc->root->host );
    80         }
    81         else if( !iu->bu || !( iu->bu->ic->flags & OPT_LOGGING_OUT ) )
    82         {
    83                 g_free( msg );
    84                 msg = g_strdup( "Removed" );
     71                g_free(msg);
     72                if (!set_getbool(&irc->b->set, "simulate_netsplit")) {
     73                        msg = g_strdup("Account off-line");
     74                } else if ((s = strchr(iu->bu->ic->acc->user, '@'))) {
     75                        msg = g_strdup_printf("%s%s %s", host_prefix,
     76                                              irc->root->host, s + 1);
     77                } else {
     78                        msg = g_strdup_printf("%s%s %s.%s",
     79                                              host_prefix, irc->root->host,
     80                                              iu->bu->ic->acc->prpl->name, irc->root->host);
     81                }
     82        } else if (!iu->bu || !(iu->bu->ic->flags & OPT_LOGGING_OUT)) {
     83                g_free(msg);
     84                msg = g_strdup("Removed");
    8585                last_ic = NULL;
    8686        }
    87         irc_user_quit( iu, msg );
    88        
    89         irc->users = g_slist_remove( irc->users, iu );
    90         g_hash_table_remove( irc->nick_user_hash, iu->key );
    91        
    92         g_free( iu->nick );
    93         if( iu->nick != iu->user ) g_free( iu->user );
    94         if( iu->nick != iu->host ) g_free( iu->host );
    95         if( iu->nick != iu->fullname ) g_free( iu->fullname );
    96         g_free( iu->pastebuf );
    97         if( iu->pastebuf_timer ) b_event_remove( iu->pastebuf_timer );
    98         g_free( iu->key );
    99         g_free( iu );
    100        
     87        irc_user_quit(iu, msg);
     88
     89        irc->users = g_slist_remove(irc->users, iu);
     90        g_hash_table_remove(irc->nick_user_hash, iu->key);
     91
     92        g_free(iu->nick);
     93        if (iu->nick != iu->user) {
     94                g_free(iu->user);
     95        }
     96        if (iu->nick != iu->host) {
     97                g_free(iu->host);
     98        }
     99        if (iu->nick != iu->fullname) {
     100                g_free(iu->fullname);
     101        }
     102        g_free(iu->pastebuf);
     103        if (iu->pastebuf_timer) {
     104                b_event_remove(iu->pastebuf_timer);
     105        }
     106        g_free(iu->key);
     107        g_free(iu);
     108
    101109        return 1;
    102110}
    103111
    104 irc_user_t *irc_user_by_name( irc_t *irc, const char *nick )
    105 {
    106         char key[strlen(nick)+1];
    107        
    108         strcpy( key, nick );
    109         if( nick_lc( irc, key ) )
    110                 return g_hash_table_lookup( irc->nick_user_hash, key );
    111         else
     112irc_user_t *irc_user_by_name(irc_t *irc, const char *nick)
     113{
     114        char key[strlen(nick) + 1];
     115
     116        strcpy(key, nick);
     117        if (nick_lc(irc, key)) {
     118                return g_hash_table_lookup(irc->nick_user_hash, key);
     119        } else {
    112120                return NULL;
    113 }
    114 
    115 int irc_user_set_nick( irc_user_t *iu, const char *new )
     121        }
     122}
     123
     124int irc_user_set_nick(irc_user_t *iu, const char *new)
    116125{
    117126        irc_t *irc = iu->irc;
    118127        irc_user_t *new_iu;
    119         char key[strlen(new)+1];
     128        char key[strlen(new) + 1];
    120129        GSList *cl;
    121        
    122         strcpy( key, new );
    123         if( iu == NULL || !nick_lc( irc, key ) ||
    124             ( ( new_iu = irc_user_by_name( irc, new ) ) && new_iu != iu ) )
     130
     131        strcpy(key, new);
     132        if (iu == NULL || !nick_lc(irc, key) ||
     133            ((new_iu = irc_user_by_name(irc, new)) && new_iu != iu)) {
    125134                return 0;
    126        
    127         for( cl = irc->channels; cl; cl = cl->next )
    128         {
     135        }
     136
     137        for (cl = irc->channels; cl; cl = cl->next) {
    129138                irc_channel_t *ic = cl->data;
    130                
     139
    131140                /* Send a NICK update if we're renaming our user, or someone
    132141                   who's in the same channel like our user. */
    133                 if( iu == irc->user ||
    134                     ( ( ic->flags & IRC_CHANNEL_JOINED ) &&
    135                       irc_channel_has_user( ic, iu ) ) )
    136                 {
    137                         irc_send_nick( iu, new );
     142                if (iu == irc->user ||
     143                    ((ic->flags & IRC_CHANNEL_JOINED) &&
     144                     irc_channel_has_user(ic, iu))) {
     145                        irc_send_nick(iu, new);
    138146                        break;
    139147                }
    140148        }
    141        
    142         irc->users = g_slist_remove( irc->users, iu );
    143         g_hash_table_remove( irc->nick_user_hash, iu->key );
    144        
    145         if( iu->nick == iu->user ) iu->user = NULL;
    146         if( iu->nick == iu->host ) iu->host = NULL;
    147         if( iu->nick == iu->fullname ) iu->fullname = NULL;
    148         g_free( iu->nick );
    149         iu->nick = g_strdup( new );
    150         if( iu->user == NULL ) iu->user = g_strdup( iu->nick );
    151         if( iu->host == NULL ) iu->host = g_strdup( iu->nick );
    152         if( iu->fullname == NULL ) iu->fullname = g_strdup( iu->nick );
    153        
    154         g_free( iu->key );
    155         iu->key = g_strdup( key );
    156         g_hash_table_insert( irc->nick_user_hash, iu->key, iu );
    157         irc->users = g_slist_insert_sorted( irc->users, iu, irc_user_cmp );
    158        
    159         if( iu == irc->user )
    160                 ipc_to_master_str( "NICK :%s\r\n", new );
    161        
     149
     150        irc->users = g_slist_remove(irc->users, iu);
     151        g_hash_table_remove(irc->nick_user_hash, iu->key);
     152
     153        if (iu->nick == iu->user) {
     154                iu->user = NULL;
     155        }
     156        if (iu->nick == iu->host) {
     157                iu->host = NULL;
     158        }
     159        if (iu->nick == iu->fullname) {
     160                iu->fullname = NULL;
     161        }
     162        g_free(iu->nick);
     163        iu->nick = g_strdup(new);
     164        if (iu->user == NULL) {
     165                iu->user = g_strdup(iu->nick);
     166        }
     167        if (iu->host == NULL) {
     168                iu->host = g_strdup(iu->nick);
     169        }
     170        if (iu->fullname == NULL) {
     171                iu->fullname = g_strdup(iu->nick);
     172        }
     173
     174        g_free(iu->key);
     175        iu->key = g_strdup(key);
     176        g_hash_table_insert(irc->nick_user_hash, iu->key, iu);
     177        irc->users = g_slist_insert_sorted(irc->users, iu, irc_user_cmp);
     178
     179        if (iu == irc->user) {
     180                ipc_to_master_str("NICK :%s\r\n", new);
     181        }
     182
    162183        return 1;
    163184}
    164185
    165 gint irc_user_cmp( gconstpointer a_, gconstpointer b_ )
     186gint irc_user_cmp(gconstpointer a_, gconstpointer b_)
    166187{
    167188        const irc_user_t *a = a_, *b = b_;
    168        
    169         return strcmp( a->key, b->key );
    170 }
    171 
    172 const char *irc_user_get_away( irc_user_t *iu )
     189
     190        return strcmp(a->key, b->key);
     191}
     192
     193const char *irc_user_get_away(irc_user_t *iu)
    173194{
    174195        irc_t *irc = iu->irc;
    175196        bee_user_t *bu = iu->bu;
    176        
    177         if( iu == irc->user )
    178                 return set_getstr( &irc->b->set, "away" );
    179         else if( bu )
    180         {
    181                 if( !bu->flags & BEE_USER_ONLINE )
     197
     198        if (iu == irc->user) {
     199                return set_getstr(&irc->b->set, "away");
     200        } else if (bu) {
     201                if (!bu->flags & BEE_USER_ONLINE) {
    182202                        return "Offline";
    183                 else if( bu->flags & BEE_USER_AWAY )
    184                 {
    185                         if( bu->status_msg )
    186                         {
     203                } else if (bu->flags & BEE_USER_AWAY) {
     204                        if (bu->status_msg) {
    187205                                static char ret[MAX_STRING];
    188                                 g_snprintf( ret, MAX_STRING - 1, "%s (%s)",
    189                                             bu->status ? : "Away", bu->status_msg );
     206                                g_snprintf(ret, MAX_STRING - 1, "%s (%s)",
     207                                           bu->status ? : "Away", bu->status_msg);
    190208                                return ret;
     209                        } else {
     210                                return bu->status ? : "Away";
    191211                        }
    192                         else
    193                                 return bu->status ? : "Away";
    194                 }
    195         }
    196        
     212                }
     213        }
     214
    197215        return NULL;
    198216}
    199217
    200 void irc_user_quit( irc_user_t *iu, const char *msg )
     218void irc_user_quit(irc_user_t *iu, const char *msg)
    201219{
    202220        GSList *l;
    203221        gboolean send_quit = FALSE;
    204        
    205         if( !iu )
     222
     223        if (!iu) {
    206224                return;
    207        
    208         for( l = iu->irc->channels; l; l = l->next )
    209         {
     225        }
     226
     227        for (l = iu->irc->channels; l; l = l->next) {
    210228                irc_channel_t *ic = l->data;
    211                 send_quit |= irc_channel_del_user( ic, iu, IRC_CDU_SILENT, NULL ) &&
    212                              ( ic->flags & IRC_CHANNEL_JOINED );
    213         }
    214        
    215         if( send_quit )
    216                 irc_send_quit( iu, msg );
     229                send_quit |= irc_channel_del_user(ic, iu, IRC_CDU_SILENT, NULL) &&
     230                             (ic->flags & IRC_CHANNEL_JOINED);
     231        }
     232
     233        if (send_quit) {
     234                irc_send_quit(iu, msg);
     235        }
    217236}
    218237
    219238/* User-type dependent functions, for root/NickServ: */
    220 static gboolean root_privmsg( irc_user_t *iu, const char *msg )
    221 {
    222         char cmd[strlen(msg)+1];
    223        
    224         strcpy( cmd, msg );
    225         root_command_string( iu->irc, cmd );
    226        
     239static gboolean root_privmsg(irc_user_t *iu, const char *msg)
     240{
     241        char cmd[strlen(msg) + 1];
     242
     243        strcpy(cmd, msg);
     244        root_command_string(iu->irc, cmd);
     245
    227246        return TRUE;
    228247}
    229248
    230 static gboolean root_ctcp( irc_user_t *iu, char * const *ctcp )
    231 {
    232         if( g_strcasecmp( ctcp[0], "VERSION" ) == 0 )
    233         {
    234                 irc_send_msg_f( iu, "NOTICE", iu->irc->user->nick, "\001%s %s\001",
    235                                 ctcp[0], PACKAGE " " BITLBEE_VERSION " " ARCH "/" CPU );
    236         }
    237         else if( g_strcasecmp( ctcp[0], "PING" ) == 0 )
    238         {
    239                 irc_send_msg_f( iu, "NOTICE", iu->irc->user->nick, "\001%s %s\001",
    240                                 ctcp[0], ctcp[1] ? : "" );
    241         }
    242        
     249static gboolean root_ctcp(irc_user_t *iu, char * const *ctcp)
     250{
     251        if (g_strcasecmp(ctcp[0], "VERSION") == 0) {
     252                irc_send_msg_f(iu, "NOTICE", iu->irc->user->nick, "\001%s %s\001",
     253                               ctcp[0], PACKAGE " " BITLBEE_VERSION " " ARCH "/" CPU);
     254        } else if (g_strcasecmp(ctcp[0], "PING") == 0) {
     255                irc_send_msg_f(iu, "NOTICE", iu->irc->user->nick, "\001%s %s\001",
     256                               ctcp[0], ctcp[1] ? : "");
     257        }
     258
    243259        return TRUE;
    244260}
     
    250266
    251267/* Echo to yourself: */
    252 static gboolean self_privmsg( irc_user_t *iu, const char *msg )
    253 {
    254         irc_send_msg( iu, "PRIVMSG", iu->nick, msg, NULL );
    255        
     268static gboolean self_privmsg(irc_user_t *iu, const char *msg)
     269{
     270        irc_send_msg(iu, "PRIVMSG", iu->nick, msg, NULL);
     271
    256272        return TRUE;
    257273}
Note: See TracChangeset for help on using the changeset viewer.