]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
* Add functions to lua API to detect message and task date (in GMT)
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 22 Apr 2011 14:57:52 +0000 (18:57 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 22 Apr 2011 14:57:52 +0000 (18:57 +0400)
src/lua/lua_common.h
src/lua/lua_message.c
src/lua/lua_task.c

index 47d6956b0630d51d259145eade4a18acc43b1da5..da3cc254e25d5dfd6d1e23d8cee2b04dd4190c29 100644 (file)
@@ -16,7 +16,7 @@
 
 extern const luaL_reg null_reg[];
 
-#define RSPAMD_LUA_API_VERSION 4
+#define RSPAMD_LUA_API_VERSION 5
 
 /* Common utility functions */
 void lua_newclass (lua_State *L, const gchar *classname, const struct luaL_reg *func);
index 2848e082ffa8dba65f0712229a671b2415bb5c14..c1b7a734fa85186542ecbb47617faec0ddb65fed 100644 (file)
@@ -68,6 +68,7 @@ LUA_FUNCTION_DEF (message, set_reply_to);
 LUA_FUNCTION_DEF (message, get_header);
 LUA_FUNCTION_DEF (message, get_header_strong);
 LUA_FUNCTION_DEF (message, set_header);
+LUA_FUNCTION_DEF (message, get_date);
 
 static const struct luaL_reg    msglib_m[] = {
        LUA_INTERFACE_DEF (message, get_subject),
@@ -81,6 +82,7 @@ static const struct luaL_reg    msglib_m[] = {
        LUA_INTERFACE_DEF (message, get_header),
        LUA_INTERFACE_DEF (message, get_header_strong),
        LUA_INTERFACE_DEF (message, set_header),
+       LUA_INTERFACE_DEF (message, get_date),
        {"__tostring", lua_class_tostring},
        {NULL, NULL}
 };
@@ -180,6 +182,25 @@ lua_message_set_header (lua_State * L)
        return 1;
 }
 
+static gint
+lua_message_get_date (lua_State * L)
+{
+       GMimeMessage                   *obj = lua_check_message (L);
+       time_t                          msg_time;
+       int                             offset;
+
+       if (obj != NULL) {
+               g_mime_message_get_date (obj, &msg_time, &offset);
+               /* Convert result to GMT */
+               msg_time -= (offset / 100) * 3600;
+               lua_pushnumber (L, msg_time);
+       }
+       else {
+               lua_pushnil (L);
+       }
+
+       return 1;
+}
 
 gint
 luaopen_message (lua_State * L)
index a0e6a3992ffd9f352f72a0e40a102edd0da8b903..1011612aadf754f8500e85d68d7c2c907e291772 100644 (file)
@@ -65,6 +65,7 @@ LUA_FUNCTION_DEF (task, get_client_ip_num);
 LUA_FUNCTION_DEF (task, get_helo);
 LUA_FUNCTION_DEF (task, get_images);
 LUA_FUNCTION_DEF (task, get_symbol);
+LUA_FUNCTION_DEF (task, get_date);
 LUA_FUNCTION_DEF (task, get_metric_score);
 LUA_FUNCTION_DEF (task, get_metric_action);
 LUA_FUNCTION_DEF (task, learn_statfile);
@@ -93,6 +94,7 @@ static const struct luaL_reg    tasklib_m[] = {
        LUA_INTERFACE_DEF (task, get_helo),
        LUA_INTERFACE_DEF (task, get_images),
        LUA_INTERFACE_DEF (task, get_symbol),
+       LUA_INTERFACE_DEF (task, get_date),
        LUA_INTERFACE_DEF (task, get_metric_score),
        LUA_INTERFACE_DEF (task, get_metric_action),
        LUA_INTERFACE_DEF (task, learn_statfile),
@@ -1045,6 +1047,24 @@ lua_task_get_symbol (lua_State *L)
        return 1;
 }
 
+static gint
+lua_task_get_date (lua_State *L)
+{
+       struct worker_task             *task = lua_check_task (L);
+       time_t                          task_time;
+
+       if (task != NULL) {
+               /* Get GMT date and store it to time_t */
+               task_time = mktime (gmtime (&task->tv.tv_sec));
+               lua_pushnumber (L, task_time);
+       }
+       else {
+               lua_pushnil (L);
+       }
+
+       return 1;
+}
+
 static gint
 lua_task_learn_statfile (lua_State *L)
 {