* add function to decode hex strings
authorWilfried Göesgens <willi@citadel.org>
Mon, 18 May 2009 22:14:43 +0000 (22:14 +0000)
committerWilfried Göesgens <willi@citadel.org>
Mon, 18 May 2009 22:14:43 +0000 (22:14 +0000)
libcitadel/lib/libcitadel.h
libcitadel/lib/stringbuf.c

index eb3a5e362c256368eb76be1d7c14cec5bb7bbf52..a40bda3c19afe5122cc3ea710d35faf22ee41ecc 100644 (file)
@@ -300,6 +300,7 @@ void StrBufConvert(StrBuf *ConvertBuf, StrBuf *TmpBuf, void *pic);
 void ctdl_iconv_open(const char *tocode, const char *fromcode, void *pic);
 void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* DefaultCharset, StrBuf *FoundCharset);
 int StrBufDecodeBase64(StrBuf *Buf);
+int StrBufDecodeHex(StrBuf *Buf);
 int StrBufRFC2047encode(StrBuf **target, const StrBuf *source);
 int StrBufSanitizeAscii(StrBuf *Buf, const char Mute);
 #define LB                     (1)             /* Internal escape chars */
index 03459bd789fe42fbb8c2ff8b470ed72a5555f81f..c59361263d5b203c243389dea3266be4185ef6d2 100644 (file)
@@ -1414,7 +1414,7 @@ int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
                        *fd = -1;
                        return -1;
                }               
-               if (FD_ISSET(*fd, &rfds)) {
+               if (FD_ISSET(*fd, &rfds) != 0) {
                        rlen = read(*fd, 
                                    &buf->buf[buf->BufUsed], 
                                    buf->BufSize - buf->BufUsed - 1);
@@ -1916,6 +1916,32 @@ int StrBufDecodeBase64(StrBuf *Buf)
        return siz;
 }
 
+/**
+ * \brief decode a buffer from base 64 encoding; destroys original
+ * \param Buf Buffor to transform
+ */
+int StrBufDecodeHex(StrBuf *Buf)
+{
+       unsigned int ch;
+       char *pch, *pche, *pchi;
+
+       if (Buf == NULL) return -1;
+
+       pch = pchi = Buf->buf;
+       pche = pch + Buf->BufUsed;
+
+       while (pchi < pche){
+               ch = decode_hex(pchi);
+               *pch = ch;
+               pch ++;
+               pchi += 2;
+       }
+
+       *pch = '\0';
+       Buf->BufUsed = pch - Buf->buf;
+       return Buf->BufUsed;
+}
+
 /**
  * \brief replace all chars >0x20 && < 0x7F with Mute
  * \param Mute char to put over invalid chars