blob: 8da8ba0c180bca6833fdcb16761b12c2be624b07 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
using Gee;
namespace Xmpp.Xep.SrvRecordsTls {
public class Module : XmppStreamNegotiationModule {
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>("", "0363_srv_records_for_xmpp_over_tls");
public override void attach(XmppStream stream) {
stream.register_connection_provider(new TlsConnectionProvider());
}
public override void detach(XmppStream stream) { }
public override bool mandatory_outstanding(XmppStream stream) { return false; }
public override bool negotiation_active(XmppStream stream) { return false; }
public override string get_ns() { return IDENTITY.ns; }
public override string get_id() { return IDENTITY.id; }
}
public class TlsConnectionProvider : ConnectionProvider {
private SrvTarget? srv_target;
public async override int? get_priority(Jid remote_name) {
GLib.List<SrvTarget>? xmpp_target = null;
try {
GLibFixes.Resolver resolver = GLibFixes.Resolver.get_default();
xmpp_target = yield resolver.lookup_service_async("xmpps-client", "tcp", remote_name.to_string(), null);
} catch (Error e) {
return null;
}
xmpp_target.sort((a, b) => { return a.get_priority() - b.get_priority(); });
srv_target = xmpp_target.nth(0).data;
return xmpp_target.nth(0).data.get_priority();
}
public async override IOStream? connect(XmppStream stream) {
SocketClient client = new SocketClient();
try {
IOStream? io_stream = yield client.connect_to_host_async(srv_target.get_hostname(), srv_target.get_port());
io_stream = TlsClientConnection.new(io_stream, new NetworkAddress(stream.remote_name.to_string(), srv_target.get_port()));
stream.add_flag(new Tls.Flag() { finished=true });
return io_stream;
} catch (Error e) {
return null;
}
}
public override string get_id() { return "srv_records"; }
}
}
|