(gnus-blocked-images): Clarify privacy implications
[emacs.git] / lisp / net / tramp-gvfs.el
bloba9a1a6085a4c62c1bcc0e147a661e8f9d5ff71e2
1 ;;; tramp-gvfs.el --- Tramp access functions for GVFS daemon -*- lexical-binding:t -*-
3 ;; Copyright (C) 2009-2018 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 <https://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 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 user option `tramp-gvfs-methods' contains the list of supported
51 ;; connection methods. Per default, these are "afp", "dav", "davs",
52 ;; "gdrive", "obex", "owncloud", "sftp" and "synce". Note that with
53 ;; "obex" it might be necessary to pair with the other bluetooth
54 ;; device, if it hasn't been done already. There might be also some
55 ;; few seconds delay in discovering available bluetooth devices.
57 ;; "gdrive" and "owncloud" connection methods require a respective
58 ;; account in GNOME Online Accounts, with enabled "Files" service.
60 ;; Other possible connection methods are "ftp", "http", "https" and
61 ;; "smb". When one of these methods is added to the list, the remote
62 ;; access for that method is performed via GVFS instead of the native
63 ;; Tramp implementation. However, this is not recommended. These
64 ;; methods are listed here for the benefit of file archives, see
65 ;; tramp-archive.el.
67 ;; GVFS offers even more connection methods. The complete list of
68 ;; connection methods of the actual GVFS implementation can be
69 ;; retrieved by:
71 ;; (message
72 ;; "%s"
73 ;; (mapcar
74 ;; 'car
75 ;; (dbus-call-method
76 ;; :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
77 ;; tramp-gvfs-interface-mounttracker "ListMountableInfo")))
79 ;; See also /usr/share/gvfs/mounts
81 ;; Note that all other connection methods are not tested, beside the
82 ;; ones offered for customization in `tramp-gvfs-methods'. If you
83 ;; request an additional connection method to be supported, please
84 ;; drop me a note.
86 ;; For hostname completion, information is retrieved either from the
87 ;; bluez daemon (for the "obex" method), the hal daemon (for the
88 ;; "synce" method), or from the zeroconf daemon (for the "afp", "dav",
89 ;; "davs", and "sftp" methods). The zeroconf daemon is pre-configured
90 ;; to discover services in the "local" domain. If another domain
91 ;; shall be used for discovering services, the user option
92 ;; `tramp-gvfs-zeroconf-domain' can be set accordingly.
94 ;; Restrictions:
96 ;; * The current GVFS implementation does not allow writing on the
97 ;; remote bluetooth device via OBEX.
99 ;; * Two shares of the same SMB server cannot be mounted in parallel.
101 ;;; Code:
103 ;; D-Bus support in the Emacs core can be disabled with configuration
104 ;; option "--without-dbus". Declare used subroutines and variables.
105 (declare-function dbus-get-unique-name "dbusbind.c")
107 (eval-when-compile (require 'cl-lib))
108 (require 'tramp)
110 (require 'dbus)
111 (require 'url-parse)
112 (require 'url-util)
113 (require 'zeroconf)
115 ;; Pacify byte-compiler.
116 (eval-when-compile
117 (require 'custom))
119 ;; We don't call `dbus-ping', because this would load dbus.el.
120 (defconst tramp-gvfs-enabled
121 (ignore-errors
122 (and (featurep 'dbusbind)
123 (tramp-compat-funcall 'dbus-get-unique-name :system)
124 (tramp-compat-funcall 'dbus-get-unique-name :session)
125 (or (tramp-compat-process-running-p "gvfs-fuse-daemon")
126 (tramp-compat-process-running-p "gvfsd-fuse"))))
127 "Non-nil when GVFS is available.")
129 ;;;###tramp-autoload
130 (defcustom tramp-gvfs-methods
131 '("afp" "dav" "davs" "gdrive" "obex" "owncloud" "sftp" "synce")
132 "List of methods for remote files, accessed with GVFS."
133 :group 'tramp
134 :version "26.1"
135 :type '(repeat (choice (const "afp")
136 (const "dav")
137 (const "davs")
138 (const "ftp")
139 (const "gdrive")
140 (const "http")
141 (const "https")
142 (const "obex")
143 (const "owncloud")
144 (const "sftp")
145 (const "smb")
146 (const "synce")))
147 :require 'tramp)
149 (defconst tramp-goa-methods '("gdrive" "owncloud")
150 "List of methods which require registration at GNOME Online Accounts.")
152 ;; Remove GNOME Online Accounts methods if not supported.
153 (unless (and tramp-gvfs-enabled
154 (member tramp-goa-service (dbus-list-known-names :session)))
155 (dolist (method tramp-goa-methods)
156 (setq tramp-gvfs-methods (delete method tramp-gvfs-methods))))
158 ;; Add defaults for `tramp-default-user-alist' and `tramp-default-host-alist'.
159 ;;;###tramp-autoload
160 (when (string-match "\\(.+\\)@\\(\\(?:gmail\\|googlemail\\)\\.com\\)"
161 user-mail-address)
162 (add-to-list 'tramp-default-user-alist
163 `("\\`gdrive\\'" nil ,(match-string 1 user-mail-address)))
164 (add-to-list 'tramp-default-host-alist
165 '("\\`gdrive\\'" nil ,(match-string 2 user-mail-address))))
166 ;;;###tramp-autoload
167 (add-to-list 'tramp-default-user-alist '("\\`synce\\'" nil nil))
169 ;;;###tramp-autoload
170 (defcustom tramp-gvfs-zeroconf-domain "local"
171 "Zeroconf domain to be used for discovering services, like host names."
172 :group 'tramp
173 :version "23.2"
174 :type 'string
175 :require 'tramp)
177 ;; Add the methods to `tramp-methods', in order to allow minibuffer
178 ;; completion.
179 ;;;###tramp-autoload
180 (when (featurep 'dbusbind)
181 (dolist (elt tramp-gvfs-methods)
182 (unless (assoc elt tramp-methods)
183 (add-to-list 'tramp-methods (cons elt nil)))))
185 (defconst tramp-gvfs-path-tramp (concat dbus-path-emacs "/Tramp")
186 "The preceding object path for own objects.")
188 (defconst tramp-gvfs-service-daemon "org.gtk.vfs.Daemon"
189 "The well known name of the GVFS daemon.")
191 (defconst tramp-gvfs-path-mounttracker "/org/gtk/vfs/mounttracker"
192 "The object path of the GVFS daemon.")
194 (defconst tramp-gvfs-interface-mounttracker "org.gtk.vfs.MountTracker"
195 "The mount tracking interface in the GVFS daemon.")
197 ;; Introspection data exist since GVFS 1.14. If there are no such
198 ;; data, we expect an earlier interface.
199 (defconst tramp-gvfs-methods-mounttracker
200 (and tramp-gvfs-enabled
201 (dbus-introspect-get-method-names
202 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
203 tramp-gvfs-interface-mounttracker))
204 "The list of supported methods of the mount tracking interface.")
206 (defconst tramp-gvfs-listmounts
207 (if (member "ListMounts" tramp-gvfs-methods-mounttracker)
208 "ListMounts"
209 "listMounts")
210 "The name of the \"listMounts\" method.
211 It has been changed in GVFS 1.14.")
213 (defconst tramp-gvfs-mountlocation
214 (if (member "MountLocation" tramp-gvfs-methods-mounttracker)
215 "MountLocation"
216 "mountLocation")
217 "The name of the \"mountLocation\" method.
218 It has been changed in GVFS 1.14.")
220 (defconst tramp-gvfs-mountlocation-signature
221 (and tramp-gvfs-enabled
222 (dbus-introspect-get-signature
223 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
224 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation))
225 "The D-Bus signature of the \"mountLocation\" method.
226 It has been changed in GVFS 1.14.")
228 ;; <interface name='org.gtk.vfs.MountTracker'>
229 ;; <method name='listMounts'>
230 ;; <arg name='mount_info_list'
231 ;; type='a{sosssssbay{aya{say}}ay}'
232 ;; direction='out'/>
233 ;; </method>
234 ;; <method name='mountLocation'>
235 ;; <arg name='mount_spec' type='{aya{say}}' direction='in'/>
236 ;; <arg name='dbus_id' type='s' direction='in'/>
237 ;; <arg name='object_path' type='o' direction='in'/>
238 ;; </method>
239 ;; <signal name='mounted'>
240 ;; <arg name='mount_info'
241 ;; type='{sosssssbay{aya{say}}ay}'/>
242 ;; </signal>
243 ;; <signal name='unmounted'>
244 ;; <arg name='mount_info'
245 ;; type='{sosssssbay{aya{say}}ay}'/>
246 ;; </signal>
247 ;; </interface>
249 ;; STRUCT mount_info
250 ;; STRING dbus_id
251 ;; OBJECT_PATH object_path
252 ;; STRING display_name
253 ;; STRING stable_name
254 ;; STRING x_content_types Since GVFS 1.0 only !!!
255 ;; STRING icon
256 ;; STRING preferred_filename_encoding
257 ;; BOOLEAN user_visible
258 ;; ARRAY BYTE fuse_mountpoint
259 ;; STRUCT mount_spec
260 ;; ARRAY BYTE mount_prefix
261 ;; ARRAY
262 ;; STRUCT mount_spec_item
263 ;; STRING key (type, user, domain, host, server,
264 ;; share, volume, port, ssl)
265 ;; ARRAY BYTE value
266 ;; ARRAY BYTE default_location Since GVFS 1.5 only !!!
268 (defconst tramp-gvfs-interface-mountoperation "org.gtk.vfs.MountOperation"
269 "Used by the dbus-proxying implementation of GMountOperation.")
271 ;; <interface name='org.gtk.vfs.MountOperation'>
272 ;; <method name='askPassword'>
273 ;; <arg name='message' type='s' direction='in'/>
274 ;; <arg name='default_user' type='s' direction='in'/>
275 ;; <arg name='default_domain' type='s' direction='in'/>
276 ;; <arg name='flags' type='u' direction='in'/>
277 ;; <arg name='handled' type='b' direction='out'/>
278 ;; <arg name='aborted' type='b' direction='out'/>
279 ;; <arg name='password' type='s' direction='out'/>
280 ;; <arg name='username' type='s' direction='out'/>
281 ;; <arg name='domain' type='s' direction='out'/>
282 ;; <arg name='anonymous' type='b' direction='out'/>
283 ;; <arg name='password_save' type='u' direction='out'/>
284 ;; </method>
285 ;; <method name='askQuestion'>
286 ;; <arg name='message' type='s' direction='in'/>
287 ;; <arg name='choices' type='as' direction='in'/>
288 ;; <arg name='handled' type='b' direction='out'/>
289 ;; <arg name='aborted' type='b' direction='out'/>
290 ;; <arg name='choice' type='u' direction='out'/>
291 ;; </method>
292 ;; </interface>
294 ;; The following flags are used in "askPassword". They are defined in
295 ;; /usr/include/glib-2.0/gio/gioenums.h.
297 (defconst tramp-gvfs-password-need-password 1
298 "Operation requires a password.")
300 (defconst tramp-gvfs-password-need-username 2
301 "Operation requires a username.")
303 (defconst tramp-gvfs-password-need-domain 4
304 "Operation requires a domain.")
306 (defconst tramp-gvfs-password-saving-supported 8
307 "Operation supports saving settings.")
309 (defconst tramp-gvfs-password-anonymous-supported 16
310 "Operation supports anonymous users.")
312 ;; For the time being, we just need org.goa.Account and org.goa.Files
313 ;; interfaces. We document the other ones, just in case.
315 ;;;###tramp-autoload
316 (defconst tramp-goa-service "org.gnome.OnlineAccounts"
317 "The well known name of the GNOME Online Accounts service.")
319 (defconst tramp-goa-path "/org/gnome/OnlineAccounts"
320 "The object path of the GNOME Online Accounts.")
322 (defconst tramp-goa-path-accounts (concat tramp-goa-path "/Accounts")
323 "The object path of the GNOME Online Accounts accounts.")
325 (defconst tramp-goa-interface-documents "org.gnome.OnlineAccounts.Documents"
326 "The documents interface of the GNOME Online Accounts.")
328 ;; <interface name='org.gnome.OnlineAccounts.Documents'>
329 ;; </interface>
331 (defconst tramp-goa-interface-printers "org.gnome.OnlineAccounts.Printers"
332 "The printers interface of the GNOME Online Accounts.")
334 ;; <interface name='org.gnome.OnlineAccounts.Printers'>
335 ;; </interface>
337 (defconst tramp-goa-interface-files "org.gnome.OnlineAccounts.Files"
338 "The files interface of the GNOME Online Accounts.")
340 ;; <interface name='org.gnome.OnlineAccounts.Files'>
341 ;; <property type='b' name='AcceptSslErrors' access='read'/>
342 ;; <property type='s' name='Uri' access='read'/>
343 ;; </interface>
345 (defconst tramp-goa-interface-contacts "org.gnome.OnlineAccounts.Contacts"
346 "The contacts interface of the GNOME Online Accounts.")
348 ;; <interface name='org.gnome.OnlineAccounts.Contacts'>
349 ;; <property type='b' name='AcceptSslErrors' access='read'/>
350 ;; <property type='s' name='Uri' access='read'/>
351 ;; </interface>
353 (defconst tramp-goa-interface-calendar "org.gnome.OnlineAccounts.Calendar"
354 "The calendar interface of the GNOME Online Accounts.")
356 ;; <interface name='org.gnome.OnlineAccounts.Calendar'>
357 ;; <property type='b' name='AcceptSslErrors' access='read'/>
358 ;; <property type='s' name='Uri' access='read'/>
359 ;; </interface>
361 (defconst tramp-goa-interface-oauth2based "org.gnome.OnlineAccounts.OAuth2Based"
362 "The oauth2based interface of the GNOME Online Accounts.")
364 ;; <interface name='org.gnome.OnlineAccounts.OAuth2Based'>
365 ;; <method name='GetAccessToken'>
366 ;; <arg type='s' name='access_token' direction='out'/>
367 ;; <arg type='i' name='expires_in' direction='out'/>
368 ;; </method>
369 ;; <property type='s' name='ClientId' access='read'/>
370 ;; <property type='s' name='ClientSecret' access='read'/>
371 ;; </interface>
373 (defconst tramp-goa-interface-account "org.gnome.OnlineAccounts.Account"
374 "The account interface of the GNOME Online Accounts.")
376 ;; <interface name='org.gnome.OnlineAccounts.Account'>
377 ;; <method name='Remove'/>
378 ;; <method name='EnsureCredentials'>
379 ;; <arg type='i' name='expires_in' direction='out'/>
380 ;; </method>
381 ;; <property type='s' name='ProviderType' access='read'/>
382 ;; <property type='s' name='ProviderName' access='read'/>
383 ;; <property type='s' name='ProviderIcon' access='read'/>
384 ;; <property type='s' name='Id' access='read'/>
385 ;; <property type='b' name='IsLocked' access='read'/>
386 ;; <property type='b' name='IsTemporary' access='readwrite'/>
387 ;; <property type='b' name='AttentionNeeded' access='read'/>
388 ;; <property type='s' name='Identity' access='read'/>
389 ;; <property type='s' name='PresentationIdentity' access='read'/>
390 ;; <property type='b' name='MailDisabled' access='readwrite'/>
391 ;; <property type='b' name='CalendarDisabled' access='readwrite'/>
392 ;; <property type='b' name='ContactsDisabled' access='readwrite'/>
393 ;; <property type='b' name='ChatDisabled' access='readwrite'/>
394 ;; <property type='b' name='DocumentsDisabled' access='readwrite'/>
395 ;; <property type='b' name='MapsDisabled' access='readwrite'/>
396 ;; <property type='b' name='MusicDisabled' access='readwrite'/>
397 ;; <property type='b' name='PrintersDisabled' access='readwrite'/>
398 ;; <property type='b' name='PhotosDisabled' access='readwrite'/>
399 ;; <property type='b' name='FilesDisabled' access='readwrite'/>
400 ;; <property type='b' name='TicketingDisabled' access='readwrite'/>
401 ;; <property type='b' name='TodoDisabled' access='readwrite'/>
402 ;; <property type='b' name='ReadLaterDisabled' access='readwrite'/>
403 ;; </interface>
405 (defconst tramp-goa-identity-regexp
406 (concat "^" "\\(" tramp-user-regexp "\\)?"
407 "@" "\\(" tramp-host-regexp "\\)?"
408 "\\(?:" ":""\\(" tramp-port-regexp "\\)" "\\)?")
409 "Regexp matching GNOME Online Accounts \"PresentationIdentity\" property.")
411 (defconst tramp-goa-interface-mail "org.gnome.OnlineAccounts.Mail"
412 "The mail interface of the GNOME Online Accounts.")
414 ;; <interface name='org.gnome.OnlineAccounts.Mail'>
415 ;; <property type='s' name='EmailAddress' access='read'/>
416 ;; <property type='s' name='Name' access='read'/>
417 ;; <property type='b' name='ImapSupported' access='read'/>
418 ;; <property type='b' name='ImapAcceptSslErrors' access='read'/>
419 ;; <property type='s' name='ImapHost' access='read'/>
420 ;; <property type='b' name='ImapUseSsl' access='read'/>
421 ;; <property type='b' name='ImapUseTls' access='read'/>
422 ;; <property type='s' name='ImapUserName' access='read'/>
423 ;; <property type='b' name='SmtpSupported' access='read'/>
424 ;; <property type='b' name='SmtpAcceptSslErrors' access='read'/>
425 ;; <property type='s' name='SmtpHost' access='read'/>
426 ;; <property type='b' name='SmtpUseAuth' access='read'/>
427 ;; <property type='b' name='SmtpAuthLogin' access='read'/>
428 ;; <property type='b' name='SmtpAuthPlain' access='read'/>
429 ;; <property type='b' name='SmtpAuthXoauth2' access='read'/>
430 ;; <property type='b' name='SmtpUseSsl' access='read'/>
431 ;; <property type='b' name='SmtpUseTls' access='read'/>
432 ;; <property type='s' name='SmtpUserName' access='read'/>
433 ;; </interface>
435 (defconst tramp-goa-interface-chat "org.gnome.OnlineAccounts.Chat"
436 "The chat interface of the GNOME Online Accounts.")
438 ;; <interface name='org.gnome.OnlineAccounts.Chat'>
439 ;; </interface>
441 (defconst tramp-goa-interface-photos "org.gnome.OnlineAccounts.Photos"
442 "The photos interface of the GNOME Online Accounts.")
444 ;; <interface name='org.gnome.OnlineAccounts.Photos'>
445 ;; </interface>
447 (defconst tramp-goa-path-manager (concat tramp-goa-path "/Manager")
448 "The object path of the GNOME Online Accounts manager.")
450 (defconst tramp-goa-interface-documents "org.gnome.OnlineAccounts.Manager"
451 "The manager interface of the GNOME Online Accounts.")
453 ;; <interface name='org.gnome.OnlineAccounts.Manager'>
454 ;; <method name='AddAccount'>
455 ;; <arg type='s' name='provider' direction='in'/>
456 ;; <arg type='s' name='identity' direction='in'/>
457 ;; <arg type='s' name='presentation_identity' direction='in'/>
458 ;; <arg type='a{sv}' name='credentials' direction='in'/>
459 ;; <arg type='a{ss}' name='details' direction='in'/>
460 ;; <arg type='o' name='account_object_path' direction='out'/>
461 ;; </method>
462 ;; </interface>
464 ;; The basic structure for GNOME Online Accounts. We use a list :type,
465 ;; in order to be compatible with Emacs 24 and 25.
466 (cl-defstruct (tramp-goa-name (:type list) :named) method user host port)
468 (defconst tramp-bluez-service "org.bluez"
469 "The well known name of the BLUEZ service.")
471 (defconst tramp-bluez-interface-manager "org.bluez.Manager"
472 "The manager interface of the BLUEZ daemon.")
474 ;; <interface name='org.bluez.Manager'>
475 ;; <method name='DefaultAdapter'>
476 ;; <arg type='o' direction='out'/>
477 ;; </method>
478 ;; <method name='FindAdapter'>
479 ;; <arg type='s' direction='in'/>
480 ;; <arg type='o' direction='out'/>
481 ;; </method>
482 ;; <method name='ListAdapters'>
483 ;; <arg type='ao' direction='out'/>
484 ;; </method>
485 ;; <signal name='AdapterAdded'>
486 ;; <arg type='o'/>
487 ;; </signal>
488 ;; <signal name='AdapterRemoved'>
489 ;; <arg type='o'/>
490 ;; </signal>
491 ;; <signal name='DefaultAdapterChanged'>
492 ;; <arg type='o'/>
493 ;; </signal>
494 ;; </interface>
496 (defconst tramp-bluez-interface-adapter "org.bluez.Adapter"
497 "The adapter interface of the BLUEZ daemon.")
499 ;; <interface name='org.bluez.Adapter'>
500 ;; <method name='GetProperties'>
501 ;; <arg type='a{sv}' direction='out'/>
502 ;; </method>
503 ;; <method name='SetProperty'>
504 ;; <arg type='s' direction='in'/>
505 ;; <arg type='v' direction='in'/>
506 ;; </method>
507 ;; <method name='RequestMode'>
508 ;; <arg type='s' direction='in'/>
509 ;; </method>
510 ;; <method name='ReleaseMode'/>
511 ;; <method name='RequestSession'/>
512 ;; <method name='ReleaseSession'/>
513 ;; <method name='StartDiscovery'/>
514 ;; <method name='StopDiscovery'/>
515 ;; <method name='ListDevices'>
516 ;; <arg type='ao' direction='out'/>
517 ;; </method>
518 ;; <method name='CreateDevice'>
519 ;; <arg type='s' direction='in'/>
520 ;; <arg type='o' direction='out'/>
521 ;; </method>
522 ;; <method name='CreatePairedDevice'>
523 ;; <arg type='s' direction='in'/>
524 ;; <arg type='o' direction='in'/>
525 ;; <arg type='s' direction='in'/>
526 ;; <arg type='o' direction='out'/>
527 ;; </method>
528 ;; <method name='CancelDeviceCreation'>
529 ;; <arg type='s' direction='in'/>
530 ;; </method>
531 ;; <method name='RemoveDevice'>
532 ;; <arg type='o' direction='in'/>
533 ;; </method>
534 ;; <method name='FindDevice'>
535 ;; <arg type='s' direction='in'/>
536 ;; <arg type='o' direction='out'/>
537 ;; </method>
538 ;; <method name='RegisterAgent'>
539 ;; <arg type='o' direction='in'/>
540 ;; <arg type='s' direction='in'/>
541 ;; </method>
542 ;; <method name='UnregisterAgent'>
543 ;; <arg type='o' direction='in'/>
544 ;; </method>
545 ;; <signal name='DeviceCreated'>
546 ;; <arg type='o'/>
547 ;; </signal>
548 ;; <signal name='DeviceRemoved'>
549 ;; <arg type='o'/>
550 ;; </signal>
551 ;; <signal name='DeviceFound'>
552 ;; <arg type='s'/>
553 ;; <arg type='a{sv}'/>
554 ;; </signal>
555 ;; <signal name='PropertyChanged'>
556 ;; <arg type='s'/>
557 ;; <arg type='v'/>
558 ;; </signal>
559 ;; <signal name='DeviceDisappeared'>
560 ;; <arg type='s'/>
561 ;; </signal>
562 ;; </interface>
564 ;;;###tramp-autoload
565 (defcustom tramp-bluez-discover-devices-timeout 60
566 "Defines seconds since last bluetooth device discovery before rescanning.
567 A value of 0 would require an immediate discovery during hostname
568 completion, nil means to use always cached values for discovered
569 devices."
570 :group 'tramp
571 :version "23.2"
572 :type '(choice (const nil) integer)
573 :require 'tramp)
575 (defvar tramp-bluez-discovery nil
576 "Indicator for a running bluetooth device discovery.
577 It keeps the timestamp of last discovery.")
579 (defvar tramp-bluez-devices nil
580 "Alist of detected bluetooth devices.
581 Every entry is a list (NAME ADDRESS).")
583 (defconst tramp-hal-service "org.freedesktop.Hal"
584 "The well known name of the HAL service.")
586 (defconst tramp-hal-path-manager "/org/freedesktop/Hal/Manager"
587 "The object path of the HAL daemon manager.")
589 (defconst tramp-hal-interface-manager "org.freedesktop.Hal.Manager"
590 "The manager interface of the HAL daemon.")
592 (defconst tramp-hal-interface-device "org.freedesktop.Hal.Device"
593 "The device interface of the HAL daemon.")
595 ;; "gvfs-<command>" utilities have been deprecated in GVFS 1.31.1. We
596 ;; must use "gio <command>" tool instead.
597 (defconst tramp-gvfs-gio-mapping
598 '(("gvfs-copy" . "copy")
599 ("gvfs-info" . "info")
600 ("gvfs-ls" . "list")
601 ("gvfs-mkdir" . "mkdir")
602 ("gvfs-monitor-file" . "monitor")
603 ("gvfs-mount" . "mount")
604 ("gvfs-move" . "move")
605 ("gvfs-rm" . "remove")
606 ("gvfs-trash" . "trash"))
607 "List of cons cells, mapping \"gvfs-<command>\" to \"gio <command>\".")
609 ;; <http://www.pygtk.org/docs/pygobject/gio-constants.html>
610 (defconst tramp-gvfs-file-attributes
611 '("name"
612 "type"
613 "standard::display-name"
614 "standard::symlink-target"
615 "unix::nlink"
616 "unix::uid"
617 "owner::user"
618 "unix::gid"
619 "owner::group"
620 "time::access"
621 "time::modified"
622 "time::changed"
623 "standard::size"
624 "unix::mode"
625 "access::can-read"
626 "access::can-write"
627 "access::can-execute"
628 "unix::inode"
629 "unix::device")
630 "GVFS file attributes.")
632 (defconst tramp-gvfs-file-attributes-with-gvfs-ls-regexp
633 (concat "[[:blank:]]" (regexp-opt tramp-gvfs-file-attributes t) "=\\(.+?\\)")
634 "Regexp to parse GVFS file attributes with `gvfs-ls'.")
636 (defconst tramp-gvfs-file-attributes-with-gvfs-info-regexp
637 (concat "^[[:blank:]]*"
638 (regexp-opt tramp-gvfs-file-attributes t)
639 ":[[:blank:]]+\\(.*\\)$")
640 "Regexp to parse GVFS file attributes with `gvfs-info'.")
642 (defconst tramp-gvfs-file-system-attributes
643 '("filesystem::free"
644 "filesystem::size"
645 "filesystem::used")
646 "GVFS file system attributes.")
648 (defconst tramp-gvfs-file-system-attributes-regexp
649 (concat "^[[:blank:]]*"
650 (regexp-opt tramp-gvfs-file-system-attributes t)
651 ":[[:blank:]]+\\(.*\\)$")
652 "Regexp to parse GVFS file system attributes with `gvfs-info'.")
654 (defconst tramp-gvfs-owncloud-default-prefix "/remote.php/webdav"
655 "Default prefix for owncloud / nextcloud methods.")
657 (defconst tramp-gvfs-owncloud-default-prefix-regexp
658 (concat (regexp-quote tramp-gvfs-owncloud-default-prefix) "$")
659 "Regexp of default prefix for owncloud / nextcloud methods.")
662 ;; New handlers should be added here.
663 ;;;###tramp-autoload
664 (defconst tramp-gvfs-file-name-handler-alist
665 '((access-file . ignore)
666 (add-name-to-file . tramp-handle-add-name-to-file)
667 ;; `byte-compiler-base-file-name' performed by default handler.
668 ;; `copy-directory' performed by default handler.
669 (copy-file . tramp-gvfs-handle-copy-file)
670 (delete-directory . tramp-gvfs-handle-delete-directory)
671 (delete-file . tramp-gvfs-handle-delete-file)
672 ;; `diff-latest-backup-file' performed by default handler.
673 (directory-file-name . tramp-handle-directory-file-name)
674 (directory-files . tramp-handle-directory-files)
675 (directory-files-and-attributes
676 . tramp-handle-directory-files-and-attributes)
677 (dired-compress-file . ignore)
678 (dired-uncache . tramp-handle-dired-uncache)
679 (expand-file-name . tramp-gvfs-handle-expand-file-name)
680 (file-accessible-directory-p . tramp-handle-file-accessible-directory-p)
681 (file-acl . ignore)
682 (file-attributes . tramp-gvfs-handle-file-attributes)
683 (file-directory-p . tramp-handle-file-directory-p)
684 (file-equal-p . tramp-handle-file-equal-p)
685 (file-executable-p . tramp-gvfs-handle-file-executable-p)
686 (file-exists-p . tramp-handle-file-exists-p)
687 (file-in-directory-p . tramp-handle-file-in-directory-p)
688 (file-local-copy . tramp-gvfs-handle-file-local-copy)
689 (file-modes . tramp-handle-file-modes)
690 (file-name-all-completions . tramp-gvfs-handle-file-name-all-completions)
691 (file-name-as-directory . tramp-handle-file-name-as-directory)
692 (file-name-case-insensitive-p . tramp-handle-file-name-case-insensitive-p)
693 (file-name-completion . tramp-handle-file-name-completion)
694 (file-name-directory . tramp-handle-file-name-directory)
695 (file-name-nondirectory . tramp-handle-file-name-nondirectory)
696 ;; `file-name-sans-versions' performed by default handler.
697 (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
698 (file-notify-add-watch . tramp-gvfs-handle-file-notify-add-watch)
699 (file-notify-rm-watch . tramp-handle-file-notify-rm-watch)
700 (file-notify-valid-p . tramp-handle-file-notify-valid-p)
701 (file-ownership-preserved-p . ignore)
702 (file-readable-p . tramp-gvfs-handle-file-readable-p)
703 (file-regular-p . tramp-handle-file-regular-p)
704 (file-remote-p . tramp-handle-file-remote-p)
705 (file-selinux-context . tramp-handle-file-selinux-context)
706 (file-symlink-p . tramp-handle-file-symlink-p)
707 (file-system-info . tramp-gvfs-handle-file-system-info)
708 (file-truename . tramp-handle-file-truename)
709 (file-writable-p . tramp-gvfs-handle-file-writable-p)
710 (find-backup-file-name . tramp-handle-find-backup-file-name)
711 ;; `find-file-noselect' performed by default handler.
712 ;; `get-file-buffer' performed by default handler.
713 (insert-directory . tramp-handle-insert-directory)
714 (insert-file-contents . tramp-handle-insert-file-contents)
715 (load . tramp-handle-load)
716 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
717 (make-directory . tramp-gvfs-handle-make-directory)
718 (make-directory-internal . ignore)
719 (make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
720 (make-symbolic-link . tramp-handle-make-symbolic-link)
721 (process-file . ignore)
722 (rename-file . tramp-gvfs-handle-rename-file)
723 (set-file-acl . ignore)
724 (set-file-modes . ignore)
725 (set-file-selinux-context . ignore)
726 (set-file-times . ignore)
727 (set-visited-file-modtime . tramp-handle-set-visited-file-modtime)
728 (shell-command . ignore)
729 (start-file-process . ignore)
730 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
731 (temporary-file-directory . tramp-handle-temporary-file-directory)
732 (unhandled-file-name-directory . ignore)
733 (vc-registered . ignore)
734 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime)
735 (write-region . tramp-gvfs-handle-write-region))
736 "Alist of handler functions for Tramp GVFS method.
737 Operations not mentioned here will be handled by the default Emacs primitives.")
739 ;; It must be a `defsubst' in order to push the whole code into
740 ;; tramp-loaddefs.el. Otherwise, there would be recursive autoloading.
741 ;;;###tramp-autoload
742 (defsubst tramp-gvfs-file-name-p (filename)
743 "Check if it's a filename handled by the GVFS daemon."
744 (and (tramp-tramp-file-p filename)
745 (let ((method
746 (tramp-file-name-method (tramp-dissect-file-name filename))))
747 (and (stringp method) (member method tramp-gvfs-methods)))))
749 ;;;###tramp-autoload
750 (defun tramp-gvfs-file-name-handler (operation &rest args)
751 "Invoke the GVFS related OPERATION.
752 First arg specifies the OPERATION, second arg is a list of arguments to
753 pass to the OPERATION."
754 (unless tramp-gvfs-enabled
755 (tramp-user-error nil "Package `tramp-gvfs' not supported"))
756 (let ((fn (assoc operation tramp-gvfs-file-name-handler-alist)))
757 (if fn
758 (save-match-data (apply (cdr fn) args))
759 (tramp-run-real-handler operation args))))
761 ;;;###tramp-autoload
762 (when (featurep 'dbusbind)
763 (tramp-register-foreign-file-name-handler
764 'tramp-gvfs-file-name-p 'tramp-gvfs-file-name-handler))
767 ;; D-Bus helper function.
769 (defun tramp-gvfs-dbus-string-to-byte-array (string)
770 "Like `dbus-string-to-byte-array' but add trailing \\0 if needed."
771 (dbus-string-to-byte-array
772 (if (string-match "^(aya{sv})" tramp-gvfs-mountlocation-signature)
773 (concat string (string 0)) string)))
775 (defun tramp-gvfs-dbus-byte-array-to-string (byte-array)
776 "Like `dbus-byte-array-to-string' but remove trailing \\0 if exists.
777 Return nil for null BYTE-ARRAY."
778 ;; The byte array could be a variant. Take care.
779 (let ((byte-array
780 (if (and (consp byte-array) (atom (car byte-array)))
781 byte-array (car byte-array))))
782 (and byte-array
783 (dbus-byte-array-to-string
784 (if (and (consp byte-array) (zerop (car (last byte-array))))
785 (butlast byte-array) byte-array)))))
787 (defun tramp-gvfs-stringify-dbus-message (message)
788 "Convert a D-Bus message into readable UTF8 strings, used for traces."
789 (cond
790 ((and (consp message) (characterp (car message)))
791 (format "%S" (tramp-gvfs-dbus-byte-array-to-string message)))
792 ((and (consp message) (not (consp (cdr message))))
793 (cons (tramp-gvfs-stringify-dbus-message (car message))
794 (tramp-gvfs-stringify-dbus-message (cdr message))))
795 ((consp message)
796 (mapcar 'tramp-gvfs-stringify-dbus-message message))
797 ((stringp message)
798 (format "%S" message))
799 (t message)))
801 (defun tramp-dbus-function (vec func args)
802 "Apply a D-Bus function FUNC from dbus.el.
803 The call will be traced by Tramp with trace level 6."
804 (let (result)
805 (tramp-message vec 6 "%s" (cons func args))
806 (setq result (apply func args))
807 (tramp-message vec 6 "%s" result(tramp-gvfs-stringify-dbus-message result))
808 result))
810 (defmacro with-tramp-dbus-call-method
811 (vec synchronous bus service path interface method &rest args)
812 "Apply a D-Bus call on bus BUS.
814 If SYNCHRONOUS is non-nil, the call is synchronously. Otherwise,
815 it is an asynchronous call, with `ignore' as callback function.
817 The other arguments have the same meaning as with `dbus-call-method'
818 or `dbus-call-method-asynchronously'."
819 `(let ((func (if ,synchronous
820 'dbus-call-method 'dbus-call-method-asynchronously))
821 (args (append (list ,bus ,service ,path ,interface ,method)
822 (if ,synchronous (list ,@args) (list 'ignore ,@args)))))
823 (tramp-dbus-function ,vec func args)))
825 (put 'with-tramp-dbus-call-method 'lisp-indent-function 2)
826 (put 'with-tramp-dbus-call-method 'edebug-form-spec '(form symbolp body))
827 (font-lock-add-keywords 'emacs-lisp-mode '("\\<with-tramp-dbus-call-method\\>"))
829 (defmacro with-tramp-dbus-get-all-properties
830 (vec bus service path interface)
831 "Return all properties of INTERFACE.
832 The call will be traced by Tramp with trace level 6."
833 ;; Check, that interface exists at object path. Retrieve properties.
834 `(when (member
835 ,interface
836 (tramp-dbus-function
837 ,vec 'dbus-introspect-get-interface-names
838 (list ,bus ,service ,path)))
839 (tramp-dbus-function
840 ,vec 'dbus-get-all-properties (list ,bus ,service ,path ,interface))))
842 (put 'with-tramp-dbus-get-all-properties 'lisp-indent-function 1)
843 (put 'with-tramp-dbus-get-all-properties 'edebug-form-spec '(form symbolp body))
844 (font-lock-add-keywords 'emacs-lisp-mode '("\\<with-tramp-dbus-get-all-properties\\>"))
846 (defvar tramp-gvfs-dbus-event-vector nil
847 "Current Tramp file name to be used, as vector.
848 It is needed when D-Bus signals or errors arrive, because there
849 is no information where to trace the message.")
851 (defun tramp-gvfs-dbus-event-error (event err)
852 "Called when a D-Bus error message arrives, see `dbus-event-error-functions'."
853 (when tramp-gvfs-dbus-event-vector
854 (tramp-message tramp-gvfs-dbus-event-vector 6 "%S" event)
855 (tramp-error tramp-gvfs-dbus-event-vector 'file-error "%s" (cadr err))))
857 ;; `dbus-event-error-hooks' has been renamed to
858 ;; `dbus-event-error-functions' in Emacs 24.3.
859 (add-hook
860 (if (boundp 'dbus-event-error-functions)
861 'dbus-event-error-functions 'dbus-event-error-hooks)
862 'tramp-gvfs-dbus-event-error)
865 ;; File name primitives.
867 (defun tramp-gvfs-do-copy-or-rename-file
868 (op filename newname &optional ok-if-already-exists keep-date
869 preserve-uid-gid preserve-extended-attributes)
870 "Copy or rename a remote file.
871 OP must be `copy' or `rename' and indicates the operation to perform.
872 FILENAME specifies the file to copy or rename, NEWNAME is the name of
873 the new file (for copy) or the new name of the file (for rename).
874 OK-IF-ALREADY-EXISTS means don't barf if NEWNAME exists already.
875 KEEP-DATE means to make sure that NEWNAME has the same timestamp
876 as FILENAME. PRESERVE-UID-GID, when non-nil, instructs to keep
877 the uid and gid if both files are on the same host.
878 PRESERVE-EXTENDED-ATTRIBUTES is ignored.
880 This function is invoked by `tramp-gvfs-handle-copy-file' and
881 `tramp-gvfs-handle-rename-file'. It is an error if OP is neither
882 of `copy' and `rename'. FILENAME and NEWNAME must be absolute
883 file names."
884 (unless (memq op '(copy rename))
885 (error "Unknown operation `%s', must be `copy' or `rename'" op))
887 (setq filename (file-truename filename))
888 (if (file-directory-p filename)
889 (progn
890 (copy-directory filename newname keep-date t)
891 (when (eq op 'rename) (delete-directory filename 'recursive)))
893 (let ((t1 (tramp-tramp-file-p filename))
894 (t2 (tramp-tramp-file-p newname))
895 (equal-remote (tramp-equal-remote filename newname))
896 (gvfs-operation (if (eq op 'copy) "gvfs-copy" "gvfs-move"))
897 (msg-operation (if (eq op 'copy) "Copying" "Renaming")))
899 (with-parsed-tramp-file-name (if t1 filename newname) nil
900 (when (and (not ok-if-already-exists) (file-exists-p newname))
901 (tramp-error v 'file-already-exists newname))
903 (if (or (and equal-remote
904 (tramp-get-connection-property v "direct-copy-failed" nil))
905 (and t1 (not (tramp-gvfs-file-name-p filename)))
906 (and t2 (not (tramp-gvfs-file-name-p newname))))
908 ;; We cannot copy or rename directly.
909 (let ((tmpfile (tramp-compat-make-temp-file filename)))
910 (if (eq op 'copy)
911 (copy-file
912 filename tmpfile t keep-date preserve-uid-gid
913 preserve-extended-attributes)
914 (rename-file filename tmpfile t))
915 (rename-file tmpfile newname ok-if-already-exists))
917 ;; Direct action.
918 (with-tramp-progress-reporter
919 v 0 (format "%s %s to %s" msg-operation filename newname)
920 (unless
921 (apply
922 'tramp-gvfs-send-command v gvfs-operation
923 (append
924 (and (eq op 'copy) (or keep-date preserve-uid-gid)
925 '("--preserve"))
926 (list
927 (tramp-gvfs-url-file-name filename)
928 (tramp-gvfs-url-file-name newname))))
930 (if (or (not equal-remote)
931 (and equal-remote
932 (tramp-get-connection-property
933 v "direct-copy-failed" nil)))
934 ;; Propagate the error.
935 (with-current-buffer (tramp-get-connection-buffer v)
936 (goto-char (point-min))
937 (tramp-error-with-buffer
938 nil v 'file-error
939 "%s failed, see buffer `%s' for details."
940 msg-operation (buffer-name)))
942 ;; Some WebDAV server, like the one from QNAP, do not
943 ;; support direct copy/move. Try a fallback.
944 (tramp-set-connection-property v "direct-copy-failed" t)
945 (tramp-gvfs-do-copy-or-rename-file
946 op filename newname ok-if-already-exists keep-date
947 preserve-uid-gid preserve-extended-attributes))))
949 (when (and t1 (eq op 'rename))
950 (with-parsed-tramp-file-name filename nil
951 (tramp-flush-file-properties v (file-name-directory localname))
952 (tramp-flush-file-properties v localname)))
954 (when t2
955 (with-parsed-tramp-file-name newname nil
956 (tramp-flush-file-properties v (file-name-directory localname))
957 (tramp-flush-file-properties v localname))))))))
959 (defun tramp-gvfs-handle-copy-file
960 (filename newname &optional ok-if-already-exists keep-date
961 preserve-uid-gid preserve-extended-attributes)
962 "Like `copy-file' for Tramp files."
963 (setq filename (expand-file-name filename))
964 (setq newname (expand-file-name newname))
965 ;; At least one file a Tramp file?
966 (if (or (tramp-tramp-file-p filename)
967 (tramp-tramp-file-p newname))
968 (tramp-gvfs-do-copy-or-rename-file
969 'copy filename newname ok-if-already-exists keep-date
970 preserve-uid-gid preserve-extended-attributes)
971 (tramp-run-real-handler
972 'copy-file
973 (list filename newname ok-if-already-exists keep-date
974 preserve-uid-gid preserve-extended-attributes))))
976 (defun tramp-gvfs-handle-delete-directory (directory &optional recursive trash)
977 "Like `delete-directory' for Tramp files."
978 (with-parsed-tramp-file-name directory nil
979 (if (and recursive (not (file-symlink-p directory)))
980 (mapc (lambda (file)
981 (if (eq t (tramp-compat-file-attribute-type
982 (file-attributes file)))
983 (delete-directory file recursive trash)
984 (delete-file file trash)))
985 (directory-files
986 directory 'full directory-files-no-dot-files-regexp))
987 (when (directory-files directory nil directory-files-no-dot-files-regexp)
988 (tramp-error
989 v 'file-error "Couldn't delete non-empty %s" directory)))
991 (tramp-flush-file-properties v (file-name-directory localname))
992 (tramp-flush-directory-properties v localname)
993 (unless
994 (tramp-gvfs-send-command
995 v (if (and trash delete-by-moving-to-trash) "gvfs-trash" "gvfs-rm")
996 (tramp-gvfs-url-file-name directory))
997 ;; Propagate the error.
998 (with-current-buffer (tramp-get-connection-buffer v)
999 (goto-char (point-min))
1000 (tramp-error-with-buffer
1001 nil v 'file-error "Couldn't delete %s" directory)))))
1003 (defun tramp-gvfs-handle-delete-file (filename &optional trash)
1004 "Like `delete-file' for Tramp files."
1005 (with-parsed-tramp-file-name filename nil
1006 (tramp-flush-file-properties v (file-name-directory localname))
1007 (tramp-flush-file-properties v localname)
1008 (unless
1009 (tramp-gvfs-send-command
1010 v (if (and trash delete-by-moving-to-trash) "gvfs-trash" "gvfs-rm")
1011 (tramp-gvfs-url-file-name filename))
1012 ;; Propagate the error.
1013 (with-current-buffer (tramp-get-connection-buffer v)
1014 (goto-char (point-min))
1015 (tramp-error-with-buffer
1016 nil v 'file-error "Couldn't delete %s" filename)))))
1018 (defun tramp-gvfs-handle-expand-file-name (name &optional dir)
1019 "Like `expand-file-name' for Tramp files."
1020 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
1021 (setq dir (or dir default-directory "/"))
1022 ;; Unless NAME is absolute, concat DIR and NAME.
1023 (unless (file-name-absolute-p name)
1024 (setq name (concat (file-name-as-directory dir) name)))
1025 ;; If NAME is not a Tramp file, run the real handler.
1026 (if (not (tramp-tramp-file-p name))
1027 (tramp-run-real-handler 'expand-file-name (list name nil))
1028 ;; Dissect NAME.
1029 (with-parsed-tramp-file-name name nil
1030 ;; If there is a default location, expand tilde.
1031 (when (string-match "\\`\\(~\\)\\(/\\|\\'\\)" localname)
1032 (save-match-data
1033 (tramp-gvfs-maybe-open-connection
1034 (make-tramp-file-name
1035 :method method :user user :domain domain
1036 :host host :port port :localname "/" :hop hop)))
1037 (setq localname
1038 (replace-match
1039 (tramp-get-connection-property v "default-location" "~")
1040 nil t localname 1)))
1041 ;; Tilde expansion is not possible.
1042 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
1043 (tramp-error
1044 v 'file-error
1045 "Cannot expand tilde in file `%s'" name))
1046 (unless (tramp-run-real-handler 'file-name-absolute-p (list localname))
1047 (setq localname (concat "/" localname)))
1048 ;; We do not pass "/..".
1049 (if (string-match "^\\(afp\\|davs?\\|smb\\)$" method)
1050 (when (string-match "^/[^/]+\\(/\\.\\./?\\)" localname)
1051 (setq localname (replace-match "/" t t localname 1)))
1052 (when (string-match "^/\\.\\./?" localname)
1053 (setq localname (replace-match "/" t t localname))))
1054 ;; There might be a double slash. Remove this.
1055 (while (string-match "//" localname)
1056 (setq localname (replace-match "/" t t localname)))
1057 ;; No tilde characters in file name, do normal
1058 ;; `expand-file-name' (this does "/./" and "/../").
1059 (tramp-make-tramp-file-name
1060 method user domain host port
1061 (tramp-run-real-handler 'expand-file-name (list localname))))))
1063 (defun tramp-gvfs-get-directory-attributes (directory)
1064 "Return GVFS attributes association list of all files in DIRECTORY."
1065 (ignore-errors
1066 ;; Don't modify `last-coding-system-used' by accident.
1067 (let ((last-coding-system-used last-coding-system-used)
1068 result)
1069 (with-parsed-tramp-file-name directory nil
1070 (with-tramp-file-property v localname "directory-attributes"
1071 (tramp-message v 5 "directory gvfs attributes: %s" localname)
1072 ;; Send command.
1073 (tramp-gvfs-send-command
1074 v "gvfs-ls" "-h" "-n" "-a"
1075 (mapconcat 'identity tramp-gvfs-file-attributes ",")
1076 (tramp-gvfs-url-file-name directory))
1077 ;; Parse output.
1078 (with-current-buffer (tramp-get-connection-buffer v)
1079 (goto-char (point-min))
1080 (while (looking-at
1081 (concat "^\\(.+\\)[[:blank:]]"
1082 "\\([[:digit:]]+\\)[[:blank:]]"
1083 "(\\(.+?\\))"
1084 tramp-gvfs-file-attributes-with-gvfs-ls-regexp))
1085 (let ((item (list (cons "type" (match-string 3))
1086 (cons "standard::size" (match-string 2))
1087 (cons "name" (match-string 1)))))
1088 (goto-char (1+ (match-end 3)))
1089 (while (looking-at
1090 (concat
1091 tramp-gvfs-file-attributes-with-gvfs-ls-regexp
1092 "\\(" tramp-gvfs-file-attributes-with-gvfs-ls-regexp
1093 "\\|" "$" "\\)"))
1094 (push (cons (match-string 1) (match-string 2)) item)
1095 (goto-char (match-end 2)))
1096 ;; Add display name as head.
1097 (push
1098 (cons (cdr (or (assoc "standard::display-name" item)
1099 (assoc "name" item)))
1100 (nreverse item))
1101 result))
1102 (forward-line)))
1103 result)))))
1105 (defun tramp-gvfs-get-root-attributes (filename &optional file-system)
1106 "Return GVFS attributes association list of FILENAME.
1107 If FILE-SYSTEM is non-nil, return file system attributes."
1108 (ignore-errors
1109 ;; Don't modify `last-coding-system-used' by accident.
1110 (let ((last-coding-system-used last-coding-system-used)
1111 result)
1112 (with-parsed-tramp-file-name filename nil
1113 (with-tramp-file-property
1114 v localname
1115 (if file-system "file-system-attributes" "file-attributes")
1116 (tramp-message
1117 v 5 "file%s gvfs attributes: %s"
1118 (if file-system " system" "") localname)
1119 ;; Send command.
1120 (if file-system
1121 (tramp-gvfs-send-command
1122 v "gvfs-info" "--filesystem" (tramp-gvfs-url-file-name filename))
1123 (tramp-gvfs-send-command
1124 v "gvfs-info" (tramp-gvfs-url-file-name filename)))
1125 ;; Parse output.
1126 (with-current-buffer (tramp-get-connection-buffer v)
1127 (goto-char (point-min))
1128 (while (re-search-forward
1129 (if file-system
1130 tramp-gvfs-file-system-attributes-regexp
1131 tramp-gvfs-file-attributes-with-gvfs-info-regexp)
1132 nil t)
1133 (push (cons (match-string 1) (match-string 2)) result))
1134 result))))))
1136 (defun tramp-gvfs-get-file-attributes (filename)
1137 "Return GVFS attributes association list of FILENAME."
1138 (setq filename (directory-file-name (expand-file-name filename)))
1139 (with-parsed-tramp-file-name filename nil
1140 (setq localname (tramp-compat-file-name-unquote localname))
1141 (if (or (and (string-match "^\\(afp\\|davs?\\|smb\\)$" method)
1142 (string-match "^/?\\([^/]+\\)$" localname))
1143 (string-equal localname "/"))
1144 (tramp-gvfs-get-root-attributes filename)
1145 (assoc
1146 (file-name-nondirectory filename)
1147 (tramp-gvfs-get-directory-attributes (file-name-directory filename))))))
1149 (defun tramp-gvfs-handle-file-attributes (filename &optional id-format)
1150 "Like `file-attributes' for Tramp files."
1151 (unless id-format (setq id-format 'integer))
1152 (ignore-errors
1153 (let ((attributes (tramp-gvfs-get-file-attributes filename))
1154 dirp res-symlink-target res-numlinks res-uid res-gid res-access
1155 res-mod res-change res-size res-filemodes res-inode res-device)
1156 (when attributes
1157 ;; ... directory or symlink
1158 (setq dirp (if (equal "directory" (cdr (assoc "type" attributes))) t))
1159 (setq res-symlink-target
1160 (cdr (assoc "standard::symlink-target" attributes)))
1161 (when (stringp res-symlink-target)
1162 (setq res-symlink-target
1163 ;; Parse unibyte codes "\xNN". We assume they are
1164 ;; non-ASCII codepoints in the range #x80 through #xff.
1165 ;; Convert them to multibyte.
1166 (decode-coding-string
1167 (replace-regexp-in-string
1168 "\\\\x\\([[:xdigit:]]\\{2\\}\\)"
1169 (lambda (x)
1170 (unibyte-string (string-to-number (match-string 1 x) 16)))
1171 res-symlink-target)
1172 'utf-8)))
1173 ;; ... number links
1174 (setq res-numlinks
1175 (string-to-number
1176 (or (cdr (assoc "unix::nlink" attributes)) "0")))
1177 ;; ... uid and gid
1178 (setq res-uid
1179 (if (eq id-format 'integer)
1180 (string-to-number
1181 (or (cdr (assoc "unix::uid" attributes))
1182 (format "%s" tramp-unknown-id-integer)))
1183 (or (cdr (assoc "owner::user" attributes))
1184 (cdr (assoc "unix::uid" attributes))
1185 tramp-unknown-id-string)))
1186 (setq res-gid
1187 (if (eq id-format 'integer)
1188 (string-to-number
1189 (or (cdr (assoc "unix::gid" attributes))
1190 (format "%s" tramp-unknown-id-integer)))
1191 (or (cdr (assoc "owner::group" attributes))
1192 (cdr (assoc "unix::gid" attributes))
1193 tramp-unknown-id-string)))
1194 ;; ... last access, modification and change time
1195 (setq res-access
1196 (seconds-to-time
1197 (string-to-number
1198 (or (cdr (assoc "time::access" attributes)) "0"))))
1199 (setq res-mod
1200 (seconds-to-time
1201 (string-to-number
1202 (or (cdr (assoc "time::modified" attributes)) "0"))))
1203 (setq res-change
1204 (seconds-to-time
1205 (string-to-number
1206 (or (cdr (assoc "time::changed" attributes)) "0"))))
1207 ;; ... size
1208 (setq res-size
1209 (string-to-number
1210 (or (cdr (assoc "standard::size" attributes)) "0")))
1211 ;; ... file mode flags
1212 (setq res-filemodes
1213 (let ((n (cdr (assoc "unix::mode" attributes))))
1214 (if n
1215 (tramp-file-mode-from-int (string-to-number n))
1216 (format
1217 "%s%s%s%s------"
1218 (if dirp "d" (if res-symlink-target "l" "-"))
1219 (if (equal (cdr (assoc "access::can-read" attributes))
1220 "FALSE")
1221 "-" "r")
1222 (if (equal (cdr (assoc "access::can-write" attributes))
1223 "FALSE")
1224 "-" "w")
1225 (if (equal (cdr (assoc "access::can-execute" attributes))
1226 "FALSE")
1227 "-" "x")))))
1228 ;; ... inode and device
1229 (setq res-inode
1230 (let ((n (cdr (assoc "unix::inode" attributes))))
1231 (if n
1232 (string-to-number n)
1233 (tramp-get-inode (tramp-dissect-file-name filename)))))
1234 (setq res-device
1235 (let ((n (cdr (assoc "unix::device" attributes))))
1236 (if n
1237 (string-to-number n)
1238 (tramp-get-device (tramp-dissect-file-name filename)))))
1240 ;; Return data gathered.
1241 (list
1242 ;; 0. t for directory, string (name linked to) for
1243 ;; symbolic link, or nil.
1244 (or dirp res-symlink-target)
1245 ;; 1. Number of links to file.
1246 res-numlinks
1247 ;; 2. File uid.
1248 res-uid
1249 ;; 3. File gid.
1250 res-gid
1251 ;; 4. Last access time, as a list of integers.
1252 ;; 5. Last modification time, likewise.
1253 ;; 6. Last status change time, likewise.
1254 res-access res-mod res-change
1255 ;; 7. Size in bytes (-1, if number is out of range).
1256 res-size
1257 ;; 8. File modes.
1258 res-filemodes
1259 ;; 9. t if file's gid would change if file were deleted
1260 ;; and recreated.
1262 ;; 10. Inode number.
1263 res-inode
1264 ;; 11. Device number.
1265 res-device
1266 )))))
1268 (defun tramp-gvfs-handle-file-executable-p (filename)
1269 "Like `file-executable-p' for Tramp files."
1270 (with-parsed-tramp-file-name filename nil
1271 (with-tramp-file-property v localname "file-executable-p"
1272 (tramp-check-cached-permissions v ?x))))
1274 (defun tramp-gvfs-handle-file-local-copy (filename)
1275 "Like `file-local-copy' for Tramp files."
1276 (with-parsed-tramp-file-name filename nil
1277 (unless (file-exists-p filename)
1278 (tramp-error
1279 v tramp-file-missing
1280 "Cannot make local copy of non-existing file `%s'" filename))
1281 (let ((tmpfile (tramp-compat-make-temp-file filename)))
1282 (copy-file filename tmpfile 'ok-if-already-exists 'keep-time)
1283 tmpfile)))
1285 (defun tramp-gvfs-handle-file-name-all-completions (filename directory)
1286 "Like `file-name-all-completions' for Tramp files."
1287 (unless (save-match-data (string-match "/" filename))
1288 (all-completions
1289 filename
1290 (with-parsed-tramp-file-name (expand-file-name directory) nil
1291 (with-tramp-file-property v localname "file-name-all-completions"
1292 (let ((result '("./" "../")))
1293 ;; Get a list of directories and files.
1294 (dolist (item (tramp-gvfs-get-directory-attributes directory) result)
1295 (if (string-equal (cdr (assoc "type" item)) "directory")
1296 (push (file-name-as-directory (car item)) result)
1297 (push (car item) result)))))))))
1299 (defun tramp-gvfs-handle-file-notify-add-watch (file-name flags _callback)
1300 "Like `file-notify-add-watch' for Tramp files."
1301 (setq file-name (expand-file-name file-name))
1302 (with-parsed-tramp-file-name file-name nil
1303 ;; TODO: We cannot watch directories, because `gio monitor' is not
1304 ;; supported for gvfs-mounted directories. However,
1305 ;; `file-notify-add-watch' uses directories.
1306 (when (or (not (tramp-gvfs-gio-tool-p v)) (file-directory-p file-name))
1307 (tramp-error
1308 v 'file-notify-error "Monitoring not supported for `%s'" file-name))
1309 (let* ((default-directory (file-name-directory file-name))
1310 (events
1311 (cond
1312 ((and (memq 'change flags) (memq 'attribute-change flags))
1313 '(created changed changes-done-hint moved deleted
1314 attribute-changed))
1315 ((memq 'change flags)
1316 '(created changed changes-done-hint moved deleted))
1317 ((memq 'attribute-change flags) '(attribute-changed))))
1318 (p (apply
1319 'start-process
1320 "gvfs-monitor" (generate-new-buffer " *gvfs-monitor*")
1321 `("gio" "monitor" ,(tramp-gvfs-url-file-name file-name)))))
1322 (if (not (processp p))
1323 (tramp-error
1324 v 'file-notify-error "Monitoring not supported for `%s'" file-name)
1325 (tramp-message
1326 v 6 "Run `%s', %S" (mapconcat 'identity (process-command p) " ") p)
1327 (process-put p 'vector v)
1328 (process-put p 'events events)
1329 (process-put p 'watch-name localname)
1330 (process-put p 'adjust-window-size-function 'ignore)
1331 (set-process-query-on-exit-flag p nil)
1332 (set-process-filter p 'tramp-gvfs-monitor-process-filter)
1333 ;; There might be an error if the monitor is not supported.
1334 ;; Give the filter a chance to read the output.
1335 (tramp-accept-process-output p 1)
1336 (unless (process-live-p p)
1337 (tramp-error
1338 p 'file-notify-error "Monitoring not supported for `%s'" file-name))
1339 p))))
1341 (defun tramp-gvfs-monitor-process-filter (proc string)
1342 "Read output from \"gvfs-monitor-file\" and add corresponding \
1343 file-notify events."
1344 (let* ((events (process-get proc 'events))
1345 (rest-string (process-get proc 'rest-string))
1346 (dd (with-current-buffer (process-buffer proc) default-directory))
1347 (ddu (regexp-quote (tramp-gvfs-url-file-name dd))))
1348 (when rest-string
1349 (tramp-message proc 10 "Previous string:\n%s" rest-string))
1350 (tramp-message proc 6 "%S\n%s" proc string)
1351 (setq string (concat rest-string string)
1352 ;; Fix action names.
1353 string (replace-regexp-in-string
1354 "attributes changed" "attribute-changed" string)
1355 string (replace-regexp-in-string
1356 "changes done" "changes-done-hint" string)
1357 string (replace-regexp-in-string
1358 "renamed to" "moved" string))
1359 ;; https://bugs.launchpad.net/bugs/1742946
1360 (when (string-match "Monitoring not supported\\|No locations given" string)
1361 (delete-process proc))
1363 (while (string-match
1364 (concat "^.+:"
1365 "[[:space:]]\\(.+\\):"
1366 "[[:space:]]" (regexp-opt tramp-gio-events t)
1367 "\\([[:space:]]\\(.+\\)\\)?$")
1368 string)
1370 (let ((file (match-string 1 string))
1371 (file1 (match-string 4 string))
1372 (action (intern-soft (match-string 2 string))))
1373 (setq string (replace-match "" nil nil string))
1374 ;; File names are returned as URL paths. We must convert them.
1375 (when (string-match ddu file)
1376 (setq file (replace-match dd nil nil file)))
1377 (while (string-match "%\\([0-9A-F]\\{2\\}\\)" file)
1378 (setq file (url-unhex-string file)))
1379 (when (string-match ddu (or file1 ""))
1380 (setq file1 (replace-match dd nil nil file1)))
1381 (while (string-match "%\\([0-9A-F]\\{2\\}\\)" (or file1 ""))
1382 (setq file1 (url-unhex-string file1)))
1383 ;; Remove watch when file or directory to be watched is deleted.
1384 (when (and (member action '(moved deleted))
1385 (string-equal file (process-get proc 'watch-name)))
1386 (delete-process proc))
1387 ;; Usually, we would add an Emacs event now. Unfortunately,
1388 ;; `unread-command-events' does not accept several events at
1389 ;; once. Therefore, we apply the callback directly.
1390 (when (member action events)
1391 (tramp-compat-funcall
1392 'file-notify-callback (list proc action file file1)))))
1394 ;; Save rest of the string.
1395 (when (zerop (length string)) (setq string nil))
1396 (when string (tramp-message proc 10 "Rest string:\n%s" string))
1397 (process-put proc 'rest-string string)))
1399 (defun tramp-gvfs-handle-file-readable-p (filename)
1400 "Like `file-readable-p' for Tramp files."
1401 (with-parsed-tramp-file-name filename nil
1402 (with-tramp-file-property v localname "file-readable-p"
1403 (tramp-check-cached-permissions v ?r))))
1405 (defun tramp-gvfs-handle-file-system-info (filename)
1406 "Like `file-system-info' for Tramp files."
1407 (setq filename (directory-file-name (expand-file-name filename)))
1408 (with-parsed-tramp-file-name filename nil
1409 ;; We don't use cached values.
1410 (tramp-flush-file-property v localname "file-system-attributes")
1411 (let* ((attr (tramp-gvfs-get-root-attributes filename 'file-system))
1412 (size (cdr (assoc "filesystem::size" attr)))
1413 (used (cdr (assoc "filesystem::used" attr)))
1414 (free (cdr (assoc "filesystem::free" attr))))
1415 (when (and (stringp size) (stringp used) (stringp free))
1416 (list (string-to-number (concat size "e0"))
1417 (- (string-to-number (concat size "e0"))
1418 (string-to-number (concat used "e0")))
1419 (string-to-number (concat free "e0")))))))
1421 (defun tramp-gvfs-handle-file-writable-p (filename)
1422 "Like `file-writable-p' for Tramp files."
1423 (with-parsed-tramp-file-name filename nil
1424 (with-tramp-file-property v localname "file-writable-p"
1425 (if (file-exists-p filename)
1426 (tramp-check-cached-permissions v ?w)
1427 ;; If file doesn't exist, check if directory is writable.
1428 (and (file-directory-p (file-name-directory filename))
1429 (file-writable-p (file-name-directory filename)))))))
1431 (defun tramp-gvfs-handle-make-directory (dir &optional parents)
1432 "Like `make-directory' for Tramp files."
1433 (setq dir (directory-file-name (expand-file-name dir)))
1434 (with-parsed-tramp-file-name dir nil
1435 (tramp-flush-file-properties v (file-name-directory localname))
1436 (tramp-flush-directory-properties v localname)
1437 (save-match-data
1438 (let ((ldir (file-name-directory dir)))
1439 ;; Make missing directory parts. "gvfs-mkdir -p ..." does not
1440 ;; work robust.
1441 (when (and parents (not (file-directory-p ldir)))
1442 (make-directory ldir parents))
1443 ;; Just do it.
1444 (unless (or (tramp-gvfs-send-command
1445 v "gvfs-mkdir" (tramp-gvfs-url-file-name dir))
1446 (and parents (file-directory-p dir)))
1447 (tramp-error v 'file-error "Couldn't make directory %s" dir))))))
1449 (defun tramp-gvfs-handle-rename-file
1450 (filename newname &optional ok-if-already-exists)
1451 "Like `rename-file' for Tramp files."
1452 ;; Check if both files are local -- invoke normal rename-file.
1453 ;; Otherwise, use Tramp from local system.
1454 (setq filename (expand-file-name filename))
1455 (setq newname (expand-file-name newname))
1456 ;; At least one file a Tramp file?
1457 (if (or (tramp-tramp-file-p filename)
1458 (tramp-tramp-file-p newname))
1459 (tramp-gvfs-do-copy-or-rename-file
1460 'rename filename newname ok-if-already-exists
1461 'keep-date 'preserve-uid-gid)
1462 (tramp-run-real-handler
1463 'rename-file (list filename newname ok-if-already-exists))))
1465 (defun tramp-gvfs-handle-write-region
1466 (start end filename &optional append visit lockname mustbenew)
1467 "Like `write-region' for Tramp files."
1468 (setq filename (expand-file-name filename))
1469 (with-parsed-tramp-file-name filename nil
1470 (when (and mustbenew (file-exists-p filename)
1471 (or (eq mustbenew 'excl)
1472 (not
1473 (y-or-n-p
1474 (format "File %s exists; overwrite anyway? " filename)))))
1475 (tramp-error v 'file-already-exists filename))
1477 (let ((tmpfile (tramp-compat-make-temp-file filename)))
1478 (when (and append (file-exists-p filename))
1479 (copy-file filename tmpfile 'ok))
1480 ;; We say `no-message' here because we don't want the visited file
1481 ;; modtime data to be clobbered from the temp file. We call
1482 ;; `set-visited-file-modtime' ourselves later on.
1483 (tramp-run-real-handler
1484 'write-region (list start end tmpfile append 'no-message lockname))
1485 (condition-case nil
1486 (rename-file tmpfile filename 'ok-if-already-exists)
1487 (error
1488 (delete-file tmpfile)
1489 (tramp-error
1490 v 'file-error "Couldn't write region to `%s'" filename))))
1492 (tramp-flush-file-properties v (file-name-directory localname))
1493 (tramp-flush-file-properties v localname)
1495 ;; Set file modification time.
1496 (when (or (eq visit t) (stringp visit))
1497 (set-visited-file-modtime
1498 (tramp-compat-file-attribute-modification-time
1499 (file-attributes filename))))
1501 ;; The end.
1502 (when (and (null noninteractive)
1503 (or (eq visit t) (null visit) (stringp visit)))
1504 (tramp-message v 0 "Wrote %s" filename))
1505 (run-hooks 'tramp-handle-write-region-hook)))
1508 ;; File name conversions.
1510 (defun tramp-gvfs-url-file-name (filename)
1511 "Return FILENAME in URL syntax."
1512 ;; "/" must NOT be hexified.
1513 (setq filename (tramp-compat-file-name-unquote filename))
1514 (let ((url-unreserved-chars (cons ?/ url-unreserved-chars))
1515 result)
1516 (setq
1517 result
1518 (url-recreate-url
1519 (if (tramp-tramp-file-p filename)
1520 (with-parsed-tramp-file-name filename nil
1521 (when (string-equal "gdrive" method)
1522 (setq method "google-drive"))
1523 (when (string-equal "owncloud" method)
1524 (setq method "davs"
1525 localname
1526 (concat (tramp-gvfs-get-remote-prefix v) localname)))
1527 (when (and user domain)
1528 (setq user (concat domain ";" user)))
1529 (url-parse-make-urlobj
1530 method (and user (url-hexify-string user))
1531 nil (and host (url-hexify-string host))
1532 (if (stringp port) (string-to-number port) port)
1533 (and localname (url-hexify-string localname)) nil nil t))
1534 (url-parse-make-urlobj
1535 "file" nil nil nil nil
1536 (url-hexify-string (file-truename filename)) nil nil t))))
1537 (when (tramp-tramp-file-p filename)
1538 (with-parsed-tramp-file-name filename nil
1539 (tramp-message v 10 "remote file `%s' is URL `%s'" filename result)))
1540 result))
1542 (defun tramp-gvfs-object-path (filename)
1543 "Create a D-Bus object path from FILENAME."
1544 (expand-file-name (dbus-escape-as-identifier filename) tramp-gvfs-path-tramp))
1546 (defun tramp-gvfs-file-name (object-path)
1547 "Retrieve file name from D-Bus OBJECT-PATH."
1548 (dbus-unescape-from-identifier
1549 (replace-regexp-in-string "^.*/\\([^/]+\\)$" "\\1" object-path)))
1552 ;; D-Bus GVFS functions.
1554 (defun tramp-gvfs-handler-askpassword (message user domain flags)
1555 "Implementation for the \"org.gtk.vfs.MountOperation.askPassword\" method."
1556 (let* ((filename
1557 (tramp-gvfs-file-name (dbus-event-path-name last-input-event)))
1558 (pw-prompt
1559 (format
1560 "%s for %s "
1561 (if (string-match "\\([pP]assword\\|[pP]assphrase\\)" message)
1562 (capitalize (match-string 1 message))
1563 "Password")
1564 filename))
1565 password)
1567 (condition-case nil
1568 (with-parsed-tramp-file-name filename l
1569 (when (and (zerop (length user))
1570 (not
1571 (zerop (logand flags tramp-gvfs-password-need-username))))
1572 (setq user (read-string "User name: ")))
1573 (when (and (zerop (length domain))
1574 (not
1575 (zerop (logand flags tramp-gvfs-password-need-domain))))
1576 (setq domain (read-string "Domain name: ")))
1578 (tramp-message l 6 "%S %S %S %d" message user domain flags)
1579 (unless (tramp-get-connection-property l "first-password-request" nil)
1580 (tramp-clear-passwd l))
1582 (setq password (tramp-read-passwd
1583 (tramp-get-connection-process l) pw-prompt))
1585 ;; Return result.
1586 (if (stringp password)
1587 (list
1588 t ;; password handled.
1589 nil ;; no abort of D-Bus.
1590 password
1591 (tramp-file-name-user l)
1592 domain
1593 nil ;; not anonymous.
1594 0) ;; no password save.
1595 ;; No password provided.
1596 (list nil t "" (tramp-file-name-user l) domain nil 0)))
1598 ;; When QUIT is raised, we shall return this information to D-Bus.
1599 (quit (list nil t "" "" "" nil 0)))))
1601 (defun tramp-gvfs-handler-askquestion (message choices)
1602 "Implementation for the \"org.gtk.vfs.MountOperation.askQuestion\" method."
1603 (save-window-excursion
1604 (let ((enable-recursive-minibuffers t)
1605 (use-dialog-box (and use-dialog-box (null noninteractive)))
1606 result)
1608 (with-parsed-tramp-file-name
1609 (tramp-gvfs-file-name (dbus-event-path-name last-input-event)) nil
1610 (tramp-message v 6 "%S %S" message choices)
1612 (setq result
1613 (condition-case nil
1614 (list
1615 t ;; handled.
1616 nil ;; no abort of D-Bus.
1617 (with-tramp-connection-property
1618 (tramp-get-connection-process v) message
1619 ;; In theory, there can be several choices.
1620 ;; Until now, there is only the question whether
1621 ;; to accept an unknown host signature or certificate.
1622 (with-temp-buffer
1623 ;; Preserve message for `progress-reporter'.
1624 (with-temp-message ""
1625 (insert message)
1626 (goto-char (point-max))
1627 (if noninteractive
1628 (message "%s" message)
1629 (pop-to-buffer (current-buffer)))
1630 (if (yes-or-no-p
1631 (concat
1632 (buffer-substring
1633 (line-beginning-position) (point))
1634 " "))
1635 0 1)))))
1637 ;; When QUIT is raised, we shall return this
1638 ;; information to D-Bus.
1639 (quit (list nil t 1))))
1641 (tramp-message v 6 "%s" result)
1643 ;; When the choice is "no", we set a dummy fuse-mountpoint in
1644 ;; order to leave the timeout.
1645 (unless (zerop (cl-caddr result))
1646 (tramp-set-file-property v "/" "fuse-mountpoint" "/"))
1648 result))))
1650 (defun tramp-gvfs-handler-mounted-unmounted (mount-info)
1651 "Signal handler for the \"org.gtk.vfs.MountTracker.mounted\" and
1652 \"org.gtk.vfs.MountTracker.unmounted\" signals."
1653 (ignore-errors
1654 (let ((signal-name (dbus-event-member-name last-input-event))
1655 (elt mount-info))
1656 ;; Jump over the first elements of the mount info. Since there
1657 ;; were changes in the entries, we cannot access dedicated
1658 ;; elements.
1659 (while (stringp (car elt)) (setq elt (cdr elt)))
1660 (let* ((fuse-mountpoint (tramp-gvfs-dbus-byte-array-to-string (cadr elt)))
1661 (mount-spec (cl-caddr elt))
1662 (prefix (tramp-gvfs-dbus-byte-array-to-string (car mount-spec)))
1663 (default-location (tramp-gvfs-dbus-byte-array-to-string
1664 (cl-cadddr elt)))
1665 (method (tramp-gvfs-dbus-byte-array-to-string
1666 (cadr (assoc "type" (cadr mount-spec)))))
1667 (user (tramp-gvfs-dbus-byte-array-to-string
1668 (cadr (assoc "user" (cadr mount-spec)))))
1669 (domain (tramp-gvfs-dbus-byte-array-to-string
1670 (cadr (assoc "domain" (cadr mount-spec)))))
1671 (host (tramp-gvfs-dbus-byte-array-to-string
1672 (cadr (or (assoc "host" (cadr mount-spec))
1673 (assoc "server" (cadr mount-spec))))))
1674 (port (tramp-gvfs-dbus-byte-array-to-string
1675 (cadr (assoc "port" (cadr mount-spec)))))
1676 (ssl (tramp-gvfs-dbus-byte-array-to-string
1677 (cadr (assoc "ssl" (cadr mount-spec)))))
1678 (uri (tramp-gvfs-dbus-byte-array-to-string
1679 (cadr (assoc "uri" (cadr mount-spec))))))
1680 (when (string-match "^\\(afp\\|smb\\)" method)
1681 (setq method (match-string 1 method)))
1682 (when (string-equal "obex" method)
1683 (setq host (tramp-bluez-device host)))
1684 (when (and (string-equal "dav" method) (string-equal "true" ssl))
1685 (setq method "davs"))
1686 (when (and (string-equal "davs" method)
1687 (string-match
1688 tramp-gvfs-owncloud-default-prefix-regexp prefix))
1689 (setq method "owncloud"))
1690 (when (string-equal "google-drive" method)
1691 (setq method "gdrive"))
1692 (when (and (string-equal "http" method) (stringp uri))
1693 (setq uri (url-generic-parse-url uri)
1694 method (url-type uri)
1695 user (url-user uri)
1696 host (url-host uri)
1697 port (url-portspec uri)))
1698 (with-parsed-tramp-file-name
1699 (tramp-make-tramp-file-name method user domain host port "") nil
1700 (tramp-message
1701 v 6 "%s %s"
1702 signal-name (tramp-gvfs-stringify-dbus-message mount-info))
1703 (tramp-flush-file-property v "/" "list-mounts")
1704 (if (string-equal (downcase signal-name) "unmounted")
1705 (tramp-flush-file-properties v "/")
1706 ;; Set mountpoint and location.
1707 (tramp-set-file-property v "/" "fuse-mountpoint" fuse-mountpoint)
1708 (tramp-set-connection-property
1709 v "default-location" default-location)))))))
1711 (when tramp-gvfs-enabled
1712 (dbus-register-signal
1713 :session nil tramp-gvfs-path-mounttracker
1714 tramp-gvfs-interface-mounttracker "mounted"
1715 'tramp-gvfs-handler-mounted-unmounted)
1716 (dbus-register-signal
1717 :session nil tramp-gvfs-path-mounttracker
1718 tramp-gvfs-interface-mounttracker "Mounted"
1719 'tramp-gvfs-handler-mounted-unmounted)
1721 (dbus-register-signal
1722 :session nil tramp-gvfs-path-mounttracker
1723 tramp-gvfs-interface-mounttracker "unmounted"
1724 'tramp-gvfs-handler-mounted-unmounted)
1725 (dbus-register-signal
1726 :session nil tramp-gvfs-path-mounttracker
1727 tramp-gvfs-interface-mounttracker "Unmounted"
1728 'tramp-gvfs-handler-mounted-unmounted))
1730 (defun tramp-gvfs-connection-mounted-p (vec)
1731 "Check, whether the location is already mounted."
1733 (tramp-get-file-property vec "/" "fuse-mountpoint" nil)
1734 (catch 'mounted
1735 (dolist
1736 (elt
1737 (with-tramp-file-property vec "/" "list-mounts"
1738 (with-tramp-dbus-call-method vec t
1739 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1740 tramp-gvfs-interface-mounttracker tramp-gvfs-listmounts))
1741 nil)
1742 ;; Jump over the first elements of the mount info. Since there
1743 ;; were changes in the entries, we cannot access dedicated
1744 ;; elements.
1745 (while (stringp (car elt)) (setq elt (cdr elt)))
1746 (let* ((fuse-mountpoint (tramp-gvfs-dbus-byte-array-to-string
1747 (cadr elt)))
1748 (mount-spec (cl-caddr elt))
1749 (prefix (tramp-gvfs-dbus-byte-array-to-string (car mount-spec)))
1750 (default-location (tramp-gvfs-dbus-byte-array-to-string
1751 (cl-cadddr elt)))
1752 (method (tramp-gvfs-dbus-byte-array-to-string
1753 (cadr (assoc "type" (cadr mount-spec)))))
1754 (user (tramp-gvfs-dbus-byte-array-to-string
1755 (cadr (assoc "user" (cadr mount-spec)))))
1756 (domain (tramp-gvfs-dbus-byte-array-to-string
1757 (cadr (assoc "domain" (cadr mount-spec)))))
1758 (host (tramp-gvfs-dbus-byte-array-to-string
1759 (cadr (or (assoc "host" (cadr mount-spec))
1760 (assoc "server" (cadr mount-spec))))))
1761 (port (tramp-gvfs-dbus-byte-array-to-string
1762 (cadr (assoc "port" (cadr mount-spec)))))
1763 (ssl (tramp-gvfs-dbus-byte-array-to-string
1764 (cadr (assoc "ssl" (cadr mount-spec)))))
1765 (uri (tramp-gvfs-dbus-byte-array-to-string
1766 (cadr (assoc "uri" (cadr mount-spec)))))
1767 (share (tramp-gvfs-dbus-byte-array-to-string
1769 (cadr (assoc "share" (cadr mount-spec)))
1770 (cadr (assoc "volume" (cadr mount-spec)))))))
1771 (when (string-match "^\\(afp\\|smb\\)" method)
1772 (setq method (match-string 1 method)))
1773 (when (string-equal "obex" method)
1774 (setq host (tramp-bluez-device host)))
1775 (when (and (string-equal "dav" method) (string-equal "true" ssl))
1776 (setq method "davs"))
1777 (when (and (string-equal "davs" method)
1778 (string-match
1779 tramp-gvfs-owncloud-default-prefix-regexp prefix))
1780 (setq method "owncloud"))
1781 (when (string-equal "google-drive" method)
1782 (setq method "gdrive"))
1783 (when (and (string-equal "synce" method) (zerop (length user)))
1784 (setq user (or (tramp-file-name-user vec) "")))
1785 (when (and (string-equal "http" method) (stringp uri))
1786 (setq uri (url-generic-parse-url uri)
1787 method (url-type uri)
1788 user (url-user uri)
1789 host (url-host uri)
1790 port (url-portspec uri)))
1791 (when (and
1792 (string-equal method (tramp-file-name-method vec))
1793 (string-equal user (tramp-file-name-user vec))
1794 (string-equal domain (tramp-file-name-domain vec))
1795 (string-equal host (tramp-file-name-host vec))
1796 (string-equal port (tramp-file-name-port vec))
1797 (string-match (concat "^/" (regexp-quote (or share "")))
1798 (tramp-file-name-unquote-localname vec)))
1799 ;; Set mountpoint and location.
1800 (tramp-set-file-property vec "/" "fuse-mountpoint" fuse-mountpoint)
1801 (tramp-set-connection-property
1802 vec "default-location" default-location)
1803 (throw 'mounted t)))))))
1805 (defun tramp-gvfs-unmount (vec)
1806 "Unmount the object identified by VEC."
1807 (setf (tramp-file-name-localname vec) "/"
1808 (tramp-file-name-hop vec) nil)
1809 (when (tramp-gvfs-connection-mounted-p vec)
1810 (tramp-gvfs-send-command
1811 vec "gvfs-mount" "-u"
1812 (tramp-gvfs-url-file-name (tramp-make-tramp-file-name vec))))
1813 (while (tramp-gvfs-connection-mounted-p vec)
1814 (read-event nil nil 0.1))
1815 (tramp-flush-connection-properties vec)
1816 (tramp-flush-connection-properties (tramp-get-connection-process vec)))
1818 (defun tramp-gvfs-mount-spec-entry (key value)
1819 "Construct a mount-spec entry to be used in a mount_spec.
1820 It was \"a(say)\", but has changed to \"a{sv})\"."
1821 (if (string-match "^(aya{sv})" tramp-gvfs-mountlocation-signature)
1822 (list :dict-entry key
1823 (list :variant (tramp-gvfs-dbus-string-to-byte-array value)))
1824 (list :struct key (tramp-gvfs-dbus-string-to-byte-array value))))
1826 (defun tramp-gvfs-mount-spec (vec)
1827 "Return a mount-spec for \"org.gtk.vfs.MountTracker.mountLocation\"."
1828 (let* ((method (tramp-file-name-method vec))
1829 (user (tramp-file-name-user vec))
1830 (domain (tramp-file-name-domain vec))
1831 (host (tramp-file-name-host vec))
1832 (port (tramp-file-name-port vec))
1833 (localname (tramp-file-name-unquote-localname vec))
1834 (share (when (string-match "^/?\\([^/]+\\)" localname)
1835 (match-string 1 localname)))
1836 (ssl (if (string-match "^davs\\|^owncloud" method) "true" "false"))
1837 (mount-spec
1838 `(:array
1839 ,@(cond
1840 ((string-equal "smb" method)
1841 (list (tramp-gvfs-mount-spec-entry "type" "smb-share")
1842 (tramp-gvfs-mount-spec-entry "server" host)
1843 (tramp-gvfs-mount-spec-entry "share" share)))
1844 ((string-equal "obex" method)
1845 (list (tramp-gvfs-mount-spec-entry "type" method)
1846 (tramp-gvfs-mount-spec-entry
1847 "host" (concat "[" (tramp-bluez-address host) "]"))))
1848 ((string-match "^dav\\|^owncloud" method)
1849 (list (tramp-gvfs-mount-spec-entry "type" "dav")
1850 (tramp-gvfs-mount-spec-entry "host" host)
1851 (tramp-gvfs-mount-spec-entry "ssl" ssl)))
1852 ((string-equal "afp" method)
1853 (list (tramp-gvfs-mount-spec-entry "type" "afp-volume")
1854 (tramp-gvfs-mount-spec-entry "host" host)
1855 (tramp-gvfs-mount-spec-entry "volume" share)))
1856 ((string-equal "gdrive" method)
1857 (list (tramp-gvfs-mount-spec-entry "type" "google-drive")
1858 (tramp-gvfs-mount-spec-entry "host" host)))
1859 ((string-match "^http" method)
1860 (list (tramp-gvfs-mount-spec-entry "type" "http")
1861 (tramp-gvfs-mount-spec-entry
1862 "uri"
1863 (url-recreate-url
1864 (url-parse-make-urlobj
1865 method user nil host port "/" nil nil t)))))
1867 (list (tramp-gvfs-mount-spec-entry "type" method)
1868 (tramp-gvfs-mount-spec-entry "host" host))))
1869 ,@(when user
1870 (list (tramp-gvfs-mount-spec-entry "user" user)))
1871 ,@(when domain
1872 (list (tramp-gvfs-mount-spec-entry "domain" domain)))
1873 ,@(when port
1874 (list (tramp-gvfs-mount-spec-entry "port" port)))))
1875 (mount-pref
1876 (if (and (string-match "^dav" method)
1877 (string-match "^/?[^/]+" localname))
1878 (match-string 0 localname)
1879 (tramp-gvfs-get-remote-prefix vec))))
1881 ;; Return.
1882 `(:struct ,(tramp-gvfs-dbus-string-to-byte-array mount-pref) ,mount-spec)))
1885 ;; Connection functions.
1887 (defun tramp-gvfs-get-remote-uid (vec id-format)
1888 "The uid of the remote connection VEC, in ID-FORMAT.
1889 ID-FORMAT valid values are `string' and `integer'."
1890 (with-tramp-connection-property vec (format "uid-%s" id-format)
1891 (let ((method (tramp-file-name-method vec))
1892 (user (tramp-file-name-user vec))
1893 (domain (tramp-file-name-domain vec))
1894 (host (tramp-file-name-host vec))
1895 (port (tramp-file-name-port vec))
1896 (localname
1897 (tramp-get-connection-property vec "default-location" nil)))
1898 (cond
1899 ((and user (equal id-format 'string)) user)
1900 (localname
1901 (tramp-compat-file-attribute-user-id
1902 (file-attributes
1903 (tramp-make-tramp-file-name method user domain host port localname)
1904 id-format)))
1905 ((equal id-format 'integer) tramp-unknown-id-integer)
1906 ((equal id-format 'string) tramp-unknown-id-string)))))
1908 (defun tramp-gvfs-get-remote-gid (vec id-format)
1909 "The gid of the remote connection VEC, in ID-FORMAT.
1910 ID-FORMAT valid values are `string' and `integer'."
1911 (with-tramp-connection-property vec (format "gid-%s" id-format)
1912 (let ((method (tramp-file-name-method vec))
1913 (user (tramp-file-name-user vec))
1914 (domain (tramp-file-name-domain vec))
1915 (host (tramp-file-name-host vec))
1916 (port (tramp-file-name-port vec))
1917 (localname
1918 (tramp-get-connection-property vec "default-location" nil)))
1919 (cond
1920 (localname
1921 (tramp-compat-file-attribute-group-id
1922 (file-attributes
1923 (tramp-make-tramp-file-name method user domain host port localname)
1924 id-format)))
1925 ((equal id-format 'integer) tramp-unknown-id-integer)
1926 ((equal id-format 'string) tramp-unknown-id-string)))))
1928 (defvar tramp-gvfs-get-remote-uid-gid-in-progress nil
1929 "Indication, that remote uid and gid determination is in progress.")
1931 (defun tramp-gvfs-get-remote-prefix (vec)
1932 "The prefix of the remote connection VEC.
1933 This is relevant for GNOME Online Accounts."
1934 (with-tramp-connection-property vec "prefix"
1935 ;; Ensure that GNOME Online Accounts are cached.
1936 (when (member (tramp-file-name-method vec) tramp-goa-methods)
1937 (tramp-get-goa-accounts vec))
1938 (tramp-get-connection-property
1939 (make-tramp-goa-name
1940 :method (tramp-file-name-method vec)
1941 :user (tramp-file-name-user vec)
1942 :host (tramp-file-name-host vec)
1943 :port (tramp-file-name-port vec))
1944 "prefix" "/")))
1946 (defun tramp-gvfs-maybe-open-connection (vec)
1947 "Maybe open a connection VEC.
1948 Does not do anything if a connection is already open, but re-opens the
1949 connection if a previous connection has died for some reason."
1950 ;; We set the file name, in case there are incoming D-Bus signals or
1951 ;; D-Bus errors.
1952 (setq tramp-gvfs-dbus-event-vector vec)
1954 ;; For password handling, we need a process bound to the connection
1955 ;; buffer. Therefore, we create a dummy process. Maybe there is a
1956 ;; better solution?
1957 (unless (get-buffer-process (tramp-get-connection-buffer vec))
1958 (let ((p (make-network-process
1959 :name (tramp-buffer-name vec)
1960 :buffer (tramp-get-connection-buffer vec)
1961 :server t :host 'local :service t :noquery t)))
1962 (process-put p 'vector vec)
1963 (set-process-query-on-exit-flag p nil)))
1965 (unless (tramp-gvfs-connection-mounted-p vec)
1966 (let* ((method (tramp-file-name-method vec))
1967 (user (tramp-file-name-user vec))
1968 (domain (tramp-file-name-domain vec))
1969 (host (tramp-file-name-host vec))
1970 (port (tramp-file-name-port vec))
1971 (localname (tramp-file-name-unquote-localname vec))
1972 (object-path
1973 (tramp-gvfs-object-path
1974 (tramp-make-tramp-file-name method user domain host port ""))))
1976 (when (and (string-equal method "afp")
1977 (string-equal localname "/"))
1978 (tramp-error vec 'file-error "Filename must contain an AFP volume"))
1980 (when (and (string-match method "davs?")
1981 (string-equal localname "/"))
1982 (tramp-error vec 'file-error "Filename must contain a WebDAV share"))
1984 (when (and (string-equal method "smb")
1985 (string-equal localname "/"))
1986 (tramp-error vec 'file-error "Filename must contain a Windows share"))
1988 (with-tramp-progress-reporter
1989 vec 3
1990 (if (zerop (length user))
1991 (format "Opening connection for %s using %s" host method)
1992 (format "Opening connection for %s@%s using %s" user host method))
1994 ;; Enable `auth-source'.
1995 (tramp-set-connection-property
1996 vec "first-password-request" tramp-cache-read-persistent-data)
1998 ;; There will be a callback of "askPassword" when a password is needed.
1999 (dbus-register-method
2000 :session dbus-service-emacs object-path
2001 tramp-gvfs-interface-mountoperation "askPassword"
2002 'tramp-gvfs-handler-askpassword)
2003 (dbus-register-method
2004 :session dbus-service-emacs object-path
2005 tramp-gvfs-interface-mountoperation "AskPassword"
2006 'tramp-gvfs-handler-askpassword)
2008 ;; There could be a callback of "askQuestion" when adding
2009 ;; fingerprints or checking certificates.
2010 (dbus-register-method
2011 :session dbus-service-emacs object-path
2012 tramp-gvfs-interface-mountoperation "askQuestion"
2013 'tramp-gvfs-handler-askquestion)
2014 (dbus-register-method
2015 :session dbus-service-emacs object-path
2016 tramp-gvfs-interface-mountoperation "AskQuestion"
2017 'tramp-gvfs-handler-askquestion)
2019 ;; The call must be asynchronously, because of the "askPassword"
2020 ;; or "askQuestion" callbacks.
2021 (if (string-match "(so)$" tramp-gvfs-mountlocation-signature)
2022 (with-tramp-dbus-call-method vec nil
2023 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
2024 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation
2025 (tramp-gvfs-mount-spec vec)
2026 `(:struct :string ,(dbus-get-unique-name :session)
2027 :object-path ,object-path))
2028 (with-tramp-dbus-call-method vec nil
2029 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
2030 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation
2031 (tramp-gvfs-mount-spec vec)
2032 :string (dbus-get-unique-name :session) :object-path object-path))
2034 ;; We must wait, until the mount is applied. This will be
2035 ;; indicated by the "mounted" signal, i.e. the "fuse-mountpoint"
2036 ;; file property.
2037 (with-timeout
2038 ((or (tramp-get-method-parameter vec 'tramp-connection-timeout)
2039 tramp-connection-timeout)
2040 (if (zerop (length (tramp-file-name-user vec)))
2041 (tramp-error
2042 vec 'file-error
2043 "Timeout reached mounting %s using %s" host method)
2044 (tramp-error
2045 vec 'file-error
2046 "Timeout reached mounting %s@%s using %s" user host method)))
2047 (while (not (tramp-get-file-property vec "/" "fuse-mountpoint" nil))
2048 (read-event nil nil 0.1)))
2050 ;; If `tramp-gvfs-handler-askquestion' has returned "No", it
2051 ;; is marked with the fuse-mountpoint "/". We shall react.
2052 (when (string-equal
2053 (tramp-get-file-property vec "/" "fuse-mountpoint" "") "/")
2054 (tramp-error vec 'file-error "FUSE mount denied"))
2056 ;; Save the password.
2057 (ignore-errors (funcall tramp-password-save-function))
2059 ;; Set connection-local variables.
2060 (tramp-set-connection-local-variables vec)
2062 ;; Mark it as connected.
2063 (tramp-set-connection-property
2064 (tramp-get-connection-process vec) "connected" t))))
2066 ;; In `tramp-check-cached-permissions', the connection properties
2067 ;; {uig,gid}-{integer,string} are used. We set them to proper values.
2068 (unless tramp-gvfs-get-remote-uid-gid-in-progress
2069 (let ((tramp-gvfs-get-remote-uid-gid-in-progress t))
2070 (tramp-gvfs-get-remote-uid vec 'integer)
2071 (tramp-gvfs-get-remote-gid vec 'integer)
2072 (tramp-gvfs-get-remote-uid vec 'string)
2073 (tramp-gvfs-get-remote-gid vec 'string))))
2075 (defun tramp-gvfs-gio-tool-p (vec)
2076 "Check, whether the gio tool is available."
2077 (with-tramp-connection-property vec "gio-tool"
2078 (zerop (tramp-call-process vec "gio" nil nil nil "version"))))
2080 (defun tramp-gvfs-send-command (vec command &rest args)
2081 "Send the COMMAND with its ARGS to connection VEC.
2082 COMMAND is a command from the gvfs-* utilities. It is replaced
2083 by the corresponding gio tool call if available. `call-process'
2084 is applied, and it returns t if the return code is zero."
2085 (let* ((locale (tramp-get-local-locale vec))
2086 (process-environment
2087 (append
2088 `(,(format "LANG=%s" locale)
2089 ,(format "LANGUAGE=%s" locale)
2090 ,(format "LC_ALL=%s" locale))
2091 process-environment)))
2092 (when (tramp-gvfs-gio-tool-p vec)
2093 ;; Use gio tool.
2094 (setq args (cons (cdr (assoc command tramp-gvfs-gio-mapping)) args)
2095 command "gio"))
2097 (with-current-buffer (tramp-get-connection-buffer vec)
2098 (tramp-gvfs-maybe-open-connection vec)
2099 (erase-buffer)
2100 (or (zerop (apply 'tramp-call-process vec command nil t nil args))
2101 ;; Remove information about mounted connection.
2102 (and (tramp-flush-file-properties vec "/") nil)))))
2105 ;; D-Bus GNOME Online Accounts functions.
2107 (defun tramp-get-goa-accounts (vec)
2108 "Retrieve GNOME Online Accounts, and cache them.
2109 The hash key is a `tramp-goa-name' structure. The value is an
2110 alist of the properties of `tramp-goa-interface-account' and
2111 `tramp-goa-interface-files' of the corresponding GNOME online
2112 account. Additionally, a property \"prefix\" is added.
2113 VEC is used only for traces."
2114 (dolist
2115 (object-path
2116 (mapcar
2117 'car
2118 (tramp-dbus-function
2119 vec 'dbus-get-all-managed-objects
2120 `(:session ,tramp-goa-service ,tramp-goa-path))))
2121 (let* ((account-properties
2122 (with-tramp-dbus-get-all-properties vec
2123 :session tramp-goa-service object-path
2124 tramp-goa-interface-account))
2125 (files-properties
2126 (with-tramp-dbus-get-all-properties vec
2127 :session tramp-goa-service object-path
2128 tramp-goa-interface-files))
2129 (identity
2130 (or (cdr (assoc "PresentationIdentity" account-properties)) ""))
2131 key)
2132 ;; Only accounts which matter.
2133 (when (and
2134 (not (cdr (assoc "FilesDisabled" account-properties)))
2135 (member
2136 (cdr (assoc "ProviderType" account-properties))
2137 '("google" "owncloud"))
2138 (string-match tramp-goa-identity-regexp identity))
2139 (setq key (make-tramp-goa-name
2140 :method (cdr (assoc "ProviderType" account-properties))
2141 :user (match-string 1 identity)
2142 :host (match-string 2 identity)
2143 :port (match-string 3 identity)))
2144 (when (string-equal (tramp-goa-name-method key) "google")
2145 (setf (tramp-goa-name-method key) "gdrive"))
2146 ;; Cache all properties.
2147 (dolist (prop (nconc account-properties files-properties))
2148 (tramp-set-connection-property key (car prop) (cdr prop)))
2149 ;; Cache "prefix".
2150 (tramp-message
2151 vec 10 "%s prefix %s" key
2152 (tramp-set-connection-property
2153 key "prefix"
2154 (directory-file-name
2155 (url-filename
2156 (url-generic-parse-url
2157 (tramp-get-connection-property key "Uri" "file:///"))))))))))
2160 ;; D-Bus BLUEZ functions.
2162 (defun tramp-bluez-address (device)
2163 "Return bluetooth device address from a given bluetooth DEVICE name."
2164 (when (stringp device)
2165 (if (string-match tramp-ipv6-regexp device)
2166 (match-string 0 device)
2167 (cadr (assoc device (tramp-bluez-list-devices))))))
2169 (defun tramp-bluez-device (address)
2170 "Return bluetooth device name from a given bluetooth device ADDRESS.
2171 ADDRESS can have the form \"xx:xx:xx:xx:xx:xx\" or \"[xx:xx:xx:xx:xx:xx]\"."
2172 (when (stringp address)
2173 (while (string-match "[][]" address)
2174 (setq address (replace-match "" t t address)))
2175 (let (result)
2176 (dolist (item (tramp-bluez-list-devices) result)
2177 (when (string-match address (cadr item))
2178 (setq result (car item)))))))
2180 (defun tramp-bluez-list-devices ()
2181 "Return all discovered bluetooth devices as list.
2182 Every entry is a list (NAME ADDRESS).
2184 If `tramp-bluez-discover-devices-timeout' is an integer, and the last
2185 discovery happened more time before indicated there, a rescan will be
2186 started, which lasts some ten seconds. Otherwise, cached results will
2187 be used."
2188 ;; Reset the scanned devices list if time has passed.
2189 (and (integerp tramp-bluez-discover-devices-timeout)
2190 (integerp tramp-bluez-discovery)
2191 (> (tramp-time-diff (current-time) tramp-bluez-discovery)
2192 tramp-bluez-discover-devices-timeout)
2193 (setq tramp-bluez-devices nil))
2195 ;; Rescan if needed.
2196 (unless tramp-bluez-devices
2197 (let ((object-path
2198 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
2199 :system tramp-bluez-service "/"
2200 tramp-bluez-interface-manager "DefaultAdapter")))
2201 (setq tramp-bluez-devices nil
2202 tramp-bluez-discovery t)
2203 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector nil
2204 :system tramp-bluez-service object-path
2205 tramp-bluez-interface-adapter "StartDiscovery")
2206 (while tramp-bluez-discovery
2207 (read-event nil nil 0.1))))
2208 (setq tramp-bluez-discovery (current-time))
2209 (tramp-message tramp-gvfs-dbus-event-vector 10 "%s" tramp-bluez-devices)
2210 tramp-bluez-devices)
2212 (defun tramp-bluez-property-changed (property value)
2213 "Signal handler for the \"org.bluez.Adapter.PropertyChanged\" signal."
2214 (tramp-message tramp-gvfs-dbus-event-vector 6 "%s %s" property value)
2215 (cond
2216 ((string-equal property "Discovering")
2217 (unless (car value)
2218 ;; "Discovering" FALSE means discovery run has been completed.
2219 ;; We stop it, because we don't need another run.
2220 (setq tramp-bluez-discovery nil)
2221 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
2222 :system tramp-bluez-service (dbus-event-path-name last-input-event)
2223 tramp-bluez-interface-adapter "StopDiscovery")))))
2225 (when tramp-gvfs-enabled
2226 (dbus-register-signal
2227 :system nil nil tramp-bluez-interface-adapter "PropertyChanged"
2228 'tramp-bluez-property-changed))
2230 (defun tramp-bluez-device-found (device args)
2231 "Signal handler for the \"org.bluez.Adapter.DeviceFound\" signal."
2232 (tramp-message tramp-gvfs-dbus-event-vector 6 "%s %s" device args)
2233 (let ((alias (car (cadr (assoc "Alias" args))))
2234 (address (car (cadr (assoc "Address" args)))))
2235 ;; Maybe we shall check the device class for being a proper
2236 ;; device, and call also SDP in order to find the obex service.
2237 (add-to-list 'tramp-bluez-devices (list alias address))))
2239 (when tramp-gvfs-enabled
2240 (dbus-register-signal
2241 :system nil nil tramp-bluez-interface-adapter "DeviceFound"
2242 'tramp-bluez-device-found))
2244 (defun tramp-bluez-parse-device-names (_ignore)
2245 "Return a list of (nil host) tuples allowed to access."
2246 (mapcar
2247 (lambda (x) (list nil (car x)))
2248 (tramp-bluez-list-devices)))
2250 ;; Add completion function for OBEX method.
2251 (when (and tramp-gvfs-enabled
2252 (member tramp-bluez-service (dbus-list-known-names :system)))
2253 (tramp-set-completion-function
2254 "obex" '((tramp-bluez-parse-device-names ""))))
2257 ;; D-Bus zeroconf functions.
2259 (defun tramp-zeroconf-parse-device-names (service)
2260 "Return a list of (user host) tuples allowed to access."
2261 (mapcar
2262 (lambda (x)
2263 (let ((host (zeroconf-service-host x))
2264 (port (zeroconf-service-port x))
2265 (text (zeroconf-service-txt x))
2266 user)
2267 (when port
2268 (setq host (format "%s%s%d" host tramp-prefix-port-regexp port)))
2269 ;; A user is marked in a TXT field like "u=guest".
2270 (while text
2271 (when (string-match "u=\\(.+\\)$" (car text))
2272 (setq user (match-string 1 (car text))))
2273 (setq text (cdr text)))
2274 (list user host)))
2275 (zeroconf-list-services service)))
2277 ;; We use the TRIM argument of `split-string', which exist since Emacs
2278 ;; 24.4. I mask this for older Emacs versions, there is no harm.
2279 (defun tramp-gvfs-parse-device-names (service)
2280 "Return a list of (user host) tuples allowed to access.
2281 This uses \"avahi-browse\" in case D-Bus is not enabled in Avahi."
2282 (let ((result
2283 (ignore-errors
2284 (tramp-compat-funcall
2285 'split-string
2286 (shell-command-to-string (format "avahi-browse -trkp %s" service))
2287 "[\n\r]+" 'omit "^\\+;.*$"))))
2288 (delete-dups
2289 (mapcar
2290 (lambda (x)
2291 (let* ((list (split-string x ";"))
2292 (host (nth 6 list))
2293 (text (tramp-compat-funcall
2294 'split-string (nth 9 list) "\" \"" 'omit "\""))
2295 user)
2296 ;; A user is marked in a TXT field like "u=guest".
2297 (while text
2298 (when (string-match "u=\\(.+\\)$" (car text))
2299 (setq user (match-string 1 (car text))))
2300 (setq text (cdr text)))
2301 (list user host)))
2302 result))))
2304 ;; Add completion functions for AFP, DAV, DAVS, SFTP and SMB methods.
2305 (when tramp-gvfs-enabled
2306 ;; Suppress D-Bus error messages.
2307 (let (tramp-gvfs-dbus-event-vector)
2308 (zeroconf-init tramp-gvfs-zeroconf-domain)
2309 (if (zeroconf-list-service-types)
2310 (progn
2311 (tramp-set-completion-function
2312 "afp" '((tramp-zeroconf-parse-device-names "_afpovertcp._tcp")))
2313 (tramp-set-completion-function
2314 "dav" '((tramp-zeroconf-parse-device-names "_webdav._tcp")))
2315 (tramp-set-completion-function
2316 "davs" '((tramp-zeroconf-parse-device-names "_webdav._tcp")))
2317 (tramp-set-completion-function
2318 "sftp" '((tramp-zeroconf-parse-device-names "_ssh._tcp")
2319 (tramp-zeroconf-parse-device-names "_workstation._tcp")))
2320 (when (member "smb" tramp-gvfs-methods)
2321 (tramp-set-completion-function
2322 "smb" '((tramp-zeroconf-parse-device-names "_smb._tcp")))))
2324 (when (executable-find "avahi-browse")
2325 (tramp-set-completion-function
2326 "afp" '((tramp-gvfs-parse-device-names "_afpovertcp._tcp")))
2327 (tramp-set-completion-function
2328 "dav" '((tramp-gvfs-parse-device-names "_webdav._tcp")))
2329 (tramp-set-completion-function
2330 "davs" '((tramp-gvfs-parse-device-names "_webdav._tcp")))
2331 (tramp-set-completion-function
2332 "sftp" '((tramp-gvfs-parse-device-names "_ssh._tcp")
2333 (tramp-gvfs-parse-device-names "_workstation._tcp")))
2334 (when (member "smb" tramp-gvfs-methods)
2335 (tramp-set-completion-function
2336 "smb" '((tramp-gvfs-parse-device-names "_smb._tcp"))))))))
2339 ;; D-Bus SYNCE functions.
2341 (defun tramp-synce-list-devices ()
2342 "Return all discovered synce devices as list.
2343 They are retrieved from the hal daemon."
2344 (let (tramp-synce-devices)
2345 (dolist (device
2346 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
2347 :system tramp-hal-service tramp-hal-path-manager
2348 tramp-hal-interface-manager "GetAllDevices"))
2349 (when (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
2350 :system tramp-hal-service device tramp-hal-interface-device
2351 "PropertyExists" "sync.plugin")
2352 (let ((prop
2353 (with-tramp-dbus-call-method
2354 tramp-gvfs-dbus-event-vector t
2355 :system tramp-hal-service device tramp-hal-interface-device
2356 "GetPropertyString" "pda.pocketpc.name")))
2357 (unless (member prop tramp-synce-devices)
2358 (push prop tramp-synce-devices)))))
2359 (tramp-message tramp-gvfs-dbus-event-vector 10 "%s" tramp-synce-devices)
2360 tramp-synce-devices))
2362 (defun tramp-synce-parse-device-names (_ignore)
2363 "Return a list of (nil host) tuples allowed to access."
2364 (mapcar
2365 (lambda (x) (list nil x))
2366 (tramp-synce-list-devices)))
2368 ;; Add completion function for SYNCE method.
2369 (when tramp-gvfs-enabled
2370 (tramp-set-completion-function
2371 "synce" '((tramp-synce-parse-device-names ""))))
2373 (add-hook 'tramp-unload-hook
2374 (lambda ()
2375 (unload-feature 'tramp-gvfs 'force)))
2377 (provide 'tramp-gvfs)
2379 ;;; TODO:
2381 ;; * (Customizable) unmount when exiting Emacs. See tramp-archive.el.
2383 ;; * Host name completion for existing mount points (afp-server,
2384 ;; smb-server, google-drive, owncloud) or via smb-network or network.
2386 ;; * Check, how two shares of the same SMB server can be mounted in
2387 ;; parallel.
2389 ;; * Apply SDP on bluetooth devices, in order to filter out obex
2390 ;; capability.
2392 ;; * Implement obex for other serial communication but bluetooth.
2394 ;; * What's up with ftps dns-sd afc admin computer?
2396 ;;; tramp-gvfs.el ends here