aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/fuzzy_backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/libserver/fuzzy_backend')
-rw-r--r--src/libserver/fuzzy_backend/fuzzy_backend.c26
-rw-r--r--src/libserver/fuzzy_backend/fuzzy_backend.h8
-rw-r--r--src/libserver/fuzzy_backend/fuzzy_backend_noop.c97
-rw-r--r--src/libserver/fuzzy_backend/fuzzy_backend_noop.h66
-rw-r--r--src/libserver/fuzzy_backend/fuzzy_backend_redis.c4
-rw-r--r--src/libserver/fuzzy_backend/fuzzy_backend_redis.h7
6 files changed, 195 insertions, 13 deletions
diff --git a/src/libserver/fuzzy_backend/fuzzy_backend.c b/src/libserver/fuzzy_backend/fuzzy_backend.c
index c18463618..3d5cbb863 100644
--- a/src/libserver/fuzzy_backend/fuzzy_backend.c
+++ b/src/libserver/fuzzy_backend/fuzzy_backend.c
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2025 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
+ * 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,
@@ -18,6 +18,7 @@
#include "fuzzy_backend.h"
#include "fuzzy_backend_sqlite.h"
#include "fuzzy_backend_redis.h"
+#include "fuzzy_backend_noop.h"
#include "cfg_file.h"
#include "fuzzy_wire.h"
@@ -26,6 +27,7 @@
enum rspamd_fuzzy_backend_type {
RSPAMD_FUZZY_BACKEND_SQLITE = 0,
RSPAMD_FUZZY_BACKEND_REDIS = 1,
+ RSPAMD_FUZZY_BACKEND_NOOP = 2,
};
static void *rspamd_fuzzy_backend_init_sqlite(struct rspamd_fuzzy_backend *bk,
@@ -96,6 +98,16 @@ static const struct rspamd_fuzzy_backend_subr fuzzy_subrs[] = {
.id = rspamd_fuzzy_backend_id_redis,
.periodic = rspamd_fuzzy_backend_expire_redis,
.close = rspamd_fuzzy_backend_close_redis,
+ },
+ [RSPAMD_FUZZY_BACKEND_NOOP] = {
+ .init = rspamd_fuzzy_backend_init_noop,
+ .check = rspamd_fuzzy_backend_check_noop,
+ .update = rspamd_fuzzy_backend_update_noop,
+ .count = rspamd_fuzzy_backend_count_noop,
+ .version = rspamd_fuzzy_backend_version_noop,
+ .id = rspamd_fuzzy_backend_id_noop,
+ .periodic = rspamd_fuzzy_backend_expire_noop,
+ .close = rspamd_fuzzy_backend_close_noop,
}};
struct rspamd_fuzzy_backend {
@@ -288,6 +300,9 @@ rspamd_fuzzy_backend_create(struct ev_loop *ev_base,
else if (strcmp(ucl_object_tostring(elt), "redis") == 0) {
type = RSPAMD_FUZZY_BACKEND_REDIS;
}
+ else if (strcmp(ucl_object_tostring(elt), "noop") == 0) {
+ type = RSPAMD_FUZZY_BACKEND_NOOP;
+ }
else {
g_set_error(err, rspamd_fuzzy_backend_quark(),
EINVAL, "invalid backend type: %s",
@@ -547,6 +562,11 @@ void rspamd_fuzzy_backend_close(struct rspamd_fuzzy_backend *bk)
g_free(bk);
}
+bool rspamd_fuzzy_backend_is_noop(struct rspamd_fuzzy_backend *bk)
+{
+ return bk->type == RSPAMD_FUZZY_BACKEND_NOOP;
+}
+
struct ev_loop *
rspamd_fuzzy_backend_event_base(struct rspamd_fuzzy_backend *backend)
{
diff --git a/src/libserver/fuzzy_backend/fuzzy_backend.h b/src/libserver/fuzzy_backend/fuzzy_backend.h
index fe22d473e..249c4d1c3 100644
--- a/src/libserver/fuzzy_backend/fuzzy_backend.h
+++ b/src/libserver/fuzzy_backend/fuzzy_backend.h
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2025 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
+ * 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,
@@ -124,6 +124,8 @@ double rspamd_fuzzy_backend_get_expire(struct rspamd_fuzzy_backend *backend);
*/
void rspamd_fuzzy_backend_close(struct rspamd_fuzzy_backend *backend);
+bool rspamd_fuzzy_backend_is_noop(struct rspamd_fuzzy_backend *bk);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/libserver/fuzzy_backend/fuzzy_backend_noop.c b/src/libserver/fuzzy_backend/fuzzy_backend_noop.c
new file mode 100644
index 000000000..024d19882
--- /dev/null
+++ b/src/libserver/fuzzy_backend/fuzzy_backend_noop.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2025 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 "fuzzy_backend_noop.h"
+
+/*
+ * No operations backend (useful for scripts only stuff)
+ */
+
+void *rspamd_fuzzy_backend_init_noop(struct rspamd_fuzzy_backend *bk,
+ const ucl_object_t *obj,
+ struct rspamd_config *cfg,
+ GError **err)
+{
+ /* Return non-NULL to distinguish from error */
+ return (void *) (uintptr_t) (-1);
+}
+
+void rspamd_fuzzy_backend_check_noop(struct rspamd_fuzzy_backend *bk,
+ const struct rspamd_fuzzy_cmd *cmd,
+ rspamd_fuzzy_check_cb cb, void *ud,
+ void *subr_ud)
+{
+ struct rspamd_fuzzy_reply rep;
+
+ if (cb) {
+ memset(&rep, 0, sizeof(rep));
+ cb(&rep, ud);
+ }
+
+ return;
+}
+
+void rspamd_fuzzy_backend_update_noop(struct rspamd_fuzzy_backend *bk,
+ GArray *updates, const char *src,
+ rspamd_fuzzy_update_cb cb, void *ud,
+ void *subr_ud)
+{
+ if (cb) {
+ cb(TRUE, 0, 0, 0, 0, ud);
+ }
+
+ return;
+}
+
+void rspamd_fuzzy_backend_count_noop(struct rspamd_fuzzy_backend *bk,
+ rspamd_fuzzy_count_cb cb, void *ud,
+ void *subr_ud)
+{
+ if (cb) {
+ cb(0, ud);
+ }
+
+ return;
+}
+
+void rspamd_fuzzy_backend_version_noop(struct rspamd_fuzzy_backend *bk,
+ const char *src,
+ rspamd_fuzzy_version_cb cb, void *ud,
+ void *subr_ud)
+{
+ if (cb) {
+ cb(0, ud);
+ }
+
+ return;
+}
+
+const char *rspamd_fuzzy_backend_id_noop(struct rspamd_fuzzy_backend *bk,
+ void *subr_ud)
+{
+ return NULL;
+}
+
+void rspamd_fuzzy_backend_expire_noop(struct rspamd_fuzzy_backend *bk,
+ void *subr_ud)
+{
+}
+
+void rspamd_fuzzy_backend_close_noop(struct rspamd_fuzzy_backend *bk,
+ void *subr_ud)
+{
+}
diff --git a/src/libserver/fuzzy_backend/fuzzy_backend_noop.h b/src/libserver/fuzzy_backend/fuzzy_backend_noop.h
new file mode 100644
index 000000000..ac063dc39
--- /dev/null
+++ b/src/libserver/fuzzy_backend/fuzzy_backend_noop.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2025 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.
+ */
+#ifndef FUZZY_BACKEND_NOOP_H
+#define FUZZY_BACKEND_NOOP_H
+
+#include "config.h"
+#include "fuzzy_backend.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Subroutines for fuzzy_backend
+ */
+void *rspamd_fuzzy_backend_init_noop(struct rspamd_fuzzy_backend *bk,
+ const ucl_object_t *obj,
+ struct rspamd_config *cfg,
+ GError **err);
+
+void rspamd_fuzzy_backend_check_noop(struct rspamd_fuzzy_backend *bk,
+ const struct rspamd_fuzzy_cmd *cmd,
+ rspamd_fuzzy_check_cb cb, void *ud,
+ void *subr_ud);
+
+void rspamd_fuzzy_backend_update_noop(struct rspamd_fuzzy_backend *bk,
+ GArray *updates, const char *src,
+ rspamd_fuzzy_update_cb cb, void *ud,
+ void *subr_ud);
+
+void rspamd_fuzzy_backend_count_noop(struct rspamd_fuzzy_backend *bk,
+ rspamd_fuzzy_count_cb cb, void *ud,
+ void *subr_ud);
+
+void rspamd_fuzzy_backend_version_noop(struct rspamd_fuzzy_backend *bk,
+ const char *src,
+ rspamd_fuzzy_version_cb cb, void *ud,
+ void *subr_ud);
+
+const char *rspamd_fuzzy_backend_id_noop(struct rspamd_fuzzy_backend *bk,
+ void *subr_ud);
+
+void rspamd_fuzzy_backend_expire_noop(struct rspamd_fuzzy_backend *bk,
+ void *subr_ud);
+
+void rspamd_fuzzy_backend_close_noop(struct rspamd_fuzzy_backend *bk,
+ void *subr_ud);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif//FUZZY_BACKEND_NOOP_H
diff --git a/src/libserver/fuzzy_backend/fuzzy_backend_redis.c b/src/libserver/fuzzy_backend/fuzzy_backend_redis.c
index 27c663070..f150d48be 100644
--- a/src/libserver/fuzzy_backend/fuzzy_backend_redis.c
+++ b/src/libserver/fuzzy_backend/fuzzy_backend_redis.c
@@ -116,11 +116,9 @@ rspamd_redis_get_servers(struct rspamd_fuzzy_backend_redis *ctx,
res = *((struct upstream_list **) lua_touserdata(L, -1));
}
else {
- struct lua_logger_trace tr;
char outbuf[8192];
- memset(&tr, 0, sizeof(tr));
- lua_logger_out_type(L, -2, outbuf, sizeof(outbuf) - 1, &tr,
+ lua_logger_out(L, -2, outbuf, sizeof(outbuf),
LUA_ESCAPE_UNPRINTABLE);
msg_err("cannot get %s upstreams for Redis fuzzy storage %s; table content: %s",
diff --git a/src/libserver/fuzzy_backend/fuzzy_backend_redis.h b/src/libserver/fuzzy_backend/fuzzy_backend_redis.h
index afeb1c573..0a536c2fa 100644
--- a/src/libserver/fuzzy_backend/fuzzy_backend_redis.h
+++ b/src/libserver/fuzzy_backend/fuzzy_backend_redis.h
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2025 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
+ * 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,
@@ -15,7 +15,6 @@
*/
#ifndef SRC_LIBSERVER_FUZZY_BACKEND_REDIS_H_
#define SRC_LIBSERVER_FUZZY_BACKEND_REDIS_H_
-
#include "config.h"
#include "fuzzy_backend.h"