From: Wilfried Göesgens Date: Thu, 12 Mar 2009 22:54:48 +0000 (+0000) Subject: * add function decode_hex() that interprets 2 chars as hexdigits representing an... X-Git-Tag: v7.86~1356 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=87bcd6a282357e425e0832177b1452e29baab3ec * add function decode_hex() that interprets 2 chars as hexdigits representing an encoded char like scanf("%02X") would do. * use it in the QP decoder. --- diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index a633d0fb1..c6454f210 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -327,6 +327,7 @@ unsigned long extract_unsigned_long(const char *source, int parmnum); void CtdlInitBase64Table(void); size_t CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen, int linebreaks); int CtdlDecodeBase64(char *dest, const char *source, size_t length); +inline unsigned int decode_hex(char *Source); int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen); void striplt(char *); int haschar(const char *st, int ch); diff --git a/libcitadel/lib/mime_parser.c b/libcitadel/lib/mime_parser.c index 026d05550..76452935a 100644 --- a/libcitadel/lib/mime_parser.c +++ b/libcitadel/lib/mime_parser.c @@ -71,6 +71,26 @@ char *fixed_partnum(char *supplied_partnum) { } +inline unsigned int decode_hex(char *Source) +{ + int ret = 0; + if (*Source < 'A') { + ret += (*Source - '0'); + } + else { + ret += (*Source - 'A' + 10); + } + ret = ret << 4; + if (*(Source + 1) < 'A') { + ret += (*(Source + 1) - '0'); + } + else { + ret += (*(Source + 1) - 'A' + 10); + } + if (ret > 255) + return 0; + return ret; +} /* * Convert "quoted-printable" to binary. Returns number of bytes decoded. @@ -94,7 +114,7 @@ int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen) { else if (encoded[pos] == '=') { ch = 0; - sscanf(&encoded[pos+1], "%02x", &ch); + ch = decode_hex(&encoded[pos+1]); pos += 3; decoded[decoded_length++] = ch; }