#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;
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)
-{
+void StrBufCutAt(StrBuf *Buf, int AfternChars, const char *At) {
if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
if (At != NULL){
AfternChars = At - Buf->buf;
}
-//*
// Strip leading and trailing spaces from a string; with premeasured and adjusted length.
// Buf the string to modify
-///
-void StrBufTrim(StrBuf *Buf)
-{
+void StrBufTrim(StrBuf *Buf) {
int delta = 0;
if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
}
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)
-{
+void StrBufSpaceToBlank(StrBuf *Buf) {
char *pche, *pch;
if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
}
}
-void StrBufStripAllBut(StrBuf *Buf, char leftboundary, char rightboundary)
-{
+void StrBufStripAllBut(StrBuf *Buf, char leftboundary, char rightboundary) {
const char *pLeft;
const char *pRight;
}
-//*
// uppercase the contents of a buffer
// Buf the buffer to translate
-///
-void StrBufUpCase(StrBuf *Buf)
-{
+void StrBufUpCase(StrBuf *Buf) {
char *pch, *pche;
if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
}
-//*
// lowercase the contents of a buffer
// Buf the buffer to translate
-///
-void StrBufLowerCase(StrBuf *Buf)
-{
+void StrBufLowerCase(StrBuf *Buf) {
char *pch, *pche;
if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
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) {
char *pch, *pche;
long NTokens;
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)
-{
+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! */
+ // End of string, bail!
if (!*d) {
d = NULL;
break;
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)) {
s++;
s++;
ReducedBy = d - s;
- /* Hack and slash */
+ // Hack and slash
if (s >= end) {
return 0;
}
*--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,
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)
-{
+// 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 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];
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];
}
-/**
- * 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;
}
-
-/**
- * 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
- */
+// 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;
* 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;
* nolinebreaks if set to 1, linebreaks are removed from the string.
* if set to 2, linebreaks are replaced by <br/>
*/
-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;
* 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;
* 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;
* 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;
* 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;
* 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;
* 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;
* 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;
* 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);
* 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)
* 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;
* 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));
* 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);
* 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);
}
* 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;
* 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;
* 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;
* 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;
* 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)
* 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)) {
* 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;