From bd8668c120ac0f725edb092b2c4ca49ffdb78ed2 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 26 Nov 2018 20:22:24 +0100 Subject: core: New functions gpgrt_fprintf_sf anf gpgrt_fprintf_sf_unlocked. * src/gpg-error.h.in (gpgrt_string_filter_t): New type. (gpgrt_fprintf_sf, gpgrt_fprintf_sf_unlocked): New. * src/gpg-error.vers, src/gpg-error.def.in: Add them. * src/visibility.c (gpgrt_fprintf_sf): New. (gpgrt_fprintf_sf_unlocked): New. * src/estream-printf.c (pr_string): Add and use args sf, sfvalue and string_no. (do_format): Add args sf and sfvalue. Keep a string format counter. (_gpgrt_estream_format): Add args sf and sfvalue. Change all callers to provide NULL for them. * src/estream.c (_gpgrt_vfprintf_unlocked, _gpgrt_vfprintf): Add sf and sfvalue and adjust all callers. (do_print_stream): Ditto. * tests/t-printf.c (stream_to_string): New. (struct sfstate_s): New. (string_filter): New. (check_fprintf_sf): New. (main): Call new test. -- The actual reason to implement these functions is to enhance the internal logging function with a filter to sanitized strings so that control values or other things can be quoted. Signed-off-by: Werner Koch --- src/estream-printf.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/estream-printf.h') diff --git a/src/estream-printf.h b/src/estream-printf.h index ae303a7..69c7052 100644 --- a/src/estream-printf.h +++ b/src/estream-printf.h @@ -124,8 +124,10 @@ typedef int (*estream_printf_out_t) (void *outfncarg, const char *buf, size_t buflen); int _gpgrt_estream_format (estream_printf_out_t outfnc, void *outfncarg, + char *(*string_filter)(const char *s,int n,void*st), + void *string_filter_state, const char *format, va_list vaargs) - _ESTREAM_GCC_A_PRINTF(3,0); + _ESTREAM_GCC_A_PRINTF(5,0); int _gpgrt_estream_printf (const char *format, ...) _ESTREAM_GCC_A_PRINTF(1,2); int _gpgrt_estream_fprintf (FILE *fp, const char *format, ... ) -- cgit v1.2.3