]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/bindings/net: change output format of net.list()
authorTomas Krizek <tomas.krizek@nic.cz>
Fri, 8 Mar 2019 15:44:24 +0000 (16:44 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 12 Mar 2019 11:42:02 +0000 (12:42 +0100)
NEWS
daemon/bindings/net.c

diff --git a/NEWS b/NEWS
index 7c2a17c416d55f7fd1841a4a0a069ea4ed76cd5b..a82954d00a82058c31a55ddbc3c382e3dd214529 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ Incompatible changes
 - DNSSEC is enabled by default
 - upstream packages for Debian now require systemd
 - libknot >= 2.8 is required
+- net.list() output format changed
 
 Improvements
 ------------
index 9139b17bfeed62af4443265e9eae5518de3fb7d8..7bd5fc5850f13c0304ed8aa3cfe64f3a74d9ef5b 100644 (file)
 static int net_list_add(const char *key, void *val, void *ext)
 {
        lua_State *L = (lua_State *)ext;
+       lua_Integer i = lua_tointeger(L, -1);
        endpoint_array_t *ep_array = val;
-       lua_newtable(L);
-       for (size_t i = ep_array->len; i--;) {
-               struct endpoint *ep = ep_array->at[i];
-               lua_pushinteger(L, ep->port);
-               lua_setfield(L, -2, "port");
-               lua_pushboolean(L, ep->flags & NET_UDP);
-               lua_setfield(L, -2, "udp");
-               lua_pushboolean(L, ep->flags & NET_TCP);
-               lua_setfield(L, -2, "tcp");
-               lua_pushboolean(L, ep->flags & NET_TLS);
-               lua_setfield(L, -2, "tls");
-       }
-       lua_setfield(L, -2, key);
+       for (size_t j = ep_array->len; j--;) {
+               struct endpoint *ep = ep_array->at[j];
+               lua_newtable(L);  // connection tuple
+
+               lua_pushstring(L, key);
+               lua_setfield(L, -2, "ip");
+
+               lua_newtable(L);  // "transport" table
+               if (ep->flags & NET_UDP) {
+                       lua_pushliteral(L, "udp");
+                       lua_setfield(L, -2, "protocol");
+                       lua_pushinteger(L, ep->port);
+                       lua_setfield(L, -2, "port");
+                       lua_pushliteral(L, "none");
+                       lua_setfield(L, -2, "security");
+               } else if (ep->flags & NET_TCP) {
+                       lua_pushliteral(L, "tcp");
+                       lua_setfield(L, -2, "protocol");
+                       lua_pushinteger(L, ep->port);
+                       lua_setfield(L, -2, "port");
+                       if (ep->flags & NET_TLS) {
+                               lua_pushliteral(L, "tls");
+                       } else {
+                               lua_pushliteral(L, "none");
+                       }
+                       lua_setfield(L, -2, "security");
+               } else {
+                       lua_pushliteral(L, "unknown");
+                       lua_setfield(L, -2, "protocol");
+               }
+               lua_setfield(L, -2, "transport");
+
+               lua_newtable(L);  // "application" table
+               lua_pushliteral(L, "dns");
+               lua_setfield(L, -2, "protocol");
+               lua_setfield(L, -2, "application");
+
+               lua_settable(L, -3);
+               i++;
+               lua_pushinteger(L, i);
+       }
        return kr_ok();
 }
 
@@ -49,7 +78,9 @@ static int net_list(lua_State *L)
 {
        struct engine *engine = engine_luaget(L);
        lua_newtable(L);
+       lua_pushinteger(L, 1);
        map_walk(&engine->net.endpoints, net_list_add, L);
+       lua_pop(L, 1);
        return 1;
 }