changeset 441:51b8f10cfeb8

Handle g_locale_from_utf8() failures The biggest issue was that when a message couldn't be utf8-decoded, the user was not notified of the failure, and sometimes didn't even know a message had been sent to him... I don't know if we can ask for a partial decoding, so the message isn't displayed but an error message is now displayed.
author Mikael Berthe <mikael@lilotux.net>
date Wed, 21 Sep 2005 22:05:43 +0200
parents 264f40222872
children 3741142ed9e7
files mcabber/src/jabglue.c
diffstat 1 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/jabglue.c	Tue Sep 20 23:19:36 2005 +0200
+++ b/mcabber/src/jabglue.c	Wed Sep 21 22:05:43 2005 +0200
@@ -29,6 +29,7 @@
 #include "hooks.h"
 #include "utils.h"
 #include "settings.h"
+#include "hbuf.h"
 
 #define JABBERPORT      5222
 #define JABBERSSLPORT   5223
@@ -540,11 +541,11 @@
       gchar *name_noutf8 = NULL;
       gchar *group_noutf8 = NULL;
 
+      buddyname = cleanalias;
       if (name) {
         name_noutf8 = from_utf8(name);
-        buddyname = name_noutf8;
-      } else
-        buddyname = cleanalias;
+        if (name_noutf8) buddyname = name_noutf8;
+      }
 
       if (group)
         group_noutf8 = from_utf8(group);
@@ -565,6 +566,18 @@
   char *jid;
   gchar *buffer = from_utf8(body);
 
+  jid = jidtodisp(from);
+
+  if (!buffer && body) {
+    scr_LogPrint(LPRINT_LOGNORM, "Decoding of message from <%s> has failed",
+                 from);
+    scr_WriteIncomingMessage(jid, "Cannot display message: "
+                             "UTF-8 conversion failure",
+                             0, HBB_PREFIX_ERR | HBB_PREFIX_IN);
+    g_free(jid);
+    return;
+  }
+
   /*
   //char *u, *h, *r;
   //jidsplit(from, &u, &h, &r);
@@ -576,7 +589,6 @@
   //             jidtodisp(from), type);
   */
 
-  jid = jidtodisp(from);
   hk_message_in(jid, timestamp, buffer, type);
   g_free(jid);
   g_free(buffer);