commit a862a1f: [Project] Add some missing methods for spf record

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Nov 30 10:21:05 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-11-30 09:56:39 +0000
URL: https://github.com/rspamd/rspamd/commit/a862a1fb19b0926fea1d1f43d764e4cd2f696fb6

[Project] Add some missing methods for spf record

---
 src/lua/lua_spf.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)

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},
 };
@@ -355,6 +365,93 @@ lua_spf_record_check_ip (lua_State *L)
 	return 3;
 }
 
+/***
+ * @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


More information about the Commits mailing list