summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-19 10:46:57 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-19 11:15:19 +0100
commit102a5e58fb8607bb4b55a3e04d9d4beb4663987b (patch)
tree91e18825c6b30fcf31b089eaeeaa6e4562ca09a7 /src
parent4c75b1bd1286acc82b213256ed27b41a56771085 (diff)
downloadrspamd-102a5e58fb8607bb4b55a3e04d9d4beb4663987b.tar.gz
rspamd-102a5e58fb8607bb4b55a3e04d9d4beb4663987b.zip
[Minor] Support base64 printing
Diffstat (limited to 'src')
-rw-r--r--src/libutil/printf.c31
-rw-r--r--src/libutil/printf.h1
2 files changed, 31 insertions, 1 deletions
diff --git a/src/libutil/printf.c b/src/libutil/printf.c
index be4ef402e..74940cc5f 100644
--- a/src/libutil/printf.c
+++ b/src/libutil/printf.c
@@ -597,7 +597,7 @@ rspamd_vprintf_common (rspamd_printf_append_func func,
glong written = 0, wr, slen;
gint64 i64;
guint64 ui64;
- guint width, sign, hex, humanize, bytes, frac_width, b32;
+ guint width, sign, hex, humanize, bytes, frac_width, b32, b64;
rspamd_fstring_t *v;
rspamd_ftok_t *tok;
GString *gs;
@@ -670,6 +670,11 @@ rspamd_vprintf_common (rspamd_printf_append_func func,
sign = 0;
fmt++;
continue;
+ case 'B':
+ b64 = 1;
+ sign = 0;
+ fmt++;
+ continue;
case 'H':
humanize = 1;
bytes = 1;
@@ -845,6 +850,30 @@ rspamd_vprintf_common (rspamd_printf_append_func func,
buf_start = fmt;
}
+ else if (G_UNLIKELY (b64)) {
+ gchar *b64buf;
+ gsize olen = 0;
+
+ if (G_UNLIKELY (slen == -1)) {
+ if (G_LIKELY (width != 0)) {
+ slen = width;
+ }
+ else {
+ /* NULL terminated string */
+ slen = strlen (p);
+ }
+ }
+
+ b64buf = rspamd_encode_base64 (p, slen, 0, &olen);
+
+ if (b64buf) {
+ RSPAMD_PRINTF_APPEND (b64buf, olen);
+ g_free (b64buf);
+ }
+ else {
+ RSPAMD_PRINTF_APPEND ("(NULL)", sizeof ("(NULL)") - 1);
+ }
+ }
else {
if (slen == -1) {
/* NULL terminated string */
diff --git a/src/libutil/printf.h b/src/libutil/printf.h
index 7cf3bd4a8..73787d3a5 100644
--- a/src/libutil/printf.h
+++ b/src/libutil/printf.h
@@ -42,6 +42,7 @@
* %s null-terminated string
* %xs hex encoded string
* %bs base32 encoded string
+ * %Bs base64 encoded string
* %*s length and string
* %Z '\0'
* %N '\n'