Software /
code /
verse
Annotate
plugins/session.lua @ 122:e2600454fd54
plugins.adhoc: Support for querying for and executing commands
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 19:30:49 +0100 |
parent | 78:f4188eff53a7 |
child | 197:7e98cf2c1d8d |
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) |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
5 |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
6 local function handle_features(features) |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
7 local session_feature = features:get_child("session", xmlns_session); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
8 if session_feature and not session_feature:get_child("optional") then |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
9 local function handle_binding(jid) |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
10 stream:debug("Establishing Session..."); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
11 stream:send_iq(st.iq({ type = "set" }):tag("session", {xmlns=xmlns_session}), |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
12 function (reply) |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
13 if reply.attr.type == "result" then |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
14 stream:event("session-success"); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
15 elseif reply.attr.type == "error" then |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
16 local err = reply:child_with_name("error"); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
17 local type, condition, text = reply:get_error(); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
18 stream:event("session-failure", { error = condition, text = text, type = type }); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
19 end |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
20 end); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
21 return true; |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
22 end |
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:
75
diff
changeset
|
23 stream:hook("bind-success", handle_binding); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
24 end |
73
b416751df2ca
verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents:
68
diff
changeset
|
25 end |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
26 stream:hook("stream-features", handle_features); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
73
diff
changeset
|
27 |
73
b416751df2ca
verse.plugins.session: Convert from spaces to tabs
Matthew Wild <mwild1@gmail.com>
parents:
68
diff
changeset
|
28 return true; |
68
1789dac44823
plugins.session: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
50
diff
changeset
|
29 end |