source: protocols/user.c @ 4be8239

Last change on this file since 4be8239 was 3ddb7477, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-03-26T12:14:37Z

One total mess that doesn't do much yet, but reorganised some stuff and
untying the IRC and the core parts a little bit. Lots of work left to do.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2002-2004 Wilmer van der Gaast and others                *
5  \********************************************************************/
6
7/* Stuff to handle, save and search buddies                             */
8
9/*
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License with
21  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
22  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23  Suite 330, Boston, MA  02111-1307  USA
24*/
25
26#define BITLBEE_CORE
27#include "bitlbee.h"
28
29user_t *user_add( irc_t *irc, char *nick )
30{
31        user_t *u, *lu = NULL;
32        char *key;
33       
34        if( !nick_ok( nick ) )
35                return( NULL );
36       
37        if( user_find( irc, nick ) != NULL )
38                return( NULL );
39       
40        return( u );
41}
42
43int user_del( irc_t *irc, char *nick )
44{
45        user_t *u, *t;
46        char *key;
47        gpointer okey, ovalue;
48       
49        if( !nick_ok( nick ) )
50                return( 0 );
51       
52        u = irc->users;
53        t = NULL;
54        while( u )
55        {
56                if( nick_cmp( u->nick, nick ) == 0 )
57                {
58                        /* Get this key now already, since "nick" might be free()d
59                           at the time we start playing with the hash... */
60                        key = g_strdup( nick );
61                        nick_lc( key );
62                       
63                        if( t )
64                                t->next = u->next;
65                        else
66                                irc->users = u->next;
67                        if( u->online )
68                                irc_kill( irc, u );
69                        g_free( u->nick );
70                        if( u->nick != u->user ) g_free( u->user );
71                        if( u->nick != u->host ) g_free( u->host );
72                        if( u->nick != u->realname ) g_free( u->realname );
73                        g_free( u->group );
74                        g_free( u->away );
75                        g_free( u->handle );
76                        g_free( u->sendbuf );
77                        if( u->sendbuf_timer ) b_event_remove( u->sendbuf_timer );
78                        g_free( u );
79                       
80                        return( 1 );
81                }
82                u = (t=u)->next;
83        }
84       
85        return( 0 );
86}
87
88user_t *user_findhandle( struct im_connection *ic, const char *handle )
89{
90        user_t *u;
91        char *nick;
92       
93        /* First, let's try a hash lookup. If it works, it's probably faster. */
94        if( ( nick = g_hash_table_lookup( ic->acc->nicks, handle ) ) &&
95            ( u = user_find( ic->irc, nick ) ) &&
96            ( ic->acc->prpl->handle_cmp( handle, u->handle ) == 0 ) )
97                return u;
98       
99        /* However, it doesn't always work, so in that case we'll have to dig
100           through the whole userlist. :-( */
101        for( u = ic->irc->users; u; u = u->next )
102                if( u->ic == ic && u->handle && ic->acc->prpl->handle_cmp( u->handle, handle ) == 0 )
103                        return u;
104       
105        return NULL;
106}
Note: See TracBrowser for help on using the repository browser.