Merge 0.7->trunk
[prosody.git] / plugins / mod_ping.lua
index 0e0f565127041437d1804e6ee8966cbfd329353f..61b717a211476773d47520a0a2ad5722e1dc5bce 100644 (file)
@@ -1,20 +1,21 @@
--- Prosody IM v0.2
--- Copyright (C) 2008 Matthew Wild
--- Copyright (C) 2008 Waqas Hussain
+-- Prosody IM
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
 -- 
 -- This project is MIT/X11 licensed. Please see the
 -- COPYING file in the source package for more information.
 --
 
+local st = require "util.stanza";
 
-\r
-local st = require "util.stanza";\r
-\r
-module:add_feature("urn:xmpp:ping");\r
-\r
-module:add_iq_handler({"c2s", "s2sin"}, "urn:xmpp:ping",\r
-       function(session, stanza)\r
-               if stanza.attr.type == "get" then\r
-                       session.send(st.reply(stanza));\r
-               end\r
-       end);\r
+module:add_feature("urn:xmpp:ping");
+
+local function ping_handler(event)
+       if event.stanza.attr.type == "get" then
+               event.origin.send(st.reply(event.stanza));
+               return true;
+       end
+end
+
+module:hook("iq/bare/urn:xmpp:ping:ping", ping_handler);
+module:hook("iq/host/urn:xmpp:ping:ping", ping_handler);