aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2020-11-16 15:55:33 +0100
committerfiaxh <git@lightrise.org>2020-11-20 15:21:18 +0100
commit07917f1d841f449157aa3aaa2507b0547dd274e7 (patch)
tree315ef3bc243491565d3d5097968dca38d67a7eab /xmpp-vala/src/module
parent881b9eec9dcd8fd8c81b0b9d7bfd2ae714d7722e (diff)
downloaddino-07917f1d841f449157aa3aaa2507b0547dd274e7.tar.gz
dino-07917f1d841f449157aa3aaa2507b0547dd274e7.zip
Refactor XmppStream, TLS and connection method logic
fixes #534
Diffstat (limited to 'xmpp-vala/src/module')
-rw-r--r--xmpp-vala/src/module/sasl.vala1
-rw-r--r--xmpp-vala/src/module/tls.vala5
-rw-r--r--xmpp-vala/src/module/xep/0030_service_discovery/module.vala18
-rw-r--r--xmpp-vala/src/module/xep/0198_stream_management.vala19
-rw-r--r--xmpp-vala/src/module/xep/0368_srv_records_tls.vala56
5 files changed, 18 insertions, 81 deletions
diff --git a/xmpp-vala/src/module/sasl.vala b/xmpp-vala/src/module/sasl.vala
index 2e87e590..3f3eca58 100644
--- a/xmpp-vala/src/module/sasl.vala
+++ b/xmpp-vala/src/module/sasl.vala
@@ -154,7 +154,6 @@ namespace Xmpp.Sasl {
public void received_features_node(XmppStream stream) {
if (stream.has_flag(Flag.IDENTITY)) return;
if (stream.is_setup_needed()) return;
- if (!stream.has_flag(Tls.Flag.IDENTITY) || !stream.get_flag(Tls.Flag.IDENTITY).finished) return;
var mechanisms = stream.features.get_subnode("mechanisms", NS_URI);
string[] supported_mechanisms = {};
diff --git a/xmpp-vala/src/module/tls.vala b/xmpp-vala/src/module/tls.vala
index c3afc4b3..1b8a5411 100644
--- a/xmpp-vala/src/module/tls.vala
+++ b/xmpp-vala/src/module/tls.vala
@@ -23,10 +23,11 @@ namespace Xmpp.Tls {
private void received_nonza(XmppStream stream, StanzaNode node) {
if (node.ns_uri == NS_URI && node.name == "proceed") {
try {
- var io_stream = stream.get_stream();
+ StartTlsXmppStream? tls_xmpp_stream = stream as StartTlsXmppStream;
+ var io_stream = tls_xmpp_stream.get_stream();
if (io_stream == null) return;
var conn = TlsClientConnection.new(io_stream, identity);
- stream.reset_stream(conn);
+ tls_xmpp_stream.reset_stream(conn);
conn.accept_certificate.connect(on_invalid_certificate);
var flag = stream.get_flag(Flag.IDENTITY);
diff --git a/xmpp-vala/src/module/xep/0030_service_discovery/module.vala b/xmpp-vala/src/module/xep/0030_service_discovery/module.vala
index 42547f62..537e460b 100644
--- a/xmpp-vala/src/module/xep/0030_service_discovery/module.vala
+++ b/xmpp-vala/src/module/xep/0030_service_discovery/module.vala
@@ -23,7 +23,10 @@ public class Module : XmppStreamModule, Iq.Handler {
}
public void remove_feature(XmppStream stream, string feature) {
- stream.get_flag(Flag.IDENTITY).remove_own_feature(feature);
+ Flag? flag = stream.get_flag(Flag.IDENTITY);
+ if (flag != null) {
+ flag.remove_own_feature(feature);
+ }
}
public void add_feature_notify(XmppStream stream, string feature) {
@@ -34,14 +37,6 @@ public class Module : XmppStreamModule, Iq.Handler {
remove_feature(stream, feature + "+notify");
}
- public void add_identity(XmppStream stream, Identity identity) {
- stream.get_flag(Flag.IDENTITY).add_own_identity(identity);
- }
-
- public void remove_identity(XmppStream stream, Identity identity) {
- stream.get_flag(Flag.IDENTITY).remove_own_identity(identity);
- }
-
public async bool has_entity_feature(XmppStream stream, Jid jid, string feature) {
return yield this.cache.has_entity_feature(jid, feature);
}
@@ -93,7 +88,7 @@ public class Module : XmppStreamModule, Iq.Handler {
public override void attach(XmppStream stream) {
stream.add_flag(new Flag());
- add_identity(stream, own_identity);
+ stream.get_flag(Flag.IDENTITY).add_own_identity(own_identity);
stream.get_module(Iq.Module.IDENTITY).register_for_namespace(NS_URI_INFO, this);
add_feature(stream, NS_URI_INFO);
@@ -102,7 +97,8 @@ public class Module : XmppStreamModule, Iq.Handler {
public override void detach(XmppStream stream) {
active_info_requests.clear();
- remove_identity(stream, own_identity);
+ Flag? flag = stream.get_flag(Flag.IDENTITY);
+ if (flag != null) flag.remove_own_identity(own_identity);
stream.get_module(Iq.Module.IDENTITY).unregister_from_namespace(NS_URI_INFO, this);
remove_feature(stream, NS_URI_INFO);
diff --git a/xmpp-vala/src/module/xep/0198_stream_management.vala b/xmpp-vala/src/module/xep/0198_stream_management.vala
index b6317425..b9185808 100644
--- a/xmpp-vala/src/module/xep/0198_stream_management.vala
+++ b/xmpp-vala/src/module/xep/0198_stream_management.vala
@@ -39,7 +39,7 @@ public class Module : XmppStreamNegotiationModule, WriteNodeFunc {
}
internal async void write_node(XmppStream stream, StanzaNode node) {
- StanzaWriter? writer = stream.writer;
+ StanzaWriter? writer = ((IoXmppStream)stream).writer;
if (writer == null) return;
try {
stream.log.node("OUT", node, stream);
@@ -104,14 +104,11 @@ public class Module : XmppStreamNegotiationModule, WriteNodeFunc {
private void check_resume(XmppStream stream) {
if (stream_has_sm_feature(stream) && session_id != null) {
- Tls.Flag? tls_flag = stream.get_flag(Tls.Flag.IDENTITY);
- if (tls_flag != null && tls_flag.finished) {
- StanzaNode node = new StanzaNode.build("resume", NS_URI).add_self_xmlns()
- .put_attribute("h", h_inbound.to_string())
- .put_attribute("previd", session_id);
- write_node.begin(stream, node);
- stream.add_flag(new Flag());
- }
+ StanzaNode node = new StanzaNode.build("resume", NS_URI).add_self_xmlns()
+ .put_attribute("h", h_inbound.to_string())
+ .put_attribute("previd", session_id);
+ write_node.begin(stream, node);
+ stream.add_flag(new Flag());
}
}
@@ -137,7 +134,7 @@ public class Module : XmppStreamNegotiationModule, WriteNodeFunc {
h_inbound = 0;
session_id = node.get_attribute("id", NS_URI);
flags = stream.flags;
- stream.write_obj = this;
+ ((IoXmppStream)stream).write_obj = this;
} else if (node.name == "resumed") {
stream.get_flag(Flag.IDENTITY).resumed = true;
@@ -152,7 +149,7 @@ public class Module : XmppStreamNegotiationModule, WriteNodeFunc {
}
in_flight_stanzas.clear();
check_queue(stream);
- stream.write_obj = this;
+ ((IoXmppStream)stream).write_obj = this;
} else if (node.name == "failed") {
stream.received_features_node(stream);
session_id = null;
diff --git a/xmpp-vala/src/module/xep/0368_srv_records_tls.vala b/xmpp-vala/src/module/xep/0368_srv_records_tls.vala
deleted file mode 100644
index 5a2a4559..00000000
--- a/xmpp-vala/src/module/xep/0368_srv_records_tls.vala
+++ /dev/null
@@ -1,56 +0,0 @@
-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 {
- debug("Connecting to %s %i (tls)", srv_target.get_hostname(), srv_target.get_port());
- IOStream? io_stream = yield client.connect_to_host_async(srv_target.get_hostname(), srv_target.get_port());
- TlsConnection tls_connection = TlsClientConnection.new(io_stream, new NetworkAddress(stream.remote_name.to_string(), srv_target.get_port()));
-#if ALPN_SUPPORT
- tls_connection.set_advertised_protocols(new string[]{"xmpp-client"});
-#endif
- tls_connection.accept_certificate.connect(stream.get_module(Tls.Module.IDENTITY).on_invalid_certificate);
- stream.add_flag(new Tls.Flag() { finished=true });
- return tls_connection;
- } catch (Error e) {
- return null;
- }
- }
-
- public override string get_id() { return "srv_records"; }
-}
-
-}