aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2013-04-23 15:14:47 +0100
committerMatthew Wild <mwild1@gmail.com>2013-04-23 15:14:47 +0100
commit106f5079b664a9ceacb77242891e42fa7425115a (patch)
treec9352f3197224088a16296c217e43ec770b21177
parent5d47f4cd480305344b4fbc71c1cf942706444f31 (diff)
parent3b59eb2735ad49245ecf539f65b9fd195a15d4c5 (diff)
downloadprosody-106f5079b664a9ceacb77242891e42fa7425115a.tar.gz
prosody-106f5079b664a9ceacb77242891e42fa7425115a.zip
Merge 0.9->trunk
-rw-r--r--core/moduleapi.lua2
-rw-r--r--core/storagemanager.lua2
-rw-r--r--net/http.lua8
-rw-r--r--net/http/server.lua13
-rw-r--r--plugins/mod_auth_internal_hashed.lua23
-rw-r--r--plugins/mod_auth_internal_plain.lua21
-rw-r--r--plugins/mod_c2s.lua2
-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_s2s/mod_s2s.lua2
-rw-r--r--plugins/mod_vcard.lua9
-rw-r--r--plugins/muc/mod_muc.lua15
13 files changed, 66 insertions, 51 deletions
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index a8e6881e..30360f73 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -338,7 +338,7 @@ function api:load_resource(path, mode)
end
function api:open_store(name, type)
- return storagemanager.open(self.host, name, type);
+ return storagemanager.open(self.host, name or self.name, type);
end
return api;
diff --git a/core/storagemanager.lua b/core/storagemanager.lua
index 36a671be..1c82af6d 100644
--- a/core/storagemanager.lua
+++ b/core/storagemanager.lua
@@ -86,7 +86,7 @@ function open(host, store, typ)
if not ret then
if err == "unsupported-store" then
log("debug", "Storage driver %s does not support store %s (%s), falling back to null driver",
- driver_name, store, typ);
+ driver_name, store, typ or "<nil>");
ret = null_storage_driver;
err = nil;
end
diff --git a/net/http.lua b/net/http.lua
index 639ecf6a..3b783a41 100644
--- a/net/http.lua
+++ b/net/http.lua
@@ -17,9 +17,9 @@ local ssl_available = pcall(require, "ssl");
local server = require "net.server"
local t_insert, t_concat = table.insert, table.concat;
-local pairs, ipairs = pairs, ipairs;
-local tonumber, tostring, xpcall, select, debug_traceback, char, format =
- tonumber, tostring, xpcall, select, debug.traceback, string.char, string.format;
+local pairs = pairs;
+local tonumber, tostring, xpcall, select, traceback =
+ tonumber, tostring, xpcall, select, debug.traceback;
local log = require "util.logger".init("http");
@@ -101,7 +101,7 @@ local function request_reader(request, data, err)
request.parser:feed(data);
end
-local function handleerr(err) log("error", "Traceback[http]: %s: %s", tostring(err), debug_traceback()); end
+local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); end
function request(u, ex, callback)
local req = url.parse(u);
diff --git a/net/http/server.lua b/net/http/server.lua
index a983b8d5..dec7da19 100644
--- a/net/http/server.lua
+++ b/net/http/server.lua
@@ -9,7 +9,7 @@ local pairs = pairs;
local s_upper = string.upper;
local setmetatable = setmetatable;
local xpcall = xpcall;
-local debug = debug;
+local traceback = debug.traceback;
local tostring = tostring;
local codes = require "net.http.codes";
@@ -27,8 +27,11 @@ local function is_wildcard_match(wildcard_event, event)
return wildcard_event:sub(1, -2) == event:sub(1, #wildcard_event-1);
end
+local recent_wildcard_events, max_cached_wildcard_events = {}, 10000;
+
local event_map = events._event_map;
setmetatable(events._handlers, {
+ -- Called when firing an event that doesn't exist (but may match a wildcard handler)
__index = function (handlers, curr_event)
if is_wildcard_event(curr_event) then return; end -- Wildcard events cannot be fired
-- Find all handlers that could match this event, sort them
@@ -58,6 +61,12 @@ setmetatable(events._handlers, {
handlers_array = false;
end
rawset(handlers, curr_event, handlers_array);
+ if not event_map[curr_event] then -- Only wildcard handlers match, if any
+ table.insert(recent_wildcard_events, curr_event);
+ if #recent_wildcard_events > max_cached_wildcard_events then
+ rawset(handlers, table.remove(recent_wildcard_events, 1), nil);
+ end
+ end
return handlers_array;
end;
__newindex = function (handlers, curr_event, handlers_array)
@@ -79,7 +88,7 @@ local _1, _2, _3;
local function _handle_request() return handle_request(_1, _2, _3); end
local last_err;
-local function _traceback_handler(err) last_err = err; log("error", "Traceback[http]: %s: %s", tostring(err), debug.traceback()); end
+local function _traceback_handler(err) last_err = err; log("error", "Traceback[httpserver]: %s", traceback(tostring(err), 2)); end
events.add_handler("http-error", function (error)
return "Error processing request: "..codes[error.code]..". Check your error log for more information.";
end, -1);
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..d226fdbe 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 {};
+ log("debug", "test password for user %s at host %s", username, host);
+ 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_c2s.lua b/plugins/mod_c2s.lua
index 4a3197d9..cafd0c71 100644
--- a/plugins/mod_c2s.lua
+++ b/plugins/mod_c2s.lua
@@ -116,7 +116,7 @@ function stream_callbacks.error(session, error, data)
end
end
-local function handleerr(err) log("error", "Traceback[c2s]: %s: %s", tostring(err), traceback()); end
+local function handleerr(err) log("error", "Traceback[c2s]: %s", traceback(tostring(err), 2)); end
function stream_callbacks.handlestanza(session, stanza)
stanza = session.filter("stanzas/in", stanza);
if stanza then
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_s2s/mod_s2s.lua b/plugins/mod_s2s/mod_s2s.lua
index 6764e857..0ece23a6 100644
--- a/plugins/mod_s2s/mod_s2s.lua
+++ b/plugins/mod_s2s/mod_s2s.lua
@@ -429,7 +429,7 @@ function stream_callbacks.error(session, error, data)
end
end
-local function handleerr(err) log("error", "Traceback[s2s]: %s: %s", tostring(err), traceback()); end
+local function handleerr(err) log("error", "Traceback[s2s]: %s", traceback(tostring(err), 2)); end
function stream_callbacks.handlestanza(session, stanza)
if stanza.attr.xmlns == "jabber:client" then --COMPAT: Prosody pre-0.6.2 may send jabber:client
stanza.attr.xmlns = nil;
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;