]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Several fixes for fuzzy scripts
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 25 Jan 2025 13:29:07 +0000 (13:29 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 25 Jan 2025 13:29:07 +0000 (13:29 +0000)
src/fuzzy_storage.c
src/libserver/fuzzy_backend/fuzzy_backend.c
src/libserver/fuzzy_backend/fuzzy_backend.h

index ca7f195b6477e65d0bfec18bee925ca957dba2e6..1b20a208dfbd87eadf265c1706ff9aecb0643209 100644 (file)
@@ -1743,28 +1743,31 @@ rspamd_fuzzy_process_command(struct fuzzy_session *session)
                                cmd->version |= RSPAMD_FUZZY_FLAG_WEAK;
                        }
 
-                       if (session->worker->index == 0 || session->ctx->peer_fd == -1) {
-                               /* Just add to the queue */
-                               up_cmd.is_shingle = is_shingle;
-                               ptr = is_shingle ? (gpointer) &up_cmd.cmd.shingle : (gpointer) &up_cmd.cmd.normal;
-                               memcpy(ptr, cmd, up_len);
-                               g_array_append_val(session->ctx->updates_pending, up_cmd);
-                       }
-                       else {
-                               /* We need to send request to the peer */
-                               up_req = g_malloc0(sizeof(*up_req));
-                               up_req->cmd.is_shingle = is_shingle;
-                               ptr = is_shingle ? (gpointer) &up_req->cmd.cmd.shingle : (gpointer) &up_req->cmd.cmd.normal;
-                               memcpy(ptr, cmd, up_len);
-
-                               if (!fuzzy_peer_try_send(session->ctx->peer_fd, up_req)) {
-                                       up_req->io_ev.data = up_req;
-                                       ev_io_init(&up_req->io_ev, fuzzy_peer_send_io,
-                                                          session->ctx->peer_fd, EV_WRITE);
-                                       ev_io_start(session->ctx->event_loop, &up_req->io_ev);
+                       /* Noop backends must skip all updates logic as irrelevant */
+                       if (!rspamd_fuzzy_backend_is_noop(session->ctx->backend)) {
+                               if (session->worker->index == 0 || session->ctx->peer_fd == -1) {
+                                       /* Just add to the queue */
+                                       up_cmd.is_shingle = is_shingle;
+                                       ptr = is_shingle ? (gpointer) &up_cmd.cmd.shingle : (gpointer) &up_cmd.cmd.normal;
+                                       memcpy(ptr, cmd, up_len);
+                                       g_array_append_val(session->ctx->updates_pending, up_cmd);
                                }
                                else {
-                                       g_free(up_req);
+                                       /* We need to send request to the peer */
+                                       up_req = g_malloc0(sizeof(*up_req));
+                                       up_req->cmd.is_shingle = is_shingle;
+                                       ptr = is_shingle ? (gpointer) &up_req->cmd.cmd.shingle : (gpointer) &up_req->cmd.cmd.normal;
+                                       memcpy(ptr, cmd, up_len);
+
+                                       if (!fuzzy_peer_try_send(session->ctx->peer_fd, up_req)) {
+                                               up_req->io_ev.data = up_req;
+                                               ev_io_init(&up_req->io_ev, fuzzy_peer_send_io,
+                                                                  session->ctx->peer_fd, EV_WRITE);
+                                               ev_io_start(session->ctx->event_loop, &up_req->io_ev);
+                                       }
+                                       else {
+                                               g_free(up_req);
+                                       }
                                }
                        }
 
@@ -2805,6 +2808,7 @@ lua_fuzzy_add_post_handler(lua_State *L)
        }
 
        wrk = *pwrk;
+       ctx = (struct rspamd_fuzzy_storage_ctx *) wrk->ctx;
 
        if (wrk && lua_isfunction(L, 2)) {
                ctx = (struct rspamd_fuzzy_storage_ctx *) wrk->ctx;
@@ -2834,6 +2838,7 @@ lua_fuzzy_add_blacklist_handler(lua_State *L)
        }
 
        wrk = *pwrk;
+       ctx = (struct rspamd_fuzzy_storage_ctx *) wrk->ctx;
 
        if (wrk && lua_isfunction(L, 2)) {
                struct rspamd_lua_fuzzy_script *script;
index bab2895cd051e6b9a27face955b8b5b1653299c5..3d5cbb863d03f7355d8c5c184be44c283036bc8f 100644 (file)
@@ -562,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)
 {
index fe22d473e4715e72817f45f8d39e5af736a6ea6f..249c4d1c3723cc00c714d6bd3f7d753682e2c0d9 100644 (file)
@@ -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