summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2019-06-12 12:31:44 +0200
committerWerner Koch <wk@gnupg.org>2019-06-13 08:46:16 +0200
commit4f11210b21a1914a1daf67474e9b82084b2cac01 (patch)
treef26af711e4bb0c7228cd0d56d958cb92d025dc5a
parentf6fd90c99aea8b604d76ae49d29bc5269c236a98 (diff)
downloadgpgme-4f11210b21a1914a1daf67474e9b82084b2cac01.tar.gz
core: At debug levels up to 9 print only an ascii dump.
* src/debug.c (_gpgme_debug_buffer): Switch between two output formats. -- The new format is much more practical than the bunch of hex digits followed by just 16 ascii chars. To get the old behaviour use a debug level of 10. Signed-off-by: Werner Koch <wk@gnupg.org>
-rw-r--r--src/debug.c86
1 files changed, 59 insertions, 27 deletions
diff --git a/src/debug.c b/src/debug.c
index a861b416..d5d11bd9 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -403,33 +403,65 @@ _gpgme_debug_buffer (int lvl, const char *const fmt,
if (!buffer)
return;
- while (idx < len)
+ if (lvl > 9)
{
- char str[51];
- char *strp = str;
- char *strp2 = &str[34];
-
- for (j = 0; j < 16; j++)
- {
- unsigned char val;
- if (idx < len)
- {
- val = buffer[idx++];
- *(strp++) = TOHEX (val >> 4);
- *(strp++) = TOHEX (val % 16);
- *(strp2++) = isprint (val) ? val : '.';
- }
- else
- {
- *(strp++) = ' ';
- *(strp++) = ' ';
- }
- if (j == 7)
- *(strp++) = ' ';
- }
- *(strp++) = ' ';
- *(strp2) = '\0';
-
- _gpgme_debug (NULL, lvl, -1, NULL, NULL, NULL, fmt, func, str);
+ while (idx < len)
+ {
+ char str[51];
+ char *strp = str;
+ char *strp2 = &str[34];
+
+ for (j = 0; j < 16; j++)
+ {
+ unsigned char val;
+ if (idx < len)
+ {
+ val = buffer[idx++];
+ *(strp++) = TOHEX (val >> 4);
+ *(strp++) = TOHEX (val % 16);
+ *(strp2++) = isprint (val)? val : '.';
+ }
+ else
+ {
+ *(strp++) = ' ';
+ *(strp++) = ' ';
+ }
+ if (j == 7)
+ *(strp++) = ' ';
+ }
+ *(strp++) = ' ';
+ *(strp2) = '\0';
+
+ _gpgme_debug (NULL, lvl, -1, NULL, NULL, NULL, fmt, func, str);
+ }
+ }
+ else
+ {
+ while (idx < len)
+ {
+ char str[48+4+1];
+ char *strp = str;
+
+ for (j = 0; j < 48; j++)
+ {
+ unsigned char val;
+ if (idx < len)
+ {
+ val = buffer[idx++];
+ if (val == '\n')
+ {
+ *strp++ = '<';
+ *strp++ = 'L';
+ *strp++ = 'F';
+ *strp++ = '>';
+ break;
+ }
+ *strp++ = (val > 31 && val < 127)? val : '.';
+ }
+ }
+ *strp = 0;
+
+ _gpgme_debug (NULL, lvl, -1, NULL, NULL, NULL, fmt, func, str);
+ }
}
}