# HG changeset patch # User Matthew Wild # Date 1275184039 -3600 # Node ID f5ac4e39e84f8b822c7707ffd3f54fd23d418126 # Parent 91e80e9f0259f62d9def1703d409cf40e699792a 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) diff -r 91e80e9f0259 -r f5ac4e39e84f plugins/session.lua --- a/plugins/session.lua Sun May 30 02:44:29 2010 +0100 +++ b/plugins/session.lua Sun May 30 02:47:19 2010 +0100 @@ -2,19 +2,28 @@ local xmlns_session = "urn:ietf:params:xml:ns:xmpp-session"; function verse.plugins.session(stream) - local function handle_binding(jid) - stream:debug("Establishing Session..."); - stream:send_iq(st.iq({ type = "set" }):tag("session", {xmlns=xmlns_session}), - function (reply) - if reply.attr.type == "result" then - stream:event("session-success"); - elseif reply.attr.type == "error" then - local err = reply:child_with_name("error"); - local type, condition, text = reply:get_error(); - stream:event("session-failure", { error = condition, text = text, type = type }); - end - end); + + local function handle_features(features) + local session_feature = features:get_child("session", xmlns_session); + if session_feature and not session_feature:get_child("optional") then + local function handle_binding(jid) + stream:debug("Establishing Session..."); + stream:send_iq(st.iq({ type = "set" }):tag("session", {xmlns=xmlns_session}), + function (reply) + if reply.attr.type == "result" then + stream:event("session-success"); + elseif reply.attr.type == "error" then + local err = reply:child_with_name("error"); + local type, condition, text = reply:get_error(); + stream:event("session-failure", { error = condition, text = text, type = type }); + end + end); + return true; + end + stream:hook("binding-success", handle_binding); + end end - stream:hook("binding-success", handle_binding); + stream:hook("stream-features", handle_features); + return true; end