Software /
code /
prosody
Comparison
plugins/muc/mod_muc.lua @ 4370:be14f96290a4
MUC: A little cleanup.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Wed, 31 Aug 2011 23:53:55 +0500 |
parent | 4260:403aba5e49d5 |
child | 4528:875b90d5ce0f |
comparison
equal
deleted
inserted
replaced
4369:3578ff5d3674 | 4370:be14f96290a4 |
---|---|
98 end | 98 end |
99 end | 99 end |
100 return reply; -- TODO cache disco reply | 100 return reply; -- TODO cache disco reply |
101 end | 101 end |
102 | 102 |
103 local function handle_to_domain(origin, stanza) | 103 local function handle_to_domain(event) |
104 local origin, stanza = event.origin, event.stanza; | |
104 local type = stanza.attr.type; | 105 local type = stanza.attr.type; |
105 if type == "error" or type == "result" then return; end | 106 if type == "error" or type == "result" then return; end |
106 if stanza.name == "iq" and type == "get" then | 107 if stanza.name == "iq" and type == "get" then |
107 local xmlns = stanza.tags[1].attr.xmlns; | 108 local xmlns = stanza.tags[1].attr.xmlns; |
108 if xmlns == "http://jabber.org/protocol/disco#info" then | 109 if xmlns == "http://jabber.org/protocol/disco#info" then |
116 end | 117 end |
117 else | 118 else |
118 host_room:handle_stanza(origin, stanza); | 119 host_room:handle_stanza(origin, stanza); |
119 --origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "The muc server doesn't deal with messages and presence directed at it")); | 120 --origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "The muc server doesn't deal with messages and presence directed at it")); |
120 end | 121 end |
122 return true; | |
121 end | 123 end |
122 | 124 |
123 function stanza_handler(event) | 125 function stanza_handler(event) |
124 local origin, stanza = event.origin, event.stanza; | 126 local origin, stanza = event.origin, event.stanza; |
125 local to_node, to_host, to_resource = jid_split(stanza.attr.to); | 127 local bare = jid_bare(stanza.attr.to); |
126 if to_node then | 128 local room = rooms[bare]; |
127 local bare = to_node.."@"..to_host; | 129 if not room then |
128 if to_host == muc_host or bare == muc_host then | 130 if not(restrict_room_creation) or |
129 local room = rooms[bare]; | 131 (restrict_room_creation == "admin" and is_admin(stanza.attr.from)) or |
130 if not room then | 132 (restrict_room_creation == "local" and select(2, jid_split(stanza.attr.from)) == module.host:gsub("^[^%.]+%.", "")) then |
131 if not(restrict_room_creation) or | 133 room = muc_new_room(bare, { |
132 (restrict_room_creation == "admin" and is_admin(stanza.attr.from)) or | 134 history_length = max_history_messages; |
133 (restrict_room_creation == "local" and select(2, jid_split(stanza.attr.from)) == module.host:gsub("^[^%.]+%.", "")) then | 135 }); |
134 room = muc_new_room(bare, { | 136 room.route_stanza = room_route_stanza; |
135 history_length = max_history_messages; | 137 room.save = room_save; |
136 }); | 138 rooms[bare] = room; |
137 room.route_stanza = room_route_stanza; | 139 end |
138 room.save = room_save; | |
139 rooms[bare] = room; | |
140 end | |
141 end | |
142 if room then | |
143 room:handle_stanza(origin, stanza); | |
144 if not next(room._occupants) and not persistent_rooms[room.jid] then -- empty, non-persistent room | |
145 rooms[bare] = nil; -- discard room | |
146 end | |
147 else | |
148 origin.send(st.error_reply(stanza, "cancel", "not-allowed")); | |
149 end | |
150 else --[[not for us?]] end | |
151 return true; | |
152 end | 140 end |
153 -- to the main muc domain | 141 if room then |
154 handle_to_domain(origin, stanza); | 142 room:handle_stanza(origin, stanza); |
143 if not next(room._occupants) and not persistent_rooms[room.jid] then -- empty, non-persistent room | |
144 rooms[bare] = nil; -- discard room | |
145 end | |
146 else | |
147 origin.send(st.error_reply(stanza, "cancel", "not-allowed")); | |
148 end | |
155 return true; | 149 return true; |
156 end | 150 end |
157 module:hook("iq/bare", stanza_handler, -1); | 151 module:hook("iq/bare", stanza_handler, -1); |
158 module:hook("message/bare", stanza_handler, -1); | 152 module:hook("message/bare", stanza_handler, -1); |
159 module:hook("presence/bare", stanza_handler, -1); | 153 module:hook("presence/bare", stanza_handler, -1); |
160 module:hook("iq/full", stanza_handler, -1); | 154 module:hook("iq/full", stanza_handler, -1); |
161 module:hook("message/full", stanza_handler, -1); | 155 module:hook("message/full", stanza_handler, -1); |
162 module:hook("presence/full", stanza_handler, -1); | 156 module:hook("presence/full", stanza_handler, -1); |
163 module:hook("iq/host", stanza_handler, -1); | 157 module:hook("iq/host", handle_to_domain, -1); |
164 module:hook("message/host", stanza_handler, -1); | 158 module:hook("message/host", handle_to_domain, -1); |
165 module:hook("presence/host", stanza_handler, -1); | 159 module:hook("presence/host", handle_to_domain, -1); |
166 | 160 |
167 hosts[module.host].send = function(stanza) -- FIXME do a generic fix | 161 hosts[module.host].send = function(stanza) -- FIXME do a generic fix |
168 if stanza.attr.type == "result" or stanza.attr.type == "error" then | 162 if stanza.attr.type == "result" or stanza.attr.type == "error" then |
169 core_post_stanza(component, stanza); | 163 core_post_stanza(component, stanza); |
170 else error("component.send only supports result and error stanzas at the moment"); end | 164 else error("component.send only supports result and error stanzas at the moment"); end |