diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2008-08-24 19:01:05 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2008-08-24 19:01:05 +0100 |
commit | 7125cb3775a0e384c0f2fc08fd56df9582199502 (patch) | |
tree | 7972791c53152194e4c5053801abd071c17128ca /account.c | |
parent | 934dddf3614eae2b4f305f42583b070bdbd5bc86 (diff) |
Added SET_INVALID, which set evaluators should now return instead of NULL
when the given value is not accepted. This to allow certain variables
actually be set to NULL (server, for example). This should fully close
#444.
Diffstat (limited to 'account.c')
-rw-r--r-- | account.c | 31 |
1 files changed, 18 insertions, 13 deletions
@@ -76,7 +76,7 @@ char *set_eval_account( set_t *set, char *value ) /* Double-check: We refuse to edit on-line accounts. */ if( set->flags & ACC_SET_OFFLINE_ONLY && acc->ic ) - return NULL; + return SET_INVALID; if( strcmp( set->key, "server" ) == 0 ) { @@ -88,14 +88,10 @@ char *set_eval_account( set_t *set, char *value ) } else { - acc->server = NULL; + acc->server = g_strdup( set->def ); 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 ); @@ -104,20 +100,29 @@ char *set_eval_account( set_t *set, char *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! */ + if( value ) + { + g_free( acc->pass ); + acc->pass = g_strdup( value ); + return NULL; /* password shouldn't be visible in plaintext! */ + } + else + { + /* NULL can (should) be stored in the set_t + variable, but is otherwise not correct. */ + return SET_INVALID; + } } else if( strcmp( set->key, "auto_connect" ) == 0 ) { if( !is_bool( value ) ) - return NULL; + return SET_INVALID; acc->auto_connect = bool2int( value ); return value; } - return NULL; + return SET_INVALID; } account_t *account_get( irc_t *irc, char *id ) @@ -257,7 +262,7 @@ int account_reconnect_delay_parse( char *value, struct account_reconnect_delay * 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. */ + dead simple and I immediately know where to continue parsing. */ if( *value == 0 ) /* If the string ends now, the delay is constant. */ @@ -290,7 +295,7 @@ 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; + return account_reconnect_delay_parse( value, &p ) ? value : SET_INVALID; } int account_reconnect_delay( account_t *a ) |