From 5c83d29c2e0a786c0b3fecb7b6bf7bdafebc7e69 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sat, 12 Jul 2008 16:32:23 +0000 Subject: [PATCH] * missing encoding function added * some tiny fixes... --- libcitadel/lib/libcitadel.h | 1 + libcitadel/lib/stringbuf.c | 42 +++++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index ef20f9543..0855af01e 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -227,6 +227,7 @@ void StrBufPrintf(StrBuf *Buf, const char *format, ...) __attribute__((__format_ void StrBufCutLeft(StrBuf *Buf, int nChars); void StrBufCutRight(StrBuf *Buf, int nChars); void StrBufEUid_unescapize(StrBuf *target, StrBuf *source); +void StrBufEUid_escapize(StrBuf *target, StrBuf *source); long StrTol(StrBuf *Buf); diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 63f47b16d..30c728f44 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -1,4 +1,4 @@ - +#include #include #include #include @@ -147,7 +147,7 @@ void StrBufAppendBuf(StrBuf *Buf, StrBuf *AppendBuf, size_t Offset) return; if (Buf->BufSize - Offset < AppendBuf->BufUsed) IncreaseBuf(Buf, (Buf->BufUsed > 0), AppendBuf->BufUsed); - memcpy(Buf->buf + Buf->BufUsed - 1, + memcpy(Buf->buf + Buf->BufUsed, AppendBuf->buf + Offset, AppendBuf->BufUsed - Offset); Buf->BufUsed += AppendBuf->BufUsed - Offset; @@ -171,10 +171,10 @@ int StrBufSub(StrBuf *dest, const StrBuf *Source, size_t Offset, size_t nChars) } if (Offset + nChars < Source->BufUsed) { - if (nChars < dest->BufSize) + if (nChars > dest->BufSize) IncreaseBuf(dest, 0, nChars + 1); memcpy(dest->buf, Source->buf + Offset, nChars); - dest->BufUsed = nChars + 1; + dest->BufUsed = nChars; dest->buf[dest->BufUsed] = '\0'; return nChars; } @@ -414,3 +414,37 @@ void StrBufEUid_unescapize(StrBuf *target, StrBuf *source) } } + +/* + * string conversion function + */ +void StrBufEUid_escapize(StrBuf *target, StrBuf *source) +{ + int i, len; + + if (target != NULL) + FlushStrBuf(target); + + if (source == NULL ||target == NULL) + { + return; + } + + len = source->BufUsed; + for (i=0; iBufUsed + 4 >= target->BufSize) + IncreaseBuf(target, 1, -1); + if ( (isalnum(source->buf[i])) || + (source->buf[i]=='-') || + (source->buf[i]=='_') ) { + target->buf[target->BufUsed++] = source->buf[i]; + } + else { + sprintf(&target->buf[target->BufUsed], + "=%02X", + source->buf[i]); + target->BufUsed += 3; + } + } + target->buf[target->BufUsed + 1] = '\0'; +} -- 2.39.2