]> code.citadel.org Git - citadel.git/blobdiff - webcit-ng/server/html2html.c
moved whitespace around
[citadel.git] / webcit-ng / server / html2html.c
index ab37b7b0896a097a4405e9937f6c048e9360af6a..8fb8be6305a6975cd27aa95f5afbc0508ead4678 100644 (file)
@@ -1,11 +1,9 @@
-//
 // Output an HTML message, modifying it slightly to make sure it plays nice
 // with the rest of our web framework.
 //
-// Copyright (c) 2005-2022 by the citadel.org team
+// Copyright (c) 2005-2024 by the citadel.org team
 //
-// This program is open source software.  Use, duplication, or
-// disclosure are subject to the GNU General Public License v3.
+// This program is open source software.  Use, duplication, or disclosure is subject to the GNU General Public License v3.
 
 #include "webcit.h"
 
 void stripquotes(char *s) {
        int len;
 
-       if (!s)
+       if (!s) {
                return;
+       }
 
        len = strlen(s);
-       if (len < 2)
+       if (len < 2) {
                return;
+       }
 
        if (((s[0] == '\"') && (s[len - 1] == '\"')) || ((s[0] == '\'') && (s[len - 1] == '\''))) {
                s[len - 1] = 0;
@@ -37,19 +37,24 @@ void extract_charset_from_meta(char *charset, char *meta_http_equiv, char *meta_
        char *ptr;
        char buf[64];
 
-       if (!charset)
+       if (!charset) {
                return;
-       if (!meta_http_equiv)
+       }
+       if (!meta_http_equiv) {
                return;
-       if (!meta_content)
+       }
+       if (!meta_content) {
                return;
+       }
 
-       if (strcasecmp(meta_http_equiv, "Content-type"))
+       if (strcasecmp(meta_http_equiv, "Content-type")) {
                return;
+       }
 
        ptr = strchr(meta_content, ';');
-       if (!ptr)
+       if (!ptr) {
                return;
+       }
 
        safestrncpy(buf, ++ptr, sizeof buf);
        string_trim(buf);
@@ -66,8 +71,9 @@ void extract_charset_from_meta(char *charset, char *meta_http_equiv, char *meta_
                }
 
                // Remove wandering punctuation
-               if ((ptr = strchr(charset, '\"')))
+               if ((ptr = strchr(charset, '\"'))) {
                        *ptr = 0;
+               }
                string_trim(charset);
        }
 }
@@ -76,7 +82,7 @@ void extract_charset_from_meta(char *charset, char *meta_http_equiv, char *meta_
 // Sanitize and enhance an HTML message for display.
 // Also convert weird character sets to UTF-8 if necessary.
 // Also fixup img src="cid:..." type inline images to fetch the image
-StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomname, long msgnum, StrBuf *Source) {
+StrBuf *html2html(const char *charset_in, int treat_as_wiki, char *roomname, long msgnum, StrBuf *Source) {
        char buf[SIZ];
        char *msg;
        char *ptr;
@@ -108,7 +114,7 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam
                return (NULL);
        }
 
-       safestrncpy(charset, supplied_charset, sizeof charset);
+       safestrncpy(charset, charset_in, sizeof charset);
        sprintf(new_window, "<a target=\"%s\" href=", TARGET);
 
        content_length = StrLength(Source);
@@ -174,10 +180,11 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam
 
                // Any of these tags cause everything up to and including
                // the tag to be removed.
-               if ((!strncasecmp(ptr, "HTML", 4))
-                   || (!strncasecmp(ptr, "HEAD", 4))
-                   || (!strncasecmp(ptr, "/HEAD", 5))
-                   || (!strncasecmp(ptr, "BODY", 4))) {
+               if (    (!strncasecmp(ptr, "HTML", 4))
+                       || (!strncasecmp(ptr, "HEAD", 4))
+                       || (!strncasecmp(ptr, "/HEAD", 5))
+                       || (!strncasecmp(ptr, "BODY", 4))
+               ) {
                        char *pBody = NULL;
 
                        if (!strncasecmp(ptr, "BODY", 4)) {
@@ -245,10 +252,10 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam
        converted_msg = NewStrBufPlain(NULL, content_length + 8192);
 
        // Convert foreign character sets to UTF-8 if necessary
-       if ((strcasecmp(charset, "us-ascii"))
-           && (strcasecmp(charset, "UTF-8"))
-           && (strcasecmp(charset, ""))
-           ) {
+       if (    (strcasecmp(charset, "us-ascii"))
+               && (strcasecmp(charset, "UTF-8"))
+               && (strcasecmp(charset, ""))
+       ) {
                syslog(LOG_DEBUG, "Converting %s to UTF-8", charset);
                ctdl_iconv_open("UTF-8", charset, &ic);
                if (ic == (iconv_t) (-1)) {
@@ -334,10 +341,10 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam
                                ptr = &ptr[8];
                        }
                        else if ((treat_as_wiki)
-                                  && (strncasecmp(ptr, "<a href=\"wiki?", 14))
-                                  && (strncasecmp(ptr, "<a href=\"dotgoto?", 17))
-                                  && (strncasecmp(ptr, "<a href=\"knrooms?", 17))
-                           ) {
+                               && (strncasecmp(ptr, "<a href=\"wiki?", 14))
+                               && (strncasecmp(ptr, "<a href=\"dotgoto?", 17))
+                               && (strncasecmp(ptr, "<a href=\"knrooms?", 17))
+                       ) {
                                content_length += 64;
                                StrBufAppendPrintf(converted_msg, "<a href=\"wiki?go=");
                                //StrBufUrlescAppend(converted_msg, "FIXME ROOM NAME", NULL);                   // FIXME make compatible with webcit-ng
@@ -366,11 +373,12 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam
                        src = strstr(ptr, "src=\"cid:");
                        ++brak;
 
-                       if (src && isspace(*(src - 1))
-                           && tag_end && (cid_start = strchr(src, ':'))
-                           && (cid_end = strchr(cid_start, '"'))
-                           && (cid_end < tag_end)
-                           ) {
+                       if (    src
+                               && isspace(*(src - 1))
+                               && tag_end && (cid_start = strchr(src, ':'))
+                               && (cid_end = strchr(cid_start, '"'))
+                               && (cid_end < tag_end)
+                       ) {
                                // copy tag and attributes up to src="cid:
                                StrBufAppendBufPlain(converted_msg, ptr, src - ptr, 0);
                                cid_start++;
@@ -398,20 +406,21 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam
 
                        strlenptr = strlen(ptr);
                        for (i = 0; i <= strlenptr; ++i) {
-                               if ((ptr[i] == 0)
-                                   || (isspace(ptr[i]))
-                                   || (ptr[i] == 10)
-                                   || (ptr[i] == 13)
-                                   || (ptr[i] == '(')
-                                   || (ptr[i] == ')')
-                                   || (ptr[i] == '<')
-                                   || (ptr[i] == '>')
-                                   || (ptr[i] == '[')
-                                   || (ptr[i] == ']')
-                                   || (ptr[i] == '"')
-                                   || (ptr[i] == '\'')
-                                   )
+                               if (    (ptr[i] == 0)
+                                       || (isspace(ptr[i]))
+                                       || (ptr[i] == 10)
+                                       || (ptr[i] == 13)
+                                       || (ptr[i] == '(')
+                                       || (ptr[i] == ')')
+                                       || (ptr[i] == '<')
+                                       || (ptr[i] == '>')
+                                       || (ptr[i] == '[')
+                                       || (ptr[i] == ']')
+                                       || (ptr[i] == '"')
+                                       || (ptr[i] == '\'')
+                               ) {
                                        linklen = i;
+                               }
                                // entity tag?
                                if (ptr[i] == '&') {
                                        if ((ptr[i + 2] == ';') ||
@@ -493,7 +502,7 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam
        // Output our big pile of markup
        StrBufAppendBuf(Target, converted_msg, 0);
 
-      BAIL:                    // A little trailing vertical whitespace...
+BAIL:  // A little trailing vertical whitespace...
        StrBufAppendPrintf(Target, "<br>\n");
 
        // Now give back the memory