diff options
author | Werner Koch <[email protected]> | 2018-11-26 19:22:24 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2018-11-26 19:22:24 +0000 |
commit | bd8668c120ac0f725edb092b2c4ca49ffdb78ed2 (patch) | |
tree | ffeea782e9dc6435822f3b3f1c950c7222ff93b9 /src/visibility.c | |
parent | core: Add a limited version of gpgrt_ftruncate. (diff) | |
download | libgpg-error-bd8668c120ac0f725edb092b2c4ca49ffdb78ed2.tar.gz libgpg-error-bd8668c120ac0f725edb092b2c4ca49ffdb78ed2.zip |
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 <[email protected]>
Diffstat (limited to 'src/visibility.c')
-rw-r--r-- | src/visibility.c | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/src/visibility.c b/src/visibility.c index 1947111..573a5a4 100644 --- a/src/visibility.c +++ b/src/visibility.c @@ -515,7 +515,7 @@ gpgrt_vfprintf (estream_t _GPGRT__RESTRICT stream, const char *_GPGRT__RESTRICT format, va_list ap) { - return _gpgrt_vfprintf (stream, format, ap); + return _gpgrt_vfprintf (stream, NULL, NULL, format, ap); } int @@ -523,7 +523,7 @@ gpgrt_vfprintf_unlocked (estream_t _GPGRT__RESTRICT stream, const char *_GPGRT__RESTRICT format, va_list ap) { - return _gpgrt_vfprintf_unlocked (stream, format, ap); + return _gpgrt_vfprintf_unlocked (stream, NULL, NULL, format, ap); } int @@ -533,7 +533,7 @@ gpgrt_printf (const char *_GPGRT__RESTRICT format, ...) int rc; va_start (ap, format); - rc = _gpgrt_vfprintf (es_stdout, format, ap); + rc = _gpgrt_vfprintf (es_stdout, NULL, NULL, format, ap); va_end (ap); return rc; @@ -546,7 +546,7 @@ gpgrt_printf_unlocked (const char *_GPGRT__RESTRICT format, ...) int rc; va_start (ap, format); - rc = _gpgrt_vfprintf_unlocked (es_stdout, format, ap); + rc = _gpgrt_vfprintf_unlocked (es_stdout, NULL, NULL, format, ap); va_end (ap); return rc; @@ -560,7 +560,7 @@ gpgrt_fprintf (estream_t _GPGRT__RESTRICT stream, int rc; va_start (ap, format); - rc = _gpgrt_vfprintf (stream, format, ap); + rc = _gpgrt_vfprintf (stream, NULL, NULL, format, ap); va_end (ap); return rc; @@ -574,7 +574,37 @@ gpgrt_fprintf_unlocked (estream_t _GPGRT__RESTRICT stream, int rc; va_start (ap, format); - rc = _gpgrt_vfprintf_unlocked (stream, format, ap); + rc = _gpgrt_vfprintf_unlocked (stream, NULL, NULL, format, ap); + va_end (ap); + + return rc; +} + +int +gpgrt_fprintf_sf (estream_t _GPGRT__RESTRICT stream, + gpgrt_string_filter_t sf, void *sfvalue, + const char *_GPGRT__RESTRICT format, ...) +{ + va_list ap; + int rc; + + va_start (ap, format); + rc = _gpgrt_vfprintf (stream, sf, sfvalue, format, ap); + va_end (ap); + + return rc; +} + +int +gpgrt_fprintf_sf_unlocked (estream_t _GPGRT__RESTRICT stream, + gpgrt_string_filter_t sf, void *sfvalue, + const char *_GPGRT__RESTRICT format, ...) +{ + va_list ap; + int rc; + + va_start (ap, format); + rc = _gpgrt_vfprintf_unlocked (stream, sf, sfvalue, format, ap); va_end (ap); return rc; |