Comparison

plugins/mod_time.lua @ 2012:12131e7d3c25

mod_time: Updated to use events (which also fixes a few minor issues).
author Waqas Hussain <waqas20@gmail.com>
date Sun, 18 Oct 2009 18:45:41 +0500
parent 1523:841d61be198f
child 2923:b7049746bd29
comparison
equal deleted inserted replaced
2011:8159497c86e3 2012:12131e7d3c25
3 -- Copyright (C) 2008-2009 Waqas Hussain 3 -- Copyright (C) 2008-2009 Waqas Hussain
4 -- 4 --
5 -- This project is MIT/X11 licensed. Please see the 5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8
9
10 8
11 local st = require "util.stanza"; 9 local st = require "util.stanza";
12 local datetime = require "util.datetime".datetime; 10 local datetime = require "util.datetime".datetime;
13 local legacy = require "util.datetime".legacy; 11 local legacy = require "util.datetime".legacy;
14 12
15 -- XEP-0202: Entity Time 13 -- XEP-0202: Entity Time
16 14
17 module:add_feature("urn:xmpp:time"); 15 module:add_feature("urn:xmpp:time");
18 16
19 module:add_iq_handler({"c2s", "s2sin"}, "urn:xmpp:time", 17 local function time_handler(event)
20 function(session, stanza) 18 local origin, stanza = event.origin, event.stanza;
21 if stanza.attr.type == "get" then 19 if stanza.attr.type == "get" then
22 session.send(st.reply(stanza):tag("time", {xmlns="urn:xmpp:time"}) 20 origin.send(st.reply(stanza):tag("time", {xmlns="urn:xmpp:time"})
23 :tag("tzo"):text("+00:00"):up() -- FIXME get the timezone in a platform independent fashion 21 :tag("tzo"):text("+00:00"):up() -- TODO get the timezone in a platform independent fashion
24 :tag("utc"):text(datetime())); 22 :tag("utc"):text(datetime()));
25 end 23 return true;
26 end); 24 end
25 end
26
27 module:hook("iq/bare/urn:xmpp:time:time", time_handler);
28 module:hook("iq/host/urn:xmpp:time:time", time_handler);
27 29
28 -- XEP-0090: Entity Time (deprecated) 30 -- XEP-0090: Entity Time (deprecated)
29 31
30 module:add_feature("jabber:iq:time"); 32 module:add_feature("jabber:iq:time");
31 33
32 module:add_iq_handler({"c2s", "s2sin"}, "jabber:iq:time", 34 local function legacy_time_handler(event)
33 function(session, stanza) 35 local origin, stanza = event.origin, event.stanza;
34 if stanza.attr.type == "get" then 36 if stanza.attr.type == "get" then
35 session.send(st.reply(stanza):tag("query", {xmlns="jabber:iq:time"}) 37 origin.send(st.reply(stanza):tag("query", {xmlns="jabber:iq:time"})
36 :tag("utc"):text(legacy())); 38 :tag("utc"):text(legacy()));
37 end 39 return true;
38 end); 40 end
41 end
42
43 module:hook("iq/bare/jabber:iq:time:query", legacy_time_handler);
44 module:hook("iq/host/jabber:iq:time:query", legacy_time_handler);