From d6d033377bb93925aff848da3a3dfa51e7c20a8a Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 6 Jan 2014 16:20:16 +0000 Subject: [PATCH] Add hostname attribute to rspamc protocol. --- src/lua/lua_task.c | 36 ++++++++++++++++++++++++++++++++++++ src/main.h | 1 + src/protocol.c | 5 +++++ src/worker.c | 3 --- 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 3980220e2..e653e25d1 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -79,6 +79,8 @@ LUA_FUNCTION_DEF (task, get_from_ip_num); LUA_FUNCTION_DEF (task, get_client_ip_num); LUA_FUNCTION_DEF (task, get_helo); LUA_FUNCTION_DEF (task, set_helo); +LUA_FUNCTION_DEF (task, get_hostname); +LUA_FUNCTION_DEF (task, set_hostname); LUA_FUNCTION_DEF (task, get_images); LUA_FUNCTION_DEF (task, get_symbol); LUA_FUNCTION_DEF (task, get_date); @@ -128,6 +130,8 @@ static const struct luaL_reg tasklib_m[] = { LUA_INTERFACE_DEF (task, get_client_ip_num), LUA_INTERFACE_DEF (task, get_helo), LUA_INTERFACE_DEF (task, set_helo), + LUA_INTERFACE_DEF (task, get_hostname), + LUA_INTERFACE_DEF (task, set_hostname), LUA_INTERFACE_DEF (task, get_images), LUA_INTERFACE_DEF (task, get_symbol), LUA_INTERFACE_DEF (task, get_date), @@ -1059,6 +1063,38 @@ lua_task_set_helo (lua_State *L) return 0; } +static gint +lua_task_get_hostname (lua_State *L) +{ + struct worker_task *task = lua_check_task (L); + + if (task) { + if (task->hostname != NULL) { + lua_pushstring (L, (gchar *)task->hostname); + return 1; + } + } + + lua_pushnil (L); + return 1; +} + +static gint +lua_task_set_hostname (lua_State *L) +{ + struct worker_task *task = lua_check_task (L); + const gchar *new_hostname; + + if (task) { + new_hostname = luaL_checkstring (L, 2); + if (new_hostname) { + task->hostname = memory_pool_strdup (task->task_pool, new_hostname); + } + } + + return 0; +} + static gint lua_task_get_images (lua_State *L) { diff --git a/src/main.h b/src/main.h index e3a13ee65..ab8146cc4 100644 --- a/src/main.h +++ b/src/main.h @@ -220,6 +220,7 @@ struct worker_task { gchar *deliver_to; /**< address to deliver */ gchar *user; /**< user to deliver */ gchar *subject; /**< subject (for non-mime) */ + gchar *hostname; /**< hostname reported by MTA */ gchar *statfile; /**< statfile for learning */ f_str_t *msg; /**< message buffer */ rspamd_io_dispatcher_t *dispatcher; /**< IO dispatcher object */ diff --git a/src/protocol.c b/src/protocol.c index 8b16dca7f..6cb0ce677 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -92,6 +92,7 @@ #define USER_HEADER "User" #define PASS_HEADER "Pass" #define JSON_HEADER "Json" +#define HOSTNAME_HEADER "Hostname" #define DELIVER_TO_HEADER "Deliver-To" static GList *custom_commands = NULL; @@ -509,6 +510,10 @@ parse_header (struct worker_task *task, f_str_t * line) task->helo = memory_pool_fstrdup (task->task_pool, line); debug_task ("read helo header, value: %s", task->helo); } + else if (g_ascii_strncasecmp (headern, HOSTNAME_HEADER, sizeof (HOSTNAME_HEADER) - 1) == 0) { + task->hostname = memory_pool_fstrdup (task->task_pool, line); + debug_task ("read hostname header, value: %s", task->hostname); + } else { msg_info ("wrong header: %s", headern); res = FALSE; diff --git a/src/worker.c b/src/worker.c index 95355bdd3..3eb91a289 100644 --- a/src/worker.c +++ b/src/worker.c @@ -383,9 +383,6 @@ static void err_socket (GError * err, void *arg) { struct worker_task *task = (struct worker_task *) arg; - struct rspamd_worker_ctx *ctx; - - ctx = task->worker->ctx; msg_info ("abnormally closing connection from: %s, error: %s", inet_ntoa (task->client_addr), err->message); /* Free buffers */ -- 2.39.5