]> source.dussan.org Git - rspamd.git/commitdiff
Fix other mime library modules.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 6 Oct 2015 15:30:52 +0000 (16:30 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 6 Oct 2015 15:30:52 +0000 (16:30 +0100)
src/libmime/message.c
src/libmime/smtp_proto.c
src/libmime/smtp_proto.h
src/libmime/smtp_utils.c

index 3537f70c0aa383d2fd8559754aca8c070b306054..183b9bcee1843dbfad63cc492730c008bbf3a334 100644 (file)
@@ -112,8 +112,7 @@ parse_recv_header (rspamd_mempool_t * pool,
                RSPAMD_RECV_STATE_PARSE_IP,
                RSPAMD_RECV_STATE_SKIP_SPACES,
                RSPAMD_RECV_STATE_ERROR
-       }                               state = RSPAMD_RECV_STATE_INIT,
-               next_state = RSPAMD_RECV_STATE_INIT;
+       } state = RSPAMD_RECV_STATE_INIT, next_state = RSPAMD_RECV_STATE_INIT;
        gboolean is_exim = FALSE;
 
        line = rh->decoded;
@@ -949,7 +948,7 @@ rspamd_normalize_text_part (struct rspamd_task *task,
                struct mime_text_part *part)
 {
        struct sb_stemmer *stem = NULL;
-       rspamd_fstring_t *w;
+       rspamd_ftok_t *w;
        const guchar *r;
        gchar *temp_word;
        guint i, nlen;
@@ -971,7 +970,7 @@ rspamd_normalize_text_part (struct rspamd_task *task,
 
        if (tmp) {
                for (i = 0; i < tmp->len; i ++) {
-                       w = &g_array_index (tmp, rspamd_fstring_t, i);
+                       w = &g_array_index (tmp, rspamd_ftok_t, i);
                        if (stem) {
                                r = sb_stemmer_stem (stem, w->begin, w->len);
                        }
@@ -980,21 +979,23 @@ rspamd_normalize_text_part (struct rspamd_task *task,
                                if (stem != NULL && r != NULL) {
                                        nlen = strlen (r);
                                        nlen = MIN (nlen, w->len);
-                                       w->begin = rspamd_mempool_alloc (task->task_pool, nlen);
-                                       memcpy (w->begin, r, nlen);
+                                       temp_word = rspamd_mempool_alloc (task->task_pool, nlen);
+                                       memcpy (temp_word, r, nlen);
+                                       w->begin = temp_word;
                                        w->len = nlen;
                                }
                                else {
-                                       temp_word = w->begin;
-                                       w->begin = rspamd_mempool_alloc (task->task_pool, w->len);
-                                       memcpy (w->begin, temp_word, w->len);
+                                       temp_word = rspamd_mempool_alloc (task->task_pool, w->len);
+                                       memcpy (temp_word, w->begin, w->len);
 
                                        if (IS_PART_UTF (part)) {
-                                               rspamd_str_lc_utf8 (w->begin, w->len);
+                                               rspamd_str_lc_utf8 (temp_word, w->len);
                                        }
                                        else {
-                                               rspamd_str_lc (w->begin, w->len);
+                                               rspamd_str_lc (temp_word, w->len);
                                        }
+
+                                       w->begin = temp_word;
                                }
                        }
                }
@@ -1463,8 +1464,9 @@ rspamd_message_parse (struct rspamd_task *task)
        guint tw, dw;
 
        tmp = rspamd_mempool_alloc (task->task_pool, sizeof (GByteArray));
-       p = task->msg.start;
+       p = task->msg.begin;
        len = task->msg.len;
+
        /* Skip any space characters to avoid some bad messages to be unparsed */
        while (g_ascii_isspace (*p) && len > 0) {
                p ++;
index 988bd37af925afc92a2f0824e5101c80649306e3..d00a25e0fefa43723f7a9da23056a4fd1b5ee18d 100644 (file)
@@ -57,7 +57,7 @@ make_smtp_error (rspamd_mempool_t *pool,
 
 gboolean
 parse_smtp_command (struct smtp_session *session,
-       rspamd_fstring_t *line,
+       rspamd_ftok_t *line,
        struct smtp_command **cmd)
 {
        enum {
@@ -66,9 +66,10 @@ parse_smtp_command (struct smtp_session *session,
                SMTP_PARSE_ARGUMENT,
                SMTP_PARSE_DONE
        }                              state;
-       gchar *p, *c, ch, cmd_buf[4];
+       const gchar *p, *c;
+       gchar ch, cmd_buf[4];
        guint i;
-       rspamd_fstring_t *arg = NULL;
+       rspamd_ftok_t *arg = NULL;
        struct smtp_command *pcmd;
 
        if (line->len == 0) {
@@ -176,8 +177,9 @@ parse_smtp_command (struct smtp_session *session,
                                }
                                arg->len = p - c;
                                arg->begin = rspamd_mempool_alloc (session->pool, arg->len);
-                               memcpy (arg->begin, c, arg->len);
+                               memcpy ((gchar *)arg->begin, c, arg->len);
                                pcmd->args = g_list_prepend (pcmd->args, arg);
+
                                if (ch == ' ' || ch == ':') {
                                        state = SMTP_PARSE_SPACES;
                                }
@@ -209,10 +211,10 @@ end:
 }
 
 static gboolean
-check_smtp_path (rspamd_fstring_t *path)
+check_smtp_path (rspamd_ftok_t *path)
 {
        guint i;
-       gchar *p;
+       const gchar *p;
 
        p = path->begin;
        if (*p != '<' || path->len < 2) {
@@ -230,7 +232,7 @@ check_smtp_path (rspamd_fstring_t *path)
 gboolean
 parse_smtp_helo (struct smtp_session *session, struct smtp_command *cmd)
 {
-       rspamd_fstring_t *arg;
+       rspamd_ftok_t *arg;
 
        if (cmd->args == NULL) {
                session->error = SMTP_ERROR_BAD_ARGUMENTS;
@@ -265,7 +267,7 @@ parse_smtp_helo (struct smtp_session *session, struct smtp_command *cmd)
 gboolean
 parse_smtp_from (struct smtp_session *session, struct smtp_command *cmd)
 {
-       rspamd_fstring_t *arg;
+       rspamd_ftok_t *arg;
        GList *cur = cmd->args;
 
        if (cmd->args == NULL) {
@@ -303,7 +305,7 @@ parse_smtp_from (struct smtp_session *session, struct smtp_command *cmd)
 gboolean
 parse_smtp_rcpt (struct smtp_session *session, struct smtp_command *cmd)
 {
-       rspamd_fstring_t *arg;
+       rspamd_ftok_t *arg;
        GList *cur = cmd->args;
 
        if (cmd->args == NULL) {
@@ -339,9 +341,9 @@ parse_smtp_rcpt (struct smtp_session *session, struct smtp_command *cmd)
 
 /* Return -1 if there are some error, 1 if all is ok and 0 in case of incomplete reply */
 static gint
-check_smtp_ustream_reply (rspamd_fstring_t *in, gchar success_code)
+check_smtp_ustream_reply (rspamd_ftok_t *in, gchar success_code)
 {
-       gchar *p;
+       const gchar *p;
 
        /* Check for 250 at the begin of line */
        if (in->len >= sizeof ("220 ") - 1) {
@@ -368,7 +370,7 @@ smtp_upstream_write_list (GList *args, gchar *buf, size_t buflen)
 {
        GList *cur = args;
        size_t r = 0;
-       rspamd_fstring_t *arg;
+       rspamd_ftok_t *arg;
 
        while (cur && r < buflen - 3) {
                arg = cur->data;
@@ -401,7 +403,7 @@ smtp_upstream_write_socket (void *arg)
 }
 
 gboolean
-smtp_upstream_read_socket (rspamd_fstring_t * in, void *arg)
+smtp_upstream_read_socket (rspamd_ftok_t * in, void *arg)
 {
        struct smtp_session *session = arg;
        gchar outbuf[BUFSIZ];
index a0f2ec5c27a5879c87c7c029b7c63dfe9bb8fb53..7ede6f8037ce21ffe0ad0e548c2a20be67ef0b5d 100644 (file)
 
 #define MAX_SMTP_UPSTREAMS 128
 
+enum smtp_command_type {
+       SMTP_COMMAND_HELO = 0,
+       SMTP_COMMAND_EHLO,
+       SMTP_COMMAND_QUIT,
+       SMTP_COMMAND_NOOP,
+       SMTP_COMMAND_MAIL,
+       SMTP_COMMAND_RCPT,
+       SMTP_COMMAND_RSET,
+       SMTP_COMMAND_DATA,
+       SMTP_COMMAND_VRFY,
+       SMTP_COMMAND_EXPN,
+       SMTP_COMMAND_HELP
+};
 struct smtp_command {
-       enum {
-               SMTP_COMMAND_HELO,
-               SMTP_COMMAND_EHLO,
-               SMTP_COMMAND_QUIT,
-               SMTP_COMMAND_NOOP,
-               SMTP_COMMAND_MAIL,
-               SMTP_COMMAND_RCPT,
-               SMTP_COMMAND_RSET,
-               SMTP_COMMAND_DATA,
-               SMTP_COMMAND_VRFY,
-               SMTP_COMMAND_EXPN,
-               SMTP_COMMAND_HELP
-       } command;
+       enum smtp_command_type command;
        GList *args;
 };
 
@@ -53,7 +54,7 @@ gchar * make_smtp_error (rspamd_mempool_t *pool,
  * Parse a single SMTP command
  */
 gboolean parse_smtp_command (struct smtp_session *session,
-       rspamd_fstring_t *line,
+       rspamd_ftok_t *line,
        struct smtp_command **cmd);
 
 /*
@@ -79,7 +80,7 @@ gboolean parse_smtp_rcpt (struct smtp_session *session,
 /*
  * Read a line from SMTP upstream
  */
-gboolean smtp_upstream_read_socket (rspamd_fstring_t * in, void *arg);
+gboolean smtp_upstream_read_socket (rspamd_ftok_t * in, void *arg);
 
 /*
  * Write to SMTP upstream
index edc7f3b1465cf49b9237ac60aa4bf30625547dad..df50abc6529ee1c3496bbc4ef3f4ef38de2a76d0 100644 (file)
@@ -35,8 +35,9 @@ free_smtp_session (gpointer arg)
        if (session) {
                if (session->task) {
                        rspamd_task_free (session->task, FALSE);
-                       if (session->task->msg.start) {
-                               munmap (session->task->msg.start, session->task->msg.len);
+                       if (session->task->msg.begin) {
+                               munmap ((gpointer)session->task->msg.begin,
+                                               session->task->msg.len);
                        }
                }
                if (session->rcpt) {