]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Project] Allow to extract augmentation values
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 13 Aug 2022 19:16:36 +0000 (20:16 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 13 Aug 2022 19:16:36 +0000 (20:16 +0100)
src/libserver/symcache/symcache_item.cxx
src/libserver/symcache/symcache_item.hxx

index c41d3d68c7156d6da2ca6f5f77daa7b629722ef5..57a0a66951a5eb906bf1c8dc21f1679f9522df42 100644 (file)
@@ -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 *
 {
index 31706058b50f4a208a95eb5870830173eacdd266..67c0960f3544589ec48b7c89623949012312c6da 100644 (file)
@@ -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