2017-03-11 22:04:58 +00:00
|
|
|
using Gee;
|
|
|
|
|
2017-03-02 14:37:32 +00:00
|
|
|
using Xmpp.Core;
|
|
|
|
|
|
|
|
namespace Xmpp.Xep.PrivateXmlStorage {
|
|
|
|
private const string NS_URI = "jabber:iq:private";
|
|
|
|
|
|
|
|
public class Module : XmppStreamModule {
|
|
|
|
public const string ID = "0049_private_xml_storage";
|
2017-03-10 20:13:35 +00:00
|
|
|
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2017-03-11 22:04:58 +00:00
|
|
|
[CCode (has_target = false)] public delegate void OnSuccess(XmppStream stream, Object? reference);
|
|
|
|
public void store(XmppStream stream, StanzaNode node, OnSuccess listener, Object? reference) {
|
2017-03-02 14:37:32 +00:00
|
|
|
StanzaNode queryNode = new StanzaNode.build("query", NS_URI).add_self_xmlns().put_node(node);
|
|
|
|
Iq.Stanza iq = new Iq.Stanza.set(queryNode);
|
2017-03-11 22:04:58 +00:00
|
|
|
stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_store_response, Tuple.create(listener, reference));
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
|
|
|
|
2017-03-11 22:04:58 +00:00
|
|
|
[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) {
|
2017-03-02 14:37:32 +00:00
|
|
|
StanzaNode queryNode = new StanzaNode.build("query", NS_URI).add_self_xmlns().put_node(node);
|
|
|
|
Iq.Stanza iq = new Iq.Stanza.get(queryNode);
|
2017-03-11 22:04:58 +00:00
|
|
|
stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_retrieve_response, Tuple.create(listener, reference));
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void attach(XmppStream stream) {
|
|
|
|
Iq.Module.require(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void detach(XmppStream stream) { }
|
|
|
|
|
|
|
|
public static void require(XmppStream stream) {
|
2017-03-11 00:40:42 +00:00
|
|
|
if (stream.get_module(IDENTITY) == null) stream.add_module(new PrivateXmlStorage.Module());
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override string get_ns() { return NS_URI; }
|
|
|
|
public override string get_id() { return ID; }
|
|
|
|
|
2017-03-11 22:04:58 +00:00
|
|
|
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);
|
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2017-03-11 22:04:58 +00:00
|
|
|
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);
|
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
|
|
|
}
|