]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Add method to get classifier options from Lua
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 9 Oct 2016 19:53:52 +0000 (20:53 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 9 Oct 2016 19:53:52 +0000 (20:53 +0100)
src/lua/lua_classifier.c

index 488a9d4776fc843eef8507b8f21508fe3efcf777..871433124b5d3e84a96cfe4b385a03234e3a7a30 100644 (file)
 /* Classifier methods */
 LUA_FUNCTION_DEF (classifier, get_statfiles);
 LUA_FUNCTION_DEF (classifier, get_statfile_by_label);
+LUA_FUNCTION_DEF (classifier, get_param);
 
 static const struct luaL_reg classifierlib_m[] = {
        LUA_INTERFACE_DEF (classifier, get_statfiles),
+       LUA_INTERFACE_DEF (classifier, get_param),
        LUA_INTERFACE_DEF (classifier, get_statfile_by_label),
        {"__tostring", rspamd_lua_class_tostring},
        {NULL, NULL}
@@ -84,6 +86,29 @@ lua_classifier_get_statfiles (lua_State *L)
        return 1;
 }
 
+static gint
+lua_classifier_get_param (lua_State *L)
+{
+       struct rspamd_classifier_config *ccf = lua_check_classifier (L);
+       const gchar *param;
+       const ucl_object_t *value;
+
+       param = luaL_checkstring (L, 2);
+
+       if (ccf != NULL && param != NULL) {
+               value = ucl_object_lookup (ccf->opts, param);
+
+               if (value != NULL) {
+                       ucl_object_push_lua (L, value, true);
+                       return 1;
+               }
+       }
+
+       lua_pushnil (L);
+
+       return 1;
+}
+
 /* Get statfile with specified label */
 static gint
 lua_classifier_get_statfile_by_label (lua_State *L)