Software /
code /
verse
Annotate
plugins/private.lua @ 177:0ffb565fcfd6
plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 31 Dec 2010 01:29:28 +0100 |
parent | 155:9c9af7a196ed |
child | 250:a5ac643a7fd6 |
rev | line source |
---|---|
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 |