aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2013-04-19 16:14:06 +0200
committerKim Alvefur <zash@zash.se>2013-04-19 16:14:06 +0200
commitd8f51285424ed45dbe6c72347742829cd65bf250 (patch)
tree3ef0a2ea8688663d800d608db52155b26d6124e1 /plugins
parente9a56e7e4bade9ea7e942abc100d026e503df14f (diff)
downloadprosody-d8f51285424ed45dbe6c72347742829cd65bf250.tar.gz
prosody-d8f51285424ed45dbe6c72347742829cd65bf250.zip
mod_auth_internal_hashed, mod_auth_internal_plain, mod_privacy, mod_private, mod_register, mod_vcard, mod_muc: Use module:open_store()
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_auth_internal_hashed.lua23
-rw-r--r--plugins/mod_auth_internal_plain.lua19
-rw-r--r--plugins/mod_privacy.lua9
-rw-r--r--plugins/mod_private.lua6
-rw-r--r--plugins/mod_register.lua5
-rw-r--r--plugins/mod_vcard.lua9
-rw-r--r--plugins/muc/mod_muc.lua15
7 files changed, 46 insertions, 40 deletions
diff --git a/plugins/mod_auth_internal_hashed.lua b/plugins/mod_auth_internal_hashed.lua
index cb6cc8ff..2b041e43 100644
--- a/plugins/mod_auth_internal_hashed.lua
+++ b/plugins/mod_auth_internal_hashed.lua
@@ -7,13 +7,14 @@
-- COPYING file in the source package for more information.
--
-local datamanager = require "util.datamanager";
local log = require "util.logger".init("auth_internal_hashed");
local getAuthenticationDatabaseSHA1 = require "util.sasl.scram".getAuthenticationDatabaseSHA1;
local usermanager = require "core.usermanager";
local generate_uuid = require "util.uuid".generate;
local new_sasl = require "util.sasl".new;
+local accounts = module:open_store("accounts");
+
local to_hex;
do
local function replace_byte_with_hex(byte)
@@ -44,7 +45,7 @@ local provider = {};
log("debug", "initializing internal_hashed authentication provider for host '%s'", host);
function provider.test_password(username, password)
- local credentials = datamanager.load(username, host, "accounts") or {};
+ local credentials = accounts:get(username) or {};
if credentials.password ~= nil and string.len(credentials.password) ~= 0 then
if credentials.password ~= password then
@@ -75,7 +76,7 @@ function provider.test_password(username, password)
end
function provider.set_password(username, password)
- local account = datamanager.load(username, host, "accounts");
+ local account = accounts:get(username);
if account then
account.salt = account.salt or generate_uuid();
account.iteration_count = account.iteration_count or iteration_count;
@@ -87,13 +88,13 @@ function provider.set_password(username, password)
account.server_key = server_key_hex
account.password = nil;
- return datamanager.store(username, host, "accounts", account);
+ return accounts:set(username, account);
end
return nil, "Account not available.";
end
function provider.user_exists(username)
- local account = datamanager.load(username, host, "accounts");
+ local account = accounts:get(username);
if not account then
log("debug", "account not found for username '%s' at host '%s'", username, host);
return nil, "Auth failed. Invalid username";
@@ -102,22 +103,22 @@ function provider.user_exists(username)
end
function provider.users()
- return datamanager.users(host, "accounts");
+ return accounts:users();
end
function provider.create_user(username, password)
if password == nil then
- return datamanager.store(username, host, "accounts", {});
+ return accounts:set(username, {});
end
local salt = generate_uuid();
local valid, stored_key, server_key = getAuthenticationDatabaseSHA1(password, salt, iteration_count);
local stored_key_hex = to_hex(stored_key);
local server_key_hex = to_hex(server_key);
- return datamanager.store(username, host, "accounts", {stored_key = stored_key_hex, server_key = server_key_hex, salt = salt, iteration_count = iteration_count});
+ return accounts:set(username, {stored_key = stored_key_hex, server_key = server_key_hex, salt = salt, iteration_count = iteration_count});
end
function provider.delete_user(username)
- return datamanager.store(username, host, "accounts", nil);
+ return accounts:set(username, nil);
end
function provider.get_sasl_handler()
@@ -126,11 +127,11 @@ function provider.get_sasl_handler()
return usermanager.test_password(username, realm, password), true;
end,
scram_sha_1 = function(sasl, username, realm)
- local credentials = datamanager.load(username, host, "accounts");
+ local credentials = accounts:get(username);
if not credentials then return; end
if credentials.password then
usermanager.set_password(username, credentials.password, host);
- credentials = datamanager.load(username, host, "accounts");
+ credentials = accounts:get(username);
if not credentials then return; end
end
diff --git a/plugins/mod_auth_internal_plain.lua b/plugins/mod_auth_internal_plain.lua
index 178ae5a5..e411c4f7 100644
--- a/plugins/mod_auth_internal_plain.lua
+++ b/plugins/mod_auth_internal_plain.lua
@@ -6,20 +6,21 @@
-- COPYING file in the source package for more information.
--
-local datamanager = require "util.datamanager";
local usermanager = require "core.usermanager";
local new_sasl = require "util.sasl".new;
local log = module._log;
local host = module.host;
+local accounts = module:open_store("accounts");
+
-- define auth provider
local provider = {};
log("debug", "initializing internal_plain authentication provider for host '%s'", host);
function provider.test_password(username, password)
log("debug", "test password '%s' for user %s at host %s", password, username, host);
- local credentials = datamanager.load(username, host, "accounts") or {};
+ local credentials = accounts:get(username) or {};
if password == credentials.password then
return true;
@@ -30,20 +31,20 @@ end
function provider.get_password(username)
log("debug", "get_password for username '%s' at host '%s'", username, host);
- return (datamanager.load(username, host, "accounts") or {}).password;
+ return (accounts:get(username) or {}).password;
end
function provider.set_password(username, password)
- local account = datamanager.load(username, host, "accounts");
+ local account = accounts:get(username);
if account then
account.password = password;
- return datamanager.store(username, host, "accounts", account);
+ return accounts:set(username, account);
end
return nil, "Account not available.";
end
function provider.user_exists(username)
- local account = datamanager.load(username, host, "accounts");
+ local account = accounts:get(username);
if not account then
log("debug", "account not found for username '%s' at host '%s'", username, host);
return nil, "Auth failed. Invalid username";
@@ -52,15 +53,15 @@ function provider.user_exists(username)
end
function provider.users()
- return datamanager.users(host, "accounts");
+ return accounts:users();
end
function provider.create_user(username, password)
- return datamanager.store(username, host, "accounts", {password = password});
+ return accounts:set(username, {password = password});
end
function provider.delete_user(username)
- return datamanager.store(username, host, "accounts", nil);
+ return accounts:set(username, nil);
end
function provider.get_sasl_handler()
diff --git a/plugins/mod_privacy.lua b/plugins/mod_privacy.lua
index dc6b153a..31ace9f9 100644
--- a/plugins/mod_privacy.lua
+++ b/plugins/mod_privacy.lua
@@ -10,7 +10,6 @@
module:add_feature("jabber:iq:privacy");
local st = require "util.stanza";
-local datamanager = require "util.datamanager";
local bare_sessions, full_sessions = prosody.bare_sessions, prosody.full_sessions;
local util_Jid = require "util.jid";
local jid_bare = util_Jid.bare;
@@ -18,6 +17,8 @@ local jid_split, jid_join = util_Jid.split, util_Jid.join;
local load_roster = require "core.rostermanager".load_roster;
local to_number = tonumber;
+local privacy_storage = module:open_store();
+
function isListUsed(origin, name, privacy_lists)
local user = bare_sessions[origin.username.."@"..origin.host];
if user then
@@ -217,7 +218,7 @@ module:hook("iq/bare/jabber:iq:privacy:query", function(data)
if stanza.attr.to == nil then -- only service requests to own bare JID
local query = stanza.tags[1]; -- the query element
local valid = false;
- local privacy_lists = datamanager.load(origin.username, origin.host, "privacy") or { lists = {} };
+ local privacy_lists = privacy_storage:get(origin.username) or { lists = {} };
if privacy_lists.lists[1] then -- Code to migrate from old privacy lists format, remove in 0.8
module:log("info", "Upgrading format of stored privacy lists for %s@%s", origin.username, origin.host);
@@ -272,7 +273,7 @@ module:hook("iq/bare/jabber:iq:privacy:query", function(data)
end
origin.send(st.error_reply(stanza, valid[1], valid[2], valid[3]));
else
- datamanager.store(origin.username, origin.host, "privacy", privacy_lists);
+ privacy_storage:set(origin.username, privacy_lists);
end
return true;
end
@@ -280,7 +281,7 @@ end);
function checkIfNeedToBeBlocked(e, session)
local origin, stanza = e.origin, e.stanza;
- local privacy_lists = datamanager.load(session.username, session.host, "privacy") or {};
+ local privacy_lists = privacy_storage:get(session.username) or {};
local bare_jid = session.username.."@"..session.host;
local to = stanza.attr.to or bare_jid;
local from = stanza.attr.from;
diff --git a/plugins/mod_private.lua b/plugins/mod_private.lua
index 29d3162c..365a997c 100644
--- a/plugins/mod_private.lua
+++ b/plugins/mod_private.lua
@@ -9,7 +9,7 @@
local st = require "util.stanza"
-local datamanager = require "util.datamanager"
+local private_storage = module:open_store();
module:add_feature("jabber:iq:private");
@@ -20,7 +20,7 @@ module:hook("iq/self/jabber:iq:private:query", function(event)
if #query.tags == 1 then
local tag = query.tags[1];
local key = tag.name..":"..tag.attr.xmlns;
- local data, err = datamanager.load(origin.username, origin.host, "private");
+ local data, err = private_storage:get(origin.username);
if err then
origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
return true;
@@ -39,7 +39,7 @@ module:hook("iq/self/jabber:iq:private:query", function(event)
data[key] = st.preserialize(tag);
end
-- TODO delete datastore if empty
- if datamanager.store(origin.username, origin.host, "private", data) then
+ if private_storage:set(origin.username, data) then
origin.send(st.reply(stanza));
else
origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
diff --git a/plugins/mod_register.lua b/plugins/mod_register.lua
index e941a128..141a4997 100644
--- a/plugins/mod_register.lua
+++ b/plugins/mod_register.lua
@@ -8,7 +8,6 @@
local st = require "util.stanza";
-local datamanager = require "util.datamanager";
local dataform_new = require "util.dataforms".new;
local usermanager_user_exists = require "core.usermanager".user_exists;
local usermanager_create_user = require "core.usermanager".create_user;
@@ -22,6 +21,8 @@ local compat = module:get_option_boolean("registration_compat", true);
local allow_registration = module:get_option_boolean("allow_registration", false);
local additional_fields = module:get_option("additional_registration_fields", {});
+local account_details = module:open_store("account_details");
+
local field_map = {
username = { name = "username", type = "text-single", label = "Username", required = true };
password = { name = "password", type = "text-private", label = "Password", required = true };
@@ -234,7 +235,7 @@ module:hook("stanza/iq/jabber:iq:register:query", function(event)
-- TODO unable to write file, file may be locked, etc, what's the correct error?
local error_reply = st.error_reply(stanza, "wait", "internal-server-error", "Failed to write data to disk.");
if usermanager_create_user(username, password, host) then
- if next(data) and not datamanager.store(username, host, "account_details", data) then
+ if next(data) and not account_details:set(username, data) then
usermanager_delete_user(username, host);
session.send(error_reply);
return true;
diff --git a/plugins/mod_vcard.lua b/plugins/mod_vcard.lua
index d3c27cc0..26b30e3a 100644
--- a/plugins/mod_vcard.lua
+++ b/plugins/mod_vcard.lua
@@ -8,7 +8,8 @@
local st = require "util.stanza"
local jid_split = require "util.jid".split;
-local datamanager = require "util.datamanager"
+
+local vcards = module:open_store();
module:add_feature("vcard-temp");
@@ -19,9 +20,9 @@ local function handle_vcard(event)
local vCard;
if to then
local node, host = jid_split(to);
- vCard = st.deserialize(datamanager.load(node, host, "vcard")); -- load vCard for user or server
+ vCard = st.deserialize(vcards:get(node)); -- load vCard for user or server
else
- vCard = st.deserialize(datamanager.load(session.username, session.host, "vcard"));-- load user's own vCard
+ vCard = st.deserialize(vcards:get(session.username));-- load user's own vCard
end
if vCard then
session.send(st.reply(stanza):add_child(vCard)); -- send vCard!
@@ -30,7 +31,7 @@ local function handle_vcard(event)
end
else
if not to then
- if datamanager.store(session.username, session.host, "vcard", st.preserialize(stanza.tags[1])) then
+ if vcards:set(session.username, st.preserialize(stanza.tags[1])) then
session.send(st.reply(stanza));
else
-- TODO unable to write file, file may be locked, etc, what's the correct error?
diff --git a/plugins/muc/mod_muc.lua b/plugins/muc/mod_muc.lua
index 2c2d02f7..7861092c 100644
--- a/plugins/muc/mod_muc.lua
+++ b/plugins/muc/mod_muc.lua
@@ -28,13 +28,14 @@ local jid_split = require "util.jid".split;
local jid_bare = require "util.jid".bare;
local st = require "util.stanza";
local uuid_gen = require "util.uuid".generate;
-local datamanager = require "util.datamanager";
local um_is_admin = require "core.usermanager".is_admin;
local hosts = prosody.hosts;
rooms = {};
local rooms = rooms;
-local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {};
+local persistent_rooms_storage = module:open_store("persistent");
+local persistent_rooms = persistent_rooms_storage:get() or {};
+local room_configs = module:open_store("config");
-- Configurable options
muclib.set_max_history_length(module:get_option_number("max_history_messages"));
@@ -66,15 +67,15 @@ local function room_save(room, forced)
_data = room._data;
_affiliations = room._affiliations;
};
- datamanager.store(node, muc_host, "config", data);
+ room_configs:set(node, data);
room._data.history = history;
elseif forced then
- datamanager.store(node, muc_host, "config", nil);
+ room_configs:set(node, nil);
if not next(room._occupants) then -- Room empty
rooms[room.jid] = nil;
end
end
- if forced then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end
+ if forced then persistent_rooms_storage:set(nil, persistent_rooms); end
end
function create_room(jid)
@@ -88,7 +89,7 @@ end
local persistent_errors = false;
for jid in pairs(persistent_rooms) do
local node = jid_split(jid);
- local data = datamanager.load(node, muc_host, "config");
+ local data = room_configs:get(node);
if data then
local room = create_room(jid);
room._data = data._data;
@@ -99,7 +100,7 @@ for jid in pairs(persistent_rooms) do
persistent_errors = true;
end
end
-if persistent_errors then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end
+if persistent_errors then persistent_rooms_storage:set(nil, persistent_rooms); end
local host_room = muc_new_room(muc_host);
host_room.route_stanza = room_route_stanza;