250
|
1 local verse = require "verse";
|
|
2
|
|
3 -- Implements XEP-0049: Private XML Storage
|
|
4
|
|
5 local xmlns_private = "jabber:iq:private";
|
|
6
|
|
7 function verse.plugins.private(stream)
|
|
8 function stream:private_set(name, xmlns, data, callback)
|
|
9 local iq = verse.iq({ type = "set" })
|
|
10 :tag("query", { xmlns = xmlns_private });
|
|
11 if data then
|
|
12 if data.name == name and data.attr and data.attr.xmlns == xmlns then
|
|
13 iq:add_child(data);
|
|
14 else
|
|
15 iq:tag(name, { xmlns = xmlns })
|
|
16 :add_child(data);
|
|
17 end
|
|
18 end
|
|
19 self:send_iq(iq, callback);
|
|
20 end
|
380
|
21
|
250
|
22 function stream:private_get(name, xmlns, callback)
|
|
23 self:send_iq(verse.iq({type="get"})
|
|
24 :tag("query", { xmlns = xmlns_private })
|
|
25 :tag(name, { xmlns = xmlns }),
|
|
26 function (reply)
|
|
27 if reply.attr.type == "result" then
|
|
28 local query = reply:get_child("query", xmlns_private);
|
|
29 local result = query:get_child(name, xmlns);
|
|
30 callback(result);
|
|
31 end
|
|
32 end);
|
|
33 end
|
|
34 end
|
|
35
|