1 ;;; tramp-gvfs.el --- Tramp access functions for GVFS daemon
3 ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
6 ;; Keywords: comm, processes
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; Access functions for the GVFS daemon from Tramp. Tested with GVFS
26 ;; 1.0.2 (Ubuntu 8.10, Gnome 2.24). It has been reported also to run
27 ;; with GVFS 0.2.5 (Ubuntu 8.04, Gnome 2.22), but there is an
28 ;; incompatibility with the mount_info structure, which has been
31 ;; It has also been tested with GVFS 1.6.2 (Ubuntu 10.04, Gnome 2.30),
32 ;; where the default_location has been added to mount_info (see
33 ;; <https://bugzilla.gnome.org/show_bug.cgi?id=561998>.
35 ;; All actions to mount a remote location, and to retrieve mount
36 ;; information, are performed by D-Bus messages. File operations
37 ;; themselves are performed via the mounted filesystem in ~/.gvfs.
38 ;; Consequently, GNU Emacs 23.1 with enabled D-Bus bindings is a
41 ;; The GVFS D-Bus interface is said to be instable. There are even no
42 ;; introspection data. The interface, as discovered during
43 ;; development time, is given in respective comments.
45 ;; The customer option `tramp-gvfs-methods' contains the list of
46 ;; supported connection methods. Per default, these are "dav",
47 ;; "davs", "obex" and "synce". Note that with "obex" it might be
48 ;; necessary to pair with the other bluetooth device, if it hasn't
49 ;; been done already. There might be also some few seconds delay in
50 ;; discovering available bluetooth devices.
52 ;; Other possible connection methods are "ftp", "sftp" and "smb".
53 ;; When one of these methods is added to the list, the remote access
54 ;; for that method is performed via GVFS instead of the native Tramp
57 ;; GVFS offers even more connection methods. The complete list of
58 ;; connection methods of the actual GVFS implementation can be
66 ;; :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
67 ;; tramp-gvfs-interface-mounttracker "listMountableInfo")))
69 ;; Note that all other connection methods are not tested, beside the
70 ;; ones offered for customization in `tramp-gvfs-methods'. If you
71 ;; request an additional connection method to be supported, please
74 ;; For hostname completion, information is retrieved either from the
75 ;; bluez daemon (for the "obex" method), the hal daemon (for the
76 ;; "synce" method), or from the zeroconf daemon (for the "dav",
77 ;; "davs", and "sftp" methods). The zeroconf daemon is pre-configured
78 ;; to discover services in the "local" domain. If another domain
79 ;; shall be used for discovering services, the customer option
80 ;; `tramp-gvfs-zeroconf-domain' can be set accordingly.
84 ;; * The current GVFS implementation does not allow to write on the
85 ;; remote bluetooth device via OBEX.
87 ;; * Two shares of the same SMB server cannot be mounted in parallel.
91 ;; D-Bus support in the Emacs core can be disabled with configuration
92 ;; option "--without-dbus". Declare used subroutines and variables.
93 (declare-function dbus-call-method "dbusbind.c")
94 (declare-function dbus-call-method-asynchronously "dbusbind.c")
95 (declare-function dbus-get-unique-name "dbusbind.c")
96 (declare-function dbus-register-method "dbusbind.c")
97 (declare-function dbus-register-signal "dbusbind.c")
99 ;; Pacify byte-compiler
110 (defcustom tramp-gvfs-methods '("dav" "davs" "obex" "synce")
111 "*List of methods for remote files, accessed with GVFS."
114 :type '(repeat (choice (const "dav")
122 ;; Add a default for `tramp-default-user-alist'. Rule: For the SYNCE
123 ;; method, no user is chosen.
124 (add-to-list 'tramp-default-user-alist
127 (defcustom tramp-gvfs-zeroconf-domain "local"
128 "*Zeroconf domain to be used for discovering services, like host names."
133 ;; Add the methods to `tramp-methods', in order to allow minibuffer
135 (eval-after-load "tramp-gvfs"
136 '(when (featurep 'tramp-gvfs)
137 (dolist (elt tramp-gvfs-methods)
138 (unless (assoc elt tramp-methods)
139 (add-to-list 'tramp-methods (cons elt nil))))))
141 (defconst tramp-gvfs-path-tramp (concat dbus-path-emacs "/Tramp")
142 "The preceeding object path for own objects.")
144 (defconst tramp-gvfs-service-daemon "org.gtk.vfs.Daemon"
145 "The well known name of the GVFS daemon.")
147 ;; Check that GVFS is available.
148 (unless (dbus-ping :session tramp-gvfs-service-daemon 100)
149 (throw 'tramp-loading nil))
151 (defconst tramp-gvfs-path-mounttracker "/org/gtk/vfs/mounttracker"
152 "The object path of the GVFS daemon.")
154 (defconst tramp-gvfs-interface-mounttracker "org.gtk.vfs.MountTracker"
155 "The mount tracking interface in the GVFS daemon.")
157 ;; <interface name='org.gtk.vfs.MountTracker'>
158 ;; <method name='listMounts'>
159 ;; <arg name='mount_info_list'
160 ;; type='a{sosssssbay{aya{say}}}'
163 ;; <method name='mountLocation'>
164 ;; <arg name='mount_spec' type='{aya{say}}' direction='in'/>
165 ;; <arg name='dbus_id' type='s' direction='in'/>
166 ;; <arg name='object_path' type='o' direction='in'/>
168 ;; <signal name='mounted'>
169 ;; <arg name='mount_info'
170 ;; type='{sosssssbay{aya{say}}}'/>
172 ;; <signal name='unmounted'>
173 ;; <arg name='mount_info'
174 ;; type='{sosssssbay{aya{say}}}'/>
180 ;; OBJECT_PATH object_path
181 ;; STRING display_name
182 ;; STRING stable_name
183 ;; STRING x_content_types Since GVFS 1.0 only !!!
185 ;; STRING prefered_filename_encoding
186 ;; BOOLEAN user_visible
187 ;; ARRAY BYTE fuse_mountpoint
189 ;; ARRAY BYTE mount_prefix
191 ;; STRUCT mount_spec_item
192 ;; STRING key (server, share, type, user, host, port)
194 ;; STRING default_location Since GVFS 1.5 only !!!
196 (defconst tramp-gvfs-interface-mountoperation "org.gtk.vfs.MountOperation"
197 "Used by the dbus-proxying implementation of GMountOperation.")
199 ;; <interface name='org.gtk.vfs.MountOperation'>
200 ;; <method name='askPassword'>
201 ;; <arg name='message' type='s' direction='in'/>
202 ;; <arg name='default_user' type='s' direction='in'/>
203 ;; <arg name='default_domain' type='s' direction='in'/>
204 ;; <arg name='flags' type='u' direction='in'/>
205 ;; <arg name='handled' type='b' direction='out'/>
206 ;; <arg name='aborted' type='b' direction='out'/>
207 ;; <arg name='password' type='s' direction='out'/>
208 ;; <arg name='username' type='s' direction='out'/>
209 ;; <arg name='domain' type='s' direction='out'/>
210 ;; <arg name='anonymous' type='b' direction='out'/>
211 ;; <arg name='password_save' type='u' direction='out'/>
213 ;; <method name='askQuestion'>
214 ;; <arg name='message' type='s' direction='in'/>
215 ;; <arg name='choices' type='as' direction='in'/>
216 ;; <arg name='handled' type='b' direction='out'/>
217 ;; <arg name='aborted' type='b' direction='out'/>
218 ;; <arg name='choice' type='u' direction='out'/>
222 ;; The following flags are used in "askPassword". They are defined in
223 ;; /usr/include/glib-2.0/gio/gioenums.h.
225 (defconst tramp-gvfs-password-need-password 1
226 "Operation requires a password.")
228 (defconst tramp-gvfs-password-need-username 2
229 "Operation requires a username.")
231 (defconst tramp-gvfs-password-need-domain 4
232 "Operation requires a domain.")
234 (defconst tramp-gvfs-password-saving-supported 8
235 "Operation supports saving settings.")
237 (defconst tramp-gvfs-password-anonymous-supported 16
238 "Operation supports anonymous users.")
240 (defconst tramp-bluez-service "org.bluez"
241 "The well known name of the BLUEZ service.")
243 (defconst tramp-bluez-interface-manager "org.bluez.Manager"
244 "The manager interface of the BLUEZ daemon.")
246 ;; <interface name='org.bluez.Manager'>
247 ;; <method name='DefaultAdapter'>
248 ;; <arg type='o' direction='out'/>
250 ;; <method name='FindAdapter'>
251 ;; <arg type='s' direction='in'/>
252 ;; <arg type='o' direction='out'/>
254 ;; <method name='ListAdapters'>
255 ;; <arg type='ao' direction='out'/>
257 ;; <signal name='AdapterAdded'>
260 ;; <signal name='AdapterRemoved'>
263 ;; <signal name='DefaultAdapterChanged'>
268 (defconst tramp-bluez-interface-adapter "org.bluez.Adapter"
269 "The adapter interface of the BLUEZ daemon.")
271 ;; <interface name='org.bluez.Adapter'>
272 ;; <method name='GetProperties'>
273 ;; <arg type='a{sv}' direction='out'/>
275 ;; <method name='SetProperty'>
276 ;; <arg type='s' direction='in'/>
277 ;; <arg type='v' direction='in'/>
279 ;; <method name='RequestMode'>
280 ;; <arg type='s' direction='in'/>
282 ;; <method name='ReleaseMode'/>
283 ;; <method name='RequestSession'/>
284 ;; <method name='ReleaseSession'/>
285 ;; <method name='StartDiscovery'/>
286 ;; <method name='StopDiscovery'/>
287 ;; <method name='ListDevices'>
288 ;; <arg type='ao' direction='out'/>
290 ;; <method name='CreateDevice'>
291 ;; <arg type='s' direction='in'/>
292 ;; <arg type='o' direction='out'/>
294 ;; <method name='CreatePairedDevice'>
295 ;; <arg type='s' direction='in'/>
296 ;; <arg type='o' direction='in'/>
297 ;; <arg type='s' direction='in'/>
298 ;; <arg type='o' direction='out'/>
300 ;; <method name='CancelDeviceCreation'>
301 ;; <arg type='s' direction='in'/>
303 ;; <method name='RemoveDevice'>
304 ;; <arg type='o' direction='in'/>
306 ;; <method name='FindDevice'>
307 ;; <arg type='s' direction='in'/>
308 ;; <arg type='o' direction='out'/>
310 ;; <method name='RegisterAgent'>
311 ;; <arg type='o' direction='in'/>
312 ;; <arg type='s' direction='in'/>
314 ;; <method name='UnregisterAgent'>
315 ;; <arg type='o' direction='in'/>
317 ;; <signal name='DeviceCreated'>
320 ;; <signal name='DeviceRemoved'>
323 ;; <signal name='DeviceFound'>
325 ;; <arg type='a{sv}'/>
327 ;; <signal name='PropertyChanged'>
331 ;; <signal name='DeviceDisappeared'>
336 (defcustom tramp-bluez-discover-devices-timeout 60
337 "Defines seconds since last bluetooth device discovery before rescanning.
338 A value of 0 would require an immediate discovery during hostname
339 completion, nil means to use always cached values for discovered
343 :type '(choice (const nil) integer))
345 (defvar tramp-bluez-discovery nil
346 "Indicator for a running bluetooth device discovery.
347 It keeps the timestamp of last discovery.")
349 (defvar tramp-bluez-devices nil
350 "Alist of detected bluetooth devices.
351 Every entry is a list (NAME ADDRESS).")
353 (defconst tramp-hal-service "org.freedesktop.Hal"
354 "The well known name of the HAL service.")
356 (defconst tramp-hal-path-manager "/org/freedesktop/Hal/Manager"
357 "The object path of the HAL daemon manager.")
359 (defconst tramp-hal-interface-manager "org.freedesktop.Hal.Manager"
360 "The manager interface of the HAL daemon.")
362 (defconst tramp-hal-interface-device "org.freedesktop.Hal.Device"
363 "The device interface of the HAL daemon.")
366 ;; New handlers should be added here.
367 (defconst tramp-gvfs-file-name-handler-alist
369 (access-file . ignore)
370 (add-name-to-file . tramp-gvfs-handle-copy-file)
371 ;; `byte-compiler-base-file-name' performed by default handler.
372 (copy-file . tramp-gvfs-handle-copy-file)
373 (delete-directory . tramp-gvfs-handle-delete-directory)
374 (delete-file . tramp-gvfs-handle-delete-file)
375 ;; `diff-latest-backup-file' performed by default handler.
376 (directory-file-name . tramp-handle-directory-file-name)
377 (directory-files . tramp-gvfs-handle-directory-files)
378 (directory-files-and-attributes
379 . tramp-gvfs-handle-directory-files-and-attributes)
380 (dired-call-process . ignore)
381 (dired-compress-file . ignore)
382 (dired-uncache . tramp-handle-dired-uncache)
383 ;; `executable-find' is not official yet. performed by default handler.
384 (expand-file-name . tramp-gvfs-handle-expand-file-name)
385 ;; `file-accessible-directory-p' performed by default handler.
386 (file-attributes . tramp-gvfs-handle-file-attributes)
387 (file-directory-p . tramp-smb-handle-file-directory-p)
388 (file-executable-p . tramp-gvfs-handle-file-executable-p)
389 (file-exists-p . tramp-gvfs-handle-file-exists-p)
390 (file-local-copy . tramp-gvfs-handle-file-local-copy)
391 ;; `file-modes' performed by default handler.
392 (file-name-all-completions . tramp-gvfs-handle-file-name-all-completions)
393 (file-name-as-directory . tramp-handle-file-name-as-directory)
394 (file-name-completion . tramp-handle-file-name-completion)
395 (file-name-directory . tramp-handle-file-name-directory)
396 (file-name-nondirectory . tramp-handle-file-name-nondirectory)
397 ;; `file-name-sans-versions' performed by default handler.
398 (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
399 (file-ownership-preserved-p . ignore)
400 (file-readable-p . tramp-gvfs-handle-file-readable-p)
401 (file-regular-p . tramp-handle-file-regular-p)
402 (file-remote-p . tramp-handle-file-remote-p)
403 (file-selinux-context . tramp-gvfs-handle-file-selinux-context)
404 (file-symlink-p . tramp-handle-file-symlink-p)
405 ;; `file-truename' performed by default handler.
406 (file-writable-p . tramp-gvfs-handle-file-writable-p)
407 (find-backup-file-name . tramp-handle-find-backup-file-name)
408 ;; `find-file-noselect' performed by default handler.
409 ;; `get-file-buffer' performed by default handler.
410 (insert-directory . tramp-gvfs-handle-insert-directory)
411 (insert-file-contents . tramp-gvfs-handle-insert-file-contents)
412 (load . tramp-handle-load)
413 (make-directory . tramp-gvfs-handle-make-directory)
414 (make-directory-internal . ignore)
415 (make-symbolic-link . ignore)
416 (process-file . tramp-gvfs-handle-process-file)
417 (rename-file . tramp-gvfs-handle-rename-file)
418 (set-file-modes . tramp-gvfs-handle-set-file-modes)
419 (set-file-selinux-context . tramp-gvfs-handle-set-file-selinux-context)
420 (set-visited-file-modtime . tramp-gvfs-handle-set-visited-file-modtime)
421 (shell-command . tramp-gvfs-handle-shell-command)
422 (start-file-process . tramp-gvfs-handle-start-file-process)
423 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
424 (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory)
425 (vc-registered . ignore)
426 (verify-visited-file-modtime
427 . tramp-gvfs-handle-verify-visited-file-modtime)
428 (write-region . tramp-gvfs-handle-write-region)
430 "Alist of handler functions for Tramp GVFS method.
431 Operations not mentioned here will be handled by the default Emacs primitives.")
433 (defun tramp-gvfs-file-name-p (filename)
434 "Check if it's a filename handled by the GVFS daemon."
435 (and (tramp-tramp-file-p filename)
437 (tramp-file-name-method (tramp-dissect-file-name filename))))
438 (and (stringp method) (member method tramp-gvfs-methods)))))
440 (defun tramp-gvfs-file-name-handler (operation &rest args)
441 "Invoke the GVFS related OPERATION.
442 First arg specifies the OPERATION, second arg is a list of arguments to
443 pass to the OPERATION."
444 (let ((fn (assoc operation tramp-gvfs-file-name-handler-alist)))
446 (save-match-data (apply (cdr fn) args))
447 (tramp-run-real-handler operation args))))
449 ;; This might be moved to tramp.el. It shall be the first file name
451 (add-to-list 'tramp-foreign-file-name-handler-alist
452 (cons 'tramp-gvfs-file-name-p 'tramp-gvfs-file-name-handler))
454 (defun tramp-gvfs-stringify-dbus-message (message)
455 "Convert a D-Bus message into readable UTF8 strings, used for traces."
457 ((and (consp message) (characterp (car message)))
458 (format "%S" (dbus-byte-array-to-string message)))
460 (mapcar 'tramp-gvfs-stringify-dbus-message message))
462 (format "%S" message))
465 (defmacro with-tramp-dbus-call-method
466 (vec synchronous bus service path interface method &rest args)
467 "Apply a D-Bus call on bus BUS.
469 If SYNCHRONOUS is non-nil, the call is synchronously. Otherwise,
470 it is an asynchronous call, with `ignore' as callback function.
472 The other arguments have the same meaning as with `dbus-call-method'
473 or `dbus-call-method-asynchronously'. Additionally, the call
474 will be traced by Tramp with trace level 6."
475 `(let ((func (if ,synchronous
476 'dbus-call-method 'dbus-call-method-asynchronously))
477 (args (append (list ,bus ,service ,path ,interface ,method)
478 (if ,synchronous (list ,@args) (list 'ignore ,@args))))
480 (tramp-message ,vec 6 "%s %s" func args)
481 (setq result (apply func args))
482 (tramp-message ,vec 6 "%s" (tramp-gvfs-stringify-dbus-message result))
485 (put 'with-tramp-dbus-call-method 'lisp-indent-function 2)
486 (put 'with-tramp-dbus-call-method 'edebug-form-spec '(form symbolp body))
487 (font-lock-add-keywords 'emacs-lisp-mode '("\\<with-tramp-dbus-call-method\\>"))
489 (defmacro with-tramp-gvfs-error-message (filename handler &rest args)
490 "Apply a Tramp GVFS `handler'.
491 In case of an error, modify the error message by replacing
492 `filename' with its GVFS mounted name."
493 `(let ((fuse-file-name (regexp-quote (tramp-gvfs-fuse-file-name ,filename)))
496 (funcall ,handler ,@args)
500 (when (and (stringp (car elt))
501 (string-match fuse-file-name (car elt)))
502 (setcar elt (replace-match ,filename t t (car elt))))
503 (setq elt (cdr elt)))
504 (signal (car err) (cdr err))))))
506 (put 'with-tramp-gvfs-error-message 'lisp-indent-function 2)
507 (put 'with-tramp-gvfs-error-message 'edebug-form-spec '(form symbolp body))
508 (font-lock-add-keywords 'emacs-lisp-mode '("\\<with-tramp-gvfs-error-message\\>"))
510 (defvar tramp-gvfs-dbus-event-vector nil
511 "Current Tramp file name to be used, as vector.
512 It is needed when D-Bus signals or errors arrive, because there
513 is no information where to trace the message.")
515 (defun tramp-gvfs-dbus-event-error (event err)
516 "Called when a D-Bus error message arrives, see `dbus-event-error-hooks'."
517 (when tramp-gvfs-dbus-event-vector
518 ;(tramp-cleanup-connection tramp-gvfs-dbus-event-vector)
519 (tramp-message tramp-gvfs-dbus-event-vector 10 "%S" event)
520 (tramp-error tramp-gvfs-dbus-event-vector 'file-error "%s" (cadr err))))
522 (add-hook 'dbus-event-error-hooks 'tramp-gvfs-dbus-event-error)
525 ;; File name primitives.
527 (defun tramp-gvfs-handle-copy-file
528 (filename newname &optional ok-if-already-exists keep-date
529 preserve-uid-gid preserve-selinux-context)
530 "Like `copy-file' for Tramp files."
531 (with-parsed-tramp-file-name
532 (if (tramp-tramp-file-p filename) filename newname) nil
533 (with-progress-reporter
534 v 0 (format "Copying %s to %s" filename newname)
538 (if (tramp-gvfs-file-name-p filename)
539 (tramp-gvfs-fuse-file-name filename)
541 (if (tramp-gvfs-file-name-p newname)
542 (tramp-gvfs-fuse-file-name newname)
544 ok-if-already-exists keep-date preserve-uid-gid)))
545 (when preserve-selinux-context
546 (setq args (append args (list preserve-selinux-context))))
547 (apply 'copy-file args))
549 ;; Error case. Let's try it with the GVFS utilities.
551 (tramp-message v 4 "`copy-file' failed, trying `gvfs-copy'")
554 (tramp-gvfs-send-command
556 (if (or keep-date preserve-uid-gid) "--preserve" "")
557 (tramp-gvfs-url-file-name filename)
558 (tramp-gvfs-url-file-name newname)))
559 ;; Propagate the error.
560 (tramp-error v (car err) "%s" (cdr err)))))))
562 (when (file-remote-p newname)
563 (with-parsed-tramp-file-name newname nil
564 (tramp-flush-file-property v (file-name-directory localname))
565 (tramp-flush-file-property v localname))))
567 (defun tramp-gvfs-handle-delete-directory (directory &optional recursive)
568 "Like `delete-directory' for Tramp files."
569 (tramp-compat-delete-directory
570 (tramp-gvfs-fuse-file-name directory) recursive))
572 (defun tramp-gvfs-handle-delete-file (filename &optional trash)
573 "Like `delete-file' for Tramp files."
574 (tramp-compat-delete-file (tramp-gvfs-fuse-file-name filename) trash))
576 (defun tramp-gvfs-handle-directory-files
577 (directory &optional full match nosort)
578 "Like `directory-files' for Tramp files."
579 (let ((fuse-file-name (tramp-gvfs-fuse-file-name directory)))
582 (if (string-match fuse-file-name x)
583 (replace-match directory t t x)
585 (directory-files fuse-file-name full match nosort))))
587 (defun tramp-gvfs-handle-directory-files-and-attributes
588 (directory &optional full match nosort id-format)
589 "Like `directory-files-and-attributes' for Tramp files."
590 (let ((fuse-file-name (tramp-gvfs-fuse-file-name directory)))
593 (when (string-match fuse-file-name (car x))
594 (setcar x (replace-match directory t t (car x))))
596 (directory-files-and-attributes
597 fuse-file-name full match nosort id-format))))
599 (defun tramp-gvfs-handle-expand-file-name (name &optional dir)
600 "Like `expand-file-name' for Tramp files."
601 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
602 (setq dir (or dir default-directory "/"))
603 ;; Unless NAME is absolute, concat DIR and NAME.
604 (unless (file-name-absolute-p name)
605 (setq name (concat (file-name-as-directory dir) name)))
606 ;; If NAME is not a Tramp file, run the real handler.
607 (if (not (tramp-tramp-file-p name))
608 (tramp-run-real-handler 'expand-file-name (list name nil))
610 (with-parsed-tramp-file-name name nil
611 ;; Tilde expansion is not possible.
612 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
615 "Cannot expand tilde in file `%s'" name))
616 (unless (tramp-run-real-handler 'file-name-absolute-p (list localname))
617 (setq localname (concat "/" localname)))
618 ;; We do not pass "/..".
619 (if (string-equal "smb" method)
620 (when (string-match "^/[^/]+\\(/\\.\\./?\\)" localname)
621 (setq localname (replace-match "/" t t localname 1)))
622 (when (string-match "^/\\.\\./?" localname)
623 (setq localname (replace-match "/" t t localname))))
624 ;; There might be a double slash. Remove this.
625 (while (string-match "//" localname)
626 (setq localname (replace-match "/" t t localname)))
627 ;; No tilde characters in file name, do normal
628 ;; `expand-file-name' (this does "/./" and "/../").
629 (tramp-make-tramp-file-name
631 (tramp-run-real-handler
632 'expand-file-name (list localname))))))
634 (defun tramp-gvfs-handle-file-attributes (filename &optional id-format)
635 "Like `file-attributes' for Tramp files."
636 (file-attributes (tramp-gvfs-fuse-file-name filename) id-format))
638 (defun tramp-gvfs-handle-file-executable-p (filename)
639 "Like `file-executable-p' for Tramp files."
640 (file-executable-p (tramp-gvfs-fuse-file-name filename)))
642 (defun tramp-gvfs-handle-file-exists-p (filename)
643 "Like `file-exists-p' for Tramp files."
644 (file-exists-p (tramp-gvfs-fuse-file-name filename)))
646 (defun tramp-gvfs-handle-file-local-copy (filename)
647 "Like `file-local-copy' for Tramp files."
648 (with-parsed-tramp-file-name filename nil
649 (let ((tmpfile (tramp-compat-make-temp-file filename)))
650 (unless (file-exists-p filename)
653 "Cannot make local copy of non-existing file `%s'" filename))
654 (copy-file filename tmpfile t t)
657 (defun tramp-gvfs-handle-file-name-all-completions (filename directory)
658 "Like `file-name-all-completions' for Tramp files."
659 (unless (save-match-data (string-match "/" filename))
660 (file-name-all-completions filename (tramp-gvfs-fuse-file-name directory))))
662 (defun tramp-gvfs-handle-file-readable-p (filename)
663 "Like `file-readable-p' for Tramp files."
664 (file-readable-p (tramp-gvfs-fuse-file-name filename)))
666 (defun tramp-gvfs-handle-file-selinux-context (filename)
667 "Like `file-selinux-context' for Tramp files."
668 (tramp-compat-funcall
669 'file-selinux-context (tramp-gvfs-fuse-file-name filename)))
671 (defun tramp-gvfs-handle-file-writable-p (filename)
672 "Like `file-writable-p' for Tramp files."
673 (file-writable-p (tramp-gvfs-fuse-file-name filename)))
675 (defun tramp-gvfs-handle-insert-directory
676 (filename switches &optional wildcard full-directory-p)
677 "Like `insert-directory' for Tramp files."
679 (tramp-gvfs-fuse-file-name filename) switches wildcard full-directory-p))
681 (defun tramp-gvfs-handle-insert-file-contents
682 (filename &optional visit beg end replace)
683 "Like `insert-file-contents' for Tramp files."
685 (let ((fuse-file-name (tramp-gvfs-fuse-file-name filename))
687 (insert-file-contents
688 (tramp-gvfs-fuse-file-name filename) visit beg end replace)))
689 (when (string-match fuse-file-name (car result))
690 (setcar result (replace-match filename t t (car result))))
692 (setq buffer-file-name filename)))
694 (defun tramp-gvfs-handle-make-directory (dir &optional parents)
695 "Like `make-directory' for Tramp files."
696 (with-parsed-tramp-file-name dir nil
698 (with-tramp-gvfs-error-message dir 'make-directory
699 (tramp-gvfs-fuse-file-name dir) parents)
701 ;; Error case. Let's try it with the GVFS utilities.
703 (tramp-message v 4 "`make-directory' failed, trying `gvfs-mkdir'")
706 (tramp-gvfs-send-command
707 v "gvfs-mkdir" (tramp-gvfs-url-file-name dir)))
708 ;; Propagate the error.
709 (tramp-error v (car err) "%s" (cdr err)))))))
711 (defun tramp-gvfs-handle-process-file
712 (program &optional infile destination display &rest args)
713 "Like `process-file' for Tramp files."
714 (let ((default-directory (tramp-gvfs-fuse-file-name default-directory)))
715 (apply 'call-process program infile destination display args)))
717 (defun tramp-gvfs-handle-rename-file
718 (filename newname &optional ok-if-already-exists)
719 "Like `rename-file' for Tramp files."
720 (with-parsed-tramp-file-name
721 (if (tramp-tramp-file-p filename) filename newname) nil
722 (with-progress-reporter
723 v 0 (format "Renaming %s to %s" filename newname)
726 (if (tramp-gvfs-file-name-p filename)
727 (tramp-gvfs-fuse-file-name filename)
729 (if (tramp-gvfs-file-name-p newname)
730 (tramp-gvfs-fuse-file-name newname)
732 ok-if-already-exists)
734 ;; Error case. Let's try it with the GVFS utilities.
736 (tramp-message v 4 "`rename-file' failed, trying `gvfs-move'")
739 (tramp-gvfs-send-command
741 (tramp-gvfs-url-file-name filename)
742 (tramp-gvfs-url-file-name newname)))
743 ;; Propagate the error.
744 (tramp-error v (car err) "%s" (cdr err)))))))
746 (when (file-remote-p filename)
747 (with-parsed-tramp-file-name filename nil
748 (tramp-flush-file-property v (file-name-directory localname))
749 (tramp-flush-file-property v localname)))
751 (when (file-remote-p newname)
752 (with-parsed-tramp-file-name newname nil
753 (tramp-flush-file-property v (file-name-directory localname))
754 (tramp-flush-file-property v localname))))
756 (defun tramp-gvfs-handle-set-file-modes (filename mode)
757 "Like `set-file-modes' for Tramp files."
758 (with-tramp-gvfs-error-message filename 'set-file-modes
759 (tramp-gvfs-fuse-file-name filename) mode))
761 (defun tramp-gvfs-handle-set-file-selinux-context (filename context)
762 "Like `set-file-selinux-context' for Tramp files."
763 (with-tramp-gvfs-error-message filename 'set-file-selinux-context
764 (tramp-gvfs-fuse-file-name filename) context))
766 (defun tramp-gvfs-handle-set-visited-file-modtime (&optional time-list)
767 "Like `set-visited-file-modtime' for Tramp files."
768 (let ((buffer-file-name (tramp-gvfs-fuse-file-name (buffer-file-name))))
769 (set-visited-file-modtime time-list)))
771 (defun tramp-gvfs-handle-shell-command
772 (command &optional output-buffer error-buffer)
773 "Like `shell-command' for Tramp files."
774 (let ((default-directory (tramp-gvfs-fuse-file-name default-directory)))
775 (shell-command command output-buffer error-buffer)))
777 (defun tramp-gvfs-handle-start-file-process (name buffer program &rest args)
778 "Like `start-file-process' for Tramp files."
779 (let ((default-directory (tramp-gvfs-fuse-file-name default-directory)))
780 (apply 'start-process name buffer program args)))
782 (defun tramp-gvfs-handle-verify-visited-file-modtime (buf)
783 "Like `verify-visited-file-modtime' for Tramp files."
784 (with-current-buffer buf
785 (let ((buffer-file-name (tramp-gvfs-fuse-file-name (buffer-file-name))))
786 (verify-visited-file-modtime buf))))
788 (defun tramp-gvfs-handle-write-region
789 (start end filename &optional append visit lockname confirm)
790 "Like `write-region' for Tramp files."
791 (with-parsed-tramp-file-name filename nil
793 (with-tramp-gvfs-error-message filename 'write-region
794 start end (tramp-gvfs-fuse-file-name filename)
795 append visit lockname confirm)
797 ;; Error case. Let's try rename.
799 (let ((tmpfile (tramp-compat-make-temp-file filename)))
800 (tramp-message v 4 "`write-region' failed, trying `rename-file'")
801 (write-region start end tmpfile)
803 (rename-file tmpfile filename)
805 (delete-file tmpfile)
806 (tramp-error v (car err) "%s" (cdr err)))))))
808 ;; Set file modification time.
809 (when (or (eq visit t) (stringp visit))
810 (set-visited-file-modtime (nth 5 (file-attributes filename))))
813 (when (or (eq visit t) (null visit) (stringp visit))
814 (tramp-message v 0 "Wrote %s" filename))
815 (run-hooks 'tramp-handle-write-region-hook)))
818 ;; File name conversions.
820 (defun tramp-gvfs-url-file-name (filename)
821 "Return FILENAME in URL syntax."
822 ;; "/" must NOT be hexlified.
823 (let ((url-unreserved-chars (append '(?/) url-unreserved-chars)))
825 (if (tramp-tramp-file-p filename)
826 (with-parsed-tramp-file-name (file-truename filename) nil
827 (when (string-match tramp-user-with-domain-regexp user)
829 (concat (match-string 2 user) ";" (match-string 2 user))))
830 (url-parse-make-urlobj
832 (tramp-file-name-real-host v) (tramp-file-name-port v)
833 (url-hexify-string localname)))
834 (url-parse-make-urlobj
835 "file" nil nil nil nil (url-hexify-string (file-truename filename)))))))
837 (defun tramp-gvfs-object-path (filename)
838 "Create a D-Bus object path from FILENAME."
839 (expand-file-name (dbus-escape-as-identifier filename) tramp-gvfs-path-tramp))
841 (defun tramp-gvfs-file-name (object-path)
842 "Retrieve file name from D-Bus OBJECT-PATH."
843 (dbus-unescape-from-identifier
844 (replace-regexp-in-string "^.*/\\([^/]+\\)$" "\\1" object-path)))
846 (defun tramp-gvfs-fuse-file-name (filename)
847 "Return FUSE file name, which is directly accessible."
848 (with-parsed-tramp-file-name (expand-file-name filename) nil
849 (tramp-gvfs-maybe-open-connection v)
850 (let ((prefix (tramp-get-file-property v "/" "prefix" ""))
852 (tramp-get-file-property v "/" "fuse-mountpoint" nil)))
853 (unless fuse-mountpoint
855 v 'file-error "There is no FUSE mount point for `%s'" filename))
856 ;; We must hide the prefix, if any.
857 (when (string-match (concat "^" (regexp-quote prefix)) localname)
858 (setq localname (replace-match "" t t localname)))
860 v 10 "remote file `%s' is local file `%s'"
861 filename (concat fuse-mountpoint localname))
862 (concat fuse-mountpoint localname))))
864 (defun tramp-bluez-address (device)
865 "Return bluetooth device address from a given bluetooth DEVICE name."
866 (when (stringp device)
867 (if (string-match tramp-ipv6-regexp device)
868 (match-string 0 device)
869 (cadr (assoc device (tramp-bluez-list-devices))))))
871 (defun tramp-bluez-device (address)
872 "Return bluetooth device name from a given bluetooth device ADDRESS.
873 ADDRESS can have the form \"xx:xx:xx:xx:xx:xx\" or \"[xx:xx:xx:xx:xx:xx]\"."
874 (when (stringp address)
875 (while (string-match "[][]" address)
876 (setq address (replace-match "" t t address)))
878 (dolist (item (tramp-bluez-list-devices) result)
879 (when (string-match address (cadr item))
880 (setq result (car item)))))))
883 ;; D-Bus GVFS functions.
885 (defun tramp-gvfs-handler-askpassword (message user domain flags)
886 "Implementation for the \"org.gtk.vfs.MountOperation.askPassword\" method."
888 (tramp-gvfs-file-name (dbus-event-path-name last-input-event)))
892 (if (string-match "\\([pP]assword\\|[pP]assphrase\\)" message)
893 (capitalize (match-string 1 message))
899 (with-parsed-tramp-file-name filename l
900 (when (and (zerop (length user))
902 (zerop (logand flags tramp-gvfs-password-need-username))))
903 (setq user (read-string "User name: ")))
904 (when (and (zerop (length domain))
905 (not (zerop (logand flags tramp-gvfs-password-need-domain))))
906 (setq domain (read-string "Domain name: ")))
908 (tramp-message l 6 "%S %S %S %d" message user domain flags)
909 (setq tramp-current-method l-method
910 tramp-current-user user
911 tramp-current-host l-host
912 password (tramp-read-passwd
913 (tramp-get-connection-process l) pw-prompt))
916 (if (stringp password)
918 t ;; password handled.
919 nil ;; no abort of D-Bus.
921 (tramp-file-name-real-user l)
923 nil ;; not anonymous.
924 0) ;; no password save.
925 ;; No password provided.
926 (list nil t "" (tramp-file-name-real-user l) domain nil 0)))
928 ;; When QUIT is raised, we shall return this information to D-Bus.
929 (quit (list nil t "" "" "" nil 0)))))
931 (defun tramp-gvfs-handler-askquestion (message choices)
932 "Implementation for the \"org.gtk.vfs.MountOperation.askQuestion\" method."
933 (save-window-excursion
934 (let ((enable-recursive-minibuffers t)
938 (with-parsed-tramp-file-name
939 (tramp-gvfs-file-name (dbus-event-path-name last-input-event)) nil
940 (tramp-message v 6 "%S %S" message choices)
942 ;; In theory, there can be several choices. Until now,
943 ;; there is only the question whether to accept an unknown
946 ;; Preserve message for `progress-reporter'.
947 (with-temp-message ""
949 (pop-to-buffer (current-buffer))
950 (setq choice (if (yes-or-no-p (concat (car choices) " ")) 0 1))
951 (tramp-message v 6 "%d" choice)))
953 ;; When the choice is "no", we set a dummy fuse-mountpoint
954 ;; in order to leave the timeout.
955 (unless (zerop choice)
956 (tramp-set-file-property v "/" "fuse-mountpoint" "/"))
960 nil ;; no abort of D-Bus.
963 ;; When QUIT is raised, we shall return this information to D-Bus.
964 (quit (list nil t 0))))))
966 (defun tramp-gvfs-handler-mounted-unmounted (mount-info)
967 "Signal handler for the \"org.gtk.vfs.MountTracker.mounted\" and
968 \"org.gtk.vfs.MountTracker.unmounted\" signals."
970 ;; The last element could be the default location in newer gvfs
971 ;; versions. We must check this.
972 (unless (consp (car (last mount-info)))
973 (setq mount-info (butlast mount-info)))
974 (let* ((signal-name (dbus-event-member-name last-input-event))
975 (mount-spec (cadar (last mount-info)))
976 (method (dbus-byte-array-to-string (cadr (assoc "type" mount-spec))))
977 (user (dbus-byte-array-to-string (cadr (assoc "user" mount-spec))))
978 (domain (dbus-byte-array-to-string
979 (cadr (assoc "domain" mount-spec))))
980 (host (dbus-byte-array-to-string
981 (cadr (or (assoc "host" mount-spec)
982 (assoc "server" mount-spec)))))
983 (port (dbus-byte-array-to-string (cadr (assoc "port" mount-spec))))
984 (ssl (dbus-byte-array-to-string (cadr (assoc "ssl" mount-spec))))
985 (prefix (concat (dbus-byte-array-to-string (caar (last mount-info)))
986 (dbus-byte-array-to-string
987 (cadr (assoc "share" mount-spec))))))
988 (when (string-match "^smb" method)
990 (when (string-equal "obex" method)
991 (setq host (tramp-bluez-device host)))
992 (when (and (string-equal "dav" method) (string-equal "true" ssl))
993 (setq method "davs"))
994 (unless (zerop (length domain))
995 (setq user (concat user tramp-prefix-domain-format domain)))
996 (unless (zerop (length port))
997 (setq host (concat host tramp-prefix-port-format port)))
998 (with-parsed-tramp-file-name
999 (tramp-make-tramp-file-name method user host "") nil
1001 v 6 "%s %s" signal-name (tramp-gvfs-stringify-dbus-message mount-info))
1002 (tramp-set-file-property v "/" "list-mounts" 'undef)
1003 (if (string-equal signal-name "unmounted")
1004 (tramp-set-file-property v "/" "fuse-mountpoint" nil)
1005 ;; Set prefix and mountpoint.
1006 (unless (string-equal prefix "/")
1007 (tramp-set-file-property v "/" "prefix" prefix))
1008 (tramp-set-file-property
1009 v "/" "fuse-mountpoint"
1010 (dbus-byte-array-to-string (car (last mount-info 2)))))))))
1012 (dbus-register-signal
1013 :session nil tramp-gvfs-path-mounttracker
1014 tramp-gvfs-interface-mounttracker "mounted"
1015 'tramp-gvfs-handler-mounted-unmounted)
1017 (dbus-register-signal
1018 :session nil tramp-gvfs-path-mounttracker
1019 tramp-gvfs-interface-mounttracker "unmounted"
1020 'tramp-gvfs-handler-mounted-unmounted)
1022 (defun tramp-gvfs-connection-mounted-p (vec)
1023 "Check, whether the location is already mounted."
1025 (tramp-get-file-property vec "/" "fuse-mountpoint" nil)
1029 (with-file-property vec "/" "list-mounts"
1030 (with-tramp-dbus-call-method vec t
1031 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1032 tramp-gvfs-interface-mounttracker "listMounts"))
1034 ;; The last element could be the default location in newer gvfs
1035 ;; versions. We must check this.
1036 (unless (consp (car (last elt))) (setq elt (butlast elt)))
1037 (let* ((mount-spec (cadar (last elt)))
1038 (method (dbus-byte-array-to-string
1039 (cadr (assoc "type" mount-spec))))
1040 (user (dbus-byte-array-to-string
1041 (cadr (assoc "user" mount-spec))))
1042 (domain (dbus-byte-array-to-string
1043 (cadr (assoc "domain" mount-spec))))
1044 (host (dbus-byte-array-to-string
1045 (cadr (or (assoc "host" mount-spec)
1046 (assoc "server" mount-spec)))))
1047 (port (dbus-byte-array-to-string
1048 (cadr (assoc "port" mount-spec))))
1049 (ssl (dbus-byte-array-to-string (cadr (assoc "ssl" mount-spec))))
1050 (prefix (concat (dbus-byte-array-to-string (caar (last elt)))
1051 (dbus-byte-array-to-string
1052 (cadr (assoc "share" mount-spec))))))
1053 (when (string-match "^smb" method)
1054 (setq method "smb"))
1055 (when (string-equal "obex" method)
1056 (setq host (tramp-bluez-device host)))
1057 (when (and (string-equal "dav" method) (string-equal "true" ssl))
1058 (setq method "davs"))
1059 (when (and (string-equal "synce" method) (zerop (length user)))
1060 (setq user (or (tramp-file-name-user vec) "")))
1061 (unless (zerop (length domain))
1062 (setq user (concat user tramp-prefix-domain-format domain)))
1063 (unless (zerop (length port))
1064 (setq host (concat host tramp-prefix-port-format port)))
1066 (string-equal method (tramp-file-name-method vec))
1067 (string-equal user (or (tramp-file-name-user vec) ""))
1068 (string-equal host (tramp-file-name-host vec))
1069 (string-match (concat "^" (regexp-quote prefix))
1070 (tramp-file-name-localname vec)))
1071 ;; Set prefix and mountpoint.
1072 (unless (string-equal prefix "/")
1073 (tramp-set-file-property vec "/" "prefix" prefix))
1074 (tramp-set-file-property
1075 vec "/" "fuse-mountpoint"
1076 (dbus-byte-array-to-string (car (last elt 2))))
1077 (throw 'mounted t)))))))
1079 (defun tramp-gvfs-mount-spec (vec)
1080 "Return a mount-spec for \"org.gtk.vfs.MountTracker.mountLocation\"."
1081 (let* ((method (tramp-file-name-method vec))
1082 (user (tramp-file-name-real-user vec))
1083 (domain (tramp-file-name-domain vec))
1084 (host (tramp-file-name-real-host vec))
1085 (port (tramp-file-name-port vec))
1086 (localname (tramp-file-name-localname vec))
1087 (ssl (if (string-match "^davs" method) "true" "false"))
1088 (mount-spec '(:array))
1096 ((string-equal "smb" method)
1097 (string-match "^/?\\([^/]+\\)" localname)
1098 `((:struct "type" ,(dbus-string-to-byte-array "smb-share"))
1099 (:struct "server" ,(dbus-string-to-byte-array host))
1100 (:struct "share" ,(dbus-string-to-byte-array
1101 (match-string 1 localname)))))
1102 ((string-equal "obex" method)
1103 `((:struct "type" ,(dbus-string-to-byte-array method))
1104 (:struct "host" ,(dbus-string-to-byte-array
1105 (concat "[" (tramp-bluez-address host) "]")))))
1106 ((string-match "^dav" method)
1107 `((:struct "type" ,(dbus-string-to-byte-array "dav"))
1108 (:struct "host" ,(dbus-string-to-byte-array host))
1109 (:struct "ssl" ,(dbus-string-to-byte-array ssl))))
1111 `((:struct "type" ,(dbus-string-to-byte-array method))
1112 (:struct "host" ,(dbus-string-to-byte-array host)))))))
1117 `(:struct "user" ,(dbus-string-to-byte-array user))
1123 `(:struct "domain" ,(dbus-string-to-byte-array domain))
1129 `(:struct "port" ,(dbus-string-to-byte-array (number-to-string port)))
1132 (when (and (string-match "^dav" method)
1133 (string-match "^/?[^/]+" localname))
1134 (setq mount-pref (match-string 0 localname)))
1137 `(:struct ,(dbus-string-to-byte-array mount-pref) ,mount-spec)))
1140 ;; Connection functions
1142 (defun tramp-gvfs-maybe-open-connection (vec)
1143 "Maybe open a connection VEC.
1144 Does not do anything if a connection is already open, but re-opens the
1145 connection if a previous connection has died for some reason."
1147 ;; We set the file name, in case there are incoming D-Bus signals or
1149 (setq tramp-gvfs-dbus-event-vector vec)
1151 ;; For password handling, we need a process bound to the connection
1152 ;; buffer. Therefore, we create a dummy process. Maybe there is a
1154 (unless (get-buffer-process (tramp-get-buffer vec))
1155 (let ((p (make-network-process
1156 :name (tramp-buffer-name vec)
1157 :buffer (tramp-get-buffer vec)
1158 :server t :host 'local :service t)))
1159 (tramp-set-process-query-on-exit-flag p nil)))
1161 (unless (tramp-gvfs-connection-mounted-p vec)
1162 (let* ((method (tramp-file-name-method vec))
1163 (user (tramp-file-name-user vec))
1164 (host (tramp-file-name-host vec))
1166 (tramp-gvfs-object-path
1167 (tramp-make-tramp-file-name method user host ""))))
1169 (with-progress-reporter
1171 (if (zerop (length user))
1172 (format "Opening connection for %s using %s" host method)
1173 (format "Opening connection for %s@%s using %s" user host method))
1175 ;; Enable auth-sorce and password-cache.
1176 (tramp-set-connection-property vec "first-password-request" t)
1178 ;; There will be a callback of "askPassword", when a password is
1180 (dbus-register-method
1181 :session dbus-service-emacs object-path
1182 tramp-gvfs-interface-mountoperation "askPassword"
1183 'tramp-gvfs-handler-askpassword)
1185 ;; There could be a callback of "askQuestion", when adding fingerprint.
1186 (dbus-register-method
1187 :session dbus-service-emacs object-path
1188 tramp-gvfs-interface-mountoperation "askQuestion"
1189 'tramp-gvfs-handler-askquestion)
1191 ;; The call must be asynchronously, because of the "askPassword"
1192 ;; or "askQuestion"callbacks.
1193 (with-tramp-dbus-call-method vec nil
1194 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1195 tramp-gvfs-interface-mounttracker "mountLocation"
1196 (tramp-gvfs-mount-spec vec) (dbus-get-unique-name :session)
1197 :object-path object-path)
1199 ;; We must wait, until the mount is applied. This will be
1200 ;; indicated by the "mounted" signal, i.e. the "fuse-mountpoint"
1204 (if (zerop (length (tramp-file-name-user vec)))
1207 "Timeout reached mounting %s using %s" host method)
1210 "Timeout reached mounting %s@%s using %s" user host method)))
1211 (while (not (tramp-get-file-property vec "/" "fuse-mountpoint" nil))
1212 (read-event nil nil 0.1)))
1214 ;; If `tramp-gvfs-handler-askquestion' has returned "No", it
1215 ;; is marked with the fuse-mountpoint "/". We shall react.
1217 (tramp-get-file-property vec "/" "fuse-mountpoint" "") "/")
1218 (tramp-error vec 'file-error "FUSE mount denied"))
1220 ;; We set the connection property "started" in order to put the
1221 ;; remote location into the cache, which is helpful for further
1223 (tramp-set-connection-property vec "started" t)))))
1225 (defun tramp-gvfs-send-command (vec command &rest args)
1226 "Send the COMMAND with its ARGS to connection VEC.
1227 COMMAND is usually a command from the gvfs-* utilities.
1228 `call-process' is applied, and its return code is returned."
1230 (with-current-buffer (tramp-get-buffer vec)
1232 (tramp-message vec 6 "%s %s" command (mapconcat 'identity args " "))
1233 (setq result (apply 'tramp-local-call-process command nil t nil args))
1234 (tramp-message vec 6 "%s" (buffer-string))
1238 ;; D-Bus BLUEZ functions.
1240 (defun tramp-bluez-list-devices ()
1241 "Return all discovered bluetooth devices as list.
1242 Every entry is a list (NAME ADDRESS).
1244 If `tramp-bluez-discover-devices-timeout' is an integer, and the last
1245 discovery happened more time before indicated there, a rescan will be
1246 started, which lasts some ten seconds. Otherwise, cached results will
1248 ;; Reset the scanned devices list if time has passed.
1249 (and (integerp tramp-bluez-discover-devices-timeout)
1250 (integerp tramp-bluez-discovery)
1251 (> (tramp-time-diff (current-time) tramp-bluez-discovery)
1252 tramp-bluez-discover-devices-timeout)
1253 (setq tramp-bluez-devices nil))
1255 ;; Rescan if needed.
1256 (unless tramp-bluez-devices
1258 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1259 :system tramp-bluez-service "/"
1260 tramp-bluez-interface-manager "DefaultAdapter")))
1261 (setq tramp-bluez-devices nil
1262 tramp-bluez-discovery t)
1263 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector nil
1264 :system tramp-bluez-service object-path
1265 tramp-bluez-interface-adapter "StartDiscovery")
1266 (while tramp-bluez-discovery
1267 (read-event nil nil 0.1))))
1268 (setq tramp-bluez-discovery (current-time))
1269 (tramp-message tramp-gvfs-dbus-event-vector 10 "%s" tramp-bluez-devices)
1270 tramp-bluez-devices)
1272 (defun tramp-bluez-property-changed (property value)
1273 "Signal handler for the \"org.bluez.Adapter.PropertyChanged\" signal."
1274 (tramp-message tramp-gvfs-dbus-event-vector 6 "%s %s" property value)
1276 ((string-equal property "Discovering")
1278 ;; "Discovering" FALSE means discovery run has been completed.
1279 ;; We stop it, because we don't need another run.
1280 (setq tramp-bluez-discovery nil)
1281 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1282 :system tramp-bluez-service (dbus-event-path-name last-input-event)
1283 tramp-bluez-interface-adapter "StopDiscovery")))))
1285 (dbus-register-signal
1286 :system nil nil tramp-bluez-interface-adapter "PropertyChanged"
1287 'tramp-bluez-property-changed)
1289 (defun tramp-bluez-device-found (device args)
1290 "Signal handler for the \"org.bluez.Adapter.DeviceFound\" signal."
1291 (tramp-message tramp-gvfs-dbus-event-vector 6 "%s %s" device args)
1292 (let ((alias (car (cadr (assoc "Alias" args))))
1293 (address (car (cadr (assoc "Address" args)))))
1294 ;; Maybe we shall check the device class for being a proper
1295 ;; device, and call also SDP in order to find the obex service.
1296 (add-to-list 'tramp-bluez-devices (list alias address))))
1298 (dbus-register-signal
1299 :system nil nil tramp-bluez-interface-adapter "DeviceFound"
1300 'tramp-bluez-device-found)
1302 (defun tramp-bluez-parse-device-names (ignore)
1303 "Return a list of (nil host) tuples allowed to access."
1305 (lambda (x) (list nil (car x)))
1306 (tramp-bluez-list-devices)))
1308 ;; Add completion function for OBEX method.
1309 (when (member tramp-bluez-service (dbus-list-known-names :system))
1310 (tramp-set-completion-function
1311 "obex" '((tramp-bluez-parse-device-names ""))))
1314 ;; D-Bus zeroconf functions.
1316 (defun tramp-zeroconf-parse-workstation-device-names (ignore)
1317 "Return a list of (user host) tuples allowed to access."
1320 (list nil (zeroconf-service-host x)))
1321 (zeroconf-list-services "_workstation._tcp")))
1323 (defun tramp-zeroconf-parse-webdav-device-names (ignore)
1324 "Return a list of (user host) tuples allowed to access."
1327 (let ((host (zeroconf-service-host x))
1328 (port (zeroconf-service-port x))
1329 (text (zeroconf-service-txt x))
1332 (setq host (format "%s%s%d" host tramp-prefix-port-regexp port)))
1333 ;; A user is marked in a TXT field like "u=guest".
1335 (when (string-match "u=\\(.+\\)$" (car text))
1336 (setq user (match-string 1 (car text))))
1337 (setq text (cdr text)))
1339 (zeroconf-list-services "_webdav._tcp")))
1341 ;; Add completion function for DAV and DAVS methods.
1342 (when (member zeroconf-service-avahi (dbus-list-known-names :system))
1343 (zeroconf-init tramp-gvfs-zeroconf-domain)
1344 (tramp-set-completion-function
1345 "sftp" '((tramp-zeroconf-parse-workstation-device-names "")))
1346 (tramp-set-completion-function
1347 "dav" '((tramp-zeroconf-parse-webdav-device-names "")))
1348 (tramp-set-completion-function
1349 "davs" '((tramp-zeroconf-parse-webdav-device-names ""))))
1352 ;; D-Bus SYNCE functions.
1354 (defun tramp-synce-list-devices ()
1355 "Return all discovered synce devices as list.
1356 They are retrieved from the hal daemon."
1357 (let (tramp-synce-devices)
1359 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1360 :system tramp-hal-service tramp-hal-path-manager
1361 tramp-hal-interface-manager "GetAllDevices"))
1362 (when (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1363 :system tramp-hal-service device tramp-hal-interface-device
1364 "PropertyExists" "sync.plugin")
1366 'tramp-synce-devices
1367 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1368 :system tramp-hal-service device tramp-hal-interface-device
1369 "GetPropertyString" "pda.pocketpc.name"))))
1370 (tramp-message tramp-gvfs-dbus-event-vector 10 "%s" tramp-synce-devices)
1371 tramp-synce-devices))
1373 (defun tramp-synce-parse-device-names (ignore)
1374 "Return a list of (nil host) tuples allowed to access."
1376 (lambda (x) (list nil x))
1377 (tramp-synce-list-devices)))
1379 ;; Add completion function for SYNCE method.
1380 (tramp-set-completion-function
1381 "synce" '((tramp-synce-parse-device-names "")))
1383 (provide 'tramp-gvfs)
1387 ;; * Host name completion via smb-server or smb-network.
1388 ;; * Check, how two shares of the same SMB server can be mounted in
1390 ;; * Apply SDP on bluetooth devices, in order to filter out obex
1392 ;; * Implement obex for other serial communication but bluetooth.
1394 ;; arch-tag: f7f660ce-77f4-4132-9663-f5c25a47f7ed
1395 ;;; tramp-gvfs.el ends here