Comparison

plugins/session.lua @ 75:f5ac4e39e84f

verse.plugins.session: Only negotiate session when support is advertised by the server, and not marked as optional (saves a round-trip in a lot of cases)
author Matthew Wild <mwild1@gmail.com>
date Sun, 30 May 2010 02:47:19 +0100
parent 73:b416751df2ca
child 78:f4188eff53a7
comparison
equal deleted inserted replaced
74:91e80e9f0259 75:f5ac4e39e84f
1 local st = require "util.stanza"; 1 local st = require "util.stanza";
2 local xmlns_session = "urn:ietf:params:xml:ns:xmpp-session"; 2 local xmlns_session = "urn:ietf:params:xml:ns:xmpp-session";
3 3
4 function verse.plugins.session(stream) 4 function verse.plugins.session(stream)
5 local function handle_binding(jid) 5
6 stream:debug("Establishing Session..."); 6 local function handle_features(features)
7 stream:send_iq(st.iq({ type = "set" }):tag("session", {xmlns=xmlns_session}), 7 local session_feature = features:get_child("session", xmlns_session);
8 function (reply) 8 if session_feature and not session_feature:get_child("optional") then
9 if reply.attr.type == "result" then 9 local function handle_binding(jid)
10 stream:event("session-success"); 10 stream:debug("Establishing Session...");
11 elseif reply.attr.type == "error" then 11 stream:send_iq(st.iq({ type = "set" }):tag("session", {xmlns=xmlns_session}),
12 local err = reply:child_with_name("error"); 12 function (reply)
13 local type, condition, text = reply:get_error(); 13 if reply.attr.type == "result" then
14 stream:event("session-failure", { error = condition, text = text, type = type }); 14 stream:event("session-success");
15 end 15 elseif reply.attr.type == "error" then
16 end); 16 local err = reply:child_with_name("error");
17 local type, condition, text = reply:get_error();
18 stream:event("session-failure", { error = condition, text = text, type = type });
19 end
20 end);
21 return true;
22 end
23 stream:hook("binding-success", handle_binding);
24 end
17 end 25 end
18 stream:hook("binding-success", handle_binding); 26 stream:hook("stream-features", handle_features);
27
19 return true; 28 return true;
20 end 29 end