aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/registration.vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2019-12-23 03:04:42 +0100
committerMarvin W <git@larma.de>2019-12-23 16:49:56 +0100
commit1eb01251e89760443d20fa6e200f2f4fdafd4e35 (patch)
tree9534c244916a284af8d90b3a4c5fa5a98844b87d /libdino/src/service/registration.vala
parent6257e9705cd51543437507dbe805b8913845dc40 (diff)
downloaddino-1eb01251e89760443d20fa6e200f2f4fdafd4e35.tar.gz
dino-1eb01251e89760443d20fa6e200f2f4fdafd4e35.zip
Don't go through ConnectionManager for initial connection attempt
Diffstat (limited to 'libdino/src/service/registration.vala')
-rw-r--r--libdino/src/service/registration.vala57
1 files changed, 40 insertions, 17 deletions
diff --git a/libdino/src/service/registration.vala b/libdino/src/service/registration.vala
index 19eebb05..073d2b74 100644
--- a/libdino/src/service/registration.vala
+++ b/libdino/src/service/registration.vala
@@ -23,29 +23,47 @@ public class Register : StreamInteractionModule, Object{
}
public async ConnectionManager.ConnectionError.Source? add_check_account(Account account) {
- SourceFunc callback = add_check_account.callback;
+ XmppStream stream = new XmppStream();
+ stream.log = new XmppLog(account.bare_jid.to_string(), Application.print_xmpp);
+ stream.add_module(new Tls.Module());
+ stream.add_module(new Iq.Module());
+ stream.add_module(new Xep.SrvRecordsTls.Module());
+ stream.add_module(new Sasl.Module(account.bare_jid.to_string(), account.password));
+
ConnectionManager.ConnectionError.Source? ret = null;
- ulong handler_id_connected = stream_interactor.stream_negotiated.connect((connected_account, stream) => {
- if (connected_account.equals(account)) {
- account.persist(db);
- account.enabled = true;
- Idle.add((owned)callback);
- }
+ SourceFunc callback = add_check_account.callback;
+ stream.stream_negotiated.connect(() => {
+ if (callback == null) return;
+ Idle.add((owned)callback);
});
- ulong handler_id_error = stream_interactor.connection_manager.connection_error.connect((connected_account, error) => {
- if (connected_account.equals(account)) {
- ret = error.source;
- }
- stream_interactor.disconnect_account.begin(account);
+ stream.get_module(Tls.Module.IDENTITY).invalid_certificate.connect((peer_cert, errors) => {
+ if (callback == null) return;
+ ret = ConnectionManager.ConnectionError.Source.TLS;
+ Idle.add((owned)callback);
+ });
+ stream.get_module(Sasl.Module.IDENTITY).received_auth_failure.connect((stream, node) => {
+ if (callback == null) return;
+ ret = ConnectionManager.ConnectionError.Source.SASL;
Idle.add((owned)callback);
});
+ stream.connect.begin(account.bare_jid.domainpart, (_, res) => {
+ try {
+ stream.connect.end(res);
+ } catch (Error e) {
+ debug("Error connecting to stream: %s", e.message);
+ }
+ if (callback != null) {
+ ret = ConnectionManager.ConnectionError.Source.CONNECTION;
+ Idle.add((owned)callback);
+ }
+ });
- stream_interactor.connect_account(account);
yield;
- stream_interactor.disconnect(handler_id_connected);
- stream_interactor.connection_manager.disconnect(handler_id_error);
+ try {
+ yield stream.disconnect();
+ } catch (Error e) {}
return ret;
}
@@ -164,10 +182,15 @@ public class Register : StreamInteractionModule, Object{
});
yield;
+
+ string? ret = null;
if (stream.negotiation_complete) {
- return yield stream.get_module(Xep.InBandRegistration.Module.IDENTITY).submit_to_server(stream, jid, form);
+ ret = yield stream.get_module(Xep.InBandRegistration.Module.IDENTITY).submit_to_server(stream, jid, form);
}
- return null;
+ try {
+ yield stream.disconnect();
+ } catch (Error e) {}
+ return ret;
}
}