struct rspamd_worker_cfg_parser {
struct rspamd_worker_param_parser *parsers; /**< parsers hash */
gint type; /**< workers quark */
+ gboolean (*def_obj_parser)(ucl_object_t *obj, gpointer ud); /**< default object parser */
+ gpointer def_ud;
UT_hash_handle hh; /**< hash by type */
};
}
}
}
+ if (wparser->def_obj_parser != NULL) {
+ if (! wparser->def_obj_parser (obj, wparser->def_ud)) {
+ return FALSE;
+ }
+ }
}
cfg->workers = g_list_prepend (cfg->workers, wrk);
nhandler->handler = handler;
HASH_ADD_STR (nparser->parsers, name, nhandler);
}
+
+
+void
+rspamd_rcl_register_worker_parser (struct config_file *cfg, gint type,
+ gboolean (*func)(ucl_object_t *, gpointer), gpointer ud)
+{
+ struct rspamd_worker_cfg_parser *nparser;
+ HASH_FIND_INT (cfg->wrk_parsers, &type, nparser);
+ if (nparser == NULL) {
+ /* Allocate new parser for this worker */
+ nparser = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_cfg_parser));
+ nparser->type = type;
+ HASH_ADD_INT (cfg->wrk_parsers, type, nparser);
+ }
+
+ nparser->def_obj_parser = func;
+ nparser->def_ud = ud;
+}
*/
void rspamd_rcl_register_worker_option (struct config_file *cfg, gint type, const gchar *name,
rspamd_rcl_handler_t handler, gpointer target, gsize offset, gint flags);
+
+/**
+ * Regiester a default parser for a worker
+ * @param cfg config structure
+ * @param type type of worker (GQuark)
+ * @param func handler function
+ * @param ud userdata for handler function
+ */
+void rspamd_rcl_register_worker_parser (struct config_file *cfg, gint type,
+ gboolean (*func)(ucl_object_t *, gpointer), gpointer ud);
#endif /* CFG_RCL_H_ */
gint cbref_fin;
/* Config file */
struct config_file *cfg;
+ /* The rest options */
+ ucl_object_t *opts;
};
/* Lua bindings */
}
/* XXX: This fucntions should be rewritten completely */
-#warning "lua_worker_get_option is broken"
static int
lua_worker_get_option (lua_State *L)
{
struct rspamd_lua_worker_ctx *ctx = lua_check_lua_worker (L);
- GList *val;
- gint i;
+ ucl_object_t *val;
const gchar *name;
if (ctx) {
lua_pushnil (L);
}
else {
- val = g_hash_table_lookup (ctx->params, name);
+ val = ucl_object_find_key (ctx->opts, name);
if (val == NULL) {
lua_pushnil (L);
}
else {
- /* Push the array */
- i = 1;
- lua_newtable (L);
- while (val) {
- lua_pushstring (L, val->data);
- lua_rawseti (L, -2, i++);
- val = g_list_next (val);
- }
+ lua_rcl_obj_push (L, val, TRUE);
}
}
}
}
}
+static gboolean
+rspamd_lua_worker_parser (ucl_object_t *obj, gpointer ud)
+{
+ struct rspamd_lua_worker_ctx *ctx = ud;
+
+ ctx->opts = obj;
+
+ return TRUE;
+}
+
gpointer
init_lua_worker (struct config_file *cfg)
{
rspamd_rcl_parse_struct_string, ctx,
G_STRUCT_OFFSET (struct rspamd_lua_worker_ctx, file), 0);
+ rspamd_rcl_register_worker_parser (cfg, type, rspamd_lua_worker_parser, ctx);
+
return ctx;
}