From 2762d7da761ed458c4fbb4b2d8942fa66dc5eabe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Mon, 18 May 2009 22:14:43 +0000 Subject: [PATCH] * add function to decode hex strings --- libcitadel/lib/libcitadel.h | 1 + libcitadel/lib/stringbuf.c | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index eb3a5e362..a40bda3c1 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -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 */ diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 03459bd78..c59361263 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -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 -- 2.30.2