plugins/private.lua

Sat, 20 Nov 2010 17:27:03 +0100

author
Kim Alvefur <zash@zash.se>
date
Sat, 20 Nov 2010 17:27:03 +0100
changeset 155
9c9af7a196ed
parent 149
f5c524412939
child 250
a5ac643a7fd6
permissions
-rw-r--r--

plugins.private, squishy: Allow setting the storage node, and not just child(s). And add to squishy.

155
9c9af7a196ed plugins.private, squishy: Allow setting the storage node, and not just child(s). And add to squishy.
Kim Alvefur <zash@zash.se>
parents: 149
diff changeset
1 -- Implements XEP-0049: Private XML Storage
9c9af7a196ed plugins.private, squishy: Allow setting the storage node, and not just child(s). And add to squishy.
Kim Alvefur <zash@zash.se>
parents: 149
diff changeset
2
149
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local xmlns_private = "jabber:iq:private";
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 function verse.plugins.private(stream)
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 function stream:private_set(name, xmlns, data, callback)
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local iq = verse.iq({ type = "set" })
155
9c9af7a196ed plugins.private, squishy: Allow setting the storage node, and not just child(s). And add to squishy.
Kim Alvefur <zash@zash.se>
parents: 149
diff changeset
8 :tag("query", { xmlns = xmlns_private });
9c9af7a196ed plugins.private, squishy: Allow setting the storage node, and not just child(s). And add to squishy.
Kim Alvefur <zash@zash.se>
parents: 149
diff changeset
9 if data then
9c9af7a196ed plugins.private, squishy: Allow setting the storage node, and not just child(s). And add to squishy.
Kim Alvefur <zash@zash.se>
parents: 149
diff changeset
10 if data.name == name and data.attr and data.attr.xmlns == xmlns then
9c9af7a196ed plugins.private, squishy: Allow setting the storage node, and not just child(s). And add to squishy.
Kim Alvefur <zash@zash.se>
parents: 149
diff changeset
11 iq:add_child(data);
9c9af7a196ed plugins.private, squishy: Allow setting the storage node, and not just child(s). And add to squishy.
Kim Alvefur <zash@zash.se>
parents: 149
diff changeset
12 else
9c9af7a196ed plugins.private, squishy: Allow setting the storage node, and not just child(s). And add to squishy.
Kim Alvefur <zash@zash.se>
parents: 149
diff changeset
13 iq:tag(name, { xmlns = xmlns })
9c9af7a196ed plugins.private, squishy: Allow setting the storage node, and not just child(s). And add to squishy.
Kim Alvefur <zash@zash.se>
parents: 149
diff changeset
14 :add_child(data);
9c9af7a196ed plugins.private, squishy: Allow setting the storage node, and not just child(s). And add to squishy.
Kim Alvefur <zash@zash.se>
parents: 149
diff changeset
15 end
9c9af7a196ed plugins.private, squishy: Allow setting the storage node, and not just child(s). And add to squishy.
Kim Alvefur <zash@zash.se>
parents: 149
diff changeset
16 end
9c9af7a196ed plugins.private, squishy: Allow setting the storage node, and not just child(s). And add to squishy.
Kim Alvefur <zash@zash.se>
parents: 149
diff changeset
17 self:send_iq(iq, callback);
149
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 end
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 function stream:private_get(name, xmlns, callback)
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 self:send_iq(verse.iq({type="get"})
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 :tag("query", { xmlns = xmlns_private })
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 :tag(name, { xmlns = xmlns }),
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 function (reply)
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 if reply.attr.type == "result" then
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 local query = reply:get_child("query", xmlns_private);
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 local result = query:get_child(name, xmlns);
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 callback(result);
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 end
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 end);
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 end
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 end
f5c524412939 plugins.private: Private XML storage support
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33

mercurial