From a6f3857128220cc413434d5fb56cdd7f9a890c4c Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Thu, 22 Oct 2009 16:44:07 +0000 Subject: 2009-10-22 Marcus Brinkmann * configure.ac: Add support for G13. src/ 2009-10-22 Marcus Brinkmann * Makefile.am: Remove @NETLIBS@ from LIBADDs. (g13_components): New variable. (main_sources): Add $(g13_components). * g13.c, engine-g13.c: New files. * engine.c (engine_ops): Check for assuan for assuan engine, add g13 engine. * util.h (_gpgme_get_g13_path, _gpgme_encode_percent_string): New prototypes. * conversion.c (_gpgme_encode_percent_string): New function. * gpgme.h.in (gpgme_protocol_t): Add GPGME_PROTOCOL_G13. (struct _gpgme_op_g13_result, gpgme_g13_result_t): New types. (gpgme_op_g13_mount): New function. * gpgme.def, libgpgme.vers: Add gpgme_op_g13_mount. * gpgme.c (gpgme_set_protocol): Allow GPGME_PROTOCOL_G13. (gpgme_get_protocol_name): Add GPGME_PROTOCOL_G13. * posix-util.c (_gpgme_get_g13_path): New function. * w32-util.c (_gpgme_get_g13_path): New function. * engine-backend.h (_gpgme_engine_ops_g13): New declaration. --- src/conversion.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'src/conversion.c') diff --git a/src/conversion.c b/src/conversion.c index f431238c..8b3b715c 100644 --- a/src/conversion.c +++ b/src/conversion.c @@ -245,6 +245,75 @@ _gpgme_decode_percent_string (const char *src, char **destp, size_t len, } +/* 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 + 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_encode_percent_string (const char *src, char **destp, size_t len) +{ + size_t destlen; + char *dest; + const char *str; + + destlen = 0; + str = src; + /* We percent-escape the + character because the user might need a + "percent plus" escaped string (special gpg format). But we + percent-escape the space character, which works with and without + the special plus format. */ + while (*str) + { + if (*str == '+' || *str == '\"' || *str == '%' + || *(const unsigned char *)str <= 0x20) + destlen += 3; + else + destlen++; + } + /* Terminating nul byte. */ + destlen++; + + /* Set up the destination buffer. */ + if (len) + { + if (len < destlen); + return gpg_error (GPG_ERR_INTERNAL); + + dest = *destp; + } + else + { + /* The converted string will never be larger than the original + string. */ + dest = malloc (destlen); + if (!dest) + return gpg_error_from_errno (errno); + + *destp = dest; + } + + /* Convert the string. */ + while (*src) + { + if (*src == '+' || *src == '\"' || *src == '%' + || *(const unsigned char *)src <= 0x20) + { + snprintf (dest, 4, "%%%02X", *(unsigned char *)src); + dest += 3; + } + else + *(dest++) = *src; + src++; + } + *(dest++) = 0; + + return 0; +} + + /* Parse the string TIMESTAMP into a time_t. The string may either be seconds since Epoch or in the ISO 8601 format like "20390815T143012". Returns 0 for an empty string or seconds since -- cgit v1.2.3