Annotate

plugins/mod_uptime.lua @ 1494:bdfa5274e111

mod_uptime: Convert to unix line endings
author Matthew Wild <mwild1@gmail.com>
date Wed, 08 Jul 2009 04:22:15 +0100
parent 896:2c0b9e3c11c3
child 1495:6c745a108e68
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
896
2c0b9e3c11c3 0.3->0.4
Matthew Wild <mwild1@gmail.com>
parents: 760
diff changeset
1 -- Prosody IM v0.4
760
90ce865eebd8 Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents: 759
diff changeset
2 -- Copyright (C) 2008-2009 Matthew Wild
90ce865eebd8 Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents: 759
diff changeset
3 -- Copyright (C) 2008-2009 Waqas Hussain
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
4 --
758
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
6 -- COPYING file in the source package for more information.
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
7 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
8
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
9
1494
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
10
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
11 local st = require "util.stanza"
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
12
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
13 local jid_split = require "util.jid".split;
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
14 local t_concat = table.concat;
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
15
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
16 local start_time = os.time();
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
17
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
18 module:add_feature("jabber:iq:last");
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
19
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
20 module:add_iq_handler({"c2s", "s2sin"}, "jabber:iq:last",
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
21 function (origin, stanza)
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
22 if stanza.tags[1].name == "query" then
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
23 if stanza.attr.type == "get" then
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
24 local node, host, resource = jid_split(stanza.attr.to);
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
25 if node or resource then
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
26 -- TODO
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
27 else
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
28 origin.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:last", seconds = tostring(os.difftime(os.time(), start_time))}));
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
29 return true;
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
30 end
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
31 end
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
32 end
bdfa5274e111 mod_uptime: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
33 end);