annotate mod_compat_muc_admin/mod_compat_muc_admin.lua @ 627:a8ff69c9b498

mod_compat_muc_admin: first commit.
author Marco Cirillo <maranda@lightwitch.org>
date Tue, 27 Mar 2012 15:49:31 +0000
parents
children c72be31941fa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
627
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
1 local st = require "util.stanza";
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
2 local jid_split = require "util.jid".split;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
3 local jid_bare = require "util.jid".bare;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
4 local jid_prep = require "util.jid".prep;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
5 local log = require "util.logger".init("mod_muc");
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
6 local muc_host = module:get_host();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
7
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
8 if not hosts[muc_host].modules.muc then -- Not a MUC host
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
9 module:log("error", "this module can only be used on muc hosts."); return false;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
10 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
11
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
12 local xmlns_ma, xmlns_mo = "http://jabber.org/protocol/muc#admin", "http://jabber.org/protocol/muc#owner";
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
13
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
14 -- COMPAT: iq condensed function
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
15 hosts[muc_host].modules.muc.stanza_handler.muc_new_room.room_mt["compat_iq"] = function (self, origin, stanza, xmlns)
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
16 local actor = stanza.attr.from;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
17 local affiliation = self:get_affiliation(actor);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
18 local current_nick = self._jid_nick[actor];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
19 local role = current_nick and self._occupants[current_nick].role or self:get_default_role(affiliation);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
20 local item = stanza.tags[1].tags[1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
21 if item and item.name == "item" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
22 if stanza.attr.type == "set" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
23 local callback = function() origin.send(st.reply(stanza)); end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
24 if item.attr.jid then -- Validate provided JID
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
25 item.attr.jid = jid_prep(item.attr.jid);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
26 if not item.attr.jid then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
27 origin.send(st.error_reply(stanza, "modify", "jid-malformed"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
28 return;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
29 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
30 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
31 if not item.attr.jid and item.attr.nick then -- COMPAT Workaround for Miranda sending 'nick' instead of 'jid' when changing affiliation
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
32 local occupant = self._occupants[self.jid.."/"..item.attr.nick];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
33 if occupant then item.attr.jid = occupant.jid; end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
34 elseif not item.attr.nick and item.attr.jid then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
35 local nick = self._jid_nick[item.attr.jid];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
36 if nick then item.attr.nick = select(3, jid_split(nick)); end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
37 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
38 local reason = item.tags[1] and item.tags[1].name == "reason" and #item.tags[1] == 1 and item.tags[1][1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
39 if item.attr.affiliation and item.attr.jid and not item.attr.role then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
40 local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback, reason);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
41 if not success then origin.send(st.error_reply(stanza, errtype, err)); end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
42 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
43 local success, errtype, err = self:set_role(actor, self.jid.."/"..item.attr.nick, item.attr.role, callback, reason);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
44 if not success then origin.send(st.error_reply(stanza, errtype, err)); end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
45 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
46 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
47 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
48 elseif stanza.attr.type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
49 local _aff = item.attr.affiliation;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
50 local _rol = item.attr.role;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
51 if _aff and not _rol then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
52 if affiliation == "owner" or (affiliation == "admin" and _aff ~= "owner" and _aff ~= "admin") then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
53 local reply = st.reply(stanza):query(xmlns);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
54 for jid, affiliation in pairs(self._affiliations) do
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
55 if affiliation == _aff then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
56 reply:tag("item", {affiliation = _aff, jid = jid}):up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
57 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
58 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
59 origin.send(reply);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
60 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
61 origin.send(st.error_reply(stanza, "auth", "forbidden"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
62 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
63 elseif _rol and not _aff then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
64 if role == "moderator" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
65 -- TODO allow admins and owners not in room? Provide read-only access to everyone who can see the participants anyway?
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
66 if _rol == "none" then _rol = nil; end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
67 local reply = st.reply(stanza):query(xmlns);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
68 for occupant_jid, occupant in pairs(self._occupants) do
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
69 if occupant.role == _rol then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
70 reply:tag("item", {
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
71 nick = select(3, jid_split(occupant_jid)),
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
72 role = _rol or "none",
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
73 affiliation = occupant.affiliation or "none",
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
74 jid = occupant.jid
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
75 }):up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
76 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
77 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
78 origin.send(reply);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
79 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
80 origin.send(st.error_reply(stanza, "auth", "forbidden"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
81 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
82 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
83 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
84 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
85 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
86 elseif stanza.attr.type == "set" or stanza.attr.type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
87 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
88 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
89 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
90
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
91 -- COMPAT: reworked handle_to_room function
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
92 hosts[muc_host].modules.muc.stanza_handler.muc_new_room.room_mt["handle_to_room"] = function (self, origin, stanza)
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
93 local type = stanza.attr.type;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
94 local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
95 if stanza.name == "iq" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
96 if xmlns == "http://jabber.org/protocol/disco#info" and type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
97 origin.send(self:get_disco_info(stanza));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
98 elseif xmlns == "http://jabber.org/protocol/disco#items" and type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
99 origin.send(self:get_disco_items(stanza));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
100 elseif (xmlns == xmlns_ma or xmlns == xmlns_mo) then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
101 if xmlns == xmlns_ma then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
102 self:compat_iq(origin, stanza, xmlns);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
103 elseif xmlns == xmlns_mo and stanza.tags[1].name == "query" and #stanza.tags[1].tags == 0 and
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
104 stanza.attr.type == "get" then -- form request
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
105 if self:get_affiliation(stanza.attr.from) ~= "owner" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
106 origin.send(st.error_reply(stanza, "auth", "forbidden", "Only owners can configure rooms"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
107 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
108 self:send_form(origin, stanza);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
109 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
110 elseif xmlns == xmlns_mo and stanza.tags[1].name == "query" and stanza.tags[1]:get_child("x", "jabber:x:data") and
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
111 stanza.attr.type == "set" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
112 if self:get_affiliation(stanza.attr.from) ~= "owner" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
113 origin.send(st.error_reply(stanza, "auth", "forbidden", "Only owners can configure rooms"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
114 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
115 self:process_form(origin, stanza);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
116 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
117 elseif xmlns == xmlns_mo and stanza.tags[1].tags[1] then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
118 local child = stanza.tags[1].tags[1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
119 if child.name == "destroy" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
120 local newjid = child.attr.jid;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
121 local reason, password;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
122 for _,tag in ipairs(child.tags) do
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
123 if tag.name == "reason" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
124 reason = #tag.tags == 0 and tag[1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
125 elseif tag.name == "password" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
126 password = #tag.tags == 0 and tag[1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
127 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
128 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
129 self:destroy(newjid, reason, password);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
130 origin.send(st.reply(stanza));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
131 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
132 self:compat_iq(origin, stanza, xmlns);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
133 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
134 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
135 origin.send(st.error_reply(stanza, "modify", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
136 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
137 elseif type == "set" or type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
138 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
139 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
140 elseif stanza.name == "message" and type == "groupchat" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
141 local from, to = stanza.attr.from, stanza.attr.to;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
142 local room = jid_bare(to);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
143 local current_nick = self._jid_nick[from];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
144 local occupant = self._occupants[current_nick];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
145 if not occupant then -- not in room
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
146 origin.send(st.error_reply(stanza, "cancel", "not-acceptable"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
147 elseif occupant.role == "visitor" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
148 origin.send(st.error_reply(stanza, "cancel", "forbidden"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
149 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
150 local from = stanza.attr.from;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
151 stanza.attr.from = current_nick;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
152 local subject = getText(stanza, {"subject"});
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
153 if subject then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
154 if occupant.role == "moderator" or
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
155 ( self._data.changesubject and occupant.role == "participant" ) then -- and participant
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
156 self:set_subject(current_nick, subject); -- TODO use broadcast_message_stanza
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
157 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
158 stanza.attr.from = from;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
159 origin.send(st.error_reply(stanza, "cancel", "forbidden"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
160 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
161 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
162 self:broadcast_message(stanza, true);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
163 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
164 stanza.attr.from = from;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
165 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
166 elseif stanza.name == "message" and type == "error" and is_kickable_error(stanza) then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
167 local current_nick = self._jid_nick[stanza.attr.from];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
168 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
169 self:handle_to_occupant(origin, build_unavailable_presence_from_error(stanza)); -- send unavailable
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
170 elseif stanza.name == "presence" then -- hack - some buggy clients send presence updates to the room rather than their nick
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
171 local to = stanza.attr.to;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
172 local current_nick = self._jid_nick[stanza.attr.from];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
173 if current_nick then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
174 stanza.attr.to = current_nick;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
175 self:handle_to_occupant(origin, stanza);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
176 stanza.attr.to = to;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
177 elseif type ~= "error" and type ~= "result" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
178 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
179 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
180 elseif stanza.name == "message" and not stanza.attr.type and #stanza.tags == 1 and self._jid_nick[stanza.attr.from]
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
181 and stanza.tags[1].name == "x" and stanza.tags[1].attr.xmlns == "http://jabber.org/protocol/muc#user" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
182 local x = stanza.tags[1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
183 local payload = (#x.tags == 1 and x.tags[1]);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
184 if payload and payload.name == "invite" and payload.attr.to then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
185 local _from, _to = stanza.attr.from, stanza.attr.to;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
186 local _invitee = jid_prep(payload.attr.to);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
187 if _invitee then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
188 local _reason = payload.tags[1] and payload.tags[1].name == 'reason' and #payload.tags[1].tags == 0 and payload.tags[1][1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
189 local invite = st.message({from = _to, to = _invitee, id = stanza.attr.id})
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
190 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'})
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
191 :tag('invite', {from=_from})
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
192 :tag('reason'):text(_reason or ""):up()
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
193 :up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
194 if self:get_password() then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
195 invite:tag("password"):text(self:get_password()):up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
196 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
197 invite:up()
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
198 :tag('x', {xmlns="jabber:x:conference", jid=_to}) -- COMPAT: Some older clients expect this
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
199 :text(_reason or "")
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
200 :up()
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
201 :tag('body') -- Add a plain message for clients which don't support invites
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
202 :text(_from..' invited you to the room '.._to..(_reason and (' ('.._reason..')') or ""))
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
203 :up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
204 if self:is_members_only() and not self:get_affiliation(_invitee) then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
205 log("debug", "%s invited %s into members only room %s, granting membership", _from, _invitee, _to);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
206 self:set_affiliation(_from, _invitee, "member", nil, "Invited by " .. self._jid_nick[_from])
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
207 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
208 self:_route_stanza(invite);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
209 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
210 origin.send(st.error_reply(stanza, "cancel", "jid-malformed"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
211 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
212 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
213 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
214 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
215 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
216 if type == "error" or type == "result" then return; end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
217 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
218 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
219 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
220
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
221