Mercurial > hg
comparison mcabber/src/jabglue.c @ 584:414fbf558f1e
jb_room_setattrib()
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 09 Dec 2005 19:49:58 +0100 |
parents | 32ae027a3238 |
children | d8f64e74206c |
comparison
equal
deleted
inserted
replaced
583:32ae027a3238 | 584:414fbf558f1e |
---|---|
568 jab_send(jc, x); | 568 jab_send(jc, x); |
569 xmlnode_free(x); | 569 xmlnode_free(x); |
570 jb_reset_keepalive(); | 570 jb_reset_keepalive(); |
571 } | 571 } |
572 | 572 |
573 // Kick or ban a MUC room member | 573 // Change role or affiliation of a MUC user |
574 // room syntax: "room@server" | 574 // room syntax: "room@server" |
575 // Either the jid or the nickname must be set (when banning, only the jid is | 575 // Either the jid or the nickname must be set (when banning, only the jid is |
576 // allowed) | 576 // allowed) |
577 // affil: new affiliation (ex. affil_none for kick, affil_outcast for ban...) | 577 // ra: new role or affiliation |
578 // (ex. role none for kick, affil outcast for ban...) | |
578 // The reason can be null | 579 // The reason can be null |
579 // Return 0 if everything is ok | 580 // Return 0 if everything is ok |
580 int jb_room_setaffil(const char *roomid, const char *jid, const char *nick, | 581 int jb_room_setattrib(const char *roomid, const char *jid, const char *nick, |
581 enum imaffiliation affil, const char *reason) | 582 struct role_affil ra, const char *reason) |
582 { | 583 { |
583 xmlnode x, y, z; | 584 xmlnode x, y, z; |
584 | 585 |
585 if (!online || !roomid) return 1; | 586 if (!online || !roomid) return 1; |
586 | 587 if (!jid && !nick) return 1; |
587 // Only none & outcast at the moment | |
588 if (affil != affil_none && affil != affil_outcast) | |
589 return 1; | |
590 | 588 |
591 if (check_jid_syntax((char*)roomid)) { | 589 if (check_jid_syntax((char*)roomid)) { |
592 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", roomid); | 590 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", roomid); |
593 return 1; | 591 return 1; |
594 } | 592 } |
595 if (jid && check_jid_syntax((char*)jid)) { | 593 if (jid && check_jid_syntax((char*)jid)) { |
596 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", jid); | 594 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", jid); |
597 return 1; | 595 return 1; |
598 } | 596 } |
599 | 597 |
600 if (affil == affil_outcast && !jid) | 598 if (ra.type == type_affil && ra.val.affil == affil_outcast && !jid) |
601 return 1; // Shouldn't happen (jid mandatory when banning) | 599 return 1; // Shouldn't happen (jid mandatory when banning) |
602 | 600 |
603 x = jutil_iqnew(JPACKET__SET, "http://jabber.org/protocol/muc#admin"); | 601 x = jutil_iqnew(JPACKET__SET, "http://jabber.org/protocol/muc#admin"); |
604 xmlnode_put_attrib(x, "id", "kick1"); // XXX | 602 xmlnode_put_attrib(x, "id", "roleaffil1"); // XXX |
605 xmlnode_put_attrib(x, "to", roomid); | 603 xmlnode_put_attrib(x, "to", roomid); |
606 xmlnode_put_attrib(x, "type", "set"); | 604 xmlnode_put_attrib(x, "type", "set"); |
607 y = xmlnode_get_tag(x, "query"); | 605 y = xmlnode_get_tag(x, "query"); |
608 z = xmlnode_insert_tag(y, "item"); | 606 z = xmlnode_insert_tag(y, "item"); |
609 | 607 |
610 if (!jid) { | 608 if (jid) { |
609 xmlnode_put_attrib(z, "jid", jid); | |
610 } else { // nick | |
611 gchar *utf8_nickname = to_utf8(nick); | 611 gchar *utf8_nickname = to_utf8(nick); |
612 xmlnode_put_attrib(z, "nick", utf8_nickname); | 612 xmlnode_put_attrib(z, "nick", utf8_nickname); |
613 g_free(utf8_nickname); | 613 g_free(utf8_nickname); |
614 } else { | 614 } |
615 xmlnode_put_attrib(z, "jid", jid); | 615 |
616 if (affil == affil_outcast) | 616 if (ra.type == type_affil) |
617 xmlnode_put_attrib(z, "affiliation", "outcast"); | 617 xmlnode_put_attrib(z, "affiliation", straffil[ra.val.affil]); |
618 } | 618 else if (ra.type == type_role) |
619 if (affil == affil_none) | 619 xmlnode_put_attrib(z, "role", strrole[ra.val.role]); |
620 xmlnode_put_attrib(z, "role", "none"); | |
621 | 620 |
622 if (reason) { | 621 if (reason) { |
623 gchar *utf8_reason = to_utf8(reason); | 622 gchar *utf8_reason = to_utf8(reason); |
624 y = xmlnode_insert_tag(z, "reason"); | 623 y = xmlnode_insert_tag(z, "reason"); |
625 xmlnode_insert_cdata(y, utf8_reason, (unsigned) -1); | 624 xmlnode_insert_cdata(y, utf8_reason, (unsigned) -1); |