summaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-02-15 17:42:20 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-02-15 17:42:20 +0000
commit7bd1072c639cb767b3afaf2e0575aeb9f988bc97 (patch)
treeccbe8c4cfa292f0b1c661783a47b3c4ec144fdbd /src/lua
parent33e4cafb3b1adfd322a7000e89e4347eb1453d92 (diff)
downloadrspamd-7bd1072c639cb767b3afaf2e0575aeb9f988bc97.tar.gz
rspamd-7bd1072c639cb767b3afaf2e0575aeb9f988bc97.zip
Also allow setting description.
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_config.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 4e9ce80ff..df998b8a0 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -207,10 +207,11 @@ LUA_FUNCTION_DEF (config, register_callback_symbol);
LUA_FUNCTION_DEF (config, register_callback_symbol_priority);
/**
- * @method rspamd_config:set_metric_symbol(name, weight, [metric])
+ * @method rspamd_config:set_metric_symbol(name, weight, [description], [metric])
* Set the value of a specified symbol in a metric
* @param {string} name name of symbol
* @param {number} weight the weight multiplier
+ * @param {string} description symbolic description
* @param {string} metric metric name (default metric is used if this value is absent)
*/
LUA_FUNCTION_DEF (config, set_metric_symbol);
@@ -1105,7 +1106,7 @@ lua_config_set_metric_symbol (lua_State * L)
{
struct rspamd_config *cfg = lua_check_config (L);
gchar *name;
- const gchar *metric_name = DEFAULT_METRIC;
+ const gchar *metric_name = DEFAULT_METRIC, *description = NULL;
double weight;
struct rspamd_symbol_def *s;
struct metric *metric;
@@ -1113,8 +1114,12 @@ lua_config_set_metric_symbol (lua_State * L)
if (cfg) {
name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2));
weight = luaL_checknumber (L, 3);
+
if (lua_gettop (L) > 3) {
- metric_name = luaL_checkstring (L, 4);
+ description = luaL_checkstring (L, 4);
+ }
+ if (lua_gettop (L) > 4) {
+ metric_name = luaL_checkstring (L, 5);
}
metric = g_hash_table_lookup (cfg->metrics, metric_name);
@@ -1122,7 +1127,7 @@ lua_config_set_metric_symbol (lua_State * L)
if (metric == NULL) {
msg_err ("metric named %s is not defined", metric_name);
}
- else if (name) {
+ else if (name != NULL) {
s = g_hash_table_lookup (metric->symbols, name);
if (s == NULL) {
@@ -1131,7 +1136,12 @@ lua_config_set_metric_symbol (lua_State * L)
s = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*s));
s->name = rspamd_mempool_strdup (cfg->cfg_pool, name);
s->weight_ptr = rspamd_mempool_alloc (cfg->cfg_pool,
- sizeof (gdouble));
+ sizeof (gdouble));
+
+ if (description != NULL) {
+ s->description = rspamd_mempool_strdup (cfg->cfg_pool,
+ description);
+ }
g_hash_table_insert (metric->symbols, s->name, s);
g_hash_table_insert (cfg->metrics_symbols, s->name, metric);