From 7f8df9e1ba8fa3b30bfc047f66e3f8fbf63b3317 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Thu, 2 Jan 2014 20:18:09 +0100 Subject: [PATCH] STRBUF: add wrapper to do source -> target buffer base 64 decoding --- libcitadel/lib/libcitadel.h | 1 + libcitadel/lib/stringbuf.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index bd7c8da9c..a1aacb5fb 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -339,6 +339,7 @@ void StrBuf_RFC822_2_Utf8(StrBuf *Target, void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* DefaultCharset, StrBuf *FoundCharset); int StrBufDecodeBase64(StrBuf *Buf); +int StrBufDecodeBase64To(const StrBuf *BufIn, StrBuf *BufOut); int StrBufDecodeHex(StrBuf *Buf); StrBuf *StrBufRFC2047encodeMessage(const StrBuf *EncodeMe); int StrBufRFC2047encode(StrBuf **target, const StrBuf *source); diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 6bcbaf1fa..547037751 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -2823,6 +2823,26 @@ int StrBufDecodeBase64(StrBuf *Buf) return siz; } +/** + * @ingroup StrBuf_DeEnCoder + * @brief decode a buffer from base 64 encoding; expects targetbuffer + * @param BufIn Buffor to transform + * @param BufOut Buffer to put result into + */ +int StrBufDecodeBase64To(const StrBuf *BufIn, StrBuf *BufOut) +{ + if ((BufIn == NULL) || (BufOut == NULL)) + return -1; + + if (BufOut->BufSize < BufIn->BufUsed) + IncreaseBuf(BufOut, BufIn->BufUsed, 0); + + BufOut->BufUsed = CtdlDecodeBase64(BufOut->buf, + BufIn->buf, + BufIn->BufUsed); + return BufOut->BufUsed; +} + /** * @ingroup StrBuf_DeEnCoder * @brief decode a buffer from base 64 encoding; destroys original -- 2.30.2