Comparison

plugins/muc/muc.lib.lua @ 6103:25ba4e2b31b3

plugins/muc/muc: Check for mediated invites in a smarter way
author daurnimator <quae@daurnimator.com>
date Tue, 18 Mar 2014 14:56:20 -0400
parent 6102:385772166289
child 6104:260a18062cb2
comparison
equal deleted inserted replaced
6102:385772166289 6103:25ba4e2b31b3
1031 return handled; 1031 return handled;
1032 end 1032 end
1033 1033
1034 function room_mt:handle_invite_to_room(origin, stanza, payload) 1034 function room_mt:handle_invite_to_room(origin, stanza, payload)
1035 local _from, _to = stanza.attr.from, stanza.attr.to; 1035 local _from, _to = stanza.attr.from, stanza.attr.to;
1036 if not self._jid_nick[_from] then -- Should be in room to send invite
1037 origin.send(st.error_reply(stanza, "auth", "forbidden"));
1038 return true;
1039 end
1036 local _invitee = jid_prep(payload.attr.to); 1040 local _invitee = jid_prep(payload.attr.to);
1037 if _invitee then 1041 if _invitee then
1038 local _reason = payload.tags[1] and payload.tags[1].name == 'reason' and #payload.tags[1].tags == 0 and payload.tags[1][1]; 1042 local _reason = payload.tags[1] and payload.tags[1].name == 'reason' and #payload.tags[1].tags == 0 and payload.tags[1][1];
1039 local invite = st.message({from = _to, to = _invitee, id = stanza.attr.id}) 1043 local invite = st.message({from = _to, to = _invitee, id = stanza.attr.id})
1040 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) 1044 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'})
1067 local type = stanza.attr.type; 1071 local type = stanza.attr.type;
1068 if type == "groupchat" then 1072 if type == "groupchat" then
1069 return self:handle_groupchat_to_room(origin, stanza) 1073 return self:handle_groupchat_to_room(origin, stanza)
1070 elseif type == "error" and is_kickable_error(stanza) then 1074 elseif type == "error" and is_kickable_error(stanza) then
1071 return self:handle_kickable(origin, stanza) 1075 return self:handle_kickable(origin, stanza)
1072 elseif not(type == "chat" or type == "error" or type == "groupchat" or type == "headline") and #stanza.tags == 1 1076 elseif type == nil then
1073 and self._jid_nick[stanza.attr.from] and stanza.tags[1].name == "x" and stanza.tags[1].attr.xmlns == "http://jabber.org/protocol/muc#user" then 1077 local x = stanza:get_child("x", "http://jabber.org/protocol/muc#user");
1074 local x = stanza.tags[1]; 1078 if x then
1075 local payload = (#x.tags == 1 and x.tags[1]); 1079 local payload = x.tags[1];
1076 if payload and payload.name == "invite" and payload.attr.to then 1080 if payload and payload.name == "invite" and payload.attr.to then
1077 return self:handle_invite_to_room(origin, stanza, payload) 1081 return self:handle_invite_to_room(origin, stanza, payload)
1078 else 1082 end
1079 origin.send(st.error_reply(stanza, "cancel", "bad-request")); 1083 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
1080 return true; 1084 return true;
1081 end 1085 end
1082 else 1086 else
1083 return nil; 1087 return nil;