comparison mcabber/src/jabglue.c @ 572:afc2bd38b15c

Implement affiliations handling, add "/room whois"
author Mikael Berthe <mikael@lilotux.net>
date Sat, 03 Dec 2005 23:40:40 +0100
parents 69afee8e1232
children 8b3db0b555a1
comparison
equal deleted inserted replaced
571:d63e6cbdc297 572:afc2bd38b15c
586 586
587 // Kick or ban a MUC room member 587 // Kick or ban a MUC room member
588 // room syntax: "room@server" 588 // room syntax: "room@server"
589 // Either the jid or the nickname must be set (when banning, only the jid is 589 // Either the jid or the nickname must be set (when banning, only the jid is
590 // allowed) 590 // allowed)
591 // kickban: 1=kick 2=ban 591 // affil: new affiliation (ex. affil_none for kick, affil_outcast for ban...)
592 // The reason can be null 592 // The reason can be null
593 // Return 0 if everything is ok 593 // Return 0 if everything is ok
594 int jb_room_kickban(const char *roomid, const char *jid, const char *nick, 594 int jb_room_setaffil(const char *roomid, const char *jid, const char *nick,
595 int kickban, const char *reason) 595 enum imaffiliation affil, const char *reason)
596 { 596 {
597 xmlnode x, y, z; 597 xmlnode x, y, z;
598 598
599 if (!online || !roomid) return 1; 599 if (!online || !roomid) return 1;
600 if (kickban != 1 && kickban != 2) return 1; 600
601 // Only none & outcast at the moment
602 if (affil != affil_none && affil != affil_outcast)
603 return 1;
601 604
602 if (check_jid_syntax((char*)roomid)) { 605 if (check_jid_syntax((char*)roomid)) {
603 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", roomid); 606 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", roomid);
604 return 1; 607 return 1;
605 } 608 }
606 if (jid && check_jid_syntax((char*)jid)) { 609 if (jid && check_jid_syntax((char*)jid)) {
607 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", jid); 610 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", jid);
608 return 1; 611 return 1;
609 } 612 }
610 613
611 if (kickban == 2 && !jid) 614 if (affil == affil_outcast && !jid)
612 return 1; // Shouldn't happen 615 return 1; // Shouldn't happen (jid mandatory when banning)
613 616
614 x = jutil_iqnew(JPACKET__SET, "http://jabber.org/protocol/muc#admin"); 617 x = jutil_iqnew(JPACKET__SET, "http://jabber.org/protocol/muc#admin");
615 xmlnode_put_attrib(x, "id", "kick1"); // XXX 618 xmlnode_put_attrib(x, "id", "kick1"); // XXX
616 xmlnode_put_attrib(x, "to", roomid); 619 xmlnode_put_attrib(x, "to", roomid);
617 xmlnode_put_attrib(x, "type", "set"); 620 xmlnode_put_attrib(x, "type", "set");
622 gchar *utf8_nickname = to_utf8(nick); 625 gchar *utf8_nickname = to_utf8(nick);
623 xmlnode_put_attrib(z, "nick", utf8_nickname); 626 xmlnode_put_attrib(z, "nick", utf8_nickname);
624 g_free(utf8_nickname); 627 g_free(utf8_nickname);
625 } else { 628 } else {
626 xmlnode_put_attrib(z, "jid", jid); 629 xmlnode_put_attrib(z, "jid", jid);
627 if (kickban == 2) 630 if (affil == affil_outcast)
628 xmlnode_put_attrib(z, "affiliation", "outcast"); 631 xmlnode_put_attrib(z, "affiliation", "outcast");
629 } 632 }
630 if (kickban == 1) 633 if (affil == affil_none)
631 xmlnode_put_attrib(z, "role", "none"); 634 xmlnode_put_attrib(z, "role", "none");
632 635
633 if (reason) { 636 if (reason) {
634 gchar *utf8_reason = to_utf8(reason); 637 gchar *utf8_reason = to_utf8(reason);
635 y = xmlnode_insert_tag(z, "reason"); 638 y = xmlnode_insert_tag(z, "reason");
956 if (!strcmp(type, "result")) { 959 if (!strcmp(type, "result")) {
957 960
958 if ((p = xmlnode_get_attrib(xmldata, "id")) != NULL) { 961 if ((p = xmlnode_get_attrib(xmldata, "id")) != NULL) {
959 int iid = atoi(p); 962 int iid = atoi(p);
960 963
961 scr_LogPrint(LPRINT_DEBUG, "iid = %d", iid); 964 //scr_LogPrint(LPRINT_DEBUG, "iid = %d", iid);
962 if (iid == s_id) { 965 if (iid == s_id) {
963 if (!regmode) { 966 if (!regmode) {
964 if (jstate == STATE_GETAUTH) { 967 if (jstate == STATE_GETAUTH) {
965 if ((x = xmlnode_get_tag(xmldata, "query")) != NULL) 968 if ((x = xmlnode_get_tag(xmldata, "query")) != NULL)
966 if (!xmlnode_get_tag(x, "digest")) { 969 if (!xmlnode_get_tag(x, "digest")) {
1142 scr_LogPrint(LPRINT_LOG, 1145 scr_LogPrint(LPRINT_LOG,
1143 "Decoding of status message of <%s> has failed: %s", 1146 "Decoding of status message of <%s> has failed: %s",
1144 from, p); 1147 from, p);
1145 } 1148 }
1146 1149
1147 // Call hk_statuschange() if status has changed or if the
1148 // status message is different
1149 rname = strchr(from, '/'); 1150 rname = strchr(from, '/');
1150 if (rname) rname++; 1151 if (rname) rname++;
1151 1152
1152 // Check for MUC presence packet 1153 // Check for MUC presence packet
1153 // There can be multiple <x> tags!! 1154 // There can be multiple <x> tags!!
1158 !strcasecmp(p, "http://jabber.org/protocol/muc#user")) 1159 !strcasecmp(p, "http://jabber.org/protocol/muc#user"))
1159 break; 1160 break;
1160 } 1161 }
1161 if (x) { // This is a MUC presence message 1162 if (x) { // This is a MUC presence message
1162 enum imrole mbrole = role_none; 1163 enum imrole mbrole = role_none;
1164 enum imaffiliation mbaffil = affil_none;
1163 const char *mbrjid = NULL; 1165 const char *mbrjid = NULL;
1164 const char *mbnewnick = NULL; 1166 const char *mbnewnick = NULL;
1165 GSList *room_elt; 1167 GSList *room_elt;
1166 int log_muc_conf = settings_opt_get_int("log_muc_conf"); 1168 int log_muc_conf = settings_opt_get_int("log_muc_conf");
1167 1169
1173 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); 1175 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM);
1174 1176
1175 // Get room member's information 1177 // Get room member's information
1176 y = xmlnode_get_tag(x, "item"); 1178 y = xmlnode_get_tag(x, "item");
1177 if (y) { 1179 if (y) {
1180 p = xmlnode_get_attrib(y, "affiliation");
1181 if (p) {
1182 if (!strcmp(p, "owner")) mbaffil = affil_owner;
1183 else if (!strcmp(p, "admin")) mbaffil = affil_admin;
1184 else if (!strcmp(p, "member")) mbaffil = affil_member;
1185 else if (!strcmp(p, "outcast")) mbaffil = affil_outcast;
1186 else if (!strcmp(p, "none")) mbaffil = affil_none;
1187 else scr_LogPrint(LPRINT_LOGNORM, "<%s>: Unknown affiliation \"%s\"",
1188 from, p);
1189 }
1178 p = xmlnode_get_attrib(y, "role"); 1190 p = xmlnode_get_attrib(y, "role");
1179 if (p) { 1191 if (p) {
1180 if (!strcmp(p, "moderator")) mbrole = role_moderator; 1192 if (!strcmp(p, "moderator")) mbrole = role_moderator;
1181 else if (!strcmp(p, "participant")) mbrole = role_participant; 1193 else if (!strcmp(p, "participant")) mbrole = role_participant;
1182 else if (!strcmp(p, "visitor")) mbrole = role_visitor; 1194 else if (!strcmp(p, "visitor")) mbrole = role_visitor;
1256 g_free(mbuf); 1268 g_free(mbuf);
1257 } 1269 }
1258 1270
1259 // Update room member status 1271 // Update room member status
1260 if (rname) 1272 if (rname)
1261 roster_setstatus(r, rname, bpprio, ust, s, mbrole, mbrjid); 1273 roster_setstatus(r, rname, bpprio, ust, s, mbrole, mbaffil, mbrjid);
1262 else 1274 else
1263 scr_LogPrint(LPRINT_LOGNORM, "MUC DBG: no rname!"); /* DBG */ 1275 scr_LogPrint(LPRINT_LOGNORM, "MUC DBG: no rname!"); /* DBG */
1264 1276
1265 buddylist_build(); 1277 buddylist_build();
1266 scr_DrawRoster(); 1278 scr_DrawRoster();
1267 1279
1268 goto out_packet_presence; 1280 goto out_packet_presence;
1269 } 1281 }
1270 1282
1271 // Not a MUC message, so this is a regular buddy... 1283 // Not a MUC message, so this is a regular buddy...
1284 // Call hk_statuschange() if status has changed or if the
1285 // status message is different
1272 m = roster_getstatusmsg(r, rname); 1286 m = roster_getstatusmsg(r, rname);
1273 if ((ust != roster_getstatus(r, rname)) || 1287 if ((ust != roster_getstatus(r, rname)) ||
1274 (!s && m && m[0]) || (s && (!m || strcmp(s, m)))) 1288 (!s && m && m[0]) || (s && (!m || strcmp(s, m))))
1275 hk_statuschange(r, rname, bpprio, 0, ust, s); 1289 hk_statuschange(r, rname, bpprio, 0, ust, s);
1276 1290