aboutsummaryrefslogtreecommitdiffstats
path: root/account.c
diff options
context:
space:
mode:
Diffstat (limited to 'account.c')
-rw-r--r--account.c112
1 files changed, 98 insertions, 14 deletions
diff --git a/account.c b/account.c
index 2c6e1069..c7480996 100644
--- a/account.c
+++ b/account.c
@@ -78,22 +78,10 @@ char *set_eval_account( set_t *set, char *value )
if( set->flags & ACC_SET_OFFLINE_ONLY && acc->ic )
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 )
+ if( strcmp( set->key, "server" ) == 0 )
{
g_free( acc->server );
- if( *value )
+ if( value && *value )
{
acc->server = g_strdup( value );
return value;
@@ -104,6 +92,22 @@ char *set_eval_account( set_t *set, char *value )
return g_strdup( set->def );
}
}
+ else if( value == NULL )
+ {
+ /* Noop, the other three can't be NULL. */
+ }
+ else 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, "auto_connect" ) == 0 )
{
if( !is_bool( value ) )
@@ -233,3 +237,83 @@ void account_off( irc_t *irc, account_t *a )
cancel_auto_reconnect( a );
}
}
+
+struct account_reconnect_delay
+{
+ int start;
+ char op;
+ int step;
+ int max;
+};
+
+int account_reconnect_delay_parse( char *value, struct account_reconnect_delay *p )
+{
+ memset( p, 0, sizeof( *p ) );
+ /* A whole day seems like a sane "maximum maximum". */
+ p->max = 86400;
+
+ /* Format: /[0-9]+([*+][0-9]+(<[0-9+]))/ */
+ while( *value && isdigit( *value ) )
+ p->start = p->start * 10 + *value++ - '0';
+
+ /* Sure, call me evil for implementing my own fscanf here, but it's
+ dead simple and I'm immediately at the next part to parse. */
+
+ if( *value == 0 )
+ /* If the string ends now, the delay is constant. */
+ return 1;
+ else if( *value != '+' && *value != '*' )
+ /* Otherwise allow either a + or a * */
+ return 0;
+
+ p->op = *value++;
+
+ /* + or * the delay by this number every time. */
+ while( *value && isdigit( *value ) )
+ p->step = p->step * 10 + *value++ - '0';
+
+ if( *value == 0 )
+ /* Use the default maximum (one day). */
+ return 1;
+ else if( *value != '<' )
+ return 0;
+
+ p->max = 0;
+ value ++;
+ while( *value && isdigit( *value ) )
+ p->max = p->max * 10 + *value++ - '0';
+
+ return p->max > 0;
+}
+
+char *set_eval_account_reconnect_delay( set_t *set, char *value )
+{
+ struct account_reconnect_delay p;
+
+ return account_reconnect_delay_parse( value, &p ) ? value : NULL;
+}
+
+int account_reconnect_delay( account_t *a )
+{
+ char *setting = set_getstr( &a->irc->set, "auto_reconnect_delay" );
+ struct account_reconnect_delay p;
+
+ if( account_reconnect_delay_parse( setting, &p ) )
+ {
+ if( a->auto_reconnect_delay == 0 )
+ a->auto_reconnect_delay = p.start;
+ else if( p.op == '+' )
+ a->auto_reconnect_delay += p.step;
+ else if( p.op == '*' )
+ a->auto_reconnect_delay *= p.step;
+
+ if( a->auto_reconnect_delay > p.max )
+ a->auto_reconnect_delay = p.max;
+ }
+ else
+ {
+ a->auto_reconnect_delay = 0;
+ }
+
+ return a->auto_reconnect_delay;
+}