annotate lisp/net/netrc.el @ 86246:a01176901861

(cvs-revert-if-needed): Fix copy&paste typo.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 20 Nov 2007 04:04:45 +0000
parents a3c27999decb
children d549ccffa35b 880960b70474
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,
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 68648
diff changeset
3 ;; 2005, 2006, 2007 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
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Modularized by Ted Zlatanov <tzz@lifelogs.com>
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; when it was part of Gnus.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
78230
84cf1e2214c5 Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
14 ;; the Free Software Foundation; either version 3, or (at your option)
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; any later version.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
25 ;; Boston, MA 02110-1301, USA.
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; Just the .netrc parsing functionality, abstracted so other packages
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; besides Gnus can use it.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;;; Code:
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;;
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
35 ;;; .netrc and .authinfo rc parsing
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;;;
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 (defalias 'netrc-point-at-eol
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 (if (fboundp 'point-at-eol)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 'point-at-eol
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 'line-end-position))
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
42 ;; autoload encrypt
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
43
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
44 (eval-and-compile
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
45 (autoload 'encrypt-find-model "encrypt")
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
46 (autoload 'encrypt-insert-file-contents "encrypt"))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
47
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
48 (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
49 "Netrc configuration."
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
50 :group 'comm)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
51
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
52 (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
53 "The name of the services file.")
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (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
56 (interactive "fFile to Parse: ")
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
57 "Parse FILE and return an list of all entries in the file."
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (when (file-exists-p file)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (with-temp-buffer
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (let ((tokens '("machine" "default" "login"
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 "password" "account" "macdef" "force"
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 "port"))
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
63 (encryption-model (encrypt-find-model file))
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 alist elem result pair)
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
65
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
66 (if encryption-model
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
67 (encrypt-insert-file-contents file encryption-model)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
68 (insert-file-contents file))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
69
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (goto-char (point-min))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;; Go through the file, line by line.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (while (not (eobp))
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
73 (narrow-to-region (point) (point-at-eol))
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; For each line, get the tokens and values.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (while (not (eobp))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (skip-chars-forward "\t ")
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; Skip lines that begin with a "#".
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (if (eq (char-after) ?#)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (goto-char (point-max))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (unless (eobp)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (setq elem
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (if (= (following-char) ?\")
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (read (current-buffer))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (buffer-substring
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (point) (progn (skip-chars-forward "^\t ")
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 (point)))))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (cond
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ((equal elem "macdef")
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;; We skip past the macro definition.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (widen)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (while (and (zerop (forward-line 1))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (looking-at "$")))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (narrow-to-region (point) (point)))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ((member elem tokens)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;; Tokens that don't have a following value are ignored,
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;; except "default".
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (when (and pair (or (cdr pair)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (equal (car pair) "default")))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (push pair alist))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (setq pair (list elem)))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (t
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 ;; Values that haven't got a preceding token are ignored.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (when pair
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (setcdr pair elem)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (push pair alist)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (setq pair nil)))))))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (when alist
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (push (nreverse alist) result))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (setq alist nil
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 pair nil)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (widen)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (forward-line 1))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (nreverse result)))))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (defun netrc-machine (list machine &optional port defaultport)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 "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
117 If PORT specified, only return entries with matching port tokens.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 Entries without port tokens default to DEFAULTPORT."
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (let ((rest list)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 result)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (while list
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (when (equal (cdr (assoc "machine" (car list))) machine)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (push (car list) result))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (pop list))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (unless result
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 ;; No machine name matches, so we look for default entries.
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (while rest
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (when (assoc "default" (car rest))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (push (car rest) result))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (pop rest)))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (when result
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (setq result (nreverse result))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (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
134 (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
135 (or port defaultport "nntp")
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
136 (or (netrc-get (car result) "port")
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
137 defaultport "nntp"))))
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (pop result))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (car result))))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
141 (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
142 "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
143 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
144 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
145
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
146 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
147 `netrc-get'."
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
148 (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
149 (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
150 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 (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
152 (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
153 info)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
154 (dolist (machine machines)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
155 (dolist (default defaults)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
156 (dolist (port ports)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
157 (let ((alist (netrc-machine authinfo-list machine port default)))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
158 (setq info (or (netrc-get alist mode) info))))))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
159 info))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
160
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (defun netrc-get (alist type)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 "Return the value of token TYPE from ALIST."
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (cdr (assoc type alist)))
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164
85712
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
165 (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
166 (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
167 (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
168 (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
169 (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
170 (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
171
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
172 (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
173 (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
174 (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
175 (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
176 (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
177 (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
178 (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
179 (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
180 (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
181 "^ *\\([^ \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
182 (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
183 (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
184 services))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
185 (nreverse services)))))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
186
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
187 (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
188 (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
189 service)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
190 (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
191 (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
192 (not (and (= number (cadr service))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
193 (eq type (caddr service)))))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
194 )
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
195 (car service)))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
196
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
197 (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
198 (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
199 service)
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
200 (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
201 (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
202 (not (and (string= name (car service))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
203 (eq type (caddr service)))))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
204 )
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
205 (cadr service)))
a3c27999decb Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents: 78230
diff changeset
206
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (provide 'netrc)
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 47927
diff changeset
209 ;;; arch-tag: af9929cc-2d12-482f-936e-eb4366f9fa55
44810
c61f121692e4 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 ;;; netrc.el ends here