else
log("error", "SSL/TLS: Error initialising for host %s: %s", host, err );
end
- end
- return ctx, err;
+ end
+ return ctx, err;
end
function reload_ssl_config()
ssl_ctx_in = certmanager.create_context(host, "server");
end
end
- return { type = "component", host = host, connected = true, s2sout = {},
+ return { type = "component", host = host, connected = true, s2sout = {},
ssl_ctx = ssl_ctx, ssl_ctx_in = ssl_ctx_in, events = events or events_new(),
dialback_secret = configmanager.get(host, "core", "dialback_secret") or uuid_gen(),
disallow_s2s = configmanager.get(host, "core", "disallow_s2s"); };
local format, rep = string.format, string.rep;
local pcall = pcall;
local debug = debug;
-local tostring, setmetatable, rawset, pairs, ipairs, type =
+local tostring, setmetatable, rawset, pairs, ipairs, type =
tostring, setmetatable, rawset, pairs, ipairs, type;
local io_open, io_write = io.open, io.write;
local math_max, rep = math.max, string.rep;
default_logging = { { to = "console" , levels = { min = (debug_mode and "debug") or "info" } } };
default_file_logging = {
- { to = "file", levels = { min = (debug_mode and "debug") or "info" }, timestamps = true }
+ { to = "file", levels = { min = (debug_mode and "debug") or "info" }, timestamps = true }
};
default_timestamp = "%b %d %H:%M:%S";
local format = string.format;
local t_insert, t_sort = table.insert, table.sort;
local get_traceback = debug.traceback;
-local tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber,
- setmetatable
- = tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber,
- setmetatable;
+local tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber, setmetatable
+ = tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber, setmetatable;
local idna_to_ascii = require "util.encodings".idna.to_ascii;
local connlisteners_get = require "net.connlisteners".get;
host_session.users = new_null_provider();
end
end);
- host_session.users = new_null_provider(); -- Start with the default usermanager provider
- local auth_provider = config.get(host, "core", "authentication") or default_provider;
- if auth_provider ~= "null" then
- modulemanager.load(host, "auth_"..auth_provider);
- end
+ host_session.users = new_null_provider(); -- Start with the default usermanager provider
+ local auth_provider = config.get(host, "core", "authentication") or default_provider;
+ if auth_provider ~= "null" then
+ modulemanager.load(host, "auth_"..auth_provider);
+ end
end;
prosody.events.add_handler("host-activated", initialize_host, 100);
prosody.events.add_handler("component-activated", initialize_host, 100);
attr[i] = nil;
local ns, nm = k:match(ns_pattern);
if nm ~= "" then
- ns = ns_prefixes[ns];
- if ns then
+ ns = ns_prefixes[ns];
+ if ns then
attr[ns..":"..nm] = attr[k];
attr[k] = nil;
end
local log = require "util.logger".init("connlisteners");
local tostring = tostring;
-local dofile, pcall, error =
- dofile, pcall, error
+local dofile, pcall, error =
+ dofile, pcall, error
module "connlisteners"
retry = socket.gettime() + self.delays[1]
};
- -- remember the query
+ -- remember the query
self.active[id] = self.active[id] or {};
self.active[id][question] = o;
- -- remember which coroutine wants the answer
+ -- remember which coroutine wants the answer
local co = coroutine.running();
if co then
set(self.wanted, qclass, qtype, qname, co, true);
end
end
end
-
+
if num == self.best_server then
self.best_server = self.best_server + 1;
if self.best_server > #self.server then
function resolver:lookup(qname, qtype, qclass) -- - - - - - - - - - lookup
self:query (qname, qtype, qclass)
while self:pulse() do
- local recvt = {}
- for i, s in ipairs(self.socket) do
- recvt[i] = s
- end
- socket.select(recvt, nil, 4)
- end
+ local recvt = {}
+ for i, s in ipairs(self.socket) do
+ recvt[i] = s
+ end
+ socket.select(recvt, nil, 4)
+ end
--print(self.cache);
return self:peek(qname, qtype, qclass);
end
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;
+ tonumber, tostring, xpcall, select, debug.traceback, string.char, string.format;
local log = require "util.logger".init("http");
end
local function expectbody(reqt, code)
- if reqt.method == "HEAD" then return nil end
- if code == 204 or code == 304 or code == 301 then return nil end
- if code >= 100 and code < 200 then return nil end
- return 1
+ if reqt.method == "HEAD" then return nil end
+ if code == 204 or code == 304 or code == 301 then return nil end
+ if code >= 100 and code < 200 then return nil end
+ return 1
end
local function request_reader(request, data, startpos)
local default_handler;
local function expectbody(reqt)
- return reqt.method == "POST";
+ return reqt.method == "POST";
end
local function send_response(request, response)
ssl.options = "no_sslv2";
end
- new{ port = port, interface = interface,
- base = base, handler = handle_request,
+ new{ port = port, interface = interface,
+ base = base, handler = handle_request,
ssl = ssl, type = (ssl and "ssl") or "tcp" };
end
end
function stream_callbacks.streamopened(session, attr)
if config.get(attr.to, "core", "component_module") ~= "component" then
- -- Trying to act as a component domain which
+ -- Trying to act as a component domain which
-- hasn't been configured
session:close{ condition = "host-unknown", text = tostring(attr.to).." does not match any configured external components" };
return;
end
- -- Note that we don't create the internal component
+ -- Note that we don't create the internal component
-- until after the external component auths successfully
session.host = attr.to;
stanza = st.error_reply(stanza, data.error.type, data.error.condition, data.error.message);
origin.send(stanza);
return true;
- else
+ else
cmdtag = command:cmdtag("executing", sessionid);
end
local get_user_password_desc = adhoc_new("Get User Password", "http://jabber.org/protocol/admin#get-user-password", get_user_password_handler, "admin");
local get_user_roster_desc = adhoc_new("Get User Roster","http://jabber.org/protocol/admin#get-user-roster", get_user_roster_handler, "admin");
local get_user_stats_desc = adhoc_new("Get User Statistics","http://jabber.org/protocol/admin#user-stats", get_user_stats_handler, "admin");
-local get_online_users_desc = adhoc_new("Get List of Online Users", "http://jabber.org/protocol/admin#get-online-users", get_online_users_command_handler, "admin");
+local get_online_users_desc = adhoc_new("Get List of Online Users", "http://jabber.org/protocol/admin#get-online-users", get_online_users_command_handler, "admin");
local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin");
local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/modules#load", load_module_handler, "admin");
local reload_modules_desc = adhoc_new("Reload module", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin");
-- If component not already created for this host, create one now
if not hosts[session.host].connected then
local send = session.send;
- session.component_session = cm_register_component(session.host, function (_, data)
+ session.component_session = cm_register_component(session.host, function (_, data)
if data.attr and data.attr.xmlns == "jabber:client" then
data.attr.xmlns = nil;
end
module:hook("s2s-stream-features", function(event)
local origin, features = event.origin, event.features;
-- FIXME only advertise compression support when TLS layer has no compression enabled
- if not origin.compressed then
+ if not origin.compressed then
features:add_child(compression_stream_feature);
end
end);
local hours = t%24;
t = (t - hours)/24;
local days = t;
- return true, string.format("This server has been running for %d day%s, %d hour%s and %d minute%s (since %s)",
- days, (days ~= 1 and "s") or "", hours, (hours ~= 1 and "s") or "",
+ return true, string.format("This server has been running for %d day%s, %d hour%s and %d minute%s (since %s)",
+ days, (days ~= 1 and "s") or "", hours, (hours ~= 1 and "s") or "",
minutes, (minutes ~= 1 and "s") or "", os.date("%c", prosody.start_time));
end
end
end
end
- local subhost_filter = function (h)
+ local subhost_filter = function (h)
return (match_jid and h:match(match_jid));
end
for session in pairs(incoming_s2s) do
- if session.to_host == host and ((not match_jid) or host:match(match_jid)
+ if session.to_host == host and ((not match_jid) or host:match(match_jid)
or (session.from_host and session.from_host:match(match_jid))
-- Pft! is what I say to list comprehensions
or (session.hosts and #array.collect(keys(session.hosts)):filter(subhost_filter)>0)) then
if hosts[from] and not hosts[to] then
-- Is an outgoing connection
local session = hosts[from].s2sout[to];
- if not session then
+ if not session then
print("No outgoing connection from "..from.." to "..to)
else
(session.close or s2smanager.destroy_session)(session);
module:hook("message/offline/broadcast", function(event)
local origin = event.origin;
- if origin.priority >= 0 then
- local node, host = origin.username, origin.host;
-
- local data = datamanager.list_load(node, host, "offline");
- if not data then return true; end
- for _, stanza in ipairs(data) do
- stanza = st.deserialize(stanza);
- stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203
- stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated)
- stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;
- origin.send(stanza);
- end
- return true;
- end
+ if origin.priority >= 0 then
+ local node, host = origin.username, origin.host;
+
+ local data = datamanager.list_load(node, host, "offline");
+ if not data then return true; end
+ for _, stanza in ipairs(data) do
+ stanza = st.deserialize(stanza);
+ stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203
+ stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated)
+ stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;
+ origin.send(stanza);
+ end
+ return true;
+ end
end);
module:hook("message/offline/delete", function(event)
end
end
-local syslog_opened
+local syslog_opened;
function syslog_sink_maker(config)
if not syslog_opened then
pposix.syslog_open("prosody");
end
local syslog, format = pposix.syslog_log, string.format;
return function (name, level, message, ...)
- if ... then
- syslog(level, format(message, ...));
- else
- syslog(level, message);
- end
- end;
+ if ... then
+ syslog(level, format(message, ...));
+ else
+ syslog(level, message);
+ end
+ end;
end
require "core.loggingmanager".register_sink_type("syslog", syslog_sink_maker);
priority[1] = "0";
end
end
- local priority = stanza:child_with_name("priority");
- if priority and #priority > 0 then
- priority = t_concat(priority);
- if s_find(priority, "^[+-]?[0-9]+$") then
- priority = tonumber(priority);
- if priority < -128 then priority = -128 end
- if priority > 127 then priority = 127 end
- else priority = 0; end
- else priority = 0; end
+ local priority = stanza:child_with_name("priority");
+ if priority and #priority > 0 then
+ priority = t_concat(priority);
+ if s_find(priority, "^[+-]?[0-9]+$") then
+ priority = tonumber(priority);
+ if priority < -128 then priority = -128 end
+ if priority > 127 then priority = 127 end
+ else priority = 0; end
+ else priority = 0; end
if full_sessions[origin.full_jid] then -- if user is still connected
origin.send(stanza); -- reflect their presence back to them
end
end
end
- if priority >= 0 then
- local offline = offlinemanager.load(node, host);
- if offline then
- for _, msg in ipairs(offline) do
- origin.send(msg); -- FIXME do we need to modify to/from in any way?
- end
- offlinemanager.deleteAll(node, host);
- end
- end
+ if priority >= 0 then
+ local offline = offlinemanager.load(node, host);
+ if offline then
+ for _, msg in ipairs(offline) do
+ origin.send(msg); -- FIXME do we need to modify to/from in any way?
+ end
+ offlinemanager.deleteAll(node, host);
+ end
+ end
end
if stanza.attr.type == "unavailable" then
origin.presence = nil;
if usermanager_create_user(username, password, host) then
session.send(st.reply(stanza)); -- user created!
module:log("info", "User account created: %s@%s", username, host);
- module:fire_event("user-registered", {
+ module:fire_event("user-registered", {
username = username, host = host, source = "mod_register",
session = session });
else
else -- stanza.attr.type == "set"
local query = stanza.tags[1];
if #query.tags == 1 and query.tags[1].name == "item"
- and query.tags[1].attr.xmlns == "jabber:iq:roster" and query.tags[1].attr.jid
+ and query.tags[1].attr.xmlns == "jabber:iq:roster" and query.tags[1].attr.jid
-- Protection against overwriting roster.pending, until we move it
and query.tags[1].attr.jid ~= "pending" then
local item = query.tags[1];
else
r_item.subscription = "none";
end
- for _, child in ipairs(item) do
+ for _, child in ipairs(item) do
if child.name == "group" then
local text = t_concat(child);
if text and text ~= "" then
local hours = t%24;
t = (t - hours)/24;
local days = t;
- return string.format("This server has been running for %d day%s, %d hour%s and %d minute%s (since %s)",
- days, (days ~= 1 and "s") or "", hours, (hours ~= 1 and "s") or "",
+ return string.format("This server has been running for %d day%s, %d hour%s and %d minute%s (since %s)",
+ days, (days ~= 1 and "s") or "", hours, (hours ~= 1 and "s") or "",
minutes, (minutes ~= 1 and "s") or "", os.date("%c", prosody.start_time));
end
local host = module:get_host();
-local registration_watchers = module:get_option("registration_watchers")
+local registration_watchers = module:get_option("registration_watchers")
or module:get_option("admins") or {};
local registration_alert = module:get_option("registration_notification") or "User $username just registered on $host from $ip";
module:log("debug", "Notifying of new registration");
local message = st.message{ type = "chat", from = host }
:tag("body")
- :text(registration_alert:gsub("%$(%w+)",
+ :text(registration_alert:gsub("%$(%w+)",
function (v) return user[v] or user.session and user.session[v] or nil; end));
for _, jid in ipairs(registration_watchers) do
local st = require "util.stanza";
-module:hook("user-registered",
+module:hook("user-registered",
function (user)
- local welcome_stanza =
+ local welcome_stanza =
st.message({ to = user.username.."@"..user.host, from = host })
:tag("body"):text(welcome_text:gsub("$(%w+)", user));
core_route_stanza(hosts[host], welcome_stanza);
end
local valid_whois = {
- moderators = true,
- anyone = true,
+ moderators = true,
+ anyone = true,
}
function room_mt:process_form(origin, stanza)
for line, active in pairs(lines_hit) do
if active ~= nil then total_active_lines = total_active_lines + 1; end
if coverage_file then
- if active == false then coverage_file:write(fn, "|", line, "|", name or "", "|miss\n");
+ if active == false then coverage_file:write(fn, "|", line, "|", name or "", "|miss\n");
else coverage_file:write(fn, "|", line, "|", name or "", "|", tostring(success), "\n"); end
end
end
function set(set, u)
assert_equal(set("*"), false, "Set with no section/key");
- assert_equal(set("*", "set_test"), false, "Set with no key");
+ assert_equal(set("*", "set_test"), false, "Set with no key");
assert_equal(set("*", "set_test", "testkey"), true, "Setting a nil global value");
assert_equal(set("*", "set_test", "testkey", 123), true, "Setting a global value");
function env.core_post_stanza(p_origin, p_stanza)
assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
- target_handled = true;
+ target_handled = true;
end
env.hosts = hosts;
function env.core_route_stanza(p_origin, p_stanza)
assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
- target_routed = true;
+ target_routed = true;
end
function env.core_post_stanza(...) env.core_route_stanza(...); end
function env.core_route_stanza(p_origin, p_stanza)
assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
- target_routed = true;
+ target_routed = true;
end
function env.core_post_stanza(...)
function env.core_route_stanza(p_origin, p_stanza)
assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
- target_routed = true;
+ target_routed = true;
end
function env.core_post_stanza(...)
function env.core_route_stanza(p_origin, p_stanza)
assert_equal(p_origin, s2sin_session, "origin of handled stanza is not correct");
assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
- target_routed = true;
+ target_routed = true;
end
function env.core_post_stanza(...)
function env.core_post_stanza(p_origin, p_stanza)
assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
- target_handled = true;
+ target_handled = true;
end
env.hosts = hosts;
--- WARNING! ---
--- This file contains a mix of encodings below.
+-- This file contains a mix of encodings below.
-- Many editors will unquestioningly convert these for you.
-- Please be careful :( (I recommend Scite)
---------------------------------
-local gmatch = string.gmatch;
-local t_concat, t_insert = table.concat, table.insert;
-local to_byte, to_char = string.byte, string.char;
+local gmatch = string.gmatch;
+local t_concat, t_insert = table.concat, table.insert;
+local to_byte, to_char = string.byte, string.char;
local function _latin1toutf8(str)
- if not str then return str; end
- local p = {};
- for ch in gmatch(str, ".") do
- ch = to_byte(ch);
- if (ch < 0x80) then
- t_insert(p, to_char(ch));
- elseif (ch < 0xC0) then
- t_insert(p, to_char(0xC2, ch));
- else
- t_insert(p, to_char(0xC3, ch - 64));
- end
- end
- return t_concat(p);
- end
+ if not str then return str; end
+ local p = {};
+ for ch in gmatch(str, ".") do
+ ch = to_byte(ch);
+ if (ch < 0x80) then
+ t_insert(p, to_char(ch));
+ elseif (ch < 0xC0) then
+ t_insert(p, to_char(0xC2, ch));
+ else
+ t_insert(p, to_char(0xC3, ch - 64));
+ end
+ end
+ return t_concat(p);
+end
function latin1toutf8()
local function assert_utf8(latin, utf8)
should_have[item] = nil;
end
if next(should_have) then
- return false, "not-enough";
+ return false, "not-enough";
end
return true, "has-all";
end
local inf = debug.getinfo(3, 'Snl');
level = level .. ","..tostring(inf.short_src):match("[^/]*$")..":"..inf.currentline;
end
- if ... then
+ if ... then
print(name, getstring(logstyles[level], level), format(message, ...));
else
print(name, getstring(logstyles[level], level), message);
--print("message :"..ch:pretty_print());
local ret, err = dm.list_append(username, host, "offline", st.preserialize(ch));
print("["..(err or "success").."] stored offline message: " ..username.."@"..host.." - "..ch.attr.from);
- end
+ end
end
-- COPYING file in the source package for more information.
--
-local t_insert, t_sort, t_remove, t_concat
- = table.insert, table.sort, table.remove, table.concat;
+local t_insert, t_sort, t_remove, t_concat
+ = table.insert, table.sort, table.remove, table.concat;
local array = {};
local array_base = {};
--
-local ipairs, pairs, setmetatable, type =
- ipairs, pairs, setmetatable, type;
+local ipairs, pairs, setmetatable, type =
+ ipairs, pairs, setmetatable, type;
module "pubsub"
return data;
end
-field_readers["text-single"] =
+field_readers["text-single"] =
function (field_tag)
local value = field_tag:child_with_name("value");
if value then
end
end
-field_readers["text-private"] =
+field_readers["text-private"] =
field_readers["text-single"];
field_readers["jid-single"] =
field_readers["text-single"];
-field_readers["jid-multi"] =
+field_readers["jid-multi"] =
function (field_tag)
local result = {};
for value_tag in field_tag:childtags() do
return result;
end
-field_readers["text-multi"] =
+field_readers["text-multi"] =
function (field_tag)
local result = {};
for value_tag in field_tag:childtags() do
return result;
end
-field_readers["boolean"] =
+field_readers["boolean"] =
function (field_tag)
local value = field_tag:child_with_name("value");
if value then
else
return false;
end
- end
+ end
end
-field_readers["hidden"] =
+field_readers["hidden"] =
function (field_tag)
local value = field_tag:child_with_name("value");
if value then
blocksize
the blocksize for the hash function in bytes
hex
- return raw hash or hexadecimal string
+ return raw hash or hexadecimal string
--]]
function hmac(key, message, hash, blocksize, hex)
if #key > blocksize then
var = ret[1];
if var == nil then break; end
x = x + 1;
- end
+ end
return x;
end
return t;
end
--- Treat the return of an iterator as key,value pairs,
+-- Treat the return of an iterator as key,value pairs,
-- and build a table
function it2table(f, s, var)
local t, var = {};
end
-- To make sure our cached lengths stay in sync with reality
- modify_hooks[logger] = function () num_level_handlers, num_source_handlers = #level_handlers, source_handlers and #source_handlers; end;
+ modify_hooks[logger] = function () num_level_handlers, num_source_handlers = #level_handlers, source_handlers and #source_handlers; end;
return logger;
end
-- hash algorithm independent Hi(PBKDF2) implementation
function Hi(hmac, str, salt, i)
local Ust = hmac(str, salt.."\0\0\0\1");
- local res = Ust;
+ local res = Ust;
for n=1,i-1 do
local Und = hmac(str, Ust)
res = binaryXOR(res, Und)
-- check for forbidden char sequences
for eq in username:gmatch("=(.?.?)") do
if eq ~= "2D" and eq ~= "3D" then
- return false
- end
+ return false
+ end
end
-- replace =2D with , and =3D with =
-- COPYING file in the source package for more information.
--
-local ipairs, pairs, setmetatable, next, tostring =
+local ipairs, pairs, setmetatable, next, tostring =
ipairs, pairs, setmetatable, next, tostring;
local t_concat = table.concat;
attr[i] = nil;
local ns, nm = k:match(ns_pattern);
if nm ~= "" then
- ns = ns_prefixes[ns];
- if ns then
+ ns = ns_prefixes[ns];
+ if ns then
attr[ns..":"..nm] = attr[k];
attr[k] = nil;
end
f ('[') f (lson_encode (k)) f ('] = ')
lson_encode (v, f, indent+1, indents)
f (',')
- end
+ end
f (' }')
end end end