aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/registration.vala
diff options
context:
space:
mode:
Diffstat (limited to 'libdino/src/service/registration.vala')
-rw-r--r--libdino/src/service/registration.vala105
1 files changed, 60 insertions, 45 deletions
diff --git a/libdino/src/service/registration.vala b/libdino/src/service/registration.vala
index f6c6e95d..b4377b98 100644
--- a/libdino/src/service/registration.vala
+++ b/libdino/src/service/registration.vala
@@ -23,33 +23,35 @@ public class Register : StreamInteractionModule, Object{
}
public async ConnectionManager.ConnectionError.Source? add_check_account(Account account) {
- 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;
+ Gee.List<XmppStreamModule> list = new ArrayList<XmppStreamModule>();
+ list.add(new Iq.Module());
+ list.add(new Sasl.Module(account.bare_jid.to_string(), account.password));
+
+ XmppStreamResult stream_result = yield Xmpp.establish_stream(account.bare_jid.domain_jid, list, Application.print_xmpp);
+
+ if (stream_result.stream == null) {
+ if (stream_result.tls_errors != null) {
+ ret = ConnectionManager.ConnectionError.Source.TLS;
+ }
+ return ret;
+ }
+ XmppStream stream = stream_result.stream;
+
SourceFunc callback = add_check_account.callback;
stream.stream_negotiated.connect(() => {
if (callback == null) return;
Idle.add((owned)callback);
});
- 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.domainpart, (_, res) => {
+ stream.loop.begin((_, res) => {
try {
- stream.connect.end(res);
+ stream.loop.end(res);
} catch (Error e) {
debug("Error connecting to stream: %s", e.message);
}
@@ -62,7 +64,7 @@ public class Register : StreamInteractionModule, Object{
yield;
try {
- yield stream.disconnect();
+ yield stream_result.stream.disconnect();
} catch (Error e) {}
return ret;
}
@@ -73,13 +75,24 @@ public class Register : StreamInteractionModule, Object{
}
public static async ServerAvailabilityReturn check_server_availability(Jid jid) {
- XmppStream stream = new XmppStream();
- stream.log = new XmppLog(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());
-
ServerAvailabilityReturn ret = new ServerAvailabilityReturn() { available=false };
+
+ Gee.List<XmppStreamModule> list = new ArrayList<XmppStreamModule>();
+ list.add(new Iq.Module());
+
+ XmppStreamResult stream_result = yield Xmpp.establish_stream(jid.domain_jid, list, Application.print_xmpp);
+
+ if (stream_result.stream == null) {
+ if (stream_result.io_error != null) {
+ debug("Error connecting to stream: %s", stream_result.io_error.message);
+ }
+ if (stream_result.tls_errors != null) {
+ ret.error_flags = stream_result.tls_errors;
+ }
+ return ret;
+ }
+ XmppStream stream = stream_result.stream;
+
SourceFunc callback = check_server_availability.callback;
stream.stream_negotiated.connect(() => {
if (callback != null) {
@@ -87,16 +100,10 @@ public class Register : StreamInteractionModule, Object{
Idle.add((owned)callback);
}
});
- stream.get_module(Tls.Module.IDENTITY).invalid_certificate.connect((peer_cert, errors) => {
- if (callback != null) {
- ret.error_flags = errors;
- Idle.add((owned)callback);
- }
- });
- stream.connect.begin(jid.domainpart, (_, res) => {
+ stream.loop.begin((_, res) => {
try {
- stream.connect.end(res);
+ stream.loop.end(res);
} catch (Error e) {
debug("Error connecting to stream: %s", e.message);
}
@@ -114,12 +121,16 @@ public class Register : StreamInteractionModule, Object{
}
public static async Xep.InBandRegistration.Form? get_registration_form(Jid jid) {
- XmppStream stream = new XmppStream();
- stream.log = new XmppLog(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 Xep.InBandRegistration.Module());
+ Gee.List<XmppStreamModule> list = new ArrayList<XmppStreamModule>();
+ list.add(new Iq.Module());
+ list.add(new Xep.InBandRegistration.Module());
+
+ XmppStreamResult stream_result = yield Xmpp.establish_stream(jid.domain_jid, list, Application.print_xmpp);
+
+ if (stream_result.stream == null) {
+ return null;
+ }
+ XmppStream stream = stream_result.stream;
SourceFunc callback = get_registration_form.callback;
@@ -129,9 +140,9 @@ public class Register : StreamInteractionModule, Object{
}
});
- stream.connect.begin(jid.domainpart, (_, res) => {
+ stream.loop.begin((_, res) => {
try {
- stream.connect.end(res);
+ stream.loop.end(res);
} catch (Error e) {
debug("Error connecting to stream: %s", e.message);
}
@@ -154,12 +165,16 @@ public class Register : StreamInteractionModule, Object{
}
public static async string? submit_form(Jid jid, Xep.InBandRegistration.Form form) {
- XmppStream stream = new XmppStream();
- stream.log = new XmppLog(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 Xep.InBandRegistration.Module());
+ Gee.List<XmppStreamModule> list = new ArrayList<XmppStreamModule>();
+ list.add(new Iq.Module());
+ list.add(new Xep.InBandRegistration.Module());
+
+ XmppStreamResult stream_result = yield Xmpp.establish_stream(jid.domain_jid, list, Application.print_xmpp);
+
+ if (stream_result.stream == null) {
+ return null;
+ }
+ XmppStream stream = stream_result.stream;
SourceFunc callback = submit_form.callback;
@@ -169,9 +184,9 @@ public class Register : StreamInteractionModule, Object{
}
});
- stream.connect.begin(jid.domainpart, (_, res) => {
+ stream.loop.begin((_, res) => {
try {
- stream.connect.end(res);
+ stream.loop.end(res);
} catch (Error e) {
debug("Error connecting to stream: %s", e.message);
}