From: Vasek Sraier Date: Fri, 24 Apr 2020 13:26:01 +0000 (+0200) Subject: sysrepo-lua: fixed schema traversal X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb27464e8f4944bee612c85cad4bf053ebdca1d2;p=thirdparty%2Fknot-resolver.git sysrepo-lua: fixed schema traversal --- diff --git a/modules/sysrepo-lua/cbindings/sysrepo_clib.c b/modules/sysrepo-lua/cbindings/sysrepo_clib.c index 71cd4b040..6aabf9ffc 100644 --- a/modules/sysrepo-lua/cbindings/sysrepo_clib.c +++ b/modules/sysrepo-lua/cbindings/sysrepo_clib.c @@ -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) { diff --git a/modules/sysrepo-lua/cbindings/sysrepo_clib.h b/modules/sysrepo-lua/cbindings/sysrepo_clib.h index e771a11de..709c806aa 100644 --- a/modules/sysrepo-lua/cbindings/sysrepo_clib.h +++ b/modules/sysrepo-lua/cbindings/sysrepo_clib.h @@ -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 */ diff --git a/modules/sysrepo-lua/ffi.lua.in b/modules/sysrepo-lua/ffi.lua.in index a1c843eb7..31ac55c87 100644 --- a/modules/sysrepo-lua/ffi.lua.in +++ b/modules/sysrepo-lua/ffi.lua.in @@ -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(); diff --git a/modules/sysrepo-lua/model.lua b/modules/sysrepo-lua/model.lua index ad11500c9..d599b6b7a 100644 --- a/modules/sysrepo-lua/model.lua +++ b/modules/sysrepo-lua/model.lua @@ -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'], }