From: Wilfried Göesgens Date: Sun, 14 Sep 2008 15:43:47 +0000 (+0000) Subject: * add define to easy make a hashkey from a stringbuffer X-Git-Tag: v7.86~1938 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=a92dc8b0a83c0afa3976ce95c5d186223ba34651;p=citadel.git * add define to easy make a hashkey from a stringbuffer * add StrBufRemoveToken * add StrBufUpcase --- diff --git a/libcitadel/debian/files b/libcitadel/debian/files index 73fc3064e..d2ac0561c 100644 --- a/libcitadel/debian/files +++ b/libcitadel/debian/files @@ -1,3 +1,3 @@ -libcitadel1_7.38-8_amd64.deb libs optional -libcitadel1-dbg_7.38-8_amd64.deb libdevel optional -libcitadel-dev_7.38-8_amd64.deb libdevel optional +libcitadel1_7.38-8_i386.deb libs optional +libcitadel1-dbg_7.38-8_i386.deb libdevel optional +libcitadel-dev_7.38-8_i386.deb libdevel optional diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index b629d0dd4..f67c6f147 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -214,6 +214,7 @@ int FlushStrBuf(StrBuf *buf); inline const char *ChrPtr(const StrBuf *Str); inline int StrLength(const StrBuf *Str); +#define SKEY(a) ChrPtr(a), StrLength(a) long StrBufPeek(StrBuf *Buf, const char* ptr, long nThChar, char PeekValue); int StrBufTCP_read_line(StrBuf *buf, int *fd, int append, const char **Error); @@ -231,6 +232,7 @@ unsigned long StrBufExtract_unsigned_long(const StrBuf* Source, int parmnum, cha long StrBufExtract_long(const StrBuf* Source, int parmnum, char separator); int StrBufExtract_int(const StrBuf* Source, int parmnum, char separator); inline int StrBufNum_tokens(const StrBuf *source, char tok); +int StrBufRemove_token(StrBuf *Source, int parmnum, char separator); void StrBufAppendBufPlain(StrBuf *Buf, const char *AppendBuf, long AppendSize, size_t Offset); void StrBufAppendBuf(StrBuf *Buf, const StrBuf *AppendBuf, size_t Offset); @@ -242,6 +244,7 @@ void StrBufVAppendPrintf(StrBuf *Buf, const char *format, va_list ap); void StrBufPrintf(StrBuf *Buf, const char *format, ...) __attribute__((__format__(__printf__,2,3))); void StrBufCutLeft(StrBuf *Buf, int nChars); void StrBufCutRight(StrBuf *Buf, int nChars); +void StrBufUpCase(StrBuf *Buf); void StrBufEUid_unescapize(StrBuf *target, const StrBuf *source); void StrBufEUid_escapize(StrBuf *target, const StrBuf *source); diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 6d429a689..e2dae7730 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -24,6 +24,10 @@ struct StrBuf { /** * \Brief 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! * \param Str the string we want to get the c-string representation for * \returns the Pointer to the Content. Don't mess with it! */ @@ -700,9 +704,73 @@ void StrBufPrintf(StrBuf *Buf, const char *format, ...) */ inline int StrBufNum_tokens(const StrBuf *source, char tok) { + if (source == NULL) + return 0; return num_tokens(source->buf, tok); } +/* + * remove_token() - a tokenizer that kills, maims, and destroys + */ +/** + * \brief a string tokenizer + * \param Source StringBuffer to read into + * \param parmnum n'th parameter to remove + * \param separator tokenizer param + * \returns -1 if not found, else length of token. + */ +int StrBufRemove_token(StrBuf *Source, int parmnum, char separator) +{ + int ReducedBy; + char *d, *s; /* dest, source */ + int count = 0; + + /* Find desired parameter */ + d = Source->buf; + while (count < parmnum) { + /* End of string, bail! */ + if (!*d) { + d = NULL; + break; + } + if (*d == separator) { + count++; + } + d++; + } + if (!d) return 0; /* Parameter not found */ + + /* Find next parameter */ + s = d; + while (*s && *s != separator) { + s++; + } + + ReducedBy = d - s; + + /* Hack and slash */ + if (*s) { + memmove(d, s, Source->BufUsed - (s - Source->buf)); + Source->BufUsed -= (ReducedBy + 1); + } + else if (d == Source->buf) { + *d = 0; + Source->BufUsed = 0; + } + else { + *--d = 0; + Source->BufUsed -= (ReducedBy + 1); + } + /* + while (*s) { + *d++ = *s++; + } + *d = 0; + */ + return ReducedBy; +} + + /** * \brief a string tokenizer * \param dest Destination StringBuffer @@ -912,7 +980,7 @@ int StrBufTCP_read_buffered_line(StrBuf *Line, return len - rlen; } } - + if (buf->BufSize - buf->BufUsed < 10) IncreaseBuf(buf, 1, -1); @@ -1057,6 +1125,19 @@ void StrBufCutRight(StrBuf *Buf, int nChars) } +void StrBufUpCase(StrBuf *Buf) +{ + char *pch, *pche; + + pch = Buf->buf; + pche = pch + Buf->BufUsed; + while (pch < pche) { + *pch = toupper(*pch); + pch ++; + } +} + + /** * \brief unhide special chars hidden to the HTML escaper * \param target buffer to put the unescaped string in