]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
qflags: WIP refactor - reimplement option() in lua
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 25 Apr 2017 15:59:49 +0000 (17:59 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 1 Aug 2017 14:51:04 +0000 (16:51 +0200)
daemon/engine.c
daemon/lua/sandbox.lua
lib/rplan.c
lib/rplan.h

index 034ab836faae76d1e64733f50b882c96a386cc5c..d0864700eae689e5c3d3e26fd562dadc8e648f27 100644 (file)
@@ -266,37 +266,6 @@ static int l_moduledir(lua_State *L)
        return 1;
 }
 
-/** Get/set context option. */
-static int l_option(lua_State *L)
-{
-       struct engine *engine = engine_luaget(L);
-       /* Look up option name */
-       unsigned opt_code = 0;
-       if (lua_isstring(L, 1)) {
-               const char *opt = lua_tostring(L, 1);
-               for (const knot_lookup_t *it = kr_query_flag_names(); it->name; ++it) {
-                       if (strcmp(it->name, opt) == 0) {
-                               opt_code = it->id;
-                               break;
-                       }
-               }
-               if (!opt_code) {
-                       lua_pushstring(L, "invalid option name");
-                       lua_error(L);
-               }
-       }
-       /* Get or set */
-       if (lua_isboolean(L, 2) || lua_isnumber(L, 2)) {
-               if (lua_toboolean(L, 2)) {
-                       engine->resolver.options |= opt_code;
-               } else {
-                       engine->resolver.options &= ~opt_code; 
-               }
-       }
-       lua_pushboolean(L, engine->resolver.options & opt_code);
-       return 1;
-}
-
 /** @internal for l_trustanchor: */
 static void ta_add(zs_scanner_t *zs)
 {
@@ -601,8 +570,6 @@ static int init_state(struct engine *engine)
        lua_setglobal(engine->L, "moduledir");
        lua_pushcfunction(engine->L, l_verbose);
        lua_setglobal(engine->L, "verbose");
-       lua_pushcfunction(engine->L, l_option);
-       lua_setglobal(engine->L, "option");
        lua_pushcfunction(engine->L, l_setuser);
        lua_setglobal(engine->L, "user");
        lua_pushcfunction(engine->L, l_trustanchor);
index 46a2e513b6cd74910b61d28413a918110c48e134..84e8ec1e1f145f228a335cd17a44be6fda7ae0fd 100644 (file)
@@ -54,6 +54,20 @@ function reorder_RR(val)
        return option('REORDER_RR', val)
 end
 
+-- Get/set resolver options via name (string)
+function option(name, val)
+       local flags = kres.context().options;
+       -- Note: no way to test existence of flags[name] but we want error anyway.
+       name = string.upper(name) -- convenience
+       if val ~= nil then
+               if (val ~= true) and (val ~= false) then
+                       panic('invalid option value: ' .. tostring(val))
+               end
+               flags[name] = val;
+       end
+       return flags[name];
+end
+
 -- Function aliases
 -- `env.VAR returns os.getenv(VAR)`
 env = {}
index c56a6916e130e786763f1ccebcb812456a8d2e00..50afcdbd360efa16d0ae2505a0346c0c07bbc0f9 100644 (file)
 #define QUERY_PROVIDES(q, name, cls, type) \
     ((q)->sclass == (cls) && (q)->stype == type && knot_dname_is_equal((q)->sname, name))
 
-/** @internal LUT of query flag names. */
-const knot_lookup_t query_flag_names[] = { // FIXME
-       //#define X(flag, _) { QUERY_ ## flag, #flag },
-       //QUERY_FLAGS(X)
-       //#undef X
-       { 0, NULL }
-};
-
-const knot_lookup_t *kr_query_flag_names(void)
-{
-       return query_flag_names;
-}
 
 static struct kr_query *query_create(knot_mm_t *pool, const knot_dname_t *name, uint32_t uid)
 {
index 5e623ea664e013447541f85d52f51d288fe114e5..3098e46717f7ce12d92985506d55b21c93b22425 100644 (file)
@@ -67,9 +67,6 @@ struct kr_qflags {
        #undef X
 };
 
-/** Query flag names table */
-KR_EXPORT KR_CONST
-const knot_lookup_t *kr_query_flag_names(void);
 
 /**
  * Single query representation.