aboutsummaryrefslogtreecommitdiffstats
path: root/src/webui.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-04-22 15:01:37 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-04-22 15:01:37 +0100
commit630ceb658d8a0ab0804280fb900553e58f3af3c0 (patch)
treea7caadc52421e0e44db3d670f8f74709cdfd2cc3 /src/webui.c
parent74784ef3bedfa11642df961d900088ebb7e003f3 (diff)
downloadrspamd-630ceb658d8a0ab0804280fb900553e58f3af3c0.tar.gz
rspamd-630ceb658d8a0ab0804280fb900553e58f3af3c0.zip
Remove legacy code.
Diffstat (limited to 'src/webui.c')
-rw-r--r--src/webui.c368
1 files changed, 0 insertions, 368 deletions
diff --git a/src/webui.c b/src/webui.c
index 287f64a0e..3027947bc 100644
--- a/src/webui.c
+++ b/src/webui.c
@@ -321,374 +321,6 @@ rspamd_webui_check_password (struct rspamd_http_connection_entry *entry,
return ret;
}
-struct scan_callback_data {
- struct rspamd_task *task;
- struct evhttp_request *req;
- struct rspamd_webui_worker_ctx *ctx;
- gboolean processed;
- struct evbuffer *out;
- gboolean first_symbol;
-};
-
-#if 0
-/*
- * Write metric result in json format
- */
-static void
-rspamd_webui_scan_metric_symbols_callback (gpointer key, gpointer value, gpointer ud)
-{
- struct scan_callback_data *cbdata = ud;
- struct symbol *s = value;
- GList *cur;
-
- /* Show data for a single symbol */
- if (cbdata->first_symbol) {
- cbdata->first_symbol = FALSE;
- evbuffer_add_printf (cbdata->out, "{\"name\":\"%s\",\"weight\":%.2f", s->name, s->score);
- }
- else {
- evbuffer_add_printf (cbdata->out, ",{\"name\":\"%s\",\"weight\":%.2f", s->name, s->score);
- }
- if (s->options) {
- evbuffer_add_printf (cbdata->out, ",\"options\":[");
- cur = s->options;
- while (cur) {
- evbuffer_add_printf (cbdata->out, "\"%s\"%c", (gchar *)cur->data, g_list_next (cur) ? ',' : ']');
- cur = g_list_next (cur);
- }
- }
- evbuffer_add (cbdata->out, "}", 1);
-}
-/*
- * Called before destroying of task's session
- */
-static void
-rspamd_webui_scan_task_free (gpointer arg)
-{
- struct scan_callback_data *cbdata = arg;
- struct evbuffer *evb;
- struct metric_result *mres;
-
- if (cbdata->processed) {
- evb = evbuffer_new ();
- if (!evb) {
- msg_err ("cannot allocate evbuffer for reply");
- evhttp_send_reply (cbdata->req, HTTP_INTERNAL, "500 insufficient memory", NULL);
- rspamd_task_free_hard (cbdata->task);
- return;
- }
- cbdata->out = evb;
- cbdata->first_symbol = TRUE;
-
- mres = g_hash_table_lookup (cbdata->task->results, DEFAULT_METRIC);
- if (mres) {
- evbuffer_add_printf (evb, "{\"is_spam\": %s,"
- "\"is_skipped\":%s,"
- "\"score\":%.2f,"
- "\"required_score\":%.2f,"
- "\"action\":\"%s\","
- "\"symbols\":[",
- mres->score >= mres->metric->actions[METRIC_ACTION_REJECT].score ? "true" : "false",
- cbdata->task->is_skipped ? "true" : "false", mres->score,
- mres->metric->actions[METRIC_ACTION_REJECT].score,
- str_action_metric (
- check_metric_action (mres->score, mres->metric->actions[METRIC_ACTION_REJECT].score, mres->metric)));
- /* Iterate all symbols */
- g_hash_table_foreach (mres->symbols, http_scan_metric_symbols_callback, cbdata);
- evbuffer_add (evb, "]}" CRLF, 4);
- }
- else {
- evbuffer_add_printf (evb, "{\"success\":false}" CRLF);
- }
- evhttp_add_header (cbdata->req->output_headers, "Connection", "close");
- http_calculate_content_length (evb, cbdata->req);
-
- evhttp_send_reply (cbdata->req, HTTP_OK, "OK", evb);
- evbuffer_free (evb);
- rspamd_task_free_hard (cbdata->task);
- }
- /* If task is not processed, just do nothing */
- return;
-}
-
-/*
- * Handler of session destroying
- */
-static void
-rspamd_webui_scan_task_event_helper (int fd, short what, gpointer arg)
-{
- struct scan_callback_data *cbdata = arg;
-
- destroy_session (cbdata->task->s);
-}
-
-/*
- * Called if all filters are processed, non-threaded and simple version
- */
-static gboolean
-rspamd_webui_scan_task_fin (gpointer arg)
-{
- struct scan_callback_data *cbdata = arg;
- static struct timeval tv = {.tv_sec = 0, .tv_usec = 0 };
-#if 0
- if (cbdata->task->state != WRITING_REPLY) {
- process_statfiles (cbdata->task);
- cbdata->task->state = WRITE_REPLY;
- }
-
- /* Check if we have all events finished */
- if (cbdata->task->state != WRITING_REPLY) {
- if (cbdata->task->fin_callback) {
- cbdata->task->fin_callback (cbdata->task->fin_arg);
- }
- else {
- /*
- * XXX: we cannot call this one directly as session mutex is locked, so we need to plan some event
- * unfortunately
- * destroy_session (cbdata->task->s);
- */
- event_base_once (cbdata->ctx->ev_base, -1, EV_TIMEOUT, http_scan_task_event_helper, cbdata, &tv);
- }
- }
-#endif
- return TRUE;
-}
-
-/*
- * Called if session was restored inside fin callback
- */
-static void
-rspamd_webui_scan_task_restore (gpointer arg)
-{
- struct scan_callback_data *cbdata = arg;
-
- /* Special state */
-#if 0
- cbdata->task->state = WRITING_REPLY;
-#endif
-}
-
-/* Prepare callback data for scan */
-static struct scan_callback_data*
-rspamd_webui_prepare_scan (struct evhttp_request *req, struct rspamd_webui_worker_ctx *ctx, struct evbuffer *in, GError **err)
-{
- struct rspamd_task *task;
- struct scan_callback_data *cbdata;
-
- /* Check for data */
- if (EVBUFFER_LENGTH (in) == 0) {
- g_set_error (err, g_quark_from_static_string ("webui"), 500, "no message for learning");
- return NULL;
- }
-
- /* Prepare task */
- task = rspamd_task_new (ctx->worker);
- if (task == NULL) {
- g_set_error (err, g_quark_from_static_string ("webui"), 500, "task cannot be created");
- return NULL;
- }
-
- task->msg = g_string_new_len (EVBUFFER_DATA (in), EVBUFFER_LENGTH (in));
-
- task->resolver = ctx->resolver;
- task->ev_base = ctx->ev_base;
-
- cbdata = memory_pool_alloc (task->task_pool, sizeof (struct scan_callback_data));
- cbdata->task = task;
- cbdata->req = req;
- cbdata->ctx = ctx;
- cbdata->processed = FALSE;
-
- if (process_message (task) == -1) {
- msg_warn ("processing of message failed");
- g_set_error (err, g_quark_from_static_string ("webui"), 500, "message cannot be processed");
- rspamd_task_free_hard (task);
- return NULL;
- }
-
- /* Set up async session */
- task->s = new_async_session (task->task_pool, http_scan_task_fin, http_scan_task_restore, http_scan_task_free, cbdata);
- if (process_filters (task) == -1) {
- msg_warn ("filtering of message failed");
- g_set_error (err, g_quark_from_static_string ("webui"), 500, "message cannot be filtered");
- rspamd_task_free_hard (task);
- return NULL;
- }
-
- cbdata->processed = TRUE;
-
- return cbdata;
-}
-
-struct learn_callback_data {
- struct rspamd_task *task;
- struct evhttp_request *req;
- struct classifier_config *classifier;
- struct rspamd_webui_worker_ctx *ctx;
- gboolean is_spam;
- gboolean processed;
-};
-
-/*
- * Called before destroying of task's session, here we can perform learning
- */
-static void
-rspamd_webui_learn_task_free (gpointer arg)
-{
- struct learn_callback_data *cbdata = arg;
- GError *err = NULL;
- struct evbuffer *evb;
-
- if (cbdata->processed) {
- evb = evbuffer_new ();
- if (!evb) {
- msg_err ("cannot allocate evbuffer for reply");
- evhttp_send_reply (cbdata->req, HTTP_INTERNAL, "500 insufficient memory", NULL);
- rspamd_task_free_hard (cbdata->task);
- return;
- }
-
- if (!learn_task_spam (cbdata->classifier, cbdata->task, cbdata->is_spam, &err)) {
- evbuffer_add_printf (evb, "{\"error\":\"%s\"}" CRLF, err->message);
- evhttp_add_header (cbdata->req->output_headers, "Connection", "close");
- http_calculate_content_length (evb, cbdata->req);
-
- evhttp_send_reply (cbdata->req, HTTP_INTERNAL + err->code, err->message, evb);
- evbuffer_free (evb);
- g_error_free (err);
- rspamd_task_free_hard (cbdata->task);
- return;
- }
- /* Successful learn */
- evbuffer_add_printf (evb, "{\"success\":true}" CRLF);
- evhttp_add_header (cbdata->req->output_headers, "Connection", "close");
- http_calculate_content_length (evb, cbdata->req);
-
- evhttp_send_reply (cbdata->req, HTTP_OK, "OK", evb);
- evbuffer_free (evb);
- rspamd_task_free_hard (cbdata->task);
- }
- /* If task is not processed, just do nothing */
- return;
-}
-
-/*
- * Handler of session destroying
- */
-static void
-rspamd_webui_learn_task_event_helper (int fd, short what, gpointer arg)
-{
- struct learn_callback_data *cbdata = arg;
-
- destroy_session (cbdata->task->s);
-}
-
-/*
- * Called if all filters are processed, non-threaded and simple version
- */
-static gboolean
-rspamd_webui_learn_task_fin (gpointer arg)
-{
- struct learn_callback_data *cbdata = arg;
- static struct timeval tv = {.tv_sec = 0, .tv_usec = 0 };
-#if 0
- if (cbdata->task->state != WRITING_REPLY) {
- cbdata->task->state = WRITE_REPLY;
- }
-
- /* Check if we have all events finished */
- if (cbdata->task->state != WRITING_REPLY) {
- if (cbdata->task->fin_callback) {
- cbdata->task->fin_callback (cbdata->task->fin_arg);
- }
- else {
- /*
- * XXX: we cannot call this one directly as session mutex is locked, so we need to plan some event
- * unfortunately
- * destroy_session (cbdata->task->s);
- */
- event_base_once (cbdata->ctx->ev_base, -1, EV_TIMEOUT, http_learn_task_event_helper, cbdata, &tv);
- }
- }
-#endif
- return TRUE;
-}
-
-/*
- * Called if session was restored inside fin callback
- */
-static void
-rspamd_webui_learn_task_restore (gpointer arg)
-{
- struct learn_callback_data *cbdata = arg;
-#if 0
- /* Special state */
- cbdata->task->state = WRITING_REPLY;
-#endif
-}
-
-/* Prepare callback data for learn */
-static struct learn_callback_data*
-rspamd_webui_prepare_learn (struct evhttp_request *req, struct rspamd_webui_worker_ctx *ctx, struct evbuffer *in, gboolean is_spam, GError **err)
-{
- struct rspamd_task *task;
- struct learn_callback_data *cbdata;
- struct classifier_config *cl;
-
- /* Check for data */
- if (EVBUFFER_LENGTH (in) == 0) {
- g_set_error (err, g_quark_from_static_string ("webui"), 500, "no message for learning");
- return NULL;
- }
- /* Check for classifier */
- cl = find_classifier_conf (ctx->cfg, "bayes");
- if (cl == NULL) {
- g_set_error (err, g_quark_from_static_string ("webui"), 500, "classifier not found");
- return NULL;
- }
- /* Prepare task */
- task = rspamd_task_new (ctx->worker);
- if (task == NULL) {
- g_set_error (err, g_quark_from_static_string ("webui"), 500, "task cannot be created");
- return NULL;
- }
-
- task->msg = g_string_new_len (EVBUFFER_DATA (in), EVBUFFER_LENGTH (in));
-
- task->resolver = ctx->resolver;
- task->ev_base = ctx->ev_base;
-
- cbdata = memory_pool_alloc (task->task_pool, sizeof (struct learn_callback_data));
- cbdata->task = task;
- cbdata->req = req;
- cbdata->classifier = cl;
- cbdata->ctx = ctx;
- cbdata->is_spam = is_spam;
- cbdata->processed = FALSE;
-
- if (process_message (task) == -1) {
- msg_warn ("processing of message failed");
- g_set_error (err, g_quark_from_static_string ("webui"), 500, "message cannot be processed");
- rspamd_task_free_hard (task);
- return NULL;
- }
-
- /* Set up async session */
- task->s = new_async_session (task->task_pool, http_learn_task_fin, http_learn_task_restore, http_learn_task_free, cbdata);
- if (process_filters (task) == -1) {
- msg_warn ("filtering of message failed");
- g_set_error (err, g_quark_from_static_string ("webui"), 500, "message cannot be filtered");
- rspamd_task_free_hard (task);
- return NULL;
- }
-
- cbdata->processed = TRUE;
-
- return cbdata;
-}
-#endif
-
-
/* Command handlers */
/*