aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2022-08-19 17:47:07 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2022-08-19 17:47:07 +0100
commit256a3e0a2967893ba3106fd99f64d16e5b7d21e9 (patch)
tree10ccd5c0b70f17018d23ceda1392c6ebbdc3b0cb /src
parentf8c8e994b960e6ccd910481c19f56d4ee887a049 (diff)
downloadrspamd-256a3e0a2967893ba3106fd99f64d16e5b7d21e9.tar.gz
rspamd-256a3e0a2967893ba3106fd99f64d16e5b7d21e9.zip
[Minor] Implement C API to obtain timeouts information
Diffstat (limited to 'src')
-rw-r--r--src/libserver/rspamd_symcache.h24
-rw-r--r--src/libserver/symcache/symcache_c.cxx26
2 files changed, 50 insertions, 0 deletions
diff --git a/src/libserver/rspamd_symcache.h b/src/libserver/rspamd_symcache.h
index ee3f4862a..597245ca7 100644
--- a/src/libserver/rspamd_symcache.h
+++ b/src/libserver/rspamd_symcache.h
@@ -542,6 +542,30 @@ const struct rspamd_symcache_item_stat *
*/
void rspamd_symcache_enable_profile (struct rspamd_task *task);
+struct rspamd_symcache_timeout_item {
+ double timeout;
+ const struct rspamd_symcache_item *item;
+};
+
+struct rspamd_symcache_timeout_result {
+ double max_timeout;
+ struct rspamd_symcache_timeout_item *items;
+ size_t nitems;
+};
+/**
+ * Gets maximum timeout announced by symbols cache
+ * @param cache
+ * @return new symcache timeout_result structure, that should be freed by call
+ * `rspamd_symcache_timeout_result_free`
+ */
+struct rspamd_symcache_timeout_result* rspamd_symcache_get_max_timeout(struct rspamd_symcache *cache);
+
+/**
+ * Frees results obtained from the previous function
+ * @param res
+ */
+void rspamd_symcache_timeout_result_free(struct rspamd_symcache_timeout_result *res);
+
/**
* Destroy internal state of the symcache runtime
* @param task
diff --git a/src/libserver/symcache/symcache_c.cxx b/src/libserver/symcache/symcache_c.cxx
index bd1c1abc4..f957aa9b6 100644
--- a/src/libserver/symcache/symcache_c.cxx
+++ b/src/libserver/symcache/symcache_c.cxx
@@ -491,6 +491,32 @@ void rspamd_symcache_enable_symbol_static (struct rspamd_symcache *cache,
real_cache->enable_symbol_delayed(symbol);
}
+/* A real structure to match C results without extra copying */
+struct rspamd_symcache_real_timeout_result {
+ struct rspamd_symcache_timeout_result c_api_result;
+ std::vector<std::pair<double, const rspamd::symcache::cache_item *>> elts;
+};
+
+struct rspamd_symcache_timeout_result*
+rspamd_symcache_get_max_timeout(struct rspamd_symcache *cache)
+{
+ auto *real_cache = C_API_SYMCACHE(cache);
+ auto *res = new rspamd_symcache_real_timeout_result;
+
+ res->c_api_result.max_timeout = real_cache->get_max_timeout(res->elts);
+ res->c_api_result.items = reinterpret_cast<struct rspamd_symcache_timeout_item *>(res->elts.data());
+ res->c_api_result.nitems = res->elts.size();
+
+ return &res->c_api_result;
+}
+
+void
+rspamd_symcache_timeout_result_free(struct rspamd_symcache_timeout_result *res)
+{
+ auto *real_result = reinterpret_cast<rspamd_symcache_real_timeout_result *>(res);
+ delete real_result;
+}
+
gboolean
rspamd_symcache_is_checked(struct rspamd_task *task,
struct rspamd_symcache *cache,