]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
sysrepo-lua: fixed schema traversal
authorVasek Sraier <git@vakabus.cz>
Fri, 24 Apr 2020 13:26:01 +0000 (15:26 +0200)
committerVasek Sraier <git@vakabus.cz>
Fri, 24 Apr 2020 13:26:01 +0000 (15:26 +0200)
modules/sysrepo-lua/cbindings/sysrepo_clib.c
modules/sysrepo-lua/cbindings/sysrepo_clib.h
modules/sysrepo-lua/ffi.lua.in
modules/sysrepo-lua/model.lua

index 71cd4b040f345be0df293e6da43c2c3bbf1fa1bc..6aabf9ffc1fada694af6812d60c49676e5a421b4 100644 (file)
@@ -287,12 +287,14 @@ KR_EXPORT const struct lys_node* schema_child_first(const struct lys_node* paren
                return NULL;
        }
 
-       return parent->child;
+       return lys_getnext(NULL, parent, NULL, 0);
 }
 
-KR_EXPORT const struct lys_node* schema_child_next(const struct lys_node* prev_child) {
+KR_EXPORT const struct lys_node* schema_child_next(const struct lys_node* parent, const struct lys_node* prev_child) {
        assert(prev_child != NULL);
-       return prev_child->next;
+       assert(parent != NULL);
+
+       return lys_getnext(prev_child, parent, NULL, 0);
 }
 
 KR_EXPORT const char* schema_get_name(const struct lys_node* node) {
index e771a11dee0a596c5a26293f12db6866d54225ed..709c806aaf985fd51fd5b1c7a2be15594cc8ae50 100644 (file)
@@ -67,7 +67,7 @@ KR_EXPORT const struct lys_module* schema_get_module(const struct lys_node* sche
 /** Given a libyang schema node, returns it's first child (or NULL if there aren't any) */
 KR_EXPORT const struct lys_node* schema_child_first(const struct lys_node* parent);
 /** Given a libyang schema node, return next sibling or NULL if there isn't any */
-KR_EXPORT const struct lys_node* schema_child_next(const struct lys_node* prev_child);
+KR_EXPORT const struct lys_node* schema_child_next(const struct lys_node* parent, const struct lys_node* prev_child);
 /** Given a libyang schema node, return it's name */
 KR_EXPORT const char* schema_get_name(const struct lys_node* node);
 /** Get schema root */
index a1c843eb706ec28bfd87609fe9682157ad09f4e7..31ac55c873c6a5944e57c032caf1b8711167496e 100644 (file)
@@ -38,8 +38,7 @@ local function initialize_ffi()
         /** Given a libyang schema node, returns it's first child */
         const struct lys_node* schema_child_first(const struct lys_node* parent);
         /** Given a libyang schema node, return next sibling or NULL if there isn't any */
-        const struct lys_node* schema_child_next(const struct lys_node* prev_child);
-        /** Given a libyang schema node, return it's name */
+        const struct lys_node* schema_child_next(const struct lys_node* parent, const struct lys_node* prev_child);        /** Given a libyang schema node, return it's name */
         const char* schema_get_name(const struct lys_node* node);
         /** Get schema root */
         const struct lys_node* schema_root();
index ad11500c913a00f5a42df6315d13cfb6ef9f4a4a..d599b6b7a0bc8fbfddbd5f3022ac4fc75f1e57c6 100644 (file)
@@ -40,7 +40,7 @@ function Helpers.get_schema_children_table(schema_node)
     while child ~= nil do
         local nm = ffi.string(clib().schema_get_name(child))
         lookup[nm] = child
-        child = clib().schema_child_next(child)
+        child = clib().schema_child_next(schema_node, child)
     end
 
     return lookup
@@ -450,10 +450,12 @@ local function ListenInterfacesNodeFactory(name)
         -- return configured container bind node
         return ContainerBindNode(
             "listen-interfaces",
-            { ["ip-address"] = "string", ["name"] = "string", ["port"] = "uint16", ["kind"] = "string" },
+            { ["ip-address"] = "string", ["id"] = "string", ["port"] = "uint16", ["kind"] = "string" },
+            -- { ["ip-address"] = "string", ["name"] = "string", ["port"] = "uint16" },
             get_arg_func,
             function(v)
                 net.listen(v["ip-address"], v["port"], { kind = v["kind"] })
+                -- net.listen(v["ip-address"], v["port"])
             end
         )
     end
@@ -468,7 +470,13 @@ local function TLSNode()
     return ContainerBindNode(
         "tls",
         { ["cert"] = "string", ["cert-key"] = "string" },
-        nil,
+        function()
+            local t = net.tls()
+            return {
+                ["cert"] = t[1],
+                ["cert-key"] = t[2],
+            }
+        end,
         function(vals) net.tls(vals["cert"], vals["cert-key"]) end
     )
 end
@@ -486,10 +494,13 @@ end
 local function get_listen_interfaces()
     -- the data structure from `net.list()` has to be transformed to be understood
     -- by ContainerBindNode
+    local id = -1;
+
     local function transform(arg)
+        id = id + 1
         return {
             ["ip-address"] = arg['transport']['ip'],
-            ["name"] = arg["kind"] .. "://" .. arg['transport']['ip'] .. tostring(arg['transport']['port']),
+            ["id"] = tostring(id),
             ["port"] = arg['transport']['port'],
             ["kind"] = arg['kind'],
         }