#include "libcitadel.h"
+/**
+ * Private Structure for the Stringbuffer
+ */
struct StrBuf {
- char *buf;
- long BufSize;
- long BufUsed;
- int ConstBuf;
+ 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? */
};
+/**
+ * \Brief Cast operator to Plain String
+ * \param 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 Str->buf;
}
+/**
+ * \brief since we know strlen()'s result, provide it here.
+ * \param 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;
}
+/**
+ * Allocate a new buffer with default buffer size
+ * \returns the new stringbuffer
+ */
StrBuf* NewStrBuf(void)
{
StrBuf *NewBuf;
return NewBuf;
}
+/**
+ * \brief Copy Constructor; returns a duplicate of CopyMe
+ * \params CopyMe Buffer to faxmilate
+ * \returns the new stringbuffer
+ */
StrBuf* NewStrBufDup(const StrBuf *CopyMe)
{
StrBuf *NewBuf;
return NewBuf;
}
+/**
+ * \brief 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
+ * \param ptr the c-string to copy; may be NULL to create a blank instance
+ * \param 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;
return NewBuf;
}
+/**
+ * \brief Set an existing buffer from a c-string
+ * \param ptr c-string to put into
+ * \param 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 = Buf->BufSize;
+ size_t CopySize;
+
+ if (nChars < 0)
+ CopySize = strlen(ptr);
+ else
+ CopySize = nChars;
+
+ while (Siz <= CopySize)
+ Siz *= 2;
+ if (Siz != Buf->BufSize)
+ IncreaseBuf(Buf, 0, Siz);
+ memcpy(Buf->buf, ptr, CopySize);
+ Buf->buf[CopySize] = '\0';
+ Buf->BufUsed = CopySize;
+ Buf->ConstBuf = 0;
+ return CopySize;
+}
+
+
+/**
+ * \brief use strbuf as wrapper for a string constant for easy handling
+ * \param StringConstant a string to wrap
+ * \param SizeOfConstant should be sizeof(StringConstant)-1
+ */
StrBuf* _NewConstStrBuf(const char* StringConstant, size_t SizeOfStrConstant)
{
StrBuf *NewBuf;
return NewBuf;
}
-
+/**
+ * \brief local utility function to resize the buffer
+ * \param Buf the buffer whichs storage we should increase
+ * \param KeepOriginal should we copy the original buffer or just start over with a new one
+ * \param DestSize what should fit in after?
+ */
static int IncreaseBuf(StrBuf *Buf, int KeepOriginal, int DestSize)
{
char *NewBuf;
return Buf->BufSize;
}
+/**
+ * \brief flush the content of a Buf; keep its struct
+ * \param buf Buffer to flush
+ */
int FlushStrBuf(StrBuf *buf)
{
if (buf->ConstBuf)
return 0;
}
+/**
+ * \brief Release a Buffer
+ * Its a double pointer, so it can NULL your pointer
+ * so fancy SIG11 appear instead of random results
+ * \param FreeMe Pointer Pointer to the buffer to free
+ */
void FreeStrBuf (StrBuf **FreeMe)
{
if (*FreeMe == NULL)
*FreeMe = NULL;
}
+/**
+ * \brief Release the buffer
+ * If you want put your StrBuf into a Hash, use this as Destructor.
+ * \param VFreeMe untyped pointer to a StrBuf. be shure to do the right thing [TM]
+ */
void HFreeStrBuf (void *VFreeMe)
{
StrBuf *FreeMe = (StrBuf*)VFreeMe;
free(FreeMe);
}
+/**
+ * \brief Wrapper around atol
+ */
long StrTol(const StrBuf *Buf)
{
if(Buf->BufUsed > 0)
return 0;
}
+/**
+ * \brief Wrapper around atoi
+ */
int StrToi(const StrBuf *Buf)
{
if(Buf->BufUsed > 0)
return 0;
}
+/**
+ * \brief modifies a Single char of the Buf
+ * You can point to it via char* or a zero-based integer
+ * \param ptr char* to zero; use NULL if unused
+ * \param nThChar zero based pointer into the string; use -1 if unused
+ * \param PeekValue The Character to place into the position
+ */
long StrBufPeek(StrBuf *Buf, const char* ptr, long nThChar, char PeekValue)
{
if (Buf == NULL)
return nThChar;
}
-
-int StrBufPlain(StrBuf *Buf, const char* ptr, int nChars)
-{
- size_t Siz = Buf->BufSize;
- size_t CopySize;
-
- if (nChars < 0)
- CopySize = strlen(ptr);
- else
- CopySize = nChars;
-
- while (Siz <= CopySize)
- Siz *= 2;
-
- if (Siz != Buf->BufSize)
- IncreaseBuf(Buf, 0, Siz);
- memcpy(Buf->buf, ptr, CopySize);
- Buf->buf[CopySize] = '\0';
- Buf->BufUsed = CopySize;
- Buf->ConstBuf = 0;
- return CopySize;
-}
-
+/**
+ * \brief Append a StringBuffer to the buffer
+ * \param Buf Buffer to modify
+ * \param AppendBuf Buffer to copy at the end of our buffer
+ * \param Offset Should we start copying from an offset?
+ */
void StrBufAppendBuf(StrBuf *Buf, const StrBuf *AppendBuf, size_t Offset)
{
if ((AppendBuf == NULL) || (Buf == NULL))
}
+/**
+ * \brief Append a C-String to the buffer
+ * \param Buf Buffer to modify
+ * \param AppendBuf Buffer to copy at the end of our buffer
+ * \param AppendSize number of bytes to copy; set to -1 if we should count it in advance
+ * \param Offset Should we start copying from an offset?
+ */
void StrBufAppendBufPlain(StrBuf *Buf, const char *AppendBuf, long AppendSize, size_t Offset)
{
long aps;
/**
- * \brief Escape a string for feeding out as a URL.
+ * \brief Escape a string for feeding out as a URL while appending it to a Buffer
* \param outbuf the output buffer
* \param oblen the size of outbuf to sanitize
* \param strbuf the input buffer
}
/*
- * Copy a string, escaping characters which have meaning in HTML.
+ * \brief Append a string, escaping characters which have meaning in HTML.
*
- * target target buffer
- * strbuf source buffer
- * nbsp If nonzero, spaces are converted to non-breaking spaces.
- * nolinebreaks if set, linebreaks are removed from the string.
+ * \param Target target buffer
+ * \param Source source buffer; set to NULL if you just have a C-String
+ * \param PlainIn Plain-C string to append; set to NULL if unused
+ * \param nbsp If nonzero, spaces are converted to non-breaking spaces.
+ * \param nolinebreaks if set, linebreaks are removed from the string.
*/
long StrEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks)
{
return Target->BufUsed;
}
+/*
+ * \brief Append a string, escaping characters which have meaning in HTML.
+ * Converts linebreaks into blanks; escapes single quotes
+ * \param Target target buffer
+ * \param Source source buffer; set to NULL if you just have a C-String
+ * \param PlainIn Plain-C string to append; set to NULL if unused
+ */
void StrMsgEscAppend(StrBuf *Target, StrBuf *Source, const char *PlainIn)
{
const char *aptr, *eiptr;
}
-inline int StrBufNum_tokens(const StrBuf *source, char tok)
-{
- return num_tokens(source->buf, tok);
-}
-
-
+/**
+ * \brief extracts a substring from Source into dest
+ * \param dest buffer to place substring into
+ * \param Source string to copy substring from
+ * \param Offset chars to skip from start
+ * \param 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, size_t Offset, size_t nChars)
{
size_t NCharsRemain;
return NCharsRemain;
}
-
+/**
+ * \brief sprintf like function appending the formated string to the buffer
+ * vsnprintf version to wrap into own calls
+ * \param Buf Buffer to extend by format and params
+ * \param format printf alike format to add
+ * \param ap va_list containing the items for format
+ */
void StrBufVAppendPrintf(StrBuf *Buf, const char *format, va_list ap)
{
va_list apl;
}
}
+/**
+ * \brief sprintf like function appending the formated string to the buffer
+ * \param Buf Buffer to extend by format and params
+ * \param format printf alike format to add
+ * \param ap va_list containing the items for format
+ */
void StrBufAppendPrintf(StrBuf *Buf, const char *format, ...)
{
size_t BufSize = Buf->BufSize;
}
}
+/**
+ * \brief sprintf like function putting the formated string into the buffer
+ * \param Buf Buffer to extend by format and params
+ * \param format printf alike format to add
+ * \param ap va_list containing the items for format
+ */
void StrBufPrintf(StrBuf *Buf, const char *format, ...)
{
size_t nWritten = Buf->BufSize + 1;
}
+/**
+ * \brief Counts the numbmer of tokens in a buffer
+ * \param Source String to count tokens in
+ * \param tok Tokenizer char to count
+ * \returns numbers of tokenizer chars found
+ */
+inline int StrBufNum_tokens(const StrBuf *source, char tok)
+{
+ return num_tokens(source->buf, tok);
+}
+
/**
* \brief a string tokenizer
* \param dest Destination StringBuffer
* \param Source StringBuffer to read into
+ * \param parmnum n'th parameter to extract
* \param separator tokenizer param
* \returns -1 if not found, else length of token.
*/
}
-/*
- * extract_int() - extract an int parm w/o supplying a buffer
+/**
+ * \brief a string tokenizer to fetch an integer
+ * \param dest Destination StringBuffer
+ * \param parmnum n'th parameter to extract
+ * \param separator tokenizer param
+ * \returns 0 if not found, else integer representation of the token
*/
int StrBufExtract_int(const StrBuf* Source, int parmnum, char separator)
{
return 0;
}
-/*
- * extract_long() - extract an long parm w/o supplying a buffer
+/**
+ * \brief a string tokenizer to fetch a long integer
+ * \param dest Destination StringBuffer
+ * \param parmnum n'th parameter to extract
+ * \param separator tokenizer param
+ * \returns 0 if not found, else long integer representation of the token
*/
long StrBufExtract_long(const StrBuf* Source, int parmnum, char separator)
{
}
-/*
- * extract_unsigned_long() - extract an unsigned long parm
+/**
+ * \brief a string tokenizer to fetch an unsigned long
+ * \param dest Destination StringBuffer
+ * \param parmnum n'th parameter to extract
+ * \param separator tokenizer param
+ * \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;
tmp.buf = buf;
buf[0] = '\0';
tmp.BufSize = 64;
tmp.BufUsed = 0;
- if (StrBufExtract_token(&tmp, Source, parmnum, separator) > 0)
- return(atoi(buf));
+ if (StrBufExtract_token(&tmp, Source, parmnum, separator) > 0) {
+ pnum = &buf[0];
+ if (*pnum == '-')
+ pnum ++;
+ return (unsigned long) atol(pnum);
+ }
else
return 0;
}
/**
- * \brief Input binary data from socket
+ * \brief Read a line from socket
+ * flushes and closes the FD on error
* \param buf the buffer to get the input to
- * \param bytes the maximal number of bytes to read
+ * \param fd pointer to the filedescriptor to read
+ * \param append Append to an existing string or replace?
+ * \param Error strerror() on error
+ * \returns numbers of chars read
*/
int StrBufTCP_read_line(StrBuf *buf, int *fd, int append, const char **Error)
{
/**
* \brief Input binary data from socket
+ * flushes and closes the FD on error
* \param buf the buffer to get the input to
- * \param bytes the maximal number of bytes to read
+ * \param fd pointer to the filedescriptor to read
+ * \param append Append to an existing string or replace?
+ * \param nBytes the maximal number of bytes to read
+ * \param Error strerror() on error
+ * \returns numbers of chars read
*/
int StrBufReadBLOB(StrBuf *Buf, int *fd, int append, long nBytes, const char **Error)
{
return nRead;
}
+/**
+ * \brief Cut nChars from the start of the string
+ * \param Buf Buffer to modify
+ * \param nChars how many chars should be skipped?
+ */
void StrBufCutLeft(StrBuf *Buf, int nChars)
{
if (nChars >= Buf->BufUsed) {
Buf->buf[Buf->BufUsed] = '\0';
}
+/**
+ * \brief Cut the trailing n Chars from the string
+ * \param Buf Buffer to modify
+ * \param nChars how many chars should be trunkated?
+ */
void StrBufCutRight(StrBuf *Buf, int nChars)
{
if (nChars >= Buf->BufUsed) {
}
-/*
- * string conversion function
+/**
+ * \brief unhide special chars hidden to the HTML escaper
+ * \param target buffer to put the unescaped string in
+ * \param source buffer to unescape
*/
void StrBufEUid_unescapize(StrBuf *target, const StrBuf *source)
{
}
-/*
- * string conversion function
+/**
+ * \brief hide special chars from the HTML escapers and friends
+ * \param target buffer to put the escaped string in
+ * \param source buffer to escape
*/
void StrBufEUid_escapize(StrBuf *target, const StrBuf *source)
{
return 0;
}
+/**
+ * \brief decode a buffer from base 64 encoding; destroys original
+ * \param Buf Buffor to transform
+ */
int StrBufDecodeBase64(StrBuf *Buf)
{
char *xferbuf;
}
-/*
- * remove escaped strings from i.e. the url string (like %20 for blanks)
+/**
+ * \brief remove escaped strings from i.e. the url string (like %20 for blanks)
+ * \param Buf Buffer to translate
+ * \param StripBlanks Reduce several blanks to one?
*/
long StrBufUnescape(StrBuf *Buf, int StripBlanks)
{
return (*target)->BufUsed;;
}
+/**
+ * \brief replaces all occurances of 'search' by 'replace'
+ * \param buf Buffer to modify
+ * \param search character to search
+ * \param relpace character to replace search by
+ */
void StrBufReplaceChars(StrBuf *buf, char search, char replace)
{
long i;