]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add some more helpers
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 13 Apr 2022 21:16:01 +0000 (22:16 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 13 Apr 2022 21:16:01 +0000 (22:16 +0100)
src/libserver/symcache/symcache_c.cxx
src/libserver/symcache/symcache_internal.hxx

index c61b17340a84fbf99f68eb0b91f93079a7f77067..88a0d5605bb06410dee4bff4e6dfca3c94c6284c 100644 (file)
@@ -93,4 +93,53 @@ rspamd_symcache_add_condition_delayed (struct rspamd_symcache *cache,
        real_cache->add_delayed_condition(sym, cbref);
 
        return TRUE;
-}
\ No newline at end of file
+}
+
+gint rspamd_symcache_find_symbol (struct rspamd_symcache *cache,
+                                                                 const gchar *name)
+{
+       auto *real_cache = C_API_SYMCACHE(cache);
+
+       auto sym_maybe = real_cache->get_item_by_name(name, false);
+
+       if (sym_maybe != nullptr) {
+               return sym_maybe->id;
+       }
+
+       return -1;
+}
+
+gboolean rspamd_symcache_stat_symbol (struct rspamd_symcache *cache,
+                                                                         const gchar *name,
+                                                                         gdouble *frequency,
+                                                                         gdouble *freq_stddev,
+                                                                         gdouble *tm,
+                                                                         guint *nhits)
+{
+       auto *real_cache = C_API_SYMCACHE(cache);
+
+       auto sym_maybe = real_cache->get_item_by_name(name, false);
+
+       if (sym_maybe != nullptr) {
+               *frequency = sym_maybe->st->avg_frequency;
+               *freq_stddev = sqrt(sym_maybe->st->stddev_frequency);
+               *tm = sym_maybe->st->time_counter.mean;
+
+               if (nhits) {
+                       *nhits = sym_maybe->st->hits;
+               }
+
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+
+guint
+rspamd_symcache_stats_symbols_count (struct rspamd_symcache *cache)
+{
+       auto *real_cache = C_API_SYMCACHE(cache);
+       return real_cache->get_stats_symbols_count();
+}
+
index e967bbe83f3337ad735537e9082bb67cae653544..155efa1ae927458cbd3ff4b657ef18336fa135f7 100644 (file)
@@ -377,6 +377,8 @@ private:
        double total_weight;
        std::size_t used_items;
        std::size_t stats_symbols_count;
+
+private:
        std::uint64_t total_hits;
 
        struct rspamd_config *cfg;
@@ -509,6 +511,14 @@ public:
         * @param cbref
         */
        auto add_delayed_condition(std::string_view sym, int cbref) -> void;
+
+       /**
+        * Returns number of symbols that needs to be checked in statistical algorithm
+        * @return
+        */
+       auto get_stats_symbols_count() const {
+               return stats_symbols_count;
+       }
 };
 
 /*