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
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.
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")
40 (cons 'mime-type mime-type
))
41 (profile .
,profile-namespace
))
43 (feature ((xmlns .
"http://jabber.org/protocol/feature-neg"))
44 ,(jabber-fn-encode (list
46 (mapcar 'car jabber-si-stream-methods
)))
48 #'jabber-si-initiate-process
(cons profile-function sid
)
49 ;; XXX: use other function here?
50 #'jabber-report-success
"Stream initiation")
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