aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/xep
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp-vala/src/module/xep')
-rw-r--r--xmpp-vala/src/module/xep/0030_service_discovery/module.vala56
-rw-r--r--xmpp-vala/src/module/xep/0045_muc/flag.vala6
-rw-r--r--xmpp-vala/src/module/xep/0045_muc/module.vala37
-rw-r--r--xmpp-vala/src/module/xep/0048_bookmarks/conference.vala2
-rw-r--r--xmpp-vala/src/module/xep/0048_bookmarks/module.vala114
-rw-r--r--xmpp-vala/src/module/xep/0049_private_xml_storage.vala45
-rw-r--r--xmpp-vala/src/module/xep/0054_vcard/module.vala36
-rw-r--r--xmpp-vala/src/module/xep/0060_pubsub.vala47
-rw-r--r--xmpp-vala/src/module/xep/0084_user_avatars.vala33
-rw-r--r--xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala21
-rw-r--r--xmpp-vala/src/module/xep/0199_ping.vala19
11 files changed, 150 insertions, 266 deletions
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 439d825c..56df7771 100644
--- a/xmpp-vala/src/module/xep/0030_service_discovery/module.vala
+++ b/xmpp-vala/src/module/xep/0030_service_discovery/module.vala
@@ -29,40 +29,18 @@ namespace Xmpp.Xep.ServiceDiscovery {
identities.add(new Identity(category, type, name));
}
- public void request_info(XmppStream stream, string jid, InfoResponseListener response_listener) {
+ [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) {
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, new IqInfoResponseListener(response_listener));
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_request_info_response, Tuple.create(listener, store));
}
- private class IqInfoResponseListener : Iq.ResponseListener, Object {
- InfoResponseListener response_listener;
- public IqInfoResponseListener(InfoResponseListener response_listener) {
- this.response_listener = response_listener;
- }
- public void on_result(XmppStream stream, Iq.Stanza iq) {
- InfoResult? result = InfoResult.create_from_iq(iq);
- if (result != null) {
- Flag.get_flag(stream).set_entitiy_features(iq.from, result.features);
- response_listener.on_result(stream, result);
- } else {
- response_listener.on_error(stream, iq);
- }
- }
- }
-
- public void request_items(XmppStream stream, string jid, ItemsResponseListener response_listener) {
+ [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) {
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, new IqItemsResponseListener(response_listener));
- }
-
- private class IqItemsResponseListener : Iq.ResponseListener, Object {
- ItemsResponseListener response_listener;
- public IqItemsResponseListener(ItemsResponseListener response_listener) { this.response_listener = response_listener; }
- public void on_result(XmppStream stream, Iq.Stanza iq) {
- //response_listener.on_result(stream, new ServiceDiscoveryItemsResult.from_iq(iq));
- }
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq);
}
public void on_iq_get(XmppStream stream, Iq.Stanza iq) {
@@ -90,11 +68,21 @@ namespace Xmpp.Xep.ServiceDiscovery {
public override string get_ns() { return NS_URI; }
public override string get_id() { return ID; }
+ private static void on_request_info_response(XmppStream stream, Iq.Stanza iq, Object o) {
+ Tuple<OnInfoResult, Object> tuple = o as Tuple<OnInfoResult, Object>;
+ OnInfoResult on_result = tuple.a;
+ InfoResult? result = InfoResult.create_from_iq(iq);
+ if (result != null) {
+ Flag.get_flag(stream).set_entitiy_features(iq.from, result.features);
+ on_result(stream, result, tuple.b);
+ }
+ }
+
private void send_query_result(XmppStream stream, Iq.Stanza iq_request) {
InfoResult query_result = new ServiceDiscovery.InfoResult(iq_request);
query_result.features = Flag.get_flag(stream).features;
query_result.identities = identities;
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, query_result.iq, null);
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, query_result.iq);
}
}
@@ -121,14 +109,4 @@ namespace Xmpp.Xep.ServiceDiscovery {
this.node = node;
}
}
-
- public interface InfoResponseListener : Object {
- public abstract void on_result(XmppStream stream, InfoResult query_result);
- public void on_error(XmppStream stream, Iq.Stanza iq) { }
- }
-
- public interface ItemsResponseListener : Object {
- public abstract void on_result(XmppStream stream, ItemsResult query_result);
- public void on_error(XmppStream stream, Iq.Stanza iq) { }
- }
}
diff --git a/xmpp-vala/src/module/xep/0045_muc/flag.vala b/xmpp-vala/src/module/xep/0045_muc/flag.vala
index 6c1ef508..13363220 100644
--- a/xmpp-vala/src/module/xep/0045_muc/flag.vala
+++ b/xmpp-vala/src/module/xep/0045_muc/flag.vala
@@ -7,7 +7,7 @@ namespace Xmpp.Xep.Muc {
public class Flag : XmppStreamFlag {
public const string ID = "muc";
- private HashMap<string, MucEnterListener> enter_listeners = new HashMap<string, MucEnterListener>();
+ private HashMap<string, ListenerHolder> enter_listeners = new HashMap<string, ListenerHolder>();
private HashMap<string, string> enter_ids = new HashMap<string, string>();
private HashMap<string, string> own_nicks = new HashMap<string, string>();
private HashMap<string, string> subjects = new HashMap<string, string>();
@@ -32,7 +32,7 @@ public class Flag : XmppStreamFlag {
public string? get_enter_id(string bare_jid) { return enter_ids[bare_jid]; }
- public MucEnterListener? get_enter_listener(string bare_jid) { return enter_listeners[bare_jid]; }
+ public ListenerHolder? get_enter_listener(string bare_jid) { return enter_listeners[bare_jid]; }
public bool is_muc(string jid) { return own_nicks[jid] != null; }
@@ -51,7 +51,7 @@ public class Flag : XmppStreamFlag {
subjects_by[bare_jid] = full_jid;
}
- public void start_muc_enter(string bare_jid, string presence_id, MucEnterListener listener) {
+ public void start_muc_enter(string bare_jid, string presence_id, ListenerHolder listener) {
enter_listeners[bare_jid] = listener;
enter_ids[bare_jid] = presence_id;
}
diff --git a/xmpp-vala/src/module/xep/0045_muc/module.vala b/xmpp-vala/src/module/xep/0045_muc/module.vala
index 3b0c3c12..8e139799 100644
--- a/xmpp-vala/src/module/xep/0045_muc/module.vala
+++ b/xmpp-vala/src/module/xep/0045_muc/module.vala
@@ -37,7 +37,7 @@ public class Module : XmppStreamModule {
public signal void received_occupant_role(XmppStream stream, string jid, string? role);
public signal void subject_set(XmppStream stream, string subject, string jid);
- public void enter(XmppStream stream, string bare_jid, string nick, string? password, MucEnterListener listener) {
+ public void enter(XmppStream stream, string bare_jid, string nick, string? password, ListenerHolder.OnSuccess success_listener, ListenerHolder.OnError error_listener, Object? store) {
Presence.Stanza presence = new Presence.Stanza();
presence.to = bare_jid + "/" + nick;
StanzaNode x_node = new StanzaNode.build("x", NS_URI).add_self_xmlns();
@@ -46,7 +46,7 @@ public class Module : XmppStreamModule {
}
presence.stanza.put_node(x_node);
- Muc.Flag.get_flag(stream).start_muc_enter(bare_jid, presence.id, listener);
+ Muc.Flag.get_flag(stream).start_muc_enter(bare_jid, presence.id, new ListenerHolder(success_listener, error_listener, store));
stream.get_module(Presence.Module.IDENTITY).send_presence(stream, presence);
}
@@ -130,20 +130,22 @@ 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) == error_stanza.original_id) {
- MucEnterListener listener = flag.get_enter_listener(bare_jid);
+ ListenerHolder listener = flag.get_enter_listener(bare_jid);
+ MucEnterError? error = null;
if (error_stanza.condition == ErrorStanza.CONDITION_NOT_AUTHORIZED && ErrorStanza.TYPE_AUTH == error_stanza.type_) {
- listener.on_error(MucEnterError.PASSWORD_REQUIRED);
+ error = MucEnterError.PASSWORD_REQUIRED;
} else if (ErrorStanza.CONDITION_REGISTRATION_REQUIRED == error_stanza.condition && ErrorStanza.TYPE_AUTH == error_stanza.type_) {
- listener.on_error(MucEnterError.NOT_IN_MEMBER_LIST);
+ error = MucEnterError.NOT_IN_MEMBER_LIST;
} else if (ErrorStanza.CONDITION_FORBIDDEN == error_stanza.condition && ErrorStanza.TYPE_AUTH == error_stanza.type_) {
- listener.on_error(MucEnterError.BANNED);
+ error = MucEnterError.BANNED;
} else if (ErrorStanza.CONDITION_CONFLICT == error_stanza.condition && ErrorStanza.TYPE_CANCEL == error_stanza.type_) {
- listener.on_error(MucEnterError.NICK_CONFLICT);
+ error = MucEnterError.NICK_CONFLICT;
} else if (ErrorStanza.CONDITION_SERVICE_UNAVAILABLE == error_stanza.condition && ErrorStanza.TYPE_WAIT == error_stanza.type_) {
- listener.on_error(MucEnterError.OCCUPANT_LIMIT_REACHED);
+ error = MucEnterError.OCCUPANT_LIMIT_REACHED;
} else if (ErrorStanza.CONDITION_ITEM_NOT_FOUND == error_stanza.condition && ErrorStanza.TYPE_CANCEL == error_stanza.type_) {
- listener.on_error(MucEnterError.ROOM_DOESNT_EXIST);
+ error = MucEnterError.ROOM_DOESNT_EXIST;
}
+ if (error == null) listener.on_error(stream, error, listener.reference);
flag.finish_muc_enter(bare_jid);
}
}
@@ -157,7 +159,8 @@ public class Module : XmppStreamModule {
ArrayList<int> status_codes = get_status_codes(x_node);
if (status_codes.contains(StatusCode.SELF_PRESENCE)) {
string bare_jid = get_bare_jid(presence.from);
- flag.get_enter_listener(bare_jid).on_success();
+ ListenerHolder listener = flag.get_enter_listener(bare_jid);
+ listener.on_success(stream, listener.reference);
flag.finish_muc_enter(bare_jid, get_resource_part(presence.from));
}
string? affiliation = x_node["item", "affiliation"].val;
@@ -233,9 +236,17 @@ public enum StatusCode {
REMOVED_SHUTDOWN = 332
}
-public interface MucEnterListener : Object {
- public abstract void on_success();
- public abstract void on_error(MucEnterError error);
+public class ListenerHolder {
+ [CCode (has_target = false)] public delegate void OnSuccess(XmppStream stream, Object? store);
+ public OnSuccess on_success { get; private set; }
+ [CCode (has_target = false)] public delegate void OnError(XmppStream stream, MucEnterError error, Object? store);
+ public OnError on_error { get; private set; }
+ public Object? reference { get; private set; }
+
+ public ListenerHolder(OnSuccess on_success, OnError on_error, Object? reference = null) {
+ this.on_success = on_success;
+ this.reference = reference;
+ }
}
}
diff --git a/xmpp-vala/src/module/xep/0048_bookmarks/conference.vala b/xmpp-vala/src/module/xep/0048_bookmarks/conference.vala
index 818ab3d0..e0988041 100644
--- a/xmpp-vala/src/module/xep/0048_bookmarks/conference.vala
+++ b/xmpp-vala/src/module/xep/0048_bookmarks/conference.vala
@@ -2,7 +2,7 @@ using Xmpp.Core;
namespace Xmpp.Xep.Bookmarks {
-public class Conference {
+public class Conference : Object {
public const string ATTRIBUTE_AUTOJOIN = "autojoin";
public const string ATTRIBUTE_JID = "jid";
diff --git a/xmpp-vala/src/module/xep/0048_bookmarks/module.vala b/xmpp-vala/src/module/xep/0048_bookmarks/module.vala
index 25191122..656ea6fd 100644
--- a/xmpp-vala/src/module/xep/0048_bookmarks/module.vala
+++ b/xmpp-vala/src/module/xep/0048_bookmarks/module.vala
@@ -11,9 +11,16 @@ public class Module : XmppStreamModule {
public signal void conferences_updated(XmppStream stream, ArrayList<Conference> conferences);
- public void get_conferences(XmppStream stream, ConferencesRetrieveResponseListener response_listener) {
+ [CCode (has_target = false)] public delegate void OnResult(XmppStream stream, ArrayList<Conference> conferences, Object? reference);
+ public void get_conferences(XmppStream stream, OnResult listener, Object? store) {
StanzaNode get_node = new StanzaNode.build("storage", NS_URI).add_self_xmlns();
- stream.get_module(PrivateXmlStorage.Module.IDENTITY).retrieve(stream, get_node, new GetConferences(response_listener));
+ stream.get_module(PrivateXmlStorage.Module.IDENTITY).retrieve(stream, get_node, on_conferences_received, Tuple.create(listener, store));
+ }
+
+ private static void on_conferences_received(XmppStream stream, StanzaNode node, Object? o) {
+ Tuple<OnResult, Object?> tuple = o as Tuple<OnResult, Object?>;
+ OnResult on_result = tuple.a;
+ on_result(stream, get_conferences_from_stanza(node), tuple.b);
}
public void set_conferences(XmppStream stream, ArrayList<Conference> conferences) {
@@ -21,89 +28,58 @@ 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, new StoreResponseListenerImpl(conferences));
+ stream.get_module(PrivateXmlStorage.Module.IDENTITY).store(stream, storage_node, on_set_conferences_response, conferences);
}
- private class StoreResponseListenerImpl : PrivateXmlStorage.StoreResponseListener, Object {
- ArrayList<Conference> conferences;
- public StoreResponseListenerImpl(ArrayList<Conference> conferences) {
- this.conferences = conferences;
- }
- public void on_success(XmppStream stream) {
- stream.get_module(Module.IDENTITY).conferences_updated(stream, conferences);
- }
+ private static void on_set_conferences_response(XmppStream stream, Object? o) {
+ ArrayList<Conference> conferences = o as ArrayList<Conference>;
+ stream.get_module(Module.IDENTITY).conferences_updated(stream, conferences);
}
public void add_conference(XmppStream stream, Conference add) {
- get_conferences(stream, new AddConference(add));
- }
-
- public void replace_conference(XmppStream stream, Conference was, Conference modified) {
- get_conferences(stream, new ModifyConference(was, modified));
+ get_conferences(stream, on_add_conference_response, add);
}
- public void remove_conference(XmppStream stream, Conference conference) {
- get_conferences(stream, new RemoveConference(conference));
+ private static void on_add_conference_response(XmppStream stream, ArrayList<Conference> conferences, Object? o) {
+ Conference add = o as Conference;
+ conferences.add(add);
+ stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
}
- private class GetConferences : PrivateXmlStorage.RetrieveResponseListener, Object {
- ConferencesRetrieveResponseListener response_listener;
-
- public GetConferences(ConferencesRetrieveResponseListener response_listener) {
- this.response_listener = response_listener;
- }
-
- public void on_result(XmppStream stream, StanzaNode node) {
- response_listener.on_result(stream, get_conferences_from_stanza(node));
- }
+ public void replace_conference(XmppStream stream, Conference was, Conference modified) {
+ get_conferences(stream, on_replace_conference_response, Tuple.create(was, modified));
}
- private class AddConference : ConferencesRetrieveResponseListener, Object {
- private Conference conference;
- public AddConference(Conference conference) {
- this.conference = conference;
- }
- public void on_result(XmppStream stream, ArrayList<Conference> conferences) {
- conferences.add(conference);
- stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
+ private static void on_replace_conference_response(XmppStream stream, ArrayList<Conference> conferences, Object? o) {
+ Tuple<Conference, Conference> tuple = o as Tuple<Conference, Conference>;
+ Conference was = tuple.a;
+ Conference modified = tuple.b;
+ foreach (Conference conference in conferences) {
+ if (conference.name == was.name && conference.jid == was.jid && conference.autojoin == was.autojoin) {
+ conference.autojoin = modified.autojoin;
+ conference.name = modified.name;
+ conference.jid = modified.jid;
+ break;
+ }
}
+ stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
}
- private class ModifyConference : ConferencesRetrieveResponseListener, Object {
- private Conference was;
- private Conference modified;
- public ModifyConference(Conference was, Conference modified) {
- this.was = was;
- this.modified = modified;
- }
- public void on_result(XmppStream stream, ArrayList<Conference> conferences) {
- foreach (Conference conference in conferences) {
- if (conference.name == was.name && conference.jid == was.jid && conference.autojoin == was.autojoin) {
- conference.autojoin = modified.autojoin;
- conference.name = modified.name;
- conference.jid = modified.jid;
- break;
- }
- }
- stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
- }
+ public void remove_conference(XmppStream stream, Conference conference) {
+ get_conferences(stream, on_remove_conference_response, conference);
}
- private class RemoveConference : ConferencesRetrieveResponseListener, Object {
- private Conference remove;
- public RemoveConference(Conference remove) {
- this.remove = remove;
- }
- public void on_result(XmppStream stream, ArrayList<Conference> conferences) {
- Conference? rem = null;
- foreach (Conference conference in conferences) {
- if (conference.name == remove.name && conference.jid == remove.jid && conference.autojoin == remove.autojoin) {
- rem = conference;
- }
+ private static void on_remove_conference_response(XmppStream stream, ArrayList<Conference> conferences, Object? o) {
+ Conference remove = o as Conference;
+ Conference? rem = null;
+ foreach (Conference conference in conferences) {
+ if (conference.name == remove.name && conference.jid == remove.jid && conference.autojoin == remove.autojoin) {
+ rem = conference;
+ break;
}
- if (rem != null) conferences.remove(rem);
- stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
}
+ if (rem != null) conferences.remove(rem);
+ stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
}
public override void attach(XmppStream stream) { }
@@ -127,8 +103,4 @@ public class Module : XmppStreamModule {
}
}
-public interface ConferencesRetrieveResponseListener : Object {
- public abstract void on_result(XmppStream stream, ArrayList<Conference> conferences);
-}
-
}
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 f59d0bdd..a5d872b6 100644
--- a/xmpp-vala/src/module/xep/0049_private_xml_storage.vala
+++ b/xmpp-vala/src/module/xep/0049_private_xml_storage.vala
@@ -1,3 +1,5 @@
+using Gee;
+
using Xmpp.Core;
namespace Xmpp.Xep.PrivateXmlStorage {
@@ -7,35 +9,18 @@ namespace Xmpp.Xep.PrivateXmlStorage {
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) {
+ [CCode (has_target = false)] public delegate void OnSuccess(XmppStream stream, Object? reference);
+ public void store(XmppStream stream, StanzaNode node, OnSuccess listener, Object? reference) {
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, new IqStoreResponse(listener));
- }
-
- private class IqStoreResponse : Iq.ResponseListener, Object {
- StoreResponseListener listener;
- public IqStoreResponse(StoreResponseListener listener) {
- this.listener = listener;
- }
- public void on_result(XmppStream stream, Iq.Stanza iq) {
- listener.on_success(stream);
- }
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_store_response, Tuple.create(listener, reference));
}
- public void retrieve(XmppStream stream, StanzaNode node, RetrieveResponseListener responseListener) {
+ [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) {
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, new IqRetrieveResponse(responseListener));
- }
-
- private class IqRetrieveResponse : Iq.ResponseListener, Object {
- RetrieveResponseListener response_listener;
- public IqRetrieveResponse(RetrieveResponseListener response_listener) { this.response_listener = response_listener; }
-
- public void on_result(XmppStream stream, Iq.Stanza iq) {
- response_listener.on_result(stream, iq.stanza.get_subnode("query", NS_URI));
- }
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_retrieve_response, Tuple.create(listener, reference));
}
public override void attach(XmppStream stream) {
@@ -50,13 +35,15 @@ namespace Xmpp.Xep.PrivateXmlStorage {
public override string get_ns() { return NS_URI; }
public override string get_id() { return ID; }
- }
- public interface StoreResponseListener : Object {
- public abstract void on_success(XmppStream stream);
- }
+ 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);
+ }
- public interface RetrieveResponseListener : Object {
- public abstract void on_result(XmppStream stream, StanzaNode stanzaNode);
+ 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 037f723b..622f2657 100644
--- a/xmpp-vala/src/module/xep/0054_vcard/module.vala
+++ b/xmpp-vala/src/module/xep/0054_vcard/module.vala
@@ -53,32 +53,22 @@ public class Module : XmppStreamModule {
} else {
iq.to = get_bare_jid(presence.from);
}
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, new IqResponseListenerImpl(this, storage, sha1));
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_received_vcard);
}
}
- private class IqResponseListenerImpl : Iq.ResponseListener, Object {
- Module outer;
- PixbufStorage storage;
- string id;
- public IqResponseListenerImpl(Module outer, PixbufStorage storage, string id) {
- this.outer = outer;
- this.id = id;
- this.storage = storage;
- }
- public void on_result(XmppStream stream, Iq.Stanza iq) {
- if (iq.is_error()) return;
- StanzaNode? vcard_node = iq.stanza.get_subnode("vCard", NS_URI);
- if (vcard_node == null) return;
- StanzaNode? photo_node = vcard_node.get_subnode("PHOTO", NS_URI);
- if (photo_node == null) return;
- StanzaNode? binary_node = photo_node.get_subnode("BINVAL", NS_URI);
- if (binary_node == null) return;
- string? content = binary_node.get_string_content();
- if (content == null) return;
- storage.store(id, Base64.decode(content));
- outer.received_avatar(stream, iq.from, id);
- }
+ private static void on_received_vcard(XmppStream stream, Iq.Stanza iq) {
+ if (iq.is_error()) return;
+ StanzaNode? vcard_node = iq.stanza.get_subnode("vCard", NS_URI);
+ if (vcard_node == null) return;
+ StanzaNode? photo_node = vcard_node.get_subnode("PHOTO", NS_URI);
+ if (photo_node == null) return;
+ StanzaNode? binary_node = photo_node.get_subnode("BINVAL", NS_URI);
+ if (binary_node == null) return;
+ string? content = binary_node.get_string_content();
+ if (content == null) return;
+ string sha1 = Checksum.compute_for_data(ChecksumType.SHA1, content.data);
+ stream.get_module(IDENTITY).received_avatar(stream, iq.from, sha1);
}
}
}
diff --git a/xmpp-vala/src/module/xep/0060_pubsub.vala b/xmpp-vala/src/module/xep/0060_pubsub.vala
index c69f6a25..2c06843e 100644
--- a/xmpp-vala/src/module/xep/0060_pubsub.vala
+++ b/xmpp-vala/src/module/xep/0060_pubsub.vala
@@ -17,23 +17,11 @@ namespace Xmpp.Xep.Pubsub {
event_listeners[node] = new EventListenerDelegate(on_result, reference);
}
- public void request(XmppStream stream, string jid, string node, RequestResponseListener listener) { // TODO multiple nodes gehen auch
+ [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, new IqRequestResponseListener(listener));
- }
-
- private class IqRequestResponseListener : Iq.ResponseListener, Object {
- RequestResponseListener response_listener;
- public IqRequestResponseListener(RequestResponseListener response_listener) { this.response_listener = response_listener; }
- public void on_result(XmppStream stream, Iq.Stanza 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? node = items_node != null ? items_node.get_attribute("node", NS_URI) : null;
- string? id = item_node != null ? item_node.get_attribute("id", NS_URI) : null;
- response_listener.on_result(stream, iq.from, id, item_node != null ? item_node.sub_nodes[0] : null);
- }
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, a, on_received_request_response, Tuple.create(listener, store));
}
public void publish(XmppStream stream, string? jid, string node_id, string node, string item_id, StanzaNode content) {
@@ -47,18 +35,6 @@ namespace Xmpp.Xep.Pubsub {
stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, null);
}
- private class IqPublishResponseListener : Iq.ResponseListener, Object {
- PublishResponseListener response_listener;
- public IqPublishResponseListener(PublishResponseListener response_listener) { this.response_listener = response_listener; }
- public void on_result(XmppStream stream, Iq.Stanza iq) {
- if (iq.is_error()) {
- response_listener.on_error(stream);
- } else {
- response_listener.on_success(stream);
- }
- }
- }
-
public override void attach(XmppStream stream) {
Iq.Module.require(stream);
Message.Module.require(stream);
@@ -87,10 +63,16 @@ namespace Xmpp.Xep.Pubsub {
event_listeners[node].on_result(stream, message.from, id, item_node.sub_nodes[0]);
}
}
- }
- public interface RequestResponseListener : Object {
- public abstract void on_result(XmppStream stream, string jid, string? id, StanzaNode? node);
+ 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 {
@@ -103,9 +85,4 @@ namespace Xmpp.Xep.Pubsub {
this.reference = reference;
}
}
-
- public interface PublishResponseListener : Object {
- public abstract void on_success(XmppStream stream);
- public abstract void on_error(XmppStream stream);
- }
}
diff --git a/xmpp-vala/src/module/xep/0084_user_avatars.vala b/xmpp-vala/src/module/xep/0084_user_avatars.vala
index edaa25df..a98d8538 100644
--- a/xmpp-vala/src/module/xep/0084_user_avatars.vala
+++ b/xmpp-vala/src/module/xep/0084_user_avatars.vala
@@ -34,17 +34,6 @@ namespace Xmpp.Xep.UserAvatars {
stream.get_module(Pubsub.Module.IDENTITY).publish(stream, null, NS_URI_METADATA, NS_URI_METADATA, sha1, metadata_node);
}
- private class PublishResponseListenerImpl : Pubsub.PublishResponseListener, Object {
- PublishResponseListener listener;
- PublishResponseListenerImpl other;
- public PublishResponseListenerImpl(PublishResponseListener listener, PublishResponseListenerImpl other) {
- this.listener = listener;
- this.other = other;
- }
- public void on_success(XmppStream stream) { listener.on_success(stream); }
- public void on_error(XmppStream stream) { listener.on_error(stream); }
- }
-
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, this);
@@ -59,17 +48,7 @@ namespace Xmpp.Xep.UserAvatars {
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, new PubsubRequestResponseListenerImpl(storage));
- }
- }
-
- class PubsubRequestResponseListenerImpl : Pubsub.RequestResponseListener, Object {
- PixbufStorage storage;
- public PubsubRequestResponseListenerImpl(PixbufStorage storage) { this.storage = storage; }
- public void on_result(XmppStream stream, string jid, string? id, StanzaNode? node) {
- if (node == null) return;
- storage.store(id, Base64.decode(node.get_string_content()));
- stream.get_module(Module.IDENTITY).received_avatar(stream, jid, id);
+ stream.get_module(Pubsub.Module.IDENTITY).request(stream, jid, NS_URI_DATA, on_pubsub_data_response, storage);
}
}
@@ -79,10 +58,12 @@ namespace Xmpp.Xep.UserAvatars {
public override string get_ns() { return NS_URI; }
public override string get_id() { return ID; }
- }
- public interface PublishResponseListener : Object {
- public abstract void on_success(XmppStream stream);
- public abstract void on_error(XmppStream stream);
+ private static void on_pubsub_data_response(XmppStream stream, string jid, string? id, StanzaNode? node, Object? o) {
+ 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 6b8ae3bb..9387faaa 100644
--- a/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala
+++ b/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala
@@ -58,26 +58,19 @@ 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, new ServiceDiscoveryInfoResponseListenerImpl(storage, ver_attribute));
+ stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, presence.from, on_received_info_response, Tuple.create(storage, ver_attribute));
} else {
ServiceDiscovery.Flag.get_flag(stream).set_entitiy_features(presence.from, capabilities);
}
}
}
- private class ServiceDiscoveryInfoResponseListenerImpl : ServiceDiscovery.InfoResponseListener, Object {
- private Storage storage;
- private string entity;
-
- public ServiceDiscoveryInfoResponseListenerImpl(Storage storage, string entity) {
- this.storage = storage;
- this.entity = entity;
- }
- public void on_result(XmppStream stream, ServiceDiscovery.InfoResult query_result) {
- if (compute_hash(query_result.identities, query_result.features) == entity) {
- storage.store_features(entity, query_result.features);
- }
+ private static void on_received_info_response(XmppStream stream, ServiceDiscovery.InfoResult query_result, Object? store) {
+ 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);
}
}
diff --git a/xmpp-vala/src/module/xep/0199_ping.vala b/xmpp-vala/src/module/xep/0199_ping.vala
index a4157e99..35cad26c 100644
--- a/xmpp-vala/src/module/xep/0199_ping.vala
+++ b/xmpp-vala/src/module/xep/0199_ping.vala
@@ -9,20 +9,10 @@ namespace Xmpp.Xep.Ping {
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) {
+ public void send_ping(XmppStream stream, string jid, ResponseListener 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, listener == null? null : new IqResponseListenerImpl(listener));
- }
-
- private class IqResponseListenerImpl : Iq.ResponseListener, Object {
- ResponseListener listener;
- public IqResponseListenerImpl(ResponseListener listener) {
- this.listener = listener;
- }
- public void on_result(XmppStream stream, Iq.Stanza iq) {
- listener.on_result(stream);
- }
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_ping_response, listener);
}
public override void attach(XmppStream stream) {
@@ -45,6 +35,11 @@ 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;
+ listener.on_result(stream);
+ }
}
public interface ResponseListener : Object {