aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2015-05-15 15:33:31 +0200
committerKim Alvefur <zash@zash.se>2015-05-15 15:33:31 +0200
commita1eac64a926aeeec8babac775aa689dab4a598d3 (patch)
tree89f1f780149b6a8649f10f20e23d88635996fc6c /plugins
parent6b32fb12b118afd85c6efbf35187a9298ace9167 (diff)
parent0ee5b781b852a955144f4c04f732ae0de19ed174 (diff)
downloadprosody-a1eac64a926aeeec8babac775aa689dab4a598d3.tar.gz
prosody-a1eac64a926aeeec8babac775aa689dab4a598d3.zip
Merge 0.10->trunk
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_storage_xep0227.lua (renamed from plugins/storage/mod_xep0227.lua)51
-rw-r--r--plugins/storage/xep227store.lib.lua168
2 files changed, 33 insertions, 186 deletions
diff --git a/plugins/storage/mod_xep0227.lua b/plugins/mod_storage_xep0227.lua
index 5d07a2ea..ef227ca3 100644
--- a/plugins/storage/mod_xep0227.lua
+++ b/plugins/mod_storage_xep0227.lua
@@ -7,28 +7,31 @@ local t_remove = table.remove;
local os_remove = os.remove;
local io_open = io.open;
+local paths = require"util.paths";
local st = require "util.stanza";
local parse_xml_real = require "util.xml".parse;
local function getXml(user, host)
local jid = user.."@"..host;
- local path = "data/"..jid..".xml";
+ local path = paths.join(prosody.paths.data, jid..".xml");
local f = io_open(path);
if not f then return; end
local s = f:read("*a");
+ f:close();
return parse_xml_real(s);
end
local function setXml(user, host, xml)
local jid = user.."@"..host;
- local path = "data/"..jid..".xml";
+ local path = paths.join(prosody.paths.data, jid..".xml");
+ local f, err = io_open(path, "w");
+ if not f then return f, err; end
if xml then
- local f = io_open(path, "w");
- if not f then return; end
local s = tostring(xml);
f:write(s);
f:close();
return true;
else
+ f:close();
return os_remove(path);
end
end
@@ -44,7 +47,7 @@ local function getUserElement(xml)
end
end
local function createOuterXml(user, host)
- return st.stanza("server-data", {xmlns='http://www.xmpp.org/extensions/xep-0227.html#ns'})
+ return st.stanza("server-data", {xmlns='urn:xmpp:pie:0'})
:tag("host", {jid=host})
:tag("user", {name = user});
end
@@ -63,19 +66,36 @@ end
local handlers = {};
+-- In order to support mod_auth_internal_hashed
+local extended = "http://prosody.im/protocol/extended-xep0227\1";
+
handlers.accounts = {
get = function(self, user)
- local user = getUserElement(getXml(user, self.host));
+ user = getUserElement(getXml(user, self.host));
if user and user.attr.password then
return { password = user.attr.password };
+ elseif user then
+ local data = {};
+ for k, v in pairs(user.attr) do
+ if k:sub(1, #extended) == extended then
+ data[k:sub(#extended+1)] = v;
+ end
+ end
+ return data;
end
end;
set = function(self, user, data)
- if data and data.password then
+ if data then
local xml = getXml(user, self.host);
if not xml then xml = createOuterXml(user, self.host); end
local usere = getUserElement(xml);
- usere.attr.password = data.password;
+ for k, v in pairs(data) do
+ if k == "password" then
+ usere.attr.password = v;
+ else
+ usere.attr[extended..k] = v;
+ end
+ end
return setXml(user, self.host, xml);
else
return setXml(user, self.host, nil);
@@ -84,7 +104,7 @@ handlers.accounts = {
};
handlers.vcard = {
get = function(self, user)
- local user = getUserElement(getXml(user, self.host));
+ user = getUserElement(getXml(user, self.host));
if user then
local vcard = user:get_child("vCard", 'vcard-temp');
if vcard then
@@ -113,7 +133,7 @@ handlers.vcard = {
};
handlers.private = {
get = function(self, user)
- local user = getUserElement(getXml(user, self.host));
+ user = getUserElement(getXml(user, self.host));
if user then
local private = user:get_child("query", "jabber:iq:private");
if private then
@@ -147,15 +167,10 @@ handlers.private = {
-----------------------------
local driver = {};
-function driver:open(host, datastore, typ)
- local instance = setmetatable({}, self);
- instance.host = host;
- instance.datastore = datastore;
+function driver:open(datastore, typ)
local handler = handlers[datastore];
- if not handler then return nil; end
- for key,val in pairs(handler) do
- instance[key] = val;
- end
+ if not handler then return nil, "unsupported-datastore"; end
+ local instance = setmetatable({ host = module.host; datastore = datastore; }, { __index = handler });
if instance.init then instance:init(); end
return instance;
end
diff --git a/plugins/storage/xep227store.lib.lua b/plugins/storage/xep227store.lib.lua
deleted file mode 100644
index 5ef8df54..00000000
--- a/plugins/storage/xep227store.lib.lua
+++ /dev/null
@@ -1,168 +0,0 @@
-
-local st = require "util.stanza";
-
-local function getXml(user, host)
- local jid = user.."@"..host;
- local path = "data/"..jid..".xml";
- local f = io.open(path);
- if not f then return; end
- local s = f:read("*a");
- return parse_xml_real(s);
-end
-local function setXml(user, host, xml)
- local jid = user.."@"..host;
- local path = "data/"..jid..".xml";
- if xml then
- local f = io.open(path, "w");
- if not f then return; end
- local s = tostring(xml);
- f:write(s);
- f:close();
- return true;
- else
- return os.remove(path);
- end
-end
-local function getUserElement(xml)
- if xml and xml.name == "server-data" then
- local host = xml.tags[1];
- if host and host.name == "host" then
- local user = host.tags[1];
- if user and user.name == "user" then
- return user;
- end
- end
- end
-end
-local function createOuterXml(user, host)
- return st.stanza("server-data", {xmlns='http://www.xmpp.org/extensions/xep-0227.html#ns'})
- :tag("host", {jid=host})
- :tag("user", {name = user});
-end
-local function removeFromArray(array, value)
- for i,item in ipairs(array) do
- if item == value then
- table.remove(array, i);
- return;
- end
- end
-end
-local function removeStanzaChild(s, child)
- removeFromArray(s.tags, child);
- removeFromArray(s, child);
-end
-
-local handlers = {};
-
-handlers.accounts = {
- get = function(self, user)
- local user = getUserElement(getXml(user, self.host));
- if user and user.attr.password then
- return { password = user.attr.password };
- end
- end;
- set = function(self, user, data)
- if data and data.password then
- local xml = getXml(user, self.host);
- if not xml then xml = createOuterXml(user, self.host); end
- local usere = getUserElement(xml);
- usere.attr.password = data.password;
- return setXml(user, self.host, xml);
- else
- return setXml(user, self.host, nil);
- end
- end;
-};
-handlers.vcard = {
- get = function(self, user)
- local user = getUserElement(getXml(user, self.host));
- if user then
- local vcard = user:get_child("vCard", 'vcard-temp');
- if vcard then
- return st.preserialize(vcard);
- end
- end
- end;
- set = function(self, user, data)
- local xml = getXml(user, self.host);
- local usere = xml and getUserElement(xml);
- if usere then
- local vcard = usere:get_child("vCard", 'vcard-temp');
- if vcard then
- removeStanzaChild(usere, vcard);
- elseif not data then
- return true;
- end
- if data then
- vcard = st.deserialize(data);
- usere:add_child(vcard);
- end
- return setXml(user, self.host, xml);
- end
- return true;
- end;
-};
-handlers.private = {
- get = function(self, user)
- local user = getUserElement(getXml(user, self.host));
- if user then
- local private = user:get_child("query", "jabber:iq:private");
- if private then
- local r = {};
- for _, tag in ipairs(private.tags) do
- r[tag.name..":"..tag.attr.xmlns] = st.preserialize(tag);
- end
- return r;
- end
- end
- end;
- set = function(self, user, data)
- local xml = getXml(user, self.host);
- local usere = xml and getUserElement(xml);
- if usere then
- local private = usere:get_child("query", 'jabber:iq:private');
- if private then removeStanzaChild(usere, private); end
- if data and next(data) ~= nil then
- private = st.stanza("query", {xmlns='jabber:iq:private'});
- for _,tag in pairs(data) do
- private:add_child(st.deserialize(tag));
- end
- usere:add_child(private);
- end
- return setXml(user, self.host, xml);
- end
- return true;
- end;
-};
-
------------------------------
-local driver = {};
-driver.__index = driver;
-
-function driver:open(host, datastore, typ)
- local cache_key = host.." "..datastore;
- if self.ds_cache[cache_key] then return self.ds_cache[cache_key]; end
- local instance = setmetatable({}, self);
- instance.host = host;
- instance.datastore = datastore;
- local handler = handlers[datastore];
- if not handler then return nil; end
- for key,val in pairs(handler) do
- instance[key] = val;
- end
- if instance.init then instance:init(); end
- self.ds_cache[cache_key] = instance;
- return instance;
-end
-
------------------------------
-local _M = {};
-
-function _M.new()
- local instance = setmetatable({}, driver);
- instance.__index = instance;
- instance.ds_cache = {};
- return instance;
-end
-
-return _M;