changeset 213:4fcdbfdf7c20

[/trunk] Changeset 225 by mikael * Fix a crash when renaming to a non-7bit name (same with group name) * Move all utf-8 usage to jabglue
author mikael
date Sun, 08 May 2005 20:27:14 +0000
parents 465d98d2f8e3
children 9484ba81ec53
files mcabber/src/TODO mcabber/src/commands.c mcabber/src/hooks.c mcabber/src/jabglue.c
diffstat 4 files changed, 34 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/TODO	Sun May 08 19:59:04 2005 +0000
+++ b/mcabber/src/TODO	Sun May 08 20:27:14 2005 +0000
@@ -2,7 +2,6 @@
 BUGS:
 
 * Colors are misnamed
-* Use UTF-8 when sending buddy name
 
 
 TODO:
--- a/mcabber/src/commands.c	Sun May 08 19:59:04 2005 +0000
+++ b/mcabber/src/commands.c	Sun May 08 20:27:14 2005 +0000
@@ -149,7 +149,6 @@
 // the network.
 void send_message(char *msg)
 {
-  char *buffer;
   const char *jid;
       
   if (!current_buddy) {
@@ -167,9 +166,7 @@
   hk_message_out(jid, 0, msg);
 
   // Network part
-  buffer = utf8_encode(msg);
-  jb_send_msg(jid, buffer);
-  free(buffer);
+  jb_send_msg(jid, msg);
 }
 
 //  process_line(line)
--- a/mcabber/src/hooks.c	Sun May 08 19:59:04 2005 +0000
+++ b/mcabber/src/hooks.c	Sun May 08 20:27:14 2005 +0000
@@ -32,7 +32,6 @@
 
 inline void hk_message_in(const char *jid, time_t timestamp, const char *msg)
 {
-  char *buffer = utf8_decode(msg);
   int new_guy = FALSE;
 
   // If this user isn't in the roster, we add it
@@ -44,10 +43,9 @@
   // Note: the hlog_write should not be called first, because in some
   // cases scr_WriteIncomingMessage() will load the history and we'd
   // have the message twice...
-  scr_WriteIncomingMessage(jid, buffer, timestamp, 0);
-  hlog_write_message(jid, timestamp, FALSE, buffer);
+  scr_WriteIncomingMessage(jid, msg, timestamp, 0);
+  hlog_write_message(jid, timestamp, FALSE, msg);
   hk_ext_cmd(jid, 'M', 'R', NULL);
-  free(buffer);
   // We need to rebuild the list if the sender is unknown or
   // if the sender is offline/invisible and hide_offline_buddies is set
   if (new_guy ||
--- a/mcabber/src/jabglue.c	Sun May 08 19:59:04 2005 +0000
+++ b/mcabber/src/jabglue.c	Sun May 08 20:27:14 2005 +0000
@@ -26,6 +26,7 @@
 #include "roster.h"
 #include "screen.h"
 #include "hooks.h"
+#include "utf8.h"
 #include "utils.h"
 
 #define JABBERPORT      5222
@@ -290,12 +291,15 @@
 
 void jb_send_msg(const char *jid, const char *text)
 {
-  xmlnode x = jutil_msgnew(TMSG_CHAT, (char*)jid, 0, (char*)text);
+  char *buffer = utf8_encode(text);
+  xmlnode x = jutil_msgnew(TMSG_CHAT, (char*)jid, 0, (char*)buffer);
   jab_send(jc, x);
   xmlnode_free(x);
+  free(buffer);
   jb_reset_keepalive();
 }
 
+// Note: the caller should check the jid is correct
 void jb_addbuddy(const char *jid, const char *group)
 {
   xmlnode x, y, z;
@@ -317,8 +321,10 @@
   xmlnode_put_attrib(z, "jid", jid);
 
   if (group) {
+    char *group_utf8 = utf8_encode(group);
     z = xmlnode_insert_tag(z, "group");
-    xmlnode_insert_cdata(z, group, (unsigned) -1);
+    xmlnode_insert_cdata(z, group_utf8, (unsigned) -1);
+    free(group_utf8);
   }
 
   jab_send(jc, x);
@@ -329,7 +335,7 @@
   g_free(cleanjid);
   buddylist_build();
 
-  // maybe not needed: if user appears his status will change
+  // useless IMHO: if user appears his status will change
   //update_roster = TRUE;
 }
 
@@ -379,25 +385,30 @@
 {
   xmlnode x, y;
   char *cleanjid;
+  char *name_utf8;
 
   if (!online) return;
 
   // XXX We should check name's and group's correctness
 
   cleanjid = jidtodisp(jid);
+  name_utf8 = utf8_encode(name);
 
   x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
   y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item");
   xmlnode_put_attrib(y, "jid", cleanjid);
-  xmlnode_put_attrib(y, "name", name);
+  xmlnode_put_attrib(y, "name", name_utf8);
 
   if (group) {
+    char *group_utf8 = utf8_encode(group);
     y = xmlnode_insert_tag(y, "group");
-    xmlnode_insert_cdata(y, group, (unsigned) -1);
+    xmlnode_insert_cdata(y, group_utf8, (unsigned) -1);
+    free(group_utf8);
   }
 
   jab_send(jc, x);
   xmlnode_free(x);
+  free(name_utf8);
   g_free(cleanjid);
 }
 
@@ -476,7 +487,7 @@
     const char *alias = xmlnode_get_attrib(y, "jid");
     //const char *sub = xmlnode_get_attrib(y, "subscription"); // TODO Not used
     const char *name = xmlnode_get_attrib(y, "name");
-    const char *group = NULL;
+    char *group = NULL;
 
     z = xmlnode_get_tag(y, "group");
     if (z) group = xmlnode_get_data(z);
@@ -484,12 +495,19 @@
     if (alias) {
       char *buddyname;
       char *cleanalias = jidtodisp(alias);
-      if (name)
-        buddyname = (char*)name;
-      else
+      char *name_noutf8 = NULL;
+      char *group_noutf8 = NULL;
+
+      if (name) {
+        name_noutf8 = utf8_decode(name);
+        buddyname = name_noutf8;
+      } else
         buddyname = cleanalias;
 
-      roster_add_user(cleanalias, buddyname, group, ROSTER_TYPE_USER);
+      if (group) group_noutf8 = utf8_decode(group);
+      roster_add_user(cleanalias, buddyname, group_noutf8, ROSTER_TYPE_USER);
+      if (name_noutf8)  free(name_noutf8);
+      if (group_noutf8) free(group_noutf8);
       g_free(cleanalias);
     }
   }
@@ -501,6 +519,7 @@
         const char *enc)
 {
   char *jid;
+  char *buffer = utf8_decode(body);
 
   /*
   //char *u, *h, *r;
@@ -512,8 +531,9 @@
   */
 
   jid = jidtodisp(from);
-  hk_message_in(jid, 0, body);
+  hk_message_in(jid, 0, buffer);
   g_free(jid);
+  free(buffer);
 }
 
 void statehandler(jconn conn, int state)