Software /
code /
prosody
Comparison
plugins/mod_admin_telnet.lua @ 9736:a5ae3f4e1a40
mod_admin_telnet: Make xmpp:ping command wait and report the reply
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 28 Dec 2018 20:59:10 +0100 |
parent | 9735:2d8ca54ecbc6 |
child | 9741:d46c376dfe2c |
comparison
equal
deleted
inserted
replaced
9735:2d8ca54ecbc6 | 9736:a5ae3f4e1a40 |
---|---|
1084 end | 1084 end |
1085 | 1085 |
1086 def_env.xmpp = {}; | 1086 def_env.xmpp = {}; |
1087 | 1087 |
1088 local st = require "util.stanza"; | 1088 local st = require "util.stanza"; |
1089 function def_env.xmpp:ping(localhost, remotehost) | 1089 local new_id = require "util.id".medium; |
1090 function def_env.xmpp:ping(localhost, remotehost, timeout) | |
1090 if not prosody.hosts[localhost] then | 1091 if not prosody.hosts[localhost] then |
1091 return nil, "No such host"; | 1092 return nil, "No such host"; |
1092 end | 1093 end |
1093 module:send(st.iq{ from=localhost, to=remotehost, type="get", id="ping" } | 1094 local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()} |
1094 :tag("ping", {xmlns="urn:xmpp:ping"}), prosody.hosts[localhost]); | 1095 :tag("ping", {xmlns="urn:xmpp:ping"}); |
1095 return true, "Sent ping"; | 1096 local ret, err; |
1097 local wait, done = async.waiter(); | |
1098 module:context(localhost):send_iq(iq, nil, timeout) | |
1099 :next(function (ret_) ret = ret_; end, | |
1100 function (err_) err = err_; end) | |
1101 :finally(done); | |
1102 wait(); | |
1103 if ret then | |
1104 return true, "pong from " .. ret.stanza.attr.from; | |
1105 elseif type(err) == "table" and st.is_stanza(err.stanza) then | |
1106 local t, cond, text = err.stanza:get_error(); | |
1107 return false, text or cond or t; | |
1108 else | |
1109 return false, tostring(err); | |
1110 end | |
1096 end | 1111 end |
1097 | 1112 |
1098 def_env.dns = {}; | 1113 def_env.dns = {}; |
1099 local adns = require"net.adns"; | 1114 local adns = require"net.adns"; |
1100 local dns = require"net.dns"; | 1115 local dns = require"net.dns"; |