2017-03-02 14:37:32 +00:00
|
|
|
using Gee;
|
|
|
|
|
|
|
|
using Dino.Entities;
|
|
|
|
using Xmpp;
|
|
|
|
|
|
|
|
namespace Dino {
|
|
|
|
|
|
|
|
public class ModuleManager {
|
2018-11-24 20:00:44 +00:00
|
|
|
private HashMap<Account, ArrayList<XmppStreamModule>> module_map = new HashMap<Account, ArrayList<XmppStreamModule>>(Account.hash_func, Account.equals_func);
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2018-01-12 20:03:09 +00:00
|
|
|
public signal void initialize_account_modules(Account account, ArrayList<XmppStreamModule> modules);
|
2017-03-10 20:45:56 +00:00
|
|
|
|
2018-01-12 20:03:09 +00:00
|
|
|
public T? get_module<T>(Account account, Xmpp.ModuleIdentity<T> identity) {
|
2017-03-10 20:45:56 +00:00
|
|
|
if (identity == null) return null;
|
|
|
|
lock (module_map) {
|
|
|
|
if (!module_map.has_key(account)) {
|
|
|
|
initialize(account);
|
|
|
|
}
|
|
|
|
var res = module_map[account].filter((module) => identity.matches(module));
|
|
|
|
if (res != null && res.next()) {
|
|
|
|
return identity.cast(res.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-01-12 20:03:09 +00:00
|
|
|
public ArrayList<XmppStreamModule> get_modules(Account account, string? resource = null) {
|
|
|
|
ArrayList<XmppStreamModule> modules = new ArrayList<XmppStreamModule>();
|
2017-06-20 23:07:06 +00:00
|
|
|
|
2017-03-10 20:45:56 +00:00
|
|
|
lock (module_map) {
|
2017-04-08 09:53:10 +00:00
|
|
|
if (!module_map.has_key(account)) initialize(account);
|
2018-01-12 20:03:09 +00:00
|
|
|
foreach (XmppStreamModule module in module_map[account]) modules.add(module);
|
2017-03-10 20:45:56 +00:00
|
|
|
}
|
2017-08-12 21:14:50 +00:00
|
|
|
|
2018-01-12 20:03:09 +00:00
|
|
|
foreach (XmppStreamModule module in module_map[account]) {
|
2017-08-12 21:14:50 +00:00
|
|
|
if (module.get_id() == Bind.Module.IDENTITY.id) {
|
2018-03-10 18:46:08 +00:00
|
|
|
(module as Bind.Module).requested_resource = resource ?? account.resourcepart;
|
2018-08-19 17:56:46 +00:00
|
|
|
} else if (module.get_id() == Sasl.Module.IDENTITY.id) {
|
|
|
|
(module as Sasl.Module).password = account.password;
|
2017-08-12 21:14:50 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
return modules;
|
|
|
|
}
|
|
|
|
|
2017-03-10 20:45:56 +00:00
|
|
|
public void initialize(Account account) {
|
|
|
|
lock(module_map) {
|
2018-01-12 20:03:09 +00:00
|
|
|
module_map[account] = new ArrayList<XmppStreamModule>();
|
2017-08-12 21:14:50 +00:00
|
|
|
module_map[account].add(new Iq.Module());
|
2017-03-10 20:45:56 +00:00
|
|
|
module_map[account].add(new Tls.Module());
|
2017-08-09 18:44:15 +00:00
|
|
|
module_map[account].add(new Xep.SrvRecordsTls.Module());
|
2018-08-19 17:56:46 +00:00
|
|
|
module_map[account].add(new Sasl.Module(account.bare_jid.to_string(), account.password));
|
2017-08-12 21:14:50 +00:00
|
|
|
module_map[account].add(new Xep.StreamManagement.Module());
|
|
|
|
module_map[account].add(new Bind.Module(account.resourcepart));
|
2017-06-20 23:07:06 +00:00
|
|
|
module_map[account].add(new Session.Module());
|
2017-03-10 20:45:56 +00:00
|
|
|
module_map[account].add(new Roster.Module());
|
2020-03-29 18:23:47 +00:00
|
|
|
module_map[account].add(new Xep.ServiceDiscovery.Module.with_identity("client", "pc", "Dino"));
|
2017-03-10 20:45:56 +00:00
|
|
|
module_map[account].add(new Xep.PrivateXmlStorage.Module());
|
|
|
|
module_map[account].add(new Xep.Bookmarks.Module());
|
2019-09-28 19:40:43 +00:00
|
|
|
module_map[account].add(new Xep.Bookmarks2.Module());
|
2017-03-10 20:45:56 +00:00
|
|
|
module_map[account].add(new Presence.Module());
|
2018-01-12 20:03:09 +00:00
|
|
|
module_map[account].add(new Xmpp.MessageModule());
|
2017-08-16 09:44:42 +00:00
|
|
|
module_map[account].add(new Xep.MessageArchiveManagement.Module());
|
2017-03-10 20:45:56 +00:00
|
|
|
module_map[account].add(new Xep.MessageCarbons.Module());
|
|
|
|
module_map[account].add(new Xep.Muc.Module());
|
|
|
|
module_map[account].add(new Xep.Pubsub.Module());
|
|
|
|
module_map[account].add(new Xep.MessageDeliveryReceipts.Module());
|
2017-10-05 19:04:39 +00:00
|
|
|
module_map[account].add(new Xep.BlockingCommand.Module());
|
2017-03-10 20:45:56 +00:00
|
|
|
module_map[account].add(new Xep.ChatStateNotifications.Module());
|
|
|
|
module_map[account].add(new Xep.ChatMarkers.Module());
|
|
|
|
module_map[account].add(new Xep.Ping.Module());
|
|
|
|
module_map[account].add(new Xep.DelayedDelivery.Module());
|
|
|
|
module_map[account].add(new StreamError.Module());
|
2018-08-19 22:27:02 +00:00
|
|
|
module_map[account].add(new Xep.InBandRegistration.Module());
|
2018-11-14 17:17:10 +00:00
|
|
|
module_map[account].add(new Xep.HttpFileUpload.Module());
|
2019-07-20 21:14:40 +00:00
|
|
|
module_map[account].add(new Xep.Socks5Bytestreams.Module());
|
2019-06-23 12:53:18 +00:00
|
|
|
module_map[account].add(new Xep.InBandBytestreams.Module());
|
|
|
|
module_map[account].add(new Xep.Jingle.Module());
|
2019-07-20 21:14:40 +00:00
|
|
|
module_map[account].add(new Xep.JingleSocks5Bytestreams.Module());
|
2019-06-23 12:53:18 +00:00
|
|
|
module_map[account].add(new Xep.JingleInBandBytestreams.Module());
|
|
|
|
module_map[account].add(new Xep.JingleFileTransfer.Module());
|
2019-09-10 18:56:00 +00:00
|
|
|
module_map[account].add(new Xep.Jet.Module());
|
2017-03-10 20:45:56 +00:00
|
|
|
initialize_account_modules(account, module_map[account]);
|
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-20 23:07:06 +00:00
|
|
|
}
|