-//
// 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;
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);
}
// Remove wandering punctuation
- if ((ptr = strchr(charset, '\"')))
+ if ((ptr = strchr(charset, '\"'))) {
*ptr = 0;
+ }
string_trim(charset);
}
}
// 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;
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);
// 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)) {
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)) {
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
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++;
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] == ';') ||
// 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