* add fuction for ascii sanitation
authorWilfried Göesgens <willi@citadel.org>
Wed, 11 Feb 2009 19:48:30 +0000 (19:48 +0000)
committerWilfried Göesgens <willi@citadel.org>
Wed, 11 Feb 2009 19:48:30 +0000 (19:48 +0000)
libcitadel/lib/libcitadel.h
libcitadel/lib/stringbuf.c

index 6137d0f145427ddeb0ad5bff35abc1ea7f211726..50d87f241591893439a06f450d182aa23598e3ac 100644 (file)
@@ -276,6 +276,7 @@ void ctdl_iconv_open(const char *tocode, const char *fromcode, void *pic);
 void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* DefaultCharset, StrBuf *FoundCharset);
 int StrBufDecodeBase64(StrBuf *Buf);
 int StrBufRFC2047encode(StrBuf **target, const StrBuf *source);
+int StrBufSanitizeAscii(StrBuf *Buf, const char Mute);
 #define LB                     (1)             /* Internal escape chars */
 #define RB                     (2)
 #define QU                     (3)
index f669ecf362ae895a76d078358a58e8fb9fda6ad6..1c544d9d10714ca644ac744450d4ad6901d74e1e 100644 (file)
@@ -1499,6 +1499,25 @@ int StrBufDecodeBase64(StrBuf *Buf)
        return siz;
 }
 
+/**
+ * \brief replace all chars >0x20 && < 0x7F with Mute
+ * \param Mute char to put over invalid chars
+ * \param Buf Buffor to transform
+ */
+int StrBufSanitizeAscii(StrBuf *Buf, const char Mute)
+{
+       char *pch;
+
+       if (Buf == NULL) return -1;
+       pch = Buf->buf;
+       while (pch < Buf->buf + Buf->BufUsed) {
+               if ((*pch < 0x20) || (*pch > 0x7F))
+                       *pch = Mute;
+               pch ++;
+       }
+       return Buf->BufUsed;
+}
+
 
 /**
  * \brief  remove escaped strings from i.e. the url string (like %20 for blanks)