diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-11-30 09:56:39 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-11-30 09:56:39 +0000 |
commit | a862a1fb19b0926fea1d1f43d764e4cd2f696fb6 (patch) | |
tree | c9e2f53cf4d66e66808da9f7fef081cc8ae9f274 /src | |
parent | af97b2e09bcf6ee2e7db850b66fe6a28bde9b17d (diff) | |
download | rspamd-a862a1fb19b0926fea1d1f43d764e4cd2f696fb6.tar.gz rspamd-a862a1fb19b0926fea1d1f43d764e4cd2f696fb6.zip |
[Project] Add some missing methods for spf record
Diffstat (limited to 'src')
-rw-r--r-- | src/lua/lua_spf.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/lua/lua_spf.c b/src/lua/lua_spf.c index a6daa26c6..8a01b0ef7 100644 --- a/src/lua/lua_spf.c +++ b/src/lua/lua_spf.c @@ -26,8 +26,14 @@ LUA_FUNCTION_DEF (spf, resolve); LUA_FUNCTION_DEF (spf, config); + LUA_FUNCTION_DEF (spf_record, check_ip); LUA_FUNCTION_DEF (spf_record, dtor); +LUA_FUNCTION_DEF (spf_record, get_domain); +LUA_FUNCTION_DEF (spf_record, get_elts); +LUA_FUNCTION_DEF (spf_record, get_ttl); +LUA_FUNCTION_DEF (spf_record, get_timestamp); +LUA_FUNCTION_DEF (spf_record, get_digest); static luaL_reg rspamd_spf_f[] = { LUA_INTERFACE_DEF (spf, resolve), @@ -37,6 +43,10 @@ static luaL_reg rspamd_spf_f[] = { static luaL_reg rspamd_spf_record_m[] = { LUA_INTERFACE_DEF (spf_record, check_ip), + LUA_INTERFACE_DEF (spf_record, get_domain), + LUA_INTERFACE_DEF (spf_record, get_ttl), + LUA_INTERFACE_DEF (spf_record, get_digest), + LUA_INTERFACE_DEF (spf_record, get_elts), {"__gc", lua_spf_record_dtor}, {NULL, NULL}, }; @@ -356,6 +366,93 @@ lua_spf_record_check_ip (lua_State *L) } /*** + * @method rspamd_spf_record:get_domain() + * Returns domain for the specific spf record +*/ +static gint +lua_spf_record_get_domain (lua_State *L) +{ + struct spf_resolved *record = + *(struct spf_resolved **) rspamd_lua_check_udata (L, 1, + SPF_RECORD_CLASS); + + if (record) { + lua_pushstring (L, record->domain); + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + +/*** + * @method rspamd_spf_record:get_ttl() + * Returns ttl for the specific spf record +*/ +static gint +lua_spf_record_get_ttl (lua_State *L) +{ + struct spf_resolved *record = + *(struct spf_resolved **) rspamd_lua_check_udata (L, 1, + SPF_RECORD_CLASS); + + if (record) { + lua_pushinteger (L, record->ttl); + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + +/*** + * @method rspamd_spf_record:get_timestamp() + * Returns ttl for the specific spf record +*/ +static gint +lua_spf_record_get_timestamp (lua_State *L) +{ + struct spf_resolved *record = + *(struct spf_resolved **) rspamd_lua_check_udata (L, 1, + SPF_RECORD_CLASS); + + if (record) { + lua_pushnumber (L, record->timestamp); + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + +/*** + * @method rspamd_spf_record:get_digest() + * Returns string hex representation of the record digest (fast hash function) +*/ +static gint +lua_spf_record_get_digest (lua_State *L) +{ + struct spf_resolved *record = + *(struct spf_resolved **) rspamd_lua_check_udata (L, 1, + SPF_RECORD_CLASS); + + if (record) { + gchar hexbuf[64]; + + rspamd_snprintf (hexbuf, sizeof (hexbuf), "%xuL", record->digest); + lua_pushstring (L, hexbuf); + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + +/*** * @function rspamd_spf.config(object) * Configures SPF library according to the UCL config * @param {table} object configuration object |