Browse Source

[Minor] Support base64 printing

tags/1.7.9
Vsevolod Stakhov 6 years ago
parent
commit
102a5e58fb
2 changed files with 31 additions and 1 deletions
  1. 30
    1
      src/libutil/printf.c
  2. 1
    0
      src/libutil/printf.h

+ 30
- 1
src/libutil/printf.c View File

@@ -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 */

+ 1
- 0
src/libutil/printf.h View File

@@ -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'

Loading…
Cancel
Save