commit c256285: [Project] Allow to extract augmentation values

Vsevolod Stakhov vsevolod at rspamd.com
Sat Aug 13 22:56:03 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-08-13 20:16:36 +0100
URL: https://github.com/rspamd/rspamd/commit/c256285b71ca1ce9fed556992d301026f8c40a6f (HEAD -> master)

[Project] Allow to extract augmentation values

---
 src/libserver/symcache/symcache_item.cxx | 15 +++++++++++++++
 src/libserver/symcache/symcache_item.hxx | 14 ++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/src/libserver/symcache/symcache_item.cxx b/src/libserver/symcache/symcache_item.cxx
index c41d3d68c..57a0a6695 100644
--- a/src/libserver/symcache/symcache_item.cxx
+++ b/src/libserver/symcache/symcache_item.cxx
@@ -500,6 +500,21 @@ cache_item::get_augmentation_weight() const -> int
 	});
 }
 
+auto cache_item::get_numeric_augmentation(std::string_view name) const -> std::optional<double>
+{
+	const auto augmentation_value_maybe = rspamd::find_map(this->augmentations, name);
+
+	if (augmentation_value_maybe.has_value()) {
+		const auto &augmentation = augmentation_value_maybe.value().get();
+
+		if (std::holds_alternative<double>(augmentation.value)) {
+			return std::get<double>(augmentation.value);
+		}
+	}
+
+	return std::nullopt;
+}
+
 
 auto virtual_item::get_parent(const symcache &cache) const -> const cache_item *
 {
diff --git a/src/libserver/symcache/symcache_item.hxx b/src/libserver/symcache/symcache_item.hxx
index 31706058b..67c0960f3 100644
--- a/src/libserver/symcache/symcache_item.hxx
+++ b/src/libserver/symcache/symcache_item.hxx
@@ -417,6 +417,20 @@ public:
 	 */
 	auto get_augmentation_weight() const -> int;
 
+	/**
+	 * Returns numeric augmentation value
+	 * @param name
+	 * @return
+	 */
+	auto get_numeric_augmentation(std::string_view name) const -> std::optional<double>;
+
+	/**
+	 * Returns string augmentation value
+	 * @param name
+	 * @return
+	 */
+	auto get_string_augmentation(std::string_view name) const -> std::optional<std::string_view>;
+
 	/**
 	 * Add a virtual symbol as a child of some normal symbol
 	 * @param ptr


More information about the Commits mailing list