From 2cda0d88a6c5832ea06c2ce102c4300938664d5c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 30 Apr 2022 12:24:55 +0100 Subject: [PATCH] [Project] Move some more methods --- src/libserver/symcache/symcache_c.cxx | 59 +++++++++++++++++++++ src/libserver/symcache/symcache_id_list.hxx | 2 +- src/libserver/symcache/symcache_item.cxx | 4 +- src/libutil/cxx/locked_file.cxx | 19 +++++-- 4 files changed, 77 insertions(+), 7 deletions(-) diff --git a/src/libserver/symcache/symcache_c.cxx b/src/libserver/symcache/symcache_c.cxx index 51b390982..14fead7e4 100644 --- a/src/libserver/symcache/symcache_c.cxx +++ b/src/libserver/symcache/symcache_c.cxx @@ -286,6 +286,65 @@ rspamd_symcache_process_settings_elt(struct rspamd_symcache *cache, real_cache->process_settings_elt(elt); } +bool +rspamd_symcache_set_allowed_settings_ids(struct rspamd_symcache *cache, + const gchar *symbol, + const guint32 *ids, + guint nids) +{ + auto *real_cache = C_API_SYMCACHE(cache); + + auto *item = real_cache->get_item_by_name_mut(symbol, false); + + if (item == nullptr) { + return false; + } + + item->allowed_ids.set_ids(ids, nids, real_cache->get_pool()); + return true; +} + +bool +rspamd_symcache_set_forbidden_settings_ids(struct rspamd_symcache *cache, + const gchar *symbol, + const guint32 *ids, + guint nids) +{ + auto *real_cache = C_API_SYMCACHE(cache); + + auto *item = real_cache->get_item_by_name_mut(symbol, false); + + if (item == nullptr) { + return false; + } + + item->forbidden_ids.set_ids(ids, nids, real_cache->get_pool()); + return true; +} + +const guint32 * +rspamd_symcache_get_allowed_settings_ids(struct rspamd_symcache *cache, + const gchar *symbol, + guint *nids) +{ + auto *real_cache = C_API_SYMCACHE(cache); + + const auto *item = real_cache->get_item_by_name(symbol, false); + return item->allowed_ids.get_ids(*nids); + +} + +const guint32 * +rspamd_symcache_get_forbidden_settings_ids (struct rspamd_symcache *cache, + const gchar *symbol, + guint *nids) +{ + auto *real_cache = C_API_SYMCACHE(cache); + + const auto *item = real_cache->get_item_by_name(symbol, false); + return item->forbidden_ids.get_ids(*nids); +} + void rspamd_symcache_disable_all_symbols(struct rspamd_task *task, struct rspamd_symcache *_cache, diff --git a/src/libserver/symcache/symcache_id_list.hxx b/src/libserver/symcache/symcache_id_list.hxx index 444ac2079..10a3ba2b7 100644 --- a/src/libserver/symcache/symcache_id_list.hxx +++ b/src/libserver/symcache/symcache_id_list.hxx @@ -54,7 +54,7 @@ struct id_list { * @param nids output of the number of elements * @return */ - auto get_ids(std::size_t &nids) const -> const std::uint32_t * + auto get_ids(unsigned &nids) const -> const std::uint32_t * { if (data.dyn.e == -1) { /* Dynamic list */ diff --git a/src/libserver/symcache/symcache_item.cxx b/src/libserver/symcache/symcache_item.cxx index 4eb2cc008..635dc6324 100644 --- a/src/libserver/symcache/symcache_item.cxx +++ b/src/libserver/symcache/symcache_item.cxx @@ -14,11 +14,11 @@ * limitations under the License. */ +#include "lua/lua_common.h" #include "symcache_internal.hxx" #include "symcache_item.hxx" #include "fmt/core.h" #include "libserver/task.h" -#include "lua/lua_common.h" namespace rspamd::symcache { @@ -56,7 +56,7 @@ auto cache_item::process_deps(const symcache &cache) -> void msg_debug_cache("process virtual dependency %s(%d) on %s(%d)", symbol.c_str(), dep.vid, vdit->symbol.c_str(), vdit->id); - std::size_t nids = 0; + unsigned nids = 0; /* Propagate ids */ msg_debug_cache("check id propagation for dependency %s from %s", diff --git a/src/libutil/cxx/locked_file.cxx b/src/libutil/cxx/locked_file.cxx index cda05a6c3..69644acbb 100644 --- a/src/libutil/cxx/locked_file.cxx +++ b/src/libutil/cxx/locked_file.cxx @@ -1,7 +1,18 @@ -// -// Created by Vsevolod Stakhov on 02/04/2022. -// - +/*- + * Copyright 2022 Vsevolod Stakhov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include "locked_file.hxx" #include #include "libutil/util.h" -- 2.39.5