Merge with 0.5
[prosody.git] / plugins / mod_uptime.lua
1 -- Prosody IM
2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
4 -- 
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
8
9
10
11 local st = require "util.stanza"
12
13 local jid_split = require "util.jid".split;
14 local t_concat = table.concat;
15
16 local start_time = prosody.start_time;
17
18 prosody.events.add_handler("server-started", function () start_time = prosody.start_time end);
19
20 module:add_feature("jabber:iq:last");
21
22 module:add_iq_handler({"c2s", "s2sin"}, "jabber:iq:last", 
23         function (origin, stanza)
24                 if stanza.tags[1].name == "query" then
25                         if stanza.attr.type == "get" then
26                                 local node, host, resource = jid_split(stanza.attr.to);
27                                 if node or resource then
28                                         -- TODO
29                                 else
30                                         origin.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:last", seconds = tostring(os.difftime(os.time(), start_time))}));
31                                         return true;
32                                 end
33                         end
34                 end
35         end);