Comparison

mod_pastebin/mod_pastebin.lua @ 2766:314cebb3071e

mod_pastebin: Check for MUC presence before handling a message. Fixes #955.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 19 Sep 2017 18:47:18 +0200
parent 1343:7dbde05b48a9
child 3008:26fe44c68791
comparison
equal deleted inserted replaced
2765:85cf9a8b4020 2766:314cebb3071e
3 module:depends("http"); 3 module:depends("http");
4 local uuid_new = require "util.uuid".generate; 4 local uuid_new = require "util.uuid".generate;
5 local os_time = os.time; 5 local os_time = os.time;
6 local t_insert, t_remove = table.insert, table.remove; 6 local t_insert, t_remove = table.insert, table.remove;
7 local add_task = require "util.timer".add_task; 7 local add_task = require "util.timer".add_task;
8 local jid_bare = require "util.jid".bare;
9 local muc_rooms = module:depends "muc".rooms;
8 10
9 local utf8_pattern = "[\194-\244][\128-\191]*$"; 11 local utf8_pattern = "[\194-\244][\128-\191]*$";
10 local function drop_invalid_utf8(seq) 12 local function drop_invalid_utf8(seq)
11 local start = seq:byte(); 13 local start = seq:byte();
12 module:log("debug", "utf8: %d, %d", start, #seq); 14 module:log("debug", "utf8: %d, %d", start, #seq);
65 return pastes[pasteid]; 67 return pastes[pasteid];
66 end 68 end
67 69
68 function check_message(data) 70 function check_message(data)
69 local origin, stanza = data.origin, data.stanza; 71 local origin, stanza = data.origin, data.stanza;
72
73 -- Only check for MUC presence when loaded on a component.
74 if module:get_host_type() == "component" then
75 local room = muc_rooms[jid_bare(stanza.attr.to)];
76 if not room then return; end
77
78 local nick = room._jid_nick[stanza.attr.from];
79 if not nick then return; end
80 end
70 81
71 local body, bodyindex, htmlindex; 82 local body, bodyindex, htmlindex;
72 for k,v in ipairs(stanza) do 83 for k,v in ipairs(stanza) do
73 if v.name == "body" then 84 if v.name == "body" then
74 body, bodyindex = v, k; 85 body, bodyindex = v, k;