Created ctdl_iconv_open() wrapper around iconv_open()
authorArt Cancro <ajc@citadel.org>
Mon, 6 Feb 2006 04:50:39 +0000 (04:50 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 6 Feb 2006 04:50:39 +0000 (04:50 +0000)
in order to add extra charset aliases.  Nonstandard, broken Microsoft charsets such as
'MS950' are now aliased to names such as 'CP950'.  This will allow WebCit to display
broken messages created by broken Microsoft products.

webcit/html2html.c
webcit/messages.c
webcit/rss.c
webcit/webcit.h

index 1f2d358c93b75987e4aa06d49136621fa0af2227..05bc77a935f1ae189f98f7a1cce0037a6755bf14 100644 (file)
@@ -216,7 +216,7 @@ void output_html(char *supplied_charset, int treat_as_wiki) {
           && (strcasecmp(charset, ""))
        ) {
                lprintf(9, "Converting %s to UTF-8\n", charset);
-               ic = iconv_open("UTF-8", charset);
+               ic = ctdl_iconv_open("UTF-8", charset);
                if (ic == (iconv_t)(-1) ) {
                        lprintf(5, "%s:%d iconv_open() failed: %s\n",
                                __FILE__, __LINE__, strerror(errno));
index 35ee6e05d82aef38aa059787a46099ad8af66bec..ec3e13ff9580a051e0a54e8150a9faa68a3ad9de 100644 (file)
@@ -28,6 +28,32 @@ struct addrbookent {
 
 
 #ifdef HAVE_ICONV
+
+/**
+ * \brief      Wrapper around iconv_open()
+ *             Our version adds aliases for non-standard Microsoft charsets
+ *              such as 'MS950', aliasing them to names like 'CP950'
+ *
+ * \param      tocode          Target encoding
+ * \param      fromcode        Source encoding
+ */
+iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode)
+{
+       iconv_t ic = (iconv_t)(-1) ;
+       ic = iconv_open(tocode, fromcode);
+       if (ic == (iconv_t)(-1) ) {
+               char alias_fromcode[64];
+               if ( (strlen(fromcode) == 5) && (!strncasecmp(fromcode, "MS", 2)) ) {
+                       safestrncpy(alias_fromcode, fromcode, sizeof alias_fromcode);
+                       alias_fromcode[0] = 'C';
+                       alias_fromcode[1] = 'P';
+                       ic = iconv_open(tocode, alias_fromcode);
+               }
+       }
+       return(ic);
+}
+
+
 /**
  * \brief  Handle subjects with RFC2047 encoding
  *  such as:
@@ -73,7 +99,7 @@ void utf8ify_rfc822_string(char *buf) {
                        ibuflen = strlen(istr);
                }
 
-               ic = iconv_open("UTF-8", charset);
+               ic = ctdl_iconv_open("UTF-8", charset);
                if (ic != (iconv_t)(-1) ) {
                        obuf = malloc(1024);
                        obuflen = 1024;
@@ -897,7 +923,7 @@ void read_message(long msgnum, int printable_view, char *section) {
           && (strcasecmp(mime_charset, "UTF-8"))
           && (strcasecmp(mime_charset, ""))
        ) {
-               ic = iconv_open("UTF-8", mime_charset);
+               ic = ctdl_iconv_open("UTF-8", mime_charset);
                if (ic == (iconv_t)(-1) ) {
                        lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
                                __FILE__, __LINE__, mime_charset, strerror(errno));
@@ -1293,7 +1319,7 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers
           && (strcasecmp(mime_charset, "UTF-8"))
           && (strcasecmp(mime_charset, ""))
        ) {
-               ic = iconv_open("UTF-8", mime_charset);
+               ic = ctdl_iconv_open("UTF-8", mime_charset);
                if (ic == (iconv_t)(-1) ) {
                        lprintf(5, "%s:%d iconv_open() failed: %s\n",
                                __FILE__, __LINE__, strerror(errno));
index 937fcbff57bdbce48cc5434469c1add642c3091e..6a962559a27b9b6f95ead77cc68ac6dd9096f76b 100644 (file)
@@ -246,7 +246,7 @@ void display_rss(char *roomname, char *request_method)
                /** Set up a character set conversion if we need to */
 #ifdef HAVE_ICONV
                if (strcasecmp(charset, "us-ascii") && strcasecmp(charset, "utf-8") && strcasecmp(charset, "") ) {
-                       ic = iconv_open("UTF-8", charset);
+                       ic = ctdl_iconv_open("UTF-8", charset);
                        if (ic == (iconv_t)(-1)) {
                                lprintf(5, "%s:%d iconv_open() failed: %s\n",
                                        __FILE__, __LINE__, strerror(errno));
index bfad3dcaeeae2ede8c3c82421b3f852ff98cef46..eababbed8c2eb5ca8c0466e5eb13a4828e68aa6f 100644 (file)
@@ -679,6 +679,10 @@ void end_tab(int tabnum, int num_tabs);
 void str_wiki_index(char *s);
 void display_wiki_page(void);
 
+#ifdef HAVE_ICONV
+iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode);
+#endif
+
 void embed_room_banner(char *, int);
 
 /* navbar types that can be passed to embed_room_banner */