Browse Source

uri_get_param_bool2 returning a tristate

Luke Dashjr 11 years ago
parent
commit
29ca896e17
2 changed files with 17 additions and 2 deletions
  1. 10 2
      util.c
  2. 7 0
      util.h

+ 10 - 2
util.c

@@ -2160,12 +2160,12 @@ nextmatch:
 	return URI_FIND_PARAM_FOUND;
 	return URI_FIND_PARAM_FOUND;
 }
 }
 
 
-bool uri_get_param_bool(const char * const uri, const char * const param, const bool defval)
+enum bfg_tristate uri_get_param_bool2(const char * const uri, const char * const param)
 {
 {
 	bool invert, foundval = true;
 	bool invert, foundval = true;
 	const char *q = uri_find_param(uri, param, &invert);
 	const char *q = uri_find_param(uri, param, &invert);
 	if (!q)
 	if (!q)
-		return defval;
+		return BTS_UNKNOWN;
 	else
 	else
 	if (q != URI_FIND_PARAM_FOUND)
 	if (q != URI_FIND_PARAM_FOUND)
 	{
 	{
@@ -2179,6 +2179,14 @@ bool uri_get_param_bool(const char * const uri, const char * const param, const
 	return foundval;
 	return foundval;
 }
 }
 
 
+bool uri_get_param_bool(const char * const uri, const char * const param, const bool defval)
+{
+	const enum bfg_tristate rv = uri_get_param_bool2(uri, param);
+	if (rv == BTS_UNKNOWN)
+		return defval;
+	return rv;
+}
+
 static
 static
 void _test_uri_find_param(const char * const uri, const char * const param, const ssize_t expect_offset, const int expect_invert)
 void _test_uri_find_param(const char * const uri, const char * const param, const ssize_t expect_offset, const int expect_invert)
 {
 {

+ 7 - 0
util.h

@@ -81,6 +81,12 @@
 
 
 #define IGNORE_RETURN_VALUE(expr)  {if(expr);}(void)0
 #define IGNORE_RETURN_VALUE(expr)  {if(expr);}(void)0
 
 
+enum bfg_tristate {
+	BTS_FALSE = (int)false,
+	BTS_TRUE  = (int)true,
+	BTS_UNKNOWN,
+};
+
 #if JANSSON_MAJOR_VERSION >= 2
 #if JANSSON_MAJOR_VERSION >= 2
 #define JSON_LOADS(str, err_ptr) json_loads((str), 0, (err_ptr))
 #define JSON_LOADS(str, err_ptr) json_loads((str), 0, (err_ptr))
 #else
 #else
@@ -121,6 +127,7 @@ extern void test_domain_funcs();
 
 
 extern bool bfg_strtobool(const char *, char **endptr, int opts);
 extern bool bfg_strtobool(const char *, char **endptr, int opts);
 
 
+extern enum bfg_tristate uri_get_param_bool2(const char *ri, const char *param);
 extern bool uri_get_param_bool(const char *uri, const char *param, bool defval);
 extern bool uri_get_param_bool(const char *uri, const char *param, bool defval);
 extern void test_uri_get_param();
 extern void test_uri_get_param();