aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/xep
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-06-13 18:14:59 +0200
committerfiaxh <git@mx.ax.lt>2017-06-13 20:12:40 +0200
commit7bbbb738fdb233f4ad91ffdd7d9247b28849d715 (patch)
tree649ac26e3feef6bae614442a7f3d6ee1057336e0 /xmpp-vala/src/module/xep
parentdabc2a8b1d2a7bf2019e5f913c736d80f11ceb53 (diff)
downloaddino-7bbbb738fdb233f4ad91ffdd7d9247b28849d715.tar.gz
dino-7bbbb738fdb233f4ad91ffdd7d9247b28849d715.zip
Get rid of manual storage objects for delegates
Diffstat (limited to 'xmpp-vala/src/module/xep')
-rw-r--r--xmpp-vala/src/module/xep/0004_data_forms.vala19
-rw-r--r--xmpp-vala/src/module/xep/0030_service_discovery/module.vala29
-rw-r--r--xmpp-vala/src/module/xep/0045_muc/module.vala58
-rw-r--r--xmpp-vala/src/module/xep/0048_bookmarks/module.vala57
-rw-r--r--xmpp-vala/src/module/xep/0049_private_xml_storage.vala26
-rw-r--r--xmpp-vala/src/module/xep/0054_vcard/module.vala5
-rw-r--r--xmpp-vala/src/module/xep/0060_pubsub.vala43
-rw-r--r--xmpp-vala/src/module/xep/0084_user_avatars.vala10
-rw-r--r--xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala10
-rw-r--r--xmpp-vala/src/module/xep/0199_ping.vala14
10 files changed, 114 insertions, 157 deletions
diff --git a/xmpp-vala/src/module/xep/0004_data_forms.vala b/xmpp-vala/src/module/xep/0004_data_forms.vala
index add2fa9a..a0e8cd43 100644
--- a/xmpp-vala/src/module/xep/0004_data_forms.vala
+++ b/xmpp-vala/src/module/xep/0004_data_forms.vala
@@ -13,17 +13,16 @@ public class DataForm {
public XmppStream stream;
public OnResult on_result;
- public Object? store;
public void cancel() {
StanzaNode stanza_node = new StanzaNode.build("x", NS_URI);
stanza_node.add_self_xmlns().set_attribute("type", "cancel");
- on_result(stream, stanza_node, store);
+ on_result(stream, stanza_node);
}
public void submit() {
stanza_node.set_attribute("type", "submit");
- on_result(stream, stanza_node, store);
+ on_result(stream, stanza_node);
}
public enum Type {
@@ -170,11 +169,11 @@ public class DataForm {
// TODO text-multi
- internal DataForm(StanzaNode node, XmppStream stream, OnResult on_result, Object? store) {
+ internal DataForm(StanzaNode node, XmppStream stream, owned OnResult listener) {
this.stanza_node = node;
this.stream = stream;
- this.on_result = on_result;
- this.store = store;
+ this.on_result = (owned)listener;
+
Gee.List<StanzaNode> field_nodes = node.get_subnodes("field", NS_URI);
foreach (StanzaNode field_node in field_nodes) {
string? type = field_node.get_attribute("type", NS_URI);
@@ -199,10 +198,10 @@ public class DataForm {
}
}
- [CCode (has_target = false)] public delegate void OnResult(XmppStream stream, StanzaNode node, Object? store);
- public static DataForm? create(XmppStream stream, StanzaNode node, OnResult on_result, Object? store) {
- return new DataForm(node, stream, on_result, store);
+ public delegate void OnResult(XmppStream stream, StanzaNode node);
+ public static DataForm? create(XmppStream stream, StanzaNode node, owned OnResult listener) {
+ return new DataForm(node, stream, (owned)listener);
}
}
-} \ No newline at end of file
+}
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 2ec0f630..d8852735 100644
--- a/xmpp-vala/src/module/xep/0030_service_discovery/module.vala
+++ b/xmpp-vala/src/module/xep/0030_service_discovery/module.vala
@@ -29,32 +29,29 @@ public class Module : XmppStreamModule, Iq.Handler {
identities.add(new Identity(category, type, name));
}
- [CCode (has_target = false)] public delegate void HasEntryCategoryRes(XmppStream stream, ArrayList<Identity>? identities, Object? store);
- public void get_entity_categories(XmppStream stream, string jid, HasEntryCategoryRes on_result, Object? store) {
+ public delegate void HasEntryCategoryRes(XmppStream stream, ArrayList<Identity>? identities);
+ public void get_entity_categories(XmppStream stream, string jid, owned HasEntryCategoryRes listener) {
ArrayList<Identity>? res = stream.get_flag(Flag.IDENTITY).get_entity_categories(jid);
- if (res != null) on_result(stream, res, store);
- request_info(stream, jid, (stream, query_result, store) => {
- Tuple<HasEntryCategoryRes, Object> tuple = store as Tuple<HasEntryCategoryRes, Object>;
- tuple.a(stream, query_result != null ? query_result.identities : null, tuple.b);
- }, Tuple.create(on_result, store));
+ if (res != null) listener(stream, res);
+ request_info(stream, jid, (stream, query_result) => {
+ listener(stream, query_result != null ? query_result.identities : null);
+ });
}
- [CCode (has_target = false)] public delegate void OnInfoResult(XmppStream stream, InfoResult? query_result, Object? store);
- public void request_info(XmppStream stream, string jid, OnInfoResult listener, Object? store) {
+ public delegate void OnInfoResult(XmppStream stream, InfoResult? query_result);
+ public void request_info(XmppStream stream, string jid, owned OnInfoResult listener) {
Iq.Stanza iq = new Iq.Stanza.get(new StanzaNode.build("query", NS_URI_INFO).add_self_xmlns());
iq.to = jid;
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream, iq, o) => {
- Tuple<OnInfoResult, Object> tuple = o as Tuple<OnInfoResult, Object>;
- OnInfoResult on_result = tuple.a;
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream, iq) => {
InfoResult? result = InfoResult.create_from_iq(iq);
stream.get_flag(Flag.IDENTITY).set_entity_features(iq.from, result != null ? result.features : null);
stream.get_flag(Flag.IDENTITY).set_entity_identities(iq.from, result != null ? result.identities : null);
- on_result(stream, result, tuple.b);
- }, Tuple.create(listener, store));
+ listener(stream, result);
+ });
}
- [CCode (has_target = false)] public delegate void OnItemsResult(XmppStream stream, ItemsResult query_result);
- public void request_items(XmppStream stream, string jid, OnItemsResult listener, Object? store) {
+ public delegate void OnItemsResult(XmppStream stream, ItemsResult query_result);
+ public void request_items(XmppStream stream, string jid, owned OnItemsResult listener) {
Iq.Stanza iq = new Iq.Stanza.get(new StanzaNode.build("query", NS_URI_ITEMS).add_self_xmlns());
iq.to = jid;
stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq);
diff --git a/xmpp-vala/src/module/xep/0045_muc/module.vala b/xmpp-vala/src/module/xep/0045_muc/module.vala
index 79870ee1..82a7d7a6 100644
--- a/xmpp-vala/src/module/xep/0045_muc/module.vala
+++ b/xmpp-vala/src/module/xep/0045_muc/module.vala
@@ -136,17 +136,22 @@ public class Module : XmppStreamModule {
return true;
}
- [CCode (has_target = false)] public delegate void OnConfigFormResult(XmppStream stream, string jid, DataForms.DataForm data_form, Object? store);
- public void get_config_form(XmppStream stream, string jid, OnConfigFormResult listener, Object? store) {
- Iq.Stanza iq = new Iq.Stanza.get(new StanzaNode.build("query", NS_URI_OWNER).add_self_xmlns()) { to=jid };
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream, iq, store) => {
- Tuple<OnConfigFormResult, Object?> tuple = store as Tuple<OnConfigFormResult, Object?>;
- StanzaNode? x_node = iq.stanza.get_deep_subnode(NS_URI_OWNER + ":query", DataForms.NS_URI + ":x");
+ public delegate void OnConfigFormResult(XmppStream stream, string jid, DataForms.DataForm data_form);
+ public void get_config_form(XmppStream stream, string jid, owned OnConfigFormResult listener) {
+ Iq.Stanza get_iq = new Iq.Stanza.get(new StanzaNode.build("query", NS_URI_OWNER).add_self_xmlns()) { to=jid };
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, get_iq, (stream, form_iq) => {
+ StanzaNode? x_node = form_iq.stanza.get_deep_subnode(NS_URI_OWNER + ":query", DataForms.NS_URI + ":x");
if (x_node != null) {
- DataForms.DataForm data_form = DataForms.DataForm.create(stream, x_node, on_config_form_result, iq);
- tuple.a(stream, iq.from, data_form, tuple.b);
+ DataForms.DataForm data_form = DataForms.DataForm.create(stream, x_node, (stream, node) => {
+ StanzaNode stanza_node = new StanzaNode.build("query", NS_URI_OWNER);
+ stanza_node.add_self_xmlns().put_node(node);
+ Iq.Stanza set_iq = new Iq.Stanza.set(stanza_node);
+ set_iq.to = form_iq.from;
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, set_iq);
+ });
+ listener(stream, form_iq.from, data_form);
}
- }, Tuple.create(listener, store));
+ });
}
public override void attach(XmppStream stream) {
@@ -162,9 +167,9 @@ public class Module : XmppStreamModule {
}
room_entered.connect((stream, jid, nick) => {
- query_affiliation(stream, jid, "member", null, null);
- query_affiliation(stream, jid, "admin", null, null);
- query_affiliation(stream, jid, "owner", null, null);
+ query_affiliation(stream, jid, "member", null);
+ query_affiliation(stream, jid, "admin", null);
+ query_affiliation(stream, jid, "owner", null);
});
}
@@ -208,9 +213,7 @@ public class Module : XmppStreamModule {
string bare_jid = get_bare_jid(presence.from);
ErrorStanza? error_stanza = presence.get_error();
if (flag.get_enter_id(bare_jid) == presence.id) {
- print("is enter id\n");
MucEnterError? error = null;
- print(@"$(error_stanza.condition) $(error_stanza.type_)\n");
switch (error_stanza.condition) {
case ErrorStanza.CONDITION_NOT_AUTHORIZED:
if (ErrorStanza.TYPE_AUTH == error_stanza.type_) error = MucEnterError.PASSWORD_REQUIRED;
@@ -305,8 +308,7 @@ public class Module : XmppStreamModule {
}
private void query_room_info(XmppStream stream, string jid) {
- stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, jid, (stream, query_result, store) => {
- Tuple<string, string> tuple = store as Tuple<string, string>;
+ stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, jid, (stream, query_result) => {
Gee.List<Feature> features = new ArrayList<Feature>();
if (query_result != null) {
@@ -333,20 +335,19 @@ public class Module : XmppStreamModule {
if (parsed != null) features.add(parsed);
}
}
- stream.get_flag(Flag.IDENTITY).set_room_features(tuple.a, features);
- }, Tuple.create(jid, "")); //TODO ugly
+ stream.get_flag(Flag.IDENTITY).set_room_features(jid, features);
+ });
}
- [CCode (has_target = false)] public delegate void OnAffiliationResult(XmppStream stream, Gee.List<string> jids, Object? store);
- private void query_affiliation(XmppStream stream, string jid, string affiliation, OnAffiliationResult? on_result, Object? store) {
+ public delegate void OnAffiliationResult(XmppStream stream, Gee.List<string> jids);
+ private void query_affiliation(XmppStream stream, string jid, string affiliation, owned OnAffiliationResult? listener) {
Iq.Stanza iq = new Iq.Stanza.get(
new StanzaNode.build("query", NS_URI_ADMIN)
.add_self_xmlns()
.put_node(new StanzaNode.build("item", NS_URI_ADMIN)
.put_attribute("affiliation", affiliation))
) { to=jid };
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream, iq, store) => {
- Tuple<OnAffiliationResult?, Object?> tuple = store as Tuple<OnAffiliationResult?, Object?>;
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream, iq) => {
if (iq.is_error()) return;
StanzaNode? query_node = iq.stanza.get_subnode("query", NS_URI_ADMIN);
if (query_node == null) return;
@@ -360,17 +361,8 @@ public class Module : XmppStreamModule {
ret_jids.add(jid_);
}
}
- if (tuple.a != null) tuple.a(stream, ret_jids, tuple.b);
- }, Tuple.create(on_result, store));
- }
-
- public static void on_config_form_result(XmppStream stream, StanzaNode node, Object? store) {
- Iq.Stanza form_iq = store as Iq.Stanza;
- StanzaNode stanza_node = new StanzaNode.build("query", NS_URI_OWNER);
- stanza_node.add_self_xmlns().put_node(node);
- Iq.Stanza set_iq = new Iq.Stanza.set(stanza_node);
- set_iq.to = form_iq.from;
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, set_iq);
+ if (listener != null) listener(stream, ret_jids);
+ });
}
private static ArrayList<int> get_status_codes(StanzaNode x_node) {
diff --git a/xmpp-vala/src/module/xep/0048_bookmarks/module.vala b/xmpp-vala/src/module/xep/0048_bookmarks/module.vala
index 3612ac4b..6f42621a 100644
--- a/xmpp-vala/src/module/xep/0048_bookmarks/module.vala
+++ b/xmpp-vala/src/module/xep/0048_bookmarks/module.vala
@@ -10,15 +10,13 @@ public class Module : XmppStreamModule {
public signal void received_conferences(XmppStream stream, Gee.List<Conference> conferences);
- [CCode (has_target = false)] public delegate void OnResult(XmppStream stream, Gee.List<Conference> conferences, Object? storage);
- public void get_conferences(XmppStream stream, OnResult listener, Object? store) {
+ public delegate void OnResult(XmppStream stream, Gee.List<Conference> conferences);
+ public void get_conferences(XmppStream stream, owned OnResult listener) {
StanzaNode get_node = new StanzaNode.build("storage", NS_URI).add_self_xmlns();
- stream.get_module(PrivateXmlStorage.Module.IDENTITY).retrieve(stream, get_node, (stream, node, o) => {
- Tuple<OnResult, Object?> tuple = o as Tuple<OnResult, Object?>;
- OnResult on_result = tuple.a;
+ stream.get_module(PrivateXmlStorage.Module.IDENTITY).retrieve(stream, get_node, (stream, node) => {
Gee.List<Conference> conferences = get_conferences_from_stanza(node);
- on_result(stream, conferences, tuple.b);
- }, Tuple.create(listener, store));
+ listener(stream, conferences);
+ });
}
public void set_conferences(XmppStream stream, Gee.List<Conference> conferences) {
@@ -26,51 +24,46 @@ public class Module : XmppStreamModule {
foreach (Conference conference in conferences) {
storage_node.put_node(conference.stanza_node);
}
- stream.get_module(PrivateXmlStorage.Module.IDENTITY).store(stream, storage_node, (stream, o) => {
- stream.get_module(Module.IDENTITY).received_conferences(stream, o as ArrayList<Conference>);
- }, conferences);
+ stream.get_module(PrivateXmlStorage.Module.IDENTITY).store(stream, storage_node, (stream) => {
+ stream.get_module(Module.IDENTITY).received_conferences(stream, conferences);
+ });
}
- public void add_conference(XmppStream stream, Conference add_) {
- get_conferences(stream, (stream, conferences, o) => {
- Conference add = o as Conference;
- conferences.add(add);
+ public void add_conference(XmppStream stream, Conference conference) {
+ get_conferences(stream, (stream, conferences) => {
+ conferences.add(conference);
stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
- }, add_);
+ });
}
- public void replace_conference(XmppStream stream, Conference was_, Conference modified_) {
- get_conferences(stream, (stream, conferences, o) => {
- Tuple<Conference, Conference> tuple = o as Tuple<Conference, Conference>;
- Conference was = tuple.a;
- Conference modified = tuple.b;
+ public void replace_conference(XmppStream stream, Conference orig_conference, Conference modified_conference) {
+ get_conferences(stream, (stream, conferences) => {
foreach (Conference conference in conferences) {
- if (conference.autojoin == was.autojoin && conference.jid == was.jid &&
- conference.name == was.name && conference.nick == was.nick) {
- conference.autojoin = modified.autojoin;
- conference.jid = modified.jid;
- conference.name = modified.name;
- conference.nick = modified.nick;
+ if (conference.autojoin == orig_conference.autojoin && conference.jid == orig_conference.jid &&
+ conference.name == orig_conference.name && conference.nick == orig_conference.nick) {
+ conference.autojoin = modified_conference.autojoin;
+ conference.jid = modified_conference.jid;
+ conference.name = modified_conference.name;
+ conference.nick = modified_conference.nick;
break;
}
}
stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
- }, Tuple.create(was_, modified_));
+ });
}
- public void remove_conference(XmppStream stream, Conference conference_) {
- get_conferences(stream, (stream, conferences, o) => {
- Conference remove = o as Conference;
+ public void remove_conference(XmppStream stream, Conference conference_remove) {
+ get_conferences(stream, (stream, conferences) => {
Conference? rem = null;
foreach (Conference conference in conferences) {
- if (conference.name == remove.name && conference.jid == remove.jid && conference.autojoin == remove.autojoin) {
+ if (conference.name == conference_remove.name && conference.jid == conference_remove.jid && conference.autojoin == conference_remove.autojoin) {
rem = conference;
break;
}
}
if (rem != null) conferences.remove(rem);
stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
- }, conference_);
+ });
}
public override void attach(XmppStream stream) { }
diff --git a/xmpp-vala/src/module/xep/0049_private_xml_storage.vala b/xmpp-vala/src/module/xep/0049_private_xml_storage.vala
index fc8f5b4c..26a297b4 100644
--- a/xmpp-vala/src/module/xep/0049_private_xml_storage.vala
+++ b/xmpp-vala/src/module/xep/0049_private_xml_storage.vala
@@ -8,18 +8,22 @@ namespace Xmpp.Xep.PrivateXmlStorage {
public class Module : XmppStreamModule {
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0049_private_xml_storage");
- [CCode (has_target = false)] public delegate void OnSuccess(XmppStream stream, Object? reference);
- public void store(XmppStream stream, StanzaNode node, OnSuccess listener, Object? reference) {
+ public delegate void OnSuccess(XmppStream stream);
+ public void store(XmppStream stream, StanzaNode node, owned OnSuccess listener) {
StanzaNode queryNode = new StanzaNode.build("query", NS_URI).add_self_xmlns().put_node(node);
Iq.Stanza iq = new Iq.Stanza.set(queryNode);
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_store_response, Tuple.create(listener, reference));
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream, iq) => {
+ listener(stream);
+ });
}
- [CCode (has_target = false)] public delegate void OnResponse(XmppStream stream, StanzaNode node, Object? reference);
- public void retrieve(XmppStream stream, StanzaNode node, OnResponse listener, Object? reference) {
+ public delegate void OnResponse(XmppStream stream, StanzaNode node);
+ public void retrieve(XmppStream stream, StanzaNode node, owned OnResponse listener) {
StanzaNode queryNode = new StanzaNode.build("query", NS_URI).add_self_xmlns().put_node(node);
Iq.Stanza iq = new Iq.Stanza.get(queryNode);
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_retrieve_response, Tuple.create(listener, reference));
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream, iq) => {
+ listener(stream, iq.stanza.get_subnode("query", NS_URI));
+ });
}
public override void attach(XmppStream stream) {
@@ -34,15 +38,5 @@ namespace Xmpp.Xep.PrivateXmlStorage {
public override string get_ns() { return NS_URI; }
public override string get_id() { return IDENTITY.id; }
-
- private static void on_store_response(XmppStream stream, Iq.Stanza iq, Object? o) {
- Tuple<OnSuccess, Object> tuple = o as Tuple<OnSuccess, Object>;
- tuple.a(stream, tuple.b);
- }
-
- private static void on_retrieve_response(XmppStream stream, Iq.Stanza iq, Object? o) {
- Tuple<OnResponse, Object> tuple = o as Tuple<OnResponse, Object>;
- tuple.a(stream, iq.stanza.get_subnode("query", NS_URI), tuple.b);
- }
}
}
diff --git a/xmpp-vala/src/module/xep/0054_vcard/module.vala b/xmpp-vala/src/module/xep/0054_vcard/module.vala
index 040e0646..b1ad3f48 100644
--- a/xmpp-vala/src/module/xep/0054_vcard/module.vala
+++ b/xmpp-vala/src/module/xep/0054_vcard/module.vala
@@ -52,12 +52,11 @@ public class Module : XmppStreamModule {
} else {
iq.to = get_bare_jid(presence.from);
}
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_received_vcard, storage);
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_received_vcard);
}
}
- private static void on_received_vcard(XmppStream stream, Iq.Stanza iq, Object? storage_obj) {
- PixbufStorage? storage = storage_obj as PixbufStorage;
+ private void on_received_vcard(XmppStream stream, Iq.Stanza iq) {
if (iq.is_error()) return;
string? res = iq.stanza.get_deep_string_content(@"$NS_URI:vCard", "PHOTO", "BINVAL");
if (res == null) return;
diff --git a/xmpp-vala/src/module/xep/0060_pubsub.vala b/xmpp-vala/src/module/xep/0060_pubsub.vala
index 8ba66995..182e6ffe 100644
--- a/xmpp-vala/src/module/xep/0060_pubsub.vala
+++ b/xmpp-vala/src/module/xep/0060_pubsub.vala
@@ -11,16 +11,22 @@ namespace Xmpp.Xep.Pubsub {
private HashMap<string, EventListenerDelegate> event_listeners = new HashMap<string, EventListenerDelegate>();
- public void add_filtered_notification(XmppStream stream, string node, EventListenerDelegate.ResultFunc on_result, Object? reference = null) {
+ public void add_filtered_notification(XmppStream stream, string node, owned EventListenerDelegate.ResultFunc listener) {
stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature_notify(stream, node);
- event_listeners[node] = new EventListenerDelegate(on_result, reference);
+ event_listeners[node] = new EventListenerDelegate((owned)listener);
}
- [CCode (has_target = false)] public delegate void OnResult(XmppStream stream, string jid, string? id, StanzaNode? node, Object? storage);
- public void request(XmppStream stream, string jid, string node, OnResult listener, Object? store) { // TODO multiple nodes gehen auch
- Iq.Stanza a = new Iq.Stanza.get(new StanzaNode.build("pubsub", NS_URI).add_self_xmlns().put_node(new StanzaNode.build("items", NS_URI).put_attribute("node", node)));
- a.to = jid;
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, a, on_received_request_response, Tuple.create(listener, store));
+ public delegate void OnResult(XmppStream stream, string jid, string? id, StanzaNode? node);
+ public void request(XmppStream stream, string jid, string node, owned OnResult listener) { // TODO multiple nodes gehen auch
+ Iq.Stanza request_iq = new Iq.Stanza.get(new StanzaNode.build("pubsub", NS_URI).add_self_xmlns().put_node(new StanzaNode.build("items", NS_URI).put_attribute("node", node)));
+ request_iq.to = jid;
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, request_iq, (stream, iq) => {
+ StanzaNode event_node = iq.stanza.get_subnode("pubsub", NS_URI);
+ StanzaNode items_node = event_node != null ? event_node.get_subnode("items", NS_URI) : null;
+ StanzaNode item_node = items_node != null ? items_node.get_subnode("item", NS_URI) : null;
+ string? id = item_node != null ? item_node.get_attribute("id", NS_URI) : null;
+ listener(stream, iq.from, id, item_node != null ? item_node.sub_nodes[0] : null);
+ });
}
public void publish(XmppStream stream, string? jid, string node_id, string node, string item_id, StanzaNode content) {
@@ -59,30 +65,17 @@ namespace Xmpp.Xep.Pubsub {
string node = items_node.get_attribute("node", NS_URI_EVENT);
string id = item_node.get_attribute("id", NS_URI_EVENT);
if (event_listeners.has_key(node)) {
- event_listeners[node].on_result(stream, message.from, id, item_node.sub_nodes[0], event_listeners[node].reference);
+ event_listeners[node].on_result(stream, message.from, id, item_node.sub_nodes[0]);
}
}
-
- private static void on_received_request_response(XmppStream stream, Iq.Stanza iq, Object? o) {
- Tuple<OnResult, Object?> tuple = o as Tuple<OnResult, Object?>;
- OnResult on_result = tuple.a;
- StanzaNode event_node = iq.stanza.get_subnode("pubsub", NS_URI);
- StanzaNode items_node = event_node != null ? event_node.get_subnode("items", NS_URI) : null;
- StanzaNode item_node = items_node != null ? items_node.get_subnode("item", NS_URI) : null;
- string? id = item_node != null ? item_node.get_attribute("id", NS_URI) : null;
- on_result(stream, iq.from, id, item_node != null ? item_node.sub_nodes[0] : null, tuple.b);
- }
}
public class EventListenerDelegate {
- [CCode (has_target = false)]
- public delegate void ResultFunc(XmppStream stream, string jid, string id, StanzaNode node, Object? object);
- public ResultFunc on_result { get; private set; }
- public Object? reference { get; private set; }
+ public delegate void ResultFunc(XmppStream stream, string jid, string id, StanzaNode? node);
+ public ResultFunc on_result { get; private owned set; }
- public EventListenerDelegate(ResultFunc on_result, Object? reference = null) {
- this.on_result = on_result;
- this.reference = reference;
+ public EventListenerDelegate(owned ResultFunc on_result) {
+ this.on_result = (owned) on_result;
}
}
}
diff --git a/xmpp-vala/src/module/xep/0084_user_avatars.vala b/xmpp-vala/src/module/xep/0084_user_avatars.vala
index f9bf057f..3648a88b 100644
--- a/xmpp-vala/src/module/xep/0084_user_avatars.vala
+++ b/xmpp-vala/src/module/xep/0084_user_avatars.vala
@@ -35,20 +35,19 @@ namespace Xmpp.Xep.UserAvatars {
public override void attach(XmppStream stream) {
Pubsub.Module.require(stream);
- stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NS_URI_METADATA, on_event_result, storage);
+ stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NS_URI_METADATA, on_pupsub_event);
}
public override void detach(XmppStream stream) { }
- public static void on_event_result(XmppStream stream, string jid, string id, StanzaNode node, Object? obj) {
- PixbufStorage? storage = obj as PixbufStorage;
+ public void on_pupsub_event(XmppStream stream, string jid, string id, StanzaNode? node) {
StanzaNode? info_node = node.get_subnode("info", NS_URI_METADATA);
if (info_node == null || info_node.get_attribute("type") != "image/png") return;
if (storage.has_image(id)) {
stream.get_module(Module.IDENTITY).received_avatar(stream, jid, id);
} else {
- stream.get_module(Pubsub.Module.IDENTITY).request(stream, jid, NS_URI_DATA, on_pubsub_data_response, storage);
+ stream.get_module(Pubsub.Module.IDENTITY).request(stream, jid, NS_URI_DATA, on_pubsub_data_response);
}
}
@@ -59,9 +58,8 @@ namespace Xmpp.Xep.UserAvatars {
public override string get_ns() { return NS_URI; }
public override string get_id() { return IDENTITY.id; }
- private static void on_pubsub_data_response(XmppStream stream, string jid, string? id, StanzaNode? node, Object? o) {
+ private void on_pubsub_data_response(XmppStream stream, string jid, string? id, StanzaNode? node) {
if (node == null) return;
- PixbufStorage storage = o as PixbufStorage;
storage.store(id, Base64.decode(node.get_string_content()));
stream.get_module(Module.IDENTITY).received_avatar(stream, jid, id);
}
diff --git a/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala b/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala
index a3f0a704..6f19fb12 100644
--- a/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala
+++ b/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala
@@ -57,20 +57,20 @@ namespace Xmpp.Xep.EntityCapabilities {
string ver_attribute = c_node.get_attribute("ver", NS_URI);
ArrayList<string> capabilities = storage.get_features(ver_attribute);
if (capabilities.size == 0) {
- stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, presence.from, on_received_info_response, Tuple.create(storage, ver_attribute));
+ stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, presence.from, (stream, query_result) => {
+ store_entity_result(stream, ver_attribute, query_result);
+ });
} else {
stream.get_flag(ServiceDiscovery.Flag.IDENTITY).set_entity_features(presence.from, capabilities);
}
}
}
- private static void on_received_info_response(XmppStream stream, ServiceDiscovery.InfoResult? query_result, Object? store) {
+ private void store_entity_result(XmppStream stream, string entity, ServiceDiscovery.InfoResult? query_result) {
if (query_result == null) return;
- Tuple<Storage, string> tuple = store as Tuple<Storage, string>;
- Storage storage = tuple.a;
- string entity = tuple.b;
if (compute_hash(query_result.identities, query_result.features) == entity) {
storage.store_features(entity, query_result.features);
+ stream.get_flag(ServiceDiscovery.Flag.IDENTITY).set_entity_features(query_result.iq.from, query_result.features);
}
}
diff --git a/xmpp-vala/src/module/xep/0199_ping.vala b/xmpp-vala/src/module/xep/0199_ping.vala
index 6cb3b4ba..3a5c6797 100644
--- a/xmpp-vala/src/module/xep/0199_ping.vala
+++ b/xmpp-vala/src/module/xep/0199_ping.vala
@@ -8,10 +8,11 @@ namespace Xmpp.Xep.Ping {
public class Module : XmppStreamModule {
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0199_ping");
- public void send_ping(XmppStream stream, string jid, ResponseListener? listener) {
+ public delegate void OnResult(XmppStream stream);
+ public void send_ping(XmppStream stream, string jid, owned OnResult? listener) {
Iq.Stanza iq = new Iq.Stanza.get(new StanzaNode.build("ping", NS_URI).add_self_xmlns());
iq.to = jid;
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_ping_response, listener);
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream) => { listener(stream); });
}
public override void attach(XmppStream stream) {
@@ -34,14 +35,5 @@ namespace Xmpp.Xep.Ping {
}
public void on_iq_set(XmppStream stream, Iq.Stanza iq) { }
}
-
- private static void on_ping_response(XmppStream stream, Iq.Stanza iq, Object? o) {
- ResponseListener? listener = o as ResponseListener;
- if (listener != null) listener.on_result(stream);
- }
- }
-
- public interface ResponseListener : Object {
- public abstract void on_result(XmppStream stream);
}
}