diff options
author | Werner Koch <wk@gnupg.org> | 2013-09-30 10:18:25 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2013-09-30 10:18:25 +0200 |
commit | d2076f27bb7c5d505abf25fc622d21794c4a5df3 (patch) | |
tree | 162b348f4714af97ab6a422e16fd3264665f216a /src/misc.c | |
parent | db60d828137c4f3682ca4ca2a54fe3d96d3db5f9 (diff) | |
download | libgcrypt-d2076f27bb7c5d505abf25fc622d21794c4a5df3.tar.gz |
Add logging functions to the API.
* src/gcrypt.h.in (_GCRY_GCC_ATTR_PRINTF): New.
(gcry_log_debug, gcry_log_debughex, gcry_log_debugmpi): New.
(gcry_log_debugpnt, gcry_log_debugsxp): New.
* src/visibility.c (gcry_log_debug): New.
(gcry_log_debughex, gcry_log_debugmpi, gcry_log_debugpnt): New.
(gcry_log_debugsxp): New.
* src/libgcrypt.def, src/libgcrypt.vers: Add new functions.
* src/misc.c (_gcry_logv): Make public.
(_gcry_log_printsxp): New.
* src/g10lib.h (log_printsxp): New macro.
--
For debugging applications it is often required to dump certain data
structures. Libgcrypt uses several internal functions for this. To
avoid re-implementing everything in the caller, we now provide access
to some of those functions.
Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src/misc.c')
-rw-r--r-- | src/misc.c | 51 |
1 files changed, 50 insertions, 1 deletions
@@ -115,7 +115,7 @@ _gcry_log_verbosity( int level ) * This is our log function which prints all log messages to stderr or * using the function defined with gcry_set_log_handler(). */ -static void +void _gcry_logv( int level, const char *fmt, va_list arg_ptr ) { if (log_handler) @@ -361,6 +361,55 @@ _gcry_log_printmpi (const char *text, gcry_mpi_t mpi) } } +/* Print SEXP in human readabale format. With TEXT of NULL print just the raw + dump without any wrappping, with TEXT an empty string, print a + trailing linefeed, otherwise print the full debug output. */ +void +_gcry_log_printsxp (const char *text, gcry_sexp_t sexp) +{ + int with_lf = 0; + + if (text && *text) + { + if ((with_lf = strchr (text, '\n'))) + log_debug ("%s", text); + else + log_debug ("%s: ", text); + } + if (sexp) + { + int any = 0; + char *buf, *p, *pend; + size_t size; + + size = gcry_sexp_sprint (sexp, GCRYSEXP_FMT_ADVANCED, NULL, 0); + p = buf = gcry_xmalloc (size); + gcry_sexp_sprint (sexp, GCRYSEXP_FMT_ADVANCED, buf, size); + + do + { + if (any && !with_lf) + log_debug ("%*s ", (int)strlen(text), ""); + else + any = 1; + pend = strchr (p, '\n'); + size = pend? (pend - p) : strlen (p); + if (with_lf) + log_debug ("%.*s\n", (int)size, p); + else + log_printf ("%.*s\n", (int)size, p); + if (pend) + p = pend + 1; + else + p += size; + } + while (*p); + gcry_free (buf); + } + if (text) + log_printf ("\n"); +} + void _gcry_burn_stack (unsigned int bytes) |