source: protocols/bee_user.c @ 81e04e1

Last change on this file since 81e04e1 was 81e04e1, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-04-01T02:32:25Z

nogaim.c is close to doing something useful again without speaking any IRC
itself.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2002-2010 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
29bee_user_t *bee_user_new( bee_t *bee, struct im_connection *ic, const char *handle )
30{
31        bee_user_t *bu;
32       
33        if( bee_user_by_handle( bee, ic, handle ) != NULL )
34                return NULL;
35       
36        bu = g_new0( bee_user_t, 1 );
37        bu->bee = bee;
38        bu->ic = ic;
39        bu->handle = g_strdup( handle );
40        bee->users = g_slist_prepend( bee->users, bu );
41       
42        if( bee->ui->user_new )
43                bee->ui->user_new( bee, bu );
44       
45        return bu;
46}
47
48int bee_user_free( bee_t *bee, struct im_connection *ic, const char *handle )
49{
50        bee_user_t *bu;
51       
52        if( ( bu = bee_user_by_handle( bee, ic, handle ) ) == NULL )
53                return 0;
54       
55        if( bee->ui->user_free )
56                bee->ui->user_free( bee, bu );
57       
58        g_free( bu->handle );
59        g_free( bu->fullname );
60        g_free( bu->group );
61        g_free( bu->status );
62        g_free( bu->status_msg );
63       
64        bee->users = g_slist_remove( bee->users, bu );
65       
66        return 1;
67}
68
69bee_user_t *bee_user_by_handle( bee_t *bee, struct im_connection *ic, const char *handle )
70{
71        GSList *l;
72       
73        for( l = bee->users; l; l = l->next )
74        {
75                bee_user_t *bu = l->data;
76               
77                if( bu->ic == ic && ic->acc->prpl->handle_cmp( bu->handle, handle ) )
78                        return bu;
79        }
80       
81        return NULL;
82}
Note: See TracBrowser for help on using the repository browser.