Software /
code /
verse
Annotate
plugins/ping.lua @ 155:9c9af7a196ed
plugins.private, squishy: Allow setting the storage node, and not just child(s). And add to squishy.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 20 Nov 2010 17:27:03 +0100 |
parent | 147:c95b84ed366b |
child | 250:a5ac643a7fd6 |
rev | line source |
---|---|
36
fc2cd2f36cdd
plugins.ping: Define xmlns_ping namespace
Matthew Wild <mwild1@gmail.com>
parents:
34
diff
changeset
|
1 local xmlns_ping = "urn:xmpp:ping"; |
32
391048601d54
plugins.ping: Add ping plugin to XMPP ping a JID
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
391048601d54
plugins.ping: Add ping plugin to XMPP ping a JID
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 function verse.plugins.ping(stream) |
391048601d54
plugins.ping: Add ping plugin to XMPP ping a JID
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 function stream:ping(jid, callback) |
391048601d54
plugins.ping: Add ping plugin to XMPP ping a JID
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local t = socket.gettime(); |
391048601d54
plugins.ping: Add ping plugin to XMPP ping a JID
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 stream:send_iq(verse.iq{ to = jid, type = "get" }:tag("ping", { xmlns = xmlns_ping }), |
391048601d54
plugins.ping: Add ping plugin to XMPP ping a JID
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 function (reply) |
41
1a1bd8cd4bdb
plugins.ping: Don't handle all errors as successful pongs, call callback with nil time and 3rd parameter a table with error info
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
8 if reply.attr.type == "error" then |
1a1bd8cd4bdb
plugins.ping: Don't handle all errors as successful pongs, call callback with nil time and 3rd parameter a table with error info
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
9 local type, condition, text = reply:get_error(); |
1a1bd8cd4bdb
plugins.ping: Don't handle all errors as successful pongs, call callback with nil time and 3rd parameter a table with error info
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
10 if condition ~= "service-unavailable" and condition ~= "feature-not-implemented" then |
1a1bd8cd4bdb
plugins.ping: Don't handle all errors as successful pongs, call callback with nil time and 3rd parameter a table with error info
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
11 callback(nil, jid, { type = type, condition = condition, text = text }); |
1a1bd8cd4bdb
plugins.ping: Don't handle all errors as successful pongs, call callback with nil time and 3rd parameter a table with error info
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
12 return; |
1a1bd8cd4bdb
plugins.ping: Don't handle all errors as successful pongs, call callback with nil time and 3rd parameter a table with error info
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
13 end |
1a1bd8cd4bdb
plugins.ping: Don't handle all errors as successful pongs, call callback with nil time and 3rd parameter a table with error info
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
14 end |
32
391048601d54
plugins.ping: Add ping plugin to XMPP ping a JID
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 callback(socket.gettime()-t, jid); |
391048601d54
plugins.ping: Add ping plugin to XMPP ping a JID
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 end); |
391048601d54
plugins.ping: Add ping plugin to XMPP ping a JID
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 end |
34
dd5899412e3f
plugins.ping: Return true on module load to indicate load success
Matthew Wild <mwild1@gmail.com>
parents:
32
diff
changeset
|
18 return true; |
32
391048601d54
plugins.ping: Add ping plugin to XMPP ping a JID
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 end |