aboutsummaryrefslogtreecommitdiffstats
path: root/set.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2008-08-24 19:01:05 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2008-08-24 19:01:05 +0100
commit7125cb3775a0e384c0f2fc08fd56df9582199502 (patch)
tree7972791c53152194e4c5053801abd071c17128ca /set.c
parent934dddf3614eae2b4f305f42583b070bdbd5bc86 (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 'set.c')
-rw-r--r--set.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/set.c b/set.c
index 112e6937..c83fc6f8 100644
--- a/set.c
+++ b/set.c
@@ -25,6 +25,9 @@
#define BITLBEE_CORE
#include "bitlbee.h"
+/* Used to use NULL for this, but NULL is actually a "valid" value. */
+char *SET_INVALID = "nee";
+
set_t *set_add( set_t **head, char *key, char *def, set_eval eval, void *data )
{
set_t *s = set_find( head, key );
@@ -113,9 +116,20 @@ int set_setstr( set_t **head, char *key, char *value )
char *nv = value;
if( !s )
+ /*
+ Used to do this, but it never really made sense.
s = set_add( head, key, NULL, NULL, NULL );
+ */
+ return 0;
- if( s->eval && !( nv = s->eval( s, value ) ) )
+ if( value == NULL && ( s->flags & SET_NULL_OK ) == 0 )
+ return 0;
+
+ /* Call the evaluator. For invalid values, evaluators should now
+ return SET_INVALID, but previously this was NULL. Try to handle
+ that too if NULL is not an allowed value for this setting. */
+ if( s->eval && ( ( nv = s->eval( s, value ) ) == SET_INVALID ||
+ ( ( s->flags & SET_NULL_OK ) == 0 && nv == NULL ) ) )
return 0;
if( s->value )
@@ -186,14 +200,14 @@ char *set_eval_int( set_t *set, char *value )
for( ; *s; s ++ )
if( !isdigit( *s ) )
- return NULL;
+ return SET_INVALID;
return value;
}
char *set_eval_bool( set_t *set, char *value )
{
- return is_bool( value ) ? value : NULL;
+ return is_bool( value ) ? value : SET_INVALID;
}
char *set_eval_to_char( set_t *set, char *value )
@@ -225,7 +239,7 @@ char *set_eval_ops( set_t *set, char *value )
irc_write( irc, ":%s!%s@%s MODE %s %s %s %s", irc->mynick, irc->mynick, irc->myhost,
irc->channel, "-oo", irc->nick, irc->mynick );
else
- return NULL;
+ return SET_INVALID;
return value;
}