Initial Commit
[packages] / xemacs-packages / w3 / lisp / url-nfs.el
1 ;;; url-nfs.el --- NFS URL interface
2
3 ;; Copyright (C) 1996-1999, 2004-2012 Free Software Foundation, Inc.
4
5 ;; Keywords: comm, data, processes
6
7 ;; This file is part of GNU Emacs.
8 ;;
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
13
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.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
21
22 ;;; Commentary:
23
24 ;;; Code:
25
26 (eval-when-compile (require 'cl))
27 (require 'url-parse)
28 (require 'url-file)
29
30 (defvar url-nfs-automounter-directory-spec
31   "file:/net/%h%f"
32   "How to invoke the NFS automounter.  Certain % sequences are recognized.
33
34 %h -- the hostname of the NFS server
35 %n -- the port # of the NFS server
36 %u -- the username to use to authenticate
37 %p -- the password to use to authenticate
38 %f -- the filename on the remote server
39 %% -- a literal %
40
41 Each can be used any number of times.")
42
43 (defun url-nfs-unescape (format host port user pass file)
44   (with-current-buffer (get-buffer-create " *nfs-parse*")
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)
51          (case escape
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))
62          (port (url-port url))
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)
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))))))
79
80 (url-nfs-create-wrapper file-exists-p (url))
81 (url-nfs-create-wrapper file-attributes (url &optional id-format))
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))
86 (url-nfs-create-wrapper directory-files (url &optional full match nosort))
87 (url-nfs-create-wrapper file-truename (url &optional counter prev-dirs))
88
89 (provide 'url-nfs)
90
91 ;;; url-nfs.el ends here