-// Copyright (c) 1987-2022 by the citadel.org team
+// Copyright (c) 1987-2023 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
-// the Free Software Foundation; either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// This program is open source software. Use, duplication, or disclosure
+// is subject to the terms of the GNU General Public License, version 3.
#define _GNU_SOURCE
#include "sysdep.h"
#ifdef HAVE_ZLIB
#include <zlib.h>
-int ZEXPORT compress_gzip(Bytef * dest, size_t * destLen,
- const Bytef * source, uLong sourceLen, int level);
+int ZEXPORT compress_gzip(Bytef * dest, size_t * destLen, const Bytef * source, uLong sourceLen, int level);
#endif
int BaseStrBufSize = 64;
int EnableSplice = 0;
"F0","F1","F2","F3","F4","F5","F6","F7","F8","F9","FA","FB","FC","FD","FE","FF"};
-/*
- * Private Structure for the Stringbuffer
- */
+// Private Structure for the Stringbuffer
struct StrBuf {
- char *buf; /**< the pointer to the dynamic buffer */
- long BufSize; /**< how many spcae do we optain */
- long BufUsed; /**< StNumber of Chars used excluding the trailing \\0 */
- int ConstBuf; /**< are we just a wrapper arround a static buffer and musn't we be changed? */
+ char *buf; // the pointer to the dynamic buffer
+ long BufSize; // how many spcae do we optain
+ long BufUsed; // Number of Chars used excluding the trailing \\0
+ int ConstBuf; // are we just a wrapper arround a static buffer and musn't we be changed?
#ifdef SIZE_DEBUG
- long nIncreases; /**< for profiling; cound how many times we needed more */
- char bt [SIZ]; /**< Stacktrace of last increase */
- char bt_lastinc [SIZ]; /**< How much did we increase last time? */
+ long nIncreases; // for profiling; cound how many times we needed more
+ char bt [SIZ]; // Stacktrace of last increase
+ char bt_lastinc[SIZ]; // How much did we increase last time?
#endif
};
size_t size, i;
char **strings;
- if (which)
+ if (which) {
pstart = pch = Buf->bt;
- else
+ }
+ else {
pstart = pch = Buf->bt_lastinc;
+ }
size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
strings = backtrace_symbols(stack_frames, size);
for (i = 0; i < size; i++) {
- if (strings != NULL)
+ if (strings != NULL) {
n = snprintf(pch, SIZ - (pch - pstart), "%s\\n", strings[i]);
- else
+ }
+ else {
n = snprintf(pch, SIZ - (pch - pstart), "%p\\n", stack_frames[i]);
+ }
pch += n;
}
free(strings);
-
-
}
#endif
char buf[SIZ * 3];
long n;
n = snprintf(buf, SIZ * 3, "%c+|%ld|%ld|%ld|%s|%s|\n",
- FromWhere,
- (*FreeMe)->nIncreases,
- (*FreeMe)->BufUsed,
- (*FreeMe)->BufSize,
- (*FreeMe)->bt,
- (*FreeMe)->bt_lastinc);
+ FromWhere,
+ (*FreeMe)->nIncreases,
+ (*FreeMe)->BufUsed,
+ (*FreeMe)->BufSize,
+ (*FreeMe)->bt,
+ (*FreeMe)->bt_lastinc
+ );
n = write(hFreeDbglog, buf, n);
}
else {
char buf[128];
long n;
n = snprintf(buf, 128, "%c_|0|%ld%ld|\n",
- FromWhere,
- (*FreeMe)->BufUsed,
- (*FreeMe)->BufSize);
+ FromWhere,
+ (*FreeMe)->BufUsed,
+ (*FreeMe)->BufSize
+ );
n = write(hFreeDbglog, buf, n);
}
}
}
-/**
+/*
* use strbuf as wrapper for a string constant for easy handling
* StringConstant a string to wrap
* SizeOfStrConstant should be sizeof(StringConstant)-1
}
-/**
+/*
* flush the content of a Buf; keep its struct
* buf Buffer to flush
*/
-int FlushStrBuf(StrBuf *buf)
-{
- if ((buf == NULL) || (buf->buf == NULL))
+int FlushStrBuf(StrBuf *buf) {
+ if ((buf == NULL) || (buf->buf == NULL)) {
return -1;
- if (buf->ConstBuf)
- return -1;
+ }
+ if (buf->ConstBuf) {
+ return -1;
+ }
buf->buf[0] ='\0';
buf->BufUsed = 0;
return 0;
}
-/**
+/*
* wipe the content of a Buf thoroughly (overwrite it -> expensive); keep its struct
* buf Buffer to wipe
*/
#ifdef SIZE_DEBUG
int hFreeDbglog = -1;
#endif
-/**
+/*
* Release a Buffer
* Its a double pointer, so it can NULL your pointer
* so fancy SIG11 appear instead of random results
* Simple string transformations *
*******************************************************************************/
-/**
- * Wrapper around atol
- */
-long StrTol(const StrBuf *Buf)
-{
+// Wrapper around atol
+long StrTol(const StrBuf *Buf) {
if (Buf == NULL)
return 0;
if(Buf->BufUsed > 0)
return 0;
}
-/**
- * Wrapper around atoi
- */
-int StrToi(const StrBuf *Buf)
-{
+
+// Wrapper around atoi
+int StrToi(const StrBuf *Buf) {
if (Buf == NULL)
return 0;
if (Buf->BufUsed > 0)
return 0;
}
-/**
- * Checks to see if the string is a pure number
- * Buf The buffer to inspect
- * @returns 1 if its a pure number, 0, if not.
- */
+
+// Checks to see if the string is a pure number
+// Buf The buffer to inspect
+// returns 1 if its a pure number, 0, if not.
int StrBufIsNumber(const StrBuf *Buf) {
char * pEnd;
if ((Buf == NULL) || (Buf->BufUsed == 0)) {
return 0;
}
-/**
- * modifies a Single char of the Buf
- * You can point to it via char* or a zero-based integer
- * Buf The buffer to manipulate
- * ptr char* to zero; use NULL if unused
- * nThChar zero based pointer into the string; use -1 if unused
- * PeekValue The Character to place into the position
- */
-long StrBufPeek(StrBuf *Buf, const char* ptr, long nThChar, char PeekValue)
-{
+
+// modifies a Single char of the Buf
+// You can point to it via char* or a zero-based integer
+// Buf The buffer to manipulate
+// ptr char* to zero; use NULL if unused
+// nThChar zero based pointer into the string; use -1 if unused
+// PeekValue The Character to place into the position
+long StrBufPeek(StrBuf *Buf, const char* ptr, long nThChar, char PeekValue) {
if (Buf == NULL)
return -1;
if (ptr != NULL)
return nThChar;
}
-/**
- * modifies a range of chars of the Buf
- * You can point to it via char* or a zero-based integer
- * Buf The buffer to manipulate
- * ptr char* to zero; use NULL if unused
- * nThChar zero based pointer into the string; use -1 if unused
- * nChars how many chars are to be flushed?
- * PookValue The Character to place into that area
- */
-long StrBufPook(StrBuf *Buf, const char* ptr, long nThChar, long nChars, char PookValue)
-{
+
+// modifies a range of chars of the Buf
+// You can point to it via char* or a zero-based integer
+// Buf The buffer to manipulate
+// ptr char* to zero; use NULL if unused
+// nThChar zero based pointer into the string; use -1 if unused
+// nChars how many chars are to be flushed?
+// PookValue The Character to place into that area
+long StrBufPook(StrBuf *Buf, const char* ptr, long nThChar, long nChars, char PookValue) {
if (Buf == NULL)
return -1;
if (ptr != NULL)
nChars = Buf->BufUsed - nThChar;
memset(Buf->buf + nThChar, PookValue, nChars);
- /* just to be shure... */
+ // just to be sure...
Buf->buf[Buf->BufUsed] = 0;
return nChars;
}
-/**
- * Append a StringBuffer to the buffer
- * Buf Buffer to modify
- * AppendBuf Buffer to copy at the end of our buffer
- * Offset Should we start copying from an offset?
- */
-void StrBufAppendBuf(StrBuf *Buf, const StrBuf *AppendBuf, unsigned long Offset)
-{
- if ((AppendBuf == NULL) || (AppendBuf->buf == NULL) ||
- (Buf == NULL) || (Buf->buf == NULL))
+
+// Append a StringBuffer to the buffer
+// Buf Buffer to modify
+// AppendBuf Buffer to copy at the end of our buffer
+// Offset Should we start copying from an offset?
+void StrBufAppendBuf(StrBuf *Buf, const StrBuf *AppendBuf, unsigned long Offset) {
+ if ((AppendBuf == NULL) || (AppendBuf->buf == NULL) || (Buf == NULL) || (Buf->buf == NULL)) {
return;
+ }
if (Buf->BufSize - Offset < AppendBuf->BufUsed + Buf->BufUsed + 1)
IncreaseBuf(Buf, (Buf->BufUsed > 0), AppendBuf->BufUsed + Buf->BufUsed);
IncreaseBuf(Buf, (Buf->BufUsed > 0), BufSizeRequired);
}
- memcpy(Buf->buf + Buf->BufUsed,
- AppendBuf + Offset,
- aps);
+ memcpy(Buf->buf + Buf->BufUsed, AppendBuf + Offset, aps);
Buf->BufUsed += aps;
Buf->buf[Buf->BufUsed] = '\0';
}
-/*
- * sprintf like function appending the formated string to the buffer
- * vsnprintf version to wrap into own calls
- * Buf Buffer to extend by format and Params
- * format printf alike format to add
- * ap va_list containing the items for format
- */
-void StrBufVAppendPrintf(StrBuf *Buf, const char *format, va_list ap)
-{
+
+// sprintf like function appending the formated string to the buffer
+// vsnprintf version to wrap into own calls
+// Buf Buffer to extend by format and Params
+// format printf alike format to add
+// ap va_list containing the items for format
+void StrBufVAppendPrintf(StrBuf *Buf, const char *format, va_list ap) {
va_list apl;
size_t BufSize;
size_t nWritten;
while (newused >= BufSize) {
va_copy(apl, ap);
- nWritten = vsnprintf(Buf->buf + Offset,
- Buf->BufSize - Offset,
- format, apl);
+ nWritten = vsnprintf(Buf->buf + Offset, Buf->BufSize - Offset, format, apl);
va_end(apl);
newused = Offset + nWritten;
if (newused >= Buf->BufSize) {
if (IncreaseBuf(Buf, 1, newused) == -1)
- return; /* TODO: error handling? */
+ return; // TODO: error handling?
newused = Buf->BufSize + 1;
}
else {
}
}
-/**
- * sprintf like function appending the formated string to the buffer
- * Buf Buffer to extend by format and Params
- * format printf alike format to add
- */
-void StrBufAppendPrintf(StrBuf *Buf, const char *format, ...)
-{
+
+// sprintf like function appending the formated string to the buffer
+// Buf Buffer to extend by format and Params
+// format printf alike format to add
+void StrBufAppendPrintf(StrBuf *Buf, const char *format, ...) {
size_t BufSize;
size_t nWritten;
size_t Offset;
while (newused >= BufSize) {
va_start(arg_ptr, format);
- nWritten = vsnprintf(Buf->buf + Buf->BufUsed,
- Buf->BufSize - Buf->BufUsed,
- format, arg_ptr);
+ nWritten = vsnprintf(Buf->buf + Buf->BufUsed, Buf->BufSize - Buf->BufUsed, format, arg_ptr);
va_end(arg_ptr);
newused = Buf->BufUsed + nWritten;
if (newused >= Buf->BufSize) {
if (IncreaseBuf(Buf, 1, newused) == -1)
- return; /* TODO: error handling? */
+ return; // TODO: error handling?
newused = Buf->BufSize + 1;
}
else {
}
}
-/**
- * sprintf like function putting the formated string into the buffer
- * Buf Buffer to extend by format and Parameters
- * format printf alike format to add
- */
-void StrBufPrintf(StrBuf *Buf, const char *format, ...)
-{
+
+// sprintf like function putting the formated string into the buffer
+// Buf Buffer to extend by format and Parameters
+// format printf alike format to add
+void StrBufPrintf(StrBuf *Buf, const char *format, ...) {
size_t nWritten;
va_list arg_ptr;
va_end(arg_ptr);
if (nWritten >= Buf->BufSize) {
if (IncreaseBuf(Buf, 0, 0) == -1)
- return; /* TODO: error handling? */
+ return; // TODO: error handling?
nWritten = Buf->BufSize + 1;
continue;
}
}
}
-/**
- * Callback for cURL to append the webserver reply to a buffer
- * ptr pre-defined by the cURL API; see man 3 curl for mre info
- * size pre-defined by the cURL API; see man 3 curl for mre info
- * nmemb pre-defined by the cURL API; see man 3 curl for mre info
- * stream pre-defined by the cURL API; see man 3 curl for mre info
- */
-size_t CurlFillStrBuf_callback(void *ptr, size_t size, size_t nmemb, void *stream)
-{
+
+// Callback for cURL to append the webserver reply to a buffer
+// ptr, size, nmemb, and stream are pre-defined by the cURL API; see man 3 curl for more info
+size_t CurlFillStrBuf_callback(void *ptr, size_t size, size_t nmemb, void *stream) {
StrBuf *Target;
}
-/**
- * extracts a substring from Source into dest
- * dest buffer to place substring into
- * Source string to copy substring from
- * Offset chars to skip from start
- * nChars number of chars to copy
- * @returns the number of chars copied; may be different from nChars due to the size of Source
- */
-int StrBufSub(StrBuf *dest, const StrBuf *Source, unsigned long Offset, size_t nChars)
-{
+// extracts a substring from Source into dest
+// dest buffer to place substring into
+// Source string to copy substring from
+// Offset chars to skip from start
+// nChars number of chars to copy
+// returns the number of chars copied; may be different from nChars due to the size of Source
+int StrBufSub(StrBuf *dest, const StrBuf *Source, unsigned long Offset, size_t nChars) {
size_t NCharsRemain;
- if (Offset > Source->BufUsed)
- {
+ if (Offset > Source->BufUsed) {
if (dest != NULL)
FlushStrBuf(dest);
return 0;
}
- if (Offset + nChars < Source->BufUsed)
- {
- if ((nChars >= dest->BufSize) &&
- (IncreaseBuf(dest, 0, nChars + 1) == -1))
+ if (Offset + nChars < Source->BufUsed) {
+ if ((nChars >= dest->BufSize) && (IncreaseBuf(dest, 0, nChars + 1) == -1)) {
return 0;
+ }
memcpy(dest->buf, Source->buf + Offset, nChars);
dest->BufUsed = nChars;
dest->buf[dest->BufUsed] = '\0';
return nChars;
}
NCharsRemain = Source->BufUsed - Offset;
- if ((NCharsRemain >= dest->BufSize) &&
- (IncreaseBuf(dest, 0, NCharsRemain + 1) == -1))
+ if ((NCharsRemain >= dest->BufSize) && (IncreaseBuf(dest, 0, NCharsRemain + 1) == -1)) {
return 0;
+ }
memcpy(dest->buf, Source->buf + Offset, NCharsRemain);
dest->BufUsed = NCharsRemain;
dest->buf[dest->BufUsed] = '\0';
int delta = 0;
if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
- while ((Buf->BufUsed > 0) &&
- isspace(Buf->buf[Buf->BufUsed - 1]))
- {
+ while ((Buf->BufUsed > 0) && isspace(Buf->buf[Buf->BufUsed - 1])) {
Buf->BufUsed --;
}
Buf->buf[Buf->BufUsed] = '\0';
* ReplLen Length of repl
* @returns -1 if fail else length of resulting Buf
*/
-int StrBufReplaceToken(StrBuf *Buf, long where, long HowLong,
- const char *Repl, long ReplLen)
-{
+int StrBufReplaceToken(StrBuf *Buf, long where, long HowLong, const char *Repl, long ReplLen) {
- if ((Buf == NULL) ||
- (where > Buf->BufUsed) ||
- (where + HowLong > Buf->BufUsed))
+ if ((Buf == NULL) || (where > Buf->BufUsed) || (where + HowLong > Buf->BufUsed)) {
return -1;
+ }
- if (where + ReplLen - HowLong > Buf->BufSize)
- if (IncreaseBuf(Buf, 1, Buf->BufUsed + ReplLen) < 0)
+ if (where + ReplLen - HowLong > Buf->BufSize) {
+ if (IncreaseBuf(Buf, 1, Buf->BufUsed + ReplLen) < 0) {
return -1;
+ }
+ }
- memmove(Buf->buf + where + ReplLen,
- Buf->buf + where + HowLong,
- Buf->BufUsed - where - HowLong);
-
- memcpy(Buf->buf + where,
- Repl, ReplLen);
-
+ memmove(Buf->buf + where + ReplLen, Buf->buf + where + HowLong, Buf->BufUsed - where - HowLong);
+ memcpy(Buf->buf + where, Repl, ReplLen);
Buf->BufUsed += ReplLen - HowLong;
-
return Buf->BufUsed;
}
* tok Tokenizer char to count
* @returns numbers of tokenizer chars found
*/
-int StrBufNum_tokens(const StrBuf *source, char tok)
-{
+int StrBufNum_tokens(const StrBuf *source, char tok) {
char *pch, *pche;
long NTokens;
if ((source == NULL) || (source->BufUsed == 0))
/* Find desired eter */
end = Source->buf + Source->BufUsed;
d = Source->buf;
- while ((d <= end) &&
- (count < parmnum))
- {
+ while ((d <= end) && (count < parmnum)) {
/* End of string, bail! */
if (!*d) {
d = NULL;
/* Find next eter */
s = d;
- while ((s <= end) &&
- (*s && *s != separator))
- {
+ while ((s <= end) && (*s && *s != separator)) {
s++;
}
if (*s == separator)
break;
}
}
- if ( (current_token == parmnum) &&
- (*s != separator)) {
+ if ( (current_token == parmnum) && (*s != separator)) {
dest->buf[len] = *s;
++len;
}
* pStart the token iterator pointer to inspect
* @returns whether the revolving pointer is inside of the search range
*/
-int StrBufHaveNextToken(const StrBuf *Source, const char **pStart)
-{
- if ((Source == NULL) ||
- (*pStart == StrBufNOTNULL) ||
- (Source->BufUsed == 0))
- {
+int StrBufHaveNextToken(const StrBuf *Source, const char **pStart) {
+ if ((Source == NULL) || (*pStart == StrBufNOTNULL) || (Source->BufUsed == 0)) {
return 0;
}
- if (*pStart == NULL)
- {
+ if (*pStart == NULL) {
return 1;
}
- else if (*pStart > Source->buf + Source->BufUsed)
- {
+ else if (*pStart > Source->buf + Source->BufUsed) {
return 0;
}
- else if (*pStart <= Source->buf)
- {
+ else if (*pStart <= Source->buf) {
return 0;
}
* separator tokenizer
* @returns -1 if not found, else length of token.
*/
-int StrBufExtract_NextToken(StrBuf *dest, const StrBuf *Source, const char **pStart, char separator)
-{
+int StrBufExtract_NextToken(StrBuf *dest, const StrBuf *Source, const char **pStart, char separator) {
const char *s; /* source */
const char *EndBuffer; /* end stop of source buffer */
int current_token = 0; /* token currently being processed */
int len = 0; /* running total length of extracted string */
- if ((Source == NULL) ||
- (Source->BufUsed == 0) )
- {
+ if ((Source == NULL) || (Source->BufUsed == 0)) {
*pStart = StrBufNOTNULL;
- if (dest != NULL)
+ if (dest != NULL) {
FlushStrBuf(dest);
+ }
return -1;
}
EndBuffer = Source->buf + Source->BufUsed;
- if (dest != NULL)
- {
+ if (dest != NULL) {
dest->buf[0] = '\0';
dest->BufUsed = 0;
}
- else
- {
+ else {
*pStart = EndBuffer + 1;
return -1;
}
- if (*pStart == NULL)
- {
+ if (*pStart == NULL) {
*pStart = Source->buf; /* we're starting to examine this buffer. */
}
- else if ((*pStart < Source->buf) ||
- (*pStart > EndBuffer ) )
- {
+ else if ((*pStart < Source->buf) || (*pStart > EndBuffer ) ) {
return -1; /* no more tokens to find. */
}
s = *pStart;
/* start to find the next token */
- while ((s <= EndBuffer) &&
- (current_token == 0) )
- {
- if (*s == separator)
- {
+ while ((s <= EndBuffer) && (current_token == 0) ) {
+ if (*s == separator) {
/* we found the next token */
++current_token;
}
- if (len >= dest->BufSize)
- {
+ if (len >= dest->BufSize) {
/* our Dest-buffer isn't big enough, increase it. */
dest->BufUsed = len;
* nTokens number of tokens to fastforward over
* @returns -1 if not found, else length of token.
*/
-int StrBufSkip_NTokenS(const StrBuf *Source, const char **pStart, char separator, int nTokens)
-{
+int StrBufSkip_NTokenS(const StrBuf *Source, const char **pStart, char separator, int nTokens) {
const char *s, *EndBuffer; //* source * /
int len = 0; //* running total length of extracted string * /
int current_token = 0; //* token currently being processed * /
- if ((Source == NULL) ||
- (Source->BufUsed ==0)) {
+ if ((Source == NULL) || (Source->BufUsed ==0)) {
return(-1);
}
if (nTokens == 0)
return (-1);
}
-
s = *pStart;
- //cit_backtrace();
- //lprintf (CTDL_DEBUG, "test >: n: %d sep: %c source: %s \n willi \n", parmnum, separator, source);
-
while ((s < EndBuffer) && !IsEmptyStr(s)) {
if (*s == separator) {
++current_token;
return(len);
}
-/**
- * a string tokenizer to fetch an integer
- * Source StringBuffer to read from
- * pStart Cursor on the tokenstring
- * separator tokenizer character
- * @returns 0 if not found, else integer representation of the token
- */
-int StrBufExtractNext_int(const StrBuf* Source, const char **pStart, char separator)
-{
+
+// a string tokenizer to fetch an integer
+// Source StringBuffer to read from
+// pStart Cursor on the tokenstring
+// separator tokenizer character
+// returns 0 if not found, else integer representation of the token
+int StrBufExtractNext_int(const StrBuf* Source, const char **pStart, char separator) {
StrBuf tmp;
char buf[64];
return 0;
}
-/**
- * a string tokenizer to fetch a long integer
- * Source StringBuffer to read from
- * pStart Cursor on the tokenstring
- * separator tokenizer character
- * @returns 0 if not found, else long integer representation of the token
- */
-long StrBufExtractNext_long(const StrBuf* Source, const char **pStart, char separator)
-{
+
+// a string tokenizer to fetch a long integer
+// Source StringBuffer to read from
+// pStart Cursor on the tokenstring
+// separator tokenizer character
+// returns 0 if not found, else long integer representation of the token
+long StrBufExtractNext_long(const StrBuf* Source, const char **pStart, char separator) {
StrBuf tmp;
char buf[64];
}
-/**
- * a string tokenizer to fetch an unsigned long
- * Source StringBuffer to read from
- * pStart Cursor on the tokenstring
- * separator tokenizer character
- * @returns 0 if not found, else unsigned long representation of the token
- */
-unsigned long StrBufExtractNext_unsigned_long(const StrBuf* Source, const char **pStart, char separator)
-{
+// a string tokenizer to fetch an unsigned long
+// Source StringBuffer to read from
+// pStart Cursor on the tokenstring
+// separator tokenizer character
+// returns 0 if not found, else unsigned long representation of the token
+unsigned long StrBufExtractNext_unsigned_long(const StrBuf* Source, const char **pStart, char separator) {
StrBuf tmp;
char buf[64];
char *pnum;
}
-
-
-
/*******************************************************************************
* Escape Appending *
*******************************************************************************/
-/**
- * Escape a string for feeding out as a URL while appending it to a Buffer
- * OutBuf the output buffer
- * In Buffer to encode
- * PlainIn way in from plain old c strings
- */
-void StrBufUrlescAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn)
-{
+// Escape a string for feeding out as a URL while appending it to a Buffer
+// OutBuf the output buffer
+// In Buffer to encode
+// PlainIn way in from plain old c strings
+void StrBufUrlescAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn) {
const char *pch, *pche;
char *pt, *pte;
int len;
- if (((In == NULL) && (PlainIn == NULL)) || (OutBuf == NULL) )
+ if (((In == NULL) && (PlainIn == NULL)) || (OutBuf == NULL) ) {
return;
+ }
if (PlainIn != NULL) {
len = strlen(PlainIn);
pch = PlainIn;
}
-/*
- * Escape a string for feeding out as a the username/password part of an URL while appending it to a Buffer
- * OutBuf the output buffer
- * In Buffer to encode
- * PlainIn way in from plain old c strings
- */
+// Escape a string for feeding out as a the username/password part of an URL while appending it to a Buffer
+// OutBuf the output buffer
+// In Buffer to encode
+// PlainIn way in from plain old c strings
void StrBufUrlescUPAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn) {
const char *pch, *pche;
char *pt, *pte;
*pt = '\0';
}
-/*
- * append a string with characters having a special meaning in xml encoded to the buffer
- * OutBuf the output buffer
- * In Buffer to encode
- * PlainIn way in from plain old c strings
- * PlainInLen way in from plain old c strings; maybe you've got binary data or know the length?
- * OverrideLowChars should chars < 0x20 be replaced by _ or escaped as xml entity?
- */
+
+// append a string with characters having a special meaning in xml encoded to the buffer
+// OutBuf the output buffer
+// In Buffer to encode
+// PlainIn way in from plain old c strings
+// PlainInLen way in from plain old c strings; maybe you've got binary data or know the length?
+// OverrideLowChars should chars < 0x20 be replaced by _ or escaped as xml entity?
void StrBufXMLEscAppend(StrBuf *OutBuf,
const StrBuf *In,
const char *PlainIn,
return Target->BufUsed;
}
-/**
- * Append a string, escaping characters which have meaning in HTML + json.
- *
- * Target target buffer
- * Source source buffer; set to NULL if you just have a C-String
- * PlainIn Plain-C string to append; set to NULL if unused
- * nbsp If nonzero, spaces are converted to non-breaking spaces.
- * nolinebreaks if set to 1, linebreaks are removed from the string.
- * if set to 2, linebreaks are replaced by <br/>
- */
-long StrHtmlEcmaEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks)
-{
+// Append a string, escaping characters which have meaning in HTML + json.
+//
+// Target target buffer
+// Source source buffer; set to NULL if you just have a C-String
+// PlainIn Plain-C string to append; set to NULL if unused
+// nbsp If nonzero, spaces are converted to non-breaking spaces.
+// nolinebreaks if set to 1, linebreaks are removed from the string.
+// if set to 2, linebreaks are replaced by <br/>
+long StrHtmlEcmaEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks) {
const char *aptr, *eiptr;
char *bptr, *eptr;
long len;
int IsUtf8Sequence = 0;
- if (((Source == NULL) && (PlainIn == NULL)) || (Target == NULL) )
+ if (((Source == NULL) && (PlainIn == NULL)) || (Target == NULL)) {
return -1;
-
+ }
if (PlainIn != NULL) {
aptr = PlainIn;
len = strlen(PlainIn);
len = Source->BufUsed;
}
- if (len == 0)
+ if (len == 0) {
return -1;
+ }
bptr = Target->buf + Target->BufUsed;
- eptr = Target->buf + Target->BufSize - 11; /* our biggest unit to put in... */
+ eptr = Target->buf + Target->BufSize - 11; // our biggest unit to put in...
- while (aptr < eiptr){
+ while (aptr < eiptr) {
if(bptr >= eptr) {
IncreaseBuf(Target, 1, -1);
- eptr = Target->buf + Target->BufSize - 11; /* our biggest unit to put in... */
+ eptr = Target->buf + Target->BufSize - 11; // our biggest unit to put in...
bptr = Target->buf + Target->BufUsed;
}
switch (*aptr) {
isxdigit(*(aptr + 3)) &&
isxdigit(*(aptr + 4)) &&
isxdigit(*(aptr + 5)))
- { /* oh, a unicode escaper. let it pass through. */
+ { /* oh, a unicode escaper. let it pass through. */
memcpy(bptr, aptr, 6);
aptr += 5;
bptr +=6;
Target->BufUsed += 6;
}
- else
- {
+ else {
*bptr = '\\';
bptr ++;
*bptr = '\\';
bptr ++;
Target->BufUsed += 2;
break;
- case 32:
+ case 32:
if (nbsp == 1) {
memcpy(bptr, HKEY(" "));
bptr += 6;
}
-/*
- * unhide special chars hidden to the HTML escaper
- * target buffer to put the unescaped string in
- * source buffer to unescape
- */
+
+// unhide special chars hidden to the HTML escaper
+// target buffer to put the unescaped string in
+// source buffer to unescape
void StrBufEUid_unescapize(StrBuf *target, const StrBuf *source) {
int a, b, len;
char hex[3];
if (target != NULL)
FlushStrBuf(target);
- if ((source == NULL) || (target == NULL) || (target->buf == NULL))
- {
+ if ((source == NULL) || (target == NULL) || (target->buf == NULL)) {
return;
}
vStreamT *StrBufNewStreamContext(eStreamType type, const char **Err) {
- //base64_decodestate *state;;
*Err = NULL;
switch (type) {
- //case eBase64Decode:
- //case eBase64Encode:
- //state = (base64_decodestate*) malloc(sizeof(base64_decodestate));
- //base64_init_decodestate(state);
- //return (vStreamT*) state;
- //break;
-
case eZLibDecode: {
z_enc_stream *stream;
return (*target)->BufUsed;;
}
-/**
- * Quoted-Printable encode a message; make it < 80 columns width.
- * source Source string to be encoded.
- * @returns buffer with encoded message.
- */
-StrBuf *StrBufRFC2047encodeMessage(const StrBuf *EncodeMe)
-{
+// Quoted-Printable encode a message; make it < 80 columns width.
+// source Source string to be encoded.
+// returns buffer with encoded message.
+StrBuf *StrBufQuotedPrintableEncode(const StrBuf *EncodeMe) {
StrBuf *OutBuf;
char *Optr, *OEptr;
const char *ptr, *eptr;
eptr = EncodeMe->buf + EncodeMe->BufUsed;
LinePos = 0;
- while (ptr < eptr)
- {
- if (Optr + 4 >= OEptr)
- {
+ while (ptr < eptr) {
+ if (Optr + 4 >= OEptr) {
long Offset;
Offset = Optr - OutBuf->buf;
OutBuf->BufUsed = Optr - OutBuf->buf;
Optr = OutBuf->buf + Offset;
OEptr = OutBuf->buf + OutBuf->BufSize;
}
- if (*ptr == '\r')
- {
- /* ignore carriage returns */
+ if (*ptr == '\r') { // ignore carriage returns
ptr ++;
}
- else if (*ptr == '\n') {
- /* hard line break */
+ else if (*ptr == '\n') { // hard line break
memcpy(Optr, HKEY("=0A"));
Optr += 3;
LinePos += 3;
ptr ++;
}
- else if (( (*ptr >= 32) && (*ptr <= 60) ) ||
- ( (*ptr >= 62) && (*ptr <= 126) ))
- {
+ else if (( (*ptr >= 32) && (*ptr <= 60) ) || ( (*ptr >= 62) && (*ptr <= 126) )) {
*Optr = *ptr;
Optr ++;
ptr ++;
ptr ++;
}
- if (LinePos > 72) {
- /* soft line break */
+ if (LinePos > 72) { // soft line break
if (isspace(*(Optr - 1))) {
ch = *(Optr - 1);
Optr --;
}
-static void AddRecipient(StrBuf *Target,
- StrBuf *UserName,
- StrBuf *EmailAddress,
- StrBuf *EncBuf)
-{
+static void AddRecipient(StrBuf *Target, StrBuf *UserName, StrBuf *EmailAddress, StrBuf *EncBuf) {
int QuoteMe = 0;
if (StrLength(Target) > 0) StrBufAppendBufPlain(Target, HKEY(", "), 0);
* \param EncBuf Temporary buffer for internal use; Please provide valid buffer.
* \returns encoded & sanitized buffer with the contents of Recp; Caller owns this memory.
*/
-StrBuf *StrBufSanitizeEmailRecipientVector(const StrBuf *Recp,
- StrBuf *UserName,
- StrBuf *EmailAddress,
- StrBuf *EncBuf)
-{
+StrBuf *StrBufSanitizeEmailRecipientVector(const StrBuf *Recp, StrBuf *UserName, StrBuf *EmailAddress, StrBuf *EncBuf) {
StrBuf *Target;
const char *pch, *pche;
const char *UserStart, *UserEnd, *EmailStart, *EmailEnd, *At;
* search character to search
* replace character to replace search by
*/
-void StrBufReplaceChars(StrBuf *buf, char search, char replace)
-{
+void StrBufReplaceChars(StrBuf *buf, char search, char replace) {
long i;
if (buf == NULL)
return;
}
-
-
-
/*******************************************************************************
* wrapping ZLib *
*******************************************************************************/
return 0;
}
+
/*******************************************************************************
* File I/O; Callbacks to libevent *
*******************************************************************************/
* where a cut left is inexpensive
*/
- if (FB->ReadWritePointer != NULL)
- {
+ if (FB->ReadWritePointer != NULL) {
long already_read;
already_read = FB->ReadWritePointer - FB->Buf->buf;
FB->ReadWritePointer = FB->Buf->buf;
bufremain = FB->Buf->BufSize;
}
- else if ((unread < 64) ||
- (bufremain < already_read))
- {
+ else if ((unread < 64) || (bufremain < already_read)) {
/*
* if its just a tiny bit remaining, or we run out of space...
* lets tidy up.
FB->ReadWritePointer = FB->Buf->buf;
bufremain = FB->Buf->BufSize - unread - 1;
}
- else if (bufremain < (FB->Buf->BufSize / 10))
- {
+ else if (bufremain < (FB->Buf->BufSize / 10)) {
/* get a bigger buffer */
IncreaseBuf(FB->Buf, 0, FB->Buf->BufUsed + 1);
return n;
}
-int StrBuf_write_one_chunk_callback(int fd, short event, IOBuffer *FB)
-{
+
+int StrBuf_write_one_chunk_callback(int fd, short event, IOBuffer *FB) {
long WriteRemain;
int n;
return n;
}
-/**
- * extract a "next line" from Buf; Ptr to persist across several iterations
- * LineBuf your line will be copied here.
- * FB BLOB with lines of text...
- * Ptr moved arround to keep the next-line across several iterations
- * has to be &NULL on start; will be &NotNULL on end of buffer
- * @returns size of copied buffer
- */
-eReadState StrBufChunkSipLine(StrBuf *LineBuf, IOBuffer *FB)
-{
+
+// extract a "next line" from Buf; Ptr to persist across several iterations
+// LineBuf your line will be copied here.
+// FB BLOB with lines of text...
+// Ptr moved arround to keep the next-line across several iterations
+// has to be &NULL on start; will be &NotNULL on end of buffer
+// returns size of copied buffer
+eReadState StrBufChunkSipLine(StrBuf *LineBuf, IOBuffer *FB) {
const char *aptr, *ptr, *eptr;
char *optr, *xptr;
eptr = FB->Buf->buf + FB->Buf->BufUsed;
xptr = LineBuf->buf + LineBuf->BufSize - 1;
- while ((ptr <= eptr) &&
- (*ptr != '\n') &&
- (*ptr != '\r') )
- {
+ while ((ptr <= eptr) && (*ptr != '\n') && (*ptr != '\r') ) {
*optr = *ptr;
optr++; ptr++;
if (optr == xptr) {
if ((*(ptr - 1) != '\r') && (*(ptr - 1) != '\n')) {
LineBuf->BufUsed = optr - LineBuf->buf;
*optr = '\0';
- if ((FB->ReadWritePointer != NULL) &&
- (FB->ReadWritePointer != FB->Buf->buf))
- {
- /* Ok, the client application read all the data
- it was interested in so far. Since there is more to read,
- we now shrink the buffer, and move the rest over.
- */
- StrBufCutLeft(FB->Buf,
- FB->ReadWritePointer - FB->Buf->buf);
+ if ((FB->ReadWritePointer != NULL) && (FB->ReadWritePointer != FB->Buf->buf)) {
+ // Ok, the client application read all the data
+ // it was interested in so far. Since there is more to read,
+ // we now shrink the buffer, and move the rest over.
+ StrBufCutLeft(FB->Buf, FB->ReadWritePointer - FB->Buf->buf);
FB->ReadWritePointer = FB->Buf->buf;
}
return eMustReadMore;
return eReadSuccess;
}
-long IOBufferStrLength(IOBuffer *FB)
-{
+
+long IOBufferStrLength(IOBuffer *FB) {
if ((FB == NULL) || (FB->Buf == NULL))
return 0;
if (FB->ReadWritePointer == NULL)
}
-/**
- * Read a line from socket
- * flushes and closes the FD on error
- * Line the line to read from the fd / I/O Buffer
- * buf the buffer to get the input to
- * fd pointer to the filedescriptor to read
- * timeout number of successless selects until we bail out
- * selectresolution how long to wait on each select
- * Error strerror() on error
- * @returns numbers of chars read
- */
+// Read a line from socket
+// flushes and closes the FD on error
+// Line the line to read from the fd / I/O Buffer
+// buf the buffer to get the input to
+// fd pointer to the filedescriptor to read
+// timeout number of successless selects until we bail out
+// selectresolution how long to wait on each select
+// Error strerror() on error
+// returns numbers of chars read
int StrBufTCP_read_buffered_line(StrBuf *Line,
StrBuf *buf,
int *fd,
if (pch != NULL) {
rlen = 0;
len = pch - buf->buf;
- if (len > 0 && (*(pch - 1) == '\r') )
+ if (len > 0 && (*(pch - 1) == '\r') ) {
rlen ++;
+ }
StrBufSub(Line, buf, 0, len - rlen);
StrBufCutLeft(buf, len + 1);
return len - rlen;
}
}
- if (buf->BufSize - buf->BufUsed < 10)
+ if (buf->BufSize - buf->BufUsed < 10) {
IncreaseBuf(buf, 1, -1);
+ }
fdflags = fcntl(*fd, F_GETFL);
IsNonBlock = (fdflags & O_NONBLOCK) == O_NONBLOCK;
nSuccessLess ++;
continue;
}
- rlen = read(*fd,
- &buf->buf[buf->BufUsed],
- buf->BufSize - buf->BufUsed - 1);
+ rlen = read(*fd, &buf->buf[buf->BufUsed], buf->BufSize - buf->BufUsed - 1);
if (rlen < 1) {
*Error = strerror(errno);
close(*fd);
buf->BufUsed += rlen;
buf->buf[buf->BufUsed] = '\0';
pch = strchr(buf->buf, '\n');
- if ((pch == NULL) &&
- (buf->BufUsed + 10 > buf->BufSize) &&
- (IncreaseBuf(buf, 1, -1) == -1))
+ if ((pch == NULL) && (buf->BufUsed + 10 > buf->BufSize) && (IncreaseBuf(buf, 1, -1) == -1)) {
return -1;
+ }
continue;
}
static const char *ErrRBLF_PreConditionFailed="StrBufTCP_read_buffered_line_fast: Wrong arguments or invalid Filedescriptor";
static const char *ErrRBLF_SelectFailed="StrBufTCP_read_buffered_line_fast: Select failed without reason";
static const char *ErrRBLF_NotEnoughSentFromServer="StrBufTCP_read_buffered_line_fast: No complete line was sent from peer";
-/**
- * Read a line from socket
- * flushes and closes the FD on error
- * Line where to append our Line read from the fd / I/O Buffer;
- * IOBuf the buffer to get the input to; lifetime pair to FD
- * Pos pointer to the current read position, should be NULL initialized on opening the FD it belongs to.!
- * fd pointer to the filedescriptor to read
- * timeout number of successless selects until we bail out
- * selectresolution how long to wait on each select
- * Error strerror() on error
- * @returns numbers of chars read or -1 in case of error. "\n" will become 0
- */
+
+
+// Read a line from socket
+// flushes and closes the FD on error
+// Line where to append our Line read from the fd / I/O Buffer;
+// IOBuf the buffer to get the input to; lifetime pair to FD
+// Pos pointer to the current read position, should be NULL initialized on opening the FD it belongs to.!
+// fd pointer to the filedescriptor to read
+// timeout number of successless selects until we bail out
+// selectresolution how long to wait on each select
+// Error strerror() on error
+// returns numbers of chars read or -1 in case of error. "\n" will become 0
int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
StrBuf *IOBuf,
const char **Pos,
struct timeval tv;
retlen = 0;
- if ((Line == NULL) ||
- (Pos == NULL) ||
- (IOBuf == NULL) ||
- (*fd == -1))
- {
- if (Pos != NULL)
+ if ((Line == NULL) || (Pos == NULL) || (IOBuf == NULL) || (*fd == -1)) {
+ if (Pos != NULL) {
*Pos = NULL;
+ }
*Error = ErrRBLF_PreConditionFailed;
return -1;
}
pos = *Pos;
- if ((IOBuf->BufUsed > 0) &&
- (pos != NULL) &&
- (pos < IOBuf->buf + IOBuf->BufUsed))
- {
+ if ((IOBuf->BufUsed > 0) && (pos != NULL) && (pos < IOBuf->buf + IOBuf->BufUsed)) {
char *pcht;
pche = IOBuf->buf + IOBuf->BufUsed;
pch = pos;
pcht = Line->buf;
- while ((pch < pche) && (*pch != '\n'))
- {
- if (Line->BufUsed + 10 > Line->BufSize)
- {
+ while ((pch < pche) && (*pch != '\n')) {
+ if (Line->BufUsed + 10 > Line->BufSize) {
long apos;
apos = pcht - Line->buf;
*pcht = '\0';
}
len = pch - pos;
- if (len > 0 && (*(pch - 1) == '\r') )
- {
+ if (len > 0 && (*(pch - 1) == '\r') ) {
retlen--;
len --;
pcht --;
}
*pcht = '\0';
- if ((pch >= pche) || (*pch == '\0'))
- {
+ if ((pch >= pche) || (*pch == '\0')) {
FlushStrBuf(IOBuf);
*Pos = NULL;
pch = NULL;
pos = 0;
}
- if ((pch != NULL) &&
- (pch <= pche))
- {
+ if ((pch != NULL) && (pch <= pche)) {
if (pch + 1 >= pche) {
*Pos = NULL;
FlushStrBuf(IOBuf);
}
- else
+ else {
*Pos = pch + 1;
-
+ }
return retlen;
}
else
/* If we come here, Pos is Unset since we read everything into Line, and now go for more. */
- if (IOBuf->BufSize - IOBuf->BufUsed < 10)
+ if (IOBuf->BufSize - IOBuf->BufUsed < 10) {
IncreaseBuf(IOBuf, 1, -1);
+ }
fdflags = fcntl(*fd, F_GETFL);
IsNonBlock = (fdflags & O_NONBLOCK) == O_NONBLOCK;
while ((nSuccessLess < timeout) &&
(pLF == NULL) &&
(*fd != -1)) {
- if (IsNonBlock)
- {
+ if (IsNonBlock) {
tv.tv_sec = 1;
tv.tv_usec = 0;
continue;
}
}
- rlen = read(*fd,
- &IOBuf->buf[IOBuf->BufUsed],
- IOBuf->BufSize - IOBuf->BufUsed - 1);
+ rlen = read(*fd, &IOBuf->buf[IOBuf->BufUsed], IOBuf->BufSize - IOBuf->BufUsed - 1);
if (rlen < 1) {
*Error = strerror(errno);
close(*fd);
if ((pLF >= pche) || (*pLF == '\0'))
pLF = NULL;
- if (IOBuf->BufUsed + 10 > IOBuf->BufSize)
- {
+ if (IOBuf->BufUsed + 10 > IOBuf->BufSize) {
long apos = 0;
if (pLF != NULL) apos = pLF - IOBuf->buf;
continue;
}
- else
- {
+ else {
nSuccessLess++;
}
}
if (pLF != NULL) {
pos = IOBuf->buf;
len = pLF - pos;
- if (len > 0 && (*(pLF - 1) == '\r') )
+ if (len > 0 && (*(pLF - 1) == '\r') ) {
len --;
+ }
StrBufAppendBufPlain(Line, ChrPtr(IOBuf), len, 0);
- if (pLF + 1 >= IOBuf->buf + IOBuf->BufUsed)
- {
+ if (pLF + 1 >= IOBuf->buf + IOBuf->BufUsed) {
FlushStrBuf(IOBuf);
}
else
struct timeval tv;
fd_set rfds;
- if ((Buf == NULL) || (Buf->buf == NULL) || (*fd == -1))
- {
+ if ((Buf == NULL) || (Buf->buf == NULL) || (*fd == -1)) {
*Error = ErrRBLF_BLOBPreConditionFailed;
return -1;
}
- if (!append)
+ if (!append) {
FlushStrBuf(Buf);
- if (Buf->BufUsed + nBytes >= Buf->BufSize)
+ }
+ if (Buf->BufUsed + nBytes >= Buf->BufSize) {
IncreaseBuf(Buf, 1, Buf->BufUsed + nBytes);
-
+ }
ptr = Buf->buf + Buf->BufUsed;
fdflags = fcntl(*fd, F_GETFL);
IsNonBlock = (fdflags & O_NONBLOCK) == O_NONBLOCK;
nSuccessLess = 0;
- while ((nRead < nBytes) &&
- (*fd != -1))
- {
- if (IsNonBlock)
- {
+ while ((nRead < nBytes) && (*fd != -1)) {
+ if (IsNonBlock) {
tv.tv_sec = 1;
tv.tv_usec = 0;
*Error = strerror(errno);
close (*fd);
*fd = -1;
- if (*Error == NULL)
+ if (*Error == NULL) {
*Error = ErrRBLF_SelectFailed;
+ }
return -1;
}
if (! FD_ISSET(*fd, &rfds) != 0) {
const char *ErrRBB_BLOBFPreConditionFailed = "StrBufReadBLOBBuffered: to many selects; aborting.";
const char *ErrRBB_too_many_selects = "StrBufReadBLOBBuffered: to many selects; aborting.";
-/**
- * Input binary data from socket
- * flushes and closes the FD on error
- * Blob put binary thing here
- * IOBuf the buffer to get the input to
- * Pos offset inside of IOBuf
- * fd pointer to the filedescriptor to read
- * append Append to an existing string or replace?
- * nBytes the maximal number of bytes to read
- * check whether we should search for '000\n' terminators in case of timeouts
- * Error strerror() on error
- * @returns numbers of chars read
- */
+
+
+// Input binary data from socket
+// flushes and closes the FD on error
+// Blob put binary thing here
+// IOBuf the buffer to get the input to
+// Pos offset inside of IOBuf
+// fd pointer to the filedescriptor to read
+// append Append to an existing string or replace?
+// nBytes the maximal number of bytes to read
+// check whether we should search for '000\n' terminators in case of timeouts
+// Error strerror() on error
+// returns numbers of chars read
int StrBufReadBLOBBuffered(StrBuf *Blob,
StrBuf *IOBuf,
const char **Pos,
int nSuccessLess = 0;
int MaxTries;
- if ((Blob == NULL) ||
- (*fd == -1) ||
- (IOBuf == NULL) ||
- (Pos == NULL))
- {
+ if ((Blob == NULL) || (*fd == -1) || (IOBuf == NULL) || (Pos == NULL)) {
if (Pos != NULL)
*Pos = NULL;
*Error = ErrRBB_BLOBFPreConditionFailed;
rlen = IOBuf->BufUsed - rlen;
- if ((IOBuf->BufUsed > 0) && (pos != NULL) && (pos < IOBuf->buf + IOBuf->BufUsed))
- {
+ if ((IOBuf->BufUsed > 0) && (pos != NULL) && (pos < IOBuf->buf + IOBuf->BufUsed)) {
if (rlen < nBytes) {
memcpy(Blob->buf + Blob->BufUsed, pos, rlen);
Blob->BufUsed += rlen;
}
}
rlen = read(*fd, ptr, IOBuf->BufSize - (ptr - IOBuf->buf));
- // if (rlen == -1) { 2021feb27 ajc changed this, apparently we will always get at least 1 byte unless the connection is broken
- if (rlen < 1) {
+ if (rlen < 1) { // We will always get at least 1 byte unless the connection is broken
close(*fd);
*fd = -1;
*Error = strerror(errno);
return nRead + nAlreadyRead;
}
-/**
- * extract a "next line" from Buf; Ptr to persist across several iterations
- * LineBuf your line will be copied here.
- * Buf BLOB with lines of text...
- * Ptr moved arround to keep the next-line across several iterations
- * has to be &NULL on start; will be &NotNULL on end of buffer
- * @returns size of remaining buffer
- */
-int StrBufSipLine(StrBuf *LineBuf, const StrBuf *Buf, const char **Ptr)
-{
+
+// extract a "next line" from Buf; Ptr to persist across several iterations
+// LineBuf your line will be copied here.
+// Buf BLOB with lines of text...
+// Ptr moved arround to keep the next-line across several iterations
+// has to be &NULL on start; will be &NotNULL on end of buffer
+// returns size of remaining buffer
+int StrBufSipLine(StrBuf *LineBuf, const StrBuf *Buf, const char **Ptr) {
const char *aptr, *ptr, *eptr;
char *optr, *xptr;
- if ((Buf == NULL) ||
- (*Ptr == StrBufNOTNULL) ||
- (LineBuf == NULL)||
- (LineBuf->buf == NULL))
- {
+ if ((Buf == NULL) || (*Ptr == StrBufNOTNULL) || (LineBuf == NULL)|| (LineBuf->buf == NULL)) {
*Ptr = StrBufNOTNULL;
return 0;
}
eptr = Buf->buf + Buf->BufUsed;
xptr = LineBuf->buf + LineBuf->BufSize - 1;
- while ((ptr <= eptr) &&
- (*ptr != '\n') &&
- (*ptr != '\r') )
- {
+ while ((ptr <= eptr) && (*ptr != '\n') && (*ptr != '\r') ) {
*optr = *ptr;
optr++; ptr++;
if (optr == xptr) {
}
-/**
- * removes double slashes from pathnames
- * Dir directory string to filter
- * RemoveTrailingSlash allows / disallows trailing slashes
- */
-void StrBufStripSlashes(StrBuf *Dir, int RemoveTrailingSlash)
-{
+// removes double slashes from pathnames
+// Dir directory string to filter
+// RemoveTrailingSlash allows / disallows trailing slashes
+void StrBufStripSlashes(StrBuf *Dir, int RemoveTrailingSlash) {
char *a, *b;
a = b = Dir->buf;
}
-/*
- * Decode a quoted-printable encoded StrBuf buffer "in place"
- * This is possible because the decoded will always be shorter than the encoded
- * so we don't have to worry about the buffer being to small.
- */
-void StrBufDecodeQP(StrBuf *Buf)
-{
+// Decode a quoted-printable encoded StrBuf buffer "in place"
+// This is possible because the decoded will always be shorter than the encoded
+// so we don't have to worry about the buffer being to small.
+void StrBufDecodeQP(StrBuf *Buf) {
if (!Buf) { // sanity check #1
return;
}