From 9753614742f16b34df76d2c4d09d16cc93edd3dc Mon Sep 17 00:00:00 2001 From: "Steffen (Daode) Nurpmeso" Date: Sat, 5 Jul 2014 15:54:36 +0200 Subject: [PATCH] Add mime_char_to_hexseq(), mime_hexseq_to_char() --- mime_cte.c | 22 ++++++++++++++++++++++ nailfuns.h | 7 +++++++ 2 files changed, 29 insertions(+) diff --git a/mime_cte.c b/mime_cte.c index 11d7e3fe..1678fb50 100644 --- a/mime_cte.c +++ b/mime_cte.c @@ -292,6 +292,28 @@ jleave: return ret; } +FL char * +mime_char_to_hexseq(char store[3], char c) +{ + char *rv; + NYD2_ENTER; + + rv = _qp_ctohex(store, c); + NYD2_LEAVE; + return rv; +} + +FL si32_t +mime_hexseq_to_char(char const *hex) +{ + si32_t rv; + NYD2_ENTER; + + rv = _qp_cfromhex(hex); + NYD2_LEAVE; + return rv; +} + FL size_t mime_cte_mustquote(char const *ln, size_t lnlen, bool_t ishead) { diff --git a/nailfuns.h b/nailfuns.h index 0ef0f1e8..d14a7a26 100644 --- a/nailfuns.h +++ b/nailfuns.h @@ -1211,6 +1211,13 @@ FL ssize_t xmime_write(char const *ptr, size_t size, /* TODO LEGACY */ * - Base64, section 6.8 */ +/* Utilities: the former converts the byte c into a (NUL terminated) + * hexadecimal string as is used in URL percent- and quoted-printable encoding, + * the latter performs the backward conversion and returns the character or -1 + * on error */ +FL char * mime_char_to_hexseq(char store[3], char c); +FL si32_t mime_hexseq_to_char(char const *hex); + /* How many characters of (the complete body) ln need to be quoted */ FL size_t mime_cte_mustquote(char const *ln, size_t lnlen, bool_t ishead); -- 2.11.4.GIT