1 ;; jabber-ft-client.el - send file transfer requests, by JEP-0096
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 (eval-when-compile (require 'cl
))
23 (require 'jabber-si-client
)
24 (require 'jabber-util
)
26 (require 'jabber-ft-common
)
28 (defun jabber-ft-send (jc jid filename desc
)
29 "Attempt to send FILENAME to JID."
30 (interactive (list (jabber-read-account)
31 (jabber-read-jid-completing "Send file to: " nil nil nil
'full
)
32 (read-file-name "Send which file: " nil nil t
)
33 (jabber-read-with-input-method "Description (optional): ")))
34 (if (zerop (length desc
)) (setq desc nil
))
35 (setq filename
(expand-file-name filename
))
36 (access-file filename
"Couldn't open file")
38 (let* ((attributes (file-attributes filename
))
39 (size (nth 7 attributes
))
40 (date (nth 5 attributes
))
41 (hash (jabber-ft-get-md5 filename
)))
42 (jabber-si-initiate jc jid
"http://jabber.org/protocol/si/profile/file-transfer"
43 `(file ((xmlns .
"http://jabber.org/protocol/si/profile/file-transfer")
44 (name .
,(file-name-nondirectory filename
))
46 (date .
,(jabber-encode-time date
))
48 (list (cons 'hash hash
))))
50 (lexical-let ((filename filename
))
51 (lambda (jc jid sid send-data-function
)
53 jid sid send-data-function filename
))))))
55 (defun jabber-ft-do-send (jid sid send-data-function filename
)
56 (if (stringp send-data-function
)
57 (message "File sending failed: %s" send-data-function
)
59 (insert-file-contents-literally filename
)
61 ;; Ever heard of buffering?
62 (funcall send-data-function
(buffer-string))
63 (message "File transfer completed")))
64 ;; File transfer is monodirectional, so ignore received data.
67 (provide 'jabber-ft-client
)
68 ;;; arch-tag: fba686d5-37b5-4165-86c5-49b76fa0ea6e