diff options
| author | Ingo Klöcker <[email protected]> | 2026-08-03 14:52:39 +0200 |
|---|---|---|
| committer | Ingo Klöcker <[email protected]> | 2026-08-03 14:52:39 +0200 |
| commit | 667ced56862ec5d50dd17e98aa26155cc2330ac3 (patch) | |
| tree | e47372d76ab69a013ec28aa221228f1c22768927 /src/conversion.c | |
| parent | Handle new SIGINFO status line (diff) | |
| download | gpgme-667ced56862ec5d50dd17e98aa26155cc2330ac3.tar.gz gpgme-667ced56862ec5d50dd17e98aa26155cc2330ac3.zip | |
Add helper to decode percent-plus encoded strings
* src/conversion.c (do_decode_percent_or_percent_plus): New.
(_gpgme_decode_percent_string): Move its code to new file-static
do_decode_percent_or_percent_plus and call it with disabled decoding of
'+'.
* src/conversion.c, src/util.h (_gpgme_decode_percent_plus_string): New.
--
GnuPG-bug-id: 8369
Diffstat (limited to 'src/conversion.c')
| -rw-r--r-- | src/conversion.c | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/src/conversion.c b/src/conversion.c index d15d7cc9..11e03e9c 100644 --- a/src/conversion.c +++ b/src/conversion.c @@ -242,16 +242,17 @@ _gpgme_decode_c_string (const char *src, char **destp, size_t len) } -/* Decode the percent escaped string SRC and store the result in the - buffer *DESTP which is LEN bytes long. If LEN is zero, then a - large enough buffer is allocated with malloc and *DESTP is set to - the result. Currently, LEN is only used to specify if allocation +/* Do the percent and plus/space decoding of string SRC and store the + result in the buffer *DESTP which is LEN bytes long. If LEN is zero, + then a large enough buffer is allocated with malloc and *DESTP is set + to the result. Currently, LEN is only used to specify if allocation is desired or not, the caller is expected to make sure that *DESTP is large enough if LEN is not zero. If BINARY is 1, then '\0' - characters are allowed in the output. */ -gpgme_error_t -_gpgme_decode_percent_string (const char *src, char **destp, size_t len, - int binary) + characters are allowed in the output. Plus decoding is only done + if WITHPLUS is 1. */ +static gpgme_error_t +do_decode_percent_or_percent_plus (const char *src, char **destp, size_t len, + int binary, int withplus) { char *dest; @@ -277,7 +278,12 @@ _gpgme_decode_percent_string (const char *src, char **destp, size_t len, /* Convert the string. */ while (*src) { - if (*src != '%') + if (*src == '+' && withplus) + { + *(dest++) = ' '; + src++; + } + else if (*src != '%') { *(dest++) = *(src++); continue; @@ -316,6 +322,36 @@ _gpgme_decode_percent_string (const char *src, char **destp, size_t len, } +/* Decode the percent escaped string SRC and store the result in the + buffer *DESTP which is LEN bytes long. If LEN is zero, then a + large enough buffer is allocated with malloc and *DESTP is set to + the result. Currently, LEN is only used to specify if allocation + is desired or not, the caller is expected to make sure that *DESTP + is large enough if LEN is not zero. If BINARY is 1, then '\0' + characters are allowed in the output. */ +gpgme_error_t +_gpgme_decode_percent_string (const char *src, char **destp, size_t len, + int binary) +{ + return do_decode_percent_or_percent_plus (src, destp, len, binary, 0); +} + + +/* Decode the percent-plus escaped string SRC and store the result in the + buffer *DESTP which is LEN bytes long. If LEN is zero, then a + large enough buffer is allocated with malloc and *DESTP is set to + the result. Currently, LEN is only used to specify if allocation + is desired or not, the caller is expected to make sure that *DESTP + is large enough if LEN is not zero. If BINARY is 1, then '\0' + characters are allowed in the output. */ +gpgme_error_t +_gpgme_decode_percent_plus_string (const char *src, char **destp, size_t len, + int binary) +{ + return do_decode_percent_or_percent_plus (src, destp, len, binary, 1); +} + + /* Encode the string SRC with percent escaping and store the result in the buffer *DESTP which is LEN bytes long. If LEN is zero, then a large enough buffer is allocated with malloc and *DESTP is set to |
