]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/engine: fixed unpacking of POD JSON vars
authorMarek Vavrusa <marek@vavrusa.com>
Tue, 5 Jul 2016 07:30:02 +0000 (00:30 -0700)
committerMarek Vavrusa <marek@vavrusa.com>
Wed, 6 Jul 2016 06:33:38 +0000 (23:33 -0700)
daemon/engine.c

index 3ab9bbaa59fe2841755f3a093f5c9d25290cf5ed..f0bcfe69a546372c3631461f8d0e54b1049f1ba9 100644 (file)
@@ -250,10 +250,17 @@ static int l_trustanchor(lua_State *L)
        lua_pushboolean(L, true);
        return 1;
 }
-
 /** Unpack JSON object to table */
 static void l_unpack_json(lua_State *L, JsonNode *table)
 {
+       /* Unpack POD */
+       switch(table->tag) {
+               case JSON_STRING: lua_pushstring(L, table->string_); return;
+               case JSON_NUMBER: lua_pushnumber(L, table->number_); return;
+               case JSON_BOOL:   lua_pushboolean(L, table->bool_); return;
+               default: break;
+       }
+       /* Unpack object or array into table */
        lua_newtable(L);
        JsonNode *node = NULL;
        json_foreach(node, table) {
@@ -369,7 +376,7 @@ static int l_trampoline(lua_State *L)
                        return 0;
                }
                JsonNode *root_node = json_decode(ret);
-               if (root_node && (root_node->tag == JSON_OBJECT || root_node->tag == JSON_ARRAY)) {
+               if (root_node) {
                        l_unpack_json(L, root_node);
                } else {
                        lua_pushstring(L, ret);