Mercurial > prosody-modules
comparison mod_muc_limits/mod_muc_limits.lua @ 557:14f39769c9e0
mod_muc_limits: Echo any MUC <x> or <body> in the error reply (required to make Gajim display the error)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 15 Jan 2012 02:05:41 +0000 |
| parents | e50bdbaa7802 |
| children | 09a5082a8162 |
comparison
equal
deleted
inserted
replaced
| 556:e50bdbaa7802 | 557:14f39769c9e0 |
|---|---|
| 1 | 1 |
| 2 local st = require "util.stanza"; | 2 local st = require "util.stanza"; |
| 3 local new_throttle = require "util.throttle".create; | 3 local new_throttle = require "util.throttle".create; |
| 4 | |
| 5 local xmlns_muc = "http://jabber.org/protocol/muc"; | |
| 4 | 6 |
| 5 local period = math.max(module:get_option_number("muc_event_rate", 0.5), 0); | 7 local period = math.max(module:get_option_number("muc_event_rate", 0.5), 0); |
| 6 local burst = math.max(module:get_option_number("muc_burst_factor", 6), 1); | 8 local burst = math.max(module:get_option_number("muc_burst_factor", 6), 1); |
| 7 | 9 |
| 8 local function handle_stanza(event) | 10 local function handle_stanza(event) |
| 24 throttle = new_throttle(period*burst, burst); | 26 throttle = new_throttle(period*burst, burst); |
| 25 room.throttle = throttle; | 27 room.throttle = throttle; |
| 26 end | 28 end |
| 27 if not throttle:poll(1) then | 29 if not throttle:poll(1) then |
| 28 module:log("warn", "Dropping stanza for %s@%s from %s, over rate limit", dest_room, dest_host, from_jid); | 30 module:log("warn", "Dropping stanza for %s@%s from %s, over rate limit", dest_room, dest_host, from_jid); |
| 29 origin.send(st.error_reply(stanza, "wait", "policy-violation", "The room is currently overactive, please try again later")); | 31 local reply = st.error_reply(stanza, "wait", "policy-violation", "The room is currently overactive, please try again later"); |
| 32 local body = stanza:get_child_text("body"); | |
| 33 if body then | |
| 34 reply:up():tag("body"):text(body):up(); | |
| 35 end | |
| 36 local x = stanza:get_child("x", xmlns_muc); | |
| 37 if x then | |
| 38 reply:add_child(st.clone(x)); | |
| 39 end | |
| 40 origin.send(reply); | |
| 30 return true; | 41 return true; |
| 31 end | 42 end |
| 32 end | 43 end |
| 33 | 44 |
| 34 function module.unload() | 45 function module.unload() |
