| 1 | -- Prosody IM |
| 2 | -- Copyright (C) 2008-2010 Matthew Wild |
| 3 | -- Copyright (C) 2008-2010 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 | local st = require "util.stanza"; |
| 10 | |
| 11 | module:add_feature("urn:xmpp:ping"); |
| 12 | |
| 13 | local function ping_handler(event) |
| 14 | if event.stanza.attr.type == "get" then |
| 15 | event.origin.send(st.reply(event.stanza)); |
| 16 | return true; |
| 17 | end |
| 18 | end |
| 19 | |
| 20 | module:hook("iq/bare/urn:xmpp:ping:ping", ping_handler); |
| 21 | module:hook("iq/host/urn:xmpp:ping:ping", ping_handler); |
| 22 | |
| 23 | -- Ad-hoc command |
| 24 | |
| 25 | function ping_command_handler (self, data, state) |
| 26 | local now = os.date("%Y-%m-%dT%X"); |
| 27 | return { info = "Pong\n"..now, status = "completed" }; |
| 28 | end |
| 29 | |
| 30 | local adhoc_new = module:require "adhoc".new; |
| 31 | local descriptor = adhoc_new("Ping", "ping", ping_command_handler); |
| 32 | module:add_item ("adhoc", descriptor); |