Fix bug #14306 with whitespace mode together with linum-mode.
[emacs.git] / lisp / net / tramp-gvfs.el
blob7c3b393873c27ea8e9e747b723f075604deba346
1 ;;; tramp-gvfs.el --- Tramp access functions for GVFS daemon
3 ;; Copyright (C) 2009-2013 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
6 ;; Keywords: comm, processes
7 ;; Package: tramp
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; Access functions for the GVFS daemon from Tramp. Tested with GVFS
27 ;; 1.0 (Ubuntu 8.10, Gnome 2.24). It has been reported also to run
28 ;; with GVFS 0.2.5 (Ubuntu 8.04, Gnome 2.22), but there is an
29 ;; incompatibility with the mount_info structure, which has been
30 ;; worked around.
32 ;; It has also been tested with GVFS 1.6 (Ubuntu 10.04, Gnome 2.30),
33 ;; where the default_location has been added to mount_info (see
34 ;; <https://bugzilla.gnome.org/show_bug.cgi?id=561998>.
36 ;; With GVFS 1.14 (Ubuntu 12.10, Gnome 3.6) the interfaces have been
37 ;; changed, again. So we must introspect the D-Bus interfaces.
39 ;; All actions to mount a remote location, and to retrieve mount
40 ;; information, are performed by D-Bus messages. File operations
41 ;; themselves are performed via the mounted filesystem in ~/.gvfs.
42 ;; Consequently, GNU Emacs 23.1 with enabled D-Bus bindings is a
43 ;; precondition.
45 ;; The GVFS D-Bus interface is said to be unstable. There were even
46 ;; no introspection data before GVFS 1.14. The interface, as
47 ;; discovered during development time, is given in respective
48 ;; comments.
50 ;; The customer option `tramp-gvfs-methods' contains the list of
51 ;; supported connection methods. Per default, these are "dav",
52 ;; "davs", "obex" and "synce". Note that with "obex" it might be
53 ;; necessary to pair with the other bluetooth device, if it hasn't
54 ;; been done already. There might be also some few seconds delay in
55 ;; discovering available bluetooth devices.
57 ;; Other possible connection methods are "ftp", "sftp" and "smb".
58 ;; When one of these methods is added to the list, the remote access
59 ;; for that method is performed via GVFS instead of the native Tramp
60 ;; implementation.
62 ;; GVFS offers even more connection methods. The complete list of
63 ;; connection methods of the actual GVFS implementation can be
64 ;; retrieved by:
66 ;; (message
67 ;; "%s"
68 ;; (mapcar
69 ;; 'car
70 ;; (dbus-call-method
71 ;; :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
72 ;; tramp-gvfs-interface-mounttracker "listMountableInfo")))
74 ;; Note that all other connection methods are not tested, beside the
75 ;; ones offered for customization in `tramp-gvfs-methods'. If you
76 ;; request an additional connection method to be supported, please
77 ;; drop me a note.
79 ;; For hostname completion, information is retrieved either from the
80 ;; bluez daemon (for the "obex" method), the hal daemon (for the
81 ;; "synce" method), or from the zeroconf daemon (for the "dav",
82 ;; "davs", and "sftp" methods). The zeroconf daemon is pre-configured
83 ;; to discover services in the "local" domain. If another domain
84 ;; shall be used for discovering services, the customer option
85 ;; `tramp-gvfs-zeroconf-domain' can be set accordingly.
87 ;; Restrictions:
89 ;; * The current GVFS implementation does not allow to write on the
90 ;; remote bluetooth device via OBEX.
92 ;; * Two shares of the same SMB server cannot be mounted in parallel.
94 ;;; Code:
96 ;; D-Bus support in the Emacs core can be disabled with configuration
97 ;; option "--without-dbus". Declare used subroutines and variables.
98 (declare-function dbus-get-unique-name "dbusbind.c")
100 ;; Pacify byte-compiler
101 (eval-when-compile
102 (require 'cl)
103 (require 'custom))
105 (require 'tramp)
107 (require 'dbus)
108 (require 'url-parse)
109 (require 'url-util)
110 (require 'zeroconf)
112 ;;;###tramp-autoload
113 (defcustom tramp-gvfs-methods '("dav" "davs" "obex" "synce")
114 "List of methods for remote files, accessed with GVFS."
115 :group 'tramp
116 :version "23.2"
117 :type '(repeat (choice (const "dav")
118 (const "davs")
119 (const "ftp")
120 (const "obex")
121 (const "sftp")
122 (const "smb")
123 (const "synce"))))
125 ;; Add a default for `tramp-default-user-alist'. Rule: For the SYNCE
126 ;; method, no user is chosen.
127 ;;;###tramp-autoload
128 (add-to-list 'tramp-default-user-alist '("\\`synce\\'" nil nil))
130 (defcustom tramp-gvfs-zeroconf-domain "local"
131 "Zeroconf domain to be used for discovering services, like host names."
132 :group 'tramp
133 :version "23.2"
134 :type 'string)
136 ;; Add the methods to `tramp-methods', in order to allow minibuffer
137 ;; completion.
138 ;;;###tramp-autoload
139 (when (featurep 'dbusbind)
140 (dolist (elt tramp-gvfs-methods)
141 (unless (assoc elt tramp-methods)
142 (add-to-list 'tramp-methods (cons elt nil)))))
144 (defconst tramp-gvfs-path-tramp (concat dbus-path-emacs "/Tramp")
145 "The preceding object path for own objects.")
147 (defconst tramp-gvfs-service-daemon "org.gtk.vfs.Daemon"
148 "The well known name of the GVFS daemon.")
150 ;; Check that GVFS is available. D-Bus integration is available since
151 ;; Emacs 23 on some system types. We don't call `dbus-ping', because
152 ;; this would load dbus.el.
153 (unless (and (tramp-compat-funcall 'dbus-get-unique-name :session)
154 (or (tramp-compat-process-running-p "gvfs-fuse-daemon")
155 (tramp-compat-process-running-p "gvfsd-fuse")))
156 (tramp-compat-user-error "Package `tramp-gvfs' not supported"))
158 (defconst tramp-gvfs-path-mounttracker "/org/gtk/vfs/mounttracker"
159 "The object path of the GVFS daemon.")
161 (defconst tramp-gvfs-interface-mounttracker "org.gtk.vfs.MountTracker"
162 "The mount tracking interface in the GVFS daemon.")
164 ;; Introspection data exist since GVFS 1.14. If there are no such
165 ;; data, we expect an earlier interface.
166 (defconst tramp-gvfs-methods-mounttracker
167 (dbus-introspect-get-method-names
168 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
169 tramp-gvfs-interface-mounttracker)
170 "The list of supported methods of the mount tracking interface.")
172 (defconst tramp-gvfs-listmounts
173 (if (member "ListMounts" tramp-gvfs-methods-mounttracker)
174 "ListMounts"
175 "listMounts")
176 "The name of the \"listMounts\" method.
177 It has been changed in GVFS 1.14.")
179 (defconst tramp-gvfs-mountlocation
180 (if (member "MountLocation" tramp-gvfs-methods-mounttracker)
181 "MountLocation"
182 "mountLocation")
183 "The name of the \"mountLocation\" method.
184 It has been changed in GVFS 1.14.")
186 (defconst tramp-gvfs-mountlocation-signature
187 (dbus-introspect-get-signature
188 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
189 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation)
190 "The D-Bus signature of the \"mountLocation\" method.
191 It has been changed in GVFS 1.14.")
193 ;; <interface name='org.gtk.vfs.MountTracker'>
194 ;; <method name='listMounts'>
195 ;; <arg name='mount_info_list'
196 ;; type='a{sosssssbay{aya{say}}ay}'
197 ;; direction='out'/>
198 ;; </method>
199 ;; <method name='mountLocation'>
200 ;; <arg name='mount_spec' type='{aya{say}}' direction='in'/>
201 ;; <arg name='dbus_id' type='s' direction='in'/>
202 ;; <arg name='object_path' type='o' direction='in'/>
203 ;; </method>
204 ;; <signal name='mounted'>
205 ;; <arg name='mount_info'
206 ;; type='{sosssssbay{aya{say}}ay}'/>
207 ;; </signal>
208 ;; <signal name='unmounted'>
209 ;; <arg name='mount_info'
210 ;; type='{sosssssbay{aya{say}}ay}'/>
211 ;; </signal>
212 ;; </interface>
214 ;; STRUCT mount_info
215 ;; STRING dbus_id
216 ;; OBJECT_PATH object_path
217 ;; STRING display_name
218 ;; STRING stable_name
219 ;; STRING x_content_types Since GVFS 1.0 only !!!
220 ;; STRING icon
221 ;; STRING preferred_filename_encoding
222 ;; BOOLEAN user_visible
223 ;; ARRAY BYTE fuse_mountpoint
224 ;; STRUCT mount_spec
225 ;; ARRAY BYTE mount_prefix
226 ;; ARRAY
227 ;; STRUCT mount_spec_item
228 ;; STRING key (server, share, type, user, host, port)
229 ;; ARRAY BYTE value
230 ;; ARRAY BYTE default_location Since GVFS 1.5 only !!!
232 (defconst tramp-gvfs-interface-mountoperation "org.gtk.vfs.MountOperation"
233 "Used by the dbus-proxying implementation of GMountOperation.")
235 ;; <interface name='org.gtk.vfs.MountOperation'>
236 ;; <method name='askPassword'>
237 ;; <arg name='message' type='s' direction='in'/>
238 ;; <arg name='default_user' type='s' direction='in'/>
239 ;; <arg name='default_domain' type='s' direction='in'/>
240 ;; <arg name='flags' type='u' direction='in'/>
241 ;; <arg name='handled' type='b' direction='out'/>
242 ;; <arg name='aborted' type='b' direction='out'/>
243 ;; <arg name='password' type='s' direction='out'/>
244 ;; <arg name='username' type='s' direction='out'/>
245 ;; <arg name='domain' type='s' direction='out'/>
246 ;; <arg name='anonymous' type='b' direction='out'/>
247 ;; <arg name='password_save' type='u' direction='out'/>
248 ;; </method>
249 ;; <method name='askQuestion'>
250 ;; <arg name='message' type='s' direction='in'/>
251 ;; <arg name='choices' type='as' direction='in'/>
252 ;; <arg name='handled' type='b' direction='out'/>
253 ;; <arg name='aborted' type='b' direction='out'/>
254 ;; <arg name='choice' type='u' direction='out'/>
255 ;; </method>
256 ;; </interface>
258 ;; The following flags are used in "askPassword". They are defined in
259 ;; /usr/include/glib-2.0/gio/gioenums.h.
261 (defconst tramp-gvfs-password-need-password 1
262 "Operation requires a password.")
264 (defconst tramp-gvfs-password-need-username 2
265 "Operation requires a username.")
267 (defconst tramp-gvfs-password-need-domain 4
268 "Operation requires a domain.")
270 (defconst tramp-gvfs-password-saving-supported 8
271 "Operation supports saving settings.")
273 (defconst tramp-gvfs-password-anonymous-supported 16
274 "Operation supports anonymous users.")
276 (defconst tramp-bluez-service "org.bluez"
277 "The well known name of the BLUEZ service.")
279 (defconst tramp-bluez-interface-manager "org.bluez.Manager"
280 "The manager interface of the BLUEZ daemon.")
282 ;; <interface name='org.bluez.Manager'>
283 ;; <method name='DefaultAdapter'>
284 ;; <arg type='o' direction='out'/>
285 ;; </method>
286 ;; <method name='FindAdapter'>
287 ;; <arg type='s' direction='in'/>
288 ;; <arg type='o' direction='out'/>
289 ;; </method>
290 ;; <method name='ListAdapters'>
291 ;; <arg type='ao' direction='out'/>
292 ;; </method>
293 ;; <signal name='AdapterAdded'>
294 ;; <arg type='o'/>
295 ;; </signal>
296 ;; <signal name='AdapterRemoved'>
297 ;; <arg type='o'/>
298 ;; </signal>
299 ;; <signal name='DefaultAdapterChanged'>
300 ;; <arg type='o'/>
301 ;; </signal>
302 ;; </interface>
304 (defconst tramp-bluez-interface-adapter "org.bluez.Adapter"
305 "The adapter interface of the BLUEZ daemon.")
307 ;; <interface name='org.bluez.Adapter'>
308 ;; <method name='GetProperties'>
309 ;; <arg type='a{sv}' direction='out'/>
310 ;; </method>
311 ;; <method name='SetProperty'>
312 ;; <arg type='s' direction='in'/>
313 ;; <arg type='v' direction='in'/>
314 ;; </method>
315 ;; <method name='RequestMode'>
316 ;; <arg type='s' direction='in'/>
317 ;; </method>
318 ;; <method name='ReleaseMode'/>
319 ;; <method name='RequestSession'/>
320 ;; <method name='ReleaseSession'/>
321 ;; <method name='StartDiscovery'/>
322 ;; <method name='StopDiscovery'/>
323 ;; <method name='ListDevices'>
324 ;; <arg type='ao' direction='out'/>
325 ;; </method>
326 ;; <method name='CreateDevice'>
327 ;; <arg type='s' direction='in'/>
328 ;; <arg type='o' direction='out'/>
329 ;; </method>
330 ;; <method name='CreatePairedDevice'>
331 ;; <arg type='s' direction='in'/>
332 ;; <arg type='o' direction='in'/>
333 ;; <arg type='s' direction='in'/>
334 ;; <arg type='o' direction='out'/>
335 ;; </method>
336 ;; <method name='CancelDeviceCreation'>
337 ;; <arg type='s' direction='in'/>
338 ;; </method>
339 ;; <method name='RemoveDevice'>
340 ;; <arg type='o' direction='in'/>
341 ;; </method>
342 ;; <method name='FindDevice'>
343 ;; <arg type='s' direction='in'/>
344 ;; <arg type='o' direction='out'/>
345 ;; </method>
346 ;; <method name='RegisterAgent'>
347 ;; <arg type='o' direction='in'/>
348 ;; <arg type='s' direction='in'/>
349 ;; </method>
350 ;; <method name='UnregisterAgent'>
351 ;; <arg type='o' direction='in'/>
352 ;; </method>
353 ;; <signal name='DeviceCreated'>
354 ;; <arg type='o'/>
355 ;; </signal>
356 ;; <signal name='DeviceRemoved'>
357 ;; <arg type='o'/>
358 ;; </signal>
359 ;; <signal name='DeviceFound'>
360 ;; <arg type='s'/>
361 ;; <arg type='a{sv}'/>
362 ;; </signal>
363 ;; <signal name='PropertyChanged'>
364 ;; <arg type='s'/>
365 ;; <arg type='v'/>
366 ;; </signal>
367 ;; <signal name='DeviceDisappeared'>
368 ;; <arg type='s'/>
369 ;; </signal>
370 ;; </interface>
372 (defcustom tramp-bluez-discover-devices-timeout 60
373 "Defines seconds since last bluetooth device discovery before rescanning.
374 A value of 0 would require an immediate discovery during hostname
375 completion, nil means to use always cached values for discovered
376 devices."
377 :group 'tramp
378 :version "23.2"
379 :type '(choice (const nil) integer))
381 (defvar tramp-bluez-discovery nil
382 "Indicator for a running bluetooth device discovery.
383 It keeps the timestamp of last discovery.")
385 (defvar tramp-bluez-devices nil
386 "Alist of detected bluetooth devices.
387 Every entry is a list (NAME ADDRESS).")
389 (defconst tramp-hal-service "org.freedesktop.Hal"
390 "The well known name of the HAL service.")
392 (defconst tramp-hal-path-manager "/org/freedesktop/Hal/Manager"
393 "The object path of the HAL daemon manager.")
395 (defconst tramp-hal-interface-manager "org.freedesktop.Hal.Manager"
396 "The manager interface of the HAL daemon.")
398 (defconst tramp-hal-interface-device "org.freedesktop.Hal.Device"
399 "The device interface of the HAL daemon.")
402 ;; New handlers should be added here.
403 (defconst tramp-gvfs-file-name-handler-alist
405 (access-file . ignore)
406 (add-name-to-file . tramp-gvfs-handle-copy-file)
407 ;; `byte-compiler-base-file-name' performed by default handler.
408 (copy-file . tramp-gvfs-handle-copy-file)
409 (delete-directory . tramp-gvfs-handle-delete-directory)
410 (delete-file . tramp-gvfs-handle-delete-file)
411 ;; `diff-latest-backup-file' performed by default handler.
412 (directory-file-name . tramp-handle-directory-file-name)
413 (directory-files . tramp-handle-directory-files)
414 (directory-files-and-attributes
415 . tramp-handle-directory-files-and-attributes)
416 (dired-call-process . ignore)
417 (dired-compress-file . ignore)
418 (dired-uncache . tramp-handle-dired-uncache)
419 ;; `executable-find' is not official yet. performed by default handler.
420 (expand-file-name . tramp-gvfs-handle-expand-file-name)
421 (file-accessible-directory-p . tramp-handle-file-accessible-directory-p)
422 (file-acl . ignore)
423 (file-attributes . tramp-gvfs-handle-file-attributes)
424 (file-directory-p . tramp-gvfs-handle-file-directory-p)
425 (file-executable-p . tramp-gvfs-handle-file-executable-p)
426 (file-exists-p . tramp-handle-file-exists-p)
427 (file-local-copy . tramp-gvfs-handle-file-local-copy)
428 (file-modes . tramp-handle-file-modes)
429 (file-name-all-completions . tramp-gvfs-handle-file-name-all-completions)
430 (file-name-as-directory . tramp-handle-file-name-as-directory)
431 (file-name-completion . tramp-handle-file-name-completion)
432 (file-name-directory . tramp-handle-file-name-directory)
433 (file-name-nondirectory . tramp-handle-file-name-nondirectory)
434 ;; `file-name-sans-versions' performed by default handler.
435 (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
436 (file-ownership-preserved-p . ignore)
437 (file-readable-p . tramp-gvfs-handle-file-readable-p)
438 (file-regular-p . tramp-handle-file-regular-p)
439 (file-remote-p . tramp-handle-file-remote-p)
440 (file-selinux-context . ignore)
441 (file-symlink-p . tramp-handle-file-symlink-p)
442 ;; `file-truename' performed by default handler.
443 (file-writable-p . tramp-gvfs-handle-file-writable-p)
444 (find-backup-file-name . tramp-handle-find-backup-file-name)
445 ;; `find-file-noselect' performed by default handler.
446 ;; `get-file-buffer' performed by default handler.
447 (insert-directory . tramp-gvfs-handle-insert-directory)
448 (insert-file-contents . tramp-gvfs-handle-insert-file-contents)
449 (load . tramp-handle-load)
450 (make-directory . tramp-gvfs-handle-make-directory)
451 (make-directory-internal . ignore)
452 (make-symbolic-link . ignore)
453 (process-file . ignore)
454 (rename-file . tramp-gvfs-handle-rename-file)
455 (set-file-acl . ignore)
456 (set-file-modes . ignore)
457 (set-file-selinux-context . ignore)
458 (set-visited-file-modtime . tramp-gvfs-handle-set-visited-file-modtime)
459 (shell-command . ignore)
460 (start-file-process . ignore)
461 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
462 (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory)
463 (vc-registered . ignore)
464 ;; `verify-visited-file-modtime' performed by default handler.
465 (write-region . tramp-gvfs-handle-write-region)
467 "Alist of handler functions for Tramp GVFS method.
468 Operations not mentioned here will be handled by the default Emacs primitives.")
470 ;; It must be a `defsubst' in order to push the whole code into
471 ;; tramp-loaddefs.el. Otherwise, there would be recursive autoloading.
472 ;;;###tramp-autoload
473 (defsubst tramp-gvfs-file-name-p (filename)
474 "Check if it's a filename handled by the GVFS daemon."
475 (and (tramp-tramp-file-p filename)
476 (let ((method
477 (tramp-file-name-method (tramp-dissect-file-name filename))))
478 (and (stringp method) (member method tramp-gvfs-methods)))))
480 ;;;###tramp-autoload
481 (defun tramp-gvfs-file-name-handler (operation &rest args)
482 "Invoke the GVFS related OPERATION.
483 First arg specifies the OPERATION, second arg is a list of arguments to
484 pass to the OPERATION."
485 (let ((fn (assoc operation tramp-gvfs-file-name-handler-alist)))
486 (if fn
487 (save-match-data (apply (cdr fn) args))
488 (tramp-run-real-handler operation args))))
490 ;; This might be moved to tramp.el. It shall be the first file name
491 ;; handler.
492 ;;;###tramp-autoload
493 (when (featurep 'dbusbind)
494 (add-to-list 'tramp-foreign-file-name-handler-alist
495 (cons 'tramp-gvfs-file-name-p 'tramp-gvfs-file-name-handler)))
498 ;; D-Bus helper function.
500 (defun tramp-gvfs-dbus-string-to-byte-array (string)
501 "Like `dbus-string-to-byte-array' but add trailing \\0 if needed."
502 (dbus-string-to-byte-array
503 (if (string-match "^(aya{sv})" tramp-gvfs-mountlocation-signature)
504 (concat string (string 0)) string)))
506 (defun tramp-gvfs-dbus-byte-array-to-string (byte-array)
507 "Like `dbus-byte-array-to-string' but remove trailing \\0 if exists."
508 ;; The byte array could be a variant. Take care.
509 (let ((byte-array
510 (if (and (consp byte-array) (atom (car byte-array)))
511 byte-array (car byte-array))))
512 (dbus-byte-array-to-string
513 (if (and (consp byte-array) (zerop (car (last byte-array))))
514 (butlast byte-array) byte-array))))
516 (defun tramp-gvfs-stringify-dbus-message (message)
517 "Convert a D-Bus message into readable UTF8 strings, used for traces."
518 (cond
519 ((and (consp message) (characterp (car message)))
520 (format "%S" (tramp-gvfs-dbus-byte-array-to-string message)))
521 ((consp message)
522 (mapcar 'tramp-gvfs-stringify-dbus-message message))
523 ((stringp message)
524 (format "%S" message))
525 (t message)))
527 (defmacro with-tramp-dbus-call-method
528 (vec synchronous bus service path interface method &rest args)
529 "Apply a D-Bus call on bus BUS.
531 If SYNCHRONOUS is non-nil, the call is synchronously. Otherwise,
532 it is an asynchronous call, with `ignore' as callback function.
534 The other arguments have the same meaning as with `dbus-call-method'
535 or `dbus-call-method-asynchronously'. Additionally, the call
536 will be traced by Tramp with trace level 6."
537 `(let ((func (if ,synchronous
538 'dbus-call-method 'dbus-call-method-asynchronously))
539 (args (append (list ,bus ,service ,path ,interface ,method)
540 (if ,synchronous (list ,@args) (list 'ignore ,@args))))
541 result)
542 (tramp-message ,vec 6 "%s %s" func args)
543 (setq result (apply func args))
544 (tramp-message ,vec 6 "%s" (tramp-gvfs-stringify-dbus-message result))
545 result))
547 (put 'with-tramp-dbus-call-method 'lisp-indent-function 2)
548 (put 'with-tramp-dbus-call-method 'edebug-form-spec '(form symbolp body))
549 (tramp-compat-font-lock-add-keywords
550 'emacs-lisp-mode '("\\<with-tramp-dbus-call-method\\>"))
552 (defmacro with-tramp-gvfs-error-message (filename handler &rest args)
553 "Apply a Tramp GVFS `handler'.
554 In case of an error, modify the error message by replacing
555 `filename' with its GVFS mounted name."
556 `(let ((fuse-file-name (regexp-quote (tramp-gvfs-fuse-file-name ,filename)))
557 elt)
558 (condition-case err
559 (tramp-compat-funcall ,handler ,@args)
560 (error
561 (setq elt (cdr err))
562 (while elt
563 (when (and (stringp (car elt))
564 (string-match fuse-file-name (car elt)))
565 (setcar elt (replace-match ,filename t t (car elt))))
566 (setq elt (cdr elt)))
567 (signal (car err) (cdr err))))))
569 (put 'with-tramp-gvfs-error-message 'lisp-indent-function 2)
570 (put 'with-tramp-gvfs-error-message 'edebug-form-spec '(form symbolp body))
571 (tramp-compat-font-lock-add-keywords
572 'emacs-lisp-mode '("\\<with-tramp-gvfs-error-message\\>"))
574 (defvar tramp-gvfs-dbus-event-vector nil
575 "Current Tramp file name to be used, as vector.
576 It is needed when D-Bus signals or errors arrive, because there
577 is no information where to trace the message.")
579 (defun tramp-gvfs-dbus-event-error (event err)
580 "Called when a D-Bus error message arrives, see `dbus-event-error-functions'."
581 (when tramp-gvfs-dbus-event-vector
582 (tramp-message tramp-gvfs-dbus-event-vector 10 "%S" event)
583 (tramp-error tramp-gvfs-dbus-event-vector 'file-error "%s" (cadr err))))
585 ;; `dbus-event-error-hooks' has been renamed to `dbus-event-error-functions'.
586 (add-hook
587 (if (boundp 'dbus-event-error-functions)
588 'dbus-event-error-functions 'dbus-event-error-hooks)
589 'tramp-gvfs-dbus-event-error)
592 ;; File name primitives.
594 (defun tramp-gvfs-handle-copy-file
595 (filename newname &optional ok-if-already-exists keep-date
596 preserve-uid-gid preserve-extended-attributes)
597 "Like `copy-file' for Tramp files."
598 (with-parsed-tramp-file-name
599 (if (tramp-tramp-file-p filename) filename newname) nil
601 (when (and (not ok-if-already-exists) (file-exists-p newname))
602 (tramp-error
603 v 'file-already-exists "File %s already exists" newname))
605 (if (or (and (tramp-tramp-file-p filename)
606 (not (tramp-gvfs-file-name-p filename)))
607 (and (tramp-tramp-file-p newname)
608 (not (tramp-gvfs-file-name-p newname))))
610 ;; We cannot copy directly.
611 (let ((tmpfile (tramp-compat-make-temp-file filename)))
612 (cond
613 (preserve-extended-attributes
614 (copy-file
615 filename tmpfile t keep-date preserve-uid-gid
616 preserve-extended-attributes))
617 (preserve-uid-gid
618 (copy-file filename tmpfile t keep-date preserve-uid-gid))
620 (copy-file filename tmpfile t keep-date)))
621 (rename-file tmpfile newname ok-if-already-exists))
623 ;; Direct copy.
624 (with-tramp-progress-reporter
625 v 0 (format "Copying %s to %s" filename newname)
626 (unless
627 (let ((args
628 (append (if (or keep-date preserve-uid-gid)
629 (list "--preserve")
630 nil)
631 (list
632 (tramp-gvfs-url-file-name filename)
633 (tramp-gvfs-url-file-name newname)))))
634 (apply 'tramp-gvfs-send-command v "gvfs-copy" args))
635 ;; Propagate the error.
636 (with-current-buffer (tramp-get-connection-buffer v)
637 (goto-char (point-min))
638 (tramp-error-with-buffer
639 nil v 'file-error
640 "Copying failed, see buffer `%s' for details." (buffer-name)))))
642 (when (file-remote-p newname)
643 (with-parsed-tramp-file-name newname nil
644 (tramp-flush-file-property v (file-name-directory localname))
645 (tramp-flush-file-property v localname))))))
647 (defun tramp-gvfs-handle-delete-directory (directory &optional recursive trash)
648 "Like `delete-directory' for Tramp files."
649 (when (and recursive (not (file-symlink-p directory)))
650 (mapc (lambda (file)
651 (if (eq t (car (file-attributes file)))
652 (tramp-compat-delete-directory file recursive trash)
653 (tramp-compat-delete-file file trash)))
654 (directory-files
655 directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
656 (with-parsed-tramp-file-name directory nil
657 (tramp-flush-file-property v (file-name-directory localname))
658 (tramp-flush-directory-property v localname)
659 (unless
660 (tramp-gvfs-send-command
661 v (if (and trash delete-by-moving-to-trash) "gvfs-trash" "gvfs-rm")
662 (tramp-gvfs-url-file-name directory))
663 ;; Propagate the error.
664 (with-current-buffer (tramp-get-connection-buffer v)
665 (goto-char (point-min))
666 (tramp-error-with-buffer
667 nil v 'file-error "Couldn't delete %s" directory)))))
669 (defun tramp-gvfs-handle-delete-file (filename &optional trash)
670 "Like `delete-file' for Tramp files."
671 (with-parsed-tramp-file-name filename nil
672 (tramp-flush-file-property v (file-name-directory localname))
673 (tramp-flush-directory-property v localname)
674 (unless
675 (tramp-gvfs-send-command
676 v (if (and trash delete-by-moving-to-trash) "gvfs-trash" "gvfs-rm")
677 (tramp-gvfs-url-file-name filename))
678 ;; Propagate the error.
679 (with-current-buffer (tramp-get-connection-buffer v)
680 (goto-char (point-min))
681 (tramp-error-with-buffer
682 nil v 'file-error "Couldn't delete %s" filename)))))
684 (defun tramp-gvfs-handle-expand-file-name (name &optional dir)
685 "Like `expand-file-name' for Tramp files."
686 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
687 (setq dir (or dir default-directory "/"))
688 ;; Unless NAME is absolute, concat DIR and NAME.
689 (unless (file-name-absolute-p name)
690 (setq name (concat (file-name-as-directory dir) name)))
691 ;; If NAME is not a Tramp file, run the real handler.
692 (if (not (tramp-tramp-file-p name))
693 (tramp-run-real-handler 'expand-file-name (list name nil))
694 ;; Dissect NAME.
695 (with-parsed-tramp-file-name name nil
696 ;; If there is a default location, expand tilde.
697 (when (string-match "\\`\\(~\\)\\(/\\|\\'\\)" localname)
698 (save-match-data
699 (tramp-gvfs-maybe-open-connection (vector method user host "/" hop)))
700 (setq localname
701 (replace-match
702 (tramp-get-file-property v "/" "default-location" "~")
703 nil t localname 1)))
704 ;; Tilde expansion is not possible.
705 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
706 (tramp-error
707 v 'file-error
708 "Cannot expand tilde in file `%s'" name))
709 (unless (tramp-run-real-handler 'file-name-absolute-p (list localname))
710 (setq localname (concat "/" localname)))
711 ;; We do not pass "/..".
712 (if (string-equal "smb" method)
713 (when (string-match "^/[^/]+\\(/\\.\\./?\\)" localname)
714 (setq localname (replace-match "/" t t localname 1)))
715 (when (string-match "^/\\.\\./?" localname)
716 (setq localname (replace-match "/" t t localname))))
717 ;; There might be a double slash. Remove this.
718 (while (string-match "//" localname)
719 (setq localname (replace-match "/" t t localname)))
720 ;; No tilde characters in file name, do normal
721 ;; `expand-file-name' (this does "/./" and "/../").
722 (tramp-make-tramp-file-name
723 method user host
724 (tramp-run-real-handler
725 'expand-file-name (list localname))))))
727 (defun tramp-gvfs-handle-file-attributes (filename &optional id-format)
728 "Like `file-attributes' for Tramp files."
729 (unless id-format (setq id-format 'integer))
730 ;; Don't modify `last-coding-system-used' by accident.
731 (let ((last-coding-system-used last-coding-system-used)
732 dirp res-symlink-target res-numlinks res-uid res-gid res-access
733 res-mod res-change res-size res-filemodes res-inode res-device)
734 (with-parsed-tramp-file-name filename nil
735 (with-tramp-file-property
736 v localname (format "file-attributes-%s" id-format)
737 (tramp-message v 5 "file attributes: %s" localname)
738 (tramp-gvfs-send-command
739 v "gvfs-info" (tramp-gvfs-url-file-name filename))
740 ;; Parse output ...
741 (with-current-buffer (tramp-get-connection-buffer v)
742 (goto-char (point-min))
743 (when (re-search-forward "attributes:" nil t)
744 ;; ... directory or symlink
745 (goto-char (point-min))
746 (setq dirp (if (re-search-forward "type:\\s-+directory" nil t) t))
747 (goto-char (point-min))
748 (setq res-symlink-target
749 (if (re-search-forward
750 "standard::symlink-target:\\s-+\\(\\S-+\\)" nil t)
751 (match-string 1)))
752 ;; ... number links
753 (goto-char (point-min))
754 (setq res-numlinks
755 (if (re-search-forward "unix::nlink:\\s-+\\([0-9]+\\)" nil t)
756 (string-to-number (match-string 1)) 0))
757 ;; ... uid and gid
758 (goto-char (point-min))
759 (setq res-uid
760 (or (if (eq id-format 'integer)
761 (if (re-search-forward
762 "unix::uid:\\s-+\\([0-9]+\\)" nil t)
763 (string-to-number (match-string 1)))
764 (if (re-search-forward
765 "owner::user:\\s-+\\(\\S-+\\)" nil t)
766 (match-string 1)))
767 (tramp-get-local-uid id-format)))
768 (setq res-gid
769 (or (if (eq id-format 'integer)
770 (if (re-search-forward
771 "unix::gid:\\s-+\\([0-9]+\\)" nil t)
772 (string-to-number (match-string 1)))
773 (if (re-search-forward
774 "owner::group:\\s-+\\(\\S-+\\)" nil t)
775 (match-string 1)))
776 (tramp-get-local-gid id-format)))
777 ;; ... last access, modification and change time
778 (goto-char (point-min))
779 (setq res-access
780 (if (re-search-forward
781 "time::access:\\s-+\\([0-9]+\\)" nil t)
782 (seconds-to-time (string-to-number (match-string 1)))
783 '(0 0)))
784 (goto-char (point-min))
785 (setq res-mod
786 (if (re-search-forward
787 "time::modified:\\s-+\\([0-9]+\\)" nil t)
788 (seconds-to-time (string-to-number (match-string 1)))
789 '(0 0)))
790 (goto-char (point-min))
791 (setq res-change
792 (if (re-search-forward
793 "time::changed:\\s-+\\([0-9]+\\)" nil t)
794 (seconds-to-time (string-to-number (match-string 1)))
795 '(0 0)))
796 ;; ... size
797 (goto-char (point-min))
798 (setq res-size
799 (if (re-search-forward
800 "standard::size:\\s-+\\([0-9]+\\)" nil t)
801 (string-to-number (match-string 1)) 0))
802 ;; ... file mode flags
803 (goto-char (point-min))
804 (setq res-filemodes
805 (if (re-search-forward "unix::mode:\\s-+\\([0-9]+\\)" nil t)
806 (tramp-file-mode-from-int (match-string 1))
807 (if dirp "drwx------" "-rwx------")))
808 ;; ... inode and device
809 (goto-char (point-min))
810 (setq res-inode
811 (if (re-search-forward "unix::inode:\\s-+\\([0-9]+\\)" nil t)
812 (string-to-number (match-string 1))
813 (tramp-get-inode v)))
814 (goto-char (point-min))
815 (setq res-device
816 (if (re-search-forward "unix::device:\\s-+\\([0-9]+\\)" nil t)
817 (string-to-number (match-string 1))
818 (tramp-get-device v)))
820 ;; Return data gathered.
821 (list
822 ;; 0. t for directory, string (name linked to) for
823 ;; symbolic link, or nil.
824 (or dirp res-symlink-target)
825 ;; 1. Number of links to file.
826 res-numlinks
827 ;; 2. File uid.
828 res-uid
829 ;; 3. File gid.
830 res-gid
831 ;; 4. Last access time, as a list of integers.
832 ;; 5. Last modification time, likewise.
833 ;; 6. Last status change time, likewise.
834 res-access res-mod res-change
835 ;; 7. Size in bytes (-1, if number is out of range).
836 res-size
837 ;; 8. File modes.
838 res-filemodes
839 ;; 9. t if file's gid would change if file were deleted
840 ;; and recreated.
842 ;; 10. Inode number.
843 res-inode
844 ;; 11. Device number.
845 res-device
846 )))))))
848 (defun tramp-gvfs-handle-file-directory-p (filename)
849 "Like `file-directory-p' for Tramp files."
850 (eq t (car (file-attributes filename))))
852 (defun tramp-gvfs-handle-file-executable-p (filename)
853 "Like `file-executable-p' for Tramp files."
854 (with-parsed-tramp-file-name filename nil
855 (with-tramp-file-property v localname "file-executable-p"
856 (tramp-check-cached-permissions v ?x))))
858 (defun tramp-gvfs-handle-file-local-copy (filename)
859 "Like `file-local-copy' for Tramp files."
860 (with-parsed-tramp-file-name filename nil
861 (let ((tmpfile (tramp-compat-make-temp-file filename)))
862 (unless (file-exists-p filename)
863 (tramp-error
864 v 'file-error
865 "Cannot make local copy of non-existing file `%s'" filename))
866 (copy-file filename tmpfile t t)
867 tmpfile)))
869 (defun tramp-gvfs-handle-file-name-all-completions (filename directory)
870 "Like `file-name-all-completions' for Tramp files."
871 (unless (save-match-data (string-match "/" filename))
872 (with-parsed-tramp-file-name (expand-file-name directory) nil
874 (all-completions
875 filename
876 (mapcar
877 'list
879 ;; Try cache entries for filename, filename with last
880 ;; character removed, filename with last two characters
881 ;; removed, ..., and finally the empty string - all
882 ;; concatenated to the local directory name.
883 (let ((remote-file-name-inhibit-cache
884 (or remote-file-name-inhibit-cache
885 tramp-completion-reread-directory-timeout)))
887 ;; This is inefficient for very long filenames, pity
888 ;; `reduce' is not available...
889 (car
890 (apply
891 'append
892 (mapcar
893 (lambda (x)
894 (let ((cache-hit
895 (tramp-get-file-property
897 (concat localname (substring filename 0 x))
898 "file-name-all-completions"
899 nil)))
900 (when cache-hit (list cache-hit))))
901 ;; We cannot use a length of 0, because file properties
902 ;; for "foo" and "foo/" are identical.
903 (tramp-compat-number-sequence (length filename) 1 -1)))))
905 ;; Cache expired or no matching cache entry found so we need
906 ;; to perform a remote operation.
907 (let ((result '("." ".."))
908 entry)
909 ;; Get a list of directories and files.
910 (tramp-gvfs-send-command
911 v "gvfs-ls" (tramp-gvfs-url-file-name directory))
913 ;; Now grab the output.
914 (with-temp-buffer
915 (insert-buffer-substring (tramp-get-connection-buffer v))
916 (goto-char (point-max))
917 (while (zerop (forward-line -1))
918 (setq entry (buffer-substring (point) (point-at-eol)))
919 (when (string-match filename entry)
920 (if (file-directory-p (expand-file-name entry directory))
921 (push (concat entry "/") result)
922 (push entry result)))))
924 ;; Because the remote op went through OK we know the
925 ;; directory we `cd'-ed to exists.
926 (tramp-set-file-property v localname "file-exists-p" t)
928 ;; Because the remote op went through OK we know every
929 ;; file listed by `ls' exists.
930 (mapc (lambda (entry)
931 (tramp-set-file-property
932 v (concat localname entry) "file-exists-p" t))
933 result)
935 ;; Store result in the cache.
936 (tramp-set-file-property
937 v (concat localname filename)
938 "file-name-all-completions" result))))))))
940 (defun tramp-gvfs-handle-file-readable-p (filename)
941 "Like `file-readable-p' for Tramp files."
942 (with-parsed-tramp-file-name filename nil
943 (with-tramp-file-property v localname "file-executable-p"
944 (tramp-check-cached-permissions v ?r))))
946 (defun tramp-gvfs-handle-file-writable-p (filename)
947 "Like `file-writable-p' for Tramp files."
948 (with-parsed-tramp-file-name filename nil
949 (with-tramp-file-property v localname "file-writable-p"
950 (if (file-exists-p filename)
951 (tramp-check-cached-permissions v ?w)
952 ;; If file doesn't exist, check if directory is writable.
953 (and (file-directory-p (file-name-directory filename))
954 (file-writable-p (file-name-directory filename)))))))
956 (defun tramp-gvfs-handle-insert-directory
957 (filename switches &optional wildcard full-directory-p)
958 "Like `insert-directory' for Tramp files."
959 ;; gvfs-* output is hard to parse. So we let `ls-lisp' do the job.
960 (with-parsed-tramp-file-name (expand-file-name filename) nil
961 (with-tramp-progress-reporter v 0 (format "Opening directory %s" filename)
962 (require 'ls-lisp)
963 (let (ls-lisp-use-insert-directory-program)
964 (tramp-run-real-handler
965 'insert-directory
966 (list filename switches wildcard full-directory-p))))))
968 (defun tramp-gvfs-handle-insert-file-contents
969 (filename &optional visit beg end replace)
970 "Like `insert-file-contents' for Tramp files."
971 (barf-if-buffer-read-only)
972 (setq filename (expand-file-name filename))
973 (let (tmpfile result)
974 (unwind-protect
975 (if (not (file-exists-p filename))
976 ;; We don't raise a Tramp error, because it might be
977 ;; suppressed, like in `find-file-noselect-1'.
978 (signal 'file-error (list "File not found on remote host" filename))
980 (setq tmpfile (file-local-copy filename)
981 result (insert-file-contents tmpfile visit beg end replace)))
982 ;; Save exit.
983 (when visit
984 (setq buffer-file-name filename)
985 (setq buffer-read-only (not (file-writable-p filename)))
986 (set-visited-file-modtime)
987 (set-buffer-modified-p nil))
988 (when (stringp tmpfile)
989 (delete-file tmpfile)))
991 ;; Result.
992 (list filename (cadr result))))
994 (defun tramp-gvfs-handle-make-directory (dir &optional parents)
995 "Like `make-directory' for Tramp files."
996 (with-parsed-tramp-file-name dir nil
997 (unless
998 (apply
999 'tramp-gvfs-send-command v "gvfs-mkdir"
1000 (if parents
1001 (list "-p" (tramp-gvfs-url-file-name dir))
1002 (list (tramp-gvfs-url-file-name dir))))
1003 ;; Propagate the error.
1004 (tramp-error v 'file-error "Couldn't make directory %s" dir))))
1006 (defun tramp-gvfs-handle-rename-file
1007 (filename newname &optional ok-if-already-exists)
1008 "Like `rename-file' for Tramp files."
1009 (with-parsed-tramp-file-name
1010 (if (tramp-tramp-file-p filename) filename newname) nil
1012 (when (and (not ok-if-already-exists) (file-exists-p newname))
1013 (tramp-error
1014 v 'file-already-exists "File %s already exists" newname))
1016 (if (or (and (tramp-tramp-file-p filename)
1017 (not (tramp-gvfs-file-name-p filename)))
1018 (and (tramp-tramp-file-p newname)
1019 (not (tramp-gvfs-file-name-p newname))))
1021 ;; We cannot move directly.
1022 (let ((tmpfile (tramp-compat-make-temp-file filename)))
1023 (rename-file filename tmpfile t)
1024 (rename-file tmpfile newname ok-if-already-exists))
1026 ;; Direct move.
1027 (with-tramp-progress-reporter
1028 v 0 (format "Renaming %s to %s" filename newname)
1029 (unless
1030 (tramp-gvfs-send-command
1031 v "gvfs-move"
1032 (tramp-gvfs-url-file-name filename)
1033 (tramp-gvfs-url-file-name newname))
1034 ;; Propagate the error.
1035 (with-current-buffer (tramp-get-buffer v)
1036 (goto-char (point-min))
1037 (tramp-error-with-buffer
1038 nil v 'file-error
1039 "Renaming failed, see buffer `%s' for details." (buffer-name)))))
1041 (when (file-remote-p filename)
1042 (with-parsed-tramp-file-name filename nil
1043 (tramp-flush-file-property v (file-name-directory localname))
1044 (tramp-flush-file-property v localname)))
1046 (when (file-remote-p newname)
1047 (with-parsed-tramp-file-name newname nil
1048 (tramp-flush-file-property v (file-name-directory localname))
1049 (tramp-flush-file-property v localname))))))
1051 (defun tramp-gvfs-handle-set-visited-file-modtime (&optional time-list)
1052 "Like `set-visited-file-modtime' for Tramp files."
1053 (unless (buffer-file-name)
1054 (error "Can't set-visited-file-modtime: buffer `%s' not visiting a file"
1055 (buffer-name)))
1056 (unless time-list
1057 (let ((f (buffer-file-name)))
1058 (with-parsed-tramp-file-name f nil
1059 (let ((remote-file-name-inhibit-cache t)
1060 (attr (file-attributes f)))
1061 ;; '(-1 65535) means file doesn't exists yet.
1062 (setq time-list (or (nth 5 attr) '(-1 65535)))))))
1063 ;; We use '(0 0) as a don't-know value.
1064 (unless (not (equal time-list '(0 0)))
1065 (tramp-run-real-handler 'set-visited-file-modtime (list time-list))))
1067 (defun tramp-gvfs-handle-write-region
1068 (start end filename &optional append visit lockname confirm)
1069 "Like `write-region' for Tramp files."
1070 (with-parsed-tramp-file-name filename nil
1071 ;; XEmacs takes a coding system as the seventh argument, not `confirm'.
1072 (when (and (not (featurep 'xemacs)) confirm (file-exists-p filename))
1073 (unless (y-or-n-p (format "File %s exists; overwrite anyway? " filename))
1074 (tramp-error v 'file-error "File not overwritten")))
1076 (let ((tmpfile (tramp-compat-make-temp-file filename)))
1077 (write-region start end tmpfile)
1078 (condition-case nil
1079 (rename-file tmpfile filename)
1080 (error
1081 (delete-file tmpfile)
1082 (tramp-error
1083 v 'file-error "Couldn't write region to `%s'" filename))))
1085 (tramp-flush-file-property v (file-name-directory localname))
1086 (tramp-flush-file-property v localname)
1088 ;; Set file modification time.
1089 (when (or (eq visit t) (stringp visit))
1090 (set-visited-file-modtime (nth 5 (file-attributes filename))))
1092 ;; The end.
1093 (when (or (eq visit t) (null visit) (stringp visit))
1094 (tramp-message v 0 "Wrote %s" filename))
1095 (run-hooks 'tramp-handle-write-region-hook)))
1098 ;; File name conversions.
1100 (defun tramp-gvfs-url-file-name (filename)
1101 "Return FILENAME in URL syntax."
1102 ;; "/" must NOT be hexlified.
1103 (let ((url-unreserved-chars (append '(?/) url-unreserved-chars))
1104 result)
1105 (setq
1106 result
1107 (url-recreate-url
1108 (if (tramp-tramp-file-p filename)
1109 (with-parsed-tramp-file-name filename nil
1110 (when (and user (string-match tramp-user-with-domain-regexp user))
1111 (setq user
1112 (concat (match-string 2 user) ";" (match-string 1 user))))
1113 (url-parse-make-urlobj
1114 method (url-hexify-string user) nil
1115 (tramp-file-name-real-host v) (tramp-file-name-port v)
1116 (url-hexify-string localname) nil nil t))
1117 (url-parse-make-urlobj
1118 "file" nil nil nil nil
1119 (url-hexify-string (file-truename filename)) nil nil t))))
1120 (when (tramp-tramp-file-p filename)
1121 (with-parsed-tramp-file-name filename nil
1122 (tramp-message v 10 "remote file `%s' is URL `%s'" filename result)))
1123 result))
1125 (defun tramp-gvfs-object-path (filename)
1126 "Create a D-Bus object path from FILENAME."
1127 (expand-file-name (dbus-escape-as-identifier filename) tramp-gvfs-path-tramp))
1129 (defun tramp-gvfs-file-name (object-path)
1130 "Retrieve file name from D-Bus OBJECT-PATH."
1131 (dbus-unescape-from-identifier
1132 (replace-regexp-in-string "^.*/\\([^/]+\\)$" "\\1" object-path)))
1134 (defun tramp-gvfs-fuse-file-name (filename)
1135 "Return FUSE file name, which is directly accessible."
1136 (with-parsed-tramp-file-name (expand-file-name filename) nil
1137 (tramp-gvfs-maybe-open-connection v)
1138 (let ((prefix (tramp-get-file-property v "/" "prefix" ""))
1139 (fuse-mountpoint
1140 (tramp-get-file-property v "/" "fuse-mountpoint" nil)))
1141 (unless fuse-mountpoint
1142 (tramp-error
1143 v 'file-error "There is no FUSE mount point for `%s'" filename))
1144 ;; We must hide the prefix, if any.
1145 (when (string-match (concat "^" (regexp-quote prefix)) localname)
1146 (setq localname (replace-match "" t t localname)))
1147 (tramp-message
1148 v 10 "remote file `%s' is local file `%s'"
1149 filename (concat fuse-mountpoint localname))
1150 (concat fuse-mountpoint localname))))
1152 (defun tramp-bluez-address (device)
1153 "Return bluetooth device address from a given bluetooth DEVICE name."
1154 (when (stringp device)
1155 (if (string-match tramp-ipv6-regexp device)
1156 (match-string 0 device)
1157 (cadr (assoc device (tramp-bluez-list-devices))))))
1159 (defun tramp-bluez-device (address)
1160 "Return bluetooth device name from a given bluetooth device ADDRESS.
1161 ADDRESS can have the form \"xx:xx:xx:xx:xx:xx\" or \"[xx:xx:xx:xx:xx:xx]\"."
1162 (when (stringp address)
1163 (while (string-match "[][]" address)
1164 (setq address (replace-match "" t t address)))
1165 (let (result)
1166 (dolist (item (tramp-bluez-list-devices) result)
1167 (when (string-match address (cadr item))
1168 (setq result (car item)))))))
1171 ;; D-Bus GVFS functions.
1173 (defun tramp-gvfs-handler-askpassword (message user domain flags)
1174 "Implementation for the \"org.gtk.vfs.MountOperation.askPassword\" method."
1175 (let* ((filename
1176 (tramp-gvfs-file-name (dbus-event-path-name last-input-event)))
1177 (pw-prompt
1178 (format
1179 "%s for %s "
1180 (if (string-match "\\([pP]assword\\|[pP]assphrase\\)" message)
1181 (capitalize (match-string 1 message))
1182 "Password")
1183 filename))
1184 password)
1186 (condition-case nil
1187 (with-parsed-tramp-file-name filename l
1188 (when (and (zerop (length user))
1189 (not
1190 (zerop (logand flags tramp-gvfs-password-need-username))))
1191 (setq user (read-string "User name: ")))
1192 (when (and (zerop (length domain))
1193 (not (zerop (logand flags tramp-gvfs-password-need-domain))))
1194 (setq domain (read-string "Domain name: ")))
1196 (tramp-message l 6 "%S %S %S %d" message user domain flags)
1197 (setq tramp-current-method l-method
1198 tramp-current-user user
1199 tramp-current-host l-host
1200 password (tramp-read-passwd
1201 (tramp-get-connection-process l) pw-prompt))
1203 ;; Return result.
1204 (if (stringp password)
1205 (list
1206 t ;; password handled.
1207 nil ;; no abort of D-Bus.
1208 password
1209 (tramp-file-name-real-user l)
1210 domain
1211 nil ;; not anonymous.
1212 0) ;; no password save.
1213 ;; No password provided.
1214 (list nil t "" (tramp-file-name-real-user l) domain nil 0)))
1216 ;; When QUIT is raised, we shall return this information to D-Bus.
1217 (quit (list nil t "" "" "" nil 0)))))
1219 (defun tramp-gvfs-handler-askquestion (message choices)
1220 "Implementation for the \"org.gtk.vfs.MountOperation.askQuestion\" method."
1221 (save-window-excursion
1222 (let ((enable-recursive-minibuffers t)
1223 choice)
1225 (condition-case nil
1226 (with-parsed-tramp-file-name
1227 (tramp-gvfs-file-name (dbus-event-path-name last-input-event)) nil
1228 (tramp-message v 6 "%S %S" message choices)
1230 ;; In theory, there can be several choices. Until now,
1231 ;; there is only the question whether to accept an unknown
1232 ;; host signature.
1233 (with-temp-buffer
1234 ;; Preserve message for `progress-reporter'.
1235 (tramp-compat-with-temp-message ""
1236 (insert message)
1237 (pop-to-buffer (current-buffer))
1238 (setq choice (if (yes-or-no-p (concat (car choices) " ")) 0 1))
1239 (tramp-message v 6 "%d" choice)))
1241 ;; When the choice is "no", we set a dummy fuse-mountpoint
1242 ;; in order to leave the timeout.
1243 (unless (zerop choice)
1244 (tramp-set-file-property v "/" "fuse-mountpoint" "/"))
1246 (list
1247 t ;; handled.
1248 nil ;; no abort of D-Bus.
1249 choice))
1251 ;; When QUIT is raised, we shall return this information to D-Bus.
1252 (quit (list nil t 0))))))
1254 (defun tramp-gvfs-handler-mounted-unmounted (mount-info)
1255 "Signal handler for the \"org.gtk.vfs.MountTracker.mounted\" and
1256 \"org.gtk.vfs.MountTracker.unmounted\" signals."
1257 (ignore-errors
1258 (let ((signal-name (dbus-event-member-name last-input-event))
1259 (elt mount-info))
1260 ;; Jump over the first elements of the mount info. Since there
1261 ;; were changes in the entries, we cannot access dedicated
1262 ;; elements.
1263 (while (stringp (car elt)) (setq elt (cdr elt)))
1264 (let* ((fuse-mountpoint (tramp-gvfs-dbus-byte-array-to-string (cadr elt)))
1265 (mount-spec (caddr elt))
1266 (default-location (tramp-gvfs-dbus-byte-array-to-string
1267 (cadddr elt)))
1268 (method (tramp-gvfs-dbus-byte-array-to-string
1269 (cadr (assoc "type" (cadr mount-spec)))))
1270 (user (tramp-gvfs-dbus-byte-array-to-string
1271 (cadr (assoc "user" (cadr mount-spec)))))
1272 (domain (tramp-gvfs-dbus-byte-array-to-string
1273 (cadr (assoc "domain" (cadr mount-spec)))))
1274 (host (tramp-gvfs-dbus-byte-array-to-string
1275 (cadr (or (assoc "host" (cadr mount-spec))
1276 (assoc "server" (cadr mount-spec))))))
1277 (port (tramp-gvfs-dbus-byte-array-to-string
1278 (cadr (assoc "port" (cadr mount-spec)))))
1279 (ssl (tramp-gvfs-dbus-byte-array-to-string
1280 (cadr (assoc "ssl" (cadr mount-spec)))))
1281 (prefix (concat (tramp-gvfs-dbus-byte-array-to-string
1282 (car mount-spec))
1283 (tramp-gvfs-dbus-byte-array-to-string
1284 (cadr (assoc "share" (cadr mount-spec)))))))
1285 (when (string-match "^smb" method)
1286 (setq method "smb"))
1287 (when (string-equal "obex" method)
1288 (setq host (tramp-bluez-device host)))
1289 (when (and (string-equal "dav" method) (string-equal "true" ssl))
1290 (setq method "davs"))
1291 (unless (zerop (length domain))
1292 (setq user (concat user tramp-prefix-domain-format domain)))
1293 (unless (zerop (length port))
1294 (setq host (concat host tramp-prefix-port-format port)))
1295 (with-parsed-tramp-file-name
1296 (tramp-make-tramp-file-name method user host "") nil
1297 (tramp-message
1298 v 6 "%s %s"
1299 signal-name (tramp-gvfs-stringify-dbus-message mount-info))
1300 (tramp-set-file-property v "/" "list-mounts" 'undef)
1301 (if (string-equal (downcase signal-name) "unmounted")
1302 (tramp-set-file-property v "/" "fuse-mountpoint" nil)
1303 ;; Set prefix, mountpoint and location.
1304 (unless (string-equal prefix "/")
1305 (tramp-set-file-property v "/" "prefix" prefix))
1306 (tramp-set-file-property v "/" "fuse-mountpoint" fuse-mountpoint)
1307 (tramp-set-file-property
1308 v "/" "default-location" default-location)))))))
1310 (dbus-register-signal
1311 :session nil tramp-gvfs-path-mounttracker
1312 tramp-gvfs-interface-mounttracker "mounted"
1313 'tramp-gvfs-handler-mounted-unmounted)
1314 (dbus-register-signal
1315 :session nil tramp-gvfs-path-mounttracker
1316 tramp-gvfs-interface-mounttracker "Mounted"
1317 'tramp-gvfs-handler-mounted-unmounted)
1319 (dbus-register-signal
1320 :session nil tramp-gvfs-path-mounttracker
1321 tramp-gvfs-interface-mounttracker "unmounted"
1322 'tramp-gvfs-handler-mounted-unmounted)
1323 (dbus-register-signal
1324 :session nil tramp-gvfs-path-mounttracker
1325 tramp-gvfs-interface-mounttracker "Unmounted"
1326 'tramp-gvfs-handler-mounted-unmounted)
1328 (defun tramp-gvfs-connection-mounted-p (vec)
1329 "Check, whether the location is already mounted."
1331 (tramp-get-file-property vec "/" "fuse-mountpoint" nil)
1332 (catch 'mounted
1333 (dolist
1334 (elt
1335 (with-tramp-file-property vec "/" "list-mounts"
1336 (with-tramp-dbus-call-method vec t
1337 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1338 tramp-gvfs-interface-mounttracker tramp-gvfs-listmounts))
1339 nil)
1340 ;; Jump over the first elements of the mount info. Since there
1341 ;; were changes in the entries, we cannot access dedicated
1342 ;; elements.
1343 (while (stringp (car elt)) (setq elt (cdr elt)))
1344 (let* ((fuse-mountpoint (tramp-gvfs-dbus-byte-array-to-string
1345 (cadr elt)))
1346 (mount-spec (caddr elt))
1347 (default-location (tramp-gvfs-dbus-byte-array-to-string
1348 (cadddr elt)))
1349 (method (tramp-gvfs-dbus-byte-array-to-string
1350 (cadr (assoc "type" (cadr mount-spec)))))
1351 (user (tramp-gvfs-dbus-byte-array-to-string
1352 (cadr (assoc "user" (cadr mount-spec)))))
1353 (domain (tramp-gvfs-dbus-byte-array-to-string
1354 (cadr (assoc "domain" (cadr mount-spec)))))
1355 (host (tramp-gvfs-dbus-byte-array-to-string
1356 (cadr (or (assoc "host" (cadr mount-spec))
1357 (assoc "server" (cadr mount-spec))))))
1358 (port (tramp-gvfs-dbus-byte-array-to-string
1359 (cadr (assoc "port" (cadr mount-spec)))))
1360 (ssl (tramp-gvfs-dbus-byte-array-to-string
1361 (cadr (assoc "ssl" (cadr mount-spec)))))
1362 (prefix (concat (tramp-gvfs-dbus-byte-array-to-string
1363 (car mount-spec))
1364 (tramp-gvfs-dbus-byte-array-to-string
1365 (cadr (assoc "share" (cadr mount-spec)))))))
1366 (when (string-match "^smb" method)
1367 (setq method "smb"))
1368 (when (string-equal "obex" method)
1369 (setq host (tramp-bluez-device host)))
1370 (when (and (string-equal "dav" method) (string-equal "true" ssl))
1371 (setq method "davs"))
1372 (when (and (string-equal "synce" method) (zerop (length user)))
1373 (setq user (or (tramp-file-name-user vec) "")))
1374 (unless (zerop (length domain))
1375 (setq user (concat user tramp-prefix-domain-format domain)))
1376 (unless (zerop (length port))
1377 (setq host (concat host tramp-prefix-port-format port)))
1378 (when (and
1379 (string-equal method (tramp-file-name-method vec))
1380 (string-equal user (or (tramp-file-name-user vec) ""))
1381 (string-equal host (tramp-file-name-host vec))
1382 (string-match (concat "^" (regexp-quote prefix))
1383 (tramp-file-name-localname vec)))
1384 ;; Set prefix, mountpoint and location.
1385 (unless (string-equal prefix "/")
1386 (tramp-set-file-property vec "/" "prefix" prefix))
1387 (tramp-set-file-property vec "/" "fuse-mountpoint" fuse-mountpoint)
1388 (tramp-set-file-property vec "/" "default-location" default-location)
1389 (throw 'mounted t)))))))
1391 (defun tramp-gvfs-mount-spec-entry (key value)
1392 "Construct a mount-spec entry to be used in a mount_spec.
1393 It was \"a(say)\", but has changed to \"a{sv})\"."
1394 (if (string-match "^(aya{sv})" tramp-gvfs-mountlocation-signature)
1395 (list :dict-entry key
1396 (list :variant (tramp-gvfs-dbus-string-to-byte-array value)))
1397 (list :struct key (tramp-gvfs-dbus-string-to-byte-array value))))
1399 (defun tramp-gvfs-mount-spec (vec)
1400 "Return a mount-spec for \"org.gtk.vfs.MountTracker.mountLocation\"."
1401 (let* ((method (tramp-file-name-method vec))
1402 (user (tramp-file-name-real-user vec))
1403 (domain (tramp-file-name-domain vec))
1404 (host (tramp-file-name-real-host vec))
1405 (port (tramp-file-name-port vec))
1406 (localname (tramp-file-name-localname vec))
1407 (ssl (if (string-match "^davs" method) "true" "false"))
1408 (mount-spec '(:array))
1409 (mount-pref "/"))
1411 (setq
1412 mount-spec
1413 (append
1414 mount-spec
1415 (cond
1416 ((string-equal "smb" method)
1417 (string-match "^/?\\([^/]+\\)" localname)
1418 (list (tramp-gvfs-mount-spec-entry "type" "smb-share")
1419 (tramp-gvfs-mount-spec-entry "server" host)
1420 (tramp-gvfs-mount-spec-entry "share" (match-string 1 localname))))
1421 ((string-equal "obex" method)
1422 (list (tramp-gvfs-mount-spec-entry "type" method)
1423 (tramp-gvfs-mount-spec-entry
1424 "host" (concat "[" (tramp-bluez-address host) "]"))))
1425 ((string-match "^dav" method)
1426 (list (tramp-gvfs-mount-spec-entry "type" "dav")
1427 (tramp-gvfs-mount-spec-entry "host" host)
1428 (tramp-gvfs-mount-spec-entry "ssl" ssl)))
1430 (list (tramp-gvfs-mount-spec-entry "type" method)
1431 (tramp-gvfs-mount-spec-entry "host" host))))))
1433 (when user
1434 (add-to-list
1435 'mount-spec (tramp-gvfs-mount-spec-entry "user" user) 'append))
1437 (when domain
1438 (add-to-list
1439 'mount-spec (tramp-gvfs-mount-spec-entry "domain" domain) 'append))
1441 (when port
1442 (add-to-list
1443 'mount-spec (tramp-gvfs-mount-spec-entry "port" (number-to-string port))
1444 'append))
1446 (when (and (string-match "^dav" method)
1447 (string-match "^/?[^/]+" localname))
1448 (setq mount-pref (match-string 0 localname)))
1450 ;; Return.
1451 `(:struct ,(tramp-gvfs-dbus-string-to-byte-array mount-pref) ,mount-spec)))
1454 ;; Connection functions
1456 (defun tramp-gvfs-maybe-open-connection (vec)
1457 "Maybe open a connection VEC.
1458 Does not do anything if a connection is already open, but re-opens the
1459 connection if a previous connection has died for some reason."
1461 ;; We set the file name, in case there are incoming D-Bus signals or
1462 ;; D-Bus errors.
1463 (setq tramp-gvfs-dbus-event-vector vec)
1465 ;; For password handling, we need a process bound to the connection
1466 ;; buffer. Therefore, we create a dummy process. Maybe there is a
1467 ;; better solution?
1468 (unless (get-buffer-process (tramp-get-connection-buffer vec))
1469 (let ((p (make-network-process
1470 :name (tramp-buffer-name vec)
1471 :buffer (tramp-get-connection-buffer vec)
1472 :server t :host 'local :service t)))
1473 (tramp-compat-set-process-query-on-exit-flag p nil)))
1475 (unless (tramp-gvfs-connection-mounted-p vec)
1476 (let* ((method (tramp-file-name-method vec))
1477 (user (tramp-file-name-user vec))
1478 (host (tramp-file-name-host vec))
1479 (localname (tramp-file-name-localname vec))
1480 (object-path
1481 (tramp-gvfs-object-path
1482 (tramp-make-tramp-file-name method user host ""))))
1484 (when (and (string-equal method "smb")
1485 (string-equal localname "/"))
1486 (tramp-error vec 'file-error "Filename must contain a Windows share"))
1488 (with-tramp-progress-reporter
1489 vec 3
1490 (if (zerop (length user))
1491 (format "Opening connection for %s using %s" host method)
1492 (format "Opening connection for %s@%s using %s" user host method))
1494 ;; Enable auth-source and password-cache.
1495 (tramp-set-connection-property vec "first-password-request" t)
1497 ;; There will be a callback of "askPassword" when a password is
1498 ;; needed.
1499 (dbus-register-method
1500 :session dbus-service-emacs object-path
1501 tramp-gvfs-interface-mountoperation "askPassword"
1502 'tramp-gvfs-handler-askpassword)
1503 (dbus-register-method
1504 :session dbus-service-emacs object-path
1505 tramp-gvfs-interface-mountoperation "AskPassword"
1506 'tramp-gvfs-handler-askpassword)
1508 ;; There could be a callback of "askQuestion" when adding fingerprint.
1509 (dbus-register-method
1510 :session dbus-service-emacs object-path
1511 tramp-gvfs-interface-mountoperation "askQuestion"
1512 'tramp-gvfs-handler-askquestion)
1513 (dbus-register-method
1514 :session dbus-service-emacs object-path
1515 tramp-gvfs-interface-mountoperation "AskQuestion"
1516 'tramp-gvfs-handler-askquestion)
1518 ;; The call must be asynchronously, because of the "askPassword"
1519 ;; or "askQuestion"callbacks.
1520 (if (string-match "(so)$" tramp-gvfs-mountlocation-signature)
1521 (with-tramp-dbus-call-method vec nil
1522 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1523 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation
1524 (tramp-gvfs-mount-spec vec)
1525 `(:struct :string ,(dbus-get-unique-name :session)
1526 :object-path ,object-path))
1527 (with-tramp-dbus-call-method vec nil
1528 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1529 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation
1530 (tramp-gvfs-mount-spec vec)
1531 :string (dbus-get-unique-name :session) :object-path object-path))
1533 ;; We must wait, until the mount is applied. This will be
1534 ;; indicated by the "mounted" signal, i.e. the "fuse-mountpoint"
1535 ;; file property.
1536 (with-timeout
1538 (if (zerop (length (tramp-file-name-user vec)))
1539 (tramp-error
1540 vec 'file-error
1541 "Timeout reached mounting %s using %s" host method)
1542 (tramp-error
1543 vec 'file-error
1544 "Timeout reached mounting %s@%s using %s" user host method)))
1545 (while (not (tramp-get-file-property vec "/" "fuse-mountpoint" nil))
1546 (read-event nil nil 0.1)))
1548 ;; If `tramp-gvfs-handler-askquestion' has returned "No", it
1549 ;; is marked with the fuse-mountpoint "/". We shall react.
1550 (when (string-equal
1551 (tramp-get-file-property vec "/" "fuse-mountpoint" "") "/")
1552 (tramp-error vec 'file-error "FUSE mount denied"))
1554 ;; In `tramp-check-cached-permissions', the connection
1555 ;; properties {uig,gid}-{integer,string} are used. We set
1556 ;; them to their local counterparts.
1557 (tramp-set-connection-property
1558 vec "uid-integer" (tramp-get-local-uid 'integer))
1559 (tramp-set-connection-property
1560 vec "gid-integer" (tramp-get-local-gid 'integer))
1561 (tramp-set-connection-property
1562 vec "uid-string" (tramp-get-local-uid 'string))
1563 (tramp-set-connection-property
1564 vec "gid-string" (tramp-get-local-gid 'string))))))
1566 (defun tramp-gvfs-send-command (vec command &rest args)
1567 "Send the COMMAND with its ARGS to connection VEC.
1568 COMMAND is usually a command from the gvfs-* utilities.
1569 `call-process' is applied, and it returns `t' if the return code is zero."
1570 (let (result)
1571 (with-current-buffer (tramp-get-connection-buffer vec)
1572 (tramp-gvfs-maybe-open-connection vec)
1573 (erase-buffer)
1574 (tramp-message vec 6 "%s %s" command (mapconcat 'identity args " "))
1575 (setq result (apply 'tramp-call-process command nil t nil args))
1576 (tramp-message vec 6 "\n%s" (buffer-string))
1577 (zerop result))))
1580 ;; D-Bus BLUEZ functions.
1582 (defun tramp-bluez-list-devices ()
1583 "Return all discovered bluetooth devices as list.
1584 Every entry is a list (NAME ADDRESS).
1586 If `tramp-bluez-discover-devices-timeout' is an integer, and the last
1587 discovery happened more time before indicated there, a rescan will be
1588 started, which lasts some ten seconds. Otherwise, cached results will
1589 be used."
1590 ;; Reset the scanned devices list if time has passed.
1591 (and (integerp tramp-bluez-discover-devices-timeout)
1592 (integerp tramp-bluez-discovery)
1593 (> (tramp-time-diff (current-time) tramp-bluez-discovery)
1594 tramp-bluez-discover-devices-timeout)
1595 (setq tramp-bluez-devices nil))
1597 ;; Rescan if needed.
1598 (unless tramp-bluez-devices
1599 (let ((object-path
1600 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1601 :system tramp-bluez-service "/"
1602 tramp-bluez-interface-manager "DefaultAdapter")))
1603 (setq tramp-bluez-devices nil
1604 tramp-bluez-discovery t)
1605 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector nil
1606 :system tramp-bluez-service object-path
1607 tramp-bluez-interface-adapter "StartDiscovery")
1608 (while tramp-bluez-discovery
1609 (read-event nil nil 0.1))))
1610 (setq tramp-bluez-discovery (current-time))
1611 (tramp-message tramp-gvfs-dbus-event-vector 10 "%s" tramp-bluez-devices)
1612 tramp-bluez-devices)
1614 (defun tramp-bluez-property-changed (property value)
1615 "Signal handler for the \"org.bluez.Adapter.PropertyChanged\" signal."
1616 (tramp-message tramp-gvfs-dbus-event-vector 6 "%s %s" property value)
1617 (cond
1618 ((string-equal property "Discovering")
1619 (unless (car value)
1620 ;; "Discovering" FALSE means discovery run has been completed.
1621 ;; We stop it, because we don't need another run.
1622 (setq tramp-bluez-discovery nil)
1623 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1624 :system tramp-bluez-service (dbus-event-path-name last-input-event)
1625 tramp-bluez-interface-adapter "StopDiscovery")))))
1627 (dbus-register-signal
1628 :system nil nil tramp-bluez-interface-adapter "PropertyChanged"
1629 'tramp-bluez-property-changed)
1631 (defun tramp-bluez-device-found (device args)
1632 "Signal handler for the \"org.bluez.Adapter.DeviceFound\" signal."
1633 (tramp-message tramp-gvfs-dbus-event-vector 6 "%s %s" device args)
1634 (let ((alias (car (cadr (assoc "Alias" args))))
1635 (address (car (cadr (assoc "Address" args)))))
1636 ;; Maybe we shall check the device class for being a proper
1637 ;; device, and call also SDP in order to find the obex service.
1638 (add-to-list 'tramp-bluez-devices (list alias address))))
1640 (dbus-register-signal
1641 :system nil nil tramp-bluez-interface-adapter "DeviceFound"
1642 'tramp-bluez-device-found)
1644 (defun tramp-bluez-parse-device-names (ignore)
1645 "Return a list of (nil host) tuples allowed to access."
1646 (mapcar
1647 (lambda (x) (list nil (car x)))
1648 (tramp-bluez-list-devices)))
1650 ;; Add completion function for OBEX method.
1651 (when (member tramp-bluez-service (dbus-list-known-names :system))
1652 (tramp-set-completion-function
1653 "obex" '((tramp-bluez-parse-device-names ""))))
1656 ;; D-Bus zeroconf functions.
1658 (defun tramp-zeroconf-parse-workstation-device-names (ignore)
1659 "Return a list of (user host) tuples allowed to access."
1660 (mapcar
1661 (lambda (x)
1662 (list nil (zeroconf-service-host x)))
1663 (zeroconf-list-services "_workstation._tcp")))
1665 (defun tramp-zeroconf-parse-webdav-device-names (ignore)
1666 "Return a list of (user host) tuples allowed to access."
1667 (mapcar
1668 (lambda (x)
1669 (let ((host (zeroconf-service-host x))
1670 (port (zeroconf-service-port x))
1671 (text (zeroconf-service-txt x))
1672 user)
1673 (when port
1674 (setq host (format "%s%s%d" host tramp-prefix-port-regexp port)))
1675 ;; A user is marked in a TXT field like "u=guest".
1676 (while text
1677 (when (string-match "u=\\(.+\\)$" (car text))
1678 (setq user (match-string 1 (car text))))
1679 (setq text (cdr text)))
1680 (list user host)))
1681 (zeroconf-list-services "_webdav._tcp")))
1683 ;; Add completion function for DAV and DAVS methods.
1684 (when (member zeroconf-service-avahi (dbus-list-known-names :system))
1685 (zeroconf-init tramp-gvfs-zeroconf-domain)
1686 (tramp-set-completion-function
1687 "sftp" '((tramp-zeroconf-parse-workstation-device-names "")))
1688 (tramp-set-completion-function
1689 "dav" '((tramp-zeroconf-parse-webdav-device-names "")))
1690 (tramp-set-completion-function
1691 "davs" '((tramp-zeroconf-parse-webdav-device-names ""))))
1694 ;; D-Bus SYNCE functions.
1696 (defun tramp-synce-list-devices ()
1697 "Return all discovered synce devices as list.
1698 They are retrieved from the hal daemon."
1699 (let (tramp-synce-devices)
1700 (dolist (device
1701 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1702 :system tramp-hal-service tramp-hal-path-manager
1703 tramp-hal-interface-manager "GetAllDevices"))
1704 (when (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1705 :system tramp-hal-service device tramp-hal-interface-device
1706 "PropertyExists" "sync.plugin")
1707 (add-to-list
1708 'tramp-synce-devices
1709 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1710 :system tramp-hal-service device tramp-hal-interface-device
1711 "GetPropertyString" "pda.pocketpc.name"))))
1712 (tramp-message tramp-gvfs-dbus-event-vector 10 "%s" tramp-synce-devices)
1713 tramp-synce-devices))
1715 (defun tramp-synce-parse-device-names (ignore)
1716 "Return a list of (nil host) tuples allowed to access."
1717 (mapcar
1718 (lambda (x) (list nil x))
1719 (tramp-synce-list-devices)))
1721 ;; Add completion function for SYNCE method.
1722 (tramp-set-completion-function
1723 "synce" '((tramp-synce-parse-device-names "")))
1725 (add-hook 'tramp-unload-hook
1726 (lambda ()
1727 (unload-feature 'tramp-gvfs 'force)))
1729 (provide 'tramp-gvfs)
1731 ;;; TODO:
1733 ;; * Host name completion via smb-server or smb-network.
1734 ;; * Check how two shares of the same SMB server can be mounted in
1735 ;; parallel.
1736 ;; * Apply SDP on bluetooth devices, in order to filter out obex
1737 ;; capability.
1738 ;; * Implement obex for other serial communication but bluetooth.
1740 ;;; tramp-gvfs.el ends here