1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
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";
public void store(XmppStream stream, StanzaNode node, StoreResponseListener listener) {
StanzaNode queryNode = new StanzaNode.build("query", NS_URI).add_self_xmlns().put_node(node);
Iq.Stanza iq = new Iq.Stanza.set(queryNode);
Iq.Module.get_module(stream).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);
}
}
public void retrieve(XmppStream stream, StanzaNode node, RetrieveResponseListener responseListener) {
StanzaNode queryNode = new StanzaNode.build("query", NS_URI).add_self_xmlns().put_node(node);
Iq.Stanza iq = new Iq.Stanza.get(queryNode);
Iq.Module.get_module(stream).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));
}
}
public override void attach(XmppStream stream) {
Iq.Module.require(stream);
}
public override void detach(XmppStream stream) { }
public static Module? get_module(XmppStream stream) {
return (Module?) stream.get_module(NS_URI, ID);
}
public static void require(XmppStream stream) {
if (get_module(stream) == null) stream.add_module(new PrivateXmlStorage.Module());
}
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);
}
public interface RetrieveResponseListener : Object {
public abstract void on_result(XmppStream stream, StanzaNode stanzaNode);
}
}
|