comparison mcabber/mcabber/xmpp_muc.c @ 2132:a09cdfceae17

Rework muc_get_item_info() Since the actor string is now dymanic, we let the caller free the memory in all cases.
author Mikael Berthe <mikael@lilotux.net>
date Tue, 24 Jun 2014 20:42:29 +0200
parents 36170c97a0b7
children fc7a758ebbde
comparison
equal deleted inserted replaced
2131:a6b93960109e 2132:a09cdfceae17
299 299
300 // muc_get_item_info(...) 300 // muc_get_item_info(...)
301 // Get room member's information from xmlndata. 301 // Get room member's information from xmlndata.
302 // The variables must be initialized before calling this function, 302 // The variables must be initialized before calling this function,
303 // because they are not touched if the relevant information is missing. 303 // because they are not touched if the relevant information is missing.
304 // Note that *actor should be freed by the caller.
304 static void muc_get_item_info(const char *from, LmMessageNode *xmldata, 305 static void muc_get_item_info(const char *from, LmMessageNode *xmldata,
305 enum imrole *mbrole, enum imaffiliation *mbaffil, 306 enum imrole *mbrole, enum imaffiliation *mbaffil,
306 const char **mbjid, const char **mbnick, 307 const char **mbjid, const char **mbnick,
307 const char **actorjid, const char **reason) 308 char **actor, const char **reason)
308 { 309 {
309 LmMessageNode *y, *z; 310 LmMessageNode *y, *z;
310 const char *p, *actornick; 311 const char *p, *actorjid, *actornick;
311 312
312 y = lm_message_node_find_child(xmldata, "item"); 313 y = lm_message_node_find_child(xmldata, "item");
313 if (!y) 314 if (!y)
314 return; 315 return;
315 316
336 *mbnick = lm_message_node_get_attribute(y, "nick"); 337 *mbnick = lm_message_node_get_attribute(y, "nick");
337 // For kick/ban, there can be actor and reason tags 338 // For kick/ban, there can be actor and reason tags
338 z = lm_message_node_find_child(y, "actor"); 339 z = lm_message_node_find_child(y, "actor");
339 if (z) { 340 if (z) {
340 actornick = lm_message_node_get_attribute(z, "nick"); 341 actornick = lm_message_node_get_attribute(z, "nick");
341 *actorjid = lm_message_node_get_attribute(z, "jid"); 342 actorjid = lm_message_node_get_attribute(z, "jid");
342 if (*actorjid) { // we have actor's jid, check if we also have nick. 343 if (actorjid) {
343 *actorjid = (!actornick) ? *actorjid : g_strdup_printf( 344 if (actornick) {
344 "%s <%s>", actornick, *actorjid 345 // We have both the actor's jid and nick
345 ); 346 *actor = g_strdup_printf("%s <%s>", actornick, actorjid);
346 } else if (actornick) *actorjid = actornick; // we have nick only. 347 } else {
348 *actor = g_strdup(actorjid); // jid only
349 }
350 } else if (!actorjid && actornick) {
351 // We only have the nickname
352 *actor = g_strdup(actornick);
353 }
347 } 354 }
348 355
349 *reason = lm_message_node_get_child_value(y, "reason"); 356 *reason = lm_message_node_get_child_value(y, "reason");
350 if (*reason && !**reason) 357 if (*reason && !**reason)
351 *reason = NULL; 358 *reason = NULL;
447 enum imaffiliation mbaffil = affil_none; 454 enum imaffiliation mbaffil = affil_none;
448 enum room_printstatus printstatus; 455 enum room_printstatus printstatus;
449 enum room_autowhois autowhois; 456 enum room_autowhois autowhois;
450 enum room_flagjoins flagjoins; 457 enum room_flagjoins flagjoins;
451 const char *mbjid = NULL, *mbnick = NULL; 458 const char *mbjid = NULL, *mbnick = NULL;
452 const char *actorjid = NULL, *reason = NULL; 459 const char *reason = NULL;
460 char *actor = NULL;
453 bool new_member = FALSE; // True if somebody else joins the room (not us) 461 bool new_member = FALSE; // True if somebody else joins the room (not us)
454 bool our_presence = FALSE; // True if this presence is from us (i.e. bears 462 bool our_presence = FALSE; // True if this presence is from us (i.e. bears
455 // code 110) 463 // code 110)
456 guint statuscode = 0; 464 guint statuscode = 0;
457 guint nickchange = 0; 465 guint nickchange = 0;
474 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); 482 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM);
475 } 483 }
476 484
477 // Get room member's information 485 // Get room member's information
478 muc_get_item_info(from, xmldata, &mbrole, &mbaffil, &mbjid, &mbnick, 486 muc_get_item_info(from, xmldata, &mbrole, &mbaffil, &mbjid, &mbnick,
479 &actorjid, &reason); 487 &actor, &reason);
480 488
481 // Get our room nickname 489 // Get our room nickname
482 ournick = buddy_getnickname(room_elt->data); 490 ournick = buddy_getnickname(room_elt->data);
483 491
484 if (!ournick) { 492 if (!ournick) {
627 // The message depends on _who_ left, and _how_ 635 // The message depends on _who_ left, and _how_
628 if (how) { 636 if (how) {
629 gchar *mbuf_end; 637 gchar *mbuf_end;
630 gchar *reason_msg = NULL; 638 gchar *reason_msg = NULL;
631 // Forced leave 639 // Forced leave
632 if (actorjid) { 640 if (actor) {
633 mbuf_end = g_strdup_printf("%s from %s by %s", 641 mbuf_end = g_strdup_printf("%s from %s by %s",
634 (how == ban ? "banned" : "kicked"), 642 (how == ban ? "banned" : "kicked"),
635 roomjid, actorjid); 643 roomjid, actor);
636 } else { 644 } else {
637 mbuf_end = g_strdup_printf("%s from %s", 645 mbuf_end = g_strdup_printf("%s from %s",
638 (how == ban ? "banned" : "kicked"), 646 (how == ban ? "banned" : "kicked"),
639 roomjid); 647 roomjid);
640 } 648 }
680 mbuf = g_strdup_printf("%s has left", rname); 688 mbuf = g_strdup_printf("%s has left", rname);
681 } 689 }
682 } 690 }
683 } 691 }
684 692
693 g_free(actor);
694
685 // Display the mbuf message if we're concerned 695 // Display the mbuf message if we're concerned
686 // or if the print_status isn't set to none. 696 // or if the print_status isn't set to none.
687 if (our_presence || printstatus != status_none) { 697 if (our_presence || printstatus != status_none) {
688 msgflags = HBB_PREFIX_INFO; 698 msgflags = HBB_PREFIX_INFO;
689 flagjoins = buddy_getflagjoins(room_elt->data); 699 flagjoins = buddy_getflagjoins(room_elt->data);