Revision: mange@freemail.hu--2005/emacs-jabber--cvs-head--0--patch-556
[emacs-jabber.git] / jabber-version.el
blobed0295ffb1b0f7d6cc94782cf139fdf38ed246cf
1 ;; jabber-version.el - version reporting by JEP-0092
3 ;; Copyright (C) 2003, 2004, 2008 - Magnus Henoch - mange@freemail.hu
4 ;; Copyright (C) 2002, 2003, 2004 - tom berger - object@intelectronica.net
6 ;; This file is a part of jabber.el.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program; if not, write to the Free Software
20 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 (require 'jabber-iq)
23 (require 'jabber-util)
24 (require 'jabber-ourversion)
26 (add-to-list 'jabber-jid-info-menu
27 (cons "Request software version" 'jabber-get-version))
28 (defun jabber-get-version (jc to)
29 "Request software version"
30 (interactive (list
31 (jabber-read-account)
32 (jabber-read-jid-completing "Request version of: " nil nil nil 'full)))
33 ;; XXX: you will not get any result unless you add the resource to the JID.
34 (jabber-send-iq jc to
35 "get"
36 '(query ((xmlns . "jabber:iq:version")))
37 #'jabber-process-data #'jabber-process-version
38 #'jabber-process-data "Version request failed"))
40 ;; called by jabber-process-data
41 (defun jabber-process-version (jc xml-data)
42 "Handle results from jabber:iq:version requests."
44 (let ((query (jabber-iq-query xml-data)))
45 (dolist (x '((name . "Name:\t\t") (version . "Version:\t") (os . "OS:\t\t")))
46 (let ((data (car (jabber-xml-node-children (car (jabber-xml-get-children query (car x)))))))
47 (when data
48 (insert (cdr x) data "\n"))))))
50 (add-to-list 'jabber-iq-get-xmlns-alist (cons "jabber:iq:version" 'jabber-return-version))
51 (add-to-list 'jabber-advertised-features "jabber:iq:version")
52 (defun jabber-return-version (jc xml-data)
53 "Return client version as defined in JEP-0092. Sender and ID are
54 determined from the incoming packet passed in XML-DATA."
55 ;; Things we might check: does this iq message really have type='get' and
56 ;; exactly one child, namely query with xmlns='jabber:iq:version'?
57 ;; Then again, jabber-process-iq should take care of that.
58 (let ((to (jabber-xml-get-attribute xml-data 'from))
59 (id (jabber-xml-get-attribute xml-data 'id)))
60 (jabber-send-iq jc to "result"
61 `(query ((xmlns . "jabber:iq:version"))
62 (name () "jabber.el")
63 (version () ,jabber-version)
64 ;; Booting... /vmemacs.el
65 ;; Shamelessly stolen from someone's sig.
66 (os () ,(emacs-version)))
67 nil nil nil nil
68 id)))
70 (provide 'jabber-version)
72 ;;; arch-tag: 2051dbe7-01b5-401e-bd8a-fe24afb88e1e