diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-24 18:38:11 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-24 18:38:11 +0300 |
commit | 5dbf570b7df0e7c9770432884f95c14b193b5b30 (patch) | |
tree | 547448e51751b47179c46b19b9d26f2991642b30 | |
parent | 616e4a7d03fba715185f55d1298cc09377313591 (diff) | |
download | rspamd-5dbf570b7df0e7c9770432884f95c14b193b5b30.tar.gz rspamd-5dbf570b7df0e7c9770432884f95c14b193b5b30.zip |
* Fix many compile time warnings and polish code
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | config.h.in | 9 | ||||
-rw-r--r-- | src/controller.c | 9 | ||||
-rw-r--r-- | src/expressions.c | 1 | ||||
-rw-r--r-- | src/filter.c | 2 | ||||
-rw-r--r-- | src/fstring.c | 4 | ||||
-rw-r--r-- | src/fuzzy.c | 2 | ||||
-rw-r--r-- | src/lmtp.c | 7 | ||||
-rw-r--r-- | src/lmtp_proto.c | 13 | ||||
-rw-r--r-- | src/mem_pool.c | 10 | ||||
-rw-r--r-- | src/message.c | 12 | ||||
-rw-r--r-- | src/plugins/regexp.c | 2 | ||||
-rw-r--r-- | src/plugins/surbl.c | 7 | ||||
-rw-r--r-- | src/protocol.c | 3 | ||||
-rw-r--r-- | src/statfile.c | 4 | ||||
-rw-r--r-- | src/url.c | 16 | ||||
-rw-r--r-- | src/util.c | 3 | ||||
-rw-r--r-- | src/worker.c | 3 | ||||
-rw-r--r-- | test/rspamd_memcached_test.c | 2 |
19 files changed, 76 insertions, 37 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index fad4f5d4a..4fd124d0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/config.h.in b/config.h.in index 982046338..1fc9108cb 100644 --- a/config.h.in +++ b/config.h.in @@ -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 @@ -133,6 +137,11 @@ #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> diff --git a/src/controller.c b/src/controller.c index 76caab0df..8a56b7f5b 100644 --- a/src/controller.c +++ b/src/controller.c @@ -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; } } diff --git a/src/expressions.c b/src/expressions.c index e010bce84..f222ea2b4 100644 --- a/src/expressions.c +++ b/src/expressions.c @@ -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; diff --git a/src/filter.c b/src/filter.c index 1b6cdc1b0..d273a21ff 100644 --- a/src/filter.c +++ b/src/filter.c @@ -264,6 +264,8 @@ continue_process_filters (struct worker_task *task) task->dispatcher->write_callback (task); return 1; } + + return -1; } int diff --git a/src/fstring.c b/src/fstring.c index 3098e8726..2202effaf 100644 --- a/src/fstring.c +++ b/src/fstring.c @@ -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; } diff --git a/src/fuzzy.c b/src/fuzzy.c index 4dfec3fb7..ecd1af64f 100644 --- a/src/fuzzy.c +++ b/src/fuzzy.c @@ -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; } diff --git a/src/lmtp.c b/src/lmtp.c index a8f10ee2c..d649d11c3 100644 --- a/src/lmtp.c +++ b/src/lmtp.c @@ -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; } } diff --git a/src/lmtp_proto.c b/src/lmtp_proto.c index ab20e41a8..e6e09a825 100644 --- a/src/lmtp_proto.c +++ b/src/lmtp_proto.c @@ -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) { diff --git a/src/mem_pool.c b/src/mem_pool.c index db8e3f351..84ebe9a79 100644 --- a/src/mem_pool.c +++ b/src/mem_pool.c @@ -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 diff --git a/src/message.c b/src/message.c index 64467c827..561c49457 100644 --- a/src/message.c +++ b/src/message.c @@ -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; } diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 03080c010..53c64d2b3 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -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; } diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index d92fe4a1a..0fe64ba2f 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -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); diff --git a/src/protocol.c b/src/protocol.c index 706040bc6..6230495bf 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -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 { diff --git a/src/statfile.c b/src/statfile.c index b77ca8779..8537a054e 100644 --- a/src/statfile.c +++ b/src/statfile.c @@ -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; @@ -23,9 +23,10 @@ */ #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 diff --git a/src/util.c b/src/util.c index e99167d47..8c878844c 100644 --- a/src/util.c +++ b/src/util.c @@ -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 diff --git a/src/worker.c b/src/worker.c index 457395a97..4d6c2bacc 100644 --- a/src/worker.c +++ b/src/worker.c @@ -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; } } diff --git a/test/rspamd_memcached_test.c b/test/rspamd_memcached_test.c index cd2e2dec8..866ae0266 100644 --- a/test/rspamd_memcached_test.c +++ b/test/rspamd_memcached_test.c @@ -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; } } |