Software /
code /
prosody
Comparison
plugins/muc/mod_muc.lua @ 6091:3a1c39b31497
plugins/muc/mod_muc: Move Xep-0307 MUC unique to seperate file
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Tue, 18 Feb 2014 17:21:47 -0500 |
parent | 6000:0f6399c86c10 |
child | 6109:566aba0482b6 |
comparison
equal
deleted
inserted
replaced
6017:ac0879a8190a | 6091:3a1c39b31497 |
---|---|
29 local muclib = module:require "muc"; | 29 local muclib = module:require "muc"; |
30 local muc_new_room = muclib.new_room; | 30 local muc_new_room = muclib.new_room; |
31 local jid_split = require "util.jid".split; | 31 local jid_split = require "util.jid".split; |
32 local jid_bare = require "util.jid".bare; | 32 local jid_bare = require "util.jid".bare; |
33 local st = require "util.stanza"; | 33 local st = require "util.stanza"; |
34 local uuid_gen = require "util.uuid".generate; | |
35 local um_is_admin = require "core.usermanager".is_admin; | 34 local um_is_admin = require "core.usermanager".is_admin; |
36 local hosts = prosody.hosts; | 35 local hosts = prosody.hosts; |
37 | 36 |
38 rooms = {}; | 37 rooms = {}; |
39 local rooms = rooms; | 38 local rooms = rooms; |
45 muclib.set_max_history_length(module:get_option_number("max_history_messages")); | 44 muclib.set_max_history_length(module:get_option_number("max_history_messages")); |
46 | 45 |
47 module:depends("disco"); | 46 module:depends("disco"); |
48 module:add_identity("conference", "text", muc_name); | 47 module:add_identity("conference", "text", muc_name); |
49 module:add_feature("http://jabber.org/protocol/muc"); | 48 module:add_feature("http://jabber.org/protocol/muc"); |
49 module:depends "muc_unique" | |
50 | 50 |
51 local function is_admin(jid) | 51 local function is_admin(jid) |
52 return um_is_admin(jid, module.host); | 52 return um_is_admin(jid, module.host); |
53 end | 53 end |
54 | 54 |
134 reply:tag("item", {jid=jid, name=room:get_name()}):up(); | 134 reply:tag("item", {jid=jid, name=room:get_name()}):up(); |
135 end | 135 end |
136 end | 136 end |
137 end); | 137 end); |
138 | 138 |
139 local function handle_to_domain(event) | |
140 local origin, stanza = event.origin, event.stanza; | |
141 local type = stanza.attr.type; | |
142 if type == "error" or type == "result" then return; end | |
143 if stanza.name == "iq" and type == "get" then | |
144 local xmlns = stanza.tags[1].attr.xmlns; | |
145 local node = stanza.tags[1].attr.node; | |
146 if xmlns == "http://jabber.org/protocol/muc#unique" then | |
147 origin.send(st.reply(stanza):tag("unique", {xmlns = xmlns}):text(uuid_gen())); -- FIXME Random UUIDs can theoretically have collisions | |
148 else | |
149 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- TODO disco/etc | |
150 end | |
151 else | |
152 host_room:handle_stanza(origin, stanza); | |
153 --origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "The muc server doesn't deal with messages and presence directed at it")); | |
154 end | |
155 return true; | |
156 end | |
157 | |
158 function stanza_handler(event) | 139 function stanza_handler(event) |
159 local origin, stanza = event.origin, event.stanza; | 140 local origin, stanza = event.origin, event.stanza; |
160 local bare = jid_bare(stanza.attr.to); | 141 local bare = jid_bare(stanza.attr.to); |
161 local room = rooms[bare]; | 142 local room = rooms[bare]; |
162 if not room then | 143 if not room then |
185 module:hook("message/bare", stanza_handler, -1); | 166 module:hook("message/bare", stanza_handler, -1); |
186 module:hook("presence/bare", stanza_handler, -1); | 167 module:hook("presence/bare", stanza_handler, -1); |
187 module:hook("iq/full", stanza_handler, -1); | 168 module:hook("iq/full", stanza_handler, -1); |
188 module:hook("message/full", stanza_handler, -1); | 169 module:hook("message/full", stanza_handler, -1); |
189 module:hook("presence/full", stanza_handler, -1); | 170 module:hook("presence/full", stanza_handler, -1); |
190 module:hook("iq/host", handle_to_domain, -1); | 171 |
172 local function handle_to_domain(event) | |
173 local origin, stanza = event.origin, event.stanza; | |
174 local type = stanza.attr.type; | |
175 if type == "error" then return; end | |
176 host_room:handle_stanza(origin, stanza); | |
177 -- origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "The muc server doesn't deal with messages and presence directed at it")); | |
178 return true; | |
179 end | |
191 module:hook("message/host", handle_to_domain, -1); | 180 module:hook("message/host", handle_to_domain, -1); |
192 module:hook("presence/host", handle_to_domain, -1); | 181 module:hook("presence/host", handle_to_domain, -1); |
193 | 182 |
194 hosts[module.host].send = function(stanza) -- FIXME do a generic fix | 183 hosts[module.host].send = function(stanza) -- FIXME do a generic fix |
195 if stanza.attr.type == "result" or stanza.attr.type == "error" then | 184 if stanza.attr.type == "result" or stanza.attr.type == "error" then |