changeset 590:a5707d61e469

Fix a few UTF-8 related issues
author Mikael Berthe <mikael@lilotux.net>
date Sat, 10 Dec 2005 23:18:26 +0100
parents 9942746e8d58
children 5a685e9012b4
files mcabber/src/commands.c mcabber/src/jabglue.c
diffstat 2 files changed, 35 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/commands.c	Sat Dec 10 20:17:49 2005 +0100
+++ b/mcabber/src/commands.c	Sat Dec 10 23:18:26 2005 +0100
@@ -1514,14 +1514,8 @@
   scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
 
   if (realjid) {
-    gchar *rjid_noutf8 = from_utf8(realjid);
-    if (!rjid_noutf8)
-      scr_LogPrint(LPRINT_LOGNORM, "Decoding of real JID has failed: %s",
-                   realjid);
-    snprintf(buffer, 127, "JID      : <%s>", rjid_noutf8);
+    snprintf(buffer, 127, "JID      : <%s>", realjid);
     scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
-    if (rjid_noutf8)
-      g_free(rjid_noutf8);
   }
 
   snprintf(buffer, 127, "Role     : %s", strroles[role]);
--- a/mcabber/src/jabglue.c	Sat Dec 10 20:17:49 2005 +0100
+++ b/mcabber/src/jabglue.c	Sat Dec 10 23:18:26 2005 +0100
@@ -254,15 +254,18 @@
 // Create an xmlnode with default presence attributes
 // Note: the caller must free the node after use
 static xmlnode presnew(enum imstatus st, const char *recipient,
-                        const char *msg)
+                       const char *msg)
 {
   unsigned int prio;
   xmlnode x;
+  gchar *utf8_recipient = to_utf8(recipient);
 
   x = jutil_presnew(JPACKET__UNKNOWN, 0, 0);
 
-  if (recipient)
-    xmlnode_put_attrib(x, "to", recipient);
+  if (utf8_recipient) {
+    xmlnode_put_attrib(x, "to", utf8_recipient);
+    g_free(utf8_recipient);
+  }
 
   switch(st) {
     case away:
@@ -377,7 +380,8 @@
 {
   xmlnode x;
   gchar *strtype;
-  gchar *buffer = to_utf8(text);
+  gchar *utf8_jid;
+  gchar *buffer;
 
   if (!online) return;
 
@@ -386,7 +390,10 @@
   else
     strtype = TMSG_CHAT;
 
-  x = jutil_msgnew(strtype, (char*)jid, NULL, (char*)buffer);
+  buffer = to_utf8(text);
+  utf8_jid = to_utf8(jid); // Resource can require UTF-8
+
+  x = jutil_msgnew(strtype, utf8_jid, NULL, (char*)buffer);
   if (subject) {
     xmlnode y;
     char *bs = to_utf8(subject);
@@ -396,7 +403,10 @@
   }
   jab_send(jc, x);
   xmlnode_free(x);
-  g_free(buffer);
+
+  if (buffer) g_free(buffer);
+  if (utf8_jid) g_free(utf8_jid);
+
   jb_reset_keepalive();
 }
 
@@ -408,18 +418,20 @@
 
   if (!online) return;
 
+  cleanjid = jidtodisp(jid);
+
   // We don't check if the jabber user already exists in the roster,
   // because it allows to re-ask for notification.
 
-  //x = jutil_presnew(JPACKET__SUBSCRIBE, jid, NULL);
-  x = jutil_presnew(JPACKET__SUBSCRIBE, (char*)jid, "online");
+  //x = jutil_presnew(JPACKET__SUBSCRIBE, cleanjid, NULL);
+  x = jutil_presnew(JPACKET__SUBSCRIBE, cleanjid, "online");
   jab_send(jc, x);
   xmlnode_free(x);
 
   x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
   y = xmlnode_get_tag(x, "query");
   z = xmlnode_insert_tag(y, "item");
-  xmlnode_put_attrib(z, "jid", jid);
+  xmlnode_put_attrib(z, "jid", cleanjid);
 
   if (name) {
     gchar *name_utf8 = to_utf8(name);
@@ -438,7 +450,6 @@
   jab_send(jc, x);
   xmlnode_free(x);
 
-  cleanjid = jidtodisp(jid);
   roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER);
   g_free(cleanjid);
   buddylist_build();
@@ -606,7 +617,9 @@
   z = xmlnode_insert_tag(y, "item");
 
   if (jid) {
-    xmlnode_put_attrib(z, "jid", jid);
+    gchar *utf8_jid = to_utf8(jid);
+    xmlnode_put_attrib(z, "jid", utf8_jid);
+    if (utf8_jid) g_free(utf8_jid);
   } else { // nick
     gchar *utf8_nickname = to_utf8(nick);
     xmlnode_put_attrib(z, "nick", utf8_nickname);
@@ -638,6 +651,7 @@
 void jb_room_invite(const char *room, const char *jid, const char *reason)
 {
   xmlnode x, y, z;
+  gchar *utf8_jid;
 
   if (!online || !room || !jid) return;
 
@@ -646,8 +660,10 @@
   y = xmlnode_insert_tag(x, "x");
   xmlnode_put_attrib(y, "xmlns", "http://jabber.org/protocol/muc#user");
 
+  utf8_jid = to_utf8(jid); // Resource can require UTF-8
   z = xmlnode_insert_tag(y, "invite");
-  xmlnode_put_attrib(z, "to", jid);
+  xmlnode_put_attrib(z, "to", utf8_jid);
+  if (utf8_jid) g_free(utf8_jid);
 
   if (reason) {
     gchar *utf8_reason = to_utf8(reason);
@@ -998,10 +1014,13 @@
   }
 
   // Update room member status
-  if (rname)
+  if (rname) {
+    gchar *mbrjid_noutf8 = from_utf8(mbjid);
     roster_setstatus(roomjid, rname, bpprio, ust, ustmsg,
-                     mbrole, mbaffil, mbjid);
-  else
+                     mbrole, mbaffil, mbrjid_noutf8);
+    if (mbrjid_noutf8)
+      g_free(mbrjid_noutf8);
+  } else
     scr_LogPrint(LPRINT_LOGNORM, "MUC DBG: no rname!"); /* DBG */
 
   buddylist_build();