Software /
code /
prosody
Comparison
plugins/mod_bosh.lua @ 5187:d71f731e8fe4
mod_bosh: Add support for stanza filters to BOSH sessions (needed by some plugins)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 22 Nov 2012 19:35:50 +0000 |
parent | 5185:ca30b21946ef |
child | 5188:6689605f8591 |
comparison
equal
deleted
inserted
replaced
5186:ad898e50b8f3 | 5187:d71f731e8fe4 |
---|---|
16 local fire_event = prosody.events.fire_event; | 16 local fire_event = prosody.events.fire_event; |
17 local core_process_stanza = prosody.core_process_stanza; | 17 local core_process_stanza = prosody.core_process_stanza; |
18 local st = require "util.stanza"; | 18 local st = require "util.stanza"; |
19 local logger = require "util.logger"; | 19 local logger = require "util.logger"; |
20 local log = logger.init("mod_bosh"); | 20 local log = logger.init("mod_bosh"); |
21 local initialize_filters = require "util.filters".initialize; | |
21 local math_min = math.min; | 22 local math_min = math.min; |
22 | 23 |
23 local xmlns_streams = "http://etherx.jabber.org/streams"; | 24 local xmlns_streams = "http://etherx.jabber.org/streams"; |
24 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; | 25 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; |
25 local xmlns_bosh = "http://jabber.org/protocol/httpbind"; -- (hard-coded into a literal in session.send) | 26 local xmlns_bosh = "http://jabber.org/protocol/httpbind"; -- (hard-coded into a literal in session.send) |
252 log = logger.init("bosh"..sid), secure = consider_bosh_secure or request.secure, | 253 log = logger.init("bosh"..sid), secure = consider_bosh_secure or request.secure, |
253 ip = get_ip_from_request(request); | 254 ip = get_ip_from_request(request); |
254 }; | 255 }; |
255 sessions[sid] = session; | 256 sessions[sid] = session; |
256 | 257 |
258 local filter = initialize_filters(session); | |
259 | |
257 session.log("debug", "BOSH session created for request from %s", session.ip); | 260 session.log("debug", "BOSH session created for request from %s", session.ip); |
258 log("info", "New BOSH session, assigned it sid '%s'", sid); | 261 log("info", "New BOSH session, assigned it sid '%s'", sid); |
259 | 262 |
260 -- Send creation response | 263 -- Send creation response |
261 local creating_session = true; | 264 local creating_session = true; |
265 -- We need to ensure that outgoing stanzas have the jabber:client xmlns | 268 -- We need to ensure that outgoing stanzas have the jabber:client xmlns |
266 if s.attr and not s.attr.xmlns then | 269 if s.attr and not s.attr.xmlns then |
267 s = st.clone(s); | 270 s = st.clone(s); |
268 s.attr.xmlns = "jabber:client"; | 271 s.attr.xmlns = "jabber:client"; |
269 end | 272 end |
273 s = filter("stanzas/out", s); | |
270 --log("debug", "Sending BOSH data: %s", tostring(s)); | 274 --log("debug", "Sending BOSH data: %s", tostring(s)); |
271 t_insert(session.send_buffer, tostring(s)); | 275 t_insert(session.send_buffer, tostring(s)); |
272 | 276 |
273 local oldest_request = r[1]; | 277 local oldest_request = r[1]; |
274 if oldest_request and not session.bosh_processing then | 278 if oldest_request and not session.bosh_processing then |
352 local session = sessions[context.sid]; | 356 local session = sessions[context.sid]; |
353 if session then | 357 if session then |
354 if stanza.attr.xmlns == xmlns_bosh then | 358 if stanza.attr.xmlns == xmlns_bosh then |
355 stanza.attr.xmlns = nil; | 359 stanza.attr.xmlns = nil; |
356 end | 360 end |
361 stanza = session.filter("stanzas/in", stanza); | |
357 core_process_stanza(session, stanza); | 362 core_process_stanza(session, stanza); |
358 end | 363 end |
359 end | 364 end |
360 | 365 |
361 function stream_callbacks.streamclosed(request) | 366 function stream_callbacks.streamclosed(request) |