plugins/session.lua

Fri, 02 Apr 2010 16:07:43 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 02 Apr 2010 16:07:43 +0100
changeset 50
432ac110544f
child 68
1789dac44823
permissions
-rw-r--r--

Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!

50
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local st = require "util.stanza";
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local xmlns_session = "urn:ietf:params:xml:ns:xmpp-session";
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 function verse.plugins.session(stream)
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local function handle_binding(jid)
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 stream:debug("Establishing Session...");
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 stream:send_iq(st.iq({ type = "set" }):tag("session", {xmlns=xmlns_session}),
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 function (reply)
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 if reply.attr.type == "result" then
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 stream:event("session-success");
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 elseif reply.attr.type == "error" then
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local err = reply:child_with_name("error");
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local type, condition, text = reply:get_error();
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 stream:event("session-failure", { error = condition, text = text, type = type });
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 end
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 end);
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 end
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 stream:hook("binding-success", handle_binding);
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 return true;
432ac110544f Add support for 3921 session negotiation (makes ejabberd happy), thanks Chris!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 end

mercurial