aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-12-28 20:59:10 +0100
committerKim Alvefur <zash@zash.se>2018-12-28 20:59:10 +0100
commit01878444937fe8b7ea149ef35cd76453517bf798 (patch)
tree2ee613f4433bf488662c8171a64e22804e58c9f2 /plugins
parentb1b7f0261f054bf83a955e073dbdeb9631518097 (diff)
downloadprosody-01878444937fe8b7ea149ef35cd76453517bf798.tar.gz
prosody-01878444937fe8b7ea149ef35cd76453517bf798.zip
mod_admin_telnet: Make xmpp:ping command wait and report the reply
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_admin_telnet.lua23
1 files changed, 19 insertions, 4 deletions
diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua
index bb97a09b..ee6a4176 100644
--- a/plugins/mod_admin_telnet.lua
+++ b/plugins/mod_admin_telnet.lua
@@ -1086,13 +1086,28 @@ end
def_env.xmpp = {};
local st = require "util.stanza";
-function def_env.xmpp:ping(localhost, remotehost)
+local new_id = require "util.id".medium;
+function def_env.xmpp:ping(localhost, remotehost, timeout)
if not prosody.hosts[localhost] then
return nil, "No such host";
end
- module:send(st.iq{ from=localhost, to=remotehost, type="get", id="ping" }
- :tag("ping", {xmlns="urn:xmpp:ping"}), prosody.hosts[localhost]);
- return true, "Sent ping";
+ local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()}
+ :tag("ping", {xmlns="urn:xmpp:ping"});
+ local ret, err;
+ local wait, done = async.waiter();
+ module:context(localhost):send_iq(iq, nil, timeout)
+ :next(function (ret_) ret = ret_; end,
+ function (err_) err = err_; end)
+ :finally(done);
+ wait();
+ if ret then
+ return true, "pong from " .. ret.stanza.attr.from;
+ elseif type(err) == "table" and st.is_stanza(err.stanza) then
+ local t, cond, text = err.stanza:get_error();
+ return false, text or cond or t;
+ else
+ return false, tostring(err);
+ end
end
def_env.dns = {};