]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Add some more methods
authorVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 21 Apr 2022 20:49:35 +0000 (21:49 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 21 Apr 2022 20:49:35 +0000 (21:49 +0100)
src/libserver/symcache/symcache_c.cxx
src/libserver/symcache/symcache_internal.hxx
src/libserver/symcache/symcache_item.hxx

index 7e552e83a8da7e5765d1f767f844be1465ded6ce..bdef8b16209e4b13a9b4bf923b8cd6caccb3597e 100644 (file)
@@ -218,9 +218,28 @@ rspamd_symcache_item_name (struct rspamd_symcache_item *item)
        return real_item->get_name().c_str();
 }
 
+gint
+rspamd_symcache_item_flags (struct rspamd_symcache_item *item)
+{
+       auto *real_item = C_API_SYMCACHE_ITEM(item);
+       return real_item->get_flags();
+}
+
 const struct rspamd_symcache_item_stat *
 rspamd_symcache_item_stat (struct rspamd_symcache_item *item)
 {
        auto *real_item = C_API_SYMCACHE_ITEM(item);
        return real_item->st;
+}
+
+void
+rspamd_symcache_foreach(struct rspamd_symcache *cache,
+                                                         void (*func) (struct rspamd_symcache_item *item, gpointer /* userdata */),
+                                                         gpointer ud)
+{
+       auto *real_cache = C_API_SYMCACHE(cache);
+
+       real_cache->symbols_foreach([&](const rspamd::symcache::cache_item* item) {
+               func((struct rspamd_symcache_item *)item, ud);
+       });
 }
\ No newline at end of file
index 1bfd2f881b5037bd63574a42bc5649b230a7ad56..974c34e756af429ca92dc787f8c0760c5db82927 100644 (file)
@@ -317,7 +317,23 @@ public:
         */
        auto periodic_resort(struct ev_loop *ev_loop, double cur_time, double last_resort) -> void;
 
+       /**
+        * A simple helper to get the reload time
+        * @return
+        */
        auto get_reload_time() const { return reload_time; };
+
+       /**
+        * Iterate over all symbols using a specific functor
+        * @tparam Functor
+        * @param f
+        */
+       template<typename Functor>
+       auto symbols_foreach(Functor f) -> void {
+               for (const auto &sym_it : items_by_symbol) {
+                       f(sym_it.second.get());
+               }
+       }
 };
 
 /*
index c5b6c8ff70d03f5bb31643dade4437b811a508cd..23347a8ecfceb4516b377a20ceebd1406a910ee0 100644 (file)
@@ -265,6 +265,10 @@ public:
                return symbol;
        }
 
+       auto get_flags() const -> auto {
+               return flags;
+       };
+
        auto add_condition(lua_State *L, int cbref) -> bool
        {
                if (!is_virtual()) {