]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Move special bolean feature to remotebackend
authorAki Tuomi <cmouse@cmouse.fi>
Sun, 10 Jan 2016 18:22:27 +0000 (20:22 +0200)
committerAki Tuomi <cmouse@cmouse.fi>
Mon, 11 Jan 2016 18:44:20 +0000 (20:44 +0200)
modules/remotebackend/remotebackend.cc
modules/remotebackend/remotebackend.hh
pdns/json.cc

index 1b10a909547db832bc8ba7a3c979cb039f775255..19a85152aabd5b28576c6f987bcf5dfcc57cdde3 100644 (file)
@@ -357,7 +357,7 @@ bool RemoteBackend::getDomainKeys(const DNSName& name, unsigned int kind, std::v
      DNSBackend::KeyData key;
      key.id = intFromJson(jsonKey, "id");
      key.flags = intFromJson(jsonKey, "flags");
-     key.active = boolFromJson(jsonKey, "active");
+     key.active = asBool(jsonKey["active"]);
      key.content = stringFromJson(jsonKey, "content");
      keys.push_back(key);
    }
index b3c745f8d89df8405f832013c9456a7efdd605ad..8e0ffa5e63de06a9225921421a6f3aa37be542a6 100644 (file)
@@ -188,5 +188,15 @@ class RemoteBackend : public DNSBackend
       if (value.is_string()) return value.string_value();
       throw JsonException("Json value not convertible to String");
     };
+
+    bool asBool(const Json& value) {
+      if (value.is_bool()) return value.bool_value();
+      try {
+        string val = asString(value);
+        if (val == "0") return false;
+        if (val == "1") return true;
+      } catch (JsonException) {};
+      throw JsonException("Json value not convertible to boolean");
+    };
 };
 #endif
index cab7fb4faaea977979a9fd05bbe96afb57623e3a..1d76b018982779c71148d0414f0f8098ebf1f4cf 100644 (file)
@@ -93,9 +93,6 @@ bool boolFromJson(const Json container, const std::string& key)
   auto val = container[key];
   if (val.is_bool()) {
     return val.bool_value();
-  } 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");
 }
@@ -105,9 +102,6 @@ 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 if (val.is_number())  {
-    if (val.int_value() == 1) return true;
-    else if (val.int_value() == 0) return false;
   }
   return default_value;
 }