Add typed identity to stream modules
This commit is contained in:
parent
29ca70a6d5
commit
9cdc3619bd
|
@ -126,9 +126,10 @@ public class XmppStream {
|
|||
foreach (XmppStreamModule module in modules) module.detach(this);
|
||||
}
|
||||
|
||||
public XmppStreamModule? get_module(string ns, string id) {
|
||||
public T? get_module<T>(ModuleIdentity<T>? identity) {
|
||||
if (identity == null) return null;
|
||||
foreach (var module in modules) {
|
||||
if (module.get_ns() == ns && module.get_id() == id) {
|
||||
if (module.get_ns() == identity.ns && module.get_id() == identity.id) {
|
||||
return module;
|
||||
}
|
||||
}
|
||||
|
@ -231,6 +232,20 @@ public abstract class XmppStreamFlag {
|
|||
public abstract string get_id();
|
||||
}
|
||||
|
||||
public class ModuleIdentity<T> : Object {
|
||||
public string ns { get; private set; }
|
||||
public string id { get; private set; }
|
||||
|
||||
public ModuleIdentity(string ns, string id) {
|
||||
this.ns = ns;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public T? cast(XmppStreamModule module) {
|
||||
return (T?) module;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class XmppStreamModule : Object {
|
||||
public abstract void attach(XmppStream stream);
|
||||
public abstract void detach(XmppStream stream);
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace Xmpp.Bind {
|
|||
/** The parties to a stream MUST consider resource binding as mandatory-to-negotiate. (RFC6120 7.3.1) */
|
||||
public class Module : XmppStreamNegotiationModule {
|
||||
public const string ID = "bind_module";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
private string requested_resource;
|
||||
|
||||
|
@ -55,7 +56,7 @@ namespace Xmpp.Bind {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace Xmpp.Iq {
|
|||
|
||||
public class Module : XmppStreamNegotiationModule {
|
||||
public const string ID = "iq_module";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
private HashMap<string, ResponseListener> responseListeners = new HashMap<string, ResponseListener>();
|
||||
private HashMap<string, ArrayList<Handler>> namespaceRegistrants = new HashMap<string, ArrayList<Handler>>();
|
||||
|
@ -38,7 +39,7 @@ namespace Xmpp.Iq {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace Xmpp.Message {
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "message_module";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public signal void pre_send_message(XmppStream stream, Message.Stanza message);
|
||||
public signal void pre_received_message(XmppStream stream, Message.Stanza message);
|
||||
|
@ -27,7 +28,7 @@ namespace Xmpp.Message {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Xmpp.Presence {
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "presence_module";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public signal void received_presence(XmppStream stream, Presence.Stanza presence);
|
||||
public signal void pre_send_presence_stanza(XmppStream stream, Presence.Stanza presence);
|
||||
|
@ -96,7 +97,7 @@ namespace Xmpp.Presence {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace Xmpp.Roster {
|
|||
|
||||
public class Module : XmppStreamModule, Iq.Handler {
|
||||
public const string ID = "roster_module";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public signal void received_roster(XmppStream stream, Collection<Item> roster);
|
||||
public signal void item_removed(XmppStream stream, Item roster_item);
|
||||
|
@ -72,7 +73,7 @@ namespace Xmpp.Roster {
|
|||
public void on_iq_get(XmppStream stream, Iq.Stanza iq) { }
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Xmpp.PlainSasl {
|
|||
|
||||
public class Module : XmppStreamNegotiationModule {
|
||||
public const string ID = "plain_module";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
private const string MECHANISM = "PLAIN";
|
||||
|
||||
private string name;
|
||||
|
@ -89,7 +90,7 @@ namespace Xmpp.PlainSasl {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace Xmpp.StreamError {
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "stream_error_module";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public override void attach(XmppStream stream) {
|
||||
stream.received_nonza.connect(on_received_nonstanza);
|
||||
|
@ -18,7 +19,7 @@ namespace Xmpp.StreamError {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Xmpp.Tls {
|
|||
|
||||
public class Module : XmppStreamNegotiationModule {
|
||||
public const string ID = "tls_module";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public bool require { get; set; default = true; }
|
||||
public bool server_supports_tls = false;
|
||||
|
@ -67,7 +68,7 @@ namespace Xmpp.Tls {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public override bool mandatory_outstanding(XmppStream stream) {
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Xmpp.Xep.Pgp {
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "0027_current_pgp_usage";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public signal void received_jid_key_id(XmppStream stream, string jid, string key_id);
|
||||
|
||||
|
@ -52,7 +53,7 @@ namespace Xmpp.Xep.Pgp {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Xmpp.Xep.ServiceDiscovery {
|
|||
|
||||
public class Module : XmppStreamModule, Iq.Handler {
|
||||
public const string ID = "0030_service_discovery_module";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public ArrayList<Identity> identities = new ArrayList<Identity>();
|
||||
|
||||
|
@ -83,7 +84,7 @@ namespace Xmpp.Xep.ServiceDiscovery {
|
|||
public override void detach(XmppStream stream) { }
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -30,6 +30,7 @@ public enum MucEnterError {
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "0045_muc_module";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public signal void received_occupant_affiliation(XmppStream stream, string jid, string? affiliation);
|
||||
public signal void received_occupant_jid(XmppStream stream, string jid, string? real_jid);
|
||||
|
@ -97,7 +98,7 @@ public class Module : XmppStreamModule {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -7,6 +7,7 @@ private const string NS_URI = "storage:bookmarks";
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "0048_bookmarks_module";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public signal void conferences_updated(XmppStream stream, ArrayList<Conference> conferences);
|
||||
|
||||
|
@ -110,7 +111,7 @@ public class Module : XmppStreamModule {
|
|||
public override void detach(XmppStream stream) { }
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Xmpp.Xep.PrivateXmlStorage {
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "0049_private_xml_storage";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public void store(XmppStream stream, StanzaNode node, StoreResponseListener listener) {
|
||||
StanzaNode queryNode = new StanzaNode.build("query", NS_URI).add_self_xmlns().put_node(node);
|
||||
|
@ -44,7 +45,7 @@ namespace Xmpp.Xep.PrivateXmlStorage {
|
|||
public override void detach(XmppStream stream) { }
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -6,6 +6,7 @@ private const string NS_URI_UPDATE = NS_URI + ":x:update";
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "0027_current_pgp_usage";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public signal void received_avatar(XmppStream stream, string jid, string id);
|
||||
|
||||
|
@ -26,7 +27,7 @@ public class Module : XmppStreamModule {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace Xmpp.Xep.Pubsub {
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "0060_pubsub_module";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
private HashMap<string, EventListenerDelegate> event_listeners = new HashMap<string, EventListenerDelegate>();
|
||||
|
||||
|
@ -70,7 +71,7 @@ namespace Xmpp.Xep.Pubsub {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace Xmpp.Xep.UserAvatars {
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "0084_user_avatars";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public signal void received_avatar(XmppStream stream, string jid, string id);
|
||||
|
||||
|
@ -73,7 +74,7 @@ namespace Xmpp.Xep.UserAvatars {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -15,6 +15,7 @@ private const string[] STATES = {STATE_ACTIVE, STATE_INACTIVE, STATE_GONE, STATE
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "0085_chat_state_notifications";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public signal void chat_state_received(XmppStream stream, string jid, string state);
|
||||
|
||||
|
@ -42,7 +43,7 @@ public class Module : XmppStreamModule {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace Xmpp.Xep.EntityCapabilities {
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "0115_entity_capabilities";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
private string own_ver_hash;
|
||||
private Storage storage;
|
||||
|
@ -36,7 +37,7 @@ namespace Xmpp.Xep.EntityCapabilities {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace Xmpp.Xep.MessageDeliveryReceipts {
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "0184_message_delivery_receipts";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public signal void receipt_received(XmppStream stream, string jid, string id);
|
||||
|
||||
|
@ -25,7 +26,7 @@ namespace Xmpp.Xep.MessageDeliveryReceipts {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace Xmpp.Xep.Ping {
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "0199_ping";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public void send_ping(XmppStream stream, string jid, ResponseListener? listener = null) {
|
||||
Iq.Stanza iq = new Iq.Stanza.get(new StanzaNode.build("ping", NS_URI).add_self_xmlns());
|
||||
|
@ -32,7 +33,7 @@ namespace Xmpp.Xep.Ping {
|
|||
public override void detach(XmppStream stream) { }
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Xmpp.Xep.DelayedDelivery {
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "0203_delayed_delivery";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public static void set_message_delay(Message.Stanza message, DateTime datetime) {
|
||||
StanzaNode delay_node = (new StanzaNode.build("delay", NS_URI)).add_self_xmlns();
|
||||
|
@ -29,7 +30,7 @@ namespace Xmpp.Xep.DelayedDelivery {
|
|||
public override void detach(XmppStream stream) { }
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Xmpp.Xep.MessageCarbons {
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "0280_message_carbons_module";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public void enable(XmppStream stream) {
|
||||
Iq.Stanza iq = new Iq.Stanza.set(new StanzaNode.build("enable", NS_URI).add_self_xmlns());
|
||||
|
@ -33,7 +34,7 @@ namespace Xmpp.Xep.MessageCarbons {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
|
@ -13,6 +13,7 @@ private const string[] MARKERS = {MARKER_RECEIVED, MARKER_DISPLAYED, MARKER_ACKN
|
|||
|
||||
public class Module : XmppStreamModule {
|
||||
public const string ID = "0333_chat_markers";
|
||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
||||
|
||||
public signal void marker_received(XmppStream stream, string jid, string marker, string id);
|
||||
|
||||
|
@ -45,7 +46,7 @@ public class Module : XmppStreamModule {
|
|||
}
|
||||
|
||||
public static Module? get_module(XmppStream stream) {
|
||||
return (Module?) stream.get_module(NS_URI, ID);
|
||||
return (Module?) stream.get_module(IDENTITY);
|
||||
}
|
||||
|
||||
public static void require(XmppStream stream) {
|
||||
|
|
Loading…
Reference in a new issue