* add slash-stripper
authorWilfried Göesgens <willi@citadel.org>
Tue, 26 May 2009 20:18:33 +0000 (20:18 +0000)
committerWilfried Göesgens <willi@citadel.org>
Tue, 26 May 2009 20:18:33 +0000 (20:18 +0000)
* fix another possible hickup situation in the linebuffered reader.

libcitadel/lib/libcitadel.h
libcitadel/lib/stringbuf.c
libcitadel/lib/tools.c

index 83bbddcf3ac9bab72d147d30e6abca16be6ec62c..4c378b9fa61668de8230ce8772be0b972dca95d1 100644 (file)
@@ -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);
index 33a472d88df7449cd83e88881f331ca79fcad46a..4990429ca9e18dc19b48ff35da40829d5c125163 100644 (file)
@@ -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)) 
index 7d933de1195b9e2d308a40f3e3304ed1ce2f972e..5662133be92854609a719e33d314a85281ad3646 100644 (file)
@@ -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