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);
/* 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);
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;
}
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");
}
}
}
- 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;
}
}
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);
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) {
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.);
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;
}
}
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;
}
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;
}
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;
}
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;
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
}
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
case 0:
if (!process_custom_command (cmd, ¶ms[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;
}
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;
}
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;
}
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;
/* 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;
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;
}
}
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;
}
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;
}
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;
/* 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;
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)) {
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);
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);
}
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));
}
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;
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;
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;
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;
}
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);
}
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;
}
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;
}
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);
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) {
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);
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));
return TRUE;
}
else {
- msg_info ("invalid chunked reply: %*s", len, buf);
+ msg_info ("invalid chunked reply: %*s", (int)len, buf);
return FALSE;
}
}
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)));
}
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;
}
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;
}
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");
}
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;
}
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;
}
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;
}
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;
}
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;
}
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),
/* 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 {
}
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);
}
}
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);
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;
event_del (¶m->ev);
event_set (¶m->ev, param->sock, EV_READ | EV_PERSIST, redirector_callback, (void *)param);
event_add (¶m->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);
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);
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));
}
}
}
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);
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;
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);
}
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);
}
}
}
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;
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);
}
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 {
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);
}
}
}
#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
}
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);
}
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;
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;
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;
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);
}
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;
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);
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);
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);
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]);
}
}
}
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);
}
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;
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);
}
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);
}
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);
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);
}
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)) {
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);
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);
}
/* 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;
* 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
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;
}
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;