Software / code / prosody
Comparison
plugins/mod_private.lua @ 6843:161cccfdf015
Merge 0.10->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 22 Sep 2015 01:31:52 +0200 |
| parent | 6354:bbb4a82db32e |
| parent | 6841:be87ab2d611c |
| child | 9228:e2e2aa76ea31 |
comparison
equal
deleted
inserted
replaced
| 6839:298182fd2387 | 6843:161cccfdf015 |
|---|---|
| 15 | 15 |
| 16 module:hook("iq/self/jabber:iq:private:query", function(event) | 16 module:hook("iq/self/jabber:iq:private:query", function(event) |
| 17 local origin, stanza = event.origin, event.stanza; | 17 local origin, stanza = event.origin, event.stanza; |
| 18 local query = stanza.tags[1]; | 18 local query = stanza.tags[1]; |
| 19 if #query.tags ~= 1 then | 19 if #query.tags ~= 1 then |
| 20 return origin.send(st.error_reply(stanza, "modify", "bad-format")); | 20 origin.send(st.error_reply(stanza, "modify", "bad-format")); |
| 21 return true; | |
| 21 end | 22 end |
| 22 local tag = query.tags[1]; | 23 local tag = query.tags[1]; |
| 23 local key = tag.name..":"..tag.attr.xmlns; | 24 local key = tag.name..":"..tag.attr.xmlns; |
| 24 if stanza.attr.type == "get" then | 25 if stanza.attr.type == "get" then |
| 25 local data, err = private_storage:get(origin.username, key); | 26 local data, err = private_storage:get(origin.username, key); |
| 26 if data then | 27 if data then |
| 27 return origin.send(st.reply(stanza):query("jabber:iq:private"):add_child(st.deserialize(data))); | 28 origin.send(st.reply(stanza):query("jabber:iq:private"):add_child(st.deserialize(data))); |
| 28 elseif err then | 29 elseif err then |
| 29 return origin.send(st.error_reply(stanza, "wait", "internal-server-error", err)); | 30 origin.send(st.error_reply(stanza, "wait", "internal-server-error", err)); |
| 30 else | 31 else |
| 31 return origin.send(st.reply(stanza):add_child(query)); | 32 origin.send(st.reply(stanza):add_child(query)); |
| 32 end | 33 end |
| 34 return true; | |
| 33 else -- type == set | 35 else -- type == set |
| 34 local data; | 36 local data; |
| 35 if #tag ~= 0 then | 37 if #tag ~= 0 then |
| 36 data = st.preserialize(tag); | 38 data = st.preserialize(tag); |
| 37 end | 39 end |
| 38 -- TODO delete datastore if empty | 40 -- TODO delete datastore if empty |
| 39 local ok, err = private_storage:set(origin.username, key, data); | 41 local ok, err = private_storage:set(origin.username, key, data); |
| 40 if not ok then | 42 if not ok then |
| 41 return origin.send(st.error_reply(stanza, "wait", "internal-server-error", err)); | 43 origin.send(st.error_reply(stanza, "wait", "internal-server-error", err)); |
| 44 return true; | |
| 42 end | 45 end |
| 43 return origin.send(st.reply(stanza)); | 46 origin.send(st.reply(stanza)); |
| 47 return true; | |
| 44 end | 48 end |
| 45 end); | 49 end); |