]> code.delx.au - gnu-emacs/blob - lisp/url/url-nfs.el
Use with-current-buffer.
[gnu-emacs] / lisp / url / url-nfs.el
1 ;;; url-nfs.el --- NFS URL interface
2 ;; Keywords: comm, data, processes
3
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5 ;;; Copyright (c) 1996 by William M. Perry <wmperry@cs.indiana.edu>
6 ;;; Copyright (c) 1996 - 1999 Free Software Foundation, Inc.
7 ;;;
8 ;;; This file is part of GNU Emacs.
9 ;;;
10 ;;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 2, or (at your option)
13 ;;; any later version.
14 ;;;
15 ;;; GNU Emacs is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
19 ;;;
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;;; Boston, MA 02111-1307, USA.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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 (save-excursion
45 (set-buffer (get-buffer-create " *nfs-parse*"))
46 (erase-buffer)
47 (insert format)
48 (goto-char (point-min))
49 (while (re-search-forward "%\\(.\\)" nil t)
50 (let ((escape (aref (match-string 1) 0)))
51 (replace-match "" t t)
52 (case escape
53 (?% (insert "%"))
54 (?h (insert host))
55 (?n (insert (or port "")))
56 (?u (insert (or user "")))
57 (?p (insert (or pass "")))
58 (?f (insert (or file "/"))))))
59 (buffer-string)))
60
61 (defun url-nfs-build-filename (url)
62 (let* ((host (url-host url))
63 (port (string-to-int (url-port url)))
64 (pass (url-password url))
65 (user (url-user url))
66 (file (url-filename url)))
67 (url-generic-parse-url
68 (url-nfs-unescape url-nfs-automounter-directory-spec
69 host port user pass file))))
70
71 (defun url-nfs (url callback cbargs)
72 (url-file (url-nfs-build-filename url) callback cbargs))
73
74 (defmacro url-nfs-create-wrapper (method args)
75 (` (defun (, (intern (format "url-nfs-%s" method))) (, args)
76 (, (format "NFS URL wrapper around `%s' call." method))
77 (setq url (url-nfs-build-filename url))
78 (and url ((, (intern (format "url-file-%s" method)))
79 (,@ (remove '&rest (remove '&optional args))))))))
80
81 (url-nfs-create-wrapper file-exists-p (url))
82 (url-nfs-create-wrapper file-attributes (url))
83 (url-nfs-create-wrapper file-symlink-p (url))
84 (url-nfs-create-wrapper file-readable-p (url))
85 (url-nfs-create-wrapper file-writable-p (url))
86 (url-nfs-create-wrapper file-executable-p (url))
87 (if (featurep 'xemacs)
88 (progn
89 (url-nfs-create-wrapper directory-files (url &optional full match nosort files-only))
90 (url-nfs-create-wrapper file-truename (url &optional default)))
91 (url-nfs-create-wrapper directory-files (url &optional full match nosort))
92 (url-nfs-create-wrapper file-truename (url &optional counter prev-dirs)))
93
94 (provide 'url-nfs)
95
96 ;;; arch-tag: cdf9c9ba-b7d2-4c29-8b48-7ae9bbc0d437