]> source.dussan.org Git - rspamd.git/commitdiff
[Rework] Remove control block support vstakhov-remove-control-block 5160/head
authorVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 26 Sep 2024 14:21:41 +0000 (15:21 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 26 Sep 2024 14:21:41 +0000 (15:21 +0100)
It has been buggy and never really used by anyone I suppose.

src/libserver/protocol.c
src/libserver/protocol_internal.h
src/libserver/task.c
src/libserver/task.h

index ee21929130e4093a1419d9e0780ff02a344522fe..a86111ff22dbf0cbed65176b98023cbe97367aee 100644 (file)
@@ -720,12 +720,6 @@ rspamd_protocol_handle_headers(struct rspamd_task *task,
                break;
        case 'm':
        case 'M':
-               IF_HEADER(MLEN_HEADER)
-               {
-                       msg_debug_protocol("read message length header, value: %T",
-                                                          hv_tok);
-                       task->protocol_flags |= RSPAMD_TASK_PROTOCOL_FLAG_HAS_CONTROL;
-               }
                IF_HEADER(MTA_TAG_HEADER)
                {
                        char *mta_tag;
@@ -782,120 +776,6 @@ if (!has_ip) {
 return TRUE;
 }
 
-#define BOOL_TO_FLAG(val, flags, flag) \
-       do {                               \
-               if ((val)) (flags) |= (flag);  \
-               else                           \
-                       (flags) &= ~(flag);        \
-       } while (0)
-
-gboolean
-rspamd_protocol_parse_task_flags(rspamd_mempool_t *pool,
-                                                                const ucl_object_t *obj,
-                                                                gpointer ud,
-                                                                struct rspamd_rcl_section *section,
-                                                                GError **err)
-{
-       struct rspamd_rcl_struct_parser *pd = ud;
-       int *target;
-       const char *key;
-       gboolean value;
-
-       target = (int *) (((char *) pd->user_struct) + pd->offset);
-       key = ucl_object_key(obj);
-       value = ucl_object_toboolean(obj);
-
-       if (key != NULL) {
-               if (g_ascii_strcasecmp(key, "pass_all") == 0) {
-                       BOOL_TO_FLAG(value, *target, RSPAMD_TASK_FLAG_PASS_ALL);
-               }
-               else if (g_ascii_strcasecmp(key, "no_log") == 0) {
-                       BOOL_TO_FLAG(value, *target, RSPAMD_TASK_FLAG_NO_LOG);
-               }
-       }
-
-       return TRUE;
-}
-
-static struct rspamd_rcl_sections_map *control_parser = NULL;
-
-RSPAMD_CONSTRUCTOR(rspamd_protocol_control_parser_ctor)
-{
-
-       struct rspamd_rcl_section *sub = rspamd_rcl_add_section(&control_parser, NULL,
-                                                                                                                       "*",
-                                                                                                                       NULL,
-                                                                                                                       NULL,
-                                                                                                                       UCL_OBJECT,
-                                                                                                                       FALSE,
-                                                                                                                       TRUE);
-       /* Default handlers */
-       rspamd_rcl_add_default_handler(sub,
-                                                                  "ip",
-                                                                  rspamd_rcl_parse_struct_addr,
-                                                                  G_STRUCT_OFFSET(struct rspamd_task, from_addr),
-                                                                  0,
-                                                                  NULL);
-       rspamd_rcl_add_default_handler(sub,
-                                                                  "from",
-                                                                  rspamd_rcl_parse_struct_mime_addr,
-                                                                  G_STRUCT_OFFSET(struct rspamd_task, from_envelope),
-                                                                  0,
-                                                                  NULL);
-       rspamd_rcl_add_default_handler(sub,
-                                                                  "rcpt",
-                                                                  rspamd_rcl_parse_struct_mime_addr,
-                                                                  G_STRUCT_OFFSET(struct rspamd_task, rcpt_envelope),
-                                                                  0,
-                                                                  NULL);
-       rspamd_rcl_add_default_handler(sub,
-                                                                  "helo",
-                                                                  rspamd_rcl_parse_struct_string,
-                                                                  G_STRUCT_OFFSET(struct rspamd_task, helo),
-                                                                  0,
-                                                                  NULL);
-       rspamd_rcl_add_default_handler(sub,
-                                                                  "user",
-                                                                  rspamd_rcl_parse_struct_string,
-                                                                  G_STRUCT_OFFSET(struct rspamd_task, auth_user),
-                                                                  0,
-                                                                  NULL);
-       rspamd_rcl_add_default_handler(sub,
-                                                                  "pass_all",
-                                                                  rspamd_protocol_parse_task_flags,
-                                                                  G_STRUCT_OFFSET(struct rspamd_task, flags),
-                                                                  0,
-                                                                  NULL);
-       rspamd_rcl_add_default_handler(sub,
-                                                                  "json",
-                                                                  rspamd_protocol_parse_task_flags,
-                                                                  G_STRUCT_OFFSET(struct rspamd_task, flags),
-                                                                  0,
-                                                                  NULL);
-}
-
-RSPAMD_DESTRUCTOR(rspamd_protocol_control_parser_dtor)
-{
-       rspamd_rcl_sections_free(control_parser);
-}
-
-gboolean
-rspamd_protocol_handle_control(struct rspamd_task *task,
-                                                          const ucl_object_t *control)
-{
-       GError *err = NULL;
-
-       if (!rspamd_rcl_parse(control_parser, task->cfg, task, task->task_pool,
-                                                 control, &err)) {
-               msg_warn_protocol("cannot parse control block: %e", err);
-               g_error_free(err);
-
-               return FALSE;
-       }
-
-       return TRUE;
-}
-
 gboolean
 rspamd_protocol_handle_request(struct rspamd_task *task,
                                                           struct rspamd_http_message *msg)
index e55e548518d431fa0e21a5b56dc2f3a8abb8f65f..11f21430e0498d2ca0cc748ee59363878b1e2c0b 100644 (file)
@@ -79,7 +79,6 @@ extern "C" {
 #define DELIVER_TO_HEADER "Deliver-To"
 #define NO_LOG_HEADER "Log"
 #define LOG_TAG_HEADER "Log-Tag"
-#define MLEN_HEADER "Message-Length"
 #define USER_AGENT_HEADER "User-Agent"
 #define MTA_TAG_HEADER "MTA-Tag"
 #define PROFILE_HEADER "Profile"
index 637f401a9317bba9cb93f8d8b3e909fbbd55ac18..8330464702afcb16ce1e3df7e183594ebca28daa 100644 (file)
@@ -323,9 +323,6 @@ gboolean
 rspamd_task_load_message(struct rspamd_task *task,
                                                 struct rspamd_http_message *msg, const char *start, gsize len)
 {
-       unsigned int control_len, r;
-       struct ucl_parser *parser;
-       ucl_object_t *control_obj;
        char filepath[PATH_MAX], *fp;
        int fd, flen;
        gulong offset = 0, shmem_size = 0;
@@ -349,8 +346,8 @@ rspamd_task_load_message(struct rspamd_task *task,
 
        if (tok) {
                /* Shared memory part */
-               r = rspamd_strlcpy(filepath, tok->begin,
-                                                  MIN(sizeof(filepath), tok->len + 1));
+               size_t r = rspamd_strlcpy(filepath, tok->begin,
+                                                                 MIN(sizeof(filepath), tok->len + 1));
 
                rspamd_url_decode(filepath, filepath, r + 1);
                flen = strlen(filepath);
@@ -448,8 +445,8 @@ rspamd_task_load_message(struct rspamd_task *task,
                if (tok) {
                        debug_task("want to scan file %T", tok);
 
-                       r = rspamd_strlcpy(filepath, tok->begin,
-                                                          MIN(sizeof(filepath), tok->len + 1));
+                       size_t r = rspamd_strlcpy(filepath, tok->begin,
+                                                                         MIN(sizeof(filepath), tok->len + 1));
 
                        rspamd_url_decode(filepath, filepath, r + 1);
                        flen = strlen(filepath);
@@ -626,41 +623,6 @@ rspamd_task_load_message(struct rspamd_task *task,
                task->flags |= RSPAMD_TASK_FLAG_EMPTY;
        }
 
-       if (task->protocol_flags & RSPAMD_TASK_PROTOCOL_FLAG_HAS_CONTROL) {
-               rspamd_ftok_t *hv = rspamd_task_get_request_header(task, MLEN_HEADER);
-               gulong message_len = 0;
-
-               if (!hv || !rspamd_strtoul(hv->begin, hv->len, &message_len) ||
-                       task->msg.len < message_len) {
-                       msg_warn_task("message has invalid message length: %ul and total len: %ul",
-                                                 message_len, task->msg.len);
-                       g_set_error(&task->err, rspamd_task_quark(), RSPAMD_PROTOCOL_ERROR,
-                                               "Invalid length");
-                       return FALSE;
-               }
-
-               control_len = task->msg.len - message_len;
-
-               if (control_len > 0) {
-                       parser = ucl_parser_new(UCL_PARSER_KEY_LOWERCASE);
-
-                       if (!ucl_parser_add_chunk(parser, task->msg.begin, control_len)) {
-                               msg_warn_task("processing of control chunk failed: %s",
-                                                         ucl_parser_get_error(parser));
-                               ucl_parser_free(parser);
-                       }
-                       else {
-                               control_obj = ucl_parser_get_object(parser);
-                               ucl_parser_free(parser);
-                               rspamd_protocol_handle_control(task, control_obj);
-                               ucl_object_unref(control_obj);
-                       }
-
-                       task->msg.begin += control_len;
-                       task->msg.len -= control_len;
-               }
-       }
-
        return TRUE;
 }
 
index 7e6341a84d6cc04803a9bdbc17ac9b0806c9df9f..6be3500987127c470f73dedb35d45f8407548d14 100644 (file)
@@ -115,9 +115,6 @@ enum rspamd_task_stage {
 #define RSPAMD_TASK_FLAG_MESSAGE_REWRITE (1u << 24u)
 #define RSPAMD_TASK_FLAG_MAX_SHIFT (24u)
 
-
-/* Request has a JSON control block */
-#define RSPAMD_TASK_PROTOCOL_FLAG_HAS_CONTROL (1u << 0u)
 /* Request has been done by a local client */
 #define RSPAMD_TASK_PROTOCOL_FLAG_LOCAL_CLIENT (1u << 1u)
 /* Request has been sent via milter */