header_line * h = (header_line *)(al+1);
g = string_catn(g, ARC_HDR_AAR, ARC_HDRLEN_AAR);
-g = string_cat(g, string_sprintf(" i=%d; %s;\r\n\t", instance, identity));
+g = string_fmt_append(g, " i=%d; %s;\r\n\t", instance, identity);
g = string_catn(g, US ar->data, ar->len);
h->slen = g->ptr - aar_off;
/* Construct the to-be-signed AMS pseudo-header: everything but the sig. */
ams_off = g->ptr;
-g = string_append(g, 7,
- ARC_HDR_AMS,
- US" i=", string_sprintf("%d", instance),
- US"; a=rsa-sha256; c=relaxed; d=", identity, /*XXX hardwired */
- US"; s=", selector);
+g = string_fmt_append(g, "%s i=%d; a=rsa-sha256; c=relaxed; d=%s; s=%s",
+ ARC_HDR_AMS, instance, identity, selector); /*XXX hardwired a= */
if (options & ARC_SIGN_OPT_TSTAMP)
- g = string_append(g, 2,
- US"; t=", string_sprintf("%lu", (u_long)now));
+ g = string_fmt_append(g, "; t=%lu", (u_long)now);
if (options & ARC_SIGN_OPT_EXPIRE)
- g = string_append(g, 2,
- US"; x=", string_sprintf("%lu", (u_long)expire));
-g = string_append(g, 3,
- US";\r\n\tbh=", pdkim_encode_base64(bodyhash),
- US";\r\n\th=");
+ g = string_fmt_append(g, "; x=%lu", (u_long)expire);
+g = string_fmt_append(g, ";\r\n\tbh=%s;\r\n\th=",
+ pdkim_encode_base64(bodyhash));
for(col = 3; rheaders; rheaders = rheaders->prev)
{
g = string_append(g, 2, US";\n\tarc=", arc_state);
if (arc_received_instance > 0)
{
- g = string_append(g, 3, US" (i=",
- string_sprintf("%d", arc_received_instance), US")");
+ g = string_fmt_append(g, " (i=%d)", arc_received_instance);
if (arc_state_reason)
g = string_append(g, 3, US"(", arc_state_reason, US")");
g = string_catn(g, US" header.s=", 10);
highest_ams = arc_received->hdr_ams;
g = string_catn(g, highest_ams->s.data, highest_ams->s.len);
- g = string_append(g, 2,
- US" arc.oldest-pass=", string_sprintf("%d", arc_oldest_pass));
+ g = string_fmt_append(g, " arc.oldest-pass=%d", arc_oldest_pass);
if (sender_host_address)
g = string_append(g, 2, US" smtp.remote-ip=", sender_host_address);
static void
never_error(uschar *log_msg, uschar *smtp_msg, int was_errno)
{
-uschar *emsg = (was_errno <= 0)? US"" :
- string_sprintf(": %s", strerror(was_errno));
+uschar *emsg = was_errno <= 0
+ ? US"" : string_sprintf(": %s", strerror(was_errno));
log_write(0, LOG_MAIN|LOG_PANIC, "%s%s", log_msg, emsg);
-if (smtp_out != NULL) smtp_printf("421 %s\r\n", FALSE, smtp_msg);
+if (smtp_out) smtp_printf("421 %s\r\n", FALSE, smtp_msg);
}
whofrom = string_append(NULL, 3, "[", sender_host_address, "]");
if (LOGGING(incoming_port))
- whofrom = string_append(whofrom, 2, ":", string_sprintf("%d", sender_host_port));
+ whofrom = string_fmt_append(whofrom, ":%d", sender_host_port);
if (LOGGING(incoming_interface))
- whofrom = string_append(whofrom, 4, " I=[",
- interface_address, "]:", string_sprintf("%d", interface_port));
+ whofrom = string_fmt_append(whofrom, " I=[%s]:%d",
+ interface_address, interface_port);
(void) string_from_gstring(whofrom); /* Terminate the newly-built string */
logmsg = string_append(logmsg, 2, "d=", s);
if (!(s = sig->selector)) s = US"<UNSET>";
logmsg = string_append(logmsg, 2, " s=", s);
-logmsg = string_append(logmsg, 7,
- " c=", sig->canon_headers == PDKIM_CANON_SIMPLE ? "simple" : "relaxed",
- "/", sig->canon_body == PDKIM_CANON_SIMPLE ? "simple" : "relaxed",
- " a=", dkim_sig_to_a_tag(sig),
-string_sprintf(" b=" SIZE_T_FMT,
- (int)sig->sighash.len > -1 ? sig->sighash.len * 8 : 0));
+logmsg = string_fmt_append(logmsg, " c=%s/%s a=%s b=" SIZE_T_FMT,
+ sig->canon_headers == PDKIM_CANON_SIMPLE ? "simple" : "relaxed",
+ sig->canon_body == PDKIM_CANON_SIMPLE ? "simple" : "relaxed",
+ dkim_sig_to_a_tag(sig),
+ (int)sig->sighash.len > -1 ? sig->sighash.len * 8 : (size_t)0);
if ((s= sig->identity)) logmsg = string_append(logmsg, 2, " i=", s);
-if (sig->created > 0) logmsg = string_cat(logmsg,
- string_sprintf(" t=%lu", sig->created));
-if (sig->expires > 0) logmsg = string_cat(logmsg,
- string_sprintf(" x=%lu", sig->expires));
-if (sig->bodylength > -1) logmsg = string_cat(logmsg,
- string_sprintf(" l=%lu", sig->bodylength));
+if (sig->created > 0) logmsg = string_fmt_append(logmsg, " t=%lu",
+ sig->created);
+if (sig->expires > 0) logmsg = string_fmt_append(logmsg, " x=%lu",
+ sig->expires);
+if (sig->bodylength > -1) logmsg = string_fmt_append(logmsg, " l=%lu",
+ sig->bodylength);
if (sig->verify_status & PDKIM_VERIFY_POLICY)
logmsg = string_append(logmsg, 5,
case EOP_BASE62D:
{
- uschar buf[16];
uschar *tt = sub;
unsigned long int n = 0;
while (*tt != 0)
}
n = n * BASE_62 + (t - base62_chars);
}
- (void)sprintf(CS buf, "%ld", n);
- yield = string_cat(yield, buf);
+ yield = string_fmt_append(yield, "%ld", n);
continue;
}
md5 base;
uschar digest[16];
int j;
- char st[33];
md5_start(&base);
md5_end(&base, sub, Ustrlen(sub), digest);
- for(j = 0; j < 16; j++) sprintf(st+2*j, "%02x", digest[j]);
- yield = string_cat(yield, US st);
+ for (j = 0; j < 16; j++)
+ yield = string_fmt_append(yield, "%02x", digest[j]);
}
continue;
hctx h;
uschar digest[20];
int j;
- char st[41];
sha1_start(&h);
sha1_end(&h, sub, Ustrlen(sub), digest);
- for(j = 0; j < 20; j++) sprintf(st+2*j, "%02X", digest[j]);
- yield = string_catn(yield, US st, 40);
+ for (j = 0; j < 20; j++)
+ yield = string_fmt_append(yield, "%02X", digest[j]);
}
continue;
{
hctx h;
blob b;
- char st[3];
if (!exim_sha_init(&h, HASH_SHA2_256))
{
exim_sha_update(&h, sub, Ustrlen(sub));
exim_sha_finish(&h, &b);
while (b.len-- > 0)
- {
- sprintf(st, "%02X", *b.data++);
- yield = string_catn(yield, US st, 2);
- }
+ yield = string_fmt_append(yield, "%02X", *b.data++);
}
#else
expand_string_message = US"sha256 only supported with TLS";
{
hctx h;
blob b;
- char st[3];
hashmethod m = !arg ? HASH_SHA3_256
: Ustrcmp(arg, "224") == 0 ? HASH_SHA3_224
: Ustrcmp(arg, "256") == 0 ? HASH_SHA3_256
exim_sha_update(&h, sub, Ustrlen(sub));
exim_sha_finish(&h, &b);
while (b.len-- > 0)
- {
- sprintf(st, "%02X", *b.data++);
- yield = string_catn(yield, US st, 2);
- }
+ yield = string_fmt_append(yield, "%02X", *b.data++);
}
continue;
#else
while (*(++t) != 0)
{
if (*t < 0x21 || 0x7E < *t)
- yield = string_catn(yield, string_sprintf("\\x%02x", *t), 4);
+ yield = string_fmt_append(yield, "\\x%02x", *t);
else
yield = string_catn(yield, t, 1);
}
{
int cnt = 0;
int sep = 0;
- uschar * cp;
uschar buffer[256];
while (string_nextinlist(CUSS &sub, &sep, buffer, sizeof(buffer)) != NULL) cnt++;
- cp = string_sprintf("%d", cnt);
- yield = string_cat(yield, cp);
+ yield = string_fmt_append(yield, "%d", cnt);
continue;
}
for (s = sub; (c = *s); s++)
yield = c < 127 && c != '\\'
? string_catn(yield, s, 1)
- : string_catn(yield, string_sprintf("\\%03o", c), 4);
+ : string_fmt_append(yield, "\\%03o", c);
continue;
}
uschar *save_sub = sub;
uschar *error = NULL;
int_eximarith_t n = eval_expr(&sub, (c == EOP_EVAL10), &error, FALSE);
- if (error != NULL)
+ if (error)
{
expand_string_message = string_sprintf("error in expression "
"evaluation: %s (after processing \"%.*s\")", error,
(int)(sub-save_sub), save_sub);
goto EXPAND_FAILED;
}
- sprintf(CS var_buffer, PR_EXIM_ARITH, n);
- yield = string_cat(yield, var_buffer);
+ yield = string_fmt_append(yield, PR_EXIM_ARITH, n);
continue;
}
"Exim time interval in \"%s\" operator", sub, name);
goto EXPAND_FAILED;
}
- sprintf(CS var_buffer, "%d", n);
- yield = string_cat(yield, var_buffer);
+ yield = string_fmt_append(yield, "%d", n);
continue;
}
/* strlen returns the length of the string */
case EOP_STRLEN:
- {
- uschar buff[24];
- (void)sprintf(CS buff, "%d", Ustrlen(sub));
- yield = string_cat(yield, buff);
+ yield = string_fmt_append(yield, "%d", Ustrlen(sub));
continue;
- }
/* length_n or l_n takes just the first n characters or the whole string,
whichever is the shorter;
int len;
uschar *ret;
- if (arg == NULL)
+ if (!arg)
{
expand_string_message = string_sprintf("missing values after %s",
name);
case EOP_STAT:
{
- uschar *s;
uschar smode[12];
uschar **modetable[3];
int i;
mode_t mode;
struct stat st;
- if ((expand_forbid & RDO_EXISTS) != 0)
+ if (expand_forbid & RDO_EXISTS)
{
expand_string_message = US"Use of the stat() expansion is not permitted";
goto EXPAND_FAILED;
}
smode[10] = 0;
- s = string_sprintf("mode=%04lo smode=%s inode=%ld device=%ld links=%ld "
+ yield = string_fmt_append(yield,
+ "mode=%04lo smode=%s inode=%ld device=%ld links=%ld "
"uid=%ld gid=%ld size=" OFF_T_FMT " atime=%ld mtime=%ld ctime=%ld",
(long)(st.st_mode & 077777), smode, (long)st.st_ino,
(long)st.st_dev, (long)st.st_nlink, (long)st.st_uid,
(long)st.st_gid, st.st_size, (long)st.st_atime,
(long)st.st_mtime, (long)st.st_ctime);
- yield = string_cat(yield, s);
continue;
}
case EOP_RANDINT:
{
- int_eximarith_t max;
- uschar *s;
+ int_eximarith_t max = expanded_string_integer(sub, TRUE);
- max = expanded_string_integer(sub, TRUE);
- if (expand_string_message != NULL)
+ if (expand_string_message)
goto EXPAND_FAILED;
- s = string_sprintf("%d", vaguely_random_number((int)max));
- yield = string_cat(yield, s);
+ yield = string_fmt_append(yield, "%d", vaguely_random_number((int)max));
continue;
}
/* Unknown operator */
default:
- expand_string_message =
- string_sprintf("unknown expansion operator \"%s\"", name);
- goto EXPAND_FAILED;
+ expand_string_message =
+ string_sprintf("unknown expansion operator \"%s\"", name);
+ goto EXPAND_FAILED;
}
}
switch (entry->type)
{
case REDIS_REPLY_INTEGER:
- result = string_cat(result, string_sprintf("%d", entry->integer));
+ result = string_fmt_append(result, "%d", entry->integer);
break;
case REDIS_REPLY_STRING:
result = string_catn(result, US entry->str, entry->len);
switch (tentry->type)
{
case REDIS_REPLY_INTEGER:
- result = string_cat(result, string_sprintf("%d", tentry->integer));
+ result = string_fmt_append(result, "%d", tentry->integer);
break;
case REDIS_REPLY_STRING:
result = string_catn(result, US tentry->str, tentry->len);
if (LOGGING(dnssec) && sender_host_dnssec) /*XXX sender_helo_dnssec? */
g = string_catn(g, US" DS", 3);
g = string_append(g, 2, US" H=", sender_fullhost);
- if (LOGGING(incoming_interface) && interface_address != NULL)
- {
- g = string_cat(g,
- string_sprintf(" I=[%s]:%d", interface_address, interface_port));
- }
+ if (LOGGING(incoming_interface) && interface_address)
+ g = string_fmt_append(g, " I=[%s]:%d", interface_address, interface_port);
}
if (f.tcp_in_fastopen && !f.tcp_in_fastopen_logged)
{
if (f.is_inetd)
return string_sprintf("SMTP connection from %s (via inetd)", hostname);
-if (LOGGING(incoming_interface) && interface_address != NULL)
+if (LOGGING(incoming_interface) && interface_address)
return string_sprintf("SMTP connection from %s I=[%s]:%d", hostname,
interface_address, interface_port);
smtp_code = US"250 "; /* Default response code plus space*/
if (!user_msg)
{
- s = string_sprintf("%.3s %s Hello %s%s%s",
+ g = string_fmt_append(NULL, "%.3s %s Hello %s%s%s",
smtp_code,
smtp_active_hostname,
sender_ident ? sender_ident : US"",
sender_ident ? US" at " : US"",
sender_host_name ? sender_host_name : sender_helo_name);
- g = string_cat(NULL, s);
if (sender_host_address)
- {
- g = string_catn(g, US" [", 2);
- g = string_cat (g, sender_host_address);
- g = string_catn(g, US"]", 1);
- }
+ g = string_fmt_append(g, " [%s]", sender_host_address);
}
/* A user-supplied EHLO greeting may not contain more than one line. Note
till then, VRFY and EXPN can be used after EHLO when space is short. */
if (thismessage_size_limit > 0)
- {
- sprintf(CS big_buffer, "%.3s-SIZE %d\r\n", smtp_code,
+ g = string_fmt_append(g, "%.3s-SIZE %d\r\n", smtp_code,
thismessage_size_limit);
- g = string_cat(g, big_buffer);
- }
else
{
g = string_catn(g, smtp_code, 3);
static void
write_logs(const host_item *host, const uschar *suffix, int basic_errno)
{
-uschar *message = LOGGING(outgoing_port)
- ? string_sprintf("H=%s [%s]:%d", host->name, host->address,
+gstring * message = LOGGING(outgoing_port)
+ ? string_fmt_append(NULL, "H=%s [%s]:%d", host->name, host->address,
host->port == PORT_NONE ? 25 : host->port)
- : string_sprintf("H=%s [%s]", host->name, host->address);
+ : string_fmt_append(NULL, "H=%s [%s]", host->name, host->address);
if (suffix)
{
- message = string_sprintf("%s: %s", message, suffix);
+ message = string_fmt_append(message, ": %s", suffix);
if (basic_errno > 0)
- message = string_sprintf("%s: %s", message, strerror(basic_errno));
+ message = string_fmt_append(message, ": %s", strerror(basic_errno));
}
else
- message = string_sprintf("%s %s", message, exim_errstr(basic_errno));
+ message = string_fmt_append(message, " %s", exim_errstr(basic_errno));
-log_write(0, LOG_MAIN, "%s", message);
-deliver_msglog("%s %s\n", tod_stamp(tod_log), message);
+log_write(0, LOG_MAIN, "%s", string_from_gstring(message));
+deliver_msglog("%s %s\n", tod_stamp(tod_log), message->s);
}
static void