fix dlen
[citadel.git] / libcitadel / lib / stringbuf.c
index d31c227c53059edb6e74c4958b5c1b6d7e459a1e..7f136deb05155c3f509e498964802ba943134315 100644 (file)
@@ -1,7 +1,6 @@
-// Copyright (c) 1987-2023 by the citadel.org team
+// Copyright (c) 1987-2024 by the citadel.org team
 //
-// This program is open source software.  Use, duplication, or disclosure
-// is subject to the terms of the GNU General Public License, version 3.
+// This program is open source software.  Use, duplication, or disclosure is subject to the GNU General Public License, version 3.
 
 #define _GNU_SOURCE
 #include "sysdep.h"
@@ -37,11 +36,11 @@ int ZEXPORT compress_gzip(Bytef * dest, size_t * destLen, const Bytef * source,
 #endif
 int BaseStrBufSize = 64;
 int EnableSplice = 0;
-int ZLibCompressionRatio = -1; /* defaults to 6 */
+int ZLibCompressionRatio = -1; // defaults to 6
 #ifdef HAVE_ZLIB
-#define DEF_MEM_LEVEL 8 /*< memlevel??? */
-#define OS_CODE 0x03   /*< unix */
-const int gz_magic[2] = { 0x1f, 0x8b };        /* gzip magic header */
+#define DEF_MEM_LEVEL 8 // memlevel???
+#define OS_CODE 0x03   // unix
+const int gz_magic[2] = { 0x1f, 0x8b };        // gzip magic header
 #endif
 
 const char *StrBufNOTNULL = ((char*) NULL) - 1;
@@ -65,18 +64,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
 };
 
@@ -93,22 +90,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
 
@@ -124,21 +123,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);
        }
 }
@@ -162,19 +163,17 @@ void dbg_Init(StrBuf *Buf) {
 }
 
 #else
-/* void it... */
+// void it...
 #define dbg_FreeStrBuf(a, b)
 #define dbg_IncreaseBuf(a)
 #define dbg_Init(a)
 
 #endif
 
-/*
- *  swaps the contents of two StrBufs
- * this is to be used to have cheap switched between a work-buffer and a target buffer 
- *  A First one
- *  B second one
- */
+// swaps the contents of two StrBufs
+// this is to be used to have cheap switched between a work-buffer and a target buffer 
+// A First one
+// B second one
 static inline void iSwapBuffers(StrBuf *A, StrBuf *B) {
        StrBuf C;
 
@@ -190,15 +189,13 @@ void SwapBuffers(StrBuf *A, StrBuf *B) {
 }
 
 
-/* 
- *  Cast operator to Plain String 
- * @note if the buffer is altered by StrBuf operations, this pointer may become 
- *  invalid. So don't lean on it after altering the buffer!
- *  Since this operation is considered cheap, rather call it often than risking
- *  your pointer to become invalid!
- *  Str the string we want to get the c-string representation for
- * @returns the Pointer to the Content. Don't mess with it!
- */
+// Cast operator to Plain String 
+// note: if the buffer is altered by StrBuf operations, this pointer may become 
+// invalid. So don't lean on it after altering the buffer!
+// Since this operation is considered cheap, rather call it often than risking
+// your pointer to become invalid!
+// Str the string we want to get the c-string representation for
+// returns the Pointer to the Content. Don't mess with it!
 inline const char *ChrPtr(const StrBuf *Str) {
        if (Str == NULL)
                return "";
@@ -206,11 +203,9 @@ inline const char *ChrPtr(const StrBuf *Str) {
 }
 
 
-/*
- *  since we know strlen()'s result, provide it here.
- *  Str the string to return the length to
- * @returns contentlength of the buffer
- */
+// since we know strlen()'s result, provide it here.
+// Str the string to return the length to
+// returns contentlength of the buffer
 inline int StrLength(const StrBuf *Str) {
        return (Str != NULL) ? Str->BufUsed : 0;
 }
@@ -274,12 +269,10 @@ void ReAdjustEmptyBuf(StrBuf *Buf, long ThreshHold, long NewSize) {
 }
 
 
-/*
- *  shrink long term buffers to their real size so they don't waste memory
- *  Buf buffer to shrink
- *  Force if not set, will just executed if the buffer is much to big; set for lifetime strings
- * @returns physical size of the buffer
- */
+// shrink long term buffers to their real size so they don't waste memory
+// Buf buffer to shrink
+// Force if not set, will just executed if the buffer is much to big; set for lifetime strings
+// returns physical size of the buffer
 long StrBufShrinkToFit(StrBuf *Buf, int Force) {
        if (Buf == NULL)
                return -1;
@@ -299,10 +292,8 @@ long StrBufShrinkToFit(StrBuf *Buf, int Force) {
 }
 
 
-/*
- *  Allocate a new buffer with default buffer size
- * @returns the new stringbuffer
- */
+// Allocate a new buffer with default buffer size
+// returns the new stringbuffer
 StrBuf *NewStrBuf(void) {
        StrBuf *NewBuf;
 
@@ -325,11 +316,9 @@ StrBuf *NewStrBuf(void) {
 }
 
 
-/* 
- *  Copy Constructor; returns a duplicate of CopyMe
- *  CopyMe Buffer to faxmilate
- * @returns the new stringbuffer
- */
+// Copy Constructor; returns a duplicate of CopyMe
+// CopyMe Buffer to faxmilate
+// returns the new stringbuffer
 StrBuf *NewStrBufDup(const StrBuf *CopyMe) {
        StrBuf *NewBuf;
        
@@ -357,14 +346,12 @@ StrBuf *NewStrBufDup(const StrBuf *CopyMe) {
 }
 
 
-/* 
- *  Copy Constructor; CreateRelpaceMe will contain CopyFlushMe afterwards.
- *  NoMe if non-NULL, we will use that buffer as value; KeepOriginal will abused as len.
- *  CopyFlushMe Buffer to faxmilate if KeepOriginal, or to move into CreateRelpaceMe if !KeepOriginal.
- *  CreateRelpaceMe If NULL, will be created, else Flushed and filled CopyFlushMe 
- *  KeepOriginal should CopyFlushMe remain intact? or may we Steal its buffer?
- * @returns the new stringbuffer
- */
+// Copy Constructor; CreateRelpaceMe will contain CopyFlushMe afterwards.
+// NoMe if non-NULL, we will use that buffer as value; KeepOriginal will abused as len.
+// CopyFlushMe Buffer to faxmilate if KeepOriginal, or to move into CreateRelpaceMe if !KeepOriginal.
+// CreateRelpaceMe If NULL, will be created, else Flushed and filled CopyFlushMe 
+// KeepOriginal should CopyFlushMe remain intact? or may we Steal its buffer?
+// returns the new stringbuffer
 void NewStrBufDupAppendFlush(StrBuf **CreateRelpaceMe, StrBuf *CopyFlushMe, const char *NoMe, int KeepOriginal) {
        StrBuf *NewBuf;
        
@@ -387,11 +374,9 @@ void NewStrBufDupAppendFlush(StrBuf **CreateRelpaceMe, StrBuf *CopyFlushMe, cons
                return;
        }
 
-       /* 
-        * Randomly Chosen: bigger than 64 chars is cheaper to swap the buffers instead of copying.
-        * else *CreateRelpaceMe may use more memory than needed in a longer term, CopyFlushMe might
-        * be a big IO-Buffer...
-        */
+       // Randomly Chosen: bigger than 64 chars is cheaper to swap the buffers instead of copying.
+       // else *CreateRelpaceMe may use more memory than needed in a longer term, CopyFlushMe might
+       // be a big IO-Buffer...
        if (KeepOriginal || (StrLength(CopyFlushMe) < 256)) {
                if (*CreateRelpaceMe == NULL) {
                        *CreateRelpaceMe = NewBuf = NewStrBufPlain(NULL, CopyFlushMe->BufUsed);
@@ -420,14 +405,12 @@ void NewStrBufDupAppendFlush(StrBuf **CreateRelpaceMe, StrBuf *CopyFlushMe, cons
 }
 
 
-/*
- *  create a new Buffer using an existing c-string
- * this function should also be used if you want to pre-suggest
- * the buffer size to allocate in conjunction with ptr == NULL
- *  ptr the c-string to copy; may be NULL to create a blank instance
- *  nChars How many chars should we copy; -1 if we should measure the length ourselves
- * @returns the new stringbuffer
- */
+// create a new Buffer using an existing c-string
+// this function should also be used if you want to pre-suggest
+// the buffer size to allocate in conjunction with ptr == NULL
+// ptr the c-string to copy; may be NULL to create a blank instance
+// nChars How many chars should we copy; -1 if we should measure the length ourselves
+// returns the new stringbuffer
 StrBuf *NewStrBufPlain(const char* ptr, int nChars) {
        StrBuf *NewBuf;
        size_t Siz = BaseStrBufSize;
@@ -473,13 +456,13 @@ StrBuf *NewStrBufPlain(const char* ptr, int nChars) {
 }
 
 
-/*
- *  Set an existing buffer from a c-string
- *  Buf buffer to load
- *  ptr c-string to put into 
- *  nChars set to -1 if we should work 0-terminated
- * @returns the new length of the string
- */
+//
+//  Set an existing buffer from a c-string
+//  Buf buffer to load
+//  ptr c-string to put into 
+//  nChars set to -1 if we should work 0-terminated
+// @returns the new length of the string
+///
 int StrBufPlain(StrBuf *Buf, const char* ptr, int nChars) {
        size_t Siz;
        size_t CopySize;
@@ -516,13 +499,12 @@ 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
- */
-StrBuf* _NewConstStrBuf(const char* StringConstant, size_t SizeOfStrConstant)
-{
+//
+//  use strbuf as wrapper for a string constant for easy handling
+//  StringConstant a string to wrap
+//  SizeOfStrConstant should be sizeof(StringConstant)-1
+///
+StrBuf *_NewConstStrBuf(const char* StringConstant, size_t SizeOfStrConstant) {
        StrBuf *NewBuf;
 
        NewBuf = (StrBuf*) malloc(sizeof(StrBuf));
@@ -539,27 +521,27 @@ 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))
+//
+//  flush the content of a Buf; keep its struct
+//  buf Buffer to flush
+///
+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
- */
-int FLUSHStrBuf(StrBuf *buf)
-{
+//
+//  wipe the content of a Buf thoroughly (overwrite it -> expensive); keep its struct
+//  buf Buffer to wipe
+///
+int FLUSHStrBuf(StrBuf *buf) {
        if (buf == NULL)
                return -1;
        if (buf->ConstBuf)
@@ -574,14 +556,13 @@ 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
- *  FreeMe Pointer Pointer to the buffer to free
- */
-void FreeStrBuf (StrBuf **FreeMe)
-{
+//
+//  Release a Buffer
+// Its a double pointer, so it can NULL your pointer
+// so fancy SIG11 appear instead of random results
+//  FreeMe Pointer Pointer to the buffer to free
+///
+void FreeStrBuf (StrBuf **FreeMe) {
        if (*FreeMe == NULL)
                return;
 
@@ -593,14 +574,14 @@ void FreeStrBuf (StrBuf **FreeMe)
        *FreeMe = NULL;
 }
 
-/*
- *  flatten a Buffer to the Char * we return 
- * Its a double pointer, so it can NULL your pointer
- * so fancy SIG11 appear instead of random results
- * The Callee then owns the buffer and is responsible for freeing it.
- *  SmashMe Pointer Pointer to the buffer to release Buf from and free
- * @returns the pointer of the buffer; Callee owns the memory thereafter.
- */
+//
+//  flatten a Buffer to the Char * we return 
+// Its a double pointer, so it can NULL your pointer
+// so fancy SIG11 appear instead of random results
+// The Callee then owns the buffer and is responsible for freeing it.
+//  SmashMe Pointer Pointer to the buffer to release Buf from and free
+// @returns the pointer of the buffer; Callee owns the memory thereafter.
+///
 char *SmashStrBuf (StrBuf **SmashMe) {
        char *Ret;
 
@@ -616,11 +597,9 @@ char *SmashStrBuf (StrBuf **SmashMe) {
 }
 
 
-/*
- *  Release the buffer
- * If you want put your StrBuf into a Hash, use this as Destructor.
- *  VFreeMe untyped pointer to a StrBuf. be shure to do the right thing [TM]
- */
+// Release the buffer
+// If you want put your StrBuf into a Hash, use this as Destructor.
+// VFreeMe untyped pointer to a StrBuf. be shure to do the right thing [TM]
 void HFreeStrBuf (void *VFreeMe) {
        StrBuf *FreeMe = (StrBuf*)VFreeMe;
        if (FreeMe == NULL)
@@ -634,15 +613,12 @@ void HFreeStrBuf (void *VFreeMe) {
 }
 
 
-/*******************************************************************************
- *                      Simple string transformations                          *
- *******************************************************************************/
+//******************************************************************************
+//                      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)
@@ -651,11 +627,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)
@@ -664,11 +638,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)) {
@@ -684,16 +657,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)
@@ -704,17 +675,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)
@@ -725,22 +694,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);
@@ -775,22 +742,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;
@@ -807,14 +770,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 {
@@ -825,13 +786,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;
@@ -848,14 +807,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 {
@@ -866,13 +823,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;
        
@@ -886,7 +841,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;
                }
@@ -894,15 +849,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;
 
@@ -915,50 +865,42 @@ 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';
        return NCharsRemain;
 }
 
-/**
- *  Cut nChars from the start of the string
- *  Buf Buffer to modify
- *  nChars how many chars should be skipped?
- */
-void StrBufCutLeft(StrBuf *Buf, int nChars)
-{
+//  Cut nChars from the start of the string
+//  Buf Buffer to modify
+//  nChars how many chars should be skipped?
+void StrBufCutLeft(StrBuf *Buf, int nChars) {
        if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
        if (nChars >= Buf->BufUsed) {
                FlushStrBuf(Buf);
@@ -969,13 +911,10 @@ void StrBufCutLeft(StrBuf *Buf, int nChars)
        Buf->buf[Buf->BufUsed] = '\0';
 }
 
-/**
- *  Cut the trailing n Chars from the string
- *  Buf Buffer to modify
- *  nChars how many chars should be trunkated?
- */
-void StrBufCutRight(StrBuf *Buf, int nChars)
-{
+// Cut the trailing n Chars from the string
+// Buf Buffer to modify
+// nChars how many chars should be trunkated?
+void StrBufCutRight(StrBuf *Buf, int nChars) {
        if ((Buf == NULL) || (Buf->BufUsed == 0) || (Buf->buf == NULL))
                return;
 
@@ -987,14 +926,12 @@ void StrBufCutRight(StrBuf *Buf, int nChars)
        Buf->buf[Buf->BufUsed] = '\0';
 }
 
-/**
- *  Cut the string after n Chars
- *  Buf Buffer to modify
- *  AfternChars after how many chars should we trunkate the string?
- *  At if non-null and points inside of our string, cut it there.
- */
-void StrBufCutAt(StrBuf *Buf, int AfternChars, const char *At)
-{
+
+//  Cut the string after n Chars
+//  Buf Buffer to modify
+//  AfternChars after how many chars should we trunkate the string?
+//  At if non-null and points inside of our string, cut it there.
+void StrBufCutAt(StrBuf *Buf, int AfternChars, const char *At) {
        if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
        if (At != NULL){
                AfternChars = At - Buf->buf;
@@ -1007,18 +944,13 @@ void StrBufCutAt(StrBuf *Buf, int AfternChars, const char *At)
 }
 
 
-/**
- *  Strip leading and trailing spaces from a string; with premeasured and adjusted length.
- *  Buf the string to modify
- */
-void StrBufTrim(StrBuf *Buf)
-{
+//  Strip leading and trailing spaces from a string; with premeasured and adjusted length.
+//  Buf the string to modify
+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';
@@ -1030,12 +962,11 @@ void StrBufTrim(StrBuf *Buf)
        }
        if (delta > 0) StrBufCutLeft(Buf, delta);
 }
-/**
- *  changes all spaces in the string  (tab, linefeed...) to Blank (0x20)
- *  Buf the string to modify
- */
-void StrBufSpaceToBlank(StrBuf *Buf)
-{
+
+
+//  changes all spaces in the string  (tab, linefeed...) to Blank (0x20)
+//  Buf the string to modify
+void StrBufSpaceToBlank(StrBuf *Buf) {
        char *pche, *pch;
 
        if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
@@ -1050,8 +981,7 @@ void StrBufSpaceToBlank(StrBuf *Buf)
        }
 }
 
-void StrBufStripAllBut(StrBuf *Buf, char leftboundary, char rightboundary)
-{
+void StrBufStripAllBut(StrBuf *Buf, char leftboundary, char rightboundary) {
        const char *pLeft;
        const char *pRight;
 
@@ -1071,12 +1001,9 @@ void StrBufStripAllBut(StrBuf *Buf, char leftboundary, char rightboundary)
 }
 
 
-/**
- *  uppercase the contents of a buffer
- *  Buf the buffer to translate
- */
-void StrBufUpCase(StrBuf *Buf) 
-{
+//  uppercase the contents of a buffer
+//  Buf the buffer to translate
+void StrBufUpCase(StrBuf *Buf) {
        char *pch, *pche;
 
        if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
@@ -1090,12 +1017,9 @@ void StrBufUpCase(StrBuf *Buf)
 }
 
 
-/**
- *  lowercase the contents of a buffer
- *  Buf the buffer to translate
- */
-void StrBufLowerCase(StrBuf *Buf) 
-{
+//  lowercase the contents of a buffer
+//  Buf the buffer to translate
+void StrBufLowerCase(StrBuf *Buf) {
        char *pch, *pche;
 
        if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
@@ -1109,52 +1033,43 @@ void StrBufLowerCase(StrBuf *Buf)
 }
 
 
-/*******************************************************************************
- *           a tokenizer that kills, maims, and destroys                       *
- *******************************************************************************/
+//******************************************************************************
+//           a tokenizer that kills, maims, and destroys                       *
+//******************************************************************************/
 
-/**
- *  Replace a token at a given place with a given length by another token with given length
- *  Buf String where to work on
- *  where where inside of the Buf is the search-token
- *  HowLong How long is the token to be replaced
- *  Repl Token to insert at 'where'
- *  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)
-{
+//*
+//  Replace a token at a given place with a given length by another token with given length
+//  Buf String where to work on
+//  where where inside of the Buf is the search-token
+//  HowLong How long is the token to be replaced
+//  Repl Token to insert at 'where'
+//  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) {
 
-       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;
-
+       Buf->buf[Buf->BufUsed] = 0;
        return Buf->BufUsed;
 }
 
-/**
- *  Counts the numbmer of tokens in a buffer
- *  source String to count tokens in
- *  tok    Tokenizer char to count
- * @returns numbers of tokenizer chars found
- */
-int StrBufNum_tokens(const StrBuf *source, char tok)
-{
+//  Counts the numbmer of tokens in a buffer
+//  source String to count tokens in
+//  tok    Tokenizer char to count
+// @returns numbers of tokenizer chars found
+int StrBufNum_tokens(const StrBuf *source, char tok) {
        char *pch, *pche;
        long NTokens;
        if ((source == NULL) || (source->BufUsed == 0))
@@ -1173,26 +1088,22 @@ int StrBufNum_tokens(const StrBuf *source, char tok)
        return NTokens;
 }
 
-/**
- *  a string tokenizer
- *  Source StringBuffer to read into
- *  parmnum n'th Parameter to remove
- *  separator tokenizer character
- * @returns -1 if not found, else length of token.
- */
-int StrBufRemove_token(StrBuf *Source, int parmnum, char separator)
-{
+
+//  a string tokenizer
+//  Source StringBuffer to read into
+//  parmnum n'th Parameter to remove
+//  separator tokenizer character
+// @returns -1 if not found, else length of token.
+int StrBufRemove_token(StrBuf *Source, int parmnum, char separator) {
        int ReducedBy;
-       char *d, *s, *end;              /* dest, source */
+       char *d, *s, *end;              // dest, source
        int count = 0;
 
-       /* Find desired eter */
+       // Find desired eter
        end = Source->buf + Source->BufUsed;
        d = Source->buf;
-       while ((d <= end) && 
-              (count < parmnum))
-       {
-               /* End of string, bail! */
+       while ((d <= end) && (count < parmnum)) {
+               // End of string, bail!
                if (!*d) {
                        d = NULL;
                        break;
@@ -1203,20 +1114,18 @@ int StrBufRemove_token(StrBuf *Source, int parmnum, char separator)
                d++;
        }
        if ((d == NULL) || (d >= end))
-               return 0;               /* @Parameter not found */
+               return 0;               // Parameter not found
 
-       /* Find next eter */
+       // Find next eter
        s = d;
-       while ((s <= end) && 
-              (*s && *s != separator))
-       {
+       while ((s <= end) && (*s && *s != separator)) {
                s++;
        }
        if (*s == separator)
                s++;
        ReducedBy = d - s;
 
-       /* Hack and slash */
+       // Hack and slash
        if (s >= end) {
                return 0;
        }
@@ -1233,17 +1142,16 @@ int StrBufRemove_token(StrBuf *Source, int parmnum, char separator)
                *--d = '\0';
                Source->BufUsed += ReducedBy;
        }
-       /*
-       while (*s) {
-               *d++ = *s++;
-       }
-       *d = 0;
-       */
+
+       //while (*s) {
+               //*d++ = *s++;
+       //}
+       //*d = 0;
+
        return ReducedBy;
 }
 
-int StrBufExtract_tokenFromStr(StrBuf *dest, const char *Source, long SourceLen, int parmnum, char separator)
-{
+int StrBufExtract_tokenFromStr(StrBuf *dest, const char *Source, long SourceLen, int parmnum, char separator) {
        const StrBuf Temp = {
                (char*)Source,
                SourceLen,
@@ -1260,19 +1168,16 @@ int StrBufExtract_tokenFromStr(StrBuf *dest, const char *Source, long SourceLen,
        return StrBufExtract_token(dest, &Temp, parmnum, separator);
 }
 
-/**
- *  a string tokenizer
- *  dest Destination StringBuffer
- *  Source StringBuffer to read into
- *  parmnum n'th Parameter to extract
- *  separator tokenizer character
- * @returns -1 if not found, else length of token.
- */
-int StrBufExtract_token(StrBuf *dest, const StrBuf *Source, int parmnum, char separator)
-{
-       const char *s, *e;              //* source * /
-       int len = 0;                    //* running total length of extracted string * /
-       int current_token = 0;          //* token currently being processed * /
+// a string tokenizer
+// dest Destination StringBuffer
+// Source StringBuffer to read into
+// parmnum n'th Parameter to extract
+// separator tokenizer character
+// returns -1 if not found, else length of token.
+int StrBufExtract_token(StrBuf *dest, const StrBuf *Source, int parmnum, char separator) {
+       const char *s, *e;              // source
+       int len = 0;                    // running total length of extracted string
+       int current_token = 0;          // token currently being processed
         
        if (dest != NULL) {
                dest->buf[0] = '\0';
@@ -1301,8 +1206,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;
                }
@@ -1324,18 +1228,12 @@ int StrBufExtract_token(StrBuf *dest, const StrBuf *Source, int parmnum, char se
 }
 
 
-
-
-
-/**
- *  a string tokenizer to fetch an integer
- *  Source String containing tokens
- *  parmnum n'th Parameter to extract
- *  separator tokenizer character
- * @returns 0 if not found, else integer representation of the token
- */
-int StrBufExtract_int(const StrBuf* Source, int parmnum, char separator)
-{
+//  a string tokenizer to fetch an integer
+//  Source String containing tokens
+//  parmnum n'th Parameter to extract
+//  separator tokenizer character
+// @returns 0 if not found, else integer representation of the token
+int StrBufExtract_int(const StrBuf* Source, int parmnum, char separator) {
        StrBuf tmp;
        char buf[64];
        
@@ -1350,15 +1248,13 @@ int StrBufExtract_int(const StrBuf* Source, int parmnum, char separator)
                return 0;
 }
 
-/**
- *  a string tokenizer to fetch a long integer
- *  Source String containing tokens
- *  parmnum n'th Parameter to extract
- *  separator tokenizer character
- * @returns 0 if not found, else long integer representation of the token
- */
-long StrBufExtract_long(const StrBuf* Source, int parmnum, char separator)
-{
+
+// a string tokenizer to fetch a long integer
+// Source String containing tokens
+// parmnum n'th Parameter to extract
+// separator tokenizer character
+// returns 0 if not found, else long integer representation of the token
+long StrBufExtract_long(const StrBuf* Source, int parmnum, char separator) {
        StrBuf tmp;
        char buf[64];
        
@@ -1374,15 +1270,12 @@ long StrBufExtract_long(const StrBuf* Source, int parmnum, char separator)
 }
 
 
-/**
- *  a string tokenizer to fetch an unsigned long
- *  Source String containing tokens
- *  parmnum n'th Parameter to extract
- *  separator tokenizer character
- * @returns 0 if not found, else unsigned long representation of the token
- */
-unsigned long StrBufExtract_unsigned_long(const StrBuf* Source, int parmnum, char separator)
-{
+// a string tokenizer to fetch an unsigned long
+// Source String containing tokens
+// parmnum n'th Parameter to extract
+// separator tokenizer character
+// returns 0 if not found, else unsigned long representation of the token
+unsigned long StrBufExtract_unsigned_long(const StrBuf* Source, int parmnum, char separator) {
        StrBuf tmp;
        char buf[64];
        char *pnum;
@@ -1403,32 +1296,22 @@ unsigned long StrBufExtract_unsigned_long(const StrBuf* Source, int parmnum, cha
 }
 
 
-
-/**
- *  a string tokenizer; Bounds checker
- *  function to make shure whether StrBufExtract_NextToken and friends have reached the end of the string.
- *  Source our tokenbuffer
- *  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))
-       {
+// a string tokenizer; Bounds checker
+// function to make shure whether StrBufExtract_NextToken and friends have reached the end of the string.
+// Source our tokenbuffer
+// 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)) {
                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;
        }
 
@@ -1443,58 +1326,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;
 
@@ -1542,14 +1414,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)
@@ -1565,12 +1435,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;
@@ -1586,15 +1452,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];
        
@@ -1609,15 +1473,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];
        
@@ -1633,15 +1495,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;
@@ -1662,27 +1521,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;
@@ -1729,12 +1583,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;
@@ -1787,14 +1639,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,
@@ -1897,8 +1748,7 @@ void StrBufXMLEscAppend(StrBuf *OutBuf,
  *  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?
  */
-void StrBufHexEscAppend(StrBuf *OutBuf, const StrBuf *In, const unsigned char *PlainIn, long PlainInLen)
-{
+void StrBufHexEscAppend(StrBuf *OutBuf, const StrBuf *In, const unsigned char *PlainIn, long PlainInLen) {
        const unsigned char *pch, *pche;
        char *pt, *pte;
        int len;
@@ -1998,8 +1848,7 @@ void StrBufHexescAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn) {
  *  nolinebreaks       if set to 1, linebreaks are removed from the string.
  *                      if set to 2, linebreaks are replaced by &ltbr/&gt
  */
-long StrEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks)
-{
+long StrEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks) {
        const char *aptr, *eiptr;
        char *bptr, *eptr;
        long len;
@@ -2108,8 +1957,7 @@ long StrEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int
  *  Source     source buffer; set to NULL if you just have a C-String
  *  PlainIn       Plain-C string to append; set to NULL if unused
  */
-void StrMsgEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn)
-{
+void StrMsgEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn) {
        const char *aptr, *eiptr;
        char *tptr, *eptr;
        long len;
@@ -2174,8 +2022,7 @@ void StrMsgEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn)
  *  Source     source buffer; set to NULL if you just have a C-String
  *  PlainIn       Plain-C string to append; set to NULL if unused
  */
-void StrIcalEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn)
-{
+void StrIcalEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn) {
        const char *aptr, *eiptr;
        char *tptr, *eptr;
        long len;
@@ -2244,8 +2091,7 @@ void StrIcalEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn)
  *  PlainIn       Plain-C string to append; set to NULL if unused
  * @returns size of result or -1
  */
-long StrECMAEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn)
-{
+long StrECMAEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn) {
        const char *aptr, *eiptr;
        char *bptr, *eptr;
        long len;
@@ -2355,26 +2201,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);
@@ -2386,16 +2229,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) {
@@ -2467,14 +2311,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 = '\\';
@@ -2503,7 +2346,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;
@@ -2543,11 +2386,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];
@@ -2593,8 +2435,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;
        }
 
@@ -2673,18 +2514,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;
@@ -2950,8 +2783,7 @@ int StrBufDecodeHex(StrBuf *Buf) {
  *  Mute char to put over invalid chars
  *  Buf Buffor to transform
  */
-int StrBufSanitizeAscii(StrBuf *Buf, const char Mute)
-{
+int StrBufSanitizeAscii(StrBuf *Buf, const char Mute) {
        unsigned char *pch;
 
        if (Buf == NULL) return -1;
@@ -2970,8 +2802,7 @@ int StrBufSanitizeAscii(StrBuf *Buf, const char Mute)
  *  Buf Buffer to translate
  *  StripBlanks Reduce several blanks to one?
  */
-long StrBufUnescape(StrBuf *Buf, int StripBlanks)
-{
+long StrBufUnescape(StrBuf *Buf, int StripBlanks) {
        int a, b;
        char hex[3];
        long len;
@@ -3023,8 +2854,7 @@ long StrBufUnescape(StrBuf *Buf, int StripBlanks)
  *     source          Source string to be encoded.
  * @returns     encoded length; -1 if non success.
  */
-int StrBufRFC2047encode(StrBuf **target, const StrBuf *source)
-{
+int StrBufRFC2047encode(StrBuf **target, const StrBuf *source) {
        const char headerStr[] = "=?UTF-8?Q?";
        int need_to_encode = 0;
        int i = 0;
@@ -3356,8 +3186,7 @@ void StrBufReplaceChars(StrBuf *buf, char search, char replace) {
  *  removes all \\r s from the string, or replaces them with \n if its not a combination of both.
  *  buf Buffer to modify
  */
-void StrBufToUnixLF(StrBuf *buf)
-{
+void StrBufToUnixLF(StrBuf *buf) {
        char *pche, *pchS, *pchT;
        if (buf == NULL)
                return;
@@ -3395,8 +3224,7 @@ void StrBufToUnixLF(StrBuf *buf)
  *  fromcode   Source encoding
  *  pic           anonimized pointer to iconv struct
  */
-void  ctdl_iconv_open(const char *tocode, const char *fromcode, void *pic)
-{
+void  ctdl_iconv_open(const char *tocode, const char *fromcode, void *pic) {
 #ifdef HAVE_ICONV
        iconv_t ic = (iconv_t)(-1) ;
        ic = iconv_open(tocode, fromcode);
@@ -3420,8 +3248,7 @@ void  ctdl_iconv_open(const char *tocode, const char *fromcode, void *pic)
  *  bptr where to start searching
  * @returns found position, NULL if none.
  */
-static inline const char *FindNextEnd (const StrBuf *Buf, const char *bptr)
-{
+static inline const char *FindNextEnd (const StrBuf *Buf, const char *bptr) {
        const char * end;
        /* Find the next ?Q? */
        if (Buf->BufUsed - (bptr - Buf->buf)  < 6)
@@ -3453,8 +3280,7 @@ static inline const char *FindNextEnd (const StrBuf *Buf, const char *bptr)
  *  TmpBuf To share a workbuffer over several iterations. prepare to have it filled with useless stuff afterwards.
  *  pic Pointer to the iconv-session Object
  */
-void StrBufConvert(StrBuf *ConvertBuf, StrBuf *TmpBuf, void *pic)
-{
+void StrBufConvert(StrBuf *ConvertBuf, StrBuf *TmpBuf, void *pic) {
 #ifdef HAVE_ICONV
        long trycount = 0;
        size_t siz;
@@ -3604,8 +3430,7 @@ inline static void DecodeSegment(StrBuf *Target,
  *  FoundCharset overrides DefaultCharset if non-empty; If we find a charset inside of the string, 
  *        put it here for later use where no string might be known.
  */
-void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* DefaultCharset, StrBuf *FoundCharset)
-{
+void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* DefaultCharset, StrBuf *FoundCharset) {
        StrBuf *ConvertBuf;
        StrBuf *ConvertBuf2;
        ConvertBuf = NewStrBufPlain(NULL, StrLength(DecodeMe));
@@ -3783,8 +3608,7 @@ void StrBuf_RFC822_2_Utf8(StrBuf *Target,
  *  Char the character to examine
  * @returns width of utf8 chars in bytes; if the sequence is broken 0 is returned; 1 if its simply ASCII.
  */
-static inline int Ctdl_GetUtf8SequenceLength(const char *CharS, const char *CharE)
-{
+static inline int Ctdl_GetUtf8SequenceLength(const char *CharS, const char *CharE) {
        int n = 0;
         unsigned char test = (1<<7);
 
@@ -3807,8 +3631,7 @@ static inline int Ctdl_GetUtf8SequenceLength(const char *CharS, const char *Char
  *  Char character to inspect
  * @returns yes or no
  */
-static inline int Ctdl_IsUtf8SequenceStart(const char Char)
-{
+static inline int Ctdl_IsUtf8SequenceStart(const char Char) {
 /** 11??.???? indicates an UTF8 Sequence. */
        return ((Char & 0xC0) == 0xC0);
 }
@@ -3818,8 +3641,7 @@ static inline int Ctdl_IsUtf8SequenceStart(const char Char)
  *  Buf string to measure
  * @returns the number of glyphs in Buf
  */
-long StrBuf_Utf8StrLen(StrBuf *Buf)
-{
+long StrBuf_Utf8StrLen(StrBuf *Buf) {
        int n = 0;
        int m = 0;
        char *aptr, *eptr;
@@ -3848,8 +3670,7 @@ long StrBuf_Utf8StrLen(StrBuf *Buf)
  *  maxlen how long may the string become?
  * @returns current length of the string
  */
-long StrBuf_Utf8StrCut(StrBuf *Buf, int maxlen)
-{
+long StrBuf_Utf8StrCut(StrBuf *Buf, int maxlen) {
        char *aptr, *eptr;
        int n = 0, m = 0;
 
@@ -3876,9 +3697,6 @@ long StrBuf_Utf8StrCut(StrBuf *Buf, int maxlen)
 }
 
 
-
-
-
 /*******************************************************************************
  *                               wrapping ZLib                                 *
  *******************************************************************************/
@@ -3955,8 +3773,7 @@ int ZEXPORT compress_gzip(Bytef * dest,
  * Attention! If you feed this a Const String, you must maintain the uncompressed buffer yourself!
  *  Buf buffer whose content is to be gzipped
  */
-int CompressBuffer(StrBuf *Buf)
-{
+int CompressBuffer(StrBuf *Buf) {
 #ifdef HAVE_ZLIB
        char *compressed_data = NULL;
        size_t compressed_len, bufsize;
@@ -3991,12 +3808,12 @@ int CompressBuffer(StrBuf *Buf)
        return 0;
 }
 
+
 /*******************************************************************************
  *           File I/O; Callbacks to libevent                                   *
  *******************************************************************************/
 
-long StrBuf_read_one_chunk_callback (int fd, short event, IOBuffer *FB)
-{
+long StrBuf_read_one_chunk_callback (int fd, short event, IOBuffer *FB) {
        long bufremain = 0;
        int n;
        
@@ -4008,8 +3825,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;
@@ -4025,9 +3841,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.
@@ -4040,8 +3854,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);
@@ -4075,8 +3888,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;
 
@@ -4114,16 +3927,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;
 
@@ -4146,10 +3957,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) {
@@ -4166,15 +3974,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;
@@ -4202,8 +4006,7 @@ eReadState StrBufChunkSipLine(StrBuf *LineBuf, IOBuffer *FB)
  *  check whether the chunk-buffer has more data waiting or not.
  *  FB Chunk-Buffer to inspect
  */
-eReadState StrBufCheckBuffer(IOBuffer *FB)
-{
+eReadState StrBufCheckBuffer(IOBuffer *FB) {
        if (FB == NULL)
                return eReadFail;
        if (FB->Buf->BufUsed == 0)
@@ -4215,8 +4018,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)
@@ -4239,8 +4042,7 @@ long IOBufferStrLength(IOBuffer *FB)
  *  Error strerror() on error 
  * @returns numbers of chars read
  */
-int StrBufTCP_read_line(StrBuf *buf, int *fd, int append, const char **Error)
-{
+int StrBufTCP_read_line(StrBuf *buf, int *fd, int append, const char **Error) {
        int len, rlen, slen;
 
        if ((buf == NULL) || (buf->buf == NULL)) {
@@ -4278,17 +4080,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, 
@@ -4309,16 +4109,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;
@@ -4341,9 +4143,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);
@@ -4355,10 +4155,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;
                }
                
@@ -4379,18 +4178,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,
@@ -4411,32 +4210,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';
@@ -4449,8 +4240,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 --;
@@ -4458,24 +4248,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 
@@ -4484,8 +4271,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;
@@ -4494,8 +4282,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;
                
@@ -4514,9 +4301,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);
@@ -4536,8 +4321,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;
@@ -4547,8 +4331,7 @@ int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
 
                        continue;
                }
-               else
-               {
+               else {
                        nSuccessLess++;
                }
        }
@@ -4556,11 +4339,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 
@@ -4583,8 +4366,7 @@ static const char *ErrRBLF_BLOBPreConditionFailed="StrBufReadBLOB: Wrong argumen
  *  Error strerror() on error 
  * @returns numbers of chars read
  */
-int StrBufReadBLOB(StrBuf *Buf, int *fd, int append, long nBytes, const char **Error)
-{
+int StrBufReadBLOB(StrBuf *Buf, int *fd, int append, long nBytes, const char **Error) {
        int fdflags;
        int rlen;
        int nSuccessLess;
@@ -4594,26 +4376,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;
                
@@ -4623,8 +4402,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) {
@@ -4651,19 +4431,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,
@@ -4685,11 +4465,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;
@@ -4709,8 +4485,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;
@@ -4770,8 +4545,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);
@@ -4815,24 +4589,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;
        }
@@ -4847,10 +4615,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) {
@@ -4881,13 +4646,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;
@@ -4914,13 +4676,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;
        }