aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/protocol.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-07-18 14:09:03 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-07-18 14:09:03 +0100
commitde4e7f2afa28c0163ae7da9f11ad59f0be12323c (patch)
tree29261fe85b0b38c07f36cfbdbfd52286fa3cadac /src/libserver/protocol.c
parentdf5d064b0ca52b81154e6a959e9ae05792b4f706 (diff)
downloadrspamd-de4e7f2afa28c0163ae7da9f11ad59f0be12323c.tar.gz
rspamd-de4e7f2afa28c0163ae7da9f11ad59f0be12323c.zip
[Project] Allow to send body via protocol
Diffstat (limited to 'src/libserver/protocol.c')
-rw-r--r--src/libserver/protocol.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c
index 12bef1dce..02dc73607 100644
--- a/src/libserver/protocol.c
+++ b/src/libserver/protocol.c
@@ -1558,6 +1558,63 @@ rspamd_protocol_http_reply (struct rspamd_http_message *msg,
}
}
+ if (task->protocol_flags & RSPAMD_TASK_PROTOCOL_FLAG_BODY_BLOCK) {
+ /* Check if we need to insert a body block */
+ if (task->flags & RSPAMD_TASK_FLAG_MESSAGE_REWRITE) {
+ GString *hdr_offset = g_string_sized_new (30);
+
+ rspamd_printf_gstring (hdr_offset, "%z", RSPAMD_FSTRING_LEN (reply));
+ rspamd_http_message_add_header (msg, "Message-Offset",
+ hdr_offset->str);
+ msg_debug_protocol ("write body block at position %s",
+ hdr_offset->str);
+ g_string_free (hdr_offset, TRUE);
+
+ /* In case of milter, we append just body, otherwise - full message */
+ if (task->protocol_flags & RSPAMD_TASK_PROTOCOL_FLAG_MILTER) {
+ const gchar *start;
+ goffset len, hdr_off;
+
+ start = task->msg.begin;
+ len = task->msg.len;
+
+ hdr_off = MESSAGE_FIELD (task, raw_headers_content).len;
+
+ if (hdr_off < len) {
+ start += hdr_off;
+ len -= hdr_off;
+
+ /* The problem here is that we need not end of headers, we need
+ * start of body.
+ *
+ * Hence, we need to skip one \r\n till there is anything else in
+ * a line.
+ */
+
+ if (*start == '\r' && len > 0) {
+ start ++;
+ len --;
+ }
+
+ if (*start == '\n' && len > 0) {
+ start ++;
+ len --;
+ }
+
+ msg_debug_protocol ("milter version of body block size %d",
+ (int)len);
+ reply = rspamd_fstring_append (reply, start, len);
+ }
+ }
+ else {
+ msg_debug_protocol ("general version of body block size %d",
+ (int)task->msg.len);
+ reply = rspamd_fstring_append (reply,
+ task->msg.begin, task->msg.len);
+ }
+ }
+ }
+
if ((task->protocol_flags & RSPAMD_TASK_PROTOCOL_FLAG_COMPRESSED) &&
rspamd_libs_reset_compression (task->cfg->libs_ctx)) {
/* We can compress output */