aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-11-13 23:10:13 +0000
committerMatthew Wild <mwild1@gmail.com>2010-11-13 23:10:13 +0000
commitac170b59fed35b0bc465605345b4ad258c56520f (patch)
tree11cf4560756af62653db3f8024ca9587f02197f8
parent60f1317b8728e8ea8c367f9f344216fb6cf0a948 (diff)
downloadprosody-ac170b59fed35b0bc465605345b4ad258c56520f.tar.gz
prosody-ac170b59fed35b0bc465605345b4ad258c56520f.zip
util.filters: Support for 'filter hooks' that get called when a session is initialized for filters
-rw-r--r--util/filters.lua13
1 files changed, 12 insertions, 1 deletions
diff --git a/util/filters.lua b/util/filters.lua
index 08e683c1..f304e71a 100644
--- a/util/filters.lua
+++ b/util/filters.lua
@@ -10,6 +10,8 @@ local t_insert, t_remove = table.insert, table.remove;
module "filters"
+local new_filter_hooks = {};
+
function initialize(session)
if not session.filters then
local filters = {};
@@ -19,13 +21,18 @@ function initialize(session)
local filter_list = filters[type];
if filter_list then
for i = 1, #filter_list do
- data = filter_list[i](data);
+ data = filter_list[i](data, session);
if data == nil then break; end
end
end
return data;
end
end
+
+ for i=1,#new_filter_hooks do
+ new_filter_hooks[i](session);
+ end
+
return session.filter;
end
@@ -65,4 +72,8 @@ function remove_filter(session, type, callback)
end
end
+function add_filter_hook(callback)
+ t_insert(new_filter_hooks, callback);
+end
+
return _M;