[prev in list] [next in list] [prev in thread] [next in thread] 

List:       varnish-commit
Subject:    [master] 80c0b3dad param: Extract boolean parsing in its own function
From:       Dridi Boukelmoune <dridi.boukelmoune () gmail ! com>
Date:       2022-06-27 13:38:06
Message-ID: 20220627133806.AE2E461149 () lists ! varnish-cache ! org
[Download RAW message or body]


commit 80c0b3dadae280b2252ad0c532b0b7528e6447c6
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date:   Tue May 31 08:06:15 2022 +0200

    param: Extract boolean parsing in its own function

diff --git a/bin/varnishd/mgt/mgt_param_tweak.c b/bin/varnishd/mgt/mgt_param_tweak.c
index cba614415..342f3c0e9 100644
--- a/bin/varnishd/mgt/mgt_param_tweak.c
+++ b/bin/varnishd/mgt/mgt_param_tweak.c
@@ -152,33 +152,43 @@ tweak_double(struct vsb *vsb, const struct parspec *par, const char *arg)
 
 /*--------------------------------------------------------------------*/
 
+static int
+parse_boolean(struct vsb *vsb, const char *arg)
+{
+
+	if (!strcasecmp(arg, "off"))
+		return (0);
+	if (!strcasecmp(arg, "disable"))
+		return (0);
+	if (!strcasecmp(arg, "no"))
+		return (0);
+	if (!strcasecmp(arg, "false"))
+		return (0);
+	if (!strcasecmp(arg, "on"))
+		return (1);
+	if (!strcasecmp(arg, "enable"))
+		return (1);
+	if (!strcasecmp(arg, "yes"))
+		return (1);
+	if (!strcasecmp(arg, "true"))
+		return (1);
+
+	VSB_cat(vsb, "use \"on\" or \"off\"\n");
+	return (-1);
+}
+
 int v_matchproto_(tweak_t)
 tweak_boolean(struct vsb *vsb, const struct parspec *par, const char *arg)
 {
 	volatile unsigned *dest;
+	int val;
 
 	dest = par->priv;
 	if (arg != NULL && arg != JSON_FMT) {
-		if (!strcasecmp(arg, "off"))
-			*dest = 0;
-		else if (!strcasecmp(arg, "disable"))
-			*dest = 0;
-		else if (!strcasecmp(arg, "no"))
-			*dest = 0;
-		else if (!strcasecmp(arg, "false"))
-			*dest = 0;
-		else if (!strcasecmp(arg, "on"))
-			*dest = 1;
-		else if (!strcasecmp(arg, "enable"))
-			*dest = 1;
-		else if (!strcasecmp(arg, "yes"))
-			*dest = 1;
-		else if (!strcasecmp(arg, "true"))
-			*dest = 1;
-		else {
-			VSB_cat(vsb, "use \"on\" or \"off\"\n");
+		val = parse_boolean(vsb, arg);
+		if (val < 0)
 			return (-1);
-		}
+		*dest = val;
 	} else if (arg == JSON_FMT) {
 		VSB_printf(vsb, "%s", *dest ? "true" : "false");
 	} else {
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic