comparison mcabber/src/jabglue.c @ 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 a3db3ee8b99e
comparison
equal deleted inserted replaced
589:9942746e8d58 590:a5707d61e469
252 252
253 // presnew(status, recipient, message) 253 // presnew(status, recipient, message)
254 // Create an xmlnode with default presence attributes 254 // Create an xmlnode with default presence attributes
255 // Note: the caller must free the node after use 255 // Note: the caller must free the node after use
256 static xmlnode presnew(enum imstatus st, const char *recipient, 256 static xmlnode presnew(enum imstatus st, const char *recipient,
257 const char *msg) 257 const char *msg)
258 { 258 {
259 unsigned int prio; 259 unsigned int prio;
260 xmlnode x; 260 xmlnode x;
261 gchar *utf8_recipient = to_utf8(recipient);
261 262
262 x = jutil_presnew(JPACKET__UNKNOWN, 0, 0); 263 x = jutil_presnew(JPACKET__UNKNOWN, 0, 0);
263 264
264 if (recipient) 265 if (utf8_recipient) {
265 xmlnode_put_attrib(x, "to", recipient); 266 xmlnode_put_attrib(x, "to", utf8_recipient);
267 g_free(utf8_recipient);
268 }
266 269
267 switch(st) { 270 switch(st) {
268 case away: 271 case away:
269 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "away", 272 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "away",
270 (unsigned) -1); 273 (unsigned) -1);
375 void jb_send_msg(const char *jid, const char *text, int type, 378 void jb_send_msg(const char *jid, const char *text, int type,
376 const char *subject) 379 const char *subject)
377 { 380 {
378 xmlnode x; 381 xmlnode x;
379 gchar *strtype; 382 gchar *strtype;
380 gchar *buffer = to_utf8(text); 383 gchar *utf8_jid;
384 gchar *buffer;
381 385
382 if (!online) return; 386 if (!online) return;
383 387
384 if (type == ROSTER_TYPE_ROOM) 388 if (type == ROSTER_TYPE_ROOM)
385 strtype = TMSG_GROUPCHAT; 389 strtype = TMSG_GROUPCHAT;
386 else 390 else
387 strtype = TMSG_CHAT; 391 strtype = TMSG_CHAT;
388 392
389 x = jutil_msgnew(strtype, (char*)jid, NULL, (char*)buffer); 393 buffer = to_utf8(text);
394 utf8_jid = to_utf8(jid); // Resource can require UTF-8
395
396 x = jutil_msgnew(strtype, utf8_jid, NULL, (char*)buffer);
390 if (subject) { 397 if (subject) {
391 xmlnode y; 398 xmlnode y;
392 char *bs = to_utf8(subject); 399 char *bs = to_utf8(subject);
393 y = xmlnode_insert_tag(x, "subject"); 400 y = xmlnode_insert_tag(x, "subject");
394 xmlnode_insert_cdata(y, bs, (unsigned) -1); 401 xmlnode_insert_cdata(y, bs, (unsigned) -1);
395 if (bs) g_free(bs); 402 if (bs) g_free(bs);
396 } 403 }
397 jab_send(jc, x); 404 jab_send(jc, x);
398 xmlnode_free(x); 405 xmlnode_free(x);
399 g_free(buffer); 406
407 if (buffer) g_free(buffer);
408 if (utf8_jid) g_free(utf8_jid);
409
400 jb_reset_keepalive(); 410 jb_reset_keepalive();
401 } 411 }
402 412
403 // Note: the caller should check the jid is correct 413 // Note: the caller should check the jid is correct
404 void jb_addbuddy(const char *jid, const char *name, const char *group) 414 void jb_addbuddy(const char *jid, const char *name, const char *group)
406 xmlnode x, y, z; 416 xmlnode x, y, z;
407 char *cleanjid; 417 char *cleanjid;
408 418
409 if (!online) return; 419 if (!online) return;
410 420
421 cleanjid = jidtodisp(jid);
422
411 // We don't check if the jabber user already exists in the roster, 423 // We don't check if the jabber user already exists in the roster,
412 // because it allows to re-ask for notification. 424 // because it allows to re-ask for notification.
413 425
414 //x = jutil_presnew(JPACKET__SUBSCRIBE, jid, NULL); 426 //x = jutil_presnew(JPACKET__SUBSCRIBE, cleanjid, NULL);
415 x = jutil_presnew(JPACKET__SUBSCRIBE, (char*)jid, "online"); 427 x = jutil_presnew(JPACKET__SUBSCRIBE, cleanjid, "online");
416 jab_send(jc, x); 428 jab_send(jc, x);
417 xmlnode_free(x); 429 xmlnode_free(x);
418 430
419 x = jutil_iqnew(JPACKET__SET, NS_ROSTER); 431 x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
420 y = xmlnode_get_tag(x, "query"); 432 y = xmlnode_get_tag(x, "query");
421 z = xmlnode_insert_tag(y, "item"); 433 z = xmlnode_insert_tag(y, "item");
422 xmlnode_put_attrib(z, "jid", jid); 434 xmlnode_put_attrib(z, "jid", cleanjid);
423 435
424 if (name) { 436 if (name) {
425 gchar *name_utf8 = to_utf8(name); 437 gchar *name_utf8 = to_utf8(name);
426 z = xmlnode_insert_tag(z, "name"); 438 z = xmlnode_insert_tag(z, "name");
427 xmlnode_insert_cdata(z, name_utf8, (unsigned) -1); 439 xmlnode_insert_cdata(z, name_utf8, (unsigned) -1);
436 } 448 }
437 449
438 jab_send(jc, x); 450 jab_send(jc, x);
439 xmlnode_free(x); 451 xmlnode_free(x);
440 452
441 cleanjid = jidtodisp(jid);
442 roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER); 453 roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER);
443 g_free(cleanjid); 454 g_free(cleanjid);
444 buddylist_build(); 455 buddylist_build();
445 456
446 update_roster = TRUE; 457 update_roster = TRUE;
604 xmlnode_put_attrib(x, "type", "set"); 615 xmlnode_put_attrib(x, "type", "set");
605 y = xmlnode_get_tag(x, "query"); 616 y = xmlnode_get_tag(x, "query");
606 z = xmlnode_insert_tag(y, "item"); 617 z = xmlnode_insert_tag(y, "item");
607 618
608 if (jid) { 619 if (jid) {
609 xmlnode_put_attrib(z, "jid", jid); 620 gchar *utf8_jid = to_utf8(jid);
621 xmlnode_put_attrib(z, "jid", utf8_jid);
622 if (utf8_jid) g_free(utf8_jid);
610 } else { // nick 623 } else { // nick
611 gchar *utf8_nickname = to_utf8(nick); 624 gchar *utf8_nickname = to_utf8(nick);
612 xmlnode_put_attrib(z, "nick", utf8_nickname); 625 xmlnode_put_attrib(z, "nick", utf8_nickname);
613 g_free(utf8_nickname); 626 g_free(utf8_nickname);
614 } 627 }
636 // room syntax: "room@server" 649 // room syntax: "room@server"
637 // reason can be null. 650 // reason can be null.
638 void jb_room_invite(const char *room, const char *jid, const char *reason) 651 void jb_room_invite(const char *room, const char *jid, const char *reason)
639 { 652 {
640 xmlnode x, y, z; 653 xmlnode x, y, z;
654 gchar *utf8_jid;
641 655
642 if (!online || !room || !jid) return; 656 if (!online || !room || !jid) return;
643 657
644 x = jutil_msgnew(NULL, (char*)room, NULL, NULL); 658 x = jutil_msgnew(NULL, (char*)room, NULL, NULL);
645 659
646 y = xmlnode_insert_tag(x, "x"); 660 y = xmlnode_insert_tag(x, "x");
647 xmlnode_put_attrib(y, "xmlns", "http://jabber.org/protocol/muc#user"); 661 xmlnode_put_attrib(y, "xmlns", "http://jabber.org/protocol/muc#user");
648 662
663 utf8_jid = to_utf8(jid); // Resource can require UTF-8
649 z = xmlnode_insert_tag(y, "invite"); 664 z = xmlnode_insert_tag(y, "invite");
650 xmlnode_put_attrib(z, "to", jid); 665 xmlnode_put_attrib(z, "to", utf8_jid);
666 if (utf8_jid) g_free(utf8_jid);
651 667
652 if (reason) { 668 if (reason) {
653 gchar *utf8_reason = to_utf8(reason); 669 gchar *utf8_reason = to_utf8(reason);
654 y = xmlnode_insert_tag(z, "reason"); 670 y = xmlnode_insert_tag(z, "reason");
655 xmlnode_insert_cdata(y, utf8_reason, (unsigned) -1); 671 xmlnode_insert_cdata(y, utf8_reason, (unsigned) -1);
996 if (log_muc_conf) hlog_write_message(roomjid, 0, FALSE, mbuf); 1012 if (log_muc_conf) hlog_write_message(roomjid, 0, FALSE, mbuf);
997 g_free(mbuf); 1013 g_free(mbuf);
998 } 1014 }
999 1015
1000 // Update room member status 1016 // Update room member status
1001 if (rname) 1017 if (rname) {
1018 gchar *mbrjid_noutf8 = from_utf8(mbjid);
1002 roster_setstatus(roomjid, rname, bpprio, ust, ustmsg, 1019 roster_setstatus(roomjid, rname, bpprio, ust, ustmsg,
1003 mbrole, mbaffil, mbjid); 1020 mbrole, mbaffil, mbrjid_noutf8);
1004 else 1021 if (mbrjid_noutf8)
1022 g_free(mbrjid_noutf8);
1023 } else
1005 scr_LogPrint(LPRINT_LOGNORM, "MUC DBG: no rname!"); /* DBG */ 1024 scr_LogPrint(LPRINT_LOGNORM, "MUC DBG: no rname!"); /* DBG */
1006 1025
1007 buddylist_build(); 1026 buddylist_build();
1008 scr_DrawRoster(); 1027 scr_DrawRoster();
1009 } 1028 }