annotate lisp/net/netrc.el @ 107853:de5ba6f3514c

Bind `C-v' to `scroll-up-command' and `M-v' to `scroll-down-command'. http://lists.gnu.org/archive/html/emacs-devel/2010-04/msg00403.html * window.c (keys_of_window): Rebind `C-v' from `scroll-up' to `scroll-up-command' and `M-v' from `scroll-down' to `scroll-down-command'. * tutorial.el (tutorial--default-keys): Rebind `C-v' to `scroll-up-command' and `M-v' to `scroll-down-command'. * emulation/cua-rect.el (cua--init-rectangles): * forms.el (forms--change-commands): * image-mode.el (image-mode-map): Remap scroll-down-command and scroll-up-command in addition to scroll-down and scroll-up.
author Juri Linkov <juri@jurta.org>
date Wed, 14 Apr 2010 03:33:32 +0300
parents bb307bf2e752
children 8d09094063d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; netrc.el --- .netrc parsing functionality
64701
34bd8e434dd7 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64085
diff changeset
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 101804
diff changeset
3 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: news
107390
bb307bf2e752 Fix keywords.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
7 ;;
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Modularized by Ted Zlatanov <tzz@lifelogs.com>
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; when it was part of Gnus.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
15 ;; the Free Software Foundation, either version 3 of the License, or
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
16 ;; (at your option) any later version.
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; Just the .netrc parsing functionality, abstracted so other packages
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; besides Gnus can use it.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;; Code:
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;;
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
34 ;;; .netrc and .authinfo rc parsing
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;;
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36
87454
0cbc451989a7 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 86963
diff changeset
37 ;; use encrypt if loaded (encrypt-file-alist has to be set as well)
95624
164c226d4a0d Remove unnecessary eval-when-compiles and eval-and-compiles.
Glenn Morris <rgm@gnu.org>
parents: 95193
diff changeset
38 (autoload 'encrypt-find-model "encrypt")
164c226d4a0d Remove unnecessary eval-when-compiles and eval-and-compiles.
Glenn Morris <rgm@gnu.org>
parents: 95193
diff changeset
39 (autoload 'encrypt-insert-file-contents "encrypt")
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 (defalias 'netrc-point-at-eol
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 (if (fboundp 'point-at-eol)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 'point-at-eol
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 'line-end-position))
95624
164c226d4a0d Remove unnecessary eval-when-compiles and eval-and-compiles.
Glenn Morris <rgm@gnu.org>
parents: 95193
diff changeset
44 (defvar encrypt-file-alist)
87454
0cbc451989a7 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 86963
diff changeset
45 (eval-when-compile
0cbc451989a7 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 86963
diff changeset
46 ;; This is unnecessary in the compiled version as it is a macro.
0cbc451989a7 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 86963
diff changeset
47 (if (fboundp 'bound-and-true-p)
0cbc451989a7 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 86963
diff changeset
48 (defalias 'netrc-bound-and-true-p 'bound-and-true-p)
0cbc451989a7 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 86963
diff changeset
49 (defmacro netrc-bound-and-true-p (var)
0cbc451989a7 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 86963
diff changeset
50 "Return the value of symbol VAR if it is bound, else nil."
0cbc451989a7 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 86963
diff changeset
51 `(and (boundp (quote ,var)) ,var))))
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
52
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
53 (defgroup netrc nil
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
54 "Netrc configuration."
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
55 :group 'comm)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
56
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
57 (defvar netrc-services-file "/etc/services"
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
58 "The name of the services file.")
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (defun netrc-parse (file)
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
61 (interactive "fFile to Parse: ")
92694
d3767aa9ae49 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 87649
diff changeset
62 "Parse FILE and return a list of all entries in the file."
99506
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
63 (if (listp file)
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
64 file
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
65 (when (file-exists-p file)
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
66 (with-temp-buffer
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
67 (let ((tokens '("machine" "default" "login"
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
68 "password" "account" "macdef" "force"
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
69 "port"))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
70 (encryption-model (when (netrc-bound-and-true-p encrypt-file-alist)
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
71 (encrypt-find-model file)))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
72 alist elem result pair)
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
73 (if encryption-model
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
74 (encrypt-insert-file-contents file encryption-model)
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
75 (insert-file-contents file))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
76 (goto-char (point-min))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
77 ;; Go through the file, line by line.
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (while (not (eobp))
99506
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
79 (narrow-to-region (point) (point-at-eol))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
80 ;; For each line, get the tokens and values.
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
81 (while (not (eobp))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
82 (skip-chars-forward "\t ")
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
83 ;; Skip lines that begin with a "#".
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
84 (if (eq (char-after) ?#)
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
85 (goto-char (point-max))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
86 (unless (eobp)
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
87 (setq elem
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
88 (if (= (following-char) ?\")
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
89 (read (current-buffer))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
90 (buffer-substring
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
91 (point) (progn (skip-chars-forward "^\t ")
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
92 (point)))))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
93 (cond
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
94 ((equal elem "macdef")
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
95 ;; We skip past the macro definition.
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
96 (widen)
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
97 (while (and (zerop (forward-line 1))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
98 (looking-at "$")))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
99 (narrow-to-region (point) (point)))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
100 ((member elem tokens)
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
101 ;; Tokens that don't have a following value are ignored,
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
102 ;; except "default".
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
103 (when (and pair (or (cdr pair)
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
104 (equal (car pair) "default")))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
105 (push pair alist))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
106 (setq pair (list elem)))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
107 (t
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
108 ;; Values that haven't got a preceding token are ignored.
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
109 (when pair
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
110 (setcdr pair elem)
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
111 (push pair alist)
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
112 (setq pair nil)))))))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
113 (when alist
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
114 (push (nreverse alist) result))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
115 (setq alist nil
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
116 pair nil)
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
117 (widen)
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
118 (forward-line 1))
fa1e1238846b Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 95624
diff changeset
119 (nreverse result))))))
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (defun netrc-machine (list machine &optional port defaultport)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 "Return the netrc values from LIST for MACHINE or for the default entry.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 If PORT specified, only return entries with matching port tokens.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 Entries without port tokens default to DEFAULTPORT."
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (let ((rest list)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 result)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (while list
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (when (equal (cdr (assoc "machine" (car list))) machine)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (push (car list) result))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (pop list))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (unless result
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 ;; No machine name matches, so we look for default entries.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (while rest
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (when (assoc "default" (car rest))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (push (car rest) result))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (pop rest)))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (when result
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (setq result (nreverse result))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (while (and result
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
140 (not (netrc-port-equal
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
141 (or port defaultport "nntp")
95193
d90ff358ee27 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94677
diff changeset
142 ;; when port is not given in the netrc file,
d90ff358ee27 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94677
diff changeset
143 ;; it should mean "any port"
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
144 (or (netrc-get (car result) "port")
95193
d90ff358ee27 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94677
diff changeset
145 defaultport port))))
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (pop result))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (car result))))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
149 (defun netrc-machine-user-or-password (mode authinfo-file-or-list machines ports defaults)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
150 "Get the user name or password according to MODE from AUTHINFO-FILE-OR-LIST.
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
151 Matches a machine from MACHINES and a port from PORTS, giving
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
152 default ports DEFAULTS to `netrc-machine'.
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
153
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
154 MODE can be \"login\" or \"password\", suitable for passing to
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
155 `netrc-get'."
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
156 (let ((authinfo-list (if (stringp authinfo-file-or-list)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
157 (netrc-parse authinfo-file-or-list)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
158 authinfo-file-or-list))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
159 (ports (or ports '(nil)))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
160 (defaults (or defaults '(nil)))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
161 info)
101804
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 100908
diff changeset
162 (if (listp mode)
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 100908
diff changeset
163 (setq info
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 100908
diff changeset
164 (mapcar
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 100908
diff changeset
165 (lambda (mode-element)
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 100908
diff changeset
166 (netrc-machine-user-or-password
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 100908
diff changeset
167 mode-element
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 100908
diff changeset
168 authinfo-list
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 100908
diff changeset
169 machines
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 100908
diff changeset
170 ports
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 100908
diff changeset
171 defaults))
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 100908
diff changeset
172 mode))
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 100908
diff changeset
173 (dolist (machine machines)
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 100908
diff changeset
174 (dolist (default defaults)
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 100908
diff changeset
175 (dolist (port ports)
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 100908
diff changeset
176 (let ((alist (netrc-machine authinfo-list machine port default)))
d775b84fdd71 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 100908
diff changeset
177 (setq info (or (netrc-get alist mode) info)))))))
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
178 info))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
179
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (defun netrc-get (alist type)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 "Return the value of token TYPE from ALIST."
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (cdr (assoc type alist)))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
184 (defun netrc-port-equal (port1 port2)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
185 (when (numberp port1)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
186 (setq port1 (or (netrc-find-service-name port1) port1)))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
187 (when (numberp port2)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
188 (setq port2 (or (netrc-find-service-name port2) port2)))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
189 (equal port1 port2))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
190
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
191 (defun netrc-parse-services ()
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
192 (when (file-exists-p netrc-services-file)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
193 (let ((services nil))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
194 (with-temp-buffer
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
195 (insert-file-contents netrc-services-file)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
196 (while (search-forward "#" nil t)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
197 (delete-region (1- (point)) (point-at-eol)))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
198 (goto-char (point-min))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
199 (while (re-search-forward
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
200 "^ *\\([^ \n\t]+\\)[ \t]+\\([0-9]+\\)/\\([^ \t\n]+\\)" nil t)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
201 (push (list (match-string 1) (string-to-number (match-string 2))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
202 (intern (downcase (match-string 3))))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
203 services))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
204 (nreverse services)))))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
205
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
206 (defun netrc-find-service-name (number &optional type)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
207 (let ((services (netrc-parse-services))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
208 service)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
209 (setq type (or type 'tcp))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
210 (while (and (setq service (pop services))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
211 (not (and (= number (cadr service))
86963
d549ccffa35b (top-level): Don't load `encrypt' features.
Glenn Morris <rgm@gnu.org>
parents: 85712
diff changeset
212 (eq type (car (cddr service)))))))
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
213 (car service)))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
214
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
215 (defun netrc-find-service-number (name &optional type)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
216 (let ((services (netrc-parse-services))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
217 service)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
218 (setq type (or type 'tcp))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
219 (while (and (setq service (pop services))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
220 (not (and (string= name (car service))
86963
d549ccffa35b (top-level): Don't load `encrypt' features.
Glenn Morris <rgm@gnu.org>
parents: 85712
diff changeset
221 (eq type (car (cddr service)))))))
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
222 (cadr service)))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
223
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (provide 'netrc)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92694
diff changeset
226 ;; arch-tag: af9929cc-2d12-482f-936e-eb4366f9fa55
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 ;;; netrc.el ends here