]> source.dussan.org Git - rspamd.git/commitdiff
* Fix many compile time warnings and polish code
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 24 Mar 2009 15:38:11 +0000 (18:38 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 24 Mar 2009 15:38:11 +0000 (18:38 +0300)
19 files changed:
CMakeLists.txt
config.h.in
src/controller.c
src/expressions.c
src/filter.c
src/fstring.c
src/fuzzy.c
src/lmtp.c
src/lmtp_proto.c
src/mem_pool.c
src/message.c
src/plugins/regexp.c
src/plugins/surbl.c
src/protocol.c
src/statfile.c
src/url.c
src/util.c
src/worker.c
test/rspamd_memcached_test.c

index fad4f5d4ab97e40505bf9d12b44be3ba59f3f1c1..4fd124d0ad9f3b5ae8a4657600eb12e2dcbb1f2b 100644 (file)
@@ -150,6 +150,7 @@ CHECK_INCLUDE_FILES(sys/stat.h  HAVE_SYS_STAT_H)
 CHECK_INCLUDE_FILES(sys/wait.h  HAVE_SYS_WAIT_H)
 CHECK_INCLUDE_FILES(sys/param.h  HAVE_SYS_PARAM_H)
 CHECK_INCLUDE_FILES(sys/cdefs.h  HAVE_SYS_CDEFS_H)
+CHECK_INCLUDE_FILES(sys/file.h  HAVE_SYS_FILE_H)
 CHECK_INCLUDE_FILES(netinet/in.h  HAVE_NETINET_IN_H)
 CHECK_INCLUDE_FILES(arpa/inet.h  HAVE_ARPA_INET_H)
 CHECK_INCLUDE_FILES(netdb.h  HAVE_NETDB_H)
@@ -206,7 +207,8 @@ ELSE (MD5_INCLUDE)
        MESSAGE(STATUS "WARNING: Using internal MD5 support")
 ENDIF (MD5_INCLUDE)
 
-SET(CMAKE_C_WARN_FLAGS " -Wall -W -Wpointer-arith -Wno-unused-parameter -Wno-unused-function -Wunused-variable -Wno-sign-compare -Wunused-value")
+SET(CMAKE_C_WARN_FLAGS "-Wall -W -Wpointer-arith -Wno-unused-parameter -Wno-unused-function -Wunused-variable -Wno-sign-compare -Wunused-value -Wno-declaration-after-statement -Wno-pointer-sign")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_WARN_FLAGS} -std=c99")
 
 # Platform specific routines
 IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
index 98204633892c9b15990e7e132d2f95d78df4c0ce..1fc9108cbbd286c4b367bec0dcf21db0904cb347 100644 (file)
@@ -31,6 +31,9 @@
 
 #cmakedefine HAVE_STDBOOL_H      1
 
+#cmakedefine HAVE_ARPA_INET_H    1
+#cmakedefine HAVE_NETINET_IN_H   1
+
 #cmakedefine HAVE_NETDB_H        1
 
 #cmakedefine HAVE_SYSLOG_H       1
@@ -56,6 +59,7 @@
 #cmakedefine HAVE_SYS_STAT_H     1
 #cmakedefine HAVE_SYS_WAIT_H     1
 #cmakedefine HAVE_SYS_PARAM_H    1
+#cmakedefine HAVE_SYS_FILE_H     1
 
 #cmakedefine HAVE_PIDFILE        1
 
 #include <sys/socket.h>
 #endif
 
+/* sys/file.h */
+#ifdef HAVE_SYS_FILE_H
+#include <sys/file.h>
+#endif
+
 /* sys/mman */
 #ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
index 76caab0dfc1e0c1e0b268051f9d39d6beaaa49ad..8a56b7f5bed5195b0db9f6158d0a84a7a83c9770 100644 (file)
@@ -295,7 +295,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                                                        case 'r':
                                                                arg = *(cmd_args + 1);
                                                                if (!arg || *arg == '\0') {
-                                                                       r = snprintf (out_buf, sizeof (out_buf), "recipient is not defined" CRLF, arg);
+                                                                       r = snprintf (out_buf, sizeof (out_buf), "recipient is not defined" CRLF);
                                                                        rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE);
                                                                        return;
                                                                }
@@ -304,7 +304,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                                                        case 'f':
                                                                arg = *(cmd_args + 1);
                                                                if (!arg || *arg == '\0') {
-                                                                       r = snprintf (out_buf, sizeof (out_buf), "from is not defined" CRLF, arg);
+                                                                       r = snprintf (out_buf, sizeof (out_buf), "from is not defined" CRLF);
                                                                        rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE);
                                                                        return;
                                                                }
@@ -314,7 +314,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                                                                session->in_class = 0;
                                                                break;
                                                        default:
-                                                               r = snprintf (out_buf, sizeof (out_buf), "tokenizer is not defined" CRLF, arg);
+                                                               r = snprintf (out_buf, sizeof (out_buf), "tokenizer is not defined" CRLF);
                                                                rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE);
                                                                return;
                                                }
@@ -432,6 +432,9 @@ controller_read_socket (f_str_t *in, void *arg)
 
                        session->state = STATE_REPLY;
                        break;
+               default:
+                       msg_debug ("controller_read_socket: unknown state while reading %d", session->state);
+                       break;
        }
 }
 
index e010bce84ed117868b5ebd20216310e07b49d5a7..f222ea2b405ab0105d0bdbdd1d557974224c2c25 100644 (file)
@@ -448,7 +448,6 @@ parse_regexp (memory_pool_t *pool, char *line)
        char *begin, *end, *p, *src;
        struct rspamd_regexp *result;
        int regexp_flags = 0;
-       enum rspamd_regexp_type type = REGEXP_NONE;
        GError *err = NULL;
        
        src = line;
index 1b6cdc1b02fd94d1405c445e40259ac574ac3e39..d273a21ffe0b8ee850000f3d0d25034a078be0a3 100644 (file)
@@ -264,6 +264,8 @@ continue_process_filters (struct worker_task *task)
                        task->dispatcher->write_callback (task);
                        return 1;
        }
+
+       return -1;
 }
 
 int 
index 3098e87262c012c87035f30fad4ba7403dc09bde..2202effafffc86b29cd83afd8c9f01827ae73574 100644 (file)
@@ -104,9 +104,9 @@ fstrstri (f_str_t *orig, f_str_t *pattern)
        }
 
        while (cur < orig->len) {
-               if (tolower (*(orig->begin + cur)) == tolower (*pattern->begin)) {
+               if (g_ascii_tolower (*(orig->begin + cur)) == g_ascii_tolower (*pattern->begin)) {
                        while (cur < orig->len && pcur < pattern->len) {
-                               if (tolower (*(orig->begin + cur)) != tolower (*(pattern->begin + pcur))) {
+                               if (g_ascii_tolower (*(orig->begin + cur)) != g_ascii_tolower (*(pattern->begin + pcur))) {
                                        pcur = 0;
                                        break;
                                }
index 4dfec3fb7a14ad9d495fc7e3979ac8a84b6f6477..ecd1af64ff01bc661fe78b8b4e9907cf46dd8486 100644 (file)
@@ -71,7 +71,7 @@ static uint32_t
 fuzzy_fnv_hash (char c, uint32_t hval)
 {
        hval ^= c;
-       hval = hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
+       hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
        return hval;
 }
 
index a8f10ee2c7255a1cccf7bac715658ec64675b056..d649d11c3041f27ae968f9ffeacc407fc301a76a 100644 (file)
@@ -28,6 +28,7 @@
 #include "lmtp.h"
 #include "lmtp_proto.h"
 #include "cfg_file.h"
+#include "util.h"
 #include "url.h"
 #include "modules.h"
 #include "message.h"
@@ -155,6 +156,9 @@ lmtp_read_socket (f_str_t *in, void *arg)
                                lmtp_write_socket (lmtp);
                        }
                        break;
+               default:
+                       msg_debug ("lmtp_read_socket: invalid state while reading from socket %d", lmtp->task->state);
+                       break;
        }
 }
 
@@ -183,6 +187,9 @@ lmtp_write_socket (void *arg)
                        msg_debug ("lmtp_write_socket: normally closing connection");
                        free_task (lmtp, TRUE);
                        break;
+               default:
+                       msg_debug ("lmtp_write_socket: invalid state while writing to socket %d", lmtp->task->state);
+                       break;
        }
 }
 
index ab20e41a8b72b274f400b17afdde04257159fc09..e6e09a825bd300fd2fbd6a1e2c92f18356368c24 100644 (file)
@@ -25,6 +25,7 @@
 #include "config.h"
 #include "main.h"
 #include "cfg_file.h"
+#include "util.h"
 #include "lmtp.h"
 #include "lmtp_proto.h"
 
@@ -117,7 +118,7 @@ read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t *line)
                                i += lhlo_command.len;
                                c = line->begin + i;
                                /* Skip spaces */
-                               while (isspace (*c) && i < line->len) {
+                               while (g_ascii_isspace (*c) && i < line->len) {
                                        i ++;
                                        c ++;
                                }
@@ -184,7 +185,7 @@ read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t *line)
                                i += data_command.len;
                                c = line->begin + i;
                                /* Skip spaces */
-                               while (isspace (*c++)) {
+                               while (g_ascii_isspace (*c++)) {
                                        i ++;
                                }
                                rcpt = memory_pool_alloc (lmtp->task->task_pool, line->len - i + 1);
@@ -229,6 +230,8 @@ read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t *line)
                        return 0;
                        break;
        }       
+
+       return 0;
 }
 
 struct mta_callback_data {
@@ -236,7 +239,6 @@ struct mta_callback_data {
        rspamd_io_dispatcher_t *dispatcher;
        enum {
                LMTP_WANT_GREETING,
-               LMTP_WANT_HELO,
                LMTP_WANT_MAIL,
                LMTP_WANT_RCPT,
                LMTP_WANT_DATA,
@@ -264,7 +266,6 @@ parse_mta_str (f_str_t *in, struct mta_callback_data *cd)
 
        switch (cd->state) {
                case LMTP_WANT_GREETING:
-               case LMTP_WANT_HELO:
                case LMTP_WANT_MAIL:
                case LMTP_WANT_RCPT:
                case LMTP_WANT_DATA:
@@ -437,12 +438,13 @@ lmtp_deliver_mta (struct worker_task *task)
        cd->dispatcher = rspamd_create_dispatcher (sock, BUFFER_LINE, mta_read_socket,
                                                                                                                NULL, mta_err_socket, NULL,
                                                                                                                (void *)cd);
+       return 0;
 }
 
 static char*
 format_lda_args (struct worker_task *task)
 {
-       char *arg, *res, *c, *r;
+       char *res, *c, *r;
        size_t len;
        GList *rcpt;
        gboolean got_args = FALSE;
@@ -637,7 +639,6 @@ int
 write_lmtp_reply (struct rspamd_lmtp_proto *lmtp)
 {
        int r;
-       char outbuf[OUTBUFSIZ];
 
        msg_debug ("write_lmtp_reply: writing reply to client");
        if (lmtp->task->error_code != 0) {
index db8e3f35153971f939b3f393c5dced85ee125d1c..84ebe9a793f4aae23f6ebacfe6fbecec8f44fd20 100644 (file)
@@ -393,12 +393,10 @@ memory_pool_delete (memory_pool_t *pool)
 void
 memory_pool_stat (memory_pool_stat_t *st)
 {
-       if (stat) {
-               st->bytes_allocated = mem_pool_stat->bytes_allocated;
-               st->chunks_allocated = mem_pool_stat->chunks_allocated;
-               st->shared_chunks_allocated = mem_pool_stat->shared_chunks_allocated;
-               st->chunks_freed = mem_pool_stat->chunks_freed;
-       }
+       st->bytes_allocated = mem_pool_stat->bytes_allocated;
+       st->chunks_allocated = mem_pool_stat->chunks_allocated;
+       st->shared_chunks_allocated = mem_pool_stat->shared_chunks_allocated;
+       st->chunks_freed = mem_pool_stat->chunks_freed;
 }
 
 #define FIXED_POOL_SIZE 4095
index 64467c82732306cfd7930a50ebf230695b25803b..561c494570183e6ec6e091e578fa8687875f83db 100644 (file)
@@ -181,12 +181,12 @@ strip_html_tags (GByteArray *src, int *stateptr)
                        case 'e':
                                /* !DOCTYPE exception */
                                if (state == 3 && p > src->data + 6
-                                                    && tolower(*(p-1)) == 'p'
-                                                && tolower(*(p-2)) == 'y'
-                                                    && tolower(*(p-3)) == 't'
-                                                    && tolower(*(p-4)) == 'c'
-                                                    && tolower(*(p-5)) == 'o'
-                                                    && tolower(*(p-6)) == 'd') {
+                                                    && g_ascii_tolower(*(p-1)) == 'p'
+                                                && g_ascii_tolower(*(p-2)) == 'y'
+                                                    && g_ascii_tolower(*(p-3)) == 't'
+                                                    && g_ascii_tolower(*(p-4)) == 'c'
+                                                    && g_ascii_tolower(*(p-5)) == 'o'
+                                                    && g_ascii_tolower(*(p-6)) == 'd') {
                                        state = 1;
                                        break;
                                }
index 03080c010351141c19f3db92d04a2336c7b897f4..53c64d2b396474fd0ccb8303abf892c2b7220eb7 100644 (file)
@@ -378,4 +378,6 @@ regexp_common_filter (struct worker_task *task)
                process_regexp_item ((struct regexp_module_item *)cur_expr->data, task);
                cur_expr = g_list_next (cur_expr);
        }
+
+       return 0;
 }
index d92fe4a1a4c7b2ce2d57226ec34d3230a5d19231..0fe64ba2fa09f13ac26feddfd2a242dfb496b324 100644 (file)
@@ -27,6 +27,7 @@
  */
 
 #include "../config.h"
+#include "../util.h"
 #include <evdns.h>
 
 #include "surbl.h"
@@ -220,6 +221,8 @@ surbl_module_config (struct config_file *cfg)
                                                                new_suffix->suffix, new_suffix->symbol);
                surbl_module_ctx->suffixes = g_list_prepend (surbl_module_ctx->suffixes, new_suffix);
        }
+
+       return 0;
 }
 
 int
@@ -410,7 +413,6 @@ memcached_callback (memcached_ctx_t *ctx, memc_error_t error, void *data)
 {
        struct memcached_param *param = (struct memcached_param *)data;
        int *url_count;
-       f_str_t c;
 
        switch (ctx->op) {
                case CMD_CONNECT:
@@ -466,6 +468,8 @@ memcached_callback (memcached_ctx_t *ctx, memc_error_t error, void *data)
                        }
                        make_surbl_requests (param->url, param->task, param->tree);
                        break;
+               default:
+                       return;
        }
 }
 
@@ -648,7 +652,6 @@ static int
 surbl_test_url (struct worker_task *task)
 {
        struct uri *url;
-       struct memcached_param *param;
        GTree *url_tree;
 
        url_tree = g_tree_new ((GCompareFunc)g_ascii_strcasecmp);
index 706040bc694a9865bffdfbb9c8cd437fe9e90722..6230495bf4bac1d7ac70b56ec3958c1bd288a98c 100644 (file)
@@ -318,7 +318,10 @@ read_rspamd_input_line (struct worker_task *task, f_str_t *line)
                case READ_HEADER:
                        return parse_header (task, fstrcstr (line, task->task_pool));
                        break;
+               default:
+                       return -1;
        }
+       return -1;
 }
 
 struct metric_callback_data {
index b77ca87799bc94c9ec9ef279db1e3d820131f7de..8537a054e04159749daf429fba58bbd35608e726 100644 (file)
@@ -96,6 +96,8 @@ statfile_pool_expire (statfile_pool_t *pool)
        if (exp.filename) {
                statfile_pool_close (pool, exp.filename, TRUE);
        }
+
+       return 0;
 }
 
 statfile_pool_t* 
@@ -444,7 +446,7 @@ statfile_pool_set_section (statfile_pool_t *pool, char *filename, uint32_t code,
                cur_offset = file->seek_pos - sizeof (struct stat_file_section);
        }
        while (cur_offset < file->len) {
-               sec = (struct stat_file_section *)(file->map + cur_offset);
+               sec = (struct stat_file_section *)((char *)file->map + cur_offset);
                if (sec->code == code) {
                        file->cur_section.code = code;
                        file->cur_section.length = sec->length;
index ff08615aa5908796fb8a4d578d264bf376f515ae..c9a1875362366ec422ee7f3ba507f747889b07b9 100644 (file)
--- a/src/url.c
+++ b/src/url.c
  */
 
 #include "config.h"
-#include "url.h"
+#include "util.h"
 #include "fstring.h"
 #include "main.h"
+#include "url.h"
 
 #define POST_CHAR 1
 #define POST_CHAR_S "\001"
@@ -131,7 +132,7 @@ enum {
 /* Convert an ASCII hex digit to the corresponding number between 0
    and 15.  H should be a hexadecimal digit that satisfies isxdigit;
    otherwise, the result is undefined.  */
-#define XDIGIT_TO_NUM(h) ((h) < 'A' ? (h) - '0' : toupper (h) - 'A' + 10)
+#define XDIGIT_TO_NUM(h) ((h) < 'A' ? (h) - '0' : g_ascii_toupper (h) - 'A' + 10)
 #define X2DIGITS_TO_NUM(h1, h2) ((XDIGIT_TO_NUM (h1) << 4) + XDIGIT_TO_NUM (h2))
 /* The reverse of the above: convert a number in the [0, 16) range to
    the ASCII representation of the corresponding hexadecimal digit.
@@ -206,6 +207,7 @@ url_strerror (enum uri_errno err)
                case URI_ERRNO_INVALID_PORT_RANGE:
                        return "Port number is not within 0-65535";
        }
+       return NULL;
 }
 
 static inline int
@@ -331,7 +333,7 @@ get_protocol_length(const unsigned char *url)
        /* RFC1738:
         * scheme  = 1*[ lowalpha | digit | "+" | "-" | "." ]
         * (but per its recommendations we accept "upalpha" too) */
-       while (isalnum(*end) || *end == '+' || *end == '-' || *end == '.')
+       while (g_ascii_isalnum (*end) || *end == '+' || *end == '-' || *end == '.')
                end++;
 
        /* Also return 0 if there's no protocol name (@end == @url). */
@@ -361,7 +363,7 @@ url_unescape (char *s)
         else {
                        char c;
                        /* Do nothing if '%' is not followed by two hex digits. */
-                       if (!h[1] || !h[2] || !(isxdigit (h[1]) && isxdigit (h[2])))
+                       if (!h[1] || !h[2] || !(g_ascii_isxdigit (h[1]) && g_ascii_isxdigit (h[2])))
                                goto copychar;
                        c = X2DIGITS_TO_NUM (h[1], h[2]);
                        /* Don't unescape %00 because there is no way to insert it
@@ -452,7 +454,7 @@ static inline int
 char_needs_escaping (const char *p)
 {
        if (*p == '%') {
-               if (isxdigit (*(p + 1)) && isxdigit (*(p + 2)))
+               if (g_ascii_isxdigit (*(p + 1)) && g_ascii_isxdigit (*(p + 2)))
                        return 0;
                else
                        /* Garbled %.. sequence: encode `%'. */
@@ -663,7 +665,7 @@ parse_uri(struct uri *uri, unsigned char *uristring, memory_pool_t *pool)
                prefix_end = struri (uri) + uri->protocollen; /* ':' */
 
                /* Check if there's a digit after the protocol name. */
-               if (isdigit (*prefix_end)) {
+               if (g_ascii_isdigit (*prefix_end)) {
                        p = struri (uri);
                        uri->ip_family = p[uri->protocollen] - '0';
                        prefix_end++;
@@ -795,7 +797,7 @@ parse_uri(struct uri *uri, unsigned char *uristring, memory_pool_t *pool)
 
                /* test if port is number */
                for (; host_end < port_end; host_end++)
-                       if (!isdigit (*host_end))
+                       if (!g_ascii_isdigit (*host_end))
                                return URI_ERRNO_INVALID_PORT;
 
                /* Check valid port value, and let show an error message
index e99167d473e17299f58ac28a04f9557d7c5196e4..8c878844c4ea25e1bfbd95667fd27b26a301a4c2 100644 (file)
@@ -265,7 +265,7 @@ pass_signal_worker (struct workq *workers, int signo)
 void convert_to_lowercase (char *str, unsigned int size)
 {
        while (size--) {
-               *str = tolower (*str);
+               *str = g_ascii_tolower (*str);
                str ++;
        }
 }
@@ -629,6 +629,7 @@ open_log (struct config_file *cfg)
                        }
                        return 0;
        }
+       return -1;
 }
 
 void 
index 457395a9749468dbc941fa238489efb6656e8186..4d6c2bacc0c9b79ede0ab9eb594bd585e5637c40 100644 (file)
@@ -169,6 +169,9 @@ read_socket (f_str_t *in, void *arg)
                                write_socket (task);
                        }
                        break;
+               default:
+                       msg_debug ("read_socket: invalid state on reading stage");
+                       break;
        }
 }
 
index cd2e2dec83455dcc097b2f5d845c83dc3f034530..866ae02661e8a99bf18aa84c48e230b295ce1c99 100644 (file)
@@ -59,6 +59,8 @@ memcached_callback (memcached_ctx_t *ctx, memc_error_t error, void *data)
                        bzero (ctx->param->buf, sizeof (buf));
                        memc_get (ctx, ctx->param);
                        break;
+               default:
+                       return;
        }
 }