aboutsummaryrefslogtreecommitdiffstats
path: root/account.c
diff options
context:
space:
mode:
Diffstat (limited to 'account.c')
-rw-r--r--account.c76
1 files changed, 63 insertions, 13 deletions
diff --git a/account.c b/account.c
index 168d18c0..186565dd 100644
--- a/account.c
+++ b/account.c
@@ -27,14 +27,17 @@
#include "bitlbee.h"
#include "account.h"
+char *set_eval_account( set_t *set, char *value );
+
account_t *account_add( irc_t *irc, struct prpl *prpl, char *user, char *pass )
{
account_t *a;
+ set_t *s;
if( irc->accounts )
{
for( a = irc->accounts; a->next; a = a->next );
- a = a->next = g_new0 ( account_t, 1 );
+ a = a->next = g_new0( account_t, 1 );
}
else
{
@@ -44,11 +47,66 @@ account_t *account_add( irc_t *irc, struct prpl *prpl, char *user, char *pass )
a->prpl = prpl;
a->user = g_strdup( user );
a->pass = g_strdup( pass );
+ a->auto_connect = 1;
a->irc = irc;
+ s = set_add( &a->set, "auto_connect", NULL, set_eval_account, a );
+ s->flags |= ACC_SET_NOSAVE;
+
+ s = set_add( &a->set, "password", NULL, set_eval_account, a );
+ s->flags |= ACC_SET_NOSAVE;
+
+ s = set_add( &a->set, "server", NULL, set_eval_account, a );
+ s->flags |= ACC_SET_NOSAVE | ACC_SET_OFFLINE_ONLY;
+
+ s = set_add( &a->set, "username", NULL, set_eval_account, a );
+ s->flags |= ACC_SET_NOSAVE | ACC_SET_OFFLINE_ONLY;
+ set_setstr( &a->set, "username", user );
+
return( a );
}
+char *set_eval_account( set_t *set, char *value )
+{
+ account_t *acc = set->data;
+
+ /* Double-check: We refuse to edit on-line accounts. */
+ if( set->flags & ACC_SET_OFFLINE_ONLY && acc->gc )
+ return NULL;
+
+ if( strcmp( set->key, "username" ) == 0 )
+ {
+ g_free( acc->user );
+ acc->user = g_strdup( value );
+ return value;
+ }
+ else if( strcmp( set->key, "password" ) == 0 )
+ {
+ g_free( acc->pass );
+ acc->pass = g_strdup( value );
+ return NULL; /* password shouldn't be visible in plaintext! */
+ }
+ else if( strcmp( set->key, "server" ) == 0 )
+ {
+ g_free( acc->server );
+ if( *value )
+ acc->server = g_strdup( value );
+ else
+ acc->server = NULL;
+ return value;
+ }
+ else if( strcmp( set->key, "auto_connect" ) == 0 )
+ {
+ if( !is_bool( value ) )
+ return NULL;
+
+ acc->auto_connect = bool2int( value );
+ return value;
+ }
+
+ return NULL;
+}
+
account_t *account_get( irc_t *irc, char *id )
{
account_t *a, *ret = NULL;
@@ -128,6 +186,9 @@ void account_del( irc_t *irc, account_t *acc )
irc->accounts = a->next;
}
+ while( a->set )
+ set_del( &a->set, a->set->key );
+
g_free( a->user );
g_free( a->pass );
if( a->server ) g_free( a->server );
@@ -141,8 +202,6 @@ void account_del( irc_t *irc, account_t *acc )
void account_on( irc_t *irc, account_t *a )
{
- struct aim_user *u;
-
if( a->gc )
{
/* Trying to enable an already-enabled account */
@@ -151,17 +210,8 @@ void account_on( irc_t *irc, account_t *a )
cancel_auto_reconnect( a );
- u = g_new0 ( struct aim_user, 1 );
- u->irc = irc;
- u->prpl = a->prpl;
- strncpy( u->username, a->user, sizeof( u->username ) - 1 );
- strncpy( u->password, a->pass, sizeof( u->password ) - 1 );
- if( a->server) strncpy( u->proto_opt[0], a->server, sizeof( u->proto_opt[0] ) - 1 );
-
- a->gc = (struct gaim_connection *) u; /* Bit hackish :-/ */
a->reconnect = 0;
-
- a->prpl->login( u );
+ a->prpl->login( a );
}
void account_off( irc_t *irc, account_t *a )