Update copyright year to 2015
[emacs.git] / lisp / net / tramp-gvfs.el
blob1ea52eb670d5c7bc06492d8714fb086bb7a9bfb5
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 (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 ;; D-Bus integration is available since Emacs 23 on some system types.
151 ;; We don't call `dbus-ping', because this would load dbus.el.
152 (defconst tramp-gvfs-enabled
153 (ignore-errors
154 (and (featurep 'dbusbind)
155 (tramp-compat-funcall 'dbus-get-unique-name :system)
156 (tramp-compat-funcall 'dbus-get-unique-name :session)
157 (or (tramp-compat-process-running-p "gvfs-fuse-daemon")
158 (tramp-compat-process-running-p "gvfsd-fuse"))))
159 "Non-nil when GVFS is available.")
161 (defconst tramp-gvfs-path-mounttracker "/org/gtk/vfs/mounttracker"
162 "The object path of the GVFS daemon.")
164 (defconst tramp-gvfs-interface-mounttracker "org.gtk.vfs.MountTracker"
165 "The mount tracking interface in the GVFS daemon.")
167 ;; Introspection data exist since GVFS 1.14. If there are no such
168 ;; data, we expect an earlier interface.
169 (defconst tramp-gvfs-methods-mounttracker
170 (and tramp-gvfs-enabled
171 (dbus-introspect-get-method-names
172 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
173 tramp-gvfs-interface-mounttracker))
174 "The list of supported methods of the mount tracking interface.")
176 (defconst tramp-gvfs-listmounts
177 (if (member "ListMounts" tramp-gvfs-methods-mounttracker)
178 "ListMounts"
179 "listMounts")
180 "The name of the \"listMounts\" method.
181 It has been changed in GVFS 1.14.")
183 (defconst tramp-gvfs-mountlocation
184 (if (member "MountLocation" tramp-gvfs-methods-mounttracker)
185 "MountLocation"
186 "mountLocation")
187 "The name of the \"mountLocation\" method.
188 It has been changed in GVFS 1.14.")
190 (defconst tramp-gvfs-mountlocation-signature
191 (and tramp-gvfs-enabled
192 (dbus-introspect-get-signature
193 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
194 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation))
195 "The D-Bus signature of the \"mountLocation\" method.
196 It has been changed in GVFS 1.14.")
198 ;; <interface name='org.gtk.vfs.MountTracker'>
199 ;; <method name='listMounts'>
200 ;; <arg name='mount_info_list'
201 ;; type='a{sosssssbay{aya{say}}ay}'
202 ;; direction='out'/>
203 ;; </method>
204 ;; <method name='mountLocation'>
205 ;; <arg name='mount_spec' type='{aya{say}}' direction='in'/>
206 ;; <arg name='dbus_id' type='s' direction='in'/>
207 ;; <arg name='object_path' type='o' direction='in'/>
208 ;; </method>
209 ;; <signal name='mounted'>
210 ;; <arg name='mount_info'
211 ;; type='{sosssssbay{aya{say}}ay}'/>
212 ;; </signal>
213 ;; <signal name='unmounted'>
214 ;; <arg name='mount_info'
215 ;; type='{sosssssbay{aya{say}}ay}'/>
216 ;; </signal>
217 ;; </interface>
219 ;; STRUCT mount_info
220 ;; STRING dbus_id
221 ;; OBJECT_PATH object_path
222 ;; STRING display_name
223 ;; STRING stable_name
224 ;; STRING x_content_types Since GVFS 1.0 only !!!
225 ;; STRING icon
226 ;; STRING preferred_filename_encoding
227 ;; BOOLEAN user_visible
228 ;; ARRAY BYTE fuse_mountpoint
229 ;; STRUCT mount_spec
230 ;; ARRAY BYTE mount_prefix
231 ;; ARRAY
232 ;; STRUCT mount_spec_item
233 ;; STRING key (server, share, type, user, host, port)
234 ;; ARRAY BYTE value
235 ;; ARRAY BYTE default_location Since GVFS 1.5 only !!!
237 (defconst tramp-gvfs-interface-mountoperation "org.gtk.vfs.MountOperation"
238 "Used by the dbus-proxying implementation of GMountOperation.")
240 ;; <interface name='org.gtk.vfs.MountOperation'>
241 ;; <method name='askPassword'>
242 ;; <arg name='message' type='s' direction='in'/>
243 ;; <arg name='default_user' type='s' direction='in'/>
244 ;; <arg name='default_domain' type='s' direction='in'/>
245 ;; <arg name='flags' type='u' direction='in'/>
246 ;; <arg name='handled' type='b' direction='out'/>
247 ;; <arg name='aborted' type='b' direction='out'/>
248 ;; <arg name='password' type='s' direction='out'/>
249 ;; <arg name='username' type='s' direction='out'/>
250 ;; <arg name='domain' type='s' direction='out'/>
251 ;; <arg name='anonymous' type='b' direction='out'/>
252 ;; <arg name='password_save' type='u' direction='out'/>
253 ;; </method>
254 ;; <method name='askQuestion'>
255 ;; <arg name='message' type='s' direction='in'/>
256 ;; <arg name='choices' type='as' direction='in'/>
257 ;; <arg name='handled' type='b' direction='out'/>
258 ;; <arg name='aborted' type='b' direction='out'/>
259 ;; <arg name='choice' type='u' direction='out'/>
260 ;; </method>
261 ;; </interface>
263 ;; The following flags are used in "askPassword". They are defined in
264 ;; /usr/include/glib-2.0/gio/gioenums.h.
266 (defconst tramp-gvfs-password-need-password 1
267 "Operation requires a password.")
269 (defconst tramp-gvfs-password-need-username 2
270 "Operation requires a username.")
272 (defconst tramp-gvfs-password-need-domain 4
273 "Operation requires a domain.")
275 (defconst tramp-gvfs-password-saving-supported 8
276 "Operation supports saving settings.")
278 (defconst tramp-gvfs-password-anonymous-supported 16
279 "Operation supports anonymous users.")
281 (defconst tramp-bluez-service "org.bluez"
282 "The well known name of the BLUEZ service.")
284 (defconst tramp-bluez-interface-manager "org.bluez.Manager"
285 "The manager interface of the BLUEZ daemon.")
287 ;; <interface name='org.bluez.Manager'>
288 ;; <method name='DefaultAdapter'>
289 ;; <arg type='o' direction='out'/>
290 ;; </method>
291 ;; <method name='FindAdapter'>
292 ;; <arg type='s' direction='in'/>
293 ;; <arg type='o' direction='out'/>
294 ;; </method>
295 ;; <method name='ListAdapters'>
296 ;; <arg type='ao' direction='out'/>
297 ;; </method>
298 ;; <signal name='AdapterAdded'>
299 ;; <arg type='o'/>
300 ;; </signal>
301 ;; <signal name='AdapterRemoved'>
302 ;; <arg type='o'/>
303 ;; </signal>
304 ;; <signal name='DefaultAdapterChanged'>
305 ;; <arg type='o'/>
306 ;; </signal>
307 ;; </interface>
309 (defconst tramp-bluez-interface-adapter "org.bluez.Adapter"
310 "The adapter interface of the BLUEZ daemon.")
312 ;; <interface name='org.bluez.Adapter'>
313 ;; <method name='GetProperties'>
314 ;; <arg type='a{sv}' direction='out'/>
315 ;; </method>
316 ;; <method name='SetProperty'>
317 ;; <arg type='s' direction='in'/>
318 ;; <arg type='v' direction='in'/>
319 ;; </method>
320 ;; <method name='RequestMode'>
321 ;; <arg type='s' direction='in'/>
322 ;; </method>
323 ;; <method name='ReleaseMode'/>
324 ;; <method name='RequestSession'/>
325 ;; <method name='ReleaseSession'/>
326 ;; <method name='StartDiscovery'/>
327 ;; <method name='StopDiscovery'/>
328 ;; <method name='ListDevices'>
329 ;; <arg type='ao' direction='out'/>
330 ;; </method>
331 ;; <method name='CreateDevice'>
332 ;; <arg type='s' direction='in'/>
333 ;; <arg type='o' direction='out'/>
334 ;; </method>
335 ;; <method name='CreatePairedDevice'>
336 ;; <arg type='s' direction='in'/>
337 ;; <arg type='o' direction='in'/>
338 ;; <arg type='s' direction='in'/>
339 ;; <arg type='o' direction='out'/>
340 ;; </method>
341 ;; <method name='CancelDeviceCreation'>
342 ;; <arg type='s' direction='in'/>
343 ;; </method>
344 ;; <method name='RemoveDevice'>
345 ;; <arg type='o' direction='in'/>
346 ;; </method>
347 ;; <method name='FindDevice'>
348 ;; <arg type='s' direction='in'/>
349 ;; <arg type='o' direction='out'/>
350 ;; </method>
351 ;; <method name='RegisterAgent'>
352 ;; <arg type='o' direction='in'/>
353 ;; <arg type='s' direction='in'/>
354 ;; </method>
355 ;; <method name='UnregisterAgent'>
356 ;; <arg type='o' direction='in'/>
357 ;; </method>
358 ;; <signal name='DeviceCreated'>
359 ;; <arg type='o'/>
360 ;; </signal>
361 ;; <signal name='DeviceRemoved'>
362 ;; <arg type='o'/>
363 ;; </signal>
364 ;; <signal name='DeviceFound'>
365 ;; <arg type='s'/>
366 ;; <arg type='a{sv}'/>
367 ;; </signal>
368 ;; <signal name='PropertyChanged'>
369 ;; <arg type='s'/>
370 ;; <arg type='v'/>
371 ;; </signal>
372 ;; <signal name='DeviceDisappeared'>
373 ;; <arg type='s'/>
374 ;; </signal>
375 ;; </interface>
377 (defcustom tramp-bluez-discover-devices-timeout 60
378 "Defines seconds since last bluetooth device discovery before rescanning.
379 A value of 0 would require an immediate discovery during hostname
380 completion, nil means to use always cached values for discovered
381 devices."
382 :group 'tramp
383 :version "23.2"
384 :type '(choice (const nil) integer))
386 (defvar tramp-bluez-discovery nil
387 "Indicator for a running bluetooth device discovery.
388 It keeps the timestamp of last discovery.")
390 (defvar tramp-bluez-devices nil
391 "Alist of detected bluetooth devices.
392 Every entry is a list (NAME ADDRESS).")
394 (defconst tramp-hal-service "org.freedesktop.Hal"
395 "The well known name of the HAL service.")
397 (defconst tramp-hal-path-manager "/org/freedesktop/Hal/Manager"
398 "The object path of the HAL daemon manager.")
400 (defconst tramp-hal-interface-manager "org.freedesktop.Hal.Manager"
401 "The manager interface of the HAL daemon.")
403 (defconst tramp-hal-interface-device "org.freedesktop.Hal.Device"
404 "The device interface of the HAL daemon.")
407 ;; New handlers should be added here.
408 (defconst tramp-gvfs-file-name-handler-alist
409 '((access-file . ignore)
410 (add-name-to-file . tramp-gvfs-handle-copy-file)
411 ;; `byte-compiler-base-file-name' performed by default handler.
412 ;; `copy-directory' performed by default handler.
413 (copy-file . tramp-gvfs-handle-copy-file)
414 (delete-directory . tramp-gvfs-handle-delete-directory)
415 (delete-file . tramp-gvfs-handle-delete-file)
416 ;; `diff-latest-backup-file' performed by default handler.
417 (directory-file-name . tramp-handle-directory-file-name)
418 (directory-files . tramp-handle-directory-files)
419 (directory-files-and-attributes
420 . tramp-handle-directory-files-and-attributes)
421 (dired-call-process . ignore)
422 (dired-compress-file . ignore)
423 (dired-uncache . tramp-handle-dired-uncache)
424 (expand-file-name . tramp-gvfs-handle-expand-file-name)
425 (file-accessible-directory-p . tramp-handle-file-accessible-directory-p)
426 (file-acl . ignore)
427 (file-attributes . tramp-gvfs-handle-file-attributes)
428 (file-directory-p . tramp-gvfs-handle-file-directory-p)
429 ;; `file-equal-p' performed by default handler.
430 (file-executable-p . tramp-gvfs-handle-file-executable-p)
431 (file-exists-p . tramp-handle-file-exists-p)
432 ;; `file-in-directory-p' performed by default handler.
433 (file-local-copy . tramp-gvfs-handle-file-local-copy)
434 (file-modes . tramp-handle-file-modes)
435 (file-name-all-completions . tramp-gvfs-handle-file-name-all-completions)
436 (file-name-as-directory . tramp-handle-file-name-as-directory)
437 (file-name-completion . tramp-handle-file-name-completion)
438 (file-name-directory . tramp-handle-file-name-directory)
439 (file-name-nondirectory . tramp-handle-file-name-nondirectory)
440 ;; `file-name-sans-versions' performed by default handler.
441 (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
442 (file-notify-add-watch . tramp-gvfs-handle-file-notify-add-watch)
443 (file-notify-rm-watch . tramp-handle-file-notify-rm-watch)
444 (file-ownership-preserved-p . ignore)
445 (file-readable-p . tramp-gvfs-handle-file-readable-p)
446 (file-regular-p . tramp-handle-file-regular-p)
447 (file-remote-p . tramp-handle-file-remote-p)
448 (file-selinux-context . ignore)
449 (file-symlink-p . tramp-handle-file-symlink-p)
450 ;; `file-truename' performed by default handler.
451 (file-writable-p . tramp-gvfs-handle-file-writable-p)
452 (find-backup-file-name . tramp-handle-find-backup-file-name)
453 ;; `find-file-noselect' performed by default handler.
454 ;; `get-file-buffer' performed by default handler.
455 (insert-directory . tramp-handle-insert-directory)
456 (insert-file-contents . tramp-handle-insert-file-contents)
457 (load . tramp-handle-load)
458 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
459 (make-directory . tramp-gvfs-handle-make-directory)
460 (make-directory-internal . ignore)
461 (make-symbolic-link . tramp-handle-make-symbolic-link)
462 (process-file . ignore)
463 (rename-file . tramp-gvfs-handle-rename-file)
464 (set-file-acl . ignore)
465 (set-file-modes . ignore)
466 (set-file-selinux-context . ignore)
467 (set-file-times . ignore)
468 (set-visited-file-modtime . tramp-handle-set-visited-file-modtime)
469 (shell-command . ignore)
470 (start-file-process . ignore)
471 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
472 (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory)
473 (vc-registered . ignore)
474 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime)
475 (write-region . tramp-gvfs-handle-write-region))
476 "Alist of handler functions for Tramp GVFS method.
477 Operations not mentioned here will be handled by the default Emacs primitives.")
479 ;; It must be a `defsubst' in order to push the whole code into
480 ;; tramp-loaddefs.el. Otherwise, there would be recursive autoloading.
481 ;;;###tramp-autoload
482 (defsubst tramp-gvfs-file-name-p (filename)
483 "Check if it's a filename handled by the GVFS daemon."
484 (and (tramp-tramp-file-p filename)
485 (let ((method
486 (tramp-file-name-method (tramp-dissect-file-name filename))))
487 (and (stringp method) (member method tramp-gvfs-methods)))))
489 ;;;###tramp-autoload
490 (defun tramp-gvfs-file-name-handler (operation &rest args)
491 "Invoke the GVFS related OPERATION.
492 First arg specifies the OPERATION, second arg is a list of arguments to
493 pass to the OPERATION."
494 (unless tramp-gvfs-enabled
495 (tramp-user-error nil "Package `tramp-gvfs' not supported"))
496 (let ((fn (assoc operation tramp-gvfs-file-name-handler-alist)))
497 (if fn
498 (save-match-data (apply (cdr fn) args))
499 (tramp-run-real-handler operation args))))
501 ;; This might be moved to tramp.el. It shall be the first file name
502 ;; handler.
503 ;;;###tramp-autoload
504 (when (featurep 'dbusbind)
505 (add-to-list 'tramp-foreign-file-name-handler-alist
506 (cons 'tramp-gvfs-file-name-p 'tramp-gvfs-file-name-handler)))
509 ;; D-Bus helper function.
511 (defun tramp-gvfs-dbus-string-to-byte-array (string)
512 "Like `dbus-string-to-byte-array' but add trailing \\0 if needed."
513 (dbus-string-to-byte-array
514 (if (string-match "^(aya{sv})" tramp-gvfs-mountlocation-signature)
515 (concat string (string 0)) string)))
517 (defun tramp-gvfs-dbus-byte-array-to-string (byte-array)
518 "Like `dbus-byte-array-to-string' but remove trailing \\0 if exists."
519 ;; The byte array could be a variant. Take care.
520 (let ((byte-array
521 (if (and (consp byte-array) (atom (car byte-array)))
522 byte-array (car byte-array))))
523 (dbus-byte-array-to-string
524 (if (and (consp byte-array) (zerop (car (last byte-array))))
525 (butlast byte-array) byte-array))))
527 (defun tramp-gvfs-stringify-dbus-message (message)
528 "Convert a D-Bus message into readable UTF8 strings, used for traces."
529 (cond
530 ((and (consp message) (characterp (car message)))
531 (format "%S" (tramp-gvfs-dbus-byte-array-to-string message)))
532 ((consp message)
533 (mapcar 'tramp-gvfs-stringify-dbus-message message))
534 ((stringp message)
535 (format "%S" message))
536 (t message)))
538 (defmacro with-tramp-dbus-call-method
539 (vec synchronous bus service path interface method &rest args)
540 "Apply a D-Bus call on bus BUS.
542 If SYNCHRONOUS is non-nil, the call is synchronously. Otherwise,
543 it is an asynchronous call, with `ignore' as callback function.
545 The other arguments have the same meaning as with `dbus-call-method'
546 or `dbus-call-method-asynchronously'. Additionally, the call
547 will be traced by Tramp with trace level 6."
548 `(let ((func (if ,synchronous
549 'dbus-call-method 'dbus-call-method-asynchronously))
550 (args (append (list ,bus ,service ,path ,interface ,method)
551 (if ,synchronous (list ,@args) (list 'ignore ,@args))))
552 result)
553 (tramp-message ,vec 6 "%s %s" func args)
554 (setq result (apply func args))
555 (tramp-message ,vec 6 "%s" (tramp-gvfs-stringify-dbus-message result))
556 result))
558 (put 'with-tramp-dbus-call-method 'lisp-indent-function 2)
559 (put 'with-tramp-dbus-call-method 'edebug-form-spec '(form symbolp body))
560 (tramp-compat-font-lock-add-keywords
561 'emacs-lisp-mode '("\\<with-tramp-dbus-call-method\\>"))
563 (defvar tramp-gvfs-dbus-event-vector nil
564 "Current Tramp file name to be used, as vector.
565 It is needed when D-Bus signals or errors arrive, because there
566 is no information where to trace the message.")
568 (defun tramp-gvfs-dbus-event-error (event err)
569 "Called when a D-Bus error message arrives, see `dbus-event-error-functions'."
570 (when tramp-gvfs-dbus-event-vector
571 (tramp-message tramp-gvfs-dbus-event-vector 10 "%S" event)
572 (tramp-error tramp-gvfs-dbus-event-vector 'file-error "%s" (cadr err))))
574 ;; `dbus-event-error-hooks' has been renamed to `dbus-event-error-functions'.
575 (add-hook
576 (if (boundp 'dbus-event-error-functions)
577 'dbus-event-error-functions 'dbus-event-error-hooks)
578 'tramp-gvfs-dbus-event-error)
581 ;; File name primitives.
583 (defun tramp-gvfs-handle-copy-file
584 (filename newname &optional ok-if-already-exists keep-date
585 preserve-uid-gid preserve-extended-attributes)
586 "Like `copy-file' for Tramp files."
587 (with-parsed-tramp-file-name
588 (if (tramp-tramp-file-p filename) filename newname) nil
590 (when (and (not ok-if-already-exists) (file-exists-p newname))
591 (tramp-error
592 v 'file-already-exists "File %s already exists" newname))
594 (if (or (and (tramp-tramp-file-p filename)
595 (not (tramp-gvfs-file-name-p filename)))
596 (and (tramp-tramp-file-p newname)
597 (not (tramp-gvfs-file-name-p newname))))
599 ;; We cannot call `copy-file' directly. Use
600 ;; `tramp-compat-funcall' for backward compatibility (number
601 ;; of arguments).
602 (let ((tmpfile (tramp-compat-make-temp-file filename)))
603 (cond
604 (preserve-extended-attributes
605 (tramp-compat-funcall
606 'copy-file
607 filename tmpfile t keep-date preserve-uid-gid
608 preserve-extended-attributes))
609 (preserve-uid-gid
610 (tramp-compat-funcall
611 'copy-file filename tmpfile t keep-date preserve-uid-gid))
613 (copy-file filename tmpfile t keep-date)))
614 (rename-file tmpfile newname ok-if-already-exists))
616 ;; Direct copy.
617 (with-tramp-progress-reporter
618 v 0 (format "Copying %s to %s" filename newname)
619 (unless
620 (let ((args
621 (append (if (or keep-date preserve-uid-gid)
622 (list "--preserve")
623 nil)
624 (list
625 (tramp-gvfs-url-file-name filename)
626 (tramp-gvfs-url-file-name newname)))))
627 (apply 'tramp-gvfs-send-command v "gvfs-copy" args))
628 ;; Propagate the error.
629 (with-current-buffer (tramp-get-connection-buffer v)
630 (goto-char (point-min))
631 (tramp-error-with-buffer
632 nil v 'file-error
633 "Copying failed, see buffer `%s' for details." (buffer-name)))))
635 (when (tramp-tramp-file-p newname)
636 (with-parsed-tramp-file-name newname nil
637 (tramp-flush-file-property v (file-name-directory localname))
638 (tramp-flush-file-property v localname))))))
640 (defun tramp-gvfs-handle-delete-directory (directory &optional recursive trash)
641 "Like `delete-directory' for Tramp files."
642 (when (and recursive (not (file-symlink-p directory)))
643 (mapc (lambda (file)
644 (if (eq t (car (file-attributes file)))
645 (tramp-compat-delete-directory file recursive trash)
646 (tramp-compat-delete-file file trash)))
647 (directory-files
648 directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
649 (with-parsed-tramp-file-name directory nil
650 (tramp-flush-file-property v (file-name-directory localname))
651 (tramp-flush-directory-property v localname)
652 (unless
653 (tramp-gvfs-send-command
654 v (if (and trash delete-by-moving-to-trash) "gvfs-trash" "gvfs-rm")
655 (tramp-gvfs-url-file-name directory))
656 ;; Propagate the error.
657 (with-current-buffer (tramp-get-connection-buffer v)
658 (goto-char (point-min))
659 (tramp-error-with-buffer
660 nil v 'file-error "Couldn't delete %s" directory)))))
662 (defun tramp-gvfs-handle-delete-file (filename &optional trash)
663 "Like `delete-file' for Tramp files."
664 (with-parsed-tramp-file-name filename nil
665 (tramp-flush-file-property v (file-name-directory localname))
666 (tramp-flush-file-property v localname)
667 (unless
668 (tramp-gvfs-send-command
669 v (if (and trash delete-by-moving-to-trash) "gvfs-trash" "gvfs-rm")
670 (tramp-gvfs-url-file-name filename))
671 ;; Propagate the error.
672 (with-current-buffer (tramp-get-connection-buffer v)
673 (goto-char (point-min))
674 (tramp-error-with-buffer
675 nil v 'file-error "Couldn't delete %s" filename)))))
677 (defun tramp-gvfs-handle-expand-file-name (name &optional dir)
678 "Like `expand-file-name' for Tramp files."
679 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
680 (setq dir (or dir default-directory "/"))
681 ;; Unless NAME is absolute, concat DIR and NAME.
682 (unless (file-name-absolute-p name)
683 (setq name (concat (file-name-as-directory dir) name)))
684 ;; If NAME is not a Tramp file, run the real handler.
685 (if (not (tramp-tramp-file-p name))
686 (tramp-run-real-handler 'expand-file-name (list name nil))
687 ;; Dissect NAME.
688 (with-parsed-tramp-file-name name nil
689 ;; If there is a default location, expand tilde.
690 (when (string-match "\\`\\(~\\)\\(/\\|\\'\\)" localname)
691 (save-match-data
692 (tramp-gvfs-maybe-open-connection (vector method user host "/" hop)))
693 (setq localname
694 (replace-match
695 (tramp-get-file-property v "/" "default-location" "~")
696 nil t localname 1)))
697 ;; Tilde expansion is not possible.
698 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
699 (tramp-error
700 v 'file-error
701 "Cannot expand tilde in file `%s'" name))
702 (unless (tramp-run-real-handler 'file-name-absolute-p (list localname))
703 (setq localname (concat "/" localname)))
704 ;; We do not pass "/..".
705 (if (string-equal "smb" method)
706 (when (string-match "^/[^/]+\\(/\\.\\./?\\)" localname)
707 (setq localname (replace-match "/" t t localname 1)))
708 (when (string-match "^/\\.\\./?" localname)
709 (setq localname (replace-match "/" t t localname))))
710 ;; There might be a double slash. Remove this.
711 (while (string-match "//" localname)
712 (setq localname (replace-match "/" t t localname)))
713 ;; No tilde characters in file name, do normal
714 ;; `expand-file-name' (this does "/./" and "/../").
715 (tramp-make-tramp-file-name
716 method user host
717 (tramp-run-real-handler
718 'expand-file-name (list localname))))))
720 (defun tramp-gvfs-handle-file-attributes (filename &optional id-format)
721 "Like `file-attributes' for Tramp files."
722 (unless id-format (setq id-format 'integer))
723 (ignore-errors
724 ;; Don't modify `last-coding-system-used' by accident.
725 (let ((last-coding-system-used last-coding-system-used)
726 dirp res-symlink-target res-numlinks res-uid res-gid res-access
727 res-mod res-change res-size res-filemodes res-inode res-device)
728 (with-parsed-tramp-file-name filename nil
729 (with-tramp-file-property
730 v localname (format "file-attributes-%s" id-format)
731 (tramp-message v 5 "file attributes: %s" localname)
732 (tramp-gvfs-send-command
733 v "gvfs-info" (tramp-gvfs-url-file-name filename))
734 ;; Parse output ...
735 (with-current-buffer (tramp-get-connection-buffer v)
736 (goto-char (point-min))
737 (when (re-search-forward "attributes:" nil t)
738 ;; ... directory or symlink
739 (goto-char (point-min))
740 (setq dirp (if (re-search-forward "type:\\s-+directory" nil t) t))
741 (goto-char (point-min))
742 (setq res-symlink-target
743 (if (re-search-forward
744 "standard::symlink-target:\\s-+\\(\\S-+\\)" nil t)
745 (match-string 1)))
746 ;; ... number links
747 (goto-char (point-min))
748 (setq res-numlinks
749 (if (re-search-forward
750 "unix::nlink:\\s-+\\([0-9]+\\)" nil t)
751 (string-to-number (match-string 1)) 0))
752 ;; ... uid and gid
753 (goto-char (point-min))
754 (setq res-uid
755 (or (if (eq id-format 'integer)
756 (if (re-search-forward
757 "unix::uid:\\s-+\\([0-9]+\\)" nil t)
758 (string-to-number (match-string 1)))
759 (if (re-search-forward
760 "owner::user:\\s-+\\(\\S-+\\)" nil t)
761 (match-string 1)))
762 (tramp-get-local-uid id-format)))
763 (setq res-gid
764 (or (if (eq id-format 'integer)
765 (if (re-search-forward
766 "unix::gid:\\s-+\\([0-9]+\\)" nil t)
767 (string-to-number (match-string 1)))
768 (if (re-search-forward
769 "owner::group:\\s-+\\(\\S-+\\)" nil t)
770 (match-string 1)))
771 (tramp-get-local-gid id-format)))
772 ;; ... last access, modification and change time
773 (goto-char (point-min))
774 (setq res-access
775 (if (re-search-forward
776 "time::access:\\s-+\\([0-9]+\\)" nil t)
777 (seconds-to-time (string-to-number (match-string 1)))
778 '(0 0)))
779 (goto-char (point-min))
780 (setq res-mod
781 (if (re-search-forward
782 "time::modified:\\s-+\\([0-9]+\\)" nil t)
783 (seconds-to-time (string-to-number (match-string 1)))
784 '(0 0)))
785 (goto-char (point-min))
786 (setq res-change
787 (if (re-search-forward
788 "time::changed:\\s-+\\([0-9]+\\)" nil t)
789 (seconds-to-time (string-to-number (match-string 1)))
790 '(0 0)))
791 ;; ... size
792 (goto-char (point-min))
793 (setq res-size
794 (if (re-search-forward
795 "standard::size:\\s-+\\([0-9]+\\)" nil t)
796 (string-to-number (match-string 1)) 0))
797 ;; ... file mode flags
798 (goto-char (point-min))
799 (setq res-filemodes
800 (if (re-search-forward "unix::mode:\\s-+\\([0-9]+\\)" nil t)
801 (tramp-file-mode-from-int
802 (string-to-number (match-string 1)))
803 (if dirp "drwx------" "-rwx------")))
804 ;; ... inode and device
805 (goto-char (point-min))
806 (setq res-inode
807 (if (re-search-forward
808 "unix::inode:\\s-+\\([0-9]+\\)" nil t)
809 (string-to-number (match-string 1))
810 (tramp-get-inode v)))
811 (goto-char (point-min))
812 (setq res-device
813 (if (re-search-forward
814 "unix::device:\\s-+\\([0-9]+\\)" nil t)
815 (string-to-number (match-string 1))
816 (tramp-get-device v)))
818 ;; Return data gathered.
819 (list
820 ;; 0. t for directory, string (name linked to) for
821 ;; symbolic link, or nil.
822 (or dirp res-symlink-target)
823 ;; 1. Number of links to file.
824 res-numlinks
825 ;; 2. File uid.
826 res-uid
827 ;; 3. File gid.
828 res-gid
829 ;; 4. Last access time, as a list of integers.
830 ;; 5. Last modification time, likewise.
831 ;; 6. Last status change time, likewise.
832 res-access res-mod res-change
833 ;; 7. Size in bytes (-1, if number is out of range).
834 res-size
835 ;; 8. File modes.
836 res-filemodes
837 ;; 9. t if file's gid would change if file were deleted
838 ;; and recreated.
840 ;; 10. Inode number.
841 res-inode
842 ;; 11. Device number.
843 res-device
844 ))))))))
846 (defun tramp-gvfs-handle-file-directory-p (filename)
847 "Like `file-directory-p' for Tramp files."
848 (eq t (car (file-attributes filename))))
850 (defun tramp-gvfs-handle-file-executable-p (filename)
851 "Like `file-executable-p' for Tramp files."
852 (with-parsed-tramp-file-name filename nil
853 (with-tramp-file-property v localname "file-executable-p"
854 (tramp-check-cached-permissions v ?x))))
856 (defun tramp-gvfs-handle-file-local-copy (filename)
857 "Like `file-local-copy' for Tramp files."
858 (with-parsed-tramp-file-name filename nil
859 (let ((tmpfile (tramp-compat-make-temp-file filename)))
860 (unless (file-exists-p filename)
861 (tramp-error
862 v 'file-error
863 "Cannot make local copy of non-existing file `%s'" filename))
864 (copy-file filename tmpfile t t)
865 tmpfile)))
867 (defun tramp-gvfs-handle-file-name-all-completions (filename directory)
868 "Like `file-name-all-completions' for Tramp files."
869 (unless (save-match-data (string-match "/" filename))
870 (with-parsed-tramp-file-name (expand-file-name directory) nil
872 (all-completions
873 filename
874 (mapcar
875 'list
877 ;; Try cache entries for filename, filename with last
878 ;; character removed, filename with last two characters
879 ;; removed, ..., and finally the empty string - all
880 ;; concatenated to the local directory name.
881 (let ((remote-file-name-inhibit-cache
882 (or remote-file-name-inhibit-cache
883 tramp-completion-reread-directory-timeout)))
885 ;; This is inefficient for very long filenames, pity
886 ;; `reduce' is not available...
887 (car
888 (apply
889 'append
890 (mapcar
891 (lambda (x)
892 (let ((cache-hit
893 (tramp-get-file-property
895 (concat localname (substring filename 0 x))
896 "file-name-all-completions"
897 nil)))
898 (when cache-hit (list cache-hit))))
899 ;; We cannot use a length of 0, because file properties
900 ;; for "foo" and "foo/" are identical.
901 (tramp-compat-number-sequence (length filename) 1 -1)))))
903 ;; Cache expired or no matching cache entry found so we need
904 ;; to perform a remote operation.
905 (let ((result '("." ".."))
906 entry)
907 ;; Get a list of directories and files.
908 (tramp-gvfs-send-command
909 v "gvfs-ls" "-h" (tramp-gvfs-url-file-name directory))
911 ;; Now grab the output.
912 (with-temp-buffer
913 (insert-buffer-substring (tramp-get-connection-buffer v))
914 (goto-char (point-max))
915 (while (zerop (forward-line -1))
916 (setq entry (buffer-substring (point) (point-at-eol)))
917 (when (string-match filename entry)
918 (if (file-directory-p (expand-file-name entry directory))
919 (push (concat entry "/") result)
920 (push entry result)))))
922 ;; Because the remote op went through OK we know the
923 ;; directory we `cd'-ed to exists.
924 (tramp-set-file-property v localname "file-exists-p" t)
926 ;; Because the remote op went through OK we know every
927 ;; file listed by `ls' exists.
928 (mapc (lambda (entry)
929 (tramp-set-file-property
930 v (concat localname entry) "file-exists-p" t))
931 result)
933 ;; Store result in the cache.
934 (tramp-set-file-property
935 v (concat localname filename)
936 "file-name-all-completions" result))))))))
938 (defun tramp-gvfs-handle-file-notify-add-watch (file-name _flags _callback)
939 "Like `file-notify-add-watch' for Tramp files."
940 (setq file-name (expand-file-name file-name))
941 (with-parsed-tramp-file-name file-name nil
942 (let ((p (start-process
943 "gvfs-monitor-file" (generate-new-buffer " *gvfs-monitor-file*")
944 "gvfs-monitor-file" (tramp-gvfs-url-file-name file-name))))
945 (if (not (processp p))
946 (tramp-error
947 v 'file-notify-error "gvfs-monitor-file failed to start")
948 (tramp-message
949 v 6 "Run `%s', %S" (mapconcat 'identity (process-command p) " ") p)
950 (tramp-set-connection-property p "vector" v)
951 (tramp-compat-set-process-query-on-exit-flag p nil)
952 (set-process-filter p 'tramp-gvfs-file-gvfs-monitor-file-process-filter)
953 (with-current-buffer (process-buffer p)
954 (setq default-directory (file-name-directory file-name)))
955 p))))
957 (defun tramp-gvfs-file-gvfs-monitor-file-process-filter (proc string)
958 "Read output from \"gvfs-monitor-file\" and add corresponding file-notify events."
959 (let* ((rest-string (tramp-compat-process-get proc 'rest-string))
960 (dd (with-current-buffer (process-buffer proc) default-directory))
961 (ddu (regexp-quote (tramp-gvfs-url-file-name dd))))
962 (when rest-string
963 (tramp-message proc 10 "Previous string:\n%s" rest-string))
964 (tramp-message proc 6 "%S\n%s" proc string)
965 (setq string (concat rest-string string)
966 ;; Attribute change is returned in unused wording.
967 string (tramp-compat-replace-regexp-in-string
968 "ATTRIB CHANGED" "ATTRIBUTE_CHANGED" string))
970 (while (string-match
971 (concat "^[\n\r]*"
972 "File Monitor Event:[\n\r]+"
973 "File = \\([^\n\r]+\\)[\n\r]+"
974 "Event = \\([^[:blank:]]+\\)[\n\r]+")
975 string)
976 (let ((action (intern-soft
977 (tramp-compat-replace-regexp-in-string
978 "_" "-" (downcase (match-string 2 string)))))
979 (file (match-string 1 string)))
980 (setq string (replace-match "" nil nil string))
981 ;; File names are returned as URL paths. We must convert them.
982 (when (string-match ddu file)
983 (setq file (replace-match dd nil nil file)))
984 (while (string-match "%\\([0-9A-F]\\{2\\}\\)" file)
985 (setq file
986 (replace-match
987 (char-to-string (string-to-number (match-string 1 file) 16))
988 nil nil file)))
989 ;; Usually, we would add an Emacs event now. Unfortunately,
990 ;; `unread-command-events' does not accept several events at
991 ;; once. Therefore, we apply the callback directly.
992 (tramp-compat-funcall 'file-notify-callback (list proc action file))))
994 ;; Save rest of the string.
995 (when (zerop (length string)) (setq string nil))
996 (when string (tramp-message proc 10 "Rest string:\n%s" string))
997 (tramp-compat-process-put proc 'rest-string string)))
999 (defun tramp-gvfs-handle-file-readable-p (filename)
1000 "Like `file-readable-p' for Tramp files."
1001 (with-parsed-tramp-file-name filename nil
1002 (with-tramp-file-property v localname "file-executable-p"
1003 (tramp-check-cached-permissions v ?r))))
1005 (defun tramp-gvfs-handle-file-writable-p (filename)
1006 "Like `file-writable-p' for Tramp files."
1007 (with-parsed-tramp-file-name filename nil
1008 (with-tramp-file-property v localname "file-writable-p"
1009 (if (file-exists-p filename)
1010 (tramp-check-cached-permissions v ?w)
1011 ;; If file doesn't exist, check if directory is writable.
1012 (and (file-directory-p (file-name-directory filename))
1013 (file-writable-p (file-name-directory filename)))))))
1015 (defun tramp-gvfs-handle-make-directory (dir &optional parents)
1016 "Like `make-directory' for Tramp files."
1017 (with-parsed-tramp-file-name dir nil
1018 (unless
1019 (apply
1020 'tramp-gvfs-send-command v "gvfs-mkdir"
1021 (if parents
1022 (list "-p" (tramp-gvfs-url-file-name dir))
1023 (list (tramp-gvfs-url-file-name dir))))
1024 ;; Propagate the error.
1025 (tramp-error v 'file-error "Couldn't make directory %s" dir))))
1027 (defun tramp-gvfs-handle-rename-file
1028 (filename newname &optional ok-if-already-exists)
1029 "Like `rename-file' for Tramp files."
1030 (with-parsed-tramp-file-name
1031 (if (tramp-tramp-file-p filename) filename newname) nil
1033 (when (and (not ok-if-already-exists) (file-exists-p newname))
1034 (tramp-error
1035 v 'file-already-exists "File %s already exists" newname))
1037 (if (or (and (tramp-tramp-file-p filename)
1038 (not (tramp-gvfs-file-name-p filename)))
1039 (and (tramp-tramp-file-p newname)
1040 (not (tramp-gvfs-file-name-p newname))))
1042 ;; We cannot move directly.
1043 (let ((tmpfile (tramp-compat-make-temp-file filename)))
1044 (rename-file filename tmpfile t)
1045 (rename-file tmpfile newname ok-if-already-exists))
1047 ;; Direct move.
1048 (with-tramp-progress-reporter
1049 v 0 (format "Renaming %s to %s" filename newname)
1050 (unless
1051 (tramp-gvfs-send-command
1052 v "gvfs-move"
1053 (tramp-gvfs-url-file-name filename)
1054 (tramp-gvfs-url-file-name newname))
1055 ;; Propagate the error.
1056 (with-current-buffer (tramp-get-buffer v)
1057 (goto-char (point-min))
1058 (tramp-error-with-buffer
1059 nil v 'file-error
1060 "Renaming failed, see buffer `%s' for details." (buffer-name)))))
1062 (when (tramp-tramp-file-p filename)
1063 (with-parsed-tramp-file-name filename nil
1064 (tramp-flush-file-property v (file-name-directory localname))
1065 (tramp-flush-file-property v localname)))
1067 (when (tramp-tramp-file-p newname)
1068 (with-parsed-tramp-file-name newname nil
1069 (tramp-flush-file-property v (file-name-directory localname))
1070 (tramp-flush-file-property v localname))))))
1072 (defun tramp-gvfs-handle-write-region
1073 (start end filename &optional append visit lockname confirm)
1074 "Like `write-region' for Tramp files."
1075 (with-parsed-tramp-file-name filename nil
1076 ;; XEmacs takes a coding system as the seventh argument, not `confirm'.
1077 (when (and (not (featurep 'xemacs)) confirm (file-exists-p filename))
1078 (unless (y-or-n-p (format "File %s exists; overwrite anyway? " filename))
1079 (tramp-error v 'file-error "File not overwritten")))
1081 (let ((tmpfile (tramp-compat-make-temp-file filename)))
1082 (when (and append (file-exists-p filename))
1083 (copy-file filename tmpfile 'ok))
1084 ;; We say `no-message' here because we don't want the visited file
1085 ;; modtime data to be clobbered from the temp file. We call
1086 ;; `set-visited-file-modtime' ourselves later on.
1087 (tramp-run-real-handler
1088 'write-region
1089 (if confirm ; don't pass this arg unless defined for backward compat.
1090 (list start end tmpfile append 'no-message lockname confirm)
1091 (list start end tmpfile append 'no-message lockname)))
1092 (condition-case nil
1093 (rename-file tmpfile filename 'ok-if-already-exists)
1094 (error
1095 (delete-file tmpfile)
1096 (tramp-error
1097 v 'file-error "Couldn't write region to `%s'" filename))))
1099 (tramp-flush-file-property v (file-name-directory localname))
1100 (tramp-flush-file-property v localname)
1102 ;; Set file modification time.
1103 (when (or (eq visit t) (stringp visit))
1104 (set-visited-file-modtime (nth 5 (file-attributes filename))))
1106 ;; The end.
1107 (when (or (eq visit t) (null visit) (stringp visit))
1108 (tramp-message v 0 "Wrote %s" filename))
1109 (run-hooks 'tramp-handle-write-region-hook)))
1112 ;; File name conversions.
1114 (defun tramp-gvfs-url-file-name (filename)
1115 "Return FILENAME in URL syntax."
1116 ;; "/" must NOT be hexlified.
1117 (let ((url-unreserved-chars (cons ?/ url-unreserved-chars))
1118 result)
1119 (setq
1120 result
1121 (url-recreate-url
1122 (if (tramp-tramp-file-p filename)
1123 (with-parsed-tramp-file-name filename nil
1124 (when (and user (string-match tramp-user-with-domain-regexp user))
1125 (setq user
1126 (concat (match-string 2 user) ";" (match-string 1 user))))
1127 (url-parse-make-urlobj
1128 method (and user (url-hexify-string user)) nil
1129 (tramp-file-name-real-host v) (tramp-file-name-port v)
1130 (and localname (url-hexify-string localname)) nil nil t))
1131 (url-parse-make-urlobj
1132 "file" nil nil nil nil
1133 (url-hexify-string (file-truename filename)) nil nil t))))
1134 (when (tramp-tramp-file-p filename)
1135 (with-parsed-tramp-file-name filename nil
1136 (tramp-message v 10 "remote file `%s' is URL `%s'" filename result)))
1137 result))
1139 (defun tramp-gvfs-object-path (filename)
1140 "Create a D-Bus object path from FILENAME."
1141 (expand-file-name (dbus-escape-as-identifier filename) tramp-gvfs-path-tramp))
1143 (defun tramp-gvfs-file-name (object-path)
1144 "Retrieve file name from D-Bus OBJECT-PATH."
1145 (dbus-unescape-from-identifier
1146 (tramp-compat-replace-regexp-in-string
1147 "^.*/\\([^/]+\\)$" "\\1" object-path)))
1149 (defun tramp-bluez-address (device)
1150 "Return bluetooth device address from a given bluetooth DEVICE name."
1151 (when (stringp device)
1152 (if (string-match tramp-ipv6-regexp device)
1153 (match-string 0 device)
1154 (cadr (assoc device (tramp-bluez-list-devices))))))
1156 (defun tramp-bluez-device (address)
1157 "Return bluetooth device name from a given bluetooth device ADDRESS.
1158 ADDRESS can have the form \"xx:xx:xx:xx:xx:xx\" or \"[xx:xx:xx:xx:xx:xx]\"."
1159 (when (stringp address)
1160 (while (string-match "[][]" address)
1161 (setq address (replace-match "" t t address)))
1162 (let (result)
1163 (dolist (item (tramp-bluez-list-devices) result)
1164 (when (string-match address (cadr item))
1165 (setq result (car item)))))))
1168 ;; D-Bus GVFS functions.
1170 (defun tramp-gvfs-handler-askpassword (message user domain flags)
1171 "Implementation for the \"org.gtk.vfs.MountOperation.askPassword\" method."
1172 (let* ((filename
1173 (tramp-gvfs-file-name (dbus-event-path-name last-input-event)))
1174 (pw-prompt
1175 (format
1176 "%s for %s "
1177 (if (string-match "\\([pP]assword\\|[pP]assphrase\\)" message)
1178 (capitalize (match-string 1 message))
1179 "Password")
1180 filename))
1181 password)
1183 (condition-case nil
1184 (with-parsed-tramp-file-name filename l
1185 (when (and (zerop (length user))
1186 (not
1187 (zerop (logand flags tramp-gvfs-password-need-username))))
1188 (setq user (read-string "User name: ")))
1189 (when (and (zerop (length domain))
1190 (not
1191 (zerop (logand flags tramp-gvfs-password-need-domain))))
1192 (setq domain (read-string "Domain name: ")))
1194 (tramp-message l 6 "%S %S %S %d" message user domain flags)
1195 (unless (tramp-get-connection-property l "first-password-request" nil)
1196 (tramp-clear-passwd l))
1198 (setq tramp-current-method l-method
1199 tramp-current-user user
1200 tramp-current-host l-host
1201 password (tramp-read-passwd
1202 (tramp-get-connection-process l) pw-prompt))
1204 ;; Return result.
1205 (if (stringp password)
1206 (list
1207 t ;; password handled.
1208 nil ;; no abort of D-Bus.
1209 password
1210 (tramp-file-name-real-user l)
1211 domain
1212 nil ;; not anonymous.
1213 0) ;; no password save.
1214 ;; No password provided.
1215 (list nil t "" (tramp-file-name-real-user l) domain nil 0)))
1217 ;; When QUIT is raised, we shall return this information to D-Bus.
1218 (quit (list nil t "" "" "" nil 0)))))
1220 (defun tramp-gvfs-handler-askquestion (message choices)
1221 "Implementation for the \"org.gtk.vfs.MountOperation.askQuestion\" method."
1222 (save-window-excursion
1223 (let ((enable-recursive-minibuffers t)
1224 choice)
1226 (condition-case nil
1227 (with-parsed-tramp-file-name
1228 (tramp-gvfs-file-name (dbus-event-path-name last-input-event)) nil
1229 (tramp-message v 6 "%S %S" message choices)
1231 ;; In theory, there can be several choices. Until now,
1232 ;; there is only the question whether to accept an unknown
1233 ;; host signature.
1234 (with-temp-buffer
1235 ;; Preserve message for `progress-reporter'.
1236 (tramp-compat-with-temp-message ""
1237 (insert message)
1238 (pop-to-buffer (current-buffer))
1239 (setq choice (if (yes-or-no-p (concat (car choices) " ")) 0 1))
1240 (tramp-message v 6 "%d" choice)))
1242 ;; When the choice is "no", we set a dummy fuse-mountpoint
1243 ;; in order to leave the timeout.
1244 (unless (zerop choice)
1245 (tramp-set-file-property v "/" "fuse-mountpoint" "/"))
1247 (list
1248 t ;; handled.
1249 nil ;; no abort of D-Bus.
1250 choice))
1252 ;; When QUIT is raised, we shall return this information to D-Bus.
1253 (quit (list nil t 0))))))
1255 (defun tramp-gvfs-handler-mounted-unmounted (mount-info)
1256 "Signal handler for the \"org.gtk.vfs.MountTracker.mounted\" and
1257 \"org.gtk.vfs.MountTracker.unmounted\" signals."
1258 (ignore-errors
1259 (let ((signal-name (dbus-event-member-name last-input-event))
1260 (elt mount-info))
1261 ;; Jump over the first elements of the mount info. Since there
1262 ;; were changes in the entries, we cannot access dedicated
1263 ;; elements.
1264 (while (stringp (car elt)) (setq elt (cdr elt)))
1265 (let* ((fuse-mountpoint (tramp-gvfs-dbus-byte-array-to-string (cadr elt)))
1266 (mount-spec (caddr elt))
1267 (default-location (tramp-gvfs-dbus-byte-array-to-string
1268 (cadddr elt)))
1269 (method (tramp-gvfs-dbus-byte-array-to-string
1270 (cadr (assoc "type" (cadr mount-spec)))))
1271 (user (tramp-gvfs-dbus-byte-array-to-string
1272 (cadr (assoc "user" (cadr mount-spec)))))
1273 (domain (tramp-gvfs-dbus-byte-array-to-string
1274 (cadr (assoc "domain" (cadr mount-spec)))))
1275 (host (tramp-gvfs-dbus-byte-array-to-string
1276 (cadr (or (assoc "host" (cadr mount-spec))
1277 (assoc "server" (cadr mount-spec))))))
1278 (port (tramp-gvfs-dbus-byte-array-to-string
1279 (cadr (assoc "port" (cadr mount-spec)))))
1280 (ssl (tramp-gvfs-dbus-byte-array-to-string
1281 (cadr (assoc "ssl" (cadr mount-spec)))))
1282 (prefix (concat (tramp-gvfs-dbus-byte-array-to-string
1283 (car mount-spec))
1284 (tramp-gvfs-dbus-byte-array-to-string
1285 (cadr (assoc "share" (cadr mount-spec)))))))
1286 (when (string-match "^smb" method)
1287 (setq method "smb"))
1288 (when (string-equal "obex" method)
1289 (setq host (tramp-bluez-device host)))
1290 (when (and (string-equal "dav" method) (string-equal "true" ssl))
1291 (setq method "davs"))
1292 (unless (zerop (length domain))
1293 (setq user (concat user tramp-prefix-domain-format domain)))
1294 (unless (zerop (length port))
1295 (setq host (concat host tramp-prefix-port-format port)))
1296 (with-parsed-tramp-file-name
1297 (tramp-make-tramp-file-name method user host "") nil
1298 (tramp-message
1299 v 6 "%s %s"
1300 signal-name (tramp-gvfs-stringify-dbus-message mount-info))
1301 (tramp-set-file-property v "/" "list-mounts" 'undef)
1302 (if (string-equal (downcase signal-name) "unmounted")
1303 (tramp-set-file-property v "/" "fuse-mountpoint" nil)
1304 ;; Set prefix, mountpoint and location.
1305 (unless (string-equal prefix "/")
1306 (tramp-set-file-property v "/" "prefix" prefix))
1307 (tramp-set-file-property v "/" "fuse-mountpoint" fuse-mountpoint)
1308 (tramp-set-file-property
1309 v "/" "default-location" default-location)))))))
1311 (when tramp-gvfs-enabled
1312 (dbus-register-signal
1313 :session nil tramp-gvfs-path-mounttracker
1314 tramp-gvfs-interface-mounttracker "mounted"
1315 'tramp-gvfs-handler-mounted-unmounted)
1316 (dbus-register-signal
1317 :session nil tramp-gvfs-path-mounttracker
1318 tramp-gvfs-interface-mounttracker "Mounted"
1319 'tramp-gvfs-handler-mounted-unmounted)
1321 (dbus-register-signal
1322 :session nil tramp-gvfs-path-mounttracker
1323 tramp-gvfs-interface-mounttracker "unmounted"
1324 'tramp-gvfs-handler-mounted-unmounted)
1325 (dbus-register-signal
1326 :session nil tramp-gvfs-path-mounttracker
1327 tramp-gvfs-interface-mounttracker "Unmounted"
1328 'tramp-gvfs-handler-mounted-unmounted))
1330 (defun tramp-gvfs-connection-mounted-p (vec)
1331 "Check, whether the location is already mounted."
1333 (tramp-get-file-property vec "/" "fuse-mountpoint" nil)
1334 (catch 'mounted
1335 (dolist
1336 (elt
1337 (with-tramp-file-property vec "/" "list-mounts"
1338 (with-tramp-dbus-call-method vec t
1339 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1340 tramp-gvfs-interface-mounttracker tramp-gvfs-listmounts))
1341 nil)
1342 ;; Jump over the first elements of the mount info. Since there
1343 ;; were changes in the entries, we cannot access dedicated
1344 ;; elements.
1345 (while (stringp (car elt)) (setq elt (cdr elt)))
1346 (let* ((fuse-mountpoint (tramp-gvfs-dbus-byte-array-to-string
1347 (cadr elt)))
1348 (mount-spec (caddr elt))
1349 (default-location (tramp-gvfs-dbus-byte-array-to-string
1350 (cadddr elt)))
1351 (method (tramp-gvfs-dbus-byte-array-to-string
1352 (cadr (assoc "type" (cadr mount-spec)))))
1353 (user (tramp-gvfs-dbus-byte-array-to-string
1354 (cadr (assoc "user" (cadr mount-spec)))))
1355 (domain (tramp-gvfs-dbus-byte-array-to-string
1356 (cadr (assoc "domain" (cadr mount-spec)))))
1357 (host (tramp-gvfs-dbus-byte-array-to-string
1358 (cadr (or (assoc "host" (cadr mount-spec))
1359 (assoc "server" (cadr mount-spec))))))
1360 (port (tramp-gvfs-dbus-byte-array-to-string
1361 (cadr (assoc "port" (cadr mount-spec)))))
1362 (ssl (tramp-gvfs-dbus-byte-array-to-string
1363 (cadr (assoc "ssl" (cadr mount-spec)))))
1364 (prefix (concat (tramp-gvfs-dbus-byte-array-to-string
1365 (car mount-spec))
1366 (tramp-gvfs-dbus-byte-array-to-string
1367 (cadr (assoc "share" (cadr mount-spec)))))))
1368 (when (string-match "^smb" method)
1369 (setq method "smb"))
1370 (when (string-equal "obex" method)
1371 (setq host (tramp-bluez-device host)))
1372 (when (and (string-equal "dav" method) (string-equal "true" ssl))
1373 (setq method "davs"))
1374 (when (and (string-equal "synce" method) (zerop (length user)))
1375 (setq user (or (tramp-file-name-user vec) "")))
1376 (unless (zerop (length domain))
1377 (setq user (concat user tramp-prefix-domain-format domain)))
1378 (unless (zerop (length port))
1379 (setq host (concat host tramp-prefix-port-format port)))
1380 (when (and
1381 (string-equal method (tramp-file-name-method vec))
1382 (string-equal user (or (tramp-file-name-user vec) ""))
1383 (string-equal host (tramp-file-name-host vec))
1384 (string-match (concat "^" (regexp-quote prefix))
1385 (tramp-file-name-localname vec)))
1386 ;; Set prefix, mountpoint and location.
1387 (unless (string-equal prefix "/")
1388 (tramp-set-file-property vec "/" "prefix" prefix))
1389 (tramp-set-file-property vec "/" "fuse-mountpoint" fuse-mountpoint)
1390 (tramp-set-file-property vec "/" "default-location" default-location)
1391 (throw 'mounted t)))))))
1393 (defun tramp-gvfs-mount-spec-entry (key value)
1394 "Construct a mount-spec entry to be used in a mount_spec.
1395 It was \"a(say)\", but has changed to \"a{sv})\"."
1396 (if (string-match "^(aya{sv})" tramp-gvfs-mountlocation-signature)
1397 (list :dict-entry key
1398 (list :variant (tramp-gvfs-dbus-string-to-byte-array value)))
1399 (list :struct key (tramp-gvfs-dbus-string-to-byte-array value))))
1401 (defun tramp-gvfs-mount-spec (vec)
1402 "Return a mount-spec for \"org.gtk.vfs.MountTracker.mountLocation\"."
1403 (let* ((method (tramp-file-name-method vec))
1404 (user (tramp-file-name-real-user vec))
1405 (domain (tramp-file-name-domain vec))
1406 (host (tramp-file-name-real-host vec))
1407 (port (tramp-file-name-port vec))
1408 (localname (tramp-file-name-localname vec))
1409 (ssl (if (string-match "^davs" method) "true" "false"))
1410 (mount-spec
1411 `(:array
1412 ,@(cond
1413 ((string-equal "smb" method)
1414 (string-match "^/?\\([^/]+\\)" localname)
1415 (list (tramp-gvfs-mount-spec-entry "type" "smb-share")
1416 (tramp-gvfs-mount-spec-entry "server" host)
1417 (tramp-gvfs-mount-spec-entry
1418 "share" (match-string 1 localname))))
1419 ((string-equal "obex" method)
1420 (list (tramp-gvfs-mount-spec-entry "type" method)
1421 (tramp-gvfs-mount-spec-entry
1422 "host" (concat "[" (tramp-bluez-address host) "]"))))
1423 ((string-match "\\`dav" method)
1424 (list (tramp-gvfs-mount-spec-entry "type" "dav")
1425 (tramp-gvfs-mount-spec-entry "host" host)
1426 (tramp-gvfs-mount-spec-entry "ssl" ssl)))
1428 (list (tramp-gvfs-mount-spec-entry "type" method)
1429 (tramp-gvfs-mount-spec-entry "host" host))))
1430 ,@(when user
1431 (list (tramp-gvfs-mount-spec-entry "user" user)))
1432 ,@(when domain
1433 (list (tramp-gvfs-mount-spec-entry "domain" domain)))
1434 ,@(when port
1435 (list (tramp-gvfs-mount-spec-entry
1436 "port" (number-to-string port))))))
1437 (mount-pref
1438 (if (and (string-match "\\`dav" method)
1439 (string-match "^/?[^/]+" localname))
1440 (match-string 0 localname)
1441 "/")))
1443 ;; Return.
1444 `(:struct ,(tramp-gvfs-dbus-string-to-byte-array mount-pref) ,mount-spec)))
1447 ;; Connection functions.
1449 (defun tramp-gvfs-maybe-open-connection (vec)
1450 "Maybe open a connection VEC.
1451 Does not do anything if a connection is already open, but re-opens the
1452 connection if a previous connection has died for some reason."
1453 (tramp-check-proper-method-and-host vec)
1455 ;; We set the file name, in case there are incoming D-Bus signals or
1456 ;; D-Bus errors.
1457 (setq tramp-gvfs-dbus-event-vector vec)
1459 ;; For password handling, we need a process bound to the connection
1460 ;; buffer. Therefore, we create a dummy process. Maybe there is a
1461 ;; better solution?
1462 (unless (get-buffer-process (tramp-get-connection-buffer vec))
1463 (let ((p (make-network-process
1464 :name (tramp-buffer-name vec)
1465 :buffer (tramp-get-connection-buffer vec)
1466 :server t :host 'local :service t)))
1467 (tramp-compat-set-process-query-on-exit-flag p nil)))
1469 (unless (tramp-gvfs-connection-mounted-p vec)
1470 (let* ((method (tramp-file-name-method vec))
1471 (user (tramp-file-name-user vec))
1472 (host (tramp-file-name-host vec))
1473 (localname (tramp-file-name-localname vec))
1474 (object-path
1475 (tramp-gvfs-object-path
1476 (tramp-make-tramp-file-name method user host ""))))
1478 (when (and (string-equal method "smb")
1479 (string-equal localname "/"))
1480 (tramp-error vec 'file-error "Filename must contain a Windows share"))
1482 (with-tramp-progress-reporter
1483 vec 3
1484 (if (zerop (length user))
1485 (format "Opening connection for %s using %s" host method)
1486 (format "Opening connection for %s@%s using %s" user host method))
1488 ;; Enable `auth-source'.
1489 (tramp-set-connection-property vec "first-password-request" t)
1491 ;; There will be a callback of "askPassword" when a password is
1492 ;; needed.
1493 (dbus-register-method
1494 :session dbus-service-emacs object-path
1495 tramp-gvfs-interface-mountoperation "askPassword"
1496 'tramp-gvfs-handler-askpassword)
1497 (dbus-register-method
1498 :session dbus-service-emacs object-path
1499 tramp-gvfs-interface-mountoperation "AskPassword"
1500 'tramp-gvfs-handler-askpassword)
1502 ;; There could be a callback of "askQuestion" when adding fingerprint.
1503 (dbus-register-method
1504 :session dbus-service-emacs object-path
1505 tramp-gvfs-interface-mountoperation "askQuestion"
1506 'tramp-gvfs-handler-askquestion)
1507 (dbus-register-method
1508 :session dbus-service-emacs object-path
1509 tramp-gvfs-interface-mountoperation "AskQuestion"
1510 'tramp-gvfs-handler-askquestion)
1512 ;; The call must be asynchronously, because of the "askPassword"
1513 ;; or "askQuestion"callbacks.
1514 (if (string-match "(so)$" tramp-gvfs-mountlocation-signature)
1515 (with-tramp-dbus-call-method vec nil
1516 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1517 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation
1518 (tramp-gvfs-mount-spec vec)
1519 `(:struct :string ,(dbus-get-unique-name :session)
1520 :object-path ,object-path))
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 :string (dbus-get-unique-name :session) :object-path object-path))
1527 ;; We must wait, until the mount is applied. This will be
1528 ;; indicated by the "mounted" signal, i.e. the "fuse-mountpoint"
1529 ;; file property.
1530 (with-timeout
1531 ((or (tramp-get-method-parameter method 'tramp-connection-timeout)
1532 tramp-connection-timeout)
1533 (if (zerop (length (tramp-file-name-user vec)))
1534 (tramp-error
1535 vec 'file-error
1536 "Timeout reached mounting %s using %s" host method)
1537 (tramp-error
1538 vec 'file-error
1539 "Timeout reached mounting %s@%s using %s" user host method)))
1540 (while (not (tramp-get-file-property vec "/" "fuse-mountpoint" nil))
1541 (read-event nil nil 0.1)))
1543 ;; If `tramp-gvfs-handler-askquestion' has returned "No", it
1544 ;; is marked with the fuse-mountpoint "/". We shall react.
1545 (when (string-equal
1546 (tramp-get-file-property vec "/" "fuse-mountpoint" "") "/")
1547 (tramp-error vec 'file-error "FUSE mount denied")))))
1549 ;; In `tramp-check-cached-permissions', the connection properties
1550 ;; {uig,gid}-{integer,string} are used. We set them to their local
1551 ;; counterparts.
1552 (with-tramp-connection-property
1553 vec "uid-integer" (tramp-get-local-uid 'integer))
1554 (with-tramp-connection-property
1555 vec "gid-integer" (tramp-get-local-gid 'integer))
1556 (with-tramp-connection-property
1557 vec "uid-string" (tramp-get-local-uid 'string))
1558 (with-tramp-connection-property
1559 vec "gid-string" (tramp-get-local-gid 'string)))
1561 (defun tramp-gvfs-send-command (vec command &rest args)
1562 "Send the COMMAND with its ARGS to connection VEC.
1563 COMMAND is usually a command from the gvfs-* utilities.
1564 `call-process' is applied, and it returns `t' if the return code is zero."
1565 (with-current-buffer (tramp-get-connection-buffer vec)
1566 (tramp-gvfs-maybe-open-connection vec)
1567 (erase-buffer)
1568 (zerop (apply 'tramp-call-process vec command nil t nil args))))
1571 ;; D-Bus BLUEZ functions.
1573 (defun tramp-bluez-list-devices ()
1574 "Return all discovered bluetooth devices as list.
1575 Every entry is a list (NAME ADDRESS).
1577 If `tramp-bluez-discover-devices-timeout' is an integer, and the last
1578 discovery happened more time before indicated there, a rescan will be
1579 started, which lasts some ten seconds. Otherwise, cached results will
1580 be used."
1581 ;; Reset the scanned devices list if time has passed.
1582 (and (integerp tramp-bluez-discover-devices-timeout)
1583 (integerp tramp-bluez-discovery)
1584 (> (tramp-time-diff (current-time) tramp-bluez-discovery)
1585 tramp-bluez-discover-devices-timeout)
1586 (setq tramp-bluez-devices nil))
1588 ;; Rescan if needed.
1589 (unless tramp-bluez-devices
1590 (let ((object-path
1591 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1592 :system tramp-bluez-service "/"
1593 tramp-bluez-interface-manager "DefaultAdapter")))
1594 (setq tramp-bluez-devices nil
1595 tramp-bluez-discovery t)
1596 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector nil
1597 :system tramp-bluez-service object-path
1598 tramp-bluez-interface-adapter "StartDiscovery")
1599 (while tramp-bluez-discovery
1600 (read-event nil nil 0.1))))
1601 (setq tramp-bluez-discovery (current-time))
1602 (tramp-message tramp-gvfs-dbus-event-vector 10 "%s" tramp-bluez-devices)
1603 tramp-bluez-devices)
1605 (defun tramp-bluez-property-changed (property value)
1606 "Signal handler for the \"org.bluez.Adapter.PropertyChanged\" signal."
1607 (tramp-message tramp-gvfs-dbus-event-vector 6 "%s %s" property value)
1608 (cond
1609 ((string-equal property "Discovering")
1610 (unless (car value)
1611 ;; "Discovering" FALSE means discovery run has been completed.
1612 ;; We stop it, because we don't need another run.
1613 (setq tramp-bluez-discovery nil)
1614 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1615 :system tramp-bluez-service (dbus-event-path-name last-input-event)
1616 tramp-bluez-interface-adapter "StopDiscovery")))))
1618 (when tramp-gvfs-enabled
1619 (dbus-register-signal
1620 :system nil nil tramp-bluez-interface-adapter "PropertyChanged"
1621 'tramp-bluez-property-changed))
1623 (defun tramp-bluez-device-found (device args)
1624 "Signal handler for the \"org.bluez.Adapter.DeviceFound\" signal."
1625 (tramp-message tramp-gvfs-dbus-event-vector 6 "%s %s" device args)
1626 (let ((alias (car (cadr (assoc "Alias" args))))
1627 (address (car (cadr (assoc "Address" args)))))
1628 ;; Maybe we shall check the device class for being a proper
1629 ;; device, and call also SDP in order to find the obex service.
1630 (add-to-list 'tramp-bluez-devices (list alias address))))
1632 (when tramp-gvfs-enabled
1633 (dbus-register-signal
1634 :system nil nil tramp-bluez-interface-adapter "DeviceFound"
1635 'tramp-bluez-device-found))
1637 (defun tramp-bluez-parse-device-names (_ignore)
1638 "Return a list of (nil host) tuples allowed to access."
1639 (mapcar
1640 (lambda (x) (list nil (car x)))
1641 (tramp-bluez-list-devices)))
1643 ;; Add completion function for OBEX method.
1644 (when (and tramp-gvfs-enabled
1645 (member tramp-bluez-service (dbus-list-known-names :system)))
1646 (tramp-set-completion-function
1647 "obex" '((tramp-bluez-parse-device-names ""))))
1650 ;; D-Bus zeroconf functions.
1652 (defun tramp-zeroconf-parse-workstation-device-names (_ignore)
1653 "Return a list of (user host) tuples allowed to access."
1654 (mapcar
1655 (lambda (x)
1656 (list nil (zeroconf-service-host x)))
1657 (zeroconf-list-services "_workstation._tcp")))
1659 (defun tramp-zeroconf-parse-webdav-device-names (_ignore)
1660 "Return a list of (user host) tuples allowed to access."
1661 (mapcar
1662 (lambda (x)
1663 (let ((host (zeroconf-service-host x))
1664 (port (zeroconf-service-port x))
1665 (text (zeroconf-service-txt x))
1666 user)
1667 (when port
1668 (setq host (format "%s%s%d" host tramp-prefix-port-regexp port)))
1669 ;; A user is marked in a TXT field like "u=guest".
1670 (while text
1671 (when (string-match "u=\\(.+\\)$" (car text))
1672 (setq user (match-string 1 (car text))))
1673 (setq text (cdr text)))
1674 (list user host)))
1675 (zeroconf-list-services "_webdav._tcp")))
1677 ;; Add completion function for SFTP, DAV and DAVS methods.
1678 (when (and tramp-gvfs-enabled
1679 (member zeroconf-service-avahi (dbus-list-known-names :system)))
1680 (zeroconf-init tramp-gvfs-zeroconf-domain)
1681 (tramp-set-completion-function
1682 "sftp" '((tramp-zeroconf-parse-workstation-device-names "")))
1683 (tramp-set-completion-function
1684 "dav" '((tramp-zeroconf-parse-webdav-device-names "")))
1685 (tramp-set-completion-function
1686 "davs" '((tramp-zeroconf-parse-webdav-device-names ""))))
1689 ;; D-Bus SYNCE functions.
1691 (defun tramp-synce-list-devices ()
1692 "Return all discovered synce devices as list.
1693 They are retrieved from the hal daemon."
1694 (let (tramp-synce-devices)
1695 (dolist (device
1696 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1697 :system tramp-hal-service tramp-hal-path-manager
1698 tramp-hal-interface-manager "GetAllDevices"))
1699 (when (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1700 :system tramp-hal-service device tramp-hal-interface-device
1701 "PropertyExists" "sync.plugin")
1702 (let ((prop
1703 (with-tramp-dbus-call-method
1704 tramp-gvfs-dbus-event-vector t
1705 :system tramp-hal-service device tramp-hal-interface-device
1706 "GetPropertyString" "pda.pocketpc.name")))
1707 (unless (member prop tramp-synce-devices)
1708 (push prop tramp-synce-devices)))))
1709 (tramp-message tramp-gvfs-dbus-event-vector 10 "%s" tramp-synce-devices)
1710 tramp-synce-devices))
1712 (defun tramp-synce-parse-device-names (_ignore)
1713 "Return a list of (nil host) tuples allowed to access."
1714 (mapcar
1715 (lambda (x) (list nil x))
1716 (tramp-synce-list-devices)))
1718 ;; Add completion function for SYNCE method.
1719 (when tramp-gvfs-enabled
1720 (tramp-set-completion-function
1721 "synce" '((tramp-synce-parse-device-names ""))))
1723 (add-hook 'tramp-unload-hook
1724 (lambda ()
1725 (unload-feature 'tramp-gvfs 'force)))
1727 (provide 'tramp-gvfs)
1729 ;;; TODO:
1731 ;; * Host name completion via smb-server or smb-network.
1732 ;; * Check how two shares of the same SMB server can be mounted in
1733 ;; parallel.
1734 ;; * Apply SDP on bluetooth devices, in order to filter out obex
1735 ;; capability.
1736 ;; * Implement obex for other serial communication but bluetooth.
1738 ;;; tramp-gvfs.el ends here