Version 0.8.90
[emacs-jabber.git] / jabber-ping.el
blob50b625764452d68ad5729a2d052f60d9ca022238
1 ;; jabber-ping.el - XMPP "Ping" by XEP-0199
3 ;; Copyright (C) 2009 - Evgenii Terechkov - evg@altlinux.org
5 ;; This file is a part of jabber.el.
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2 of the License, or
10 ;; (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program; if not, write to the Free Software
19 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 (require 'jabber-iq)
22 (require 'jabber-util)
24 (add-to-list 'jabber-jid-info-menu
25 (cons "Ping" 'jabber-ping))
27 (defun jabber-ping-send (jc to process-func on-success on-error)
28 "Send XEP-0199 ping IQ stanza. JC is connection to use, TO is
29 full JID, PROCESS-FUNC is fucntion to call to process result,
30 ON-SUCCESS and ON-ERROR is arg for this function depending on
31 result."
32 (jabber-send-iq jc to "get"
33 '(ping ((xmlns . "urn:xmpp:ping")))
34 process-func on-success
35 process-func on-error))
37 (defun jabber-ping (to)
38 "Ping XMPP entity. TO is full JID. All connected JIDs is used."
39 (interactive (list (jabber-read-jid-completing "Send ping to: " nil nil nil 'full)))
40 (dolist (jc jabber-connections)
41 (jabber-ping-send jc to 'jabber-silent-process-data 'jabber-process-ping "Ping is unsupported")))
43 ;; called by jabber-process-data
44 (defun jabber-process-ping (jc xml-data)
45 "Handle results from ping requests."
46 (let ((to (jabber-xml-get-attribute xml-data 'from)))
47 (format "%s is alive" to)))
49 (add-to-list 'jabber-iq-get-xmlns-alist (cons "urn:xmpp:ping" 'jabber-pong))
50 (add-to-list 'jabber-advertised-features "urn:xmpp:ping")
52 (defun jabber-pong (jc xml-data)
53 "Return pong as defined in XEP-0199. Sender and Id are
54 determined from the incoming packet passed in XML-DATA."
55 (let ((to (jabber-xml-get-attribute xml-data 'from))
56 (id (jabber-xml-get-attribute xml-data 'id)))
57 (jabber-send-iq jc to "result" nil nil nil nil nil id)))
59 (provide 'jabber-ping)