Disconnect stanza listeners from pipeline

This commit is contained in:
fiaxh 2017-11-21 23:27:27 +01:00
parent f3063f56b7
commit de133218da
11 changed files with 59 additions and 33 deletions

View file

@ -3,7 +3,7 @@ Version=1.0
Name=Dino Name=Dino
GenericName=Jabber/XMPP Client GenericName=Jabber/XMPP Client
Keywords=chat;talk;im;message;xmpp;jabber; Keywords=chat;talk;im;message;xmpp;jabber;
Exec=dino Exec=dino %U
Icon=dino Icon=dino
StartupNotify=false StartupNotify=false
Terminal=false Terminal=false

View file

@ -17,7 +17,7 @@ public class FileProvider : Dino.FileProvider, Object {
public FileProvider(StreamInteractor stream_interactor, Dino.Database dino_db) { public FileProvider(StreamInteractor stream_interactor, Dino.Database dino_db) {
this.stream_interactor = stream_interactor; this.stream_interactor = stream_interactor;
this.url_regex = new Regex("""^(?i)\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»]))$"""); this.url_regex = new Regex("""^(?i)\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»]))$""");
this.file_ext_regex = new Regex("""\.(png|jpg|jpeg|svg|gif)"""); this.file_ext_regex = new Regex("""\.(png|jpg|jpeg|svg|gif|pgp)""");
stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(check_message); stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(check_message);
stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(check_message); stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(check_message);

View file

@ -21,6 +21,7 @@ public class StreamModule : XmppStreamModule {
private ConcurrentSet<string> active_devicelist_requests = new ConcurrentSet<string>(); private ConcurrentSet<string> active_devicelist_requests = new ConcurrentSet<string>();
private Map<string, ArrayList<int32>> device_lists = new HashMap<string, ArrayList<int32>>(); private Map<string, ArrayList<int32>> device_lists = new HashMap<string, ArrayList<int32>>();
private Map<string, ArrayList<int32>> ignored_devices = new HashMap<string, ArrayList<int32>>(); private Map<string, ArrayList<int32>> ignored_devices = new HashMap<string, ArrayList<int32>>();
private ReceivedPipelineListener received_pipeline_listener;
public signal void store_created(Store store); public signal void store_created(Store store);
public signal void device_list_loaded(string jid); public signal void device_list_loaded(string jid);
@ -117,10 +118,15 @@ public class StreamModule : XmppStreamModule {
this.store = Plugin.get_context().create_store(); this.store = Plugin.get_context().create_store();
store_created(store); store_created(store);
stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(new ReceivedPipelineListener(store)); received_pipeline_listener = new ReceivedPipelineListener(store);
stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(received_pipeline_listener);
stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NODE_DEVICELIST, (stream, jid, id, node) => on_devicelist(stream, jid, id, node)); stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NODE_DEVICELIST, (stream, jid, id, node) => on_devicelist(stream, jid, id, node));
} }
public override void detach(XmppStream stream) {
stream.get_module(Message.Module.IDENTITY).received_pipeline.disconnect(received_pipeline_listener);
}
public void request_user_devicelist(XmppStream stream, string jid) { public void request_user_devicelist(XmppStream stream, string jid) {
if (active_devicelist_requests.add(jid)) { if (active_devicelist_requests.add(jid)) {
if (Plugin.DEBUG) print(@"OMEMO: requesting device list for $jid\n"); if (Plugin.DEBUG) print(@"OMEMO: requesting device list for $jid\n");
@ -369,10 +375,6 @@ public class StreamModule : XmppStreamModule {
stream.get_module(Pubsub.Module.IDENTITY).publish(stream, null, @"$NODE_BUNDLES:$device_id", @"$NODE_BUNDLES:$device_id", "1", bundle); stream.get_module(Pubsub.Module.IDENTITY).publish(stream, null, @"$NODE_BUNDLES:$device_id", @"$NODE_BUNDLES:$device_id", "1", bundle);
} }
public override void detach(XmppStream stream) {
}
public override string get_ns() { public override string get_ns() {
return NS_URI; return NS_URI;
} }

View file

@ -15,6 +15,7 @@ namespace Dino.Plugins.OpenPgp {
private string? signed_status = null; private string? signed_status = null;
private Key? own_key = null; private Key? own_key = null;
private ReceivedPipelineDecryptListener received_pipeline_decrypt_listener = new ReceivedPipelineDecryptListener();
public Module(string? own_key_id = null) { public Module(string? own_key_id = null) {
set_private_key_id(own_key_id); set_private_key_id(own_key_id);
@ -28,7 +29,6 @@ namespace Dino.Plugins.OpenPgp {
} catch (Error e) { } } catch (Error e) { }
if (own_key != null) { if (own_key != null) {
signed_status = gpg_sign("", own_key); signed_status = gpg_sign("", own_key);
get_sign_key(signed_status, "");
} }
} }
} }
@ -46,13 +46,14 @@ namespace Dino.Plugins.OpenPgp {
public override void attach(XmppStream stream) { public override void attach(XmppStream stream) {
stream.get_module(Presence.Module.IDENTITY).received_presence.connect(on_received_presence); stream.get_module(Presence.Module.IDENTITY).received_presence.connect(on_received_presence);
stream.get_module(Presence.Module.IDENTITY).pre_send_presence_stanza.connect(on_pre_send_presence_stanza); stream.get_module(Presence.Module.IDENTITY).pre_send_presence_stanza.connect(on_pre_send_presence_stanza);
stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(new ReceivedPipelineDecryptListener()); stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(received_pipeline_decrypt_listener);
stream.add_flag(new Flag()); stream.add_flag(new Flag());
} }
public override void detach(XmppStream stream) { public override void detach(XmppStream stream) {
stream.get_module(Presence.Module.IDENTITY).received_presence.disconnect(on_received_presence); stream.get_module(Presence.Module.IDENTITY).received_presence.disconnect(on_received_presence);
stream.get_module(Presence.Module.IDENTITY).pre_send_presence_stanza.disconnect(on_pre_send_presence_stanza); stream.get_module(Presence.Module.IDENTITY).pre_send_presence_stanza.disconnect(on_pre_send_presence_stanza);
stream.get_module(Message.Module.IDENTITY).received_pipeline.disconnect(received_pipeline_decrypt_listener);
} }
public static void require(XmppStream stream) { public static void require(XmppStream stream) {
@ -63,21 +64,19 @@ namespace Dino.Plugins.OpenPgp {
public override string get_id() { return IDENTITY.id; } public override string get_id() { return IDENTITY.id; }
private void on_received_presence(XmppStream stream, Presence.Stanza presence) { private void on_received_presence(XmppStream stream, Presence.Stanza presence) {
StanzaNode x_node = presence.stanza.get_subnode("x", NS_URI_SIGNED);
if (x_node == null) return;
string? sig = x_node.get_string_content();
if (sig == null) return;
new Thread<void*> (null, () => { new Thread<void*> (null, () => {
StanzaNode x_node = presence.stanza.get_subnode("x", NS_URI_SIGNED); string signed_data = presence.status == null ? "" : presence.status;
if (x_node != null) { string? key_id = get_sign_key(sig, signed_data);
string? sig = x_node.get_string_content(); if (key_id != null) {
if (sig != null) { stream.get_flag(Flag.IDENTITY).set_key_id(presence.from, key_id);
string signed_data = presence.status == null ? "" : presence.status; Idle.add(() => {
string? key_id = get_sign_key(sig, signed_data); received_jid_key_id(stream, presence.from, key_id);
if (key_id != null) { return false;
stream.get_flag(Flag.IDENTITY).set_key_id(presence.from, key_id); });
Idle.add(() => {
received_jid_key_id(stream, presence.from, key_id);
return false;
});
}
}
} }
return null; return null;
}); });

View file

@ -30,13 +30,18 @@ public abstract class StanzaListener<T> : Object {
} }
public class StanzaListenerHolder<T> : Object { public class StanzaListenerHolder<T> : Object {
private Gee.List<StanzaListener<T>> listeners = new ArrayList<StanzaListener<T>>(); private ArrayList<StanzaListener<T>> listeners = new ArrayList<StanzaListener<T>>();
public new void connect(StanzaListener<T> listener) { public new void connect(StanzaListener<T> listener) {
listeners.add(listener); listeners.add(listener);
resort_list(); resort_list();
} }
public new void disconnect(StanzaListener<T> listener) {
listeners.remove(listener);
resort_list();
}
public async void run(Core.XmppStream stream, T stanza) { public async void run(Core.XmppStream stream, T stanza) {
foreach (StanzaListener<T> l in listeners) { foreach (StanzaListener<T> l in listeners) {
yield l.run(stream, stanza); yield l.run(stream, stanza);
@ -63,7 +68,7 @@ public class StanzaListenerHolder<T> : Object {
} }
private void resort_list() { private void resort_list() {
Gee.List<StanzaListener<T>> new_list = new ArrayList<StanzaListener<T>>(); ArrayList<StanzaListener<T>> new_list = new ArrayList<StanzaListener<T>>();
while (listeners.size > new_list.size) { while (listeners.size > new_list.size) {
bool changed = false; bool changed = false;
foreach (StanzaListener<T> l in listeners) { foreach (StanzaListener<T> l in listeners) {

View file

@ -18,6 +18,8 @@ public class Module : XmppStreamModule {
public signal void chat_state_received(XmppStream stream, string jid, string state); public signal void chat_state_received(XmppStream stream, string jid, string state);
private SendPipelineListener send_pipeline_listener = new SendPipelineListener();
/** /**
* "A message stanza that does not contain standard messaging content [...] SHOULD be a state other than <active/>" (0085, 5.6) * "A message stanza that does not contain standard messaging content [...] SHOULD be a state other than <active/>" (0085, 5.6)
*/ */
@ -31,12 +33,13 @@ public class Module : XmppStreamModule {
public override void attach(XmppStream stream) { public override void attach(XmppStream stream) {
stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI); stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI);
stream.get_module(Message.Module.IDENTITY).send_pipeline.connect(new SendPipelineListener()); stream.get_module(Message.Module.IDENTITY).send_pipeline.connect(send_pipeline_listener);
stream.get_module(Message.Module.IDENTITY).received_message.connect(on_received_message); stream.get_module(Message.Module.IDENTITY).received_message.connect(on_received_message);
} }
public override void detach(XmppStream stream) { public override void detach(XmppStream stream) {
stream.get_module(Message.Module.IDENTITY).received_message.disconnect(on_received_message); stream.get_module(Message.Module.IDENTITY).received_message.disconnect(on_received_message);
stream.get_module(Message.Module.IDENTITY).send_pipeline.disconnect(send_pipeline_listener);
} }
public override string get_ns() { return NS_URI; } public override string get_ns() { return NS_URI; }

View file

@ -8,6 +8,8 @@ namespace Xmpp.Xep.MessageDeliveryReceipts {
public signal void receipt_received(XmppStream stream, string jid, string id); public signal void receipt_received(XmppStream stream, string jid, string id);
private SendPipelineListener send_pipeline_listener = new SendPipelineListener();
public void send_received(XmppStream stream, string from, string message_id) { public void send_received(XmppStream stream, string from, string message_id) {
Message.Stanza received_message = new Message.Stanza(); Message.Stanza received_message = new Message.Stanza();
received_message.to = from; received_message.to = from;
@ -22,11 +24,12 @@ namespace Xmpp.Xep.MessageDeliveryReceipts {
public override void attach(XmppStream stream) { public override void attach(XmppStream stream) {
stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI); stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI);
stream.get_module(Message.Module.IDENTITY).received_message.connect(received_message); stream.get_module(Message.Module.IDENTITY).received_message.connect(received_message);
stream.get_module(Message.Module.IDENTITY).send_pipeline.connect(new SendPipelineListener()); stream.get_module(Message.Module.IDENTITY).send_pipeline.connect(send_pipeline_listener);
} }
public override void detach(XmppStream stream) { public override void detach(XmppStream stream) {
stream.get_module(Message.Module.IDENTITY).received_message.disconnect(received_message); stream.get_module(Message.Module.IDENTITY).received_message.disconnect(received_message);
stream.get_module(Message.Module.IDENTITY).send_pipeline.disconnect(send_pipeline_listener);
} }
public override string get_ns() { return NS_URI; } public override string get_ns() { return NS_URI; }

View file

@ -6,6 +6,8 @@ namespace Xmpp.Xep.DelayedDelivery {
public class Module : XmppStreamModule { public class Module : XmppStreamModule {
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0203_delayed_delivery"); public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0203_delayed_delivery");
private ReceivedPipelineListener received_pipeline_listener = new ReceivedPipelineListener();
public static void set_message_delay(Message.Stanza message, DateTime datetime) { public static void set_message_delay(Message.Stanza message, DateTime datetime) {
StanzaNode delay_node = (new StanzaNode.build("delay", NS_URI)).add_self_xmlns(); StanzaNode delay_node = (new StanzaNode.build("delay", NS_URI)).add_self_xmlns();
delay_node.put_attribute("stamp", DateTimeProfiles.to_datetime(datetime)); delay_node.put_attribute("stamp", DateTimeProfiles.to_datetime(datetime));
@ -27,10 +29,12 @@ namespace Xmpp.Xep.DelayedDelivery {
} }
public override void attach(XmppStream stream) { public override void attach(XmppStream stream) {
stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(new ReceivedPipelineListener()); stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(received_pipeline_listener);
} }
public override void detach(XmppStream stream) { } public override void detach(XmppStream stream) {
stream.get_module(Message.Module.IDENTITY).received_pipeline.disconnect(received_pipeline_listener);
}
public override string get_ns() { return NS_URI; } public override string get_ns() { return NS_URI; }
public override string get_id() { return IDENTITY.id; } public override string get_id() { return IDENTITY.id; }

View file

@ -6,6 +6,8 @@ namespace Xmpp.Xep.MessageCarbons {
public class Module : XmppStreamModule { public class Module : XmppStreamModule {
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0280_message_carbons_module"); public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0280_message_carbons_module");
private ReceivedPipelineListener received_pipeline_listener = new ReceivedPipelineListener();
public void enable(XmppStream stream) { public void enable(XmppStream stream) {
Iq.Stanza iq = new Iq.Stanza.set(new StanzaNode.build("enable", NS_URI).add_self_xmlns()); Iq.Stanza iq = new Iq.Stanza.set(new StanzaNode.build("enable", NS_URI).add_self_xmlns());
stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq); stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq);
@ -18,12 +20,13 @@ namespace Xmpp.Xep.MessageCarbons {
public override void attach(XmppStream stream) { public override void attach(XmppStream stream) {
stream.stream_negotiated.connect(enable); stream.stream_negotiated.connect(enable);
stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(new ReceivedPipelineListener()); stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(received_pipeline_listener);
stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI); stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI);
} }
public override void detach(XmppStream stream) { public override void detach(XmppStream stream) {
stream.stream_negotiated.disconnect(enable); stream.stream_negotiated.disconnect(enable);
stream.get_module(Message.Module.IDENTITY).received_pipeline.disconnect(received_pipeline_listener);
} }
public override string get_ns() { return NS_URI; } public override string get_ns() { return NS_URI; }

View file

@ -14,6 +14,8 @@ public class Module : XmppStreamModule {
public signal void feature_available(XmppStream stream); public signal void feature_available(XmppStream stream);
private ReceivedPipelineListener received_pipeline_listener = new ReceivedPipelineListener();
public void query_archive(XmppStream stream, string? jid, DateTime? start, DateTime? end) { public void query_archive(XmppStream stream, string? jid, DateTime? start, DateTime? end) {
if (stream.get_flag(Flag.IDENTITY) == null) return; if (stream.get_flag(Flag.IDENTITY) == null) return;
@ -42,11 +44,13 @@ public class Module : XmppStreamModule {
} }
public override void attach(XmppStream stream) { public override void attach(XmppStream stream) {
stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(new ReceivedPipelineListener()); stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(received_pipeline_listener);
stream.stream_negotiated.connect(query_availability); stream.stream_negotiated.connect(query_availability);
} }
public override void detach(XmppStream stream) { } public override void detach(XmppStream stream) {
stream.get_module(Message.Module.IDENTITY).received_pipeline.disconnect(received_pipeline_listener);
}
public override string get_ns() { return NS_URI; } public override string get_ns() { return NS_URI; }
public override string get_id() { return IDENTITY.id; } public override string get_id() { return IDENTITY.id; }

View file

@ -16,6 +16,8 @@ public class Module : XmppStreamModule {
public signal void marker_received(XmppStream stream, string jid, string marker, string id); public signal void marker_received(XmppStream stream, string jid, string marker, string id);
private SendPipelineListener send_pipeline_listener = new SendPipelineListener();
public void send_marker(XmppStream stream, string jid, string message_id, string type_, string marker) { public void send_marker(XmppStream stream, string jid, string message_id, string type_, string marker) {
Message.Stanza received_message = new Message.Stanza(); Message.Stanza received_message = new Message.Stanza();
received_message.to = jid; received_message.to = jid;
@ -31,12 +33,13 @@ public class Module : XmppStreamModule {
public override void attach(XmppStream stream) { public override void attach(XmppStream stream) {
stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI); stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI);
stream.get_module(Message.Module.IDENTITY).send_pipeline.connect(new SendPipelineListener()); stream.get_module(Message.Module.IDENTITY).send_pipeline.connect(send_pipeline_listener);
stream.get_module(Message.Module.IDENTITY).received_message.connect(on_received_message); stream.get_module(Message.Module.IDENTITY).received_message.connect(on_received_message);
} }
public override void detach(XmppStream stream) { public override void detach(XmppStream stream) {
stream.get_module(Message.Module.IDENTITY).received_message.disconnect(on_received_message); stream.get_module(Message.Module.IDENTITY).received_message.disconnect(on_received_message);
stream.get_module(Message.Module.IDENTITY).send_pipeline.disconnect(send_pipeline_listener);
} }
public override string get_ns() { return NS_URI; } public override string get_ns() { return NS_URI; }