/*
- * Copyright (c) 1987-2011 by the citadel.org team
+ * Copyright (c) 1987-2013 by the citadel.org team
*
* This program is open source software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
void StrBufStripAllBut(StrBuf *Buf, char leftboundary, char rightboundary)
{
- const char *pBuff;
const char *pLeft;
const char *pRight;
- if ((Buf == NULL) || (Buf->buf == NULL))
+ if ((Buf == NULL) || (Buf->buf == NULL)) {
return;
- pLeft = pBuff = Buf->buf;
- while (pBuff != NULL) {
- pLeft = pBuff;
- pBuff = strchr(pBuff, leftboundary);
- if (pBuff != NULL)
- pBuff++;
}
-
- if (pLeft != NULL)
- pBuff = pLeft;
- else
- pBuff = Buf->buf;
- pRight = strchr(pBuff, rightboundary);
- if (pRight != NULL)
+
+ pRight = strchr(Buf->buf, rightboundary);
+ if (pRight != NULL) {
StrBufCutAt(Buf, 0, pRight);
- if (pLeft != NULL)
- StrBufCutLeft(Buf, pLeft - Buf->buf);
+ }
+ else {
+ StrBufCutAt(Buf, 0, Buf->buf);
+ return;
+ }
+
+ pLeft = strrchr(ChrPtr(Buf), leftboundary);
+ if (pLeft != NULL) {
+ StrBufCutLeft(Buf, pLeft - Buf->buf + 1);
+ }
+ else {
+ StrBufCutAt(Buf, 0, Buf->buf);
+ return;
+ }
}
*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
return Target->BufUsed;
}
+
+/**
+ * @ingroup StrBuf_DeEnCoder
+ * @brief replace all non-Ascii characters by another
+ * @param Buf buffer to inspect
+ * @param repl charater to stamp over non ascii chars
+ */
+void StrBufAsciify(StrBuf *Buf, const char repl)
+{
+ long offset;
+
+ for (offset = 0; offset < Buf->BufUsed; offset ++)
+ if (!isascii(Buf->buf[offset]))
+ Buf->buf[offset] = repl;
+
+}
+
/**
* @ingroup StrBuf_DeEnCoder
* @brief unhide special chars hidden to the HTML escaper
return StrLength(FB->Buf) - (FB->ReadWritePointer - FB->Buf->buf);
}
-void FDIOBufferInit(FDIOBuffer *FDB, IOBuffer *IO, int FD, long TotalSendSize)
+inline static void FDIOBufferFlush(FDIOBuffer *FDB)
{
memset(FDB, 0, sizeof(FDIOBuffer));
+ FDB->OtherFD = -1;
+ FDB->SplicePipe[0] = -1;
+ FDB->SplicePipe[1] = -1;
+}
+
+void FDIOBufferInit(FDIOBuffer *FDB, IOBuffer *IO, int FD, long TotalSendSize)
+{
+ FDIOBufferFlush(FDB);
FDB->ChunkSize =
FDB->TotalSendSize = TotalSendSize;
FDB->IOB = IO;
#ifdef LINUX_SPLICE
if (EnableSplice)
{
- close(FDB->SplicePipe[0]);
- close(FDB->SplicePipe[1]);
+ if (FDB->SplicePipe[0] > 0)
+ close(FDB->SplicePipe[0]);
+ if (FDB->SplicePipe[1] > 0)
+ close(FDB->SplicePipe[1]);
}
else
#endif
FreeStrBuf(&FDB->ChunkBuffer);
- close(FDB->OtherFD);
- memset(FDB, 0, sizeof(FDIOBuffer));
+ if (FDB->OtherFD > 0)
+ close(FDB->OtherFD);
+ FDIOBufferFlush(FDB);
}
int FileSendChunked(FDIOBuffer *FDB, const char **Err)
continue;
}
+ else
+ {
+ nSuccessLess++;
+ }
}
*Pos = NULL;
if (pLF != NULL) {