From 95ce924064310c1cb86dfcd649f54dfdb081c0d3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Tue, 26 May 2009 20:18:33 +0000 Subject: [PATCH] * add slash-stripper * fix another possible hickup situation in the linebuffered reader. --- libcitadel/lib/libcitadel.h | 1 + libcitadel/lib/stringbuf.c | 4 ++-- libcitadel/lib/tools.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 83bbddcf3..4c378b9fa 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -351,6 +351,7 @@ size_t CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen, int li int CtdlDecodeBase64(char *dest, const char *source, size_t length); unsigned int decode_hex(char *Source); int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen); +void StripSlashes(char *Dir, int TrailingSlash); size_t striplt(char *); int haschar(const char *st, int ch); void remove_token(char *source, int parmnum, char separator); diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 33a472d88..4990429ca 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -1553,9 +1553,9 @@ int StrBufTCP_read_buffered_line_fast(StrBuf *Line, { pche = buf->buf + buf->BufUsed; pch = pos; - while ((pch <= pche) && (*pch != '\n')) + while ((pch < pche) && (*pch != '\n')) pch ++; - if (*pch == 0) + if ((pch >= pche) || (*pch == '\0')) pch = NULL; if ((pch != NULL) && (pch <= pche)) diff --git a/libcitadel/lib/tools.c b/libcitadel/lib/tools.c index 7d933de11..5662133be 100644 --- a/libcitadel/lib/tools.c +++ b/libcitadel/lib/tools.c @@ -456,6 +456,35 @@ char *rfc2047encode(char *line, long length) return result; } +/* + * removes double slashes from pathnames + * allows / disallows trailing slashes + */ +void StripSlashes(char *Dir, int TrailingSlash) +{ + char *a, *b; + + a = b = Dir; + + while (!IsEmptyStr(a)) { + if (*a == '/') { + while (*a == '/') + a++; + *b = '/'; + b++; + } + else { + *b = *a; + b++; a++; + } + } + if ((TrailingSlash) && (*(b - 1) != '/')){ + *b = '/'; + b++; + } + *b = '\0'; + +} /* * Strip leading and trailing spaces from a string -- 2.30.2