comparison mcabber/mcabber/nohtml.c @ 2251:f3bd1564fa70

Stop html-escaping otr messages and do only strip known tags. We'd like to remove that for good, but pidgin-otr and Adium are still sending html tags.
author franky
date Fri, 19 Feb 2016 22:14:15 +0100
parents e6d355e50d7a
children f5402d705f67
comparison
equal deleted inserted replaced
2250:df5837a72b35 2251:f3bd1564fa70
36 * The caller must g_free the string after use. 36 * The caller must g_free the string after use.
37 * Code mostly derived from strunescape(), in libjabber. 37 * Code mostly derived from strunescape(), in libjabber.
38 */ 38 */
39 char *html_strip(const char *htmlbuf) 39 char *html_strip(const char *htmlbuf)
40 { 40 {
41 int i, j=0; 41 int i, j=0, html_len;
42 char *nohtml; 42 char *nohtml;
43 43
44 if (!htmlbuf) return(NULL); 44 if (!htmlbuf) return(NULL);
45 45
46 nohtml = g_strdup(htmlbuf); 46 nohtml = g_strdup(htmlbuf);
47 47
48 if (!strchr(htmlbuf, '&') && !strchr(htmlbuf, '<')) 48 html_len = (int)strlen(htmlbuf);
49 return(nohtml); 49 for (i = 0; i < html_len; i++) {
50
51 for (i = 0; i < (int)strlen(htmlbuf); i++) {
52 if (htmlbuf[i] == '&') { 50 if (htmlbuf[i] == '&') {
53 if (!strncmp(&htmlbuf[i],"&amp;",5)) { 51 if (!strncmp(&htmlbuf[i],"&amp;",5)) {
54 nohtml[j] = '&'; 52 nohtml[j] = '&';
55 i += 4; 53 i += 4;
56 } else if (!strncmp(&htmlbuf[i],"&quot;", 6)) { 54 } else if (!strncmp(&htmlbuf[i],"&quot;", 6)) {
63 nohtml[j] = '<'; 61 nohtml[j] = '<';
64 i += 3; 62 i += 3;
65 } else if (!strncmp(&htmlbuf[i],"&gt;", 4)) { 63 } else if (!strncmp(&htmlbuf[i],"&gt;", 4)) {
66 nohtml[j] = '>'; 64 nohtml[j] = '>';
67 i += 3; 65 i += 3;
66 } else {
67 nohtml[j] = htmlbuf[i];
68 } 68 }
69 } else if (!strncmp(&htmlbuf[i],"<br>", 4) ||
70 !strncmp(&htmlbuf[i],"<br/>", 5)) {
71 nohtml[j] = '\n';
72 i += (htmlbuf[i+3] == '/' ? 4 : 3);
73 } else if (htmlbuf[i] == '<') { 69 } else if (htmlbuf[i] == '<') {
74 /* Let's strip all unknown tags */ 70 if (!strncmp(&htmlbuf[i],"<br>", 4)) {
75 j--; 71 nohtml[j] = '\n';
76 while (htmlbuf[++i] != '>'); 72 i += 3;
73 } else if (!strncmp(&htmlbuf[i],"<br/>", 5)) {
74 nohtml[j] = '\n';
75 i += 4;
76 } else if (!strncmp(&htmlbuf[i],"<FONT>", 6)) {
77 /* Let's strip <FONT> from Adium */
78 i += 5;
79 j--;
80 } else if (!strncmp(&htmlbuf[i],"</FONT>", 7)) {
81 i += 6;
82 j--;
83 } else {
84 nohtml[j] = htmlbuf[i];
85 }
77 } else 86 } else
78 nohtml[j] = htmlbuf[i]; 87 nohtml[j] = htmlbuf[i];
79 j++; 88 j++;
80 } 89 }
81 nohtml[j] = '\0'; 90 nohtml[j] = '\0';