tls_in.on_connect_ports = NULL;
sep = 0;
while ((s = string_nextinlist(&list, &sep, big_buffer, big_buffer_size)))
- {
- if (!isdigit(*s))
+ if (isdigit(*s))
+ g = string_append_listele(g, ':', s);
+ else
{
struct servent * smtp_service = getservbyname(CS s, "tcp");
if (!smtp_service)
log_write(0, LOG_PANIC_DIE|LOG_CONFIG, "TCP port \"%s\" not found", s);
- s = string_sprintf("%d", (int)ntohs(smtp_service->s_port));
+ g = string_append_listele_fmt(g, ':', FALSE, "%d",
+ (int)ntohs(smtp_service->s_port));
}
- g = string_append_listele(g, ':', s);
- }
+
if (g)
tls_in.on_connect_ports = g->s;
break;
/* First option has no tag and is timeout */
if ((item = string_nextinlist(&list, &sep, NULL, 0)))
- g = string_append_listele(g, ',',
- string_sprintf("timeout=%s", item));
+ g = string_append_listele_fmt(g, ',', TRUE, "timeout=%s", item);
/* The rest of the options from the expansion */
while ((item = string_nextinlist(&list, &sep, NULL, 0)))
options is the readsock expansion. */
if (sub_arg[3] && *sub_arg[3])
- g = string_append_listele(g, ',',
- string_sprintf("eol=%s",
- string_printing2(sub_arg[3], SP_TAB|SP_SPACE)));
+ g = string_append_listele_fmt(g, ',', TRUE,
+ "eol=%s", string_printing2(sub_arg[3], SP_TAB|SP_SPACE));
}
/* Gat a (possibly cached) handle for the connection */
extern gstring *string_append(gstring *, int, ...) WARN_UNUSED_RESULT;
extern gstring *string_append_listele(gstring *, uschar, const uschar *) WARN_UNUSED_RESULT;
extern gstring *string_append_listele_n(gstring *, uschar, const uschar *, unsigned) WARN_UNUSED_RESULT;
-extern gstring *string_append_listele_fmt(gstring *, uschar, const char *, ...) WARN_UNUSED_RESULT;
+extern gstring *string_append_listele_fmt(gstring *, uschar, BOOL, const char *, ...) WARN_UNUSED_RESULT;
extern gstring *string_append2_listele_n(gstring *, const uschar *, const uschar *, unsigned) WARN_UNUSED_RESULT;
extern uschar *string_base62_32(unsigned long int);
extern uschar *string_base62_64(unsigned long int);
arc_line * line = as->hdr_as;
if (line)
{
- g = string_append_listele_fmt(g, ',', " (\"i\":%u" /*)*/
+ g = string_append_listele_fmt(g, ',', FALSE,
+ " (\"i\":%u" /*)*/
", \"d\":\"%#b\""
", \"s\":\"%#b\"",
as->instance, &line->d, &line->s);
/* Listmaker that takes a format string and args for the element.
-Currently no checking of the element content for sep chars */
+A flag arg is required to handle embedded sep chars in the (expanded) element;
+if false then no check is done */
gstring *
-string_append_listele_fmt(gstring * list, uschar sep, const char * fmt, ...)
+string_append_listele_fmt(gstring * list, uschar sep, BOOL check,
+ const char * fmt, ...)
{
+va_list ap;
+unsigned start;
+gstring * g;
+
if (list && list->ptr)
+ {
list = string_catn(list, &sep, 1);
+ start = list->ptr;
+ }
+else
+ start = 0;
-va_list ap;
va_start(ap, fmt);
list = string_vformat_trc(list, US __FUNCTION__, __LINE__,
STRING_SPRINTF_BUFFER_SIZE, SVFMT_REBUFFER|SVFMT_EXTEND, fmt, ap);
va_end(ap);
(void) string_from_gstring(list);
-return list;
+
+/* if the appended element turns out to have an embedded sep char, rewind
+and do the lazy-coded separate string method */
+
+if (!check || !Ustrchr(&list->s[start], sep))
+ return list;
+
+va_start(ap, fmt);
+g = string_vformat_trc(NULL, US __FUNCTION__, __LINE__,
+ STRING_SPRINTF_BUFFER_SIZE, SVFMT_REBUFFER|SVFMT_EXTEND, fmt, ap);
+va_end(ap);
+
+list->ptr = start;
+return string_append_listele_n(list, sep, g->s, g->ptr);
}
case GNUTLS_SAN_RFC822NAME: tag = US"MAIL"; break;
default: continue; /* ignore unrecognised types */
}
- list = string_append_listele(list, sep,
- match == -1 ? string_sprintf("%s=%s", tag, ele) : ele);
+ list = match == -1
+ ? string_append_listele_fmt(list, sep, TRUE, "%s=%s", tag, ele)
+ : string_append_listele(list, sep, ele);
}
/*NOTREACHED*/
}
ele = string_copyn(ele, len);
if (Ustrlen(ele) == len) /* ignore any with embedded nul */
- list = string_append_listele(list, osep,
- match == -1 ? string_sprintf("%s=%s", tag, ele) : ele);
+ list = match == -1
+ ? string_append_listele_fmt(list, osep, TRUE, "%s=%s", tag, ele)
+ : string_append_listele(list, osep, ele);
}
sk_GENERAL_NAME_free(san);