guile feature
[bpt/emacs.git] / lisp / url / url-nfs.el
CommitLineData
8c8b8430 1;;; url-nfs.el --- NFS URL interface
abbcaa05 2
ba318903 3;; Copyright (C) 1996-1999, 2004-2014 Free Software Foundation, Inc.
abbcaa05 4
8c8b8430
SM
5;; Keywords: comm, data, processes
6
abbcaa05
SM
7;; This file is part of GNU Emacs.
8;;
4936186e 9;; GNU Emacs is free software: you can redistribute it and/or modify
abbcaa05 10;; it under the terms of the GNU General Public License as published by
4936186e
GM
11;; the Free Software Foundation, either version 3 of the License, or
12;; (at your option) any later version.
13
abbcaa05
SM
14;; GNU Emacs is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details.
4936186e 18
abbcaa05 19;; You should have received a copy of the GNU General Public License
4936186e 20;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
abbcaa05
SM
21
22;;; Commentary:
23
24;;; Code:
8c8b8430 25
8c8b8430
SM
26(require 'url-parse)
27(require 'url-file)
28
f1a4e679 29(defcustom url-nfs-automounter-directory-spec "file:/net/%h%f"
fb7ada5f 30 "How to invoke the NFS automounter. Certain % sequences are recognized.
8c8b8430
SM
31
32%h -- the hostname of the NFS server
33%n -- the port # of the NFS server
34%u -- the username to use to authenticate
35%p -- the password to use to authenticate
36%f -- the filename on the remote server
37%% -- a literal %
38
f1a4e679
CY
39Each can be used any number of times."
40 :group 'url
41 :type 'string)
8c8b8430
SM
42
43(defun url-nfs-unescape (format host port user pass file)
937e6a56 44 (with-current-buffer (get-buffer-create " *nfs-parse*")
8c8b8430
SM
45 (erase-buffer)
46 (insert format)
47 (goto-char (point-min))
48 (while (re-search-forward "%\\(.\\)" nil t)
49 (let ((escape (aref (match-string 1) 0)))
50 (replace-match "" t t)
a464a6c7 51 (pcase escape
8c8b8430
SM
52 (?% (insert "%"))
53 (?h (insert host))
54 (?n (insert (or port "")))
55 (?u (insert (or user "")))
56 (?p (insert (or pass "")))
57 (?f (insert (or file "/"))))))
58 (buffer-string)))
59
60(defun url-nfs-build-filename (url)
61 (let* ((host (url-host url))
60b5eb78 62 (port (url-port url))
8c8b8430
SM
63 (pass (url-password url))
64 (user (url-user url))
65 (file (url-filename url)))
66 (url-generic-parse-url
67 (url-nfs-unescape url-nfs-automounter-directory-spec
68 host port user pass file))))
69
70(defun url-nfs (url callback cbargs)
71 (url-file (url-nfs-build-filename url) callback cbargs))
72
73(defmacro url-nfs-create-wrapper (method args)
abbcaa05
SM
74 `(defun ,(intern (format "url-nfs-%s" method)) ,args
75 ,(format "NFS URL wrapper around `%s' call." method)
76 (setq url (url-nfs-build-filename url))
77 (and url (,(intern (format "url-file-%s" method))
78 ,@(remove '&rest (remove '&optional args))))))
8c8b8430
SM
79
80(url-nfs-create-wrapper file-exists-p (url))
abbcaa05 81(url-nfs-create-wrapper file-attributes (url &optional id-format))
8c8b8430
SM
82(url-nfs-create-wrapper file-symlink-p (url))
83(url-nfs-create-wrapper file-readable-p (url))
84(url-nfs-create-wrapper file-writable-p (url))
85(url-nfs-create-wrapper file-executable-p (url))
cc38a294
EZ
86(url-nfs-create-wrapper directory-files (url &optional full match nosort))
87(url-nfs-create-wrapper file-truename (url &optional counter prev-dirs))
8c8b8430
SM
88
89(provide 'url-nfs)
e5566bd5 90
abbcaa05 91;;; url-nfs.el ends here