From 1b4a2e07e8648904c1164642e3de0179c7ab00af Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 18 Oct 2021 15:39:02 +0100 Subject: [PATCH] [Project] Start work on cdb backend --- src/libstat/CMakeLists.txt | 3 +- src/libstat/backends/backends.h | 2 +- src/libstat/backends/cdb_backend.cxx | 118 +++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 src/libstat/backends/cdb_backend.cxx diff --git a/src/libstat/CMakeLists.txt b/src/libstat/CMakeLists.txt index 1019a9925..83020a56d 100644 --- a/src/libstat/CMakeLists.txt +++ b/src/libstat/CMakeLists.txt @@ -9,7 +9,8 @@ SET(CLASSIFIERSSRC ${CMAKE_CURRENT_SOURCE_DIR}/classifiers/bayes.c ${CMAKE_CURRENT_SOURCE_DIR}/classifiers/lua_classifier.c) SET(BACKENDSSRC ${CMAKE_CURRENT_SOURCE_DIR}/backends/mmaped_file.c - ${CMAKE_CURRENT_SOURCE_DIR}/backends/sqlite3_backend.c) + ${CMAKE_CURRENT_SOURCE_DIR}/backends/sqlite3_backend.c + ${CMAKE_CURRENT_SOURCE_DIR}/backends/cdb_backend.cxx) SET(CACHESSRC ${CMAKE_CURRENT_SOURCE_DIR}/learn_cache/sqlite3_cache.c) SET(BACKENDSSRC ${BACKENDSSRC} diff --git a/src/libstat/backends/backends.h b/src/libstat/backends/backends.h index fa3785540..7b61093bb 100644 --- a/src/libstat/backends/backends.h +++ b/src/libstat/backends/backends.h @@ -112,8 +112,8 @@ struct rspamd_stat_backend { void rspamd_##name##_close (gpointer ctx) RSPAMD_STAT_BACKEND_DEF(mmaped_file); - RSPAMD_STAT_BACKEND_DEF(sqlite3); +RSPAMD_STAT_BACKEND_DEF(cdb); #ifdef WITH_HIREDIS diff --git a/src/libstat/backends/cdb_backend.cxx b/src/libstat/backends/cdb_backend.cxx new file mode 100644 index 000000000..a36876a8f --- /dev/null +++ b/src/libstat/backends/cdb_backend.cxx @@ -0,0 +1,118 @@ +/*- + * Copyright 2021 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. + */ + +/* + * CDB read only statistics backend + */ + +#include "config.h" +#include "stat_internal.h" +#include "contrib/cdb/cdb.h" + +namespace rspamd::stat::cdb { + +} + +/* C exports */ +gpointer +rspamd_cdb_init(struct rspamd_stat_ctx* ctx, + struct rspamd_config* cfg, + struct rspamd_statfile* st) +{ + return nullptr; +} +gpointer +rspamd_cdb_runtime(struct rspamd_task* task, + struct rspamd_statfile_config* stcf, + gboolean learn, + gpointer ctx) +{ + return nullptr; +} +gboolean +rspamd_cdb_process_tokens(struct rspamd_task* task, + GPtrArray* tokens, + gint id, + gpointer ctx) +{ + return false; +} +gboolean +rspamd_cdb_finalize_process(struct rspamd_task* task, + gpointer runtime, + gpointer ctx) +{ + return false; +} +gboolean +rspamd_cdb_learn_tokens(struct rspamd_task* task, + GPtrArray* tokens, + gint id, + gpointer ctx) +{ + return false; +} +gboolean +rspamd_cdb_finalize_learn(struct rspamd_task* task, + gpointer runtime, + gpointer ctx, + GError** err) +{ + return false; +} + +gulong rspamd_cdb_total_learns(struct rspamd_task* task, + gpointer runtime, + gpointer ctx) +{ + return 0; +} +gulong +rspamd_cdb_inc_learns(struct rspamd_task* task, + gpointer runtime, + gpointer ctx) +{ + return (gulong)-1; +} +gulong +rspamd_cdb_dec_learns(struct rspamd_task* task, + gpointer runtime, + gpointer ctx) +{ + return (gulong)-1; +} +gulong +rspamd_cdb_learns(struct rspamd_task* task, + gpointer runtime, + gpointer ctx) +{ + return 0; +} +ucl_object_t* +rspamd_cdb_get_stat(gpointer runtime, gpointer ctx) +{ + return nullptr; +} +gpointer +rspamd_cdb_load_tokenizer_config(gpointer runtime, gsize* len) +{ + return nullptr; +} +void +rspamd_cdb_close(gpointer ctx) +{ + +} \ No newline at end of file -- 2.39.5