Software /
code /
verse
Diff
plugins/private.lua @ 255:be126fe7c4e7
Merge with MattJ & mva
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 03 Dec 2011 19:46:47 +0100 |
parent | 250:a5ac643a7fd6 |
child | 380:0891b4e27766 |
line wrap: on
line diff
--- a/plugins/private.lua Mon Nov 28 17:16:04 2011 +0100 +++ b/plugins/private.lua Sat Dec 03 19:46:47 2011 +0100 @@ -1,33 +1,35 @@ --- Implements XEP-0049: Private XML Storage - -local xmlns_private = "jabber:iq:private"; - -function verse.plugins.private(stream) - function stream:private_set(name, xmlns, data, callback) - local iq = verse.iq({ type = "set" }) - :tag("query", { xmlns = xmlns_private }); - if data then - if data.name == name and data.attr and data.attr.xmlns == xmlns then - iq:add_child(data); - else - iq:tag(name, { xmlns = xmlns }) - :add_child(data); - end - end - self:send_iq(iq, callback); - end - - function stream:private_get(name, xmlns, callback) - self:send_iq(verse.iq({type="get"}) - :tag("query", { xmlns = xmlns_private }) - :tag(name, { xmlns = xmlns }), - function (reply) - if reply.attr.type == "result" then - local query = reply:get_child("query", xmlns_private); - local result = query:get_child(name, xmlns); - callback(result); - end - end); - end -end - +local verse = require "verse"; + +-- Implements XEP-0049: Private XML Storage + +local xmlns_private = "jabber:iq:private"; + +function verse.plugins.private(stream) + function stream:private_set(name, xmlns, data, callback) + local iq = verse.iq({ type = "set" }) + :tag("query", { xmlns = xmlns_private }); + if data then + if data.name == name and data.attr and data.attr.xmlns == xmlns then + iq:add_child(data); + else + iq:tag(name, { xmlns = xmlns }) + :add_child(data); + end + end + self:send_iq(iq, callback); + end + + function stream:private_get(name, xmlns, callback) + self:send_iq(verse.iq({type="get"}) + :tag("query", { xmlns = xmlns_private }) + :tag(name, { xmlns = xmlns }), + function (reply) + if reply.attr.type == "result" then + local query = reply:get_child("query", xmlns_private); + local result = query:get_child(name, xmlns); + callback(result); + end + end); + end +end +