Comparison

plugins/muc/muc.lib.lua @ 1778:f4213d84ba8a

MUC: Correct routing of vCard requests to bare JID.
author Waqas Hussain <waqas20@gmail.com>
date Sun, 13 Sep 2009 23:52:09 +0500
parent 1769:39865fbbb2f7
child 1808:e164fdb2d18f
comparison
equal deleted inserted replaced
1777:de86734d3f7f 1778:f4213d84ba8a
14 local st = require "util.stanza"; 14 local st = require "util.stanza";
15 local log = require "util.logger".init("mod_muc"); 15 local log = require "util.logger".init("mod_muc");
16 local multitable_new = require "util.multitable".new; 16 local multitable_new = require "util.multitable".new;
17 local t_insert, t_remove = table.insert, table.remove; 17 local t_insert, t_remove = table.insert, table.remove;
18 local setmetatable = setmetatable; 18 local setmetatable = setmetatable;
19 local base64 = require "util.encodings".base64;
20 local md5 = require "util.hashes".md5;
19 21
20 local muc_domain = nil; --module:get_host(); 22 local muc_domain = nil; --module:get_host();
21 local history_length = 20; 23 local history_length = 20;
22 24
23 ------------ 25 ------------
289 end 291 end
290 end 292 end
291 elseif type ~= 'result' then -- bad type 293 elseif type ~= 'result' then -- bad type
292 origin.send(st.error_reply(stanza, "modify", "bad-request")); -- FIXME correct error? 294 origin.send(st.error_reply(stanza, "modify", "bad-request")); -- FIXME correct error?
293 end 295 end
294 elseif not current_nick and type ~= "error" and type ~= "result" then -- not in room 296 elseif not current_nick then -- not in room
295 origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); 297 if type == "error" or type == "result" then
298 local id = stanza.name == "iq" and stanza.attr.id and base64.decode(stanza.attr.id);
299 local _nick, _id, _hash = (id or ""):match("^(.+)%z(.*)%z(.+)$");
300 local occupant = self._occupants[stanza.attr.to];
301 if occupant and _nick and self._jid_nick[_nick] and _id and _hash then
302 local id, _to = stanza.attr.id;
303 for jid in pairs(occupant.sessions) do
304 if md5(jid) == _hash then
305 _to = jid;
306 break;
307 end
308 end
309 if _to then
310 stanza.attr.to, stanza.attr.from, stanza.attr.id = _to, self._jid_nick[_nick], _id;
311 self:route_stanza(stanza);
312 stanza.attr.to, stanza.attr.from, stanza.attr.id = to, from, id;
313 end
314 end
315 else
316 origin.send(st.error_reply(stanza, "cancel", "not-acceptable"));
317 end
296 elseif stanza.name == "message" and type == "groupchat" then -- groupchat messages not allowed in PM 318 elseif stanza.name == "message" and type == "groupchat" then -- groupchat messages not allowed in PM
297 origin.send(st.error_reply(stanza, "modify", "bad-request")); 319 origin.send(st.error_reply(stanza, "modify", "bad-request"));
298 else -- private stanza 320 else -- private stanza
299 local o_data = self._occupants[to]; 321 local o_data = self._occupants[to];
300 if o_data then 322 if o_data then
301 log("debug", "%s sent private stanza to %s (%s)", from, to, o_data.jid); 323 log("debug", "%s sent private stanza to %s (%s)", from, to, o_data.jid);
302 local jid = o_data.jid; 324 local jid = o_data.jid;
325 local bare = jid_bare(jid);
303 stanza.attr.to, stanza.attr.from = jid, current_nick; 326 stanza.attr.to, stanza.attr.from = jid, current_nick;
304 -- TODO if stanza.name=='iq' and type=='get' and stanza.tags[1].attr.xmlns == 'vcard-temp' then jid = jid_bare(jid); end 327 local id = stanza.attr.id;
328 if stanza.name=='iq' and type=='get' and stanza.tags[1].attr.xmlns == 'vcard-temp' and bare ~= jid then
329 stanza.attr.to = bare;
330 stanza.attr.id = base64.encode(jid.."\0"..id.."\0"..md5(from));
331 end
305 self:route_stanza(stanza); 332 self:route_stanza(stanza);
306 stanza.attr.to, stanza.attr.from = to, from; 333 stanza.attr.to, stanza.attr.from, stanza.attr.id = to, from, id;
307 elseif type ~= "error" and type ~= "result" then -- recipient not in room 334 elseif type ~= "error" and type ~= "result" then -- recipient not in room
308 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Recipient not in room")); 335 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Recipient not in room"));
309 end 336 end
310 end 337 end
311 end 338 end