Software /
code /
prosody-modules
Annotate
mod_smacks/mod_smacks.lua @ 200:64a573203c20
mod_smacks: Better logic for deciding what is a stanza and what is not, and deciding when to send ack requests
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 08 Jul 2010 14:00:05 +0100 |
parent | 160:9a7671720dec |
child | 201:bc24f58a0d39 |
rev | line source |
---|---|
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local st = require "util.stanza"; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local t_insert, t_remove = table.insert, table.remove; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local tonumber, tostring = tonumber, tostring; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local xmlns_sm = "urn:xmpp:sm:2"; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local sm_attr = { xmlns = xmlns_sm }; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
200
64a573203c20
mod_smacks: Better logic for deciding what is a stanza and what is not, and deciding when to send ack requests
Matthew Wild <mwild1@gmail.com>
parents:
160
diff
changeset
|
10 local max_unacked_stanzas = 0; |
64a573203c20
mod_smacks: Better logic for deciding what is a stanza and what is not, and deciding when to send ack requests
Matthew Wild <mwild1@gmail.com>
parents:
160
diff
changeset
|
11 |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 module:add_event_hook("stream-features", |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 function (session, features) |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 features:tag("sm", sm_attr):tag("optional"):up():up(); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 end); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 module:hook("s2s-stream-features", |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 function (data) |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 data.features:tag("sm", sm_attr):tag("optional"):up():up(); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 module:hook_stanza(xmlns_sm, "enable", |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 function (session, stanza) |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 module:log("debug", "Enabling stream management"); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 session.smacks = true; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 session.handled_stanza_count = 0; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 -- Overwrite process_stanza() and send() |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 local queue, queue_length = {}, 0; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 session.outgoing_stanza_queue, session.outgoing_stanza_count = queue, queue_length; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 local _send = session.send; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 function session.send(stanza) |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 local attr = stanza.attr; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 if attr and not attr.xmlns then -- Stanza in default stream namespace |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 queue_length = queue_length + 1; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 session.outgoing_stanza_count = queue_length; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 queue[queue_length] = st.reply(stanza); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 local ok, err = _send(stanza); |
200
64a573203c20
mod_smacks: Better logic for deciding what is a stanza and what is not, and deciding when to send ack requests
Matthew Wild <mwild1@gmail.com>
parents:
160
diff
changeset
|
39 if ok and queue_length > max_unacked_stanzas and not session.awaiting_ack then |
64a573203c20
mod_smacks: Better logic for deciding what is a stanza and what is not, and deciding when to send ack requests
Matthew Wild <mwild1@gmail.com>
parents:
160
diff
changeset
|
40 session.awaiting_ack = true; |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 return _send(st.stanza("r", { xmlns = xmlns_sm })); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 return ok, err; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 _send(st.stanza("enabled", sm_attr)); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 return true; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 end); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 module:hook_stanza(xmlns_sm, "r", function (origin, stanza) |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 if not origin.smacks then |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 module:log("debug", "Received ack request from non-smack-enabled session"); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 return; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 module:log("debug", "Received ack request, acking for %d", origin.handled_stanza_count); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 -- Reply with <a> |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 origin.send(st.stanza("a", { xmlns = xmlns_sm, h = tostring(origin.handled_stanza_count) })); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 return true; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 end); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 module:hook_stanza(xmlns_sm, "a", function (origin, stanza) |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 if not origin.smacks then return; end |
200
64a573203c20
mod_smacks: Better logic for deciding what is a stanza and what is not, and deciding when to send ack requests
Matthew Wild <mwild1@gmail.com>
parents:
160
diff
changeset
|
62 origin.awaiting_ack = nil; |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 -- Remove handled stanzas from outgoing_stanza_queue |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 local handled_stanza_count = tonumber(stanza.attr.h)+1; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 for i=1,handled_stanza_count do |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 t_remove(origin.outgoing_stanza_queue, 1); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 return true; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 end); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 --TODO: Optimise... incoming stanzas should be handled by a per-session |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 -- function that has a counter as an upvalue (no table indexing for increments, |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 -- and won't slow non-198 sessions). We can also then remove the .handled flag |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 -- on stanzas |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 function catch_all_incoming_stanzas(data) |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 local origin, stanza = data.origin, data.stanza; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 if origin.smacks and not stanza.handled then |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 stanza.handled = true; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 origin.handled_stanza_count = origin.handled_stanza_count + 1; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 module:log("debug", "Handled %d stanzas", origin.handled_stanza_count); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 module:hook("message/bare", catch_all_incoming_stanzas, 1000); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 module:hook("message/full", catch_all_incoming_stanzas, 1000); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 module:hook("message/host", catch_all_incoming_stanzas, 1000); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 module:hook("presence/bare", catch_all_incoming_stanzas, 1000); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 module:hook("presence/full", catch_all_incoming_stanzas, 1000); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 module:hook("presence/host", catch_all_incoming_stanzas, 1000); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 module:hook("iq/bare", catch_all_incoming_stanzas, 1000); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 module:hook("iq/full", catch_all_incoming_stanzas, 1000); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 module:hook("iq/host", catch_all_incoming_stanzas, 1000); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 function handle_unacked_stanzas(session) |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 local queue = session.outgoing_stanza_queue; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 local error_attr = { type = "cancel" }; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 if #queue > 0 then |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 for i=1,#queue do |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 local reply = queue[i]; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 if reply.attr.to ~= session.full_jid then |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 reply.attr.type = "error"; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 reply:tag("error", error_attr) |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 :tag("recipient-unavailable", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 core_process_stanza(session, queue[i]); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 queue[i] = nil; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 local _destroy_session = sessionmanager.destroy_session; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 function sessionmanager.destroy_session(session, err) |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 if session.smacks then |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 local queue = session.outgoing_stanza_queue; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 if #queue > 0 then |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 module:log("warn", "Destroying session with %d unacked stanzas:", #queue); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 for i=1,#queue do |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 module:log("warn", "::%s", tostring(queue[i])); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 handle_unacked_stanzas(session); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 return _destroy_session(session, err); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 end |