]> source.dussan.org Git - rspamd.git/commitdiff
Add hostname attribute to rspamc protocol.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 6 Jan 2014 16:20:16 +0000 (16:20 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 6 Jan 2014 16:20:16 +0000 (16:20 +0000)
src/lua/lua_task.c
src/main.h
src/protocol.c
src/worker.c

index 3980220e2b439a2dc4ae40d721fabd934fdb1352..e653e25d1ce093ba6d4ddd4e0586d1d1f082854d 100644 (file)
@@ -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)
 {
index e3a13ee650d31813b6a049a5cf973601235a11f0..ab8146cc41c20f50fd89b71ae9e491282a5d51b5 100644 (file)
@@ -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                                                       */
index 8b16dca7f5899a28423ff56e66d9e7e1994c7c27..6cb0ce677202dca57823e2688f5e0a2853e6cbfd 100644 (file)
@@ -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;
index 95355bdd3fde572516db207576cb139fd9ae8002..3eb91a289b305605f30bcce945e0ff56f52220b9 100644 (file)
@@ -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 */