comparison mcabber/src/jabglue.c @ 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 b44be19d6229
children 5927c3bfba13
comparison
equal deleted inserted replaced
440:264f40222872 441:51b8f10cfeb8
27 #include "roster.h" 27 #include "roster.h"
28 #include "screen.h" 28 #include "screen.h"
29 #include "hooks.h" 29 #include "hooks.h"
30 #include "utils.h" 30 #include "utils.h"
31 #include "settings.h" 31 #include "settings.h"
32 #include "hbuf.h"
32 33
33 #define JABBERPORT 5222 34 #define JABBERPORT 5222
34 #define JABBERSSLPORT 5223 35 #define JABBERSSLPORT 5223
35 36
36 #define JABBER_AGENT_GROUP "Jabber Agents" 37 #define JABBER_AGENT_GROUP "Jabber Agents"
538 char *buddyname; 539 char *buddyname;
539 char *cleanalias = jidtodisp(alias); 540 char *cleanalias = jidtodisp(alias);
540 gchar *name_noutf8 = NULL; 541 gchar *name_noutf8 = NULL;
541 gchar *group_noutf8 = NULL; 542 gchar *group_noutf8 = NULL;
542 543
544 buddyname = cleanalias;
543 if (name) { 545 if (name) {
544 name_noutf8 = from_utf8(name); 546 name_noutf8 = from_utf8(name);
545 buddyname = name_noutf8; 547 if (name_noutf8) buddyname = name_noutf8;
546 } else 548 }
547 buddyname = cleanalias;
548 549
549 if (group) 550 if (group)
550 group_noutf8 = from_utf8(group); 551 group_noutf8 = from_utf8(group);
551 552
552 roster_add_user(cleanalias, buddyname, group_noutf8, ROSTER_TYPE_USER); 553 roster_add_user(cleanalias, buddyname, group_noutf8, ROSTER_TYPE_USER);
562 void gotmessage(char *type, const char *from, const char *body, 563 void gotmessage(char *type, const char *from, const char *body,
563 const char *enc, time_t timestamp) 564 const char *enc, time_t timestamp)
564 { 565 {
565 char *jid; 566 char *jid;
566 gchar *buffer = from_utf8(body); 567 gchar *buffer = from_utf8(body);
568
569 jid = jidtodisp(from);
570
571 if (!buffer && body) {
572 scr_LogPrint(LPRINT_LOGNORM, "Decoding of message from <%s> has failed",
573 from);
574 scr_WriteIncomingMessage(jid, "Cannot display message: "
575 "UTF-8 conversion failure",
576 0, HBB_PREFIX_ERR | HBB_PREFIX_IN);
577 g_free(jid);
578 return;
579 }
567 580
568 /* 581 /*
569 //char *u, *h, *r; 582 //char *u, *h, *r;
570 //jidsplit(from, &u, &h, &r); 583 //jidsplit(from, &u, &h, &r);
571 // Maybe we should remember the resource? 584 // Maybe we should remember the resource?
574 "There is an extra part in message (resource?): %s", r); 587 "There is an extra part in message (resource?): %s", r);
575 //scr_LogPrint(LPRINT_NORMAL, "Msg from <%s>, type=%s", 588 //scr_LogPrint(LPRINT_NORMAL, "Msg from <%s>, type=%s",
576 // jidtodisp(from), type); 589 // jidtodisp(from), type);
577 */ 590 */
578 591
579 jid = jidtodisp(from);
580 hk_message_in(jid, timestamp, buffer, type); 592 hk_message_in(jid, timestamp, buffer, type);
581 g_free(jid); 593 g_free(jid);
582 g_free(buffer); 594 g_free(buffer);
583 } 595 }
584 596