commit 09704cf: [Minor] Add method to print resolved spf element

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Apr 11 17:21:12 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-04-11 16:15:25 +0100
URL: https://github.com/rspamd/rspamd/commit/09704cf02c243c4a2b90899222f033d91d4df88f

[Minor] Add method to print resolved spf element

---
 src/libserver/spf.c | 30 ++++++++++++++++++++++++++++++
 src/libserver/spf.h | 30 ++++++++++++++++++------------
 2 files changed, 48 insertions(+), 12 deletions(-)

diff --git a/src/libserver/spf.c b/src/libserver/spf.c
index f7078f3e9..ee2c06923 100644
--- a/src/libserver/spf.c
+++ b/src/libserver/spf.c
@@ -2279,3 +2279,33 @@ spf_record_unref (struct spf_resolved *rec)
 {
 	REF_RELEASE (rec);
 }
+
+gchar *
+spf_addr_mask_to_string (struct spf_addr *addr)
+{
+	GString *res;
+	gchar *s, ipstr[INET6_ADDRSTRLEN + 1];
+
+	if (addr->flags & RSPAMD_SPF_FLAG_ANY) {
+		res = g_string_new ("any");
+	}
+	else if (addr->flags & RSPAMD_SPF_FLAG_IPV4) {
+		(void)inet_ntop (AF_INET, addr->addr4, ipstr, sizeof (ipstr));
+		res = g_string_sized_new (sizeof (ipstr));
+		rspamd_printf_gstring (res, "%s/%d", ipstr, addr->m.dual.mask_v4);
+	}
+	else if (addr->flags & RSPAMD_SPF_FLAG_IPV6) {
+		(void)inet_ntop (AF_INET6, addr->addr6, ipstr, sizeof (ipstr));
+		res = g_string_sized_new (sizeof (ipstr));
+		rspamd_printf_gstring (res, "%s/%d", ipstr, addr->m.dual.mask_v6);
+	}
+	else {
+		res = g_string_new ("unknown");
+	}
+
+	s = res->str;
+	g_string_free (res, FALSE);
+
+
+	return s;
+}
\ No newline at end of file
diff --git a/src/libserver/spf.h b/src/libserver/spf.h
index 83716297f..5df52d0e0 100644
--- a/src/libserver/spf.h
+++ b/src/libserver/spf.h
@@ -29,18 +29,18 @@ typedef enum spf_action_e {
 	SPF_RESOLVE_EXP
 } spf_action_t;
 
-#define RSPAMD_SPF_FLAG_IPV6 (1 << 0)
-#define RSPAMD_SPF_FLAG_IPV4 (1 << 1)
-#define RSPAMD_SPF_FLAG_PROCESSED (1 << 2)
-#define RSPAMD_SPF_FLAG_ANY (1 << 3)
-#define RSPAMD_SPF_FLAG_PARSED (1 << 4)
-#define RSPAMD_SPF_FLAG_INVALID (1 << 5)
-#define RSPAMD_SPF_FLAG_REFERENCE (1 << 6)
-#define RSPAMD_SPF_FLAG_REDIRECT (1 << 7)
-#define RSPAMD_SPF_FLAG_TEMPFAIL (1 << 8)
-#define RSPAMD_SPF_FLAG_NA (1 << 9)
-#define RSPAMD_SPF_FLAG_PERMFAIL (1 << 10)
-#define RSPAMD_SPF_FLAG_RESOLVED (1 << 11)
+#define RSPAMD_SPF_FLAG_IPV6 (1u << 0u)
+#define RSPAMD_SPF_FLAG_IPV4 (1u << 1u)
+#define RSPAMD_SPF_FLAG_PROCESSED (1u << 2u)
+#define RSPAMD_SPF_FLAG_ANY (1u << 3u)
+#define RSPAMD_SPF_FLAG_PARSED (1u << 4u)
+#define RSPAMD_SPF_FLAG_INVALID (1u << 5u)
+#define RSPAMD_SPF_FLAG_REFERENCE (1u << 6u)
+#define RSPAMD_SPF_FLAG_REDIRECT (1u << 7u)
+#define RSPAMD_SPF_FLAG_TEMPFAIL (1u << 8u)
+#define RSPAMD_SPF_FLAG_NA (1u << 9u)
+#define RSPAMD_SPF_FLAG_PERMFAIL (1u << 10u)
+#define RSPAMD_SPF_FLAG_RESOLVED (1u << 11u)
 
 struct spf_addr {
 	guchar addr6[sizeof (struct in6_addr)];
@@ -92,4 +92,10 @@ struct spf_resolved * spf_record_ref (struct spf_resolved *rec);
  */
 void spf_record_unref (struct spf_resolved *rec);
 
+/**
+ * Prints address + mask in a freshly allocated string (must be freed)
+ * @param addr
+ * @return
+ */
+gchar *spf_addr_mask_to_string (struct spf_addr *addr);
 #endif


More information about the Commits mailing list