add strbuff wrapper for base64 encoding
authorWilfried Goesgens <dothebart@citadel.org>
Tue, 24 Sep 2013 22:33:29 +0000 (00:33 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Tue, 24 Sep 2013 22:33:29 +0000 (00:33 +0200)
libcitadel/lib/libcitadel.h
libcitadel/lib/stringbuf.c

index af6e16c170421fd097ee2468b26fc3d551452d60..062ac35206f605db499d27b1d6efbed4e4e21286 100644 (file)
@@ -352,6 +352,7 @@ void StrBufUrlescAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn);
 void StrBufUrlescUPAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn);
 void StrBufHexescAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn);
 void StrBufHexEscAppend(StrBuf *OutBuf, const StrBuf *In, const unsigned char *PlainIn, long PlainInLen);
+void StrBufBase64Append(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn, long PlainInLen, int linebreaks);
 long StrEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks);
 long StrECMAEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn);
 long StrHtmlEcmaEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks);
index 1b9ea072366221b9bea1f8cf1f438a229f795bb3..4cee2be32980d3133f41bdd9749a48ae850b375e 100644 (file)
@@ -1985,6 +1985,45 @@ void StrBufHexEscAppend(StrBuf *OutBuf, const StrBuf *In, const unsigned char *P
        *pt = '\0';
 }
 
+void StrBufBase64Append(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn, long PlainInLen, int linebreaks)
+{
+       const char *pch;
+       char *pt;
+       int len;
+       long ExpectLen;
+       
+       if (((In == NULL) && (PlainIn == NULL)) || (OutBuf == NULL) )
+               return;
+       if (PlainIn != NULL) {
+               if (PlainInLen < 0)
+                       len = strlen(PlainIn);
+               else
+                       len = PlainInLen;
+               pch = PlainIn;
+       }
+       else {
+               pch = In->buf;
+               len = In->BufUsed;
+       }
+
+       if (len == 0) 
+               return;
+
+       ExpectLen = ((len * 134) / 100) + OutBuf->BufUsed;
+
+       if (ExpectLen > OutBuf->BufSize)
+               if (IncreaseBuf(OutBuf, 1, ExpectLen) < ExpectLen)
+                       return;
+
+       pt = OutBuf->buf + OutBuf->BufUsed;
+
+       len = CtdlEncodeBase64(pt, pch, len, linebreaks);
+
+       pt += len;
+       OutBuf->BufUsed += len;
+       *pt = '\0';
+}
+
 /** 
  * @ingroup StrBuf_DeEnCoder
  * @brief append a string in hex encoding to the buffer