aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2015-05-03 18:39:27 +0200
committerKim Alvefur <zash@zash.se>2015-05-03 18:39:27 +0200
commit009cde88a5518e95481126c547bf0b79f95ac797 (patch)
tree1db58cd52f622c3560457cf589cdc8e6326d28e6
parent86867275492107937cea9b5887de077679bc751d (diff)
parenta7606f77d99c798faa7067331e5b9ac0272c5ad1 (diff)
downloadprosody-009cde88a5518e95481126c547bf0b79f95ac797.tar.gz
prosody-009cde88a5518e95481126c547bf0b79f95ac797.zip
Merge 0.10->trunk
-rw-r--r--core/moduleapi.lua31
-rw-r--r--net/dns.lua2
-rwxr-xr-xprosodyctl2
-rw-r--r--util-src/encodings.c5
-rw-r--r--util-src/pposix.c5
-rw-r--r--util/datamanager.lua2
-rw-r--r--util/events.lua68
7 files changed, 108 insertions, 7 deletions
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index d6aa0ef0..9845c227 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -122,6 +122,18 @@ function api:unhook(event, handler)
return self:unhook_object_event((hosts[self.host] or prosody).events, event, handler);
end
+function api:wrap_object_event(events_object, event, handler)
+ return self:hook_object_event(assert(events_object.wrappers, "no wrappers"), event, handler);
+end
+
+function api:wrap_event(event, handler)
+ return self:wrap_object_event((hosts[self.host] or prosody).events, event, handler);
+end
+
+function api:wrap_global(event, handler)
+ return self:hook_object_event(prosody.events, event, handler, priority);
+end
+
function api:require(lib)
local f, n = pluginloader.load_code(self.name, lib..".lib.lua", self.environment);
if not f then
@@ -395,6 +407,25 @@ function api:measure(name, type)
return measure(type, "/"..self.host.."/mod_"..self.name.."/"..name);
end
+function api:measure_object_event(events_object, event_name, stat_name)
+ local m = self:measure(stat_name or event_name, "duration");
+ local function handler(handlers, event_name, event_data)
+ local finished = m();
+ local ret = handlers(event_name, event_data);
+ finished();
+ return ret;
+ end
+ return self:hook_object_event(events_object, event_name, handler);
+end
+
+function api:measure_event(event_name, stat_name)
+ return self:hook_object_event((hosts[self.host] or prosody).events.wrappers, event_name, handler);
+end
+
+function api:measure_global_event(event_name, stat_name)
+ return self:hook_object_event(prosody.events.wrappers, event_name, handler);
+end
+
function api.init(mm)
modulemanager = mm;
return api;
diff --git a/net/dns.lua b/net/dns.lua
index 2128fb1a..037f3ec6 100644
--- a/net/dns.lua
+++ b/net/dns.lua
@@ -226,7 +226,7 @@ end
function dns.random(...) -- - - - - - - - - - - - - - - - - - - dns.random
- math.randomseed(math.floor(10000*socket.gettime()) % 0x100000000);
+ math.randomseed(math.floor(10000*socket.gettime()) % 0x80000000);
dns.random = math.random;
return dns.random(...);
end
diff --git a/prosodyctl b/prosodyctl
index e8fca0ce..ef436106 100755
--- a/prosodyctl
+++ b/prosodyctl
@@ -1146,7 +1146,7 @@ function commands.check(arg)
end
if (not (config.get(host, "anonymous_login")
or config.get(host, "authentication") == "anonymous"))
- and not x509_verify_identity(host, "_xmpp-client", cert) then
+ and not x509_verify_identity(host, "_xmpp-server", cert) then
print(" Not vaild for server-to-server connections to "..host..".")
cert_ok = false
end
diff --git a/util-src/encodings.c b/util-src/encodings.c
index 2eaad2c8..c00b2267 100644
--- a/util-src/encodings.c
+++ b/util-src/encodings.c
@@ -476,14 +476,15 @@ static int Lidna_to_unicode(lua_State* L) { /** idna.to_unicode(s) */
static int Lidna_to_ascii(lua_State* L) { /** idna.to_ascii(s) */
size_t len;
const char* s = check_utf8(L, 1, &len);
+ char* output = NULL;
+ int ret;
if(s == NULL || len != strlen(s)) {
lua_pushnil(L);
return 1; /* TODO return error message */
}
- char* output = NULL;
- int ret = idna_to_ascii_8z(s, &output, IDNA_USE_STD3_ASCII_RULES);
+ ret = idna_to_ascii_8z(s, &output, IDNA_USE_STD3_ASCII_RULES);
if(ret == IDNA_SUCCESS) {
lua_pushstring(L, output);
diff --git a/util-src/pposix.c b/util-src/pposix.c
index d797f032..5288b08c 100644
--- a/util-src/pposix.c
+++ b/util-src/pposix.c
@@ -750,7 +750,10 @@ int lc_fallocate(lua_State* L) {
lua_pushstring(L, strerror(ret));
/* posix_fallocate() can leave a bunch of NULs at the end, so we cut that
* this assumes that offset == length of the file */
- ftruncate(fileno(f), offset);
+ if(ftruncate(fileno(f), offset) != 0) {
+ lua_pushstring(L, strerror(errno));
+ return 3;
+ }
return 2;
}
}
diff --git a/util/datamanager.lua b/util/datamanager.lua
index b82349f1..b4138638 100644
--- a/util/datamanager.lua
+++ b/util/datamanager.lua
@@ -293,7 +293,7 @@ function users(host, store, typ)
local mode, err = lfs.attributes(store_dir, "mode");
if not mode then
- return function() log("debug", err or (store_dir .. " does not exist")) end
+ return function() log("debug", "%s", err or (store_dir .. " does not exist")) end
end
local next, state = lfs.dir(store_dir);
return function(state)
diff --git a/util/events.lua b/util/events.lua
index 40ca3913..79de1151 100644
--- a/util/events.lua
+++ b/util/events.lua
@@ -17,6 +17,8 @@ module "events"
function new()
local handlers = {};
+ local global_wrappers;
+ local wrappers = {};
local event_map = {};
local function _rebuild_index(handlers, event)
local _handlers = event_map[event];
@@ -60,7 +62,7 @@ function new()
remove_handler(event, handler);
end
end;
- local function fire_event(event_name, event_data)
+ local function _fire_event(event_name, event_data)
local h = handlers[event_name];
if h then
for i=1,#h do
@@ -69,11 +71,75 @@ function new()
end
end
end;
+ local function fire_event(event_name, event_data)
+ local w = wrappers[event_name] or global_wrappers;
+ if w then
+ local curr_wrapper = #w;
+ local function c(event_name, event_data)
+ curr_wrapper = curr_wrapper - 1;
+ if curr_wrapper == 0 then
+ if global_wrappers == nil or w == global_wrappers then
+ return _fire_event(event_name, event_data);
+ end
+ w, curr_wrapper = global_wrappers, #global_wrappers;
+ return w[curr_wrapper](c, event_name, event_data);
+ else
+ return w[curr_wrapper](c, event_name, event_data);
+ end
+ end
+ return w[curr_wrapper](c, event_name, event_data);
+ end
+ return _fire_event(event_name, event_data);
+ end
+ local function add_wrapper(event_name, wrapper)
+ local w;
+ if event_name == false then
+ w = global_wrappers;
+ if not w then
+ w = {};
+ global_wrappers = w;
+ end
+ else
+ w = wrappers[event_name];
+ if not w then
+ w = {};
+ wrappers[event_name] = w;
+ end
+ end
+ w[#w+1] = wrapper;
+ end
+ local function remove_wrapper(event_name, wrapper)
+ local w;
+ if event_name == false then
+ w = global_wrappers;
+ else
+ w = wrappers[event_name];
+ end
+ if not w then return; end
+ for i = #w, 1 do
+ if w[i] == wrapper then
+ table.remove(w, i);
+ end
+ end
+ if #w == 0 then
+ if event_name == nil then
+ global_wrappers = nil;
+ else
+ wrappers[event_name] = nil;
+ end
+ end
+ end
return {
add_handler = add_handler;
remove_handler = remove_handler;
add_handlers = add_handlers;
remove_handlers = remove_handlers;
+ wrappers = {
+ add_handler = add_wrapper;
+ remove_handler = remove_wrapper;
+ };
+ add_wrapper = add_wrapper;
+ remove_wrapper = remove_wrapper;
fire_event = fire_event;
_handlers = handlers;
_event_map = event_map;