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)
{
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);
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 = {}
#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)
{