client.lua

Sat, 21 Aug 2010 14:51:36 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 21 Aug 2010 14:51:36 +0100
changeset 99
0f5a8d530fcd
parent 97
ad6006779416
child 137
e4b9d3c5332c
permissions
-rw-r--r--

verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities

26
6c5fab6c11cf Rename verse2 -> verse
Matthew Wild <mwild1@gmail.com>
parents: 25
diff changeset
1 local verse = require "verse";
1
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local stream = verse.stream_mt;
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3
30
9c96318913f7 Revert module names throughout to their Prosody equivalents
Matthew Wild <mwild1@gmail.com>
parents: 28
diff changeset
4 local jid_split = require "util.jid".split;
1
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local lxp = require "lxp";
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local st = require "util.stanza";
22
e6fad7c411fe verse.client: Extend verse object with message/iq/presence/stanza methods from util.stanza
Matthew Wild <mwild1@gmail.com>
parents: 21
diff changeset
7
e6fad7c411fe verse.client: Extend verse object with message/iq/presence/stanza methods from util.stanza
Matthew Wild <mwild1@gmail.com>
parents: 21
diff changeset
8 -- Shortcuts to save having to load util.stanza
52
8416508bfeb4 verse.client: Add verse.error_reply() helper
Matthew Wild <mwild1@gmail.com>
parents: 50
diff changeset
9 verse.message, verse.presence, verse.iq, verse.stanza, verse.reply, verse.error_reply =
8416508bfeb4 verse.client: Add verse.error_reply() helper
Matthew Wild <mwild1@gmail.com>
parents: 50
diff changeset
10 st.message, st.presence, st.iq, st.stanza, st.reply, st.error_reply;
22
e6fad7c411fe verse.client: Extend verse object with message/iq/presence/stanza methods from util.stanza
Matthew Wild <mwild1@gmail.com>
parents: 21
diff changeset
11
47
3ebffb4fc48c verse.client, squishy: Rename "xmlhandlers" to "core.xmlhandlers" in line with Prosody's structure
Matthew Wild <mwild1@gmail.com>
parents: 46
diff changeset
12 local init_xmlhandlers = require "core.xmlhandlers";
1
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13
10
3a422606a040 verse.client: Fire events on stream features, errors, etc. and on non-stream tags such as SASL and TLS
Matthew Wild <mwild1@gmail.com>
parents: 1
diff changeset
14 local xmlns_stream = "http://etherx.jabber.org/streams";
1
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
48
abccad4b8559 verse.client: Update stream_callbacks format for new xmlhandlers API (thanks to Bill Clark for the patch)
Matthew Wild <mwild1@gmail.com>
parents: 47
diff changeset
16 local stream_callbacks = {
abccad4b8559 verse.client: Update stream_callbacks format for new xmlhandlers API (thanks to Bill Clark for the patch)
Matthew Wild <mwild1@gmail.com>
parents: 47
diff changeset
17 stream_ns = xmlns_stream,
abccad4b8559 verse.client: Update stream_callbacks format for new xmlhandlers API (thanks to Bill Clark for the patch)
Matthew Wild <mwild1@gmail.com>
parents: 47
diff changeset
18 stream_tag = "stream",
abccad4b8559 verse.client: Update stream_callbacks format for new xmlhandlers API (thanks to Bill Clark for the patch)
Matthew Wild <mwild1@gmail.com>
parents: 47
diff changeset
19 default_ns = "jabber:client" };
1
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 function stream_callbacks.streamopened(stream, attr)
83
8221f3c25fd4 verse.client: Add stream_id property
Matthew Wild <mwild1@gmail.com>
parents: 81
diff changeset
22 stream.stream_id = attr.id;
8221f3c25fd4 verse.client: Add stream_id property
Matthew Wild <mwild1@gmail.com>
parents: 81
diff changeset
23 if not stream:event("opened", attr) then
1
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 stream.notopen = nil;
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 end
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 return true;
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 end
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 function stream_callbacks.streamclosed(stream)
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 return stream:event("closed");
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 end
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 function stream_callbacks.handlestanza(stream, stanza)
10
3a422606a040 verse.client: Fire events on stream features, errors, etc. and on non-stream tags such as SASL and TLS
Matthew Wild <mwild1@gmail.com>
parents: 1
diff changeset
34 if stanza.attr.xmlns == xmlns_stream then
3a422606a040 verse.client: Fire events on stream features, errors, etc. and on non-stream tags such as SASL and TLS
Matthew Wild <mwild1@gmail.com>
parents: 1
diff changeset
35 return stream:event("stream-"..stanza.name, stanza);
3a422606a040 verse.client: Fire events on stream features, errors, etc. and on non-stream tags such as SASL and TLS
Matthew Wild <mwild1@gmail.com>
parents: 1
diff changeset
36 elseif stanza.attr.xmlns then
3a422606a040 verse.client: Fire events on stream features, errors, etc. and on non-stream tags such as SASL and TLS
Matthew Wild <mwild1@gmail.com>
parents: 1
diff changeset
37 return stream:event("stream/"..stanza.attr.xmlns, stanza);
3a422606a040 verse.client: Fire events on stream features, errors, etc. and on non-stream tags such as SASL and TLS
Matthew Wild <mwild1@gmail.com>
parents: 1
diff changeset
38 end
28
afe9e6d6c87a verse.client: New stanza dispatcher to fire events based on the name (and in the case of iq, xmlns) of the stanza
Matthew Wild <mwild1@gmail.com>
parents: 26
diff changeset
39
1
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 return stream:event("stanza", stanza);
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 end
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42
70
36d113fb0f3c verse.client: Add stream:reset(), keep self.data static between resets
Matthew Wild <mwild1@gmail.com>
parents: 62
diff changeset
43 function stream:reset()
1
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 -- Reset stream
70
36d113fb0f3c verse.client: Add stream:reset(), keep self.data static between resets
Matthew Wild <mwild1@gmail.com>
parents: 62
diff changeset
45 local parser = lxp.new(init_xmlhandlers(self, stream_callbacks), "\1");
36d113fb0f3c verse.client: Add stream:reset(), keep self.data static between resets
Matthew Wild <mwild1@gmail.com>
parents: 62
diff changeset
46 self.parser = parser;
1
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47
70
36d113fb0f3c verse.client: Add stream:reset(), keep self.data static between resets
Matthew Wild <mwild1@gmail.com>
parents: 62
diff changeset
48 self.notopen = true;
1
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 return true;
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 end
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 function stream:connect_client(jid, pass)
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 self.jid, self.password = jid, pass;
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 self.username, self.host, self.resource = jid_split(jid);
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56
62
d4b6f9e33c6e verse.client: Load TLS along with other core plugins
Matthew Wild <mwild1@gmail.com>
parents: 52
diff changeset
57 -- Required XMPP features
d4b6f9e33c6e verse.client: Load TLS along with other core plugins
Matthew Wild <mwild1@gmail.com>
parents: 52
diff changeset
58 self:add_plugin("tls");
38
c40cc28ac7df verse.client: Automatically load sasl and bind plugins
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
59 self:add_plugin("sasl");
c40cc28ac7df verse.client: Automatically load sasl and bind plugins
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
60 self:add_plugin("bind");
50
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents: 49
diff changeset
61 self:add_plugin("session");
38
c40cc28ac7df verse.client: Automatically load sasl and bind plugins
Matthew Wild <mwild1@gmail.com>
parents: 37
diff changeset
62
70
36d113fb0f3c verse.client: Add stream:reset(), keep self.data static between resets
Matthew Wild <mwild1@gmail.com>
parents: 62
diff changeset
63 function self.data(conn, data)
36d113fb0f3c verse.client: Add stream:reset(), keep self.data static between resets
Matthew Wild <mwild1@gmail.com>
parents: 62
diff changeset
64 local ok, err = self.parser:parse(data);
36d113fb0f3c verse.client: Add stream:reset(), keep self.data static between resets
Matthew Wild <mwild1@gmail.com>
parents: 62
diff changeset
65 if ok then return; end
36d113fb0f3c verse.client: Add stream:reset(), keep self.data static between resets
Matthew Wild <mwild1@gmail.com>
parents: 62
diff changeset
66 stream:debug("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "));
36d113fb0f3c verse.client: Add stream:reset(), keep self.data static between resets
Matthew Wild <mwild1@gmail.com>
parents: 62
diff changeset
67 stream:close("xml-not-well-formed");
36d113fb0f3c verse.client: Add stream:reset(), keep self.data static between resets
Matthew Wild <mwild1@gmail.com>
parents: 62
diff changeset
68 end
36d113fb0f3c verse.client: Add stream:reset(), keep self.data static between resets
Matthew Wild <mwild1@gmail.com>
parents: 62
diff changeset
69
1
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 self:hook("incoming-raw", function (data) return self.data(self.conn, data); end);
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71
13
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
72 self.curr_id = 0;
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
73
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
74 self.tracked_iqs = {};
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
75 self:hook("stanza", function (stanza)
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
76 local id, type = stanza.attr.id, stanza.attr.type;
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
77 if id and stanza.name == "iq" and (type == "result" or type == "error") and self.tracked_iqs[id] then
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
78 self.tracked_iqs[id](stanza);
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
79 self.tracked_iqs[id] = nil;
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
80 return true;
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
81 end
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
82 end);
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
83
37
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
84 self:hook("stanza", function (stanza)
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
85 if stanza.attr.xmlns == nil or stanza.attr.xmlns == "jabber:client" then
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
86 if stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
87 local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns;
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
88 if xmlns then
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
89 ret = self:event("iq/"..xmlns, stanza);
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
90 if not ret then
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
91 ret = self:event("iq", stanza);
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
92 end
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
93 end
81
0924a3d05e40 Bounce service-unavailable on unhandled iq stanzas (thanks Kev, Florob and anyone else who poked me)
Matthew Wild <mwild1@gmail.com>
parents: 78
diff changeset
94 if ret == nil then
0924a3d05e40 Bounce service-unavailable on unhandled iq stanzas (thanks Kev, Florob and anyone else who poked me)
Matthew Wild <mwild1@gmail.com>
parents: 78
diff changeset
95 self:send(verse.error_reply(stanza, "cancel", "service-unavailable"));
0924a3d05e40 Bounce service-unavailable on unhandled iq stanzas (thanks Kev, Florob and anyone else who poked me)
Matthew Wild <mwild1@gmail.com>
parents: 78
diff changeset
96 return true;
0924a3d05e40 Bounce service-unavailable on unhandled iq stanzas (thanks Kev, Florob and anyone else who poked me)
Matthew Wild <mwild1@gmail.com>
parents: 78
diff changeset
97 end
37
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
98 else
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
99 ret = self:event(stanza.name, stanza);
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
100 end
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
101 end
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
102 return ret;
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
103 end, -1);
0ccd523e110a verse.client: Don't hook the stanza event every time a stanza comes in :)
Matthew Wild <mwild1@gmail.com>
parents: 30
diff changeset
104
76
927167321283 verse.client: Fire 'ready' event on stream when resource binding or session negotiation is complete, hook this instead of binding-success
Matthew Wild <mwild1@gmail.com>
parents: 70
diff changeset
105 local function stream_ready()
927167321283 verse.client: Fire 'ready' event on stream when resource binding or session negotiation is complete, hook this instead of binding-success
Matthew Wild <mwild1@gmail.com>
parents: 70
diff changeset
106 self:event("ready");
927167321283 verse.client: Fire 'ready' event on stream when resource binding or session negotiation is complete, hook this instead of binding-success
Matthew Wild <mwild1@gmail.com>
parents: 70
diff changeset
107 end
927167321283 verse.client: Fire 'ready' event on stream when resource binding or session negotiation is complete, hook this instead of binding-success
Matthew Wild <mwild1@gmail.com>
parents: 70
diff changeset
108 self:hook("session-success", stream_ready, -1)
78
f4188eff53a7 verse.client, verse.plugins.bind, verse.plugins.session: Rename binding-success and binding-failure to bind-success and bind-failure for consistency
Matthew Wild <mwild1@gmail.com>
parents: 76
diff changeset
109 self:hook("bind-success", stream_ready, -1);
76
927167321283 verse.client: Fire 'ready' event on stream when resource binding or session negotiation is complete, hook this instead of binding-success
Matthew Wild <mwild1@gmail.com>
parents: 70
diff changeset
110
97
ad6006779416 verse.client: Update stream:close() to use base stream:close(), and not add an XMPP-specific :close() to the base stream
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
111 local _base_close = self.close;
ad6006779416 verse.client: Update stream:close() to use base stream:close(), and not add an XMPP-specific :close() to the base stream
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
112 function self:close(reason)
ad6006779416 verse.client: Update stream:close() to use base stream:close(), and not add an XMPP-specific :close() to the base stream
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
113 if not self.notopen then
ad6006779416 verse.client: Update stream:close() to use base stream:close(), and not add an XMPP-specific :close() to the base stream
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
114 self:send("</stream:stream>");
ad6006779416 verse.client: Update stream:close() to use base stream:close(), and not add an XMPP-specific :close() to the base stream
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
115 end
ad6006779416 verse.client: Update stream:close() to use base stream:close(), and not add an XMPP-specific :close() to the base stream
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
116 return _base_close(self);
ad6006779416 verse.client: Update stream:close() to use base stream:close(), and not add an XMPP-specific :close() to the base stream
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
117 end
ad6006779416 verse.client: Update stream:close() to use base stream:close(), and not add an XMPP-specific :close() to the base stream
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
118
1
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 -- Initialise connection
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 self:connect(self.connect_host or self.host, self.connect_port or 5222);
11
ce349990bd21 verse.client: Add stream:reopen()
Matthew Wild <mwild1@gmail.com>
parents: 10
diff changeset
121 self:reopen();
1
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 end
7c8d0a2fc004 Break client-specific code into verse.client module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123
11
ce349990bd21 verse.client: Add stream:reopen()
Matthew Wild <mwild1@gmail.com>
parents: 10
diff changeset
124 function stream:reopen()
70
36d113fb0f3c verse.client: Add stream:reset(), keep self.data static between resets
Matthew Wild <mwild1@gmail.com>
parents: 62
diff changeset
125 self:reset();
49
9c10ff584e87 verse.client: Add missing version to stream header (thanks Bill Clark)
Matthew Wild <mwild1@gmail.com>
parents: 48
diff changeset
126 self:send(st.stanza("stream:stream", { to = self.host, ["xmlns:stream"]='http://etherx.jabber.org/streams',
9c10ff584e87 verse.client: Add missing version to stream header (thanks Bill Clark)
Matthew Wild <mwild1@gmail.com>
parents: 48
diff changeset
127 xmlns = "jabber:client", version = "1.0" }):top_tag());
11
ce349990bd21 verse.client: Add stream:reopen()
Matthew Wild <mwild1@gmail.com>
parents: 10
diff changeset
128 end
ce349990bd21 verse.client: Add stream:reopen()
Matthew Wild <mwild1@gmail.com>
parents: 10
diff changeset
129
13
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
130 function stream:send_iq(iq, callback)
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
131 local id = self:new_id();
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
132 self.tracked_iqs[id] = callback;
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
133 iq.attr.id = id;
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
134 self:send(iq);
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
135 end
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
136
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
137 function stream:new_id()
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
138 self.curr_id = self.curr_id + 1;
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
139 return tostring(self.curr_id);
c3d83b98fb4f verse.client: Add stream:send_iq() and stream:new_id() for sending iqs with response handlers, and for generating stream-unique ids respectively
Matthew Wild <mwild1@gmail.com>
parents: 12
diff changeset
140 end

mercurial