summaryrefslogtreecommitdiffstats
path: root/src/rspamadm/control.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-15 00:20:16 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-15 00:20:16 +0000
commit8e619c6815cc6c44c498e77390454e89ac4930cf (patch)
treed706a7628044a24f099bdbe5353b76756e223f6d /src/rspamadm/control.c
parent72bdfc30aaf95f5c686bce08623938fd6338367b (diff)
downloadrspamd-8e619c6815cc6c44c498e77390454e89ac4930cf.tar.gz
rspamd-8e619c6815cc6c44c498e77390454e89ac4930cf.zip
Use lua for formatting 'fuzzy_stat' control output
Diffstat (limited to 'src/rspamadm/control.c')
-rw-r--r--src/rspamadm/control.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/rspamadm/control.c b/src/rspamadm/control.c
index 979b7403f..b99296ee0 100644
--- a/src/rspamadm/control.c
+++ b/src/rspamadm/control.c
@@ -31,11 +31,14 @@
#include "unix-std.h"
#include <event.h>
#include "libutil/util.h"
+#include "lua/lua_common.h"
+#include "fuzzy_stat.lua.h"
static gchar *control_path = RSPAMD_DBDIR "/rspamd.sock";
gboolean json = FALSE;
gboolean compact = FALSE;
gdouble timeout = 1.0;
+gboolean fuzzy_stat_cmd = FALSE;
static void rspamadm_control (gint argc, gchar **argv);
static const char *rspamadm_control_help (gboolean full_help);
@@ -119,7 +122,18 @@ rspamd_control_finish_handler (struct rspamd_http_connection *conn,
rspamd_ucl_emit_fstring (obj, UCL_EMIT_JSON_COMPACT, &out);
}
else {
- rspamd_ucl_emit_fstring (obj, UCL_EMIT_CONFIG, &out);
+ if (fuzzy_stat_cmd) {
+ rspamadm_execute_lua_ucl_subr (conn->ud, 0, NULL, obj,
+ rspamadm_script_fuzzy_stat);
+
+ rspamd_fstring_free (out);
+ ucl_object_unref (obj);
+ ucl_parser_free (parser);
+ return 0;
+ }
+ else {
+ rspamd_ucl_emit_fstring (obj, UCL_EMIT_CONFIG, &out);
+ }
}
rspamd_fprintf (stdout, "%V", out);
@@ -143,6 +157,7 @@ rspamadm_control (gint argc, gchar **argv)
struct rspamd_http_message *msg;
rspamd_inet_addr_t *addr;
struct timeval tv;
+ lua_State *L;
gint sock;
context = g_option_context_new (
@@ -182,6 +197,7 @@ rspamadm_control (gint argc, gchar **argv)
else if (g_ascii_strcasecmp (cmd, "fuzzystat") == 0 ||
g_ascii_strcasecmp (cmd, "fuzzy_stat") == 0) {
path = "/fuzzystat";
+ fuzzy_stat_cmd = TRUE;
}
else {
rspamd_fprintf (stderr, "unknown command: %s\n", cmd);
@@ -202,6 +218,8 @@ rspamadm_control (gint argc, gchar **argv)
exit (1);
}
+ L = rspamd_lua_init ();
+
conn = rspamd_http_connection_new (NULL, rspamd_control_error_handler,
rspamd_control_finish_handler, RSPAMD_HTTP_CLIENT_SIMPLE,
RSPAMD_HTTP_CLIENT, NULL);
@@ -209,12 +227,13 @@ rspamadm_control (gint argc, gchar **argv)
msg->url = rspamd_fstring_new_init (path, strlen (path));
double_to_tv (timeout, &tv);
- rspamd_http_connection_write_message (conn, msg, NULL, NULL, NULL, sock,
+ rspamd_http_connection_write_message (conn, msg, NULL, NULL, L, sock,
&tv, ev_base);
event_base_loop (ev_base, 0);
rspamd_http_connection_unref (conn);
rspamd_inet_address_destroy (addr);
+ lua_close (L);
close (sock);
}