diff options
author | fiaxh <git@mx.ax.lt> | 2018-08-19 23:27:02 +0100 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2018-08-22 20:29:24 +0200 |
commit | 4be8c92a2c0e454ae217aea8f8eac69c99416214 (patch) | |
tree | d705773699389699d8165a4cef8b6712f2849dd8 /libdino/src/service/registration.vala | |
parent | ee5c838a6ba85c9d6e72ac2941a7994505aaa4fc (diff) | |
download | dino-4be8c92a2c0e454ae217aea8f8eac69c99416214.tar.gz dino-4be8c92a2c0e454ae217aea8f8eac69c99416214.zip |
In-Band Registration
Diffstat (limited to 'libdino/src/service/registration.vala')
-rw-r--r-- | libdino/src/service/registration.vala | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/libdino/src/service/registration.vala b/libdino/src/service/registration.vala new file mode 100644 index 00000000..32d8b04b --- /dev/null +++ b/libdino/src/service/registration.vala @@ -0,0 +1,42 @@ +using Gee; + +using Xmpp; +using Dino.Entities; + +namespace Dino { + +public class Register { + + public static async Xep.InBandRegistration.Form get_registration_form(Jid jid) { + XmppStream stream = new XmppStream(); + stream.add_module(new Tls.Module()); + stream.add_module(new Iq.Module()); + stream.add_module(new Xep.InBandRegistration.Module()); + stream.connect.begin(jid.bare_jid.to_string()); + + Xep.InBandRegistration.Form? form = null; + SourceFunc callback = get_registration_form.callback; + stream.stream_negotiated.connect(() => { + if (callback != null) { + Idle.add((owned)callback); + } + }); + Timeout.add_seconds(5, () => { + if (callback != null) { + Idle.add((owned)callback); + } + return false; + }); + yield; + if (stream.negotiation_complete) { + form = yield stream.get_module(Xep.InBandRegistration.Module.IDENTITY).get_from_server(stream, jid); + } + return form; + } + + public static async string submit_form(Jid jid, Xep.InBandRegistration.Form form) { + return yield form.stream.get_module(Xep.InBandRegistration.Module.IDENTITY).submit_to_server(form.stream, jid, form); + } +} + +} |