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;
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)
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;
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);
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);
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;
}