client.lua

changeset 457
73d4eb93657b
parent 452
628896d39d8e
child 458
6c3797c0bb44
equal deleted inserted replaced
456:6a65142052c8 457:73d4eb93657b
2 local stream = verse.stream_mt; 2 local stream = verse.stream_mt;
3 3
4 local jid_split = require "util.jid".split; 4 local jid_split = require "util.jid".split;
5 local adns = require "net.adns"; 5 local adns = require "net.adns";
6 local st = require "util.stanza"; 6 local st = require "util.stanza";
7 local new_id = require "util.id".short;
8
9 math.randomseed((require"socket".gettime() * 1000000) % 0x80000000);
7 10
8 -- Shortcuts to save having to load util.stanza 11 -- Shortcuts to save having to load util.stanza
9 verse.message, verse.presence, verse.iq, verse.stanza, verse.reply, verse.error_reply = 12 verse.message, verse.presence, verse.iq, verse.stanza, verse.reply, verse.error_reply =
10 st.message, st.presence, st.iq, st.stanza, st.reply, st.error_reply; 13 st.message, st.presence, st.iq, st.stanza, st.reply, st.error_reply;
14
15 function verse.iq(attr)
16 if not attr.id then
17 attr.id = new_id();
18 end
19 return st.iq(attr);
20 end
11 21
12 local new_xmpp_stream = require "util.xmppstream".new; 22 local new_xmpp_stream = require "util.xmppstream".new;
13 23
14 local xmlns_stream = "http://etherx.jabber.org/streams"; 24 local xmlns_stream = "http://etherx.jabber.org/streams";
15 25
206 self:send(st.stanza("stream:stream", { to = self.host, ["xmlns:stream"]='http://etherx.jabber.org/streams', 216 self:send(st.stanza("stream:stream", { to = self.host, ["xmlns:stream"]='http://etherx.jabber.org/streams',
207 xmlns = "jabber:client", version = "1.0" }):top_tag()); 217 xmlns = "jabber:client", version = "1.0" }):top_tag());
208 end 218 end
209 219
210 function stream:send_iq(iq, callback) 220 function stream:send_iq(iq, callback)
211 local id = self:new_id(); 221 local id = iq.attr.id or uuid.generate();
212 self.tracked_iqs[id] = callback; 222 self.tracked_iqs[id] = callback;
213 iq.attr.id = id; 223 iq.attr.id = id;
214 self:send(iq); 224 self:send(iq);
215 end 225 end
216
217 function stream:new_id()
218 self.curr_id = self.curr_id + 1;
219 return tostring(self.curr_id);
220 end

mercurial