Changeset

1658:0baa849761b6

Merge with Tobias
author Matthew Wild <mwild1@gmail.com>
date Mon, 10 Aug 2009 14:29:28 +0100
parents 1655:dc42bf326713 (diff) 1657:1fe566011e2b (current diff)
children 1659:6092fc9b078b
files
diffstat 8 files changed, 50 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sun Aug 09 21:19:03 2009 +0200
+++ b/Makefile	Mon Aug 10 14:29:28 2009 +0100
@@ -71,7 +71,7 @@
 	sed 's|certs/|$(INSTALLEDCONFIG)/certs/|' prosody.cfg.lua.dist > prosody.cfg.lua.install
 
 prosody.release:
-	test -e .hg/dirstate && hexdump -n6 -e'6/1 "%01x"' .hg/dirstate \
+	test -e .hg/dirstate && hexdump -n6 -e'6/1 "%02x"' .hg/dirstate \
 	    > prosody.version || true
 
 prosody.version: prosody.release
--- a/plugins/mod_bosh.lua	Sun Aug 09 21:19:03 2009 +0200
+++ b/plugins/mod_bosh.lua	Mon Aug 10 14:29:28 2009 +0100
@@ -6,7 +6,6 @@
 -- COPYING file in the source package for more information.
 --
 
-
 module.host = "*" -- Global module
 
 local hosts = _G.hosts;
@@ -23,14 +22,13 @@
 local logger = require "util.logger";
 local log = logger.init("mod_bosh");
 local stream_callbacks = { stream_tag = "http://jabber.org/protocol/httpbind|body" };
-local config = require "core.configmanager";
 local xmlns_bosh = "http://jabber.org/protocol/httpbind"; -- (hard-coded into a literal in session.send)
 
-local BOSH_DEFAULT_HOLD = tonumber(config.get("*", "core", "bosh_default_hold")) or 1;
-local BOSH_DEFAULT_INACTIVITY = tonumber(config.get("*", "core", "bosh_max_inactivity")) or 60;
-local BOSH_DEFAULT_POLLING = tonumber(config.get("*", "core", "bosh_max_polling")) or 5;
-local BOSH_DEFAULT_REQUESTS = tonumber(config.get("*", "core", "bosh_max_requests")) or 2;
-local BOSH_DEFAULT_MAXPAUSE = tonumber(config.get("*", "core", "bosh_max_pause")) or 300;
+local BOSH_DEFAULT_HOLD = tonumber(module:get_option("bosh_default_hold")) or 1;
+local BOSH_DEFAULT_INACTIVITY = tonumber(module:get_option("bosh_max_inactivity")) or 60;
+local BOSH_DEFAULT_POLLING = tonumber(module:get_option("bosh_max_polling")) or 5;
+local BOSH_DEFAULT_REQUESTS = tonumber(module:get_option("bosh_max_requests")) or 2;
+local BOSH_DEFAULT_MAXPAUSE = tonumber(module:get_option("bosh_max_pause")) or 300;
 
 local default_headers = { ["Content-Type"] = "text/xml; charset=utf-8" };
 
@@ -275,7 +273,7 @@
 	end
 end
 
-local ports = config.get(module.host, "core", "bosh_ports") or { 5280 };
+local ports = module:get_option("bosh_ports") or { 5280 };
 httpserver.new_from_config(ports, "http-bind", handle_request);
 
 server.addtimer(on_timer);
--- a/plugins/mod_selftests.lua	Sun Aug 09 21:19:03 2009 +0200
+++ b/plugins/mod_selftests.lua	Mon Aug 10 14:29:28 2009 +0100
@@ -6,14 +6,13 @@
 -- COPYING file in the source package for more information.
 --
 
-
+module.host = "*" -- Global module
 
 local st = require "util.stanza";
 local register_component = require "core.componentmanager".register_component;
 local core_route_stanza = core_route_stanza;
 local socket = require "socket";
-local config = require "core.configmanager";
-local ping_hosts = config.get("*", "mod_selftests", "ping_hosts") or { "coversant.interop.xmpp.org", "djabberd.interop.xmpp.org", "djabberd-trunk.interop.xmpp.org", "ejabberd.interop.xmpp.org", "openfire.interop.xmpp.org" };
+local ping_hosts = module:get_option("ping_hosts") or { "coversant.interop.xmpp.org", "djabberd.interop.xmpp.org", "djabberd-trunk.interop.xmpp.org", "ejabberd.interop.xmpp.org", "openfire.interop.xmpp.org" };
 
 local open_pings = {};
 
--- a/plugins/mod_tls.lua	Sun Aug 09 21:19:03 2009 +0200
+++ b/plugins/mod_tls.lua	Mon Aug 10 14:29:28 2009 +0100
@@ -6,14 +6,11 @@
 -- COPYING file in the source package for more information.
 --
 
-
-
 local st = require "util.stanza";
 
 local xmlns_starttls ='urn:ietf:params:xml:ns:xmpp-tls';
 
-local config = require "core.configmanager";
-local secure_auth_only = config.get("*", "core", "require_encryption");
+local secure_auth_only = module:get_option("require_encryption");
 
 module:add_handler("c2s_unauthed", "starttls", xmlns_starttls,
 		function (session, stanza)
--- a/plugins/mod_version.lua	Sun Aug 09 21:19:03 2009 +0200
+++ b/plugins/mod_version.lua	Mon Aug 10 14:29:28 2009 +0100
@@ -6,17 +6,13 @@
 -- COPYING file in the source package for more information.
 --
 
-
-local prosody = prosody;
 local st = require "util.stanza";
 
-local xmlns_version = "jabber:iq:version"
-
-module:add_feature(xmlns_version);
+module:add_feature("jabber:iq:version");
 
 local version = "the best operating system ever!";
 
-if not require "core.configmanager".get("*", "core", "hide_os_type") then
+if not module:get_option("hide_os_type") then
 	if os.getenv("WINDIR") then
 		version = "Windows";
 	else
@@ -31,11 +27,15 @@
 
 version = version:match("^%s*(.-)%s*$") or version;
 
-module:add_iq_handler({"c2s", "s2sin"}, xmlns_version, function(session, stanza)
-	if stanza.attr.type == "get" then
-		session.send(st.reply(stanza):query(xmlns_version)
-			:tag("name"):text("Prosody"):up()
-			:tag("version"):text(prosody.version):up()
-			:tag("os"):text(version));
+local query = st.stanza("query", {xmlns = "jabber:iq:version"})
+	:tag("name"):text("Prosody"):up()
+	:tag("version"):text(prosody.version):up()
+	:tag("os"):text(version);
+
+module:hook("iq/host/jabber:iq:version:query", function(event)
+	local stanza = event.stanza;
+	if stanza.attr.type == "get" and stanza.attr.to == module.host then
+		event.origin.send(st.reply(stanza):add_child(query));
+		return true;
 	end
 end);
--- a/plugins/mod_watchregistrations.lua	Sun Aug 09 21:19:03 2009 +0200
+++ b/plugins/mod_watchregistrations.lua	Mon Aug 10 14:29:28 2009 +0100
@@ -9,12 +9,10 @@
 
 local host = module:get_host();
 
-local config = require "core.configmanager";
+local registration_watchers = module:get_option("registration_watchers") 
+	or module:get_option("admins") or {};
 
-local registration_watchers = config.get(host, "core", "registration_watchers") 
-	or config.get(host, "core", "admins") or {};
-
-local registration_alert = config.get(host, "core", "registration_notification") or "User $username just registered on $host from $ip";
+local registration_alert = module:get_option("registration_notification") or "User $username just registered on $host from $ip";
 
 local st = require "util.stanza";
 
--- a/plugins/mod_welcome.lua	Sun Aug 09 21:19:03 2009 +0200
+++ b/plugins/mod_welcome.lua	Mon Aug 10 14:29:28 2009 +0100
@@ -6,10 +6,8 @@
 -- COPYING file in the source package for more information.
 --
 
-local config = require "core.configmanager";
-
 local host = module:get_host();
-local welcome_text = config.get("*", "core", "welcome_message") or "Hello $user, welcome to the $host IM server!";
+local welcome_text = module:get_option("welcome_message") or "Hello $user, welcome to the $host IM server!";
 
 local st = require "util.stanza";
 
--- a/tools/ejabberdsql2prosody.lua	Sun Aug 09 21:19:03 2009 +0200
+++ b/tools/ejabberdsql2prosody.lua	Mon Aug 10 14:29:28 2009 +0100
@@ -136,8 +136,8 @@
 	while true do
 		local tname, tuples = readInsert();
 		if tname then
-			if t[name] then
-				local t_name = t[name];
+			if t[tname] then
+				local t_name = t[tname];
 				for i=1,#tuples do
 					table.insert(t_name, tuples[i]);
 				end
@@ -284,6 +284,12 @@
 	local ret, err = dm.store(node, host, "private", private);
 	print("["..(err or "success").."] private: " ..node.."@"..host.." - "..xmlns);
 end
+function offline_msg(node, host, t, stanza)
+	stanza.attr.stamp = os.date("!%Y-%m-%dT%H:%M:%SZ", t);
+	stanza.attr.stamp_legacy = os.date("!%Y%m%dT%H:%M:%S", t);
+	local ret, err = dm.list_append(node, host, "offline", st.preserialize(stanza));
+	print("["..(err or "success").."] offline: " ..node.."@"..host.." - "..os.date("!%Y-%m-%dT%H:%M:%SZ", t));
+end
 for i, row in ipairs(t["rosterusers"] or NULL) do
 	local node, contact = row.username, row.jid;
 	local name = row.nick;
@@ -321,5 +327,20 @@
 	print("["..(err or "success").."] vCard: "..row.username.."@"..host);
 end
 for i, row in ipairs(t["private_storage"] or NULL) do
-	private_storage(row.username, host, row.namespace, st.preserialize(parse_xml(row.data)));
+	private_storage(row.username, host, row.namespace, parse_xml(row.data));
+end
+table.sort(t["spool"] or NULL, function(a,b) return a.seq < b.seq; end); -- sort by sequence number, just in case
+local time_offset = os.difftime(os.time(os.date("!*t")), os.time(os.date("*t"))) -- to deal with timezones
+local date_parse = function(s)
+	local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)");
+	return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec-time_offset});
 end
+for i, row in ipairs(t["spool"] or NULL) do
+	local stanza = parse_xml(row.xml);
+	local last_child = stanza.tags[#stanza.tags];
+	if not last_child or last_child ~= stanza[#stanza] then error("Last child of offline message is not a tag"); end
+	if last_child.name ~= "x" and last_child.attr.xmlns ~= "jabber:x:delay" then error("Last child of offline message is not a timestamp"); end
+	stanza[#stanza], stanza.tags[#stanza.tags] = nil, nil;
+	local t = date_parse(last_child.attr.stamp);
+	offline_msg(row.username, host, t, stanza);
+end