Revision: mange@freemail.hu--2005/emacs-jabber--cvs-head--0--patch-556
[emacs-jabber.git] / jabber-si-client.el
blob8e1c5a20c5bcb2f72b617600eabdac2839f42e7c
1 ;; jabber-si-client.el - send stream requests, by JEP-0095
3 ;; Copyright (C) 2004 - Magnus Henoch - mange@freemail.hu
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-feature-neg)
24 (require 'jabber-si-common)
26 (defun jabber-si-initiate (jc jid profile-namespace profile-data profile-function &optional mime-type)
27 "Try to initiate a stream to JID.
28 PROFILE-NAMESPACE is, well, the namespace of the profile to use.
29 PROFILE-DATA is the XML data to send within the SI request.
30 PROFILE-FUNCTION is the \"connection established\" function.
31 See `jabber-si-stream-methods'.
32 MIME-TYPE is the MIME type to specify.
33 Returns the SID."
35 (let ((sid (apply 'format "emacs-sid-%d.%d.%d" (current-time))))
36 (jabber-send-iq jc jid "set"
37 `(si ((xmlns . "http://jabber.org/protocol/si")
38 (id . ,sid)
39 ,(if mime-type
40 (cons 'mime-type mime-type))
41 (profile . ,profile-namespace))
42 ,profile-data
43 (feature ((xmlns . "http://jabber.org/protocol/feature-neg"))
44 ,(jabber-fn-encode (list
45 (cons "stream-method"
46 (mapcar 'car jabber-si-stream-methods)))
47 'request)))
48 #'jabber-si-initiate-process (cons profile-function sid)
49 ;; XXX: use other function here?
50 #'jabber-report-success "Stream initiation")
51 sid))
53 (defun jabber-si-initiate-process (jc xml-data closure-data)
54 "Act on response to our SI query."
56 (let* ((profile-function (car closure-data))
57 (sid (cdr closure-data))
58 (from (jabber-xml-get-attribute xml-data 'from))
59 (query (jabber-iq-query xml-data))
60 (feature-node (car (jabber-xml-get-children query 'feature)))
61 (feature-alist (jabber-fn-parse feature-node 'response))
62 (chosen-method (cadr (assoc "stream-method" feature-alist)))
63 (method-data (assoc chosen-method jabber-si-stream-methods)))
64 ;; Our work is done. Hand it over to the stream method.
65 (let ((stream-negotiate (nth 1 method-data)))
66 (funcall stream-negotiate jc from sid profile-function))))
68 (provide 'jabber-si-client)
70 ;;; arch-tag: e14ec451-3f18-4f36-b92a-e8a8aa1f5acd