changeset 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 df5837a72b35
children 2c7cca6dec6a
files mcabber/mcabber/nohtml.c mcabber/mcabber/otr.c
diffstat 2 files changed, 24 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabber/nohtml.c	Sat Feb 13 13:48:43 2016 +0100
+++ b/mcabber/mcabber/nohtml.c	Fri Feb 19 22:14:15 2016 +0100
@@ -38,17 +38,15 @@
  */
 char *html_strip(const char *htmlbuf)
 {
-  int i, j=0;
+  int i, j=0, html_len;
   char *nohtml;
 
   if (!htmlbuf) return(NULL);
 
   nohtml = g_strdup(htmlbuf);
 
-  if (!strchr(htmlbuf, '&') && !strchr(htmlbuf, '<'))
-    return(nohtml);
-
-  for (i = 0; i < (int)strlen(htmlbuf); i++) {
+  html_len = (int)strlen(htmlbuf);
+  for (i = 0; i < html_len; i++) {
     if (htmlbuf[i] == '&') {
       if (!strncmp(&htmlbuf[i],"&amp;",5)) {
         nohtml[j] = '&';
@@ -65,15 +63,26 @@
       } else if (!strncmp(&htmlbuf[i],"&gt;", 4)) {
         nohtml[j] = '>';
         i += 3;
+      } else {
+        nohtml[j] = htmlbuf[i];
       }
-    } else if (!strncmp(&htmlbuf[i],"<br>", 4) ||
-               !strncmp(&htmlbuf[i],"<br/>", 5)) {
-      nohtml[j] = '\n';
-      i += (htmlbuf[i+3] == '/' ? 4 : 3);
     } else if (htmlbuf[i] == '<') {
-      /* Let's strip all unknown tags */
-      j--;
-      while (htmlbuf[++i] != '>');
+      if (!strncmp(&htmlbuf[i],"<br>", 4)) {
+        nohtml[j] = '\n';
+        i += 3;
+      } else if (!strncmp(&htmlbuf[i],"<br/>", 5)) {
+        nohtml[j] = '\n';
+        i += 4;
+      } else if (!strncmp(&htmlbuf[i],"<FONT>", 6)) {
+        /* Let's strip <FONT> from Adium */
+        i += 5;
+        j--;
+      } else if (!strncmp(&htmlbuf[i],"</FONT>", 7)) {
+        i += 6;
+        j--;
+      } else {
+        nohtml[j] = htmlbuf[i];
+      }
     } else
       nohtml[j] = htmlbuf[i];
     j++;
--- a/mcabber/mcabber/otr.c	Sat Feb 13 13:48:43 2016 +0100
+++ b/mcabber/mcabber/otr.c	Fri Feb 19 22:14:15 2016 +0100
@@ -610,7 +610,7 @@
 {
   gcry_error_t err;
   char *newmessage = NULL;
-  char *htmlmsg, *rmsg;
+  char *rmsg;
   ConnContext *ctx = otr_get_context(buddy);
 
   if (!encryption_status)
@@ -633,18 +633,16 @@
                                NULL, NULL, NULL);
 #endif
   else {
-    htmlmsg = html_escape(msg);
     err = otrl_message_sending(userstate, &ops, NULL, ctx->accountname,
 #ifdef HAVE_LIBOTR3
-                               ctx->protocol, ctx->username, htmlmsg, NULL,
+                               ctx->protocol, ctx->username, msg, NULL,
                                &newmessage, NULL, NULL);
 #else
                                // INSTAG XXX
                                ctx->protocol, ctx->username, OTRL_INSTAG_BEST,
-                               htmlmsg, NULL, &newmessage, OTRL_FRAGMENT_SEND_SKIP,
+                               msg, NULL, &newmessage, OTRL_FRAGMENT_SEND_SKIP,
                                NULL, NULL, NULL);
 #endif
-    g_free(htmlmsg);
   }
 
   if (err)