]> code.citadel.org Git - citadel.git/blobdiff - libcitadel/lib/stringbuf.c
moved whitespace around
[citadel.git] / libcitadel / lib / stringbuf.c
index 3d8b3010d914a096c893177f37eb7604153014b6..b382025b957fc9d103d40877e1c30b835c56190b 100644 (file)
@@ -1,18 +1,7 @@
-// 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"
@@ -44,8 +33,7 @@
 
 #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;
@@ -77,18 +65,16 @@ const char HexList[256][3] = {
        "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
 };
 
@@ -105,22 +91,24 @@ static void StrBufBacktrace(StrBuf *Buf, int which) {
        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
 
@@ -136,21 +124,23 @@ void dbg_FreeStrBuf(StrBuf *FreeMe, char *FromWhere) {
                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);
        }
 }
@@ -528,7 +518,7 @@ int StrBufPlain(StrBuf *Buf, const char* ptr, int nChars) {
 }
 
 
-/**
+/*
  *  use strbuf as wrapper for a string constant for easy handling
  *  StringConstant a string to wrap
  *  SizeOfStrConstant should be sizeof(StringConstant)-1
@@ -551,22 +541,23 @@ StrBuf* _NewConstStrBuf(const char* StringConstant, size_t SizeOfStrConstant)
 }
 
 
-/**
+/*
  *  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
  */
@@ -586,7 +577,7 @@ int FLUSHStrBuf(StrBuf *buf)
 #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
@@ -650,11 +641,8 @@ void HFreeStrBuf (void *VFreeMe) {
  *                      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)
@@ -663,11 +651,9 @@ long StrTol(const StrBuf *Buf)
                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)
@@ -676,11 +662,10 @@ int StrToi(const StrBuf *Buf)
                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)) {
@@ -696,16 +681,14 @@ int StrBufIsNumber(const StrBuf *Buf) {
        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)
@@ -716,17 +699,15 @@ long StrBufPeek(StrBuf *Buf, const char* ptr, long nThChar, char PeekValue)
        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)
@@ -737,22 +718,20 @@ long StrBufPook(StrBuf *Buf, const char* ptr, long nThChar, long nChars, char Po
                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);
@@ -787,22 +766,18 @@ void StrBufAppendBufPlain(StrBuf *Buf, const char *AppendBuf, long AppendSize, u
                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;
@@ -819,14 +794,12 @@ void StrBufVAppendPrintf(StrBuf *Buf, const char *format, va_list ap)
        
        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 {
@@ -837,13 +810,11 @@ void StrBufVAppendPrintf(StrBuf *Buf, const char *format, va_list ap)
        }
 }
 
-/**
- *  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;
@@ -860,14 +831,12 @@ void StrBufAppendPrintf(StrBuf *Buf, const char *format, ...)
 
        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 {
@@ -878,13 +847,11 @@ void StrBufAppendPrintf(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, ...)
-{
+
+//  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;
        
@@ -898,7 +865,7 @@ void StrBufPrintf(StrBuf *Buf, const char *format, ...)
                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;
                }
@@ -906,15 +873,10 @@ void StrBufPrintf(StrBuf *Buf, const char *format, ...)
        }
 }
 
-/**
- *  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;
 
@@ -927,37 +889,32 @@ size_t CurlFillStrBuf_callback(void *ptr, size_t size, size_t nmemb, void *strea
 }
 
 
-/**
- *  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';
@@ -1028,9 +985,7 @@ void StrBufTrim(StrBuf *Buf)
        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';
@@ -1134,28 +1089,21 @@ void StrBufLowerCase(StrBuf *Buf)
  *  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;
 }
 
@@ -1165,8 +1113,7 @@ int StrBufReplaceToken(StrBuf *Buf, long where, long HowLong,
  *  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))
@@ -1201,9 +1148,7 @@ int StrBufRemove_token(StrBuf *Source, int parmnum, char separator)
        /* 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;
@@ -1219,9 +1164,7 @@ int StrBufRemove_token(StrBuf *Source, int parmnum, char separator)
 
        /* Find next eter */
        s = d;
-       while ((s <= end) && 
-              (*s && *s != separator))
-       {
+       while ((s <= end) && (*s && *s != separator)) {
                s++;
        }
        if (*s == separator)
@@ -1313,8 +1256,7 @@ int StrBufExtract_token(StrBuf *dest, const StrBuf *Source, int parmnum, char se
                                break;
                        }
                }
-               if ( (current_token == parmnum) && 
-                    (*s != separator)) {
+               if ( (current_token == parmnum) && (*s != separator)) {
                        dest->buf[len] = *s;
                        ++len;
                }
@@ -1423,24 +1365,17 @@ unsigned long StrBufExtract_unsigned_long(const StrBuf* Source, int parmnum, cha
  *  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;
        }
 
@@ -1455,58 +1390,47 @@ int StrBufHaveNextToken(const StrBuf *Source, const char **pStart)
  *  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;
 
@@ -1554,14 +1478,12 @@ int StrBufExtract_NextToken(StrBuf *dest, const StrBuf *Source, const char **pSt
  *  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)
@@ -1577,12 +1499,8 @@ int StrBufSkip_NTokenS(const StrBuf *Source, const char **pStart, char separator
                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;
@@ -1598,15 +1516,13 @@ int StrBufSkip_NTokenS(const StrBuf *Source, const char **pStart, char separator
        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];
        
@@ -1621,15 +1537,13 @@ int StrBufExtractNext_int(const StrBuf* Source, const char **pStart, char separa
                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];
        
@@ -1645,15 +1559,12 @@ long StrBufExtractNext_long(const StrBuf* Source, const char **pStart, char sepa
 }
 
 
-/**
- *  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;
@@ -1674,27 +1585,22 @@ unsigned long StrBufExtractNext_unsigned_long(const StrBuf* Source, const char *
 }
 
 
-
-
-
 /*******************************************************************************
  *                             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;
@@ -1741,12 +1647,10 @@ void StrBufUrlescAppend(StrBuf *OutBuf, const StrBuf *In, const char *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;
@@ -1799,14 +1703,13 @@ void StrBufUrlescUPAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn)
        *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,
@@ -2367,26 +2270,23 @@ long StrECMAEscAppend(StrBuf *Target, const StrBuf *Source, 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 &ltbr/&gt
- */
-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 &ltbr/&gt
+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);
@@ -2398,16 +2298,17 @@ long StrHtmlEcmaEscAppend(StrBuf *Target, const StrBuf *Source, const char *Plai
                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) {
@@ -2479,14 +2380,13 @@ long StrHtmlEcmaEscAppend(StrBuf *Target, const StrBuf *Source, const char *Plai
                            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 = '\\';
@@ -2515,7 +2415,7 @@ long StrHtmlEcmaEscAppend(StrBuf *Target, const StrBuf *Source, const char *Plai
                        bptr ++;
                        Target->BufUsed += 2;
                        break;
-               case  32:
+               case 32:
                        if (nbsp == 1) {
                                memcpy(bptr, HKEY("&nbsp;"));
                                bptr += 6;
@@ -2555,11 +2455,10 @@ void StrBufAsciify(StrBuf *Buf, const char repl) {
        
 }
 
-/*
- *  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];
@@ -2605,8 +2504,7 @@ void StrBufEUid_escapize(StrBuf *target, const StrBuf *source) {
        if (target != NULL)
                FlushStrBuf(target);
 
-       if ((source == NULL) || (target == NULL) || (target->buf == NULL))
-       {
+       if ((source == NULL) || (target == NULL) || (target->buf == NULL)) {
                return;
        }
 
@@ -2685,18 +2583,10 @@ typedef struct __z_enc_stream {
 
 
 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;
@@ -3108,13 +2998,10 @@ int StrBufRFC2047encode(StrBuf **target, const StrBuf *source)
        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;
@@ -3128,10 +3015,8 @@ StrBuf *StrBufRFC2047encodeMessage(const StrBuf *EncodeMe)
        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;
@@ -3139,21 +3024,16 @@ StrBuf *StrBufRFC2047encodeMessage(const StrBuf *EncodeMe)
                        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 ++;
@@ -3171,8 +3051,7 @@ StrBuf *StrBufRFC2047encodeMessage(const StrBuf *EncodeMe)
                        ptr ++;
                }
 
-               if (LinePos > 72) {
-                       /* soft line break */
+               if (LinePos > 72) {             // soft line break
                        if (isspace(*(Optr - 1))) {
                                ch = *(Optr - 1);
                                Optr --;
@@ -3198,11 +3077,7 @@ StrBuf *StrBufRFC2047encodeMessage(const StrBuf *EncodeMe)
 }
 
 
-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);
@@ -3230,11 +3105,7 @@ static void AddRecipient(StrBuf *Target,
  * \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;
@@ -3373,8 +3244,7 @@ StrBuf *StrBufSanitizeEmailRecipientVector(const StrBuf *Recp,
  *  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;
@@ -3908,9 +3778,6 @@ long StrBuf_Utf8StrCut(StrBuf *Buf, int maxlen)
 }
 
 
-
-
-
 /*******************************************************************************
  *                               wrapping ZLib                                 *
  *******************************************************************************/
@@ -4023,6 +3890,7 @@ int CompressBuffer(StrBuf *Buf)
        return 0;
 }
 
+
 /*******************************************************************************
  *           File I/O; Callbacks to libevent                                   *
  *******************************************************************************/
@@ -4040,8 +3908,7 @@ long StrBuf_read_one_chunk_callback (int fd, short event, IOBuffer *FB)
         * where a cut left is inexpensive
         */
 
-       if (FB->ReadWritePointer != NULL)
-       {
+       if (FB->ReadWritePointer != NULL) {
                long already_read;
                
                already_read = FB->ReadWritePointer - FB->Buf->buf;
@@ -4057,9 +3924,7 @@ long StrBuf_read_one_chunk_callback (int fd, short event, IOBuffer *FB)
                                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.
@@ -4072,8 +3937,7 @@ long StrBuf_read_one_chunk_callback (int fd, short event, IOBuffer *FB)
                                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);
@@ -4107,8 +3971,8 @@ long StrBuf_read_one_chunk_callback (int fd, short event, IOBuffer *FB)
        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;
 
@@ -4146,16 +4010,14 @@ int StrBuf_write_one_chunk_callback(int fd, short event, IOBuffer *FB)
        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;
 
@@ -4178,10 +4040,7 @@ eReadState StrBufChunkSipLine(StrBuf *LineBuf, IOBuffer *FB)
        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) {
@@ -4198,15 +4057,11 @@ eReadState StrBufChunkSipLine(StrBuf *LineBuf, IOBuffer *FB)
                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;
@@ -4247,8 +4102,8 @@ eReadState StrBufCheckBuffer(IOBuffer *FB)
        return eReadSuccess;
 }
 
-long IOBufferStrLength(IOBuffer *FB)
-{
+
+long IOBufferStrLength(IOBuffer *FB) {
        if ((FB == NULL) || (FB->Buf == NULL))
                return 0;
        if (FB->ReadWritePointer == NULL)
@@ -4310,17 +4165,15 @@ int StrBufTCP_read_line(StrBuf *buf, int *fd, int append, const char **Error)
 }
 
 
-/**
- *  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, 
@@ -4341,16 +4194,18 @@ int StrBufTCP_read_buffered_line(StrBuf *Line,
                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;
@@ -4373,9 +4228,7 @@ int StrBufTCP_read_buffered_line(StrBuf *Line,
                        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);
@@ -4387,10 +4240,9 @@ int StrBufTCP_read_buffered_line(StrBuf *Line,
                        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;
                }
                
@@ -4411,18 +4263,18 @@ int StrBufTCP_read_buffered_line(StrBuf *Line,
 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,
@@ -4443,32 +4295,24 @@ int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
        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';
@@ -4481,8 +4325,7 @@ int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
                }
 
                len = pch - pos;
-               if (len > 0 && (*(pch - 1) == '\r') )
-               {
+               if (len > 0 && (*(pch - 1) == '\r') ) {
                        retlen--;
                        len --;
                        pcht --;
@@ -4490,24 +4333,21 @@ int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
                }
                *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 
@@ -4516,8 +4356,9 @@ int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
 
        /* 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;
@@ -4526,8 +4367,7 @@ int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
        while ((nSuccessLess < timeout) && 
               (pLF == NULL) &&
               (*fd != -1)) {
-               if (IsNonBlock)
-               {
+               if (IsNonBlock) {
                        tv.tv_sec = 1;
                        tv.tv_usec = 0;
                
@@ -4546,9 +4386,7 @@ int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
                                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);
@@ -4568,8 +4406,7 @@ int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
                        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;
@@ -4579,8 +4416,7 @@ int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
 
                        continue;
                }
-               else
-               {
+               else {
                        nSuccessLess++;
                }
        }
@@ -4588,11 +4424,11 @@ int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
        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 
@@ -4626,26 +4462,23 @@ int StrBufReadBLOB(StrBuf *Buf, int *fd, int append, long nBytes, const char **E
        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;
                
@@ -4655,8 +4488,9 @@ int StrBufReadBLOB(StrBuf *Buf, int *fd, int append, long nBytes, const char **E
                                *Error = strerror(errno);
                                close (*fd);
                                *fd = -1;
-                               if (*Error == NULL)
+                               if (*Error == NULL) {
                                        *Error = ErrRBLF_SelectFailed;
+                               }
                                return -1;
                        }
                        if (! FD_ISSET(*fd, &rfds) != 0) {
@@ -4683,19 +4517,19 @@ int StrBufReadBLOB(StrBuf *Buf, int *fd, int append, long nBytes, const char **E
 
 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,
@@ -4717,11 +4551,7 @@ int StrBufReadBLOBBuffered(StrBuf *Blob,
        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;
@@ -4741,8 +4571,7 @@ int StrBufReadBLOBBuffered(StrBuf *Blob,
        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;
@@ -4802,8 +4631,7 @@ int StrBufReadBLOBBuffered(StrBuf *Blob,
                        }
                }
                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);
@@ -4847,24 +4675,18 @@ int StrBufReadBLOBBuffered(StrBuf *Blob,
        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;
        }
@@ -4879,10 +4701,7 @@ int StrBufSipLine(StrBuf *LineBuf, const StrBuf *Buf, const char **Ptr)
        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) {
@@ -4913,13 +4732,10 @@ int StrBufSipLine(StrBuf *LineBuf, const StrBuf *Buf, const char **Ptr)
 }
 
 
-/**
- *  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;
@@ -4946,13 +4762,10 @@ void StrBufStripSlashes(StrBuf *Dir, int RemoveTrailingSlash)
 }
 
 
-/*
- * 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;
        }