From: Aki Tuomi Date: Fri, 8 Jan 2016 12:38:01 +0000 (+0200) Subject: Allow 1 or 0 as boolean too X-Git-Tag: dnsdist-1.0.0-alpha2~36^2~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9895aa4b8d45ae8b662972bffb9bb128da74d0ed;p=pdns Allow 1 or 0 as boolean too --- diff --git a/pdns/json.cc b/pdns/json.cc index 29e24f2ca..cab7fb4fa 100644 --- a/pdns/json.cc +++ b/pdns/json.cc @@ -93,9 +93,11 @@ bool boolFromJson(const Json container, const std::string& key) auto val = container[key]; if (val.is_bool()) { return val.bool_value(); - } else { - throw JsonException("Key '" + string(key) + "' not present or not a Bool"); + } else if (val.is_number()) { + if (val.int_value() == 1) return true; + else if (val.int_value() == 0) return false; } + throw JsonException("Key '" + string(key) + "' not present or not a Bool"); } bool boolFromJson(const Json container, const std::string& key, const bool default_value) @@ -103,7 +105,9 @@ bool boolFromJson(const Json container, const std::string& key, const bool defau auto val = container[key]; if (val.is_bool()) { return val.bool_value(); - } else { - return default_value; + } else if (val.is_number()) { + if (val.int_value() == 1) return true; + else if (val.int_value() == 0) return false; } + return default_value; }