In Tramp. check ssh Control* options only when needed
[emacs.git] / lisp / net / tramp-gvfs.el
blob5988a284c6eef47e15a85ad12bee9a39770de19a
1 ;;; tramp-gvfs.el --- Tramp access functions for GVFS daemon
3 ;; Copyright (C) 2009-2015 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", "sftp" and "synce". Note that with "obex" it might
53 ;; be 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" and "smb". When one of
58 ;; these methods is added to the list, the remote access for that
59 ;; 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 (require 'tramp)
102 (require 'dbus)
103 (require 'url-parse)
104 (require 'url-util)
105 (require 'zeroconf)
107 ;; Pacify byte-compiler.
108 (eval-when-compile
109 (require 'cl)
110 (require 'custom))
112 ;;;###tramp-autoload
113 (defcustom tramp-gvfs-methods '("dav" "davs" "obex" "sftp" "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 ;;;###tramp-autoload
131 (defcustom tramp-gvfs-zeroconf-domain "local"
132 "Zeroconf domain to be used for discovering services, like host names."
133 :group 'tramp
134 :version "23.2"
135 :type 'string)
137 ;; Add the methods to `tramp-methods', in order to allow minibuffer
138 ;; completion.
139 ;;;###tramp-autoload
140 (when (featurep 'dbusbind)
141 (dolist (elt tramp-gvfs-methods)
142 (unless (assoc elt tramp-methods)
143 (add-to-list 'tramp-methods (cons elt nil)))))
145 (defconst tramp-gvfs-path-tramp (concat dbus-path-emacs "/Tramp")
146 "The preceding object path for own objects.")
148 (defconst tramp-gvfs-service-daemon "org.gtk.vfs.Daemon"
149 "The well known name of the GVFS daemon.")
151 ;; D-Bus integration is available since Emacs 23 on some system types.
152 ;; We don't call `dbus-ping', because this would load dbus.el.
153 (defconst tramp-gvfs-enabled
154 (ignore-errors
155 (and (featurep 'dbusbind)
156 (tramp-compat-funcall 'dbus-get-unique-name :system)
157 (tramp-compat-funcall 'dbus-get-unique-name :session)
158 (or (tramp-compat-process-running-p "gvfs-fuse-daemon")
159 (tramp-compat-process-running-p "gvfsd-fuse"))))
160 "Non-nil when GVFS is available.")
162 (defconst tramp-gvfs-path-mounttracker "/org/gtk/vfs/mounttracker"
163 "The object path of the GVFS daemon.")
165 (defconst tramp-gvfs-interface-mounttracker "org.gtk.vfs.MountTracker"
166 "The mount tracking interface in the GVFS daemon.")
168 ;; Introspection data exist since GVFS 1.14. If there are no such
169 ;; data, we expect an earlier interface.
170 (defconst tramp-gvfs-methods-mounttracker
171 (and tramp-gvfs-enabled
172 (dbus-introspect-get-method-names
173 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
174 tramp-gvfs-interface-mounttracker))
175 "The list of supported methods of the mount tracking interface.")
177 (defconst tramp-gvfs-listmounts
178 (if (member "ListMounts" tramp-gvfs-methods-mounttracker)
179 "ListMounts"
180 "listMounts")
181 "The name of the \"listMounts\" method.
182 It has been changed in GVFS 1.14.")
184 (defconst tramp-gvfs-mountlocation
185 (if (member "MountLocation" tramp-gvfs-methods-mounttracker)
186 "MountLocation"
187 "mountLocation")
188 "The name of the \"mountLocation\" method.
189 It has been changed in GVFS 1.14.")
191 (defconst tramp-gvfs-mountlocation-signature
192 (and tramp-gvfs-enabled
193 (dbus-introspect-get-signature
194 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
195 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation))
196 "The D-Bus signature of the \"mountLocation\" method.
197 It has been changed in GVFS 1.14.")
199 ;; <interface name='org.gtk.vfs.MountTracker'>
200 ;; <method name='listMounts'>
201 ;; <arg name='mount_info_list'
202 ;; type='a{sosssssbay{aya{say}}ay}'
203 ;; direction='out'/>
204 ;; </method>
205 ;; <method name='mountLocation'>
206 ;; <arg name='mount_spec' type='{aya{say}}' direction='in'/>
207 ;; <arg name='dbus_id' type='s' direction='in'/>
208 ;; <arg name='object_path' type='o' direction='in'/>
209 ;; </method>
210 ;; <signal name='mounted'>
211 ;; <arg name='mount_info'
212 ;; type='{sosssssbay{aya{say}}ay}'/>
213 ;; </signal>
214 ;; <signal name='unmounted'>
215 ;; <arg name='mount_info'
216 ;; type='{sosssssbay{aya{say}}ay}'/>
217 ;; </signal>
218 ;; </interface>
220 ;; STRUCT mount_info
221 ;; STRING dbus_id
222 ;; OBJECT_PATH object_path
223 ;; STRING display_name
224 ;; STRING stable_name
225 ;; STRING x_content_types Since GVFS 1.0 only !!!
226 ;; STRING icon
227 ;; STRING preferred_filename_encoding
228 ;; BOOLEAN user_visible
229 ;; ARRAY BYTE fuse_mountpoint
230 ;; STRUCT mount_spec
231 ;; ARRAY BYTE mount_prefix
232 ;; ARRAY
233 ;; STRUCT mount_spec_item
234 ;; STRING key (server, share, type, user, host, port)
235 ;; ARRAY BYTE value
236 ;; ARRAY BYTE default_location Since GVFS 1.5 only !!!
238 (defconst tramp-gvfs-interface-mountoperation "org.gtk.vfs.MountOperation"
239 "Used by the dbus-proxying implementation of GMountOperation.")
241 ;; <interface name='org.gtk.vfs.MountOperation'>
242 ;; <method name='askPassword'>
243 ;; <arg name='message' type='s' direction='in'/>
244 ;; <arg name='default_user' type='s' direction='in'/>
245 ;; <arg name='default_domain' type='s' direction='in'/>
246 ;; <arg name='flags' type='u' direction='in'/>
247 ;; <arg name='handled' type='b' direction='out'/>
248 ;; <arg name='aborted' type='b' direction='out'/>
249 ;; <arg name='password' type='s' direction='out'/>
250 ;; <arg name='username' type='s' direction='out'/>
251 ;; <arg name='domain' type='s' direction='out'/>
252 ;; <arg name='anonymous' type='b' direction='out'/>
253 ;; <arg name='password_save' type='u' direction='out'/>
254 ;; </method>
255 ;; <method name='askQuestion'>
256 ;; <arg name='message' type='s' direction='in'/>
257 ;; <arg name='choices' type='as' direction='in'/>
258 ;; <arg name='handled' type='b' direction='out'/>
259 ;; <arg name='aborted' type='b' direction='out'/>
260 ;; <arg name='choice' type='u' direction='out'/>
261 ;; </method>
262 ;; </interface>
264 ;; The following flags are used in "askPassword". They are defined in
265 ;; /usr/include/glib-2.0/gio/gioenums.h.
267 (defconst tramp-gvfs-password-need-password 1
268 "Operation requires a password.")
270 (defconst tramp-gvfs-password-need-username 2
271 "Operation requires a username.")
273 (defconst tramp-gvfs-password-need-domain 4
274 "Operation requires a domain.")
276 (defconst tramp-gvfs-password-saving-supported 8
277 "Operation supports saving settings.")
279 (defconst tramp-gvfs-password-anonymous-supported 16
280 "Operation supports anonymous users.")
282 (defconst tramp-bluez-service "org.bluez"
283 "The well known name of the BLUEZ service.")
285 (defconst tramp-bluez-interface-manager "org.bluez.Manager"
286 "The manager interface of the BLUEZ daemon.")
288 ;; <interface name='org.bluez.Manager'>
289 ;; <method name='DefaultAdapter'>
290 ;; <arg type='o' direction='out'/>
291 ;; </method>
292 ;; <method name='FindAdapter'>
293 ;; <arg type='s' direction='in'/>
294 ;; <arg type='o' direction='out'/>
295 ;; </method>
296 ;; <method name='ListAdapters'>
297 ;; <arg type='ao' direction='out'/>
298 ;; </method>
299 ;; <signal name='AdapterAdded'>
300 ;; <arg type='o'/>
301 ;; </signal>
302 ;; <signal name='AdapterRemoved'>
303 ;; <arg type='o'/>
304 ;; </signal>
305 ;; <signal name='DefaultAdapterChanged'>
306 ;; <arg type='o'/>
307 ;; </signal>
308 ;; </interface>
310 (defconst tramp-bluez-interface-adapter "org.bluez.Adapter"
311 "The adapter interface of the BLUEZ daemon.")
313 ;; <interface name='org.bluez.Adapter'>
314 ;; <method name='GetProperties'>
315 ;; <arg type='a{sv}' direction='out'/>
316 ;; </method>
317 ;; <method name='SetProperty'>
318 ;; <arg type='s' direction='in'/>
319 ;; <arg type='v' direction='in'/>
320 ;; </method>
321 ;; <method name='RequestMode'>
322 ;; <arg type='s' direction='in'/>
323 ;; </method>
324 ;; <method name='ReleaseMode'/>
325 ;; <method name='RequestSession'/>
326 ;; <method name='ReleaseSession'/>
327 ;; <method name='StartDiscovery'/>
328 ;; <method name='StopDiscovery'/>
329 ;; <method name='ListDevices'>
330 ;; <arg type='ao' direction='out'/>
331 ;; </method>
332 ;; <method name='CreateDevice'>
333 ;; <arg type='s' direction='in'/>
334 ;; <arg type='o' direction='out'/>
335 ;; </method>
336 ;; <method name='CreatePairedDevice'>
337 ;; <arg type='s' direction='in'/>
338 ;; <arg type='o' direction='in'/>
339 ;; <arg type='s' direction='in'/>
340 ;; <arg type='o' direction='out'/>
341 ;; </method>
342 ;; <method name='CancelDeviceCreation'>
343 ;; <arg type='s' direction='in'/>
344 ;; </method>
345 ;; <method name='RemoveDevice'>
346 ;; <arg type='o' direction='in'/>
347 ;; </method>
348 ;; <method name='FindDevice'>
349 ;; <arg type='s' direction='in'/>
350 ;; <arg type='o' direction='out'/>
351 ;; </method>
352 ;; <method name='RegisterAgent'>
353 ;; <arg type='o' direction='in'/>
354 ;; <arg type='s' direction='in'/>
355 ;; </method>
356 ;; <method name='UnregisterAgent'>
357 ;; <arg type='o' direction='in'/>
358 ;; </method>
359 ;; <signal name='DeviceCreated'>
360 ;; <arg type='o'/>
361 ;; </signal>
362 ;; <signal name='DeviceRemoved'>
363 ;; <arg type='o'/>
364 ;; </signal>
365 ;; <signal name='DeviceFound'>
366 ;; <arg type='s'/>
367 ;; <arg type='a{sv}'/>
368 ;; </signal>
369 ;; <signal name='PropertyChanged'>
370 ;; <arg type='s'/>
371 ;; <arg type='v'/>
372 ;; </signal>
373 ;; <signal name='DeviceDisappeared'>
374 ;; <arg type='s'/>
375 ;; </signal>
376 ;; </interface>
378 ;;;###tramp-autoload
379 (defcustom tramp-bluez-discover-devices-timeout 60
380 "Defines seconds since last bluetooth device discovery before rescanning.
381 A value of 0 would require an immediate discovery during hostname
382 completion, nil means to use always cached values for discovered
383 devices."
384 :group 'tramp
385 :version "23.2"
386 :type '(choice (const nil) integer))
388 (defvar tramp-bluez-discovery nil
389 "Indicator for a running bluetooth device discovery.
390 It keeps the timestamp of last discovery.")
392 (defvar tramp-bluez-devices nil
393 "Alist of detected bluetooth devices.
394 Every entry is a list (NAME ADDRESS).")
396 (defconst tramp-hal-service "org.freedesktop.Hal"
397 "The well known name of the HAL service.")
399 (defconst tramp-hal-path-manager "/org/freedesktop/Hal/Manager"
400 "The object path of the HAL daemon manager.")
402 (defconst tramp-hal-interface-manager "org.freedesktop.Hal.Manager"
403 "The manager interface of the HAL daemon.")
405 (defconst tramp-hal-interface-device "org.freedesktop.Hal.Device"
406 "The device interface of the HAL daemon.")
409 ;; New handlers should be added here.
410 (defconst tramp-gvfs-file-name-handler-alist
411 '((access-file . ignore)
412 (add-name-to-file . tramp-gvfs-handle-copy-file)
413 ;; `byte-compiler-base-file-name' performed by default handler.
414 ;; `copy-directory' performed by default handler.
415 (copy-file . tramp-gvfs-handle-copy-file)
416 (delete-directory . tramp-gvfs-handle-delete-directory)
417 (delete-file . tramp-gvfs-handle-delete-file)
418 ;; `diff-latest-backup-file' performed by default handler.
419 (directory-file-name . tramp-handle-directory-file-name)
420 (directory-files . tramp-handle-directory-files)
421 (directory-files-and-attributes
422 . tramp-handle-directory-files-and-attributes)
423 (dired-call-process . ignore)
424 (dired-compress-file . ignore)
425 (dired-uncache . tramp-handle-dired-uncache)
426 (expand-file-name . tramp-gvfs-handle-expand-file-name)
427 (file-accessible-directory-p . tramp-handle-file-accessible-directory-p)
428 (file-acl . ignore)
429 (file-attributes . tramp-gvfs-handle-file-attributes)
430 (file-directory-p . tramp-gvfs-handle-file-directory-p)
431 ;; `file-equal-p' performed by default handler.
432 (file-executable-p . tramp-gvfs-handle-file-executable-p)
433 (file-exists-p . tramp-handle-file-exists-p)
434 ;; `file-in-directory-p' performed by default handler.
435 (file-local-copy . tramp-gvfs-handle-file-local-copy)
436 (file-modes . tramp-handle-file-modes)
437 (file-name-all-completions . tramp-gvfs-handle-file-name-all-completions)
438 (file-name-as-directory . tramp-handle-file-name-as-directory)
439 (file-name-completion . tramp-handle-file-name-completion)
440 (file-name-directory . tramp-handle-file-name-directory)
441 (file-name-nondirectory . tramp-handle-file-name-nondirectory)
442 ;; `file-name-sans-versions' performed by default handler.
443 (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
444 (file-notify-add-watch . tramp-gvfs-handle-file-notify-add-watch)
445 (file-notify-rm-watch . tramp-handle-file-notify-rm-watch)
446 (file-ownership-preserved-p . ignore)
447 (file-readable-p . tramp-gvfs-handle-file-readable-p)
448 (file-regular-p . tramp-handle-file-regular-p)
449 (file-remote-p . tramp-handle-file-remote-p)
450 (file-selinux-context . ignore)
451 (file-symlink-p . tramp-handle-file-symlink-p)
452 ;; `file-truename' performed by default handler.
453 (file-writable-p . tramp-gvfs-handle-file-writable-p)
454 (find-backup-file-name . tramp-handle-find-backup-file-name)
455 ;; `find-file-noselect' performed by default handler.
456 ;; `get-file-buffer' performed by default handler.
457 (insert-directory . tramp-handle-insert-directory)
458 (insert-file-contents . tramp-handle-insert-file-contents)
459 (load . tramp-handle-load)
460 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
461 (make-directory . tramp-gvfs-handle-make-directory)
462 (make-directory-internal . ignore)
463 (make-symbolic-link . tramp-handle-make-symbolic-link)
464 (process-file . ignore)
465 (rename-file . tramp-gvfs-handle-rename-file)
466 (set-file-acl . ignore)
467 (set-file-modes . ignore)
468 (set-file-selinux-context . ignore)
469 (set-file-times . ignore)
470 (set-visited-file-modtime . tramp-handle-set-visited-file-modtime)
471 (shell-command . ignore)
472 (start-file-process . ignore)
473 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
474 (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory)
475 (vc-registered . ignore)
476 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime)
477 (write-region . tramp-gvfs-handle-write-region))
478 "Alist of handler functions for Tramp GVFS method.
479 Operations not mentioned here will be handled by the default Emacs primitives.")
481 ;; It must be a `defsubst' in order to push the whole code into
482 ;; tramp-loaddefs.el. Otherwise, there would be recursive autoloading.
483 ;;;###tramp-autoload
484 (defsubst tramp-gvfs-file-name-p (filename)
485 "Check if it's a filename handled by the GVFS daemon."
486 (and (tramp-tramp-file-p filename)
487 (let ((method
488 (tramp-file-name-method (tramp-dissect-file-name filename))))
489 (and (stringp method) (member method tramp-gvfs-methods)))))
491 ;;;###tramp-autoload
492 (defun tramp-gvfs-file-name-handler (operation &rest args)
493 "Invoke the GVFS related OPERATION.
494 First arg specifies the OPERATION, second arg is a list of arguments to
495 pass to the OPERATION."
496 (unless tramp-gvfs-enabled
497 (tramp-user-error nil "Package `tramp-gvfs' not supported"))
498 (let ((fn (assoc operation tramp-gvfs-file-name-handler-alist)))
499 (if fn
500 (save-match-data (apply (cdr fn) args))
501 (tramp-run-real-handler operation args))))
503 ;; This might be moved to tramp.el. It shall be the first file name
504 ;; handler.
505 ;;;###tramp-autoload
506 (when (featurep 'dbusbind)
507 (add-to-list 'tramp-foreign-file-name-handler-alist
508 (cons 'tramp-gvfs-file-name-p 'tramp-gvfs-file-name-handler)))
511 ;; D-Bus helper function.
513 (defun tramp-gvfs-dbus-string-to-byte-array (string)
514 "Like `dbus-string-to-byte-array' but add trailing \\0 if needed."
515 (dbus-string-to-byte-array
516 (if (string-match "^(aya{sv})" tramp-gvfs-mountlocation-signature)
517 (concat string (string 0)) string)))
519 (defun tramp-gvfs-dbus-byte-array-to-string (byte-array)
520 "Like `dbus-byte-array-to-string' but remove trailing \\0 if exists."
521 ;; The byte array could be a variant. Take care.
522 (let ((byte-array
523 (if (and (consp byte-array) (atom (car byte-array)))
524 byte-array (car byte-array))))
525 (dbus-byte-array-to-string
526 (if (and (consp byte-array) (zerop (car (last byte-array))))
527 (butlast byte-array) byte-array))))
529 (defun tramp-gvfs-stringify-dbus-message (message)
530 "Convert a D-Bus message into readable UTF8 strings, used for traces."
531 (cond
532 ((and (consp message) (characterp (car message)))
533 (format "%S" (tramp-gvfs-dbus-byte-array-to-string message)))
534 ((consp message)
535 (mapcar 'tramp-gvfs-stringify-dbus-message message))
536 ((stringp message)
537 (format "%S" message))
538 (t message)))
540 (defmacro with-tramp-dbus-call-method
541 (vec synchronous bus service path interface method &rest args)
542 "Apply a D-Bus call on bus BUS.
544 If SYNCHRONOUS is non-nil, the call is synchronously. Otherwise,
545 it is an asynchronous call, with `ignore' as callback function.
547 The other arguments have the same meaning as with `dbus-call-method'
548 or `dbus-call-method-asynchronously'. Additionally, the call
549 will be traced by Tramp with trace level 6."
550 `(let ((func (if ,synchronous
551 'dbus-call-method 'dbus-call-method-asynchronously))
552 (args (append (list ,bus ,service ,path ,interface ,method)
553 (if ,synchronous (list ,@args) (list 'ignore ,@args))))
554 result)
555 (tramp-message ,vec 6 "%s %s" func args)
556 (setq result (apply func args))
557 (tramp-message ,vec 6 "%s" (tramp-gvfs-stringify-dbus-message result))
558 result))
560 (put 'with-tramp-dbus-call-method 'lisp-indent-function 2)
561 (put 'with-tramp-dbus-call-method 'edebug-form-spec '(form symbolp body))
562 (tramp-compat-font-lock-add-keywords
563 'emacs-lisp-mode '("\\<with-tramp-dbus-call-method\\>"))
565 (defvar tramp-gvfs-dbus-event-vector nil
566 "Current Tramp file name to be used, as vector.
567 It is needed when D-Bus signals or errors arrive, because there
568 is no information where to trace the message.")
570 (defun tramp-gvfs-dbus-event-error (event err)
571 "Called when a D-Bus error message arrives, see `dbus-event-error-functions'."
572 (when tramp-gvfs-dbus-event-vector
573 (tramp-message tramp-gvfs-dbus-event-vector 10 "%S" event)
574 (tramp-error tramp-gvfs-dbus-event-vector 'file-error "%s" (cadr err))))
576 ;; `dbus-event-error-hooks' has been renamed to `dbus-event-error-functions'.
577 (add-hook
578 (if (boundp 'dbus-event-error-functions)
579 'dbus-event-error-functions 'dbus-event-error-hooks)
580 'tramp-gvfs-dbus-event-error)
583 ;; File name primitives.
585 (defun tramp-gvfs-handle-copy-file
586 (filename newname &optional ok-if-already-exists keep-date
587 preserve-uid-gid preserve-extended-attributes)
588 "Like `copy-file' for Tramp files."
589 (with-parsed-tramp-file-name
590 (if (tramp-tramp-file-p filename) filename newname) nil
592 (when (and (not ok-if-already-exists) (file-exists-p newname))
593 (tramp-error
594 v 'file-already-exists "File %s already exists" newname))
596 (if (or (and (tramp-tramp-file-p filename)
597 (not (tramp-gvfs-file-name-p filename)))
598 (and (tramp-tramp-file-p newname)
599 (not (tramp-gvfs-file-name-p newname))))
601 ;; We cannot call `copy-file' directly. Use
602 ;; `tramp-compat-funcall' for backward compatibility (number
603 ;; of arguments).
604 (let ((tmpfile (tramp-compat-make-temp-file filename)))
605 (cond
606 (preserve-extended-attributes
607 (tramp-compat-funcall
608 'copy-file
609 filename tmpfile t keep-date preserve-uid-gid
610 preserve-extended-attributes))
611 (preserve-uid-gid
612 (tramp-compat-funcall
613 'copy-file filename tmpfile t keep-date preserve-uid-gid))
615 (copy-file filename tmpfile t keep-date)))
616 (rename-file tmpfile newname ok-if-already-exists))
618 ;; Direct copy.
619 (with-tramp-progress-reporter
620 v 0 (format "Copying %s to %s" filename newname)
621 (unless
622 (let ((args
623 (append (if (or keep-date preserve-uid-gid)
624 (list "--preserve")
625 nil)
626 (list
627 (tramp-gvfs-url-file-name filename)
628 (tramp-gvfs-url-file-name newname)))))
629 (apply 'tramp-gvfs-send-command v "gvfs-copy" args))
630 ;; Propagate the error.
631 (with-current-buffer (tramp-get-connection-buffer v)
632 (goto-char (point-min))
633 (tramp-error-with-buffer
634 nil v 'file-error
635 "Copying failed, see buffer `%s' for details." (buffer-name)))))
637 (when (tramp-tramp-file-p newname)
638 (with-parsed-tramp-file-name newname nil
639 (tramp-flush-file-property v (file-name-directory localname))
640 (tramp-flush-file-property v localname))))))
642 (defun tramp-gvfs-handle-delete-directory (directory &optional recursive trash)
643 "Like `delete-directory' for Tramp files."
644 (when (and recursive (not (file-symlink-p directory)))
645 (mapc (lambda (file)
646 (if (eq t (car (file-attributes file)))
647 (tramp-compat-delete-directory file recursive trash)
648 (tramp-compat-delete-file file trash)))
649 (directory-files
650 directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
651 (with-parsed-tramp-file-name directory nil
652 (tramp-flush-file-property v (file-name-directory localname))
653 (tramp-flush-directory-property v localname)
654 (unless
655 (tramp-gvfs-send-command
656 v (if (and trash delete-by-moving-to-trash) "gvfs-trash" "gvfs-rm")
657 (tramp-gvfs-url-file-name directory))
658 ;; Propagate the error.
659 (with-current-buffer (tramp-get-connection-buffer v)
660 (goto-char (point-min))
661 (tramp-error-with-buffer
662 nil v 'file-error "Couldn't delete %s" directory)))))
664 (defun tramp-gvfs-handle-delete-file (filename &optional trash)
665 "Like `delete-file' for Tramp files."
666 (with-parsed-tramp-file-name filename nil
667 (tramp-flush-file-property v (file-name-directory localname))
668 (tramp-flush-file-property v localname)
669 (unless
670 (tramp-gvfs-send-command
671 v (if (and trash delete-by-moving-to-trash) "gvfs-trash" "gvfs-rm")
672 (tramp-gvfs-url-file-name filename))
673 ;; Propagate the error.
674 (with-current-buffer (tramp-get-connection-buffer v)
675 (goto-char (point-min))
676 (tramp-error-with-buffer
677 nil v 'file-error "Couldn't delete %s" filename)))))
679 (defun tramp-gvfs-handle-expand-file-name (name &optional dir)
680 "Like `expand-file-name' for Tramp files."
681 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
682 (setq dir (or dir default-directory "/"))
683 ;; Unless NAME is absolute, concat DIR and NAME.
684 (unless (file-name-absolute-p name)
685 (setq name (concat (file-name-as-directory dir) name)))
686 ;; If NAME is not a Tramp file, run the real handler.
687 (if (not (tramp-tramp-file-p name))
688 (tramp-run-real-handler 'expand-file-name (list name nil))
689 ;; Dissect NAME.
690 (with-parsed-tramp-file-name name nil
691 ;; If there is a default location, expand tilde.
692 (when (string-match "\\`\\(~\\)\\(/\\|\\'\\)" localname)
693 (save-match-data
694 (tramp-gvfs-maybe-open-connection (vector method user host "/" hop)))
695 (setq localname
696 (replace-match
697 (tramp-get-file-property v "/" "default-location" "~")
698 nil t localname 1)))
699 ;; Tilde expansion is not possible.
700 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
701 (tramp-error
702 v 'file-error
703 "Cannot expand tilde in file `%s'" name))
704 (unless (tramp-run-real-handler 'file-name-absolute-p (list localname))
705 (setq localname (concat "/" localname)))
706 ;; We do not pass "/..".
707 (if (string-equal "smb" method)
708 (when (string-match "^/[^/]+\\(/\\.\\./?\\)" localname)
709 (setq localname (replace-match "/" t t localname 1)))
710 (when (string-match "^/\\.\\./?" localname)
711 (setq localname (replace-match "/" t t localname))))
712 ;; There might be a double slash. Remove this.
713 (while (string-match "//" localname)
714 (setq localname (replace-match "/" t t localname)))
715 ;; No tilde characters in file name, do normal
716 ;; `expand-file-name' (this does "/./" and "/../").
717 (tramp-make-tramp-file-name
718 method user host
719 (tramp-run-real-handler
720 'expand-file-name (list localname))))))
722 (defun tramp-gvfs-handle-file-attributes (filename &optional id-format)
723 "Like `file-attributes' for Tramp files."
724 (unless id-format (setq id-format 'integer))
725 (ignore-errors
726 ;; Don't modify `last-coding-system-used' by accident.
727 (let ((last-coding-system-used last-coding-system-used)
728 dirp res-symlink-target res-numlinks res-uid res-gid res-access
729 res-mod res-change res-size res-filemodes res-inode res-device)
730 (with-parsed-tramp-file-name filename nil
731 (with-tramp-file-property
732 v localname (format "file-attributes-%s" id-format)
733 (tramp-message v 5 "file attributes: %s" localname)
734 (tramp-gvfs-send-command
735 v "gvfs-info" (tramp-gvfs-url-file-name filename))
736 ;; Parse output ...
737 (with-current-buffer (tramp-get-connection-buffer v)
738 (goto-char (point-min))
739 (when (re-search-forward "attributes:" nil t)
740 ;; ... directory or symlink
741 (goto-char (point-min))
742 (setq dirp (if (re-search-forward "type:\\s-+directory" nil t) t))
743 (goto-char (point-min))
744 (setq res-symlink-target
745 (if (re-search-forward
746 "standard::symlink-target:\\s-+\\(\\S-+\\)" nil t)
747 (match-string 1)))
748 ;; ... number links
749 (goto-char (point-min))
750 (setq res-numlinks
751 (if (re-search-forward
752 "unix::nlink:\\s-+\\([0-9]+\\)" nil t)
753 (string-to-number (match-string 1)) 0))
754 ;; ... uid and gid
755 (goto-char (point-min))
756 (setq res-uid
757 (or (if (eq id-format 'integer)
758 (if (re-search-forward
759 "unix::uid:\\s-+\\([0-9]+\\)" nil t)
760 (string-to-number (match-string 1)))
761 (if (re-search-forward
762 "owner::user:\\s-+\\(\\S-+\\)" nil t)
763 (match-string 1)))
764 (tramp-get-local-uid id-format)))
765 (setq res-gid
766 (or (if (eq id-format 'integer)
767 (if (re-search-forward
768 "unix::gid:\\s-+\\([0-9]+\\)" nil t)
769 (string-to-number (match-string 1)))
770 (if (re-search-forward
771 "owner::group:\\s-+\\(\\S-+\\)" nil t)
772 (match-string 1)))
773 (tramp-get-local-gid id-format)))
774 ;; ... last access, modification and change time
775 (goto-char (point-min))
776 (setq res-access
777 (if (re-search-forward
778 "time::access:\\s-+\\([0-9]+\\)" nil t)
779 (seconds-to-time (string-to-number (match-string 1)))
780 '(0 0)))
781 (goto-char (point-min))
782 (setq res-mod
783 (if (re-search-forward
784 "time::modified:\\s-+\\([0-9]+\\)" nil t)
785 (seconds-to-time (string-to-number (match-string 1)))
786 '(0 0)))
787 (goto-char (point-min))
788 (setq res-change
789 (if (re-search-forward
790 "time::changed:\\s-+\\([0-9]+\\)" nil t)
791 (seconds-to-time (string-to-number (match-string 1)))
792 '(0 0)))
793 ;; ... size
794 (goto-char (point-min))
795 (setq res-size
796 (if (re-search-forward
797 "standard::size:\\s-+\\([0-9]+\\)" nil t)
798 (string-to-number (match-string 1)) 0))
799 ;; ... file mode flags
800 (goto-char (point-min))
801 (setq res-filemodes
802 (if (re-search-forward "unix::mode:\\s-+\\([0-9]+\\)" nil t)
803 (tramp-file-mode-from-int
804 (string-to-number (match-string 1)))
805 (if dirp "drwx------" "-rwx------")))
806 ;; ... inode and device
807 (goto-char (point-min))
808 (setq res-inode
809 (if (re-search-forward
810 "unix::inode:\\s-+\\([0-9]+\\)" nil t)
811 (string-to-number (match-string 1))
812 (tramp-get-inode v)))
813 (goto-char (point-min))
814 (setq res-device
815 (if (re-search-forward
816 "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" "-h" (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-notify-add-watch (file-name _flags _callback)
941 "Like `file-notify-add-watch' for Tramp files."
942 (setq file-name (expand-file-name file-name))
943 (with-parsed-tramp-file-name file-name nil
944 (let ((p (start-process
945 "gvfs-monitor-file" (generate-new-buffer " *gvfs-monitor-file*")
946 "gvfs-monitor-file" (tramp-gvfs-url-file-name file-name))))
947 (if (not (processp p))
948 (tramp-error
949 v 'file-notify-error "gvfs-monitor-file failed to start")
950 (tramp-message
951 v 6 "Run `%s', %S" (mapconcat 'identity (process-command p) " ") p)
952 (tramp-set-connection-property p "vector" v)
953 (tramp-compat-set-process-query-on-exit-flag p nil)
954 (set-process-filter p 'tramp-gvfs-file-gvfs-monitor-file-process-filter)
955 (with-current-buffer (process-buffer p)
956 (setq default-directory (file-name-directory file-name)))
957 p))))
959 (defun tramp-gvfs-file-gvfs-monitor-file-process-filter (proc string)
960 "Read output from \"gvfs-monitor-file\" and add corresponding file-notify events."
961 (let* ((rest-string (tramp-compat-process-get proc 'rest-string))
962 (dd (with-current-buffer (process-buffer proc) default-directory))
963 (ddu (regexp-quote (tramp-gvfs-url-file-name dd))))
964 (when rest-string
965 (tramp-message proc 10 "Previous string:\n%s" rest-string))
966 (tramp-message proc 6 "%S\n%s" proc string)
967 (setq string (concat rest-string string)
968 ;; Attribute change is returned in unused wording.
969 string (tramp-compat-replace-regexp-in-string
970 "ATTRIB CHANGED" "ATTRIBUTE_CHANGED" string))
972 (while (string-match
973 (concat "^[\n\r]*"
974 "File Monitor Event:[\n\r]+"
975 "File = \\([^\n\r]+\\)[\n\r]+"
976 "Event = \\([^[:blank:]]+\\)[\n\r]+")
977 string)
978 (let ((action (intern-soft
979 (tramp-compat-replace-regexp-in-string
980 "_" "-" (downcase (match-string 2 string)))))
981 (file (match-string 1 string)))
982 (setq string (replace-match "" nil nil string))
983 ;; File names are returned as URL paths. We must convert them.
984 (when (string-match ddu file)
985 (setq file (replace-match dd nil nil file)))
986 (while (string-match "%\\([0-9A-F]\\{2\\}\\)" file)
987 (setq file
988 (replace-match
989 (char-to-string (string-to-number (match-string 1 file) 16))
990 nil nil file)))
991 ;; Usually, we would add an Emacs event now. Unfortunately,
992 ;; `unread-command-events' does not accept several events at
993 ;; once. Therefore, we apply the callback directly.
994 (tramp-compat-funcall 'file-notify-callback (list proc action file))))
996 ;; Save rest of the string.
997 (when (zerop (length string)) (setq string nil))
998 (when string (tramp-message proc 10 "Rest string:\n%s" string))
999 (tramp-compat-process-put proc 'rest-string string)))
1001 (defun tramp-gvfs-handle-file-readable-p (filename)
1002 "Like `file-readable-p' for Tramp files."
1003 (with-parsed-tramp-file-name filename nil
1004 (with-tramp-file-property v localname "file-executable-p"
1005 (tramp-check-cached-permissions v ?r))))
1007 (defun tramp-gvfs-handle-file-writable-p (filename)
1008 "Like `file-writable-p' for Tramp files."
1009 (with-parsed-tramp-file-name filename nil
1010 (with-tramp-file-property v localname "file-writable-p"
1011 (if (file-exists-p filename)
1012 (tramp-check-cached-permissions v ?w)
1013 ;; If file doesn't exist, check if directory is writable.
1014 (and (file-directory-p (file-name-directory filename))
1015 (file-writable-p (file-name-directory filename)))))))
1017 (defun tramp-gvfs-handle-make-directory (dir &optional parents)
1018 "Like `make-directory' for Tramp files."
1019 (with-parsed-tramp-file-name dir nil
1020 (unless
1021 (apply
1022 'tramp-gvfs-send-command v "gvfs-mkdir"
1023 (if parents
1024 (list "-p" (tramp-gvfs-url-file-name dir))
1025 (list (tramp-gvfs-url-file-name dir))))
1026 ;; Propagate the error.
1027 (tramp-error v 'file-error "Couldn't make directory %s" dir))))
1029 (defun tramp-gvfs-handle-rename-file
1030 (filename newname &optional ok-if-already-exists)
1031 "Like `rename-file' for Tramp files."
1032 (with-parsed-tramp-file-name
1033 (if (tramp-tramp-file-p filename) filename newname) nil
1035 (when (and (not ok-if-already-exists) (file-exists-p newname))
1036 (tramp-error
1037 v 'file-already-exists "File %s already exists" newname))
1039 (if (or (and (tramp-tramp-file-p filename)
1040 (not (tramp-gvfs-file-name-p filename)))
1041 (and (tramp-tramp-file-p newname)
1042 (not (tramp-gvfs-file-name-p newname))))
1044 ;; We cannot move directly.
1045 (let ((tmpfile (tramp-compat-make-temp-file filename)))
1046 (rename-file filename tmpfile t)
1047 (rename-file tmpfile newname ok-if-already-exists))
1049 ;; Direct move.
1050 (with-tramp-progress-reporter
1051 v 0 (format "Renaming %s to %s" filename newname)
1052 (unless
1053 (tramp-gvfs-send-command
1054 v "gvfs-move"
1055 (tramp-gvfs-url-file-name filename)
1056 (tramp-gvfs-url-file-name newname))
1057 ;; Propagate the error.
1058 (with-current-buffer (tramp-get-buffer v)
1059 (goto-char (point-min))
1060 (tramp-error-with-buffer
1061 nil v 'file-error
1062 "Renaming failed, see buffer `%s' for details." (buffer-name)))))
1064 (when (tramp-tramp-file-p filename)
1065 (with-parsed-tramp-file-name filename nil
1066 (tramp-flush-file-property v (file-name-directory localname))
1067 (tramp-flush-file-property v localname)))
1069 (when (tramp-tramp-file-p newname)
1070 (with-parsed-tramp-file-name newname nil
1071 (tramp-flush-file-property v (file-name-directory localname))
1072 (tramp-flush-file-property v localname))))))
1074 (defun tramp-gvfs-handle-write-region
1075 (start end filename &optional append visit lockname confirm)
1076 "Like `write-region' for Tramp files."
1077 (with-parsed-tramp-file-name filename nil
1078 ;; XEmacs takes a coding system as the seventh argument, not `confirm'.
1079 (when (and (not (featurep 'xemacs)) confirm (file-exists-p filename))
1080 (unless (y-or-n-p (format "File %s exists; overwrite anyway? " filename))
1081 (tramp-error v 'file-error "File not overwritten")))
1083 (let ((tmpfile (tramp-compat-make-temp-file filename)))
1084 (when (and append (file-exists-p filename))
1085 (copy-file filename tmpfile 'ok))
1086 ;; We say `no-message' here because we don't want the visited file
1087 ;; modtime data to be clobbered from the temp file. We call
1088 ;; `set-visited-file-modtime' ourselves later on.
1089 (tramp-run-real-handler
1090 'write-region
1091 (if confirm ; don't pass this arg unless defined for backward compat.
1092 (list start end tmpfile append 'no-message lockname confirm)
1093 (list start end tmpfile append 'no-message lockname)))
1094 (condition-case nil
1095 (rename-file tmpfile filename 'ok-if-already-exists)
1096 (error
1097 (delete-file tmpfile)
1098 (tramp-error
1099 v 'file-error "Couldn't write region to `%s'" filename))))
1101 (tramp-flush-file-property v (file-name-directory localname))
1102 (tramp-flush-file-property v localname)
1104 ;; Set file modification time.
1105 (when (or (eq visit t) (stringp visit))
1106 (set-visited-file-modtime (nth 5 (file-attributes filename))))
1108 ;; The end.
1109 (when (or (eq visit t) (null visit) (stringp visit))
1110 (tramp-message v 0 "Wrote %s" filename))
1111 (run-hooks 'tramp-handle-write-region-hook)))
1114 ;; File name conversions.
1116 (defun tramp-gvfs-url-file-name (filename)
1117 "Return FILENAME in URL syntax."
1118 ;; "/" must NOT be hexlified.
1119 (let ((url-unreserved-chars (cons ?/ url-unreserved-chars))
1120 result)
1121 (setq
1122 result
1123 (url-recreate-url
1124 (if (tramp-tramp-file-p filename)
1125 (with-parsed-tramp-file-name filename nil
1126 (when (and user (string-match tramp-user-with-domain-regexp user))
1127 (setq user
1128 (concat (match-string 2 user) ";" (match-string 1 user))))
1129 (url-parse-make-urlobj
1130 method (and user (url-hexify-string user)) nil
1131 (tramp-file-name-real-host v) (tramp-file-name-port v)
1132 (and localname (url-hexify-string localname)) nil nil t))
1133 (url-parse-make-urlobj
1134 "file" nil nil nil nil
1135 (url-hexify-string (file-truename filename)) nil nil t))))
1136 (when (tramp-tramp-file-p filename)
1137 (with-parsed-tramp-file-name filename nil
1138 (tramp-message v 10 "remote file `%s' is URL `%s'" filename result)))
1139 result))
1141 (defun tramp-gvfs-object-path (filename)
1142 "Create a D-Bus object path from FILENAME."
1143 (expand-file-name (dbus-escape-as-identifier filename) tramp-gvfs-path-tramp))
1145 (defun tramp-gvfs-file-name (object-path)
1146 "Retrieve file name from D-Bus OBJECT-PATH."
1147 (dbus-unescape-from-identifier
1148 (tramp-compat-replace-regexp-in-string
1149 "^.*/\\([^/]+\\)$" "\\1" object-path)))
1151 (defun tramp-bluez-address (device)
1152 "Return bluetooth device address from a given bluetooth DEVICE name."
1153 (when (stringp device)
1154 (if (string-match tramp-ipv6-regexp device)
1155 (match-string 0 device)
1156 (cadr (assoc device (tramp-bluez-list-devices))))))
1158 (defun tramp-bluez-device (address)
1159 "Return bluetooth device name from a given bluetooth device ADDRESS.
1160 ADDRESS can have the form \"xx:xx:xx:xx:xx:xx\" or \"[xx:xx:xx:xx:xx:xx]\"."
1161 (when (stringp address)
1162 (while (string-match "[][]" address)
1163 (setq address (replace-match "" t t address)))
1164 (let (result)
1165 (dolist (item (tramp-bluez-list-devices) result)
1166 (when (string-match address (cadr item))
1167 (setq result (car item)))))))
1170 ;; D-Bus GVFS functions.
1172 (defun tramp-gvfs-handler-askpassword (message user domain flags)
1173 "Implementation for the \"org.gtk.vfs.MountOperation.askPassword\" method."
1174 (let* ((filename
1175 (tramp-gvfs-file-name (dbus-event-path-name last-input-event)))
1176 (pw-prompt
1177 (format
1178 "%s for %s "
1179 (if (string-match "\\([pP]assword\\|[pP]assphrase\\)" message)
1180 (capitalize (match-string 1 message))
1181 "Password")
1182 filename))
1183 password)
1185 (condition-case nil
1186 (with-parsed-tramp-file-name filename l
1187 (when (and (zerop (length user))
1188 (not
1189 (zerop (logand flags tramp-gvfs-password-need-username))))
1190 (setq user (read-string "User name: ")))
1191 (when (and (zerop (length domain))
1192 (not
1193 (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 (unless (tramp-get-connection-property l "first-password-request" nil)
1198 (tramp-clear-passwd l))
1200 (setq tramp-current-method l-method
1201 tramp-current-user user
1202 tramp-current-host l-host
1203 password (tramp-read-passwd
1204 (tramp-get-connection-process l) pw-prompt))
1206 ;; Return result.
1207 (if (stringp password)
1208 (list
1209 t ;; password handled.
1210 nil ;; no abort of D-Bus.
1211 password
1212 (tramp-file-name-real-user l)
1213 domain
1214 nil ;; not anonymous.
1215 0) ;; no password save.
1216 ;; No password provided.
1217 (list nil t "" (tramp-file-name-real-user l) domain nil 0)))
1219 ;; When QUIT is raised, we shall return this information to D-Bus.
1220 (quit (list nil t "" "" "" nil 0)))))
1222 (defun tramp-gvfs-handler-askquestion (message choices)
1223 "Implementation for the \"org.gtk.vfs.MountOperation.askQuestion\" method."
1224 (save-window-excursion
1225 (let ((enable-recursive-minibuffers t)
1226 choice)
1228 (condition-case nil
1229 (with-parsed-tramp-file-name
1230 (tramp-gvfs-file-name (dbus-event-path-name last-input-event)) nil
1231 (tramp-message v 6 "%S %S" message choices)
1233 ;; In theory, there can be several choices. Until now,
1234 ;; there is only the question whether to accept an unknown
1235 ;; host signature.
1236 (with-temp-buffer
1237 ;; Preserve message for `progress-reporter'.
1238 (tramp-compat-with-temp-message ""
1239 (insert message)
1240 (pop-to-buffer (current-buffer))
1241 (setq choice (if (yes-or-no-p (concat (car choices) " ")) 0 1))
1242 (tramp-message v 6 "%d" choice)))
1244 ;; When the choice is "no", we set a dummy fuse-mountpoint
1245 ;; in order to leave the timeout.
1246 (unless (zerop choice)
1247 (tramp-set-file-property v "/" "fuse-mountpoint" "/"))
1249 (list
1250 t ;; handled.
1251 nil ;; no abort of D-Bus.
1252 choice))
1254 ;; When QUIT is raised, we shall return this information to D-Bus.
1255 (quit (list nil t 0))))))
1257 (defun tramp-gvfs-handler-mounted-unmounted (mount-info)
1258 "Signal handler for the \"org.gtk.vfs.MountTracker.mounted\" and
1259 \"org.gtk.vfs.MountTracker.unmounted\" signals."
1260 (ignore-errors
1261 (let ((signal-name (dbus-event-member-name last-input-event))
1262 (elt mount-info))
1263 ;; Jump over the first elements of the mount info. Since there
1264 ;; were changes in the entries, we cannot access dedicated
1265 ;; elements.
1266 (while (stringp (car elt)) (setq elt (cdr elt)))
1267 (let* ((fuse-mountpoint (tramp-gvfs-dbus-byte-array-to-string (cadr elt)))
1268 (mount-spec (caddr elt))
1269 (default-location (tramp-gvfs-dbus-byte-array-to-string
1270 (cadddr elt)))
1271 (method (tramp-gvfs-dbus-byte-array-to-string
1272 (cadr (assoc "type" (cadr mount-spec)))))
1273 (user (tramp-gvfs-dbus-byte-array-to-string
1274 (cadr (assoc "user" (cadr mount-spec)))))
1275 (domain (tramp-gvfs-dbus-byte-array-to-string
1276 (cadr (assoc "domain" (cadr mount-spec)))))
1277 (host (tramp-gvfs-dbus-byte-array-to-string
1278 (cadr (or (assoc "host" (cadr mount-spec))
1279 (assoc "server" (cadr mount-spec))))))
1280 (port (tramp-gvfs-dbus-byte-array-to-string
1281 (cadr (assoc "port" (cadr mount-spec)))))
1282 (ssl (tramp-gvfs-dbus-byte-array-to-string
1283 (cadr (assoc "ssl" (cadr mount-spec)))))
1284 (prefix (concat (tramp-gvfs-dbus-byte-array-to-string
1285 (car mount-spec))
1286 (tramp-gvfs-dbus-byte-array-to-string
1287 (cadr (assoc "share" (cadr mount-spec)))))))
1288 (when (string-match "^smb" method)
1289 (setq method "smb"))
1290 (when (string-equal "obex" method)
1291 (setq host (tramp-bluez-device host)))
1292 (when (and (string-equal "dav" method) (string-equal "true" ssl))
1293 (setq method "davs"))
1294 (unless (zerop (length domain))
1295 (setq user (concat user tramp-prefix-domain-format domain)))
1296 (unless (zerop (length port))
1297 (setq host (concat host tramp-prefix-port-format port)))
1298 (with-parsed-tramp-file-name
1299 (tramp-make-tramp-file-name method user host "") nil
1300 (tramp-message
1301 v 6 "%s %s"
1302 signal-name (tramp-gvfs-stringify-dbus-message mount-info))
1303 (tramp-set-file-property v "/" "list-mounts" 'undef)
1304 (if (string-equal (downcase signal-name) "unmounted")
1305 (tramp-set-file-property v "/" "fuse-mountpoint" nil)
1306 ;; Set prefix, mountpoint and location.
1307 (unless (string-equal prefix "/")
1308 (tramp-set-file-property v "/" "prefix" prefix))
1309 (tramp-set-file-property v "/" "fuse-mountpoint" fuse-mountpoint)
1310 (tramp-set-file-property
1311 v "/" "default-location" default-location)))))))
1313 (when tramp-gvfs-enabled
1314 (dbus-register-signal
1315 :session nil tramp-gvfs-path-mounttracker
1316 tramp-gvfs-interface-mounttracker "mounted"
1317 'tramp-gvfs-handler-mounted-unmounted)
1318 (dbus-register-signal
1319 :session nil tramp-gvfs-path-mounttracker
1320 tramp-gvfs-interface-mounttracker "Mounted"
1321 '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)
1327 (dbus-register-signal
1328 :session nil tramp-gvfs-path-mounttracker
1329 tramp-gvfs-interface-mounttracker "Unmounted"
1330 'tramp-gvfs-handler-mounted-unmounted))
1332 (defun tramp-gvfs-connection-mounted-p (vec)
1333 "Check, whether the location is already mounted."
1335 (tramp-get-file-property vec "/" "fuse-mountpoint" nil)
1336 (catch 'mounted
1337 (dolist
1338 (elt
1339 (with-tramp-file-property vec "/" "list-mounts"
1340 (with-tramp-dbus-call-method vec t
1341 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1342 tramp-gvfs-interface-mounttracker tramp-gvfs-listmounts))
1343 nil)
1344 ;; Jump over the first elements of the mount info. Since there
1345 ;; were changes in the entries, we cannot access dedicated
1346 ;; elements.
1347 (while (stringp (car elt)) (setq elt (cdr elt)))
1348 (let* ((fuse-mountpoint (tramp-gvfs-dbus-byte-array-to-string
1349 (cadr elt)))
1350 (mount-spec (caddr elt))
1351 (default-location (tramp-gvfs-dbus-byte-array-to-string
1352 (cadddr elt)))
1353 (method (tramp-gvfs-dbus-byte-array-to-string
1354 (cadr (assoc "type" (cadr mount-spec)))))
1355 (user (tramp-gvfs-dbus-byte-array-to-string
1356 (cadr (assoc "user" (cadr mount-spec)))))
1357 (domain (tramp-gvfs-dbus-byte-array-to-string
1358 (cadr (assoc "domain" (cadr mount-spec)))))
1359 (host (tramp-gvfs-dbus-byte-array-to-string
1360 (cadr (or (assoc "host" (cadr mount-spec))
1361 (assoc "server" (cadr mount-spec))))))
1362 (port (tramp-gvfs-dbus-byte-array-to-string
1363 (cadr (assoc "port" (cadr mount-spec)))))
1364 (ssl (tramp-gvfs-dbus-byte-array-to-string
1365 (cadr (assoc "ssl" (cadr mount-spec)))))
1366 (prefix (concat (tramp-gvfs-dbus-byte-array-to-string
1367 (car mount-spec))
1368 (tramp-gvfs-dbus-byte-array-to-string
1369 (cadr (assoc "share" (cadr mount-spec)))))))
1370 (when (string-match "^smb" method)
1371 (setq method "smb"))
1372 (when (string-equal "obex" method)
1373 (setq host (tramp-bluez-device host)))
1374 (when (and (string-equal "dav" method) (string-equal "true" ssl))
1375 (setq method "davs"))
1376 (when (and (string-equal "synce" method) (zerop (length user)))
1377 (setq user (or (tramp-file-name-user vec) "")))
1378 (unless (zerop (length domain))
1379 (setq user (concat user tramp-prefix-domain-format domain)))
1380 (unless (zerop (length port))
1381 (setq host (concat host tramp-prefix-port-format port)))
1382 (when (and
1383 (string-equal method (tramp-file-name-method vec))
1384 (string-equal user (or (tramp-file-name-user vec) ""))
1385 (string-equal host (tramp-file-name-host vec))
1386 (string-match (concat "^" (regexp-quote prefix))
1387 (tramp-file-name-localname vec)))
1388 ;; Set prefix, mountpoint and location.
1389 (unless (string-equal prefix "/")
1390 (tramp-set-file-property vec "/" "prefix" prefix))
1391 (tramp-set-file-property vec "/" "fuse-mountpoint" fuse-mountpoint)
1392 (tramp-set-file-property vec "/" "default-location" default-location)
1393 (throw 'mounted t)))))))
1395 (defun tramp-gvfs-mount-spec-entry (key value)
1396 "Construct a mount-spec entry to be used in a mount_spec.
1397 It was \"a(say)\", but has changed to \"a{sv})\"."
1398 (if (string-match "^(aya{sv})" tramp-gvfs-mountlocation-signature)
1399 (list :dict-entry key
1400 (list :variant (tramp-gvfs-dbus-string-to-byte-array value)))
1401 (list :struct key (tramp-gvfs-dbus-string-to-byte-array value))))
1403 (defun tramp-gvfs-mount-spec (vec)
1404 "Return a mount-spec for \"org.gtk.vfs.MountTracker.mountLocation\"."
1405 (let* ((method (tramp-file-name-method vec))
1406 (user (tramp-file-name-real-user vec))
1407 (domain (tramp-file-name-domain vec))
1408 (host (tramp-file-name-real-host vec))
1409 (port (tramp-file-name-port vec))
1410 (localname (tramp-file-name-localname vec))
1411 (ssl (if (string-match "^davs" method) "true" "false"))
1412 (mount-spec
1413 `(:array
1414 ,@(cond
1415 ((string-equal "smb" method)
1416 (string-match "^/?\\([^/]+\\)" localname)
1417 (list (tramp-gvfs-mount-spec-entry "type" "smb-share")
1418 (tramp-gvfs-mount-spec-entry "server" host)
1419 (tramp-gvfs-mount-spec-entry
1420 "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))))
1432 ,@(when user
1433 (list (tramp-gvfs-mount-spec-entry "user" user)))
1434 ,@(when domain
1435 (list (tramp-gvfs-mount-spec-entry "domain" domain)))
1436 ,@(when port
1437 (list (tramp-gvfs-mount-spec-entry
1438 "port" (number-to-string port))))))
1439 (mount-pref
1440 (if (and (string-match "\\`dav" method)
1441 (string-match "^/?[^/]+" localname))
1442 (match-string 0 localname)
1443 "/")))
1445 ;; Return.
1446 `(:struct ,(tramp-gvfs-dbus-string-to-byte-array mount-pref) ,mount-spec)))
1449 ;; Connection functions.
1451 (defun tramp-gvfs-maybe-open-connection (vec)
1452 "Maybe open a connection VEC.
1453 Does not do anything if a connection is already open, but re-opens the
1454 connection if a previous connection has died for some reason."
1455 (tramp-check-proper-method-and-host vec)
1457 ;; We set the file name, in case there are incoming D-Bus signals or
1458 ;; D-Bus errors.
1459 (setq tramp-gvfs-dbus-event-vector vec)
1461 ;; For password handling, we need a process bound to the connection
1462 ;; buffer. Therefore, we create a dummy process. Maybe there is a
1463 ;; better solution?
1464 (unless (get-buffer-process (tramp-get-connection-buffer vec))
1465 (let ((p (make-network-process
1466 :name (tramp-buffer-name vec)
1467 :buffer (tramp-get-connection-buffer vec)
1468 :server t :host 'local :service t)))
1469 (tramp-compat-set-process-query-on-exit-flag p nil)))
1471 (unless (tramp-gvfs-connection-mounted-p vec)
1472 (let* ((method (tramp-file-name-method vec))
1473 (user (tramp-file-name-user vec))
1474 (host (tramp-file-name-host vec))
1475 (localname (tramp-file-name-localname vec))
1476 (object-path
1477 (tramp-gvfs-object-path
1478 (tramp-make-tramp-file-name method user host ""))))
1480 (when (and (string-equal method "smb")
1481 (string-equal localname "/"))
1482 (tramp-error vec 'file-error "Filename must contain a Windows share"))
1484 (with-tramp-progress-reporter
1485 vec 3
1486 (if (zerop (length user))
1487 (format "Opening connection for %s using %s" host method)
1488 (format "Opening connection for %s@%s using %s" user host method))
1490 ;; Enable `auth-source'.
1491 (tramp-set-connection-property vec "first-password-request" t)
1493 ;; There will be a callback of "askPassword" when a password is
1494 ;; needed.
1495 (dbus-register-method
1496 :session dbus-service-emacs object-path
1497 tramp-gvfs-interface-mountoperation "askPassword"
1498 'tramp-gvfs-handler-askpassword)
1499 (dbus-register-method
1500 :session dbus-service-emacs object-path
1501 tramp-gvfs-interface-mountoperation "AskPassword"
1502 'tramp-gvfs-handler-askpassword)
1504 ;; There could be a callback of "askQuestion" when adding fingerprint.
1505 (dbus-register-method
1506 :session dbus-service-emacs object-path
1507 tramp-gvfs-interface-mountoperation "askQuestion"
1508 'tramp-gvfs-handler-askquestion)
1509 (dbus-register-method
1510 :session dbus-service-emacs object-path
1511 tramp-gvfs-interface-mountoperation "AskQuestion"
1512 'tramp-gvfs-handler-askquestion)
1514 ;; The call must be asynchronously, because of the "askPassword"
1515 ;; or "askQuestion"callbacks.
1516 (if (string-match "(so)$" tramp-gvfs-mountlocation-signature)
1517 (with-tramp-dbus-call-method vec nil
1518 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1519 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation
1520 (tramp-gvfs-mount-spec vec)
1521 `(:struct :string ,(dbus-get-unique-name :session)
1522 :object-path ,object-path))
1523 (with-tramp-dbus-call-method vec nil
1524 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1525 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation
1526 (tramp-gvfs-mount-spec vec)
1527 :string (dbus-get-unique-name :session) :object-path object-path))
1529 ;; We must wait, until the mount is applied. This will be
1530 ;; indicated by the "mounted" signal, i.e. the "fuse-mountpoint"
1531 ;; file property.
1532 (with-timeout
1533 ((or (tramp-get-method-parameter method 'tramp-connection-timeout)
1534 tramp-connection-timeout)
1535 (if (zerop (length (tramp-file-name-user vec)))
1536 (tramp-error
1537 vec 'file-error
1538 "Timeout reached mounting %s using %s" host method)
1539 (tramp-error
1540 vec 'file-error
1541 "Timeout reached mounting %s@%s using %s" user host method)))
1542 (while (not (tramp-get-file-property vec "/" "fuse-mountpoint" nil))
1543 (read-event nil nil 0.1)))
1545 ;; If `tramp-gvfs-handler-askquestion' has returned "No", it
1546 ;; is marked with the fuse-mountpoint "/". We shall react.
1547 (when (string-equal
1548 (tramp-get-file-property vec "/" "fuse-mountpoint" "") "/")
1549 (tramp-error vec 'file-error "FUSE mount denied")))))
1551 ;; In `tramp-check-cached-permissions', the connection properties
1552 ;; {uig,gid}-{integer,string} are used. We set them to their local
1553 ;; counterparts.
1554 (with-tramp-connection-property
1555 vec "uid-integer" (tramp-get-local-uid 'integer))
1556 (with-tramp-connection-property
1557 vec "gid-integer" (tramp-get-local-gid 'integer))
1558 (with-tramp-connection-property
1559 vec "uid-string" (tramp-get-local-uid 'string))
1560 (with-tramp-connection-property
1561 vec "gid-string" (tramp-get-local-gid 'string)))
1563 (defun tramp-gvfs-send-command (vec command &rest args)
1564 "Send the COMMAND with its ARGS to connection VEC.
1565 COMMAND is usually a command from the gvfs-* utilities.
1566 `call-process' is applied, and it returns `t' if the return code is zero."
1567 (with-current-buffer (tramp-get-connection-buffer vec)
1568 (tramp-gvfs-maybe-open-connection vec)
1569 (erase-buffer)
1570 (zerop (apply 'tramp-call-process vec command nil t nil args))))
1573 ;; D-Bus BLUEZ functions.
1575 (defun tramp-bluez-list-devices ()
1576 "Return all discovered bluetooth devices as list.
1577 Every entry is a list (NAME ADDRESS).
1579 If `tramp-bluez-discover-devices-timeout' is an integer, and the last
1580 discovery happened more time before indicated there, a rescan will be
1581 started, which lasts some ten seconds. Otherwise, cached results will
1582 be used."
1583 ;; Reset the scanned devices list if time has passed.
1584 (and (integerp tramp-bluez-discover-devices-timeout)
1585 (integerp tramp-bluez-discovery)
1586 (> (tramp-time-diff (current-time) tramp-bluez-discovery)
1587 tramp-bluez-discover-devices-timeout)
1588 (setq tramp-bluez-devices nil))
1590 ;; Rescan if needed.
1591 (unless tramp-bluez-devices
1592 (let ((object-path
1593 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1594 :system tramp-bluez-service "/"
1595 tramp-bluez-interface-manager "DefaultAdapter")))
1596 (setq tramp-bluez-devices nil
1597 tramp-bluez-discovery t)
1598 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector nil
1599 :system tramp-bluez-service object-path
1600 tramp-bluez-interface-adapter "StartDiscovery")
1601 (while tramp-bluez-discovery
1602 (read-event nil nil 0.1))))
1603 (setq tramp-bluez-discovery (current-time))
1604 (tramp-message tramp-gvfs-dbus-event-vector 10 "%s" tramp-bluez-devices)
1605 tramp-bluez-devices)
1607 (defun tramp-bluez-property-changed (property value)
1608 "Signal handler for the \"org.bluez.Adapter.PropertyChanged\" signal."
1609 (tramp-message tramp-gvfs-dbus-event-vector 6 "%s %s" property value)
1610 (cond
1611 ((string-equal property "Discovering")
1612 (unless (car value)
1613 ;; "Discovering" FALSE means discovery run has been completed.
1614 ;; We stop it, because we don't need another run.
1615 (setq tramp-bluez-discovery nil)
1616 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1617 :system tramp-bluez-service (dbus-event-path-name last-input-event)
1618 tramp-bluez-interface-adapter "StopDiscovery")))))
1620 (when tramp-gvfs-enabled
1621 (dbus-register-signal
1622 :system nil nil tramp-bluez-interface-adapter "PropertyChanged"
1623 'tramp-bluez-property-changed))
1625 (defun tramp-bluez-device-found (device args)
1626 "Signal handler for the \"org.bluez.Adapter.DeviceFound\" signal."
1627 (tramp-message tramp-gvfs-dbus-event-vector 6 "%s %s" device args)
1628 (let ((alias (car (cadr (assoc "Alias" args))))
1629 (address (car (cadr (assoc "Address" args)))))
1630 ;; Maybe we shall check the device class for being a proper
1631 ;; device, and call also SDP in order to find the obex service.
1632 (add-to-list 'tramp-bluez-devices (list alias address))))
1634 (when tramp-gvfs-enabled
1635 (dbus-register-signal
1636 :system nil nil tramp-bluez-interface-adapter "DeviceFound"
1637 'tramp-bluez-device-found))
1639 (defun tramp-bluez-parse-device-names (_ignore)
1640 "Return a list of (nil host) tuples allowed to access."
1641 (mapcar
1642 (lambda (x) (list nil (car x)))
1643 (tramp-bluez-list-devices)))
1645 ;; Add completion function for OBEX method.
1646 (when (and tramp-gvfs-enabled
1647 (member tramp-bluez-service (dbus-list-known-names :system)))
1648 (tramp-set-completion-function
1649 "obex" '((tramp-bluez-parse-device-names ""))))
1652 ;; D-Bus zeroconf functions.
1654 (defun tramp-zeroconf-parse-workstation-device-names (_ignore)
1655 "Return a list of (user host) tuples allowed to access."
1656 (mapcar
1657 (lambda (x)
1658 (list nil (zeroconf-service-host x)))
1659 (zeroconf-list-services "_workstation._tcp")))
1661 (defun tramp-zeroconf-parse-webdav-device-names (_ignore)
1662 "Return a list of (user host) tuples allowed to access."
1663 (mapcar
1664 (lambda (x)
1665 (let ((host (zeroconf-service-host x))
1666 (port (zeroconf-service-port x))
1667 (text (zeroconf-service-txt x))
1668 user)
1669 (when port
1670 (setq host (format "%s%s%d" host tramp-prefix-port-regexp port)))
1671 ;; A user is marked in a TXT field like "u=guest".
1672 (while text
1673 (when (string-match "u=\\(.+\\)$" (car text))
1674 (setq user (match-string 1 (car text))))
1675 (setq text (cdr text)))
1676 (list user host)))
1677 (zeroconf-list-services "_webdav._tcp")))
1679 ;; Add completion function for SFTP, DAV and DAVS methods.
1680 (when (and tramp-gvfs-enabled
1681 (member zeroconf-service-avahi (dbus-list-known-names :system)))
1682 (zeroconf-init tramp-gvfs-zeroconf-domain)
1683 (tramp-set-completion-function
1684 "sftp" '((tramp-zeroconf-parse-workstation-device-names "")))
1685 (tramp-set-completion-function
1686 "dav" '((tramp-zeroconf-parse-webdav-device-names "")))
1687 (tramp-set-completion-function
1688 "davs" '((tramp-zeroconf-parse-webdav-device-names ""))))
1691 ;; D-Bus SYNCE functions.
1693 (defun tramp-synce-list-devices ()
1694 "Return all discovered synce devices as list.
1695 They are retrieved from the hal daemon."
1696 (let (tramp-synce-devices)
1697 (dolist (device
1698 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1699 :system tramp-hal-service tramp-hal-path-manager
1700 tramp-hal-interface-manager "GetAllDevices"))
1701 (when (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1702 :system tramp-hal-service device tramp-hal-interface-device
1703 "PropertyExists" "sync.plugin")
1704 (let ((prop
1705 (with-tramp-dbus-call-method
1706 tramp-gvfs-dbus-event-vector t
1707 :system tramp-hal-service device tramp-hal-interface-device
1708 "GetPropertyString" "pda.pocketpc.name")))
1709 (unless (member prop tramp-synce-devices)
1710 (push prop tramp-synce-devices)))))
1711 (tramp-message tramp-gvfs-dbus-event-vector 10 "%s" tramp-synce-devices)
1712 tramp-synce-devices))
1714 (defun tramp-synce-parse-device-names (_ignore)
1715 "Return a list of (nil host) tuples allowed to access."
1716 (mapcar
1717 (lambda (x) (list nil x))
1718 (tramp-synce-list-devices)))
1720 ;; Add completion function for SYNCE method.
1721 (when tramp-gvfs-enabled
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