diff options
Diffstat (limited to 'xmpp-vala/src/module')
-rw-r--r-- | xmpp-vala/src/module/tls.vala | 2 | ||||
-rw-r--r-- | xmpp-vala/src/module/xep/0333_chat_markers.vala | 2 | ||||
-rw-r--r-- | xmpp-vala/src/module/xep/0368_srv_records_tls.vala | 53 |
3 files changed, 55 insertions, 2 deletions
diff --git a/xmpp-vala/src/module/tls.vala b/xmpp-vala/src/module/tls.vala index 8cc7ad16..dd4fd82d 100644 --- a/xmpp-vala/src/module/tls.vala +++ b/xmpp-vala/src/module/tls.vala @@ -81,7 +81,7 @@ namespace Xmpp.Tls { public class Flag : XmppStreamFlag { public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "tls"); public TlsCertificate? peer_certificate; - public bool finished = false; + public bool finished { get; set; default=false; } public override string get_ns() { return NS_URI; } public override string get_id() { return IDENTITY.id; } diff --git a/xmpp-vala/src/module/xep/0333_chat_markers.vala b/xmpp-vala/src/module/xep/0333_chat_markers.vala index 11817a22..9c1b9c74 100644 --- a/xmpp-vala/src/module/xep/0333_chat_markers.vala +++ b/xmpp-vala/src/module/xep/0333_chat_markers.vala @@ -45,7 +45,7 @@ public class Module : XmppStreamModule { } public static void require(XmppStream stream) { - if (stream.get_module(IDENTITY) == null) stream.add_module(new ChatMarkers.Module()); + if (stream.get_module(IDENTITY) == null) stream.add_module(new Module()); } public override string get_ns() { return NS_URI; } diff --git a/xmpp-vala/src/module/xep/0368_srv_records_tls.vala b/xmpp-vala/src/module/xep/0368_srv_records_tls.vala new file mode 100644 index 00000000..da70b513 --- /dev/null +++ b/xmpp-vala/src/module/xep/0368_srv_records_tls.vala @@ -0,0 +1,53 @@ +using Gee; + +using Xmpp.Core; + +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 static void require(XmppStream stream) { + if (stream.get_module(IDENTITY) == null) stream.add_module(new Module()); + } + + 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 override int? get_priority(string remote_name) { + GLib.List<SrvTarget>? xmpp_target = null; + try { + Resolver resolver = Resolver.get_default(); + xmpp_target = resolver.lookup_service("xmpps-client", "tcp", remote_name, 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 override IOStream? connect(XmppStream stream) { + SocketClient client = new SocketClient(); + IOStream? io_stream = client.connect_to_host(srv_target.get_hostname(), srv_target.get_port()); + io_stream = TlsClientConnection.new(io_stream, new NetworkAddress(srv_target.get_hostname(), srv_target.get_port())); + stream.add_flag(new Tls.Flag() { finished=true }); + return io_stream; + } + + public override string get_id() { return "start_tls"; } +} + +} |