aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/session.vala
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-06-21 01:07:06 +0200
committerfiaxh <git@mx.ax.lt>2017-06-21 01:58:09 +0200
commit3f0089db86e2057293a33453361678989919147f (patch)
tree97d7748903ba57ebfcb19a6eb640536651dd6a8f /xmpp-vala/src/module/session.vala
parent26973c89e391de673b6ac1db024a3098b1191393 (diff)
downloaddino-3f0089db86e2057293a33453361678989919147f.tar.gz
dino-3f0089db86e2057293a33453361678989919147f.zip
Session establishment
Diffstat (limited to 'xmpp-vala/src/module/session.vala')
-rw-r--r--xmpp-vala/src/module/session.vala54
1 files changed, 54 insertions, 0 deletions
diff --git a/xmpp-vala/src/module/session.vala b/xmpp-vala/src/module/session.vala
new file mode 100644
index 00000000..f37e585f
--- /dev/null
+++ b/xmpp-vala/src/module/session.vala
@@ -0,0 +1,54 @@
+using Xmpp.Core;
+
+namespace Xmpp.Session {
+private const string NS_URI = "urn:ietf:params:xml:ns:xmpp-session";
+
+public class Module : XmppStreamNegotiationModule {
+ public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "session");
+
+ public override void attach(XmppStream stream) {
+ Bind.Module.require(stream);
+ stream.get_module(Bind.Module.IDENTITY).bound_to_resource.connect(on_bound_resource);
+ }
+
+ public override void detach(XmppStream stream) {
+ stream.get_module(Bind.Module.IDENTITY).bound_to_resource.disconnect(on_bound_resource);
+ }
+
+ public static void require(XmppStream stream) {
+ if (stream.get_module(IDENTITY) == null) stream.add_module(new Module());
+ }
+
+ /* the client MUST establish a session if it desires to engage in instant messaging and presence functionality (RFC 3921 3) */
+ public override bool mandatory_outstanding(XmppStream stream) {
+ return !stream.has_flag(Flag.IDENTITY) || !stream.get_flag(Flag.IDENTITY).finished;
+ }
+
+ public override bool negotiation_active(XmppStream stream) {
+ return stream.has_flag(Flag.IDENTITY) && !stream.get_flag(Flag.IDENTITY).finished;
+ }
+
+ public override string get_ns() { return NS_URI; }
+ public override string get_id() { return IDENTITY.id; }
+
+ private void on_bound_resource(XmppStream stream, string my_jid) {
+ if (stream.features.get_subnode("session", NS_URI) != null) {
+ stream.add_flag(new Flag());
+ Iq.Stanza iq = new Iq.Stanza.set(new StanzaNode.build("session", NS_URI).add_self_xmlns()) { to=stream.remote_name };
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream, iq) => {
+ if (!iq.is_error()) {
+ stream.get_flag(Flag.IDENTITY).finished = true;
+ }
+ });
+ }
+ }
+}
+
+public class Flag : XmppStreamFlag {
+ public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "session");
+ public bool finished = false;
+
+ public override string get_ns() { return NS_URI; }
+ public override string get_id() { return IDENTITY.id; }
+}
+}