* foolproof the hex-decoder
authorWilfried Göesgens <willi@citadel.org>
Mon, 16 Mar 2009 21:25:19 +0000 (21:25 +0000)
committerWilfried Göesgens <willi@citadel.org>
Mon, 16 Mar 2009 21:25:19 +0000 (21:25 +0000)
* some inline handling to fixup mips

libcitadel/lib/libcitadel.h
libcitadel/lib/mime_parser.c
libcitadel/lib/stringbuf.c

index c6454f210332eb56bd1c88a7171db0294594fc2b..223ddf134683748507c545deaf345a88c67d492c 100644 (file)
@@ -249,7 +249,7 @@ int StrBufSub(StrBuf *dest, const StrBuf *Source, unsigned long Offset, size_t n
 unsigned long StrBufExtract_unsigned_long(const StrBuf* Source, int parmnum, char separator);
 long StrBufExtract_long(const StrBuf* Source, int parmnum, char separator);
 int StrBufExtract_int(const StrBuf* Source, int parmnum, char separator);
-inline int StrBufNum_tokens(const StrBuf *source, char tok);
+int StrBufNum_tokens(const StrBuf *source, char tok);
 int StrBufRemove_token(StrBuf *Source, int parmnum, char separator);
 
 int StrBufExtract_NextToken(StrBuf *dest, const StrBuf *Source, const char **pStart, char separator);
@@ -327,7 +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);
+unsigned int decode_hex(char *Source);
 int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
 void striplt(char *);
 int haschar(const char *st, int ch);
index 66f8c0c782d70f4e14871303b9060565f501f8ca..85f955c0c5e10b57b3a88b6dda8ace7d7e9644b4 100644 (file)
@@ -71,35 +71,41 @@ char *fixed_partnum(char *supplied_partnum) {
 }
 
 
-unsigned int decode_hex(char *Source)
+static inline unsigned int _decode_hex(char *Source)
 {
        int ret = 0;
-       if (*Source  < 'A') {
+       if      ((*Source >= '0') && (*Source <= '9')) {
                ret += (*Source - '0');
        }
-       else if (*Source > 'Z') {
+       else if ((*Source >= 'A') && (*Source <= 'F')) {
+               ret += (*Source - 'A' + 10);
+       }
+       else if ((*Source >= 'a') && (*Source <= 'f')) {
                ret += (*Source - 'a' + 10);
        }
        else {
-               ret += (*Source - 'A' + 10);
+               return '?';
        }
-
+               
        ret = ret << 4;
-
-       if (*(Source + 1) < 'A') {
-               ret += (*(Source + 1) - '0');
+       
+       if      ((*(Source + 1) >= '0') && (*(Source + 1) <= '9')) {
+               ret |= (*(Source + 1) - '0');
        }
-       else if (*(Source + 1) > 'Z') {
-               ret += (*(Source + 1) - 'a' + 10);
+       else if ((*(Source + 1) >= 'A') && (*(Source + 1) <= 'F')) {
+               ret |= (*(Source + 1) - 'A' + 10);
        }
-       else {
-               ret += (*(Source + 1) - 'A' + 10);
+       else if ((*(Source + 1) >= 'a') && (*(Source + 1) <= 'f')) {
+               ret |= (*(Source + 1) - 'a' + 10);
        }
-       if (ret > 255)
+       else {
                return '?';
+       }
        return ret;
 }
 
+unsigned int decode_hex(char *Source) {return _decode_hex(Source);}
+
 /*
  * Convert "quoted-printable" to binary.  Returns number of bytes decoded.
  * according to RFC2045 section 6.7
@@ -122,7 +128,7 @@ int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen) {
                else if (encoded[pos] == '=')
                {
                        ch = 0;
-                       ch = decode_hex(&encoded[pos+1]);
+                       ch = _decode_hex(&encoded[pos+1]);
                        pos += 3;
                        decoded[decoded_length++] = ch;
                }
index b7dc903c8e392394da2b604c9278727552098fad..f64ae13b0e4b0b0acefc1cd946600c154e0a53ee 100644 (file)
@@ -806,7 +806,7 @@ void StrBufPrintf(StrBuf *Buf, const char *format, ...)
  * \param tok    Tokenizer char to count
  * \returns numbers of tokenizer chars found
  */
-inline int StrBufNum_tokens(const StrBuf *source, char tok)
+int StrBufNum_tokens(const StrBuf *source, char tok)
 {
        if (source == NULL)
                return 0;