]> source.dussan.org Git - rspamd.git/commitdiff
* Use rspamd_snprintf instead of libc one
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 24 Jun 2010 16:57:05 +0000 (20:57 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 24 Jun 2010 16:57:05 +0000 (20:57 +0400)
16 files changed:
src/cfg_xml.c
src/controller.c
src/filter.c
src/fuzzy_storage.c
src/lmtp.c
src/lmtp_proto.c
src/logger.c
src/map.c
src/plugins/fuzzy_check.c
src/plugins/surbl.c
src/protocol.c
src/smtp.c
src/smtp_proto.c
src/statfile_sync.c
src/upstream.c
src/util.c

index bfe71c957bd3fb0e978c8f30d49148b5d7ac8373..d2d685182cd13126d5e01f7a386ff6e80e9b6526 100644 (file)
@@ -1687,9 +1687,9 @@ xml_dump_workers (struct config_file *cfg, FILE *f)
                fprintf (f, "  <bind_socket>%s</bind_socket>" EOL, escaped_str);
                g_free (escaped_str);
 
-               fprintf (f, "  <count>%u</count>" EOL, wrk->count);
-               fprintf (f, "  <maxfiles>%u</maxfiles>" EOL, wrk->rlimit_nofile);
-               fprintf (f, "  <maxcore>%u</maxcore>" EOL, wrk->rlimit_maxcore);
+               fprintf (f, "  <count>%ud</count>" EOL, wrk->count);
+               fprintf (f, "  <maxfiles>%ud</maxfiles>" EOL, wrk->rlimit_nofile);
+               fprintf (f, "  <maxcore>%ud</maxcore>" EOL, wrk->rlimit_maxcore);
                
                /* Now dump other attrs */
                fprintf (f, "<!-- Other params -->" EOL);
@@ -1842,7 +1842,7 @@ xml_dump_logging (struct config_file *cfg, FILE *f)
        /* Other options */
        fprintf (f, " <log_urls>%s</log_urls>" EOL, cfg->log_urls ? "yes" : "no");
        if (cfg->log_buf_size != 0) {
-               fprintf (f, " <log_buffer>%u</log_buffer>" EOL, (unsigned)cfg->log_buf_size);
+               fprintf (f, " <log_buffer>%ud</log_buffer>" EOL, (unsigned)cfg->log_buf_size);
        }
        if (cfg->debug_ip_map != NULL) {
                escaped_value = g_markup_escape_text (cfg->debug_ip_map, -1);
index 2644a6d08b1709e0c1ca3640e893ee0db4327f7b..f94088e8a89ad82c593f455b8f94b1bf2236e3d7 100644 (file)
@@ -160,7 +160,7 @@ check_auth (struct controller_command *cmd, struct controller_session *session)
        int                             r;
 
        if (cmd->privilleged && !session->authorized) {
-               r = snprintf (out_buf, sizeof (out_buf), "not authorized" CRLF);
+               r = rspamd_snprintf (out_buf, sizeof (out_buf), "not authorized" CRLF);
                if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                        return 0;
                }
@@ -179,7 +179,7 @@ counter_write_callback (gpointer key, gpointer value, void *data)
        char                            out_buf[128];
        int                             r;
 
-       r = snprintf (out_buf, sizeof (out_buf), "%s: %llu" CRLF, name, (unsigned long long int)cd->value);
+       r = rspamd_snprintf (out_buf, sizeof (out_buf), "%s: %llu" CRLF, name, (unsigned long long int)cd->value);
        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, TRUE, FALSE)) {
                msg_warn ("cannot write to socket");
        }
@@ -226,7 +226,7 @@ write_whole_statfile (struct controller_session *session, char *symbol, struct c
                }
        }
 
-       i = rspamd_snprintf (out_buf, sizeof (out_buf), "%uL %uL %uL" CRLF, rev, ti, pos);
+       i = rspamd_snprintf (out_buf, sizeof (out_buf), "%udL %udL %udL" CRLF, rev, ti, pos);
        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, i, TRUE, FALSE)) {
                return FALSE;
        }
@@ -304,7 +304,7 @@ process_sync_command (struct controller_session *session, char **args)
        }
        
        while (binlog_sync (binlog, rev, &time, &data)) {
-               r = snprintf (out_buf, sizeof (out_buf), "%lu %lu %lu" CRLF, (long unsigned)rev, (long unsigned)time, (long unsigned)data->len);
+               r = rspamd_snprintf (out_buf, sizeof (out_buf), "%ul %ul %ul" CRLF, (long unsigned)rev, (long unsigned)time, (long unsigned)data->len);
                if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, TRUE, FALSE)) {
                        if (data != NULL) {
                                g_free (data);
@@ -348,25 +348,25 @@ process_stat_command (struct controller_session *session)
        GList                          *cur_cl, *cur_st;
 
        memory_pool_stat (&mem_st);
-       r = snprintf (out_buf, sizeof (out_buf), "Messages scanned: %u" CRLF, session->worker->srv->stat->messages_scanned);
+       r = rspamd_snprintf (out_buf, sizeof (out_buf), "Messages scanned: %ud" CRLF, session->worker->srv->stat->messages_scanned);
        if (session->worker->srv->stat->messages_scanned > 0) {
-               r += snprintf (out_buf + r, sizeof (out_buf) - r, "Messages treated as spam: %u, %.2f%%" CRLF, session->worker->srv->stat->messages_spam,
+               r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Messages treated as spam: %ud, %.2f%%" CRLF, session->worker->srv->stat->messages_spam,
                                                                (double)session->worker->srv->stat->messages_spam / (double)session->worker->srv->stat->messages_scanned * 100.);
-               r += snprintf (out_buf + r, sizeof (out_buf) - r, "Messages treated as ham: %u, %.2f%%" CRLF, session->worker->srv->stat->messages_ham,
+               r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Messages treated as ham: %ud, %.2f%%" CRLF, session->worker->srv->stat->messages_ham,
                                                                (double)session->worker->srv->stat->messages_ham / (double)session->worker->srv->stat->messages_scanned * 100.);
        }
-       r += snprintf (out_buf + r, sizeof (out_buf) - r, "Messages learned: %u" CRLF, session->worker->srv->stat->messages_learned);
-       r += snprintf (out_buf + r, sizeof (out_buf) - r, "Connections count: %u" CRLF, session->worker->srv->stat->connections_count);
-       r += snprintf (out_buf + r, sizeof (out_buf) - r, "Control connections count: %u" CRLF, session->worker->srv->stat->control_connections_count);
-       r += snprintf (out_buf + r, sizeof (out_buf) - r, "Pools allocated: %ld" CRLF, (long int)mem_st.pools_allocated);
-       r += snprintf (out_buf + r, sizeof (out_buf) - r, "Pools freed: %ld" CRLF, (long int)mem_st.pools_freed);
-       r += snprintf (out_buf + r, sizeof (out_buf) - r, "Bytes allocated: %ld" CRLF, (long int)mem_st.bytes_allocated);
-       r += snprintf (out_buf + r, sizeof (out_buf) - r, "Memory chunks allocated: %ld" CRLF, (long int)mem_st.chunks_allocated);
-       r += snprintf (out_buf + r, sizeof (out_buf) - r, "Shared chunks allocated: %ld" CRLF, (long int)mem_st.shared_chunks_allocated);
-       r += snprintf (out_buf + r, sizeof (out_buf) - r, "Chunks freed: %ld" CRLF, (long int)mem_st.chunks_freed);
-       r += snprintf (out_buf + r, sizeof (out_buf) - r, "Oversized chunks: %ld" CRLF, (long int)mem_st.oversized_chunks);
-       r += snprintf (out_buf + r, sizeof (out_buf) - r, "Fuzzy hashes stored: %u" CRLF, session->worker->srv->stat->fuzzy_hashes);
-       r += snprintf (out_buf + r, sizeof (out_buf) - r, "Fuzzy hashes expired: %u" CRLF, session->worker->srv->stat->fuzzy_hashes_expired);
+       r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Messages learned: %ud" CRLF, session->worker->srv->stat->messages_learned);
+       r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Connections count: %ud" CRLF, session->worker->srv->stat->connections_count);
+       r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Control connections count: %ud" CRLF, session->worker->srv->stat->control_connections_count);
+       r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Pools allocated: %l" CRLF, (long int)mem_st.pools_allocated);
+       r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Pools freed: %l" CRLF, (long int)mem_st.pools_freed);
+       r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Bytes allocated: %l" CRLF, (long int)mem_st.bytes_allocated);
+       r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Memory chunks allocated: %l" CRLF, (long int)mem_st.chunks_allocated);
+       r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Shared chunks allocated: %l" CRLF, (long int)mem_st.shared_chunks_allocated);
+       r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Chunks freed: %l" CRLF, (long int)mem_st.chunks_freed);
+       r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Oversized chunks: %l" CRLF, (long int)mem_st.oversized_chunks);
+       r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Fuzzy hashes stored: %ud" CRLF, session->worker->srv->stat->fuzzy_hashes);
+       r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Fuzzy hashes expired: %ud" CRLF, session->worker->srv->stat->fuzzy_hashes_expired);
        /* Now write statistics for each statfile */
        cur_cl = g_list_first (session->cfg->classifiers);
        while (cur_cl) {
@@ -383,8 +383,8 @@ process_stat_command (struct controller_session *session)
                                statfile_get_revision (statfile, &rev, &ti);
                                if (total != (uint64_t)-1 && used != (uint64_t)-1) {
                                        numbuf = g_format_size_for_display (st->size);
-                                       r += snprintf (out_buf + r, sizeof (out_buf) - r, 
-                                                       "Statfile: %s (version %lu); length: %s; free blocks: %lu; total blocks: %lu; free: %.2f%%" CRLF,
+                                       r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, 
+                                                       "Statfile: %s (version %ul); length: %s; free blocks: %ul; total blocks: %ul; free: %.2f%%" CRLF,
                                                        st->symbol, (long unsigned)rev, numbuf, 
                                                        (long unsigned)(total - used), (long unsigned)total,
                                                        (double)((double)(total - used) / (double)total) * 100.);
@@ -414,14 +414,14 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                arg = *cmd_args;
                if (!arg || *arg == '\0') {
                        msg_debug ("empty password passed");
-                       r = snprintf (out_buf, sizeof (out_buf), "password command requires one argument" CRLF);
+                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "password command requires one argument" CRLF);
                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                return FALSE;
                        }
                        return TRUE;
                }
                if (password == NULL) {
-                       r = snprintf (out_buf, sizeof (out_buf), "password command disabled in config, authorized access unallowed" CRLF);
+                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "password command disabled in config, authorized access unallowed" CRLF);
                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                return FALSE;
                        }
@@ -429,14 +429,14 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                }
                if (strncmp (arg, password, strlen (arg)) == 0) {
                        session->authorized = 1;
-                       r = snprintf (out_buf, sizeof (out_buf), "password accepted" CRLF);
+                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "password accepted" CRLF);
                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                return FALSE;
                        }
                }
                else {
                        session->authorized = 0;
-                       r = snprintf (out_buf, sizeof (out_buf), "password NOT accepted" CRLF);
+                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "password NOT accepted" CRLF);
                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                return FALSE;
                        }
@@ -447,7 +447,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                break;
        case COMMAND_RELOAD:
                if (check_auth (cmd, session)) {
-                       r = snprintf (out_buf, sizeof (out_buf), "reload request sent" CRLF);
+                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "reload request sent" CRLF);
                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                return FALSE;
                        }
@@ -461,7 +461,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                break;
        case COMMAND_SHUTDOWN:
                if (check_auth (cmd, session)) {
-                       r = snprintf (out_buf, sizeof (out_buf), "shutdown request sent" CRLF);
+                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "shutdown request sent" CRLF);
                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                return FALSE;
                        }
@@ -476,18 +476,18 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                                days = uptime / 86400;
                                hours = uptime / 3600 - days * 24;
                                minutes = uptime / 60 - hours * 60 - days * 1440;
-                               r = snprintf (out_buf, sizeof (out_buf), "%d day%s %d hour%s %d minute%s" CRLF, days, days > 1 ? "s" : " ", hours, hours > 1 ? "s" : " ", minutes, minutes > 1 ? "s" : " ");
+                               r = rspamd_snprintf (out_buf, sizeof (out_buf), "%d day%s %d hour%s %d minute%s" CRLF, days, days > 1 ? "s" : " ", hours, hours > 1 ? "s" : " ", minutes, minutes > 1 ? "s" : " ");
                        }
                        /* If uptime is less than 1 minute print only seconds */
                        else if (uptime / 60 == 0) {
-                               r = snprintf (out_buf, sizeof (out_buf), "%d second%s" CRLF, (int)uptime, (int)uptime > 1 ? "s" : " ");
+                               r = rspamd_snprintf (out_buf, sizeof (out_buf), "%d second%s" CRLF, (int)uptime, (int)uptime > 1 ? "s" : " ");
                        }
                        /* Else print the minutes and seconds. */
                        else {
                                hours = uptime / 3600;
                                minutes = uptime / 60 - hours * 60;
                                uptime -= hours * 3600 + minutes * 60;
-                               r = snprintf (out_buf, sizeof (out_buf), "%d hour%s %d minute%s %d second%s" CRLF, hours, hours > 1 ? "s" : " ", minutes, minutes > 1 ? "s" : " ", (int)uptime, uptime > 1 ? "s" : " ");
+                               r = rspamd_snprintf (out_buf, sizeof (out_buf), "%d hour%s %d minute%s %d second%s" CRLF, hours, hours > 1 ? "s" : " ", minutes, minutes > 1 ? "s" : " ", (int)uptime, uptime > 1 ? "s" : " ");
                        }
                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                return FALSE;
@@ -499,7 +499,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                        arg = *cmd_args;
                        if (!arg || *arg == '\0') {
                                msg_debug ("no statfile specified in learn command");
-                               r = snprintf (out_buf, sizeof (out_buf), "learn command requires at least two arguments: stat filename and its size" CRLF);
+                               r = rspamd_snprintf (out_buf, sizeof (out_buf), "learn command requires at least two arguments: stat filename and its size" CRLF);
                                if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                        return FALSE;
                                }
@@ -508,7 +508,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                        arg = *(cmd_args + 1);
                        if (arg == NULL || *arg == '\0') {
                                msg_debug ("no statfile size specified in learn command");
-                               r = snprintf (out_buf, sizeof (out_buf), "learn command requires at least two arguments: stat filename and its size" CRLF);
+                               r = rspamd_snprintf (out_buf, sizeof (out_buf), "learn command requires at least two arguments: stat filename and its size" CRLF);
                                if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                        return FALSE;
                                }
@@ -517,7 +517,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                        size = strtoul (arg, &err_str, 10);
                        if (err_str && *err_str != '\0') {
                                msg_debug ("message size is invalid: %s", arg);
-                               r = snprintf (out_buf, sizeof (out_buf), "learn size is invalid" CRLF);
+                               r = rspamd_snprintf (out_buf, sizeof (out_buf), "learn size is invalid" CRLF);
                                if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                        return FALSE;
                                }
@@ -527,7 +527,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                        session->learn_symbol = memory_pool_strdup (session->session_pool, *cmd_args);
                        cl = g_hash_table_lookup (session->cfg->classifiers_symbols, *cmd_args);
                        if (cl == NULL) {
-                               r = snprintf (out_buf, sizeof (out_buf), "statfile %s is not defined" CRLF, *cmd_args);
+                               r = rspamd_snprintf (out_buf, sizeof (out_buf), "statfile %s is not defined" CRLF, *cmd_args);
                                if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                        return FALSE;
                                }
@@ -547,7 +547,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);
+                                                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "recipient is not defined" CRLF);
                                                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                                                return FALSE;
                                                        }
@@ -557,7 +557,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);
+                                                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "from is not defined" CRLF);
                                                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                                                return FALSE;
                                                        }
@@ -570,7 +570,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                                        case 'm':
                                                arg = *(cmd_args + 1);
                                                if (!arg || *arg == '\0') {
-                                                       r = snprintf (out_buf, sizeof (out_buf), "multiplier is not defined" CRLF);
+                                                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "multiplier is not defined" CRLF);
                                                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                                                return FALSE;
                                                        }
@@ -578,7 +578,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                                                session->learn_multiplier = strtod (arg, NULL);
                                                break;
                                        default:
-                                               r = snprintf (out_buf, sizeof (out_buf), "tokenizer is not defined" CRLF);
+                                               r = rspamd_snprintf (out_buf, sizeof (out_buf), "tokenizer is not defined" CRLF);
                                                if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                                        return FALSE;
                                                }
@@ -595,7 +595,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                arg = *cmd_args;
                if (!arg || *arg == '\0') {
                        msg_debug ("no statfile specified in weights command");
-                       r = snprintf (out_buf, sizeof (out_buf), "weights command requires two arguments: statfile and message size" CRLF);
+                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "weights command requires two arguments: statfile and message size" CRLF);
                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                return FALSE;
                        }
@@ -604,7 +604,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                arg = *(cmd_args + 1);
                if (arg == NULL || *arg == '\0') {
                        msg_debug ("no message size specified in weights command");
-                       r = snprintf (out_buf, sizeof (out_buf), "weights command requires two arguments: statfile and message size" CRLF);
+                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "weights command requires two arguments: statfile and message size" CRLF);
                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                return FALSE;
                        }
@@ -613,7 +613,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                size = strtoul (arg, &err_str, 10);
                if (err_str && *err_str != '\0') {
                        msg_debug ("message size is invalid: %s", arg);
-                       r = snprintf (out_buf, sizeof (out_buf), "message size is invalid" CRLF);
+                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "message size is invalid" CRLF);
                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                return FALSE;
                        }
@@ -622,7 +622,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
 
                cl = g_hash_table_lookup (session->cfg->classifiers_symbols, *cmd_args);
                if (cl == NULL) {
-                       r = snprintf (out_buf, sizeof (out_buf), "statfile %s is not defined" CRLF, *cmd_args);
+                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "statfile %s is not defined" CRLF, *cmd_args);
                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                return FALSE;
                        }
@@ -636,7 +636,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                break;
        case COMMAND_SYNC:
                if (!process_sync_command (session, cmd_args)) {
-                       r = snprintf (out_buf, sizeof (out_buf), "FAIL" CRLF);
+                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "FAIL" CRLF);
                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                return FALSE;
                        }
@@ -644,7 +644,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
                }
                break;
        case COMMAND_HELP:
-               r = snprintf (out_buf, sizeof (out_buf),
+               r = rspamd_snprintf (out_buf, sizeof (out_buf),
                        "Rspamd CLI commands (* - privileged command):" CRLF
                        "    help - this help message" CRLF
                        "(*) learn <statfile> <size> [-r recipient] [-m multiplier] [-f from] [-n] - learn message to specified statfile" CRLF
@@ -722,7 +722,7 @@ controller_read_socket (f_str_t * in, void *arg)
                        case 0:
                                if (!process_custom_command (cmd, &params[1], session)) {
                                        msg_debug ("'%s'", cmd);
-                                       i = snprintf (out_buf, sizeof (out_buf), "Unknown command" CRLF);
+                                       i = rspamd_snprintf (out_buf, sizeof (out_buf), "Unknown command" CRLF);
                                        if (!rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) {
                                                return FALSE;
                                        }
@@ -730,7 +730,7 @@ controller_read_socket (f_str_t * in, void *arg)
                                break;
                        default:
                                msg_debug ("'%s'", cmd);
-                               i = snprintf (out_buf, sizeof (out_buf), "Ambigious command" CRLF);
+                               i = rspamd_snprintf (out_buf, sizeof (out_buf), "Ambigious command" CRLF);
                                if (!rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) {
                                        return FALSE;
                                }
@@ -760,7 +760,7 @@ controller_read_socket (f_str_t * in, void *arg)
                        msg_warn ("processing of message failed");
                        free_task (task, FALSE);
                        session->state = STATE_REPLY;
-                       r = snprintf (out_buf, sizeof (out_buf), "cannot process message" CRLF);
+                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "cannot process message" CRLF);
                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                return FALSE;
                        }
@@ -790,7 +790,7 @@ controller_read_socket (f_str_t * in, void *arg)
                                c.len = part->content->len;
                        }
                        if (!session->learn_classifier->tokenizer->tokenize_func (session->learn_classifier->tokenizer, session->session_pool, &c, &tokens)) {
-                               i = snprintf (out_buf, sizeof (out_buf), "learn fail, tokenizer error" CRLF);
+                               i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn fail, tokenizer error" CRLF);
                                free_task (task, FALSE);
                                if (!rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) {
                                        return FALSE;
@@ -803,7 +803,7 @@ controller_read_socket (f_str_t * in, void *arg)
                
                /* Handle messages without text */
                if (tokens == NULL) {
-                       i = snprintf (out_buf, sizeof (out_buf), "learn fail, no tokens can be extracted (no text data)" CRLF);
+                       i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn fail, no tokens can be extracted (no text data)" CRLF);
                        free_task (task, FALSE);
                        if (!rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) {
                                return FALSE;
@@ -817,7 +817,7 @@ controller_read_socket (f_str_t * in, void *arg)
                                                session->learn_symbol, &st, TRUE);
                if (statfile == NULL) {
                        free_task (task, FALSE);
-                       i = snprintf (out_buf, sizeof (out_buf), "learn failed" CRLF);
+                       i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn failed" CRLF);
                        if (!rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) {
                                return FALSE;
                        }
@@ -839,7 +839,7 @@ controller_read_socket (f_str_t * in, void *arg)
                }
                
                free_task (task, FALSE);
-               i = snprintf (out_buf, sizeof (out_buf), "learn ok, sum weight: %.2f" CRLF, sum);
+               i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn ok, sum weight: %.2f" CRLF, sum);
                if (!rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) {
                        return FALSE;
                }
@@ -859,7 +859,7 @@ controller_read_socket (f_str_t * in, void *arg)
                        msg_warn ("processing of message failed");
                        free_task (task, FALSE);
                        session->state = STATE_REPLY;
-                       r = snprintf (out_buf, sizeof (out_buf), "cannot process message" CRLF);
+                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "cannot process message" CRLF);
                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                return FALSE;
                        }
@@ -877,7 +877,7 @@ controller_read_socket (f_str_t * in, void *arg)
                        c.begin = part->content->data;
                        c.len = part->content->len;
                        if (!session->learn_classifier->tokenizer->tokenize_func (session->learn_classifier->tokenizer, session->session_pool, &c, &tokens)) {
-                               i = snprintf (out_buf, sizeof (out_buf), "weights fail, tokenizer error" CRLF);
+                               i = rspamd_snprintf (out_buf, sizeof (out_buf), "weights fail, tokenizer error" CRLF);
                                free_task (task, FALSE);
                                if (!rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) {
                                        return FALSE;
@@ -890,7 +890,7 @@ controller_read_socket (f_str_t * in, void *arg)
                
                /* Handle messages without text */
                if (tokens == NULL) {
-                       i = snprintf (out_buf, sizeof (out_buf), "weights fail, no tokens can be extracted (no text data)" CRLF);
+                       i = rspamd_snprintf (out_buf, sizeof (out_buf), "weights fail, no tokens can be extracted (no text data)" CRLF);
                        free_task (task, FALSE);
                        if (!rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) {
                                return FALSE;
@@ -910,7 +910,7 @@ controller_read_socket (f_str_t * in, void *arg)
 
                while (cur) {
                        w = cur->data;
-                       i += snprintf (out_buf + i, sizeof (out_buf) - i, "%s: %.2Lg" CRLF, w->name, w->weight);
+                       i += rspamd_snprintf (out_buf + i, sizeof (out_buf) - i, "%s: %.2Lg" CRLF, w->name, w->weight);
                        cur = g_list_next (cur);
                }
                if (!rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) {
@@ -1053,7 +1053,7 @@ start_controller (struct rspamd_worker *worker)
        hostbuf = alloca (hostmax);
        gethostname (hostbuf, hostmax);
        hostbuf[hostmax - 1] = '\0';
-       snprintf (greetingbuf, sizeof (greetingbuf), "Rspamd version %s is running on %s" CRLF, RVERSION, hostbuf);
+       rspamd_snprintf (greetingbuf, sizeof (greetingbuf), "Rspamd version %s is running on %s" CRLF, RVERSION, hostbuf);
        /* Accept event */
        event_set (&worker->bind_ev, worker->cf->listen_sock, EV_READ | EV_PERSIST, accept_socket, (void *)worker);
        event_add (&worker->bind_ev, NULL);
index b2c4b7ab567880f5b061918ab2ec75ea9f7e16b2..d91ef9a254fd09cdad9e8963ebed6881c8fc44e9 100644 (file)
@@ -580,26 +580,26 @@ insert_metric_header (gpointer metric_name, gpointer metric_value, gpointer data
        struct metric_result           *metric_res = (struct metric_result *)metric_value;
        double                          ms, rs;
 
-       snprintf (header_name, sizeof (header_name), "X-Spam-%s", metric_res->metric->name);
+       rspamd_snprintf (header_name, sizeof (header_name), "X-Spam-%s", metric_res->metric->name);
 
        if (!check_metric_settings (task, metric_res->metric, &ms, &rs)) {
                ms = metric_res->metric->required_score;
        }
        if (metric_res->score >= ms) {
-               r += snprintf (outbuf + r, sizeof (outbuf) - r, "yes; %.2f/%.2f/%.2f; ", metric_res->score, ms, rs);
+               r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "yes; %.2f/%.2f/%.2f; ", metric_res->score, ms, rs);
        }
        else {
-               r += snprintf (outbuf + r, sizeof (outbuf) - r, "no; %.2f/%.2f/%.2f; ", metric_res->score, ms, rs);
+               r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "no; %.2f/%.2f/%.2f; ", metric_res->score, ms, rs);
        }
 
        symbols = g_hash_table_get_keys (metric_res->symbols);
        cur = symbols;
        while (cur) {
                if (g_list_next (cur) != NULL) {
-                       r += snprintf (outbuf + r, sizeof (outbuf) - r, "%s,", (char *)cur->data);
+                       r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "%s,", (char *)cur->data);
                }
                else {
-                       r += snprintf (outbuf + r, sizeof (outbuf) - r, "%s", (char *)cur->data);
+                       r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "%s", (char *)cur->data);
                }
                cur = g_list_next (cur);
        }
index 843fe8f094b104bff3b65b793e959aa8a59cd574..7db272c11d407b8aafaed3c9b42654ffd2b12cf6 100644 (file)
@@ -632,7 +632,7 @@ process_fuzzy_command (struct fuzzy_session *session)
        switch (session->cmd.cmd) {
        case FUZZY_CHECK:
                if ((r = process_check_command (&session->cmd, &flag))) {
-                       r = snprintf (buf, sizeof (buf), "OK %d %d" CRLF, r, flag);
+                       r = rspamd_snprintf (buf, sizeof (buf), "OK %d %d" CRLF, r, flag);
                        if (sendto (session->fd, buf, r, 0, (struct sockaddr *)&session->sa, session->salen) == -1) {
                                msg_err ("error while writing reply: %s", strerror (errno));
                        }
index 47962ce93ec6265c708a3a54f9be089a75210ebe..7ba43d6cb79c7dd60b913530aaf42bf88f49f257 100644 (file)
@@ -301,7 +301,7 @@ start_lmtp_worker (struct rspamd_worker *worker)
        hostbuf = alloca (hostmax);
        gethostname (hostbuf, hostmax);
        hostbuf[hostmax - 1] = '\0';
-       snprintf (greetingbuf, sizeof (greetingbuf), "%d rspamd version %s LMTP on %s Ready\r\n", LMTP_OK, RVERSION, hostbuf);
+       rspamd_snprintf (greetingbuf, sizeof (greetingbuf), "%d rspamd version %s LMTP on %s Ready\r\n", LMTP_OK, RVERSION, hostbuf);
 
        io_tv.tv_sec = WORKER_IO_TIMEOUT;
        io_tv.tv_usec = 0;
index c9a58a64177db36e894452780895a984d6f86861..1bf56f6775a9b9e5f586142e2a80254eb2cf87ea 100644 (file)
@@ -95,10 +95,10 @@ out_lmtp_reply (struct worker_task *task, int code, char *rcode, char *msg)
        int                             r;
 
        if (*rcode == '\0') {
-               r = snprintf (outbuf, OUTBUFSIZ, "%d %s\r\n", code, msg);
+               r = rspamd_snprintf (outbuf, OUTBUFSIZ, "%d %s\r\n", code, msg);
        }
        else {
-               r = snprintf (outbuf, OUTBUFSIZ, "%d %s %s\r\n", code, rcode, msg);
+               r = rspamd_snprintf (outbuf, OUTBUFSIZ, "%d %s %s\r\n", code, rcode, msg);
        }
        if (! rspamd_dispatcher_write (task->dispatcher, outbuf, r, FALSE, FALSE)) {
                return FALSE;
@@ -347,10 +347,10 @@ mta_read_socket (f_str_t * in, void *arg)
                gethostname (hostbuf, hostmax);
                hostbuf[hostmax - 1] = '\0';
                if (cd->task->cfg->deliver_lmtp) {
-                       r = snprintf (outbuf, sizeof (outbuf), "LHLO %s" CRLF, hostbuf);
+                       r = rspamd_snprintf (outbuf, sizeof (outbuf), "LHLO %s" CRLF, hostbuf);
                }
                else {
-                       r = snprintf (outbuf, sizeof (outbuf), "HELO %s" CRLF, hostbuf);
+                       r = rspamd_snprintf (outbuf, sizeof (outbuf), "HELO %s" CRLF, hostbuf);
                }
                if (! rspamd_dispatcher_write (cd->task->dispatcher, outbuf, r, FALSE, FALSE)) {
                        return FALSE;
@@ -363,7 +363,7 @@ mta_read_socket (f_str_t * in, void *arg)
                        close_mta_connection (cd, FALSE);
                        return FALSE;
                }
-               r = snprintf (outbuf, sizeof (outbuf), "MAIL FROM: <%s>" CRLF, cd->task->from);
+               r = rspamd_snprintf (outbuf, sizeof (outbuf), "MAIL FROM: <%s>" CRLF, cd->task->from);
                if (! rspamd_dispatcher_write (cd->task->dispatcher, outbuf, r, FALSE, FALSE)) {
                        return FALSE;
                }
@@ -378,7 +378,7 @@ mta_read_socket (f_str_t * in, void *arg)
                cur = g_list_first (cd->task->rcpt);
                r = 0;
                while (cur) {
-                       r += snprintf (outbuf + r, sizeof (outbuf) - r, "RCPT TO: <%s>" CRLF, (char *)cur->data);
+                       r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "RCPT TO: <%s>" CRLF, (char *)cur->data);
                        cur = g_list_next (cur);
                }
 
@@ -393,7 +393,7 @@ mta_read_socket (f_str_t * in, void *arg)
                        close_mta_connection (cd, FALSE);
                        return FALSE;
                }
-               r = snprintf (outbuf, sizeof (outbuf), "DATA" CRLF);
+               r = rspamd_snprintf (outbuf, sizeof (outbuf), "DATA" CRLF);
                if (! rspamd_dispatcher_write (cd->task->dispatcher, outbuf, r, FALSE, FALSE)) {
                        return FALSE;
                }
@@ -411,7 +411,7 @@ mta_read_socket (f_str_t * in, void *arg)
                        return FALSE;
                }
                memory_pool_add_destructor (cd->task->task_pool, (pool_destruct_func) g_free, c);
-               r = snprintf (outbuf, sizeof (outbuf), CRLF "." CRLF);
+               r = rspamd_snprintf (outbuf, sizeof (outbuf), CRLF "." CRLF);
                if (! rspamd_dispatcher_write (cd->task->dispatcher, outbuf, r, FALSE, FALSE)) {
                        return FALSE;
                }
index 722bcad72137885b8b20b64ae3b2f7109fd1a8a5..25839d02640012c6d56337aa47f7cd264502da9f 100644 (file)
@@ -172,7 +172,7 @@ close_log (void)
        case RSPAMD_LOG_FILE:
                if (rspamd_log->enabled) {
                        if (rspamd_log->repeats > REPEATS_MIN) {
-                               snprintf (tmpbuf, sizeof (tmpbuf), "Last message repeated %u times", rspamd_log->repeats);
+                               snprintf (tmpbuf, sizeof (tmpbuf), "Last message repeated %ud times", rspamd_log->repeats);
                                rspamd_log->repeats = 0;
                                if (rspamd_log->saved_message) {
                                        file_log_function (NULL, rspamd_log->saved_function, rspamd_log->cfg->log_level, rspamd_log->saved_message, TRUE, NULL);
@@ -448,7 +448,7 @@ file_log_function (const gchar * log_domain, const gchar *function, GLogLevelFla
                                return;
                        }
                        else if (rspamd_log->repeats > REPEATS_MAX) {
-                               snprintf (tmpbuf, sizeof (tmpbuf), "Last message repeated %u times", rspamd_log->repeats);
+                               rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "Last message repeated %ud times", rspamd_log->repeats);
                                rspamd_log->repeats = 0;
                                /* It is safe to use temporary buffer here as it is not static */
                                if (rspamd_log->saved_message) {
@@ -463,7 +463,7 @@ file_log_function (const gchar * log_domain, const gchar *function, GLogLevelFla
                else {
                        rspamd_log->last_line_cksum = cksum;
                        if (rspamd_log->repeats > REPEATS_MIN) {
-                               snprintf (tmpbuf, sizeof (tmpbuf), "Last message repeated %u times", rspamd_log->repeats);
+                               rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "Last message repeated %ud times", rspamd_log->repeats);
                                rspamd_log->repeats = 0;
                                if (rspamd_log->saved_message) {
                                        file_log_function (log_domain, rspamd_log->saved_function, log_level, rspamd_log->saved_message, forced, arg);
index bb3d049370fa480d27b05a7717612f700e5f8f48..d6e57715a46ca6999d27be036b6b9120a00cd789 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -82,12 +82,12 @@ write_http_request (struct rspamd_map *map, struct http_map_data *data, int sock
        char                            outbuf[BUFSIZ];
        int                             r;
 
-       r = snprintf (outbuf, sizeof (outbuf), "GET %s%s HTTP/1.1" CRLF "Connection: close" CRLF "Host: %s" CRLF, (*data->path == '/') ? "" : "/", data->path, data->host);
+       r = rspamd_snprintf (outbuf, sizeof (outbuf), "GET %s%s HTTP/1.1" CRLF "Connection: close" CRLF "Host: %s" CRLF, (*data->path == '/') ? "" : "/", data->path, data->host);
        if (data->last_checked != 0) {
-               r += snprintf (outbuf + r, sizeof (outbuf) - r, "If-Modified-Since: %s" CRLF, asctime (gmtime (&data->last_checked)));
+               r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "If-Modified-Since: %s" CRLF, asctime (gmtime (&data->last_checked)));
        }
 
-       r += snprintf (outbuf + r, sizeof (outbuf) - r, CRLF);
+       r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, CRLF);
 
        if (write (sock, outbuf, r) == -1) {
                msg_err ("failed to write request: %d, %s", errno, strerror (errno));
@@ -239,7 +239,7 @@ read_http_chunked (u_char * buf, size_t len, struct rspamd_map *map, struct http
                                return TRUE;
                        }
                        else {
-                               msg_info ("invalid chunked reply: %*s", len, buf);
+                               msg_info ("invalid chunked reply: %*s", (int)len, buf);
                                return FALSE;
                        }
                }
index 198cf08e4ad593ffb15335e0ed4639742486e040..da301ddca010cb7103694f1d0d7d87d1238dc930 100644 (file)
@@ -383,7 +383,7 @@ fuzzy_io_callback (int fd, short what, void *arg)
                                nval = fuzzy_normalize (value, map->weight);
                        }
 
-                       snprintf (buf, sizeof (buf), "%d: %d / %.2f", flag, value, nval);
+                       rspamd_snprintf (buf, sizeof (buf), "%d: %d / %.2f", flag, value, nval);
                        insert_result (session->task, symbol, nval, g_list_prepend (NULL, 
                                                memory_pool_strdup (session->task->task_pool, buf)));
                }
@@ -445,14 +445,14 @@ fuzzy_learn_callback (int fd, short what, void *arg)
                        goto err;
                }
                else if (buf[0] == 'O' && buf[1] == 'K') {
-                       r = snprintf (buf, sizeof (buf), "OK" CRLF);
+                       r = rspamd_snprintf (buf, sizeof (buf), "OK" CRLF);
                        if (! rspamd_dispatcher_write (session->session->dispatcher, buf, r, FALSE, FALSE)) {
                                return;
                        }
                        goto ok;
                }
                else {
-                       r = snprintf (buf, sizeof (buf), "ERR" CRLF);
+                       r = rspamd_snprintf (buf, sizeof (buf), "ERR" CRLF);
                        if (! rspamd_dispatcher_write (session->session->dispatcher, buf, r, FALSE, FALSE)) {
                                return;
                        }
@@ -468,7 +468,7 @@ fuzzy_learn_callback (int fd, short what, void *arg)
 
   err:
        msg_err ("got error in IO with server %s:%d, %d, %s", session->server->name, session->server->port, errno, strerror (errno));
-       r = snprintf (buf, sizeof (buf), "Error" CRLF);
+       r = rspamd_snprintf (buf, sizeof (buf), "Error" CRLF);
        if (! rspamd_dispatcher_write (session->session->dispatcher, buf, r, FALSE, FALSE)) {
                return;
        }
@@ -581,7 +581,7 @@ fuzzy_process_handler (struct controller_session *session, f_str_t * in)
                msg_warn ("processing of message failed");
                free_task (task, FALSE);
                session->state = STATE_REPLY;
-               r = snprintf (out_buf, sizeof (out_buf), "cannot process message" CRLF);
+               r = rspamd_snprintf (out_buf, sizeof (out_buf), "cannot process message" CRLF);
                if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                        msg_warn ("write error");
                }
@@ -612,7 +612,7 @@ fuzzy_process_handler (struct controller_session *session, f_str_t * in)
                                if ((sock = make_udp_socket (&selected->addr, selected->port, FALSE, TRUE)) == -1) {
                                        msg_warn ("cannot connect to %s, %d, %s", selected->name, errno, strerror (errno));
                                        session->state = STATE_REPLY;
-                                       r = snprintf (out_buf, sizeof (out_buf), "no hashes written" CRLF);
+                                       r = rspamd_snprintf (out_buf, sizeof (out_buf), "no hashes written" CRLF);
                                        if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                                return;
                                        }
@@ -643,7 +643,7 @@ fuzzy_process_handler (struct controller_session *session, f_str_t * in)
                        else {
                                /* Cannot write hash */
                                session->state = STATE_REPLY;
-                               r = snprintf (out_buf, sizeof (out_buf), "cannot write fuzzy hash" CRLF);
+                               r = rspamd_snprintf (out_buf, sizeof (out_buf), "cannot write fuzzy hash" CRLF);
                                if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                                        return;
                                }
@@ -657,7 +657,7 @@ fuzzy_process_handler (struct controller_session *session, f_str_t * in)
        free_task (task, FALSE);
        if (*saved == 0) {
                session->state = STATE_REPLY;
-               r = snprintf (out_buf, sizeof (out_buf), "no hashes written" CRLF);
+               r = rspamd_snprintf (out_buf, sizeof (out_buf), "no hashes written" CRLF);
                if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                        return;
                }
@@ -675,7 +675,7 @@ fuzzy_controller_handler (char **args, struct controller_session *session, int c
        arg = args[0];
        if (!arg || *arg == '\0') {
                msg_info ("empty content length");
-               r = snprintf (out_buf, sizeof (out_buf), "fuzzy command requires length as argument" CRLF);
+               r = rspamd_snprintf (out_buf, sizeof (out_buf), "fuzzy command requires length as argument" CRLF);
                if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                        return;
                }
@@ -685,7 +685,7 @@ fuzzy_controller_handler (char **args, struct controller_session *session, int c
        errno = 0;
        size = strtoul (arg, &err_str, 10);
        if (errno != 0 || (err_str && *err_str != '\0')) {
-               r = snprintf (out_buf, sizeof (out_buf), "learn size is invalid" CRLF);
+               r = rspamd_snprintf (out_buf, sizeof (out_buf), "learn size is invalid" CRLF);
                if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
                        return;
                }
index 699bd79d18f407a786cef83495f2d352c50e020f..90f2bc5fefd8fc6640f00ffe2f61f46a6d376ec2 100644 (file)
@@ -322,7 +322,7 @@ format_surbl_request (memory_pool_t * pool, f_str_t * hostname, struct suffix_it
        if (is_numeric && dots_num == 3) {
                /* This is ip address */
                result = memory_pool_alloc (pool, len);
-               r = snprintf (result, len, "%*s.%*s.%*s.%*s", 
+               r = rspamd_snprintf (result, len, "%*s.%*s.%*s.%*s", 
                                (int)(hostname->len - (dots[2] - hostname->begin + 1)),
                                dots[2] + 1,
                                (int)(dots[2] - dots[1] - 1),
@@ -350,7 +350,7 @@ format_surbl_request (memory_pool_t * pool, f_str_t * hostname, struct suffix_it
                /* Hack for bugged windows resolver */
                ip_num &= 0xFFFFFFFF;
                /* Get octets */
-               r = snprintf (result, len, "%u.%u.%u.%u",
+               r = rspamd_snprintf (result, len, "%u.%u.%u.%u",
                        (uint32_t) ip_num & 0x000000FF, (uint32_t) (ip_num & 0x0000FF00) >> 8, (uint32_t) (ip_num & 0x00FF0000) >> 16, (uint32_t) (ip_num & 0xFF000000) >> 24);
        }
        else {
@@ -370,21 +370,21 @@ format_surbl_request (memory_pool_t * pool, f_str_t * hostname, struct suffix_it
                }
                if (level != MAX_LEVELS) {
                        if (level == 0) {
-                               r = snprintf (result, len, "%*s", (int)hostname->len, hostname->begin);
+                               r = rspamd_snprintf (result, len, "%*s", (int)hostname->len, hostname->begin);
                        }
                        else {
-                               r = snprintf (result, len, "%*s", 
+                               r = rspamd_snprintf (result, len, "%*s", 
                                        (int)(hostname->len - (dots[level - 1] - hostname->begin + 1)),
                                        dots[level - 1] + 1);
                        }
                }
                else if (dots_num >= 2) {
-                       r = snprintf (result, len, "%*s",
+                       r = rspamd_snprintf (result, len, "%*s",
                                        (int)(hostname->len - (dots[dots_num - 2] - hostname->begin + 1)),
                                        dots[dots_num - 2] + 1);
                }
                else {
-                       r = snprintf (result, len, "%*s", (int)hostname->len, hostname->begin);
+                       r = rspamd_snprintf (result, len, "%*s", (int)hostname->len, hostname->begin);
                }
        }
 
@@ -399,7 +399,7 @@ format_surbl_request (memory_pool_t * pool, f_str_t * hostname, struct suffix_it
 
 
        if (append_suffix) {
-               r += snprintf (result + r, len - r, ".%s", suffix->suffix);
+               r += rspamd_snprintf (result + r, len - r, ".%s", suffix->suffix);
        }
 
        msg_debug ("request: %s, dots: %d, level: %d, orig: %*s", result, dots_num, level, (int)hostname->len, hostname->begin);
@@ -469,7 +469,7 @@ process_dns_results (struct worker_task *task, struct suffix_item *suffix, char
                                len = strlen (suffix->symbol) - 2 + strlen (bit->symbol) + 1;
                                *c = '\0';
                                symbol = memory_pool_alloc (task->task_pool, len);
-                               snprintf (symbol, len, "%s%s%s", suffix->symbol, bit->symbol, c + 2);
+                               rspamd_snprintf (symbol, len, "%s%s%s", suffix->symbol, bit->symbol, c + 2);
                                *c = '%';
                                insert_result (task, symbol, 1, g_list_prepend (NULL, memory_pool_strdup (task->task_pool, url)));
                                found = 1;
@@ -665,7 +665,7 @@ redirector_callback (int fd, short what, void *arg)
                        event_del (&param->ev);
                        event_set (&param->ev, param->sock, EV_READ | EV_PERSIST, redirector_callback, (void *)param);
                        event_add (&param->ev, timeout);
-                       r = snprintf (url_buf, sizeof (url_buf), "GET %s HTTP/1.0\r\n\r\n", struri (param->url));
+                       r = rspamd_snprintf (url_buf, sizeof (url_buf), "GET %s HTTP/1.0\r\n\r\n", struri (param->url));
                        if (write (param->sock, url_buf, r) == -1) {
                                msg_err ("write failed %s", strerror (errno));
                                remove_normal_event (param->task->s, free_redirector_session, param);
@@ -839,9 +839,9 @@ urls_command_handler (struct worker_task *task)
 
        outbuf = memory_pool_alloc (task->task_pool, buflen * sizeof (char));
 
-       r = snprintf (outbuf, buflen, "%s 0 %s" CRLF, (task->proto == SPAMC_PROTO) ? SPAMD_REPLY_BANNER : RSPAMD_REPLY_BANNER, "OK");
+       r = rspamd_snprintf (outbuf, buflen, "%s 0 %s" CRLF, (task->proto == SPAMC_PROTO) ? SPAMD_REPLY_BANNER : RSPAMD_REPLY_BANNER, "OK");
 
-       r += snprintf (outbuf + r, buflen - r - 2, "URLs: ");
+       r += rspamd_snprintf (outbuf + r, buflen - r - 2, "URLs: ");
 
        cur = g_list_first (task->urls);
 
@@ -854,10 +854,10 @@ urls_command_handler (struct worker_task *task)
                        f.len = url->hostlen;
                        if ((urlstr = format_surbl_request (task->task_pool, &f, NULL, FALSE, &err)) != NULL) {
                                if (g_list_next (cur) != NULL) {
-                                       r += snprintf (outbuf + r, buflen - r - 2, "%s <\"%s\">, ", (char *)urlstr, struri (url));
+                                       r += rspamd_snprintf (outbuf + r, buflen - r - 2, "%s <\"%s\">, ", (char *)urlstr, struri (url));
                                }
                                else {
-                                       r += snprintf (outbuf + r, buflen - r - 2, "%s <\"%s\">", (char *)urlstr, struri (url));
+                                       r += rspamd_snprintf (outbuf + r, buflen - r - 2, "%s <\"%s\">", (char *)urlstr, struri (url));
                                }
                        }
                }
index 7f2907f86310bf14a3d032d3238c8ed50abc4d0c..276b63a9eaa1560397e8e1543ae4e7b9755fb7bc 100644 (file)
@@ -429,10 +429,10 @@ write_hashes_to_log (struct worker_task *task, char *logbuf, int offset, int siz
                text_part = cur->data;
                if (text_part->fuzzy) {
                        if (cur->next != NULL) {
-                               offset += snprintf (logbuf + offset, size - offset, " part: %Xd,", text_part->fuzzy->h);
+                               offset += rspamd_snprintf (logbuf + offset, size - offset, " part: %Xd,", text_part->fuzzy->h);
                        }
                        else {
-                               offset += snprintf (logbuf + offset, size - offset, " part: %Xd", text_part->fuzzy->h);
+                               offset += rspamd_snprintf (logbuf + offset, size - offset, " part: %Xd", text_part->fuzzy->h);
                        }
                }
                cur = g_list_next (cur);
@@ -448,7 +448,7 @@ show_url_header (struct worker_task *task)
        GList                          *cur;
        f_str_t                         host;
 
-       r = snprintf (outbuf, sizeof (outbuf), "Urls: ");
+       r = rspamd_snprintf (outbuf, sizeof (outbuf), "Urls: ");
        cur = task->urls;
        while (cur) {
                url = cur->data;
@@ -478,14 +478,14 @@ show_url_header (struct worker_task *task)
                        c = *(host.begin + host.len);
                        *(host.begin + host.len) = '\0';
                        debug_task ("write url: %s", host.begin);
-                       r += snprintf (outbuf + r, sizeof (outbuf) - r, "%s, ", host.begin);
+                       r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "%s, ", host.begin);
                        *(host.begin + host.len) = c;
                }
                else {
                        c = *(host.begin + host.len);
                        *(host.begin + host.len) = '\0';
                        debug_task ("write url: %s", host.begin);
-                       r += snprintf (outbuf + r, sizeof (outbuf) - r, "%s" CRLF, host.begin);
+                       r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "%s" CRLF, host.begin);
                        *(host.begin + host.len) = c;
                }
                cur = g_list_next (cur);
@@ -508,14 +508,14 @@ metric_symbols_callback (gpointer key, gpointer value, void *user_data)
        }
 
        if (s->options) {
-               r = snprintf (outbuf, OUTBUFSIZ, "Symbol: %s; ", (char *)key);
+               r = rspamd_snprintf (outbuf, OUTBUFSIZ, "Symbol: %s; ", (char *)key);
                cur = s->options;
                while (cur) {
                        if (g_list_next (cur)) {
-                               r += snprintf (outbuf + r, OUTBUFSIZ - r, "%s,", (char *)cur->data);
+                               r += rspamd_snprintf (outbuf + r, OUTBUFSIZ - r, "%s,", (char *)cur->data);
                        }
                        else {
-                               r += snprintf (outbuf + r, OUTBUFSIZ - r, "%s" CRLF, (char *)cur->data);
+                               r += rspamd_snprintf (outbuf + r, OUTBUFSIZ - r, "%s" CRLF, (char *)cur->data);
                        }
                        cur = g_list_next (cur);
                }
@@ -526,9 +526,9 @@ metric_symbols_callback (gpointer key, gpointer value, void *user_data)
                }
        }
        else {
-               r = snprintf (outbuf, OUTBUFSIZ, "Symbol: %s" CRLF, (char *)key);
+               r = rspamd_snprintf (outbuf, OUTBUFSIZ, "Symbol: %s" CRLF, (char *)key);
        }
-       cd->log_offset += snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "%s,", (char *)key);
+       cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "%s,", (char *)key);
 
        if (! rspamd_dispatcher_write (task->dispatcher, outbuf, r, FALSE, FALSE)) {
                cd->alive = FALSE;
@@ -547,10 +547,10 @@ show_metric_symbols (struct metric_result *metric_res, struct metric_callback_da
                cur = symbols;
                while (cur) {
                        if (g_list_next (cur) != NULL) {
-                               r += snprintf (outbuf + r, sizeof (outbuf) - r, "%s,", (char *)cur->data);
+                               r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "%s,", (char *)cur->data);
                        }
                        else {
-                               r += snprintf (outbuf + r, sizeof (outbuf) - r, "%s" CRLF, (char *)cur->data);
+                               r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "%s" CRLF, (char *)cur->data);
                        }
                        cur = g_list_next (cur);
                }
@@ -595,26 +595,26 @@ show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data
                        rs = m->reject_score;
                }
                if (task->proto == SPAMC_PROTO) {
-                       r = snprintf (outbuf, sizeof (outbuf), "Spam: False ; 0 / %.2f" CRLF, ms);
+                       r = rspamd_snprintf (outbuf, sizeof (outbuf), "Spam: False ; 0 / %.2f" CRLF, ms);
                }
                else {
                        if (strcmp (task->proto_ver, RSPAMC_PROTO_1_1) == 0) {
                 if (!task->is_skipped) {
-                                   r = snprintf (outbuf, sizeof (outbuf), "Metric: default; False; 0 / %.2f / %.2f" CRLF, ms, rs);
+                                   r = rspamd_snprintf (outbuf, sizeof (outbuf), "Metric: default; False; 0 / %.2f / %.2f" CRLF, ms, rs);
                 }
                 else {
-                                   r = snprintf (outbuf, sizeof (outbuf), "Metric: default; Skip; 0 / %.2f / %.2f" CRLF, ms, rs);
+                                   r = rspamd_snprintf (outbuf, sizeof (outbuf), "Metric: default; Skip; 0 / %.2f / %.2f" CRLF, ms, rs);
                 }
                        }
                        else {
-                               r = snprintf (outbuf, sizeof (outbuf), "Metric: default; False; 0 / %.2f" CRLF, ms);
+                               r = rspamd_snprintf (outbuf, sizeof (outbuf), "Metric: default; False; 0 / %.2f" CRLF, ms);
                        }
                }
         if (!task->is_skipped) {
-                   cd->log_offset += snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: F: [0/%.2f/%.2f] [", "default", ms, rs);
+                   cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: F: [0/%.2f/%.2f] [", "default", ms, rs);
         }
         else {
-                   cd->log_offset += snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: S: [0/%.2f/%.2f] [", "default", ms, rs);
+                   cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: S: [0/%.2f/%.2f] [", "default", ms, rs);
         }
        }
        else {
@@ -632,30 +632,30 @@ show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data
                        is_spam = 1;
                }
                if (task->proto == SPAMC_PROTO) {
-                       r = snprintf (outbuf, sizeof (outbuf), "Spam: %s ; %.2f / %.2f" CRLF, (is_spam) ? "True" : "False", metric_res->score, ms);
+                       r = rspamd_snprintf (outbuf, sizeof (outbuf), "Spam: %s ; %.2f / %.2f" CRLF, (is_spam) ? "True" : "False", metric_res->score, ms);
                }
                else {
                        if (strcmp (task->proto_ver, RSPAMC_PROTO_1_1) == 0) {
                 if (!task->is_skipped) {
-                                   r = snprintf (outbuf, sizeof (outbuf), "Metric: %s; %s; %.2f / %.2f / %.2f" CRLF, 
+                                   r = rspamd_snprintf (outbuf, sizeof (outbuf), "Metric: %s; %s; %.2f / %.2f / %.2f" CRLF, 
                                                (char *)metric_name, (is_spam) ? "True" : "False", metric_res->score, ms, rs);
                 }
                 else {
-                                   r = snprintf (outbuf, sizeof (outbuf), "Metric: %s; Skip; %.2f / %.2f / %.2f" CRLF, 
+                                   r = rspamd_snprintf (outbuf, sizeof (outbuf), "Metric: %s; Skip; %.2f / %.2f / %.2f" CRLF, 
                                                (char *)metric_name, metric_res->score, ms, rs);
                 }
                        }
                        else {
-                               r = snprintf (outbuf, sizeof (outbuf), "Metric: %s; %s; %.2f / %.2f" CRLF, 
+                               r = rspamd_snprintf (outbuf, sizeof (outbuf), "Metric: %s; %s; %.2f / %.2f" CRLF, 
                                                (char *)metric_name, (is_spam) ? "True" : "False", metric_res->score, ms);
                        }
                }
         if (!task->is_skipped) {
-                   cd->log_offset += snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: %s: [%.2f/%.2f/%.2f] [", 
+                   cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: %s: [%.2f/%.2f/%.2f] [", 
                                (char *)metric_name, is_spam ? "T" : "F", metric_res->score, ms, rs);
         }
         else {
-                   cd->log_offset += snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: %s: [%.2f/%.2f/%.2f] [", 
+                   cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: %s: [%.2f/%.2f/%.2f] [", 
                                (char *)metric_name, "S", metric_res->score, ms, rs);
         
         }
@@ -679,10 +679,10 @@ show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data
                }
        }
 #ifdef HAVE_CLOCK_GETTIME
-       cd->log_offset += snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "]), len: %ld, time: %sms",
+       cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "]), len: %l, time: %sms",
                (long int)task->msg->len, calculate_check_time (&task->ts, task->cfg->clock_res));
 #else
-       cd->log_offset += snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "]), len: %ld, time: %sms",
+       cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "]), len: %l, time: %sms",
                (long int)task->msg->len, calculate_check_time (&task->tv, task->cfg->clock_res));
 #endif
 }
@@ -696,7 +696,7 @@ show_messages (struct worker_task *task)
        
        cur = task->messages;
        while (cur) {
-               r += snprintf (outbuf + r, sizeof (outbuf) - r, "Message: %s" CRLF, (char *)cur->data);
+               r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "Message: %s" CRLF, (char *)cur->data);
                cur = g_list_next (cur);
        }
 
@@ -711,7 +711,7 @@ write_check_reply (struct worker_task *task)
        struct metric_result           *metric_res;
        struct metric_callback_data     cd;
 
-       r = snprintf (outbuf, sizeof (outbuf), "%s/%s 0 %s" CRLF, (task->proto == SPAMC_PROTO) ? SPAMD_REPLY_BANNER : RSPAMD_REPLY_BANNER,
+       r = rspamd_snprintf (outbuf, sizeof (outbuf), "%s/%s 0 %s" CRLF, (task->proto == SPAMC_PROTO) ? SPAMD_REPLY_BANNER : RSPAMD_REPLY_BANNER,
                                        task->proto_ver, "OK");
        if (! rspamd_dispatcher_write (task->dispatcher, outbuf, r, TRUE, FALSE)) {
                return FALSE;
@@ -719,7 +719,7 @@ write_check_reply (struct worker_task *task)
 
        cd.task = task;
        cd.log_buf = logbuf;
-       cd.log_offset = snprintf (logbuf, sizeof (logbuf), "msg ok, id: <%s>, ", task->message_id);
+       cd.log_offset = rspamd_snprintf (logbuf, sizeof (logbuf), "msg ok, id: <%s>, ", task->message_id);
        cd.log_size = sizeof (logbuf);
        cd.alive = TRUE;
 
@@ -799,13 +799,13 @@ write_process_reply (struct worker_task *task)
        struct metric_result           *metric_res;
        struct metric_callback_data     cd;
 
-       r = snprintf (outbuf, sizeof (outbuf), "%s/%s 0 %s" CRLF "Content-Length: %zd" CRLF CRLF, 
+       r = rspamd_snprintf (outbuf, sizeof (outbuf), "%s/%s 0 %s" CRLF "Content-Length: %zd" CRLF CRLF, 
                        (task->proto == SPAMC_PROTO) ? SPAMD_REPLY_BANNER : RSPAMD_REPLY_BANNER, 
                        task->proto_ver, "OK", task->msg->len);
 
        cd.task = task;
        cd.log_buf = logbuf;
-       cd.log_offset = snprintf (logbuf, sizeof (logbuf), "msg ok, id: <%s>, ", task->message_id);
+       cd.log_offset = rspamd_snprintf (logbuf, sizeof (logbuf), "msg ok, id: <%s>, ", task->message_id);
        cd.log_size = sizeof (logbuf);
        cd.alive = TRUE;
 
@@ -888,12 +888,12 @@ write_reply (struct worker_task *task)
        if (task->error_code != 0) {
                /* Write error message and error code to reply */
                if (task->proto == SPAMC_PROTO) {
-                       r = snprintf (outbuf, sizeof (outbuf), "%s/%s %d %s" CRLF CRLF, 
+                       r = rspamd_snprintf (outbuf, sizeof (outbuf), "%s/%s %d %s" CRLF CRLF, 
                                        SPAMD_REPLY_BANNER, task->proto_ver, task->error_code, SPAMD_ERROR);
                        debug_task ("writing error: %s", outbuf);
                }
                else {
-                       r = snprintf (outbuf, sizeof (outbuf), "%s/%s %d %s" CRLF "%s: %s" CRLF CRLF, 
+                       r = rspamd_snprintf (outbuf, sizeof (outbuf), "%s/%s %d %s" CRLF "%s: %s" CRLF CRLF, 
                                        RSPAMD_REPLY_BANNER, task->proto_ver, task->error_code, SPAMD_ERROR, ERROR_HEADER, task->last_error);
                        debug_task ("writing error: %s", outbuf);
                }
@@ -914,12 +914,12 @@ write_reply (struct worker_task *task)
                        return write_process_reply (task);
                        break;
                case CMD_SKIP:
-                       r = snprintf (outbuf, sizeof (outbuf), "%s/%s 0 %s" CRLF, 
+                       r = rspamd_snprintf (outbuf, sizeof (outbuf), "%s/%s 0 %s" CRLF, 
                                        (task->proto == SPAMC_PROTO) ? SPAMD_REPLY_BANNER : RSPAMD_REPLY_BANNER, task->proto_ver, SPAMD_OK);
                        return rspamd_dispatcher_write (task->dispatcher, outbuf, r, FALSE, FALSE);
                        break;
                case CMD_PING:
-                       r = snprintf (outbuf, sizeof (outbuf), "%s/%s 0 PONG" CRLF, 
+                       r = rspamd_snprintf (outbuf, sizeof (outbuf), "%s/%s 0 PONG" CRLF, 
                                        (task->proto == SPAMC_PROTO) ? SPAMD_REPLY_BANNER : RSPAMD_REPLY_BANNER, task->proto_ver);
                        return rspamd_dispatcher_write (task->dispatcher, outbuf, r, FALSE, FALSE);
                        break;
index 74d156bdd144597f66ff186bd32ee700616ff420..1b95a52bb2adc11d0e16b572722a88b205a1d97c 100644 (file)
@@ -231,7 +231,7 @@ read_smtp_command (struct smtp_session *session, f_str_t *line)
                                                session->state = SMTP_STATE_WAIT_UPSTREAM;
                                                session->upstream_state = SMTP_STATE_BEFORE_DATA;
                                                rspamd_dispatcher_restore (session->upstream_dispatcher);
-                                               r = snprintf (outbuf, sizeof (outbuf), "RCPT TO: ");
+                                               r = rspamd_snprintf (outbuf, sizeof (outbuf), "RCPT TO: ");
                                                r += smtp_upstream_write_list (session->rcpt->data, outbuf + r, sizeof (outbuf) - r);
                                                session->cur_rcpt = NULL;
                                                return rspamd_dispatcher_write (session->upstream_dispatcher, outbuf, r, FALSE, FALSE);
@@ -274,7 +274,7 @@ read_smtp_command (struct smtp_session *session, f_str_t *line)
                                else {
                                        session->upstream_state = SMTP_STATE_DATA;
                                        rspamd_dispatcher_restore (session->upstream_dispatcher);
-                                       r = snprintf (outbuf, sizeof (outbuf), "DATA" CRLF);
+                                       r = rspamd_snprintf (outbuf, sizeof (outbuf), "DATA" CRLF);
                                        session->state = SMTP_STATE_WAIT_UPSTREAM;
                                        session->error = SMTP_ERROR_DATA_OK;
                                        return rspamd_dispatcher_write (session->upstream_dispatcher, outbuf, r, FALSE, FALSE);
@@ -527,26 +527,26 @@ smtp_write_socket (void *arg)
                                        is_spam = TRUE;
                                }
 
-                               r = snprintf (logbuf, sizeof (logbuf), "msg ok, id: <%s>, ", session->task->message_id);
-                               r += snprintf (logbuf + r, sizeof (logbuf) - r, "(%s: %s: [%.2f/%.2f/%.2f] [", 
+                               r = rspamd_snprintf (logbuf, sizeof (logbuf), "msg ok, id: <%s>, ", session->task->message_id);
+                               r += rspamd_snprintf (logbuf + r, sizeof (logbuf) - r, "(%s: %s: [%.2f/%.2f/%.2f] [", 
                                                (char *)m->name, is_spam ? "T" : "F", metric_res->score, ms, rs);
                                symbols = g_hash_table_get_keys (metric_res->symbols);
                                cur = symbols;
                                while (cur) {
                                        if (g_list_next (cur) != NULL) {
-                                               r += snprintf (logbuf + r, sizeof (logbuf) - r, "%s,", (char *)cur->data);
+                                               r += rspamd_snprintf (logbuf + r, sizeof (logbuf) - r, "%s,", (char *)cur->data);
                                        }
                                        else {
-                                               r += snprintf (logbuf + r, sizeof (logbuf) - r, "%s", (char *)cur->data);
+                                               r += rspamd_snprintf (logbuf + r, sizeof (logbuf) - r, "%s", (char *)cur->data);
                                        }
                                        cur = g_list_next (cur);
                                }
                                g_list_free (symbols);
 #ifdef HAVE_CLOCK_GETTIME
-                               r += snprintf (logbuf + r, sizeof (logbuf) - r, "]), len: %ld, time: %sms",
+                               r += rspamd_snprintf (logbuf + r, sizeof (logbuf) - r, "]), len: %l, time: %sms",
                                        (long int)session->task->msg->len, calculate_check_time (&session->task->ts, session->cfg->clock_res));
 #else
-                               r += snprintf (logbuf + r, sizeof (logbuf) - r, "]), len: %ld, time: %sms",
+                               r += rspamd_snprintf (logbuf + r, sizeof (logbuf) - r, "]), len: %l, time: %sms",
                                        (long int)session->task->msg->len, calculate_check_time (&session->task->tv, session->cfg->clock_res));
 #endif
                                msg_info ("%s", logbuf);
@@ -968,16 +968,16 @@ make_capabilities (struct smtp_worker_ctx *ctx, const char *line)
        
        p = result;
        if (num == 0) {
-               p += snprintf (p, len - (p - result), "250 %s" CRLF, hostbuf);
+               p += rspamd_snprintf (p, len - (p - result), "250 %s" CRLF, hostbuf);
        }
        else {
-               p += snprintf (p, len - (p - result), "250-%s" CRLF, hostbuf);
+               p += rspamd_snprintf (p, len - (p - result), "250-%s" CRLF, hostbuf);
                for (i = 0; i < num; i ++) {
                        if (i != num - 1) {
-                               p += snprintf (p, len - (p - result), "250-%s" CRLF, strv[i]);
+                               p += rspamd_snprintf (p, len - (p - result), "250-%s" CRLF, strv[i]);
                        }
                        else {
-                               p += snprintf (p, len - (p - result), "250 %s" CRLF, strv[i]);
+                               p += rspamd_snprintf (p, len - (p - result), "250 %s" CRLF, strv[i]);
                        }
                }
        }
index f0669198cef8c9de31d45ca3f9eba494cff3306f..dd1e6cbc317cd4f3b844e351032d274306e8e60d 100644 (file)
@@ -42,8 +42,8 @@ make_smtp_error (struct smtp_session *session, int error_code, const char *forma
        va_start (vp, format);
        len += sizeof ("65535 ") + sizeof (CRLF) - 1;
        result = memory_pool_alloc (session->pool, len);
-       p = result + snprintf (result, len, "%d ", error_code);
-       p += vsnprintf (p, len - (p - result), format, vp);
+       p = result + rspamd_snprintf (result, len, "%d ", error_code);
+       p = rspamd_vsnprintf (p, len - (p - result), format, vp);
        *p++ = CR; *p++ = LF; *p = '\0';
        va_end (vp);
 
@@ -413,7 +413,7 @@ smtp_upstream_read_socket (f_str_t * in, void *arg)
                        }
                        else if (r == 1) {
                                if (session->ctx->use_xclient) {
-                                       r = snprintf (outbuf, sizeof (outbuf), "XCLIENT NAME=%s ADDR=%s" CRLF, 
+                                       r = rspamd_snprintf (outbuf, sizeof (outbuf), "XCLIENT NAME=%s ADDR=%s" CRLF, 
                                                        session->resolved ? session->hostname : "[UNDEFINED]",
                                                        inet_ntoa (session->client_addr));
                                        session->upstream_state = SMTP_STATE_HELO;
@@ -422,7 +422,7 @@ smtp_upstream_read_socket (f_str_t * in, void *arg)
                                else {
                                        session->upstream_state = SMTP_STATE_FROM;
                                        if (session->helo) {
-                                               r = snprintf (outbuf, sizeof (outbuf), "%s %s" CRLF, 
+                                               r = rspamd_snprintf (outbuf, sizeof (outbuf), "%s %s" CRLF, 
                                                        session->esmtp ? "EHLO" : "HELO",
                                                        session->helo);
                                        }
@@ -453,7 +453,7 @@ smtp_upstream_read_socket (f_str_t * in, void *arg)
                        else if (r == 1) {
                                session->upstream_state = SMTP_STATE_FROM;
                                if (session->helo) {
-                                       r = snprintf (outbuf, sizeof (outbuf), "%s %s" CRLF, 
+                                       r = rspamd_snprintf (outbuf, sizeof (outbuf), "%s %s" CRLF, 
                                                session->esmtp ? "EHLO" : "HELO",
                                                session->helo);
                                }
@@ -481,7 +481,7 @@ smtp_upstream_read_socket (f_str_t * in, void *arg)
                                return FALSE;
                        }
                        else if (r == 1) {
-                               r = snprintf (outbuf, sizeof (outbuf), "MAIL FROM: ");
+                               r = rspamd_snprintf (outbuf, sizeof (outbuf), "MAIL FROM: ");
                                r += smtp_upstream_write_list (session->from, outbuf + r, sizeof (outbuf) - r);
                                session->upstream_state = SMTP_STATE_RCPT;
                                return rspamd_dispatcher_write (session->upstream_dispatcher, outbuf, r, FALSE, FALSE);
@@ -505,7 +505,7 @@ smtp_upstream_read_socket (f_str_t * in, void *arg)
                                return FALSE;
                        }
                        else if (r == 1) {
-                               r = snprintf (outbuf, sizeof (outbuf), "RCPT TO: ");
+                               r = rspamd_snprintf (outbuf, sizeof (outbuf), "RCPT TO: ");
                                session->cur_rcpt = g_list_first (session->rcpt);
                                r += smtp_upstream_write_list (session->cur_rcpt->data, outbuf + r, sizeof (outbuf) - r);
                                session->cur_rcpt = g_list_next (session->cur_rcpt);
@@ -537,7 +537,7 @@ smtp_upstream_read_socket (f_str_t * in, void *arg)
                        }
                        else if (r == 1) {
                                if (session->cur_rcpt != NULL) {
-                                       r = snprintf (outbuf, sizeof (outbuf), "RCPT TO: ");
+                                       r = rspamd_snprintf (outbuf, sizeof (outbuf), "RCPT TO: ");
                                        r += smtp_upstream_write_list (session->cur_rcpt, outbuf + r, sizeof (outbuf) - r);
                                        session->cur_rcpt = g_list_next (session->cur_rcpt);
                                        if (! rspamd_dispatcher_write (session->upstream_dispatcher, outbuf, r, FALSE, FALSE)) {
@@ -583,7 +583,7 @@ smtp_upstream_read_socket (f_str_t * in, void *arg)
                        else if (r == 1) {
                                r = strlen (session->cfg->temp_dir) + sizeof ("/rspamd-XXXXXX");
                                session->temp_name = memory_pool_alloc (session->pool, r);
-                               snprintf (session->temp_name, r, "%s%crspamd-XXXXXX", session->cfg->temp_dir, G_DIR_SEPARATOR);
+                               rspamd_snprintf (session->temp_name, r, "%s%crspamd-XXXXXX", session->cfg->temp_dir, G_DIR_SEPARATOR);
 #ifdef HAVE_MKSTEMP
                                /* Umask is set before */
                                session->temp_fd = mkstemp (session->temp_name);
index 1e5baeb7dd5d6bef8d135f4fd5c92584d7238073..e2f62aca26dd7946b4ca774340ec4eacec769329 100644 (file)
@@ -76,7 +76,7 @@ log_next_sync (const char *symbol, time_t delay)
     tmp = localtime(&t);
 
        if (tmp) {
-               r = snprintf (outstr, sizeof (outstr), "statfile_sync: next sync of %s at ", symbol);
+               r = rspamd_snprintf (outstr, sizeof (outstr), "statfile_sync: next sync of %s at ", symbol);
                if ((r = strftime(outstr + r, sizeof(outstr) - r, "%T", tmp)) != 0) {
                        msg_info (outstr);
                }
@@ -175,7 +175,7 @@ sync_read (f_str_t * in, void *arg)
                        /* Skip greeting line and write sync command */
                        /* Write initial data */
                        statfile_get_revision (ctx->real_statfile, &rev, &ti);
-                       rev = snprintf (buf, sizeof (buf), "sync %s %ld %ld" CRLF, ctx->st->symbol, (long int)rev, (long int)ti);
+                       rev = rspamd_snprintf (buf, sizeof (buf), "sync %s %l %l" CRLF, ctx->st->symbol, (long int)rev, (long int)ti);
                        ctx->state = SYNC_STATE_READ_LINE;
                        return rspamd_dispatcher_write (ctx->dispatcher, buf, rev, FALSE, FALSE);       
                        break;
index cb5171075ae4cecc0b50dab2e7033ec5c0797be2..cf96f4624d7cc2abd581f3fc6d3a02d17fd17c34 100644 (file)
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifdef _THREAD_SAFE
-#   include <pthread.h>
-#endif
-
-#include <sys/types.h>
-#include <time.h>
-#include <stdlib.h>
-#include <stdio.h>
-#ifdef HAVE_STDINT_H
-#   include <stdint.h>
-#endif
-#ifdef HAVE_INTTYPES_H
-#   include <inttypes.h>
-#endif
-#include <limits.h>
-#ifdef WITH_DEBUG
-#   include <syslog.h>
-#endif
+#include "config.h"
 #include "upstream.h"
 
 #ifdef WITH_DEBUG
index 67b93337e7029b54efa409c22e70804c602ddb39..9a82a25f65aefbfaa139d7069ff8d56cf4fdeefe 100644 (file)
@@ -1124,8 +1124,9 @@ rspamd_snprintf (u_char *buf, size_t max, const char *fmt, ...)
        va_list   args;
 
        va_start (args, fmt);
-       p = rspamd_vsnprintf (buf, max, fmt, args);
+       p = rspamd_vsnprintf (buf, max - 1, fmt, args);
        va_end (args);
+       *p = '\0';
 
        return p - buf;
 }
@@ -1208,7 +1209,12 @@ rspamd_vsnprintf (u_char *buf, size_t max, const char *fmt, va_list args)
                                        break;
 
                                case '*':
-                                       slen = va_arg(args, size_t);
+                                       d = (int)va_arg (args, int);
+                                       if (G_UNLIKELY (d < 0)) {
+                                               msg_err ("crititcal error: size is less than 0");
+                                               g_assert (0);
+                                       }
+                                       slen = (size_t)d;
                                        fmt++;
                                        continue;