Diff

plugins/mod_uptime.lua @ 235:6526df1a7277

Added mod_uptime: [XEP-0012: Last Activity] queries now work when directed at the server.
author Waqas Hussain <waqas20@gmail.com>
date Mon, 10 Nov 2008 01:33:37 +0500
child 314:851f271d25b0
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/mod_uptime.lua	Mon Nov 10 01:33:37 2008 +0500
@@ -0,0 +1,25 @@
+
+local st = require "util.stanza"
+local send = require "core.sessionmanager".send_to_session
+
+local jid_split = require "util.jid".split;
+local t_concat = table.concat;
+
+local start_time = os.time();
+
+add_iq_handler({"c2s", "s2sin"}, "jabber:iq:last", 
+	function (origin, stanza)
+		if stanza.tags[1].name == "query" then
+			if stanza.attr.type == "get" then
+				local node, host, resource = jid_split(stanza.attr.to);
+				if node or resource then
+					-- TODO
+				else
+					origin.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:last", seconds = tostring(os.difftime(os.time(), start_time))}));
+					return true;
+				end
+			end
+		end
+	end);
+
+