1 | /********************************************************************\ |
---|
2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
3 | * * |
---|
4 | * Copyright 2002-2010 Wilmer van der Gaast and others * |
---|
5 | \********************************************************************/ |
---|
6 | |
---|
7 | /* Some IM-core stuff */ |
---|
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 | |
---|
29 | static char *set_eval_away_status( set_t *set, char *value ); |
---|
30 | |
---|
31 | bee_t *bee_new() |
---|
32 | { |
---|
33 | bee_t *b = g_new0( bee_t, 1 ); |
---|
34 | set_t *s; |
---|
35 | |
---|
36 | s = set_add( &b->set, "away", NULL, set_eval_away_status, b ); |
---|
37 | s->flags |= SET_NULL_OK; |
---|
38 | s = set_add( &b->set, "auto_connect", "true", set_eval_bool, b ); |
---|
39 | s = set_add( &b->set, "auto_reconnect", "true", set_eval_bool, b ); |
---|
40 | s = set_add( &b->set, "auto_reconnect_delay", "5*3<900", NULL/*set_eval_account_reconnect_delay*/, b ); |
---|
41 | s = set_add( &b->set, "debug", "false", set_eval_bool, b ); |
---|
42 | s = set_add( &b->set, "password", NULL, NULL/*set_eval_password*/, b ); |
---|
43 | s->flags |= SET_NULL_OK; |
---|
44 | s = set_add( &b->set, "save_on_quit", "true", set_eval_bool, b ); |
---|
45 | s = set_add( &b->set, "status", NULL, set_eval_away_status, b ); |
---|
46 | s->flags |= SET_NULL_OK; |
---|
47 | s = set_add( &b->set, "strip_html", "true", NULL, b ); |
---|
48 | |
---|
49 | b->user = g_malloc( 1 ); |
---|
50 | |
---|
51 | return b; |
---|
52 | } |
---|
53 | |
---|
54 | void bee_free( bee_t *b ) |
---|
55 | { |
---|
56 | while( b->accounts ) |
---|
57 | { |
---|
58 | if( b->accounts->ic ) |
---|
59 | imc_logout( b->accounts->ic, FALSE ); |
---|
60 | else if( b->accounts->reconnect ) |
---|
61 | cancel_auto_reconnect( b->accounts ); |
---|
62 | |
---|
63 | if( b->accounts->ic == NULL ) |
---|
64 | account_del( b, b->accounts ); |
---|
65 | else |
---|
66 | /* Nasty hack, but account_del() doesn't work in this |
---|
67 | case and we don't want infinite loops, do we? ;-) */ |
---|
68 | b->accounts = b->accounts->next; |
---|
69 | } |
---|
70 | |
---|
71 | while( b->set ) |
---|
72 | set_del( &b->set, b->set->key ); |
---|
73 | |
---|
74 | g_free( b->user ); |
---|
75 | g_free( b ); |
---|
76 | } |
---|
77 | |
---|
78 | static char *set_eval_away_status( set_t *set, char *value ) |
---|
79 | { |
---|
80 | bee_t *bee = set->data; |
---|
81 | account_t *a; |
---|
82 | |
---|
83 | g_free( set->value ); |
---|
84 | set->value = g_strdup( value ); |
---|
85 | |
---|
86 | for( a = bee->accounts; a; a = a->next ) |
---|
87 | { |
---|
88 | struct im_connection *ic = a->ic; |
---|
89 | |
---|
90 | if( ic && ic->flags & OPT_LOGGED_IN ) |
---|
91 | imc_away_send_update( ic ); |
---|
92 | } |
---|
93 | |
---|
94 | return value; |
---|
95 | } |
---|