Commit 2f0b8aed authored by Vladimír Čunát's avatar Vladimír Čunát

qflags: WIP refactor - reimplement option() in lua

parent b7213a6f
......@@ -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);
......
......@@ -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 = {}
......
......@@ -27,18 +27,6 @@
#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)
{
......
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment