}
task = rspamd_task_new (session->ctx->worker);
- task->msg = msg->body;
task->resolver = ctx->resolver;
task->ev_base = ctx->ev_base;
task->sock = conn_ent->conn->fd;
- if (!rspamd_task_process (task, msg, NULL, FALSE)) {
+ /* XXX: Handle encrypted messages */
+ if (!rspamd_task_process (task, msg, msg->body->str, msg->body->len, NULL, FALSE)) {
msg_warn ("filters cannot be processed for %s", task->message_id);
rspamd_controller_send_error (conn_ent, 500, task->last_error);
destroy_session (task->s);
task = rspamd_task_new (session->ctx->worker);
task->ev_base = session->ctx->ev_base;
- task->msg = msg->body;
task->resolver = ctx->resolver;
task->ev_base = ctx->ev_base;
task->http_conn = rspamd_http_connection_ref (conn_ent->conn);
task->sock = conn_ent->conn->fd;
- if (!rspamd_task_process (task, msg, NULL, FALSE)) {
+ /* XXX: handle encrypted messages */
+ if (!rspamd_task_process (task, msg, msg->body->str, msg->body->len, NULL, FALSE)) {
msg_warn ("filters cannot be processed for %s", task->message_id);
rspamd_controller_send_error (conn_ent, 500, task->last_error);
destroy_session (task->s);
gint rc;
tmp = rspamd_mempool_alloc (task->task_pool, sizeof (GByteArray));
- tmp->data = task->msg->str;
- tmp->len = task->msg->len;
+ tmp->data = (guint8 *)task->msg.start;
+ tmp->len = task->msg.len;
stream = g_mime_stream_mem_new_with_byte_array (tmp);
/*
if (task->is_mime) {
debug_task ("construct mime parser from string length %d",
- (gint)task->msg->len);
+ (gint)task->msg.len);
/* create a new parser object to parse the stream */
parser = g_mime_parser_new_with_stream (stream);
g_object_unref (stream);
if (session) {
if (session->task) {
rspamd_task_free (session->task, FALSE);
- if (session->task->msg->str) {
- munmap (session->task->msg->str, session->task->msg->len);
+ if (session->task->msg.start) {
+ munmap (session->task->msg.start, session->task->msg.len);
}
}
if (session->rcpt) {
cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset,
cd->log_size - cd->log_offset,
"]), len: %z, time: %s,",
- task->msg->len,
+ task->msg.len,
calculate_check_time (&task->tv, &task->ts, task->cfg->clock_res,
&task->scan_milliseconds));
#else
cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset,
cd->log_size - cd->log_offset,
"]), len: %z, time: %s,",
- task->msg->len,
+ task->msg.len,
calculate_check_time (&task->tv, task->cfg->clock_res,
&task->scan_milliseconds));
#endif
g_return_val_if_fail (ctx != NULL, DKIM_ERROR);
g_return_val_if_fail (key != NULL, DKIM_ERROR);
- g_return_val_if_fail (task->msg != NULL, DKIM_ERROR);
+ g_return_val_if_fail (task->msg.len > 0, DKIM_ERROR);
/* First of all find place of body */
- p = task->msg->str;
+ p = task->msg.start;
- end = task->msg->str + task->msg->len;
+ end = task->msg.start + task->msg.len;
while (p <= end) {
/* Search for \r\n\r\n at the end of headers */
#ifdef HAVE_CLOCK_GETTIME
rspamd_printf_gstring (logbuf, "]), len: %z, time: %s, dns req: %d,",
- task->msg->len, calculate_check_time (&task->tv, &task->ts,
+ task->msg.len, calculate_check_time (&task->tv, &task->ts,
task->cfg->clock_res, &task->scan_milliseconds), task->dns_requests);
#else
rspamd_printf_gstring (logbuf, "]), len: %z, time: %s, dns req: %d,",
}
row->scan_time = task->scan_milliseconds;
- row->len = (task->msg == NULL ? 0 : task->msg->len);
+ row->len = task->msg.len;
row->completed = TRUE;
}
gboolean
rspamd_task_process (struct rspamd_task *task,
- struct rspamd_http_message *msg, GThreadPool *classify_pool,
+ struct rspamd_http_message *msg, const gchar *start, gsize len,
+ GThreadPool *classify_pool,
gboolean process_extra_filters)
{
gint r;
GError *err = NULL;
- if (msg->body->len == 0) {
- msg_err ("got zero length body");
- task->last_error = "message's body is empty";
- return FALSE;
- }
-
- /* XXX: awful hack */
- if (msg->peer_key != NULL) {
- task->msg = rspamd_mempool_alloc (task->task_pool, sizeof (GString));
- task->msg->len = msg->body->len - 16;
- task->msg->allocated_len = 0;
- task->msg->str = msg->body->str + 16;
- }
- else {
- task->msg = msg->body;
- }
- debug_task ("got string of length %z", task->msg->len);
+ task->msg.start = start;
+ task->msg.len = len;
+ debug_task ("got string of length %z", task->msg.len);
/* We got body, set wanna_die flag */
task->s->wanna_die = TRUE;
gchar *hostname; /**< hostname reported by MTA */
GHashTable *request_headers; /**< HTTP headers in a request */
GHashTable *reply_headers; /**< Custom reply headers */
- GString *msg; /**< message buffer */
+ struct {
+ const gchar *start;
+ gsize len;
+ } msg; /**< message buffer */
struct rspamd_http_connection *http_conn; /**< HTTP server connection */
struct rspamd_async_session * s; /**< async session object */
gint parts_count; /**< mime parts count */
* @return task has been successfully parsed and processed
*/
gboolean rspamd_task_process (struct rspamd_task *task,
- struct rspamd_http_message *msg, GThreadPool *classify_pool,
+ struct rspamd_http_message *msg, const gchar *start, gsize len,
+ GThreadPool *classify_pool,
gboolean process_extra_filters);
/**
ptask = lua_newuserdata (L, sizeof (gpointer));
rspamd_lua_setclass (L, "rspamd{task}", -1);
*ptask = task;
- task->msg = g_string_new_len (data, len);
+ task->msg.start = rspamd_mempool_alloc (task->task_pool, len + 1);
+ memcpy ((gpointer)task->msg.start, data, len);
+ task->msg.len = len;
}
return 1;
}
{
struct rspamd_task *task = lua_check_task (L);
- if (task != NULL && task->msg != NULL && task->msg->len > 0) {
+ if (task != NULL && task->msg.len > 0) {
if (process_message (task) == 0) {
lua_pushboolean (L, TRUE);
}
task->cfg = ctx->cfg;
/* Allocate message from string */
- task->msg = msg->body;
+ /* XXX: what about encrypted messsages ? */
+ task->msg.start = msg->body->str;
+ task->msg.len = msg->body->len;
saved = rspamd_mempool_alloc0 (task->task_pool, sizeof (gint));
err = rspamd_mempool_alloc0 (task->task_pool, sizeof (GError *));
case REGEXP_MESSAGE:
debug_task ("checking message regexp: %s", re->regexp_text);
regexp = re->raw_regexp;
- ct = task->msg->str;
- clen = task->msg->len;
+ ct = (guint8 *)task->msg.start;
+ clen = task->msg.len;
if (regexp_module_ctx->max_size != 0 && clen >
regexp_module_ctx->max_size) {
task->peer_key = rspamd_http_connection_key_ref (msg->peer_key);
}
- if (!rspamd_task_process (task, msg, ctx->classify_pool, TRUE)) {
+ if (!rspamd_task_process (task, msg, chunk, len, ctx->classify_pool, TRUE)) {
task->state = WRITE_REPLY;
}