Annotate

plugins/session.lua @ 73:b416751df2ca

verse.plugins.session: Convert from spaces to tabs
author Matthew Wild <mwild1@gmail.com>
date Sun, 30 May 2010 02:37:03 +0100
parent 68:1789dac44823
child 75:f5ac4e39e84f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
68
1789dac44823 plugins.session: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 50
diff changeset
1 local st = require "util.stanza";
1789dac44823 plugins.session: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 50
diff changeset
2 local xmlns_session = "urn:ietf:params:xml:ns:xmpp-session";
1789dac44823 plugins.session: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 50
diff changeset
3
1789dac44823 plugins.session: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 50
diff changeset
4 function verse.plugins.session(stream)
73
b416751df2ca verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents: 68
diff changeset
5 local function handle_binding(jid)
b416751df2ca verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents: 68
diff changeset
6 stream:debug("Establishing Session...");
b416751df2ca verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents: 68
diff changeset
7 stream:send_iq(st.iq({ type = "set" }):tag("session", {xmlns=xmlns_session}),
b416751df2ca verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents: 68
diff changeset
8 function (reply)
b416751df2ca verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents: 68
diff changeset
9 if reply.attr.type == "result" then
b416751df2ca verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents: 68
diff changeset
10 stream:event("session-success");
b416751df2ca verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents: 68
diff changeset
11 elseif reply.attr.type == "error" then
b416751df2ca verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents: 68
diff changeset
12 local err = reply:child_with_name("error");
b416751df2ca verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents: 68
diff changeset
13 local type, condition, text = reply:get_error();
b416751df2ca verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents: 68
diff changeset
14 stream:event("session-failure", { error = condition, text = text, type = type });
b416751df2ca verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents: 68
diff changeset
15 end
b416751df2ca verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents: 68
diff changeset
16 end);
b416751df2ca verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents: 68
diff changeset
17 end
b416751df2ca verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents: 68
diff changeset
18 stream:hook("binding-success", handle_binding);
b416751df2ca verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents: 68
diff changeset
19 return true;
68
1789dac44823 plugins.session: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 50
diff changeset
20 end