/* Add the formatted string FORMAT to the debug line *LINE. */ void _assuan_debug_add (assuan_context_t ctx, void **line, const char *format, ...) { va_list arg_ptr; char *toadd; char *result; int res; if (!*line) return; va_start (arg_ptr, format); res = gpgrt_vasprintf (&toadd, format, arg_ptr); va_end (arg_ptr); if (res < 0) { free (*line); *line = NULL; } res = gpgrt_asprintf (&result, "%s%s", *(char **) line, toadd); free (toadd); free (*line); if (res < 0) *line = NULL; else *line = result; }
/* Log the formatted string FORMAT at debug category CAT higher. */ void _assuan_debug (assuan_context_t ctx, unsigned int cat, const char *format, ...) { va_list arg_ptr; int saved_errno; char *msg; int res; /* vasprintf is an expensive operation thus we first check whether the callback has enabled CAT for logging. */ if (!ctx || !ctx->log_cb || !(*ctx->log_cb) (ctx, ctx->log_cb_data, cat, NULL)) return; saved_errno = errno; va_start (arg_ptr, format); res = gpgrt_vasprintf (&msg, format, arg_ptr); va_end (arg_ptr); if (res < 0) return; ctx->log_cb (ctx, ctx->log_cb_data, cat, msg); free (msg); gpg_err_set_errno (saved_errno); }
/* Variable argument version of tty_get. The prompt is is actually a format string with arguments. */ char * tty_getf (const char *promptfmt, ... ) { va_list arg_ptr; char *prompt; char *answer; va_start (arg_ptr, promptfmt); if (gpgrt_vasprintf (&prompt, promptfmt, arg_ptr) < 0) log_fatal ("estream_vasprintf failed: %s\n", strerror (errno)); va_end (arg_ptr); answer = tty_get (prompt); xfree (prompt); return answer; }
/* Start a new debug line in *LINE, logged at level LEVEL or higher, and starting with the formatted string FORMAT. */ void _assuan_debug_begin (assuan_context_t ctx, void **line, unsigned int cat, const char *format, ...) { va_list arg_ptr; int res; *line = NULL; /* Probe if this wants to be logged based on category. */ if (! ctx || ! ctx->log_cb || ! (*ctx->log_cb) (ctx, ctx->log_cb_data, cat, NULL)) return; va_start (arg_ptr, format); res = gpgrt_vasprintf ((char **) line, format, arg_ptr); va_end (arg_ptr); if (res < 0) *line = NULL; }