Software /
code /
verse
Annotate
component.lua @ 438:98dc1750584d 0.10.0
pubsub: Support for 'notify' in retract and purge operations
This is a slight API change for :retract(), but should be backwards-compatible.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 06 Dec 2021 09:09:50 +0000 |
parent | 411:db462d4feb44 |
child | 485:c9a144591649 |
rev | line source |
---|---|
84
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local verse = require "verse"; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local stream = verse.stream_mt; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local jid_split = require "util.jid".split; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local lxp = require "lxp"; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local st = require "util.stanza"; |
410
6171ef2a4025
component: Import sha1 via util.hashes
Kim Alvefur <zash@zash.se>
parents:
400
diff
changeset
|
7 local sha1 = require "util.hashes".sha1; |
84
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 -- Shortcuts to save having to load util.stanza |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 verse.message, verse.presence, verse.iq, verse.stanza, verse.reply, verse.error_reply = |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 st.message, st.presence, st.iq, st.stanza, st.reply, st.error_reply; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
161
b177bcea2006
squishy, verse.client, verse.component, verse.bosh: Port to util.xmppstream instead of xmlhandlers which has been removed from Prosody. Also remove util.ztact from squishy for the same reason.
Matthew Wild <mwild1@gmail.com>
parents:
150
diff
changeset
|
13 local new_xmpp_stream = require "util.xmppstream".new; |
84
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local xmlns_stream = "http://etherx.jabber.org/streams"; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local xmlns_component = "jabber:component:accept"; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 local stream_callbacks = { |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 stream_ns = xmlns_stream, |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 stream_tag = "stream", |
150
728cc7f2f0c2
verse.component: Namespacing fixes
Matthew Wild <mwild1@gmail.com>
parents:
84
diff
changeset
|
21 default_ns = xmlns_component }; |
411 | 22 |
84
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 function stream_callbacks.streamopened(stream, attr) |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 stream.stream_id = attr.id; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 if not stream:event("opened", attr) then |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 stream.notopen = nil; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 return true; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 function stream_callbacks.streamclosed(stream) |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 return stream:event("closed"); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 function stream_callbacks.handlestanza(stream, stanza) |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 if stanza.attr.xmlns == xmlns_stream then |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 return stream:event("stream-"..stanza.name, stanza); |
150
728cc7f2f0c2
verse.component: Namespacing fixes
Matthew Wild <mwild1@gmail.com>
parents:
84
diff
changeset
|
38 elseif stanza.attr.xmlns or stanza.name == "handshake" then |
728cc7f2f0c2
verse.component: Namespacing fixes
Matthew Wild <mwild1@gmail.com>
parents:
84
diff
changeset
|
39 return stream:event("stream/"..(stanza.attr.xmlns or xmlns_component), stanza); |
84
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 return stream:event("stanza", stanza); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 function stream:reset() |
161
b177bcea2006
squishy, verse.client, verse.component, verse.bosh: Port to util.xmppstream instead of xmlhandlers which has been removed from Prosody. Also remove util.ztact from squishy for the same reason.
Matthew Wild <mwild1@gmail.com>
parents:
150
diff
changeset
|
46 if self.stream then |
b177bcea2006
squishy, verse.client, verse.component, verse.bosh: Port to util.xmppstream instead of xmlhandlers which has been removed from Prosody. Also remove util.ztact from squishy for the same reason.
Matthew Wild <mwild1@gmail.com>
parents:
150
diff
changeset
|
47 self.stream:reset(); |
b177bcea2006
squishy, verse.client, verse.component, verse.bosh: Port to util.xmppstream instead of xmlhandlers which has been removed from Prosody. Also remove util.ztact from squishy for the same reason.
Matthew Wild <mwild1@gmail.com>
parents:
150
diff
changeset
|
48 else |
b177bcea2006
squishy, verse.client, verse.component, verse.bosh: Port to util.xmppstream instead of xmlhandlers which has been removed from Prosody. Also remove util.ztact from squishy for the same reason.
Matthew Wild <mwild1@gmail.com>
parents:
150
diff
changeset
|
49 self.stream = new_xmpp_stream(self, stream_callbacks); |
b177bcea2006
squishy, verse.client, verse.component, verse.bosh: Port to util.xmppstream instead of xmlhandlers which has been removed from Prosody. Also remove util.ztact from squishy for the same reason.
Matthew Wild <mwild1@gmail.com>
parents:
150
diff
changeset
|
50 end |
84
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 self.notopen = true; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 return true; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 function stream:connect_component(jid, pass) |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 self.jid, self.password = jid, pass; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 self.username, self.host, self.resource = jid_split(jid); |
411 | 58 |
84
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 function self.data(conn, data) |
161
b177bcea2006
squishy, verse.client, verse.component, verse.bosh: Port to util.xmppstream instead of xmlhandlers which has been removed from Prosody. Also remove util.ztact from squishy for the same reason.
Matthew Wild <mwild1@gmail.com>
parents:
150
diff
changeset
|
60 local ok, err = self.stream:feed(data); |
84
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 if ok then return; end |
400
0db9cb909cf1
client, component: Fix logging of invalid XML
Matthew Wild <mwild1@gmail.com>
parents:
314
diff
changeset
|
62 stream:debug("Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " ")); |
84
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 stream:close("xml-not-well-formed"); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 end |
411 | 65 |
84
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 self:hook("incoming-raw", function (data) return self.data(self.conn, data); end); |
411 | 67 |
84
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 self.curr_id = 0; |
411 | 69 |
84
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 self.tracked_iqs = {}; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 self:hook("stanza", function (stanza) |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 local id, type = stanza.attr.id, stanza.attr.type; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 if id and stanza.name == "iq" and (type == "result" or type == "error") and self.tracked_iqs[id] then |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 self.tracked_iqs[id](stanza); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 self.tracked_iqs[id] = nil; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 return true; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 end); |
411 | 79 |
84
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 self:hook("stanza", function (stanza) |
282
52b971d9ebc3
client, component: `ret` was probably meant to be a local
Kim Alvefur <zash@zash.se>
parents:
161
diff
changeset
|
81 local ret; |
84
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 if stanza.attr.xmlns == nil or stanza.attr.xmlns == "jabber:client" then |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 if stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 if xmlns then |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 ret = self:event("iq/"..xmlns, stanza); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 if not ret then |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 ret = self:event("iq", stanza); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 if ret == nil then |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 self:send(verse.error_reply(stanza, "cancel", "service-unavailable")); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 return true; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 else |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 ret = self:event(stanza.name, stanza); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 return ret; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 end, -1); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 self:hook("opened", function (attr) |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 print(self.jid, self.stream_id, attr.id); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 local token = sha1(self.stream_id..pass, true); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 self:send(st.stanza("handshake", { xmlns = xmlns_component }):text(token)); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 self:hook("stream/"..xmlns_component, function (stanza) |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 if stanza.name == "handshake" then |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 self:event("authentication-success"); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 end); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 end); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 local function stream_ready() |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 self:event("ready"); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 self:hook("authentication-success", stream_ready, -1); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 -- Initialise connection |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 self:connect(self.connect_host or self.host, self.connect_port or 5347); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 self:reopen(); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 function stream:reopen() |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 self:reset(); |
314
ee5fc3ee9150
component: allow binding to non-host jids (thanks mva)
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
126 self:send(st.stanza("stream:stream", { to = self.jid, ["xmlns:stream"]='http://etherx.jabber.org/streams', |
84
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 xmlns = xmlns_component, version = "1.0" }):top_tag()); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 function stream:close(reason) |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 if not self.notopen then |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 self:send("</stream:stream>"); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 local on_disconnect = self.conn.disconnect(); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 self.conn:close(); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 on_disconnect(conn, reason); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 function stream:send_iq(iq, callback) |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 local id = self:new_id(); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 self.tracked_iqs[id] = callback; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 iq.attr.id = id; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 self:send(iq); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 end |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 function stream:new_id() |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 self.curr_id = self.curr_id + 1; |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 return tostring(self.curr_id); |
d85d2443478e
verse.component: XEP-0114 support \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 end |