source: account.c @ 34b17d9

Last change on this file since 34b17d9 was 547f937, checked in by Jelmer Vernooij <jelmer@…>, at 2005-12-14T11:15:04Z

Remove statement that couldn't be executed anyway

  • Property mode set to 100644
File size: 3.5 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/* Account management functions                                         */
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#include "account.h"
29
30account_t *account_add( irc_t *irc, struct prpl *prpl, char *user, char *pass )
31{
32        account_t *a;
33       
34        if( irc->accounts )
35        {
36                for( a = irc->accounts; a->next; a = a->next );
37                a = a->next = g_new0 ( account_t, 1 );
38        }
39        else
40        {
41                irc->accounts = a = g_new0 ( account_t, 1 );
42        }
43       
44        a->prpl = prpl;
45        a->user = g_strdup( user );
46        a->pass = g_strdup( pass );
47        a->irc = irc;
48       
49        return( a );
50}
51
52account_t *account_get( irc_t *irc, char *id )
53{
54        account_t *a, *ret = NULL;
55        int nr;
56       
57        if( sscanf( id, "%d", &nr ) == 1 && nr < 1000 )
58        {
59                for( a = irc->accounts; a; a = a->next )
60                        if( ( nr-- ) == 0 )
61                                return( a );
62               
63                return( NULL );
64        }
65       
66        for( a = irc->accounts; a; a = a->next )
67        {
68                if( g_strcasecmp( id, a->prpl->name ) == 0 )
69                {
70                        if( !ret )
71                                ret = a;
72                        else
73                                return( NULL ); /* We don't want to match more than one... */
74                }
75                else if( strstr( a->user, id ) )
76                {
77                        if( !ret )
78                                ret = a;
79                        else
80                                return( NULL );
81                }
82        }
83       
84        return( ret );
85}
86
87void account_del( irc_t *irc, account_t *acc )
88{
89        account_t *a, *l = NULL;
90       
91        for( a = irc->accounts; a; a = (l=a)->next )
92                if( a == acc )
93                {
94                        if( a->gc ) return; /* Caller should have checked, accounts still in use can't be deleted. */
95                       
96                        if( l )
97                        {
98                                l->next = a->next;
99                        }
100                        else
101                        {
102                                irc->accounts = a->next;
103                        }
104                       
105                        g_free( a->user );
106                        g_free( a->pass );
107                        if( a->server ) g_free( a->server );
108                        if( a->reconnect )      /* This prevents any reconnect still queued to happen */
109                                cancel_auto_reconnect( a );
110                        g_free( a );
111                       
112                        break;
113                }
114}
115
116void account_on( irc_t *irc, account_t *a )
117{
118        struct aim_user *u;
119       
120        if( a->gc )
121        {
122                /* Trying to enable an already-enabled account */
123                return;
124        }
125       
126        cancel_auto_reconnect( a );
127       
128        u = g_new0 ( struct aim_user, 1 );
129        u->irc = irc;
130        u->prpl = a->prpl;
131        strncpy( u->username, a->user, sizeof( u->username ) - 1 );
132        strncpy( u->password, a->pass, sizeof( u->password ) - 1 );
133        if( a->server) strncpy( u->proto_opt[0], a->server, sizeof( u->proto_opt[0] ) - 1 );
134       
135        a->gc = (struct gaim_connection *) u; /* Bit hackish :-/ */
136        a->reconnect = 0;
137       
138        a->prpl->login( u );
139}
140
141void account_off( irc_t *irc, account_t *a )
142{
143        account_offline( a->gc );
144        a->gc = NULL;
145        if( a->reconnect )
146        {
147                /* Shouldn't happen */
148                cancel_auto_reconnect( a );
149        }
150}
Note: See TracBrowser for help on using the repository browser.