aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2011-03-29 22:21:28 -0400
committerChong Yidong2011-03-29 22:21:28 -0400
commite742e11707450212291d8e1c1bc13fbe51de1cb2 (patch)
tree24c9483345411b11befee44b72bb713f62f7b14b
parenteb7ffc147d1b6910e73b5323ecfa4cc45f7464a4 (diff)
downloademacs-e742e11707450212291d8e1c1bc13fbe51de1cb2.tar.gz
emacs-e742e11707450212291d8e1c1bc13fbe51de1cb2.zip
Change default type of open-protocol-stream.
* nnimap.el (nnimap-stream, nnimap-open-connection-1): Accept `network' value. * nntp.el (nntp-open-connection-function): Document the fact that some values are not functions but are instead handled specially. Recognize nntp-open-plain-stream value. (nntp-open-connection): Recognize that value. * proto-stream.el (open-protocol-stream): Bring back `network' type. Make this the default type. (proto-stream-open-plain): Rename from proto-stream-open-default. (open-protocol-stream, proto-stream-open-starttls) (proto-stream-open-tls, proto-stream-open-shell): Replace `default' with `plain'.
-rw-r--r--lisp/gnus/ChangeLog17
-rw-r--r--lisp/gnus/nnimap.el14
-rw-r--r--lisp/gnus/nntp.el50
-rw-r--r--lisp/gnus/proto-stream.el90
4 files changed, 94 insertions, 77 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog
index a6faaf036a5..f6b7db61d96 100644
--- a/lisp/gnus/ChangeLog
+++ b/lisp/gnus/ChangeLog
@@ -1,3 +1,20 @@
12011-03-30 Chong Yidong <cyd@stupidchicken.com>
2
3 * proto-stream.el (open-protocol-stream): Bring back `network' type.
4 Make this the default type.
5 (proto-stream-open-plain): Rename from proto-stream-open-default.
6 (open-protocol-stream, proto-stream-open-starttls)
7 (proto-stream-open-tls, proto-stream-open-shell): Replace `default'
8 with `plain'.
9
10 * nnimap.el (nnimap-stream, nnimap-open-connection-1): Accept `network'
11 value.
12
13 * nntp.el (nntp-open-connection-function): Document the fact that some
14 values are not functions but are instead handled specially. Recognize
15 nntp-open-plain-stream value.
16 (nntp-open-connection): Recognize that value.
17
12011-03-29 Julien Danjou <julien@danjou.info> 182011-03-29 Julien Danjou <julien@danjou.info>
2 19
3 * mm-view.el (mm-display-inline-fontify): Use `set-normal-mode' with 20 * mm-view.el (mm-display-inline-fontify): Use `set-normal-mode' with
diff --git a/lisp/gnus/nnimap.el b/lisp/gnus/nnimap.el
index 15d7f463d41..ccb082d6c71 100644
--- a/lisp/gnus/nnimap.el
+++ b/lisp/gnus/nnimap.el
@@ -61,10 +61,12 @@ If nnimap-stream is `ssl', this will default to `imaps'. If not,
61it will default to `imap'.") 61it will default to `imap'.")
62 62
63(defvoo nnimap-stream 'undecided 63(defvoo nnimap-stream 'undecided
64 "How nnimap will talk to the IMAP server. 64 "How nnimap talks to the IMAP server.
65Values are `ssl', `default', `try-starttls', `starttls' or 65The value should be either `undecided', `ssl' or `tls',
66`shell'. The default is to try `ssl' first, and then 66`network', `starttls', `plain', or `shell'.
67`try-starttls'.") 67
68If the value is `undecided', nnimap tries `ssl' first, then falls
69back on `network'.")
68 70
69(defvoo nnimap-shell-program (if (boundp 'imap-shell-program) 71(defvoo nnimap-shell-program (if (boundp 'imap-shell-program)
70 (if (listp imap-shell-program) 72 (if (listp imap-shell-program)
@@ -319,7 +321,7 @@ textual parts.")
319 (setq nnimap-stream 'ssl)) 321 (setq nnimap-stream 'ssl))
320 (let ((stream 322 (let ((stream
321 (if (eq nnimap-stream 'undecided) 323 (if (eq nnimap-stream 'undecided)
322 (loop for type in '(ssl try-starttls) 324 (loop for type in '(ssl network)
323 for stream = (let ((nnimap-stream type)) 325 for stream = (let ((nnimap-stream type))
324 (nnimap-open-connection-1 buffer)) 326 (nnimap-open-connection-1 buffer))
325 while (eq stream 'no-connect) 327 while (eq stream 'no-connect)
@@ -339,7 +341,7 @@ textual parts.")
339 (port nil) 341 (port nil)
340 (ports 342 (ports
341 (cond 343 (cond
342 ((memq nnimap-stream '(try-starttls default starttls)) 344 ((memq nnimap-stream '(network plain starttls))
343 (nnheader-message 7 "Opening connection to %s..." 345 (nnheader-message 7 "Opening connection to %s..."
344 nnimap-address) 346 nnimap-address)
345 '("imap" "143")) 347 '("imap" "143"))
diff --git a/lisp/gnus/nntp.el b/lisp/gnus/nntp.el
index 9065027d34f..fa765e17463 100644
--- a/lisp/gnus/nntp.el
+++ b/lisp/gnus/nntp.el
@@ -76,27 +76,27 @@ to innd, you could say something like:
76You probably don't want to do that, though.") 76You probably don't want to do that, though.")
77 77
78(defvoo nntp-open-connection-function 'nntp-open-network-stream 78(defvoo nntp-open-connection-function 'nntp-open-network-stream
79 "*Function used for connecting to a remote system. 79 "Method for connecting to a remote system.
80It will be called with the buffer to output in as argument. 80It should be a function, which is called with the output buffer
81 81as its single argument, or one of the following special values:
82Currently, five such functions are provided (please refer to their 82
83respective doc string for more information), three of them establishing 83- `nntp-open-network-stream' specifies a network connection,
84direct connections to the nntp server, and two of them using an indirect 84 upgrading to a TLS connection via STARTTLS if possible.
85host. 85- `nntp-open-plain-stream' specifies an unencrypted network
86 86 connection (no STARTTLS upgrade is attempted).
87Direct connections: 87- `nntp-open-ssl-stream' or `nntp-open-tls-stream' specify a TLS
88- `nntp-open-network-stream' (the default), 88 network connection.
89- `network-only' (the same as the above, but don't do automatic 89
90 STARTTLS upgrades). 90Apart from the above special values, valid functions are as
91- `nntp-open-ssl-stream', 91follows; please refer to their respective doc string for more
92- `nntp-open-tls-stream', 92information.
93- `nntp-open-netcat-stream'. 93For direct connections:
94- `nntp-open-telnet-stream'. 94- `nntp-open-netcat-stream'
95 95- `nntp-open-telnet-stream'
96Indirect connections: 96For indirect connections:
97- `nntp-open-via-rlogin-and-netcat', 97- `nntp-open-via-rlogin-and-netcat'
98- `nntp-open-via-rlogin-and-telnet', 98- `nntp-open-via-rlogin-and-telnet'
99- `nntp-open-via-telnet-and-telnet'.") 99- `nntp-open-via-telnet-and-telnet'")
100 100
101(defvoo nntp-never-echoes-commands nil 101(defvoo nntp-never-echoes-commands nil
102 "*Non-nil means the nntp server never echoes commands. 102 "*Non-nil means the nntp server never echoes commands.
@@ -1339,15 +1339,15 @@ password contained in '~/.nntp-authinfo'."
1339 (condition-case err 1339 (condition-case err
1340 (let ((coding-system-for-read nntp-coding-system-for-read) 1340 (let ((coding-system-for-read nntp-coding-system-for-read)
1341 (coding-system-for-write nntp-coding-system-for-write) 1341 (coding-system-for-write nntp-coding-system-for-write)
1342 (map '((nntp-open-network-stream try-starttls) 1342 (map '((nntp-open-network-stream network)
1343 (network-only default) 1343 (network-only plain) ; compat
1344 (nntp-open-plain-stream plain)
1344 (nntp-open-ssl-stream tls) 1345 (nntp-open-ssl-stream tls)
1345 (nntp-open-tls-stream tls)))) 1346 (nntp-open-tls-stream tls))))
1346 (if (assoc nntp-open-connection-function map) 1347 (if (assoc nntp-open-connection-function map)
1347 (open-protocol-stream 1348 (open-protocol-stream
1348 "nntpd" pbuffer nntp-address nntp-port-number 1349 "nntpd" pbuffer nntp-address nntp-port-number
1349 :type (or (cadr (assoc nntp-open-connection-function map)) 1350 :type (cadr (assoc nntp-open-connection-function map))
1350 'try-starttls)
1351 :end-of-command "^\\([2345]\\|[.]\\).*\n" 1351 :end-of-command "^\\([2345]\\|[.]\\).*\n"
1352 :capability-command "CAPABILITIES\r\n" 1352 :capability-command "CAPABILITIES\r\n"
1353 :success "^3" 1353 :success "^3"
diff --git a/lisp/gnus/proto-stream.el b/lisp/gnus/proto-stream.el
index 5e92cb40264..45cc974e7a9 100644
--- a/lisp/gnus/proto-stream.el
+++ b/lisp/gnus/proto-stream.el
@@ -37,7 +37,7 @@
37 37
38;; (open-protocol-stream 38;; (open-protocol-stream
39;; "*nnimap*" buffer address port 39;; "*nnimap*" buffer address port
40;; :type 'try-starttls 40;; :type 'network
41;; :capability-command "1 CAPABILITY\r\n" 41;; :capability-command "1 CAPABILITY\r\n"
42;; :success " OK " 42;; :success " OK "
43;; :starttls-function 43;; :starttls-function
@@ -65,17 +65,20 @@ the same meanings as in `open-network-stream'. The remaining
65PARAMETERS should be a sequence of keywords and values: 65PARAMETERS should be a sequence of keywords and values:
66 66
67:type specifies the connection type, one of the following: 67:type specifies the connection type, one of the following:
68 `default' -- An ordinary network connection. 68 nil or `network'
69 `try-starttls' 69 -- Begin with an ordinary network connection, and if
70 -- Begin an ordinary network connection, and try 70 the parameters :success and :capability-command
71 upgrading it to an encrypted connection via 71 are also supplied, try to upgrade to an encrypted
72 STARTTLS if both HOST and Emacs support TLS. If 72 connection via STARTTLS. Even if that
73 that fails, keep the unencrypted connection. 73 fails (e.g. if HOST does not support TLS), retain
74 `starttls' -- Begin an ordinary connection, and try upgrading 74 an unencrypted connection.
75 it via STARTTLS. If that fails for any reason, 75 `plain' -- An ordinary, unencrypted network connection.
76 drop the connection; in this case, the returned 76 `starttls' -- Begin with an ordinary connection, and try
77 process object is a killed process. 77 upgrading via STARTTLS. If that fails for any
78 `tls' or `ssl' -- A TLS connection. 78 reason, drop the connection; in that case the
79 returned object is a killed process.
80 `tls' -- A TLS connection.
81 `ssl' -- Equivalent to `tls'.
79 `shell' -- A shell connection. 82 `shell' -- A shell connection.
80 83
81:return-list specifies this function's return value. 84:return-list specifies this function's return value.
@@ -85,16 +88,15 @@ PARAMETERS should be a sequence of keywords and values:
85 :greeting -- the greeting returned by HOST (a string), or nil. 88 :greeting -- the greeting returned by HOST (a string), or nil.
86 :capabilities -- a string representing HOST's capabilities, 89 :capabilities -- a string representing HOST's capabilities,
87 or nil if none could be found. 90 or nil if none could be found.
88 :type -- the actual connection type; either `default' for an 91 :type -- the resulting connection type; `plain' (unencrypted)
89 unencrypted connection, or `tls'. 92 or `tls' (TLS-encrypted).
90 93
91:end-of-command specifies a regexp matching the end of a command. 94:end-of-command specifies a regexp matching the end of a command.
92 If non-nil, it defaults to \"\\n\". 95 If non-nil, it defaults to \"\\n\".
93 96
94:success specifies a regexp matching a message indicating a 97:success specifies a regexp matching a message indicating a
95 successful STARTTLS negotiation. For instance, the default 98 successful STARTTLS negotiation. For instance, the default
96 should be \"^3\" for an NNTP connection. If this is not 99 should be \"^3\" for an NNTP connection.
97 supplied, STARTTLS will always fail.
98 100
99:capability-command specifies a command used to query the HOST 101:capability-command specifies a command used to query the HOST
100 for its capabilities. For instance, for IMAP this should be 102 for its capabilities. For instance, for IMAP this should be
@@ -106,27 +108,24 @@ PARAMETERS should be a sequence of keywords and values:
106 STARTTLS if the server supports STARTTLS, and nil otherwise." 108 STARTTLS if the server supports STARTTLS, and nil otherwise."
107 (let ((type (plist-get parameters :type)) 109 (let ((type (plist-get parameters :type))
108 (return-list (plist-get parameters :return-list))) 110 (return-list (plist-get parameters :return-list)))
109 (if (and (null return-list) (memq type '(nil default))) 111 (if (and (not return-list)
110 ;; The simplest case---no encryption, and no need to report 112 (or (eq type 'plain)
111 ;; connection properties. Like `open-network-stream', this 113 (and (memq type '(nil network))
112 ;; doesn't read anything into BUFFER yet. 114 (not (and (plist-get parameters :success)
115 (plist-get parameters :capability-command))))))
116 ;; The simplest case is equivalent to `open-network-stream'.
113 (open-network-stream name buffer host service) 117 (open-network-stream name buffer host service)
114 ;; For everything else, refer to proto-stream-open-*. 118 ;; For everything else, refer to proto-stream-open-*.
115 (unless (plist-get parameters :end-of-command) 119 (unless (plist-get parameters :end-of-command)
116 (setq parameters 120 (setq parameters (append '(:end-of-command "\r\n") parameters)))
117 (append '(:end-of-command "\r\n") parameters)))
118 (let* ((connection-function 121 (let* ((connection-function
119 (cond 122 (cond
120 ((memq type '(nil default)) 123 ((eq type 'plain) 'proto-stream-open-plain)
121 'proto-stream-open-default) 124 ((memq type '(nil network starttls))
122 ((memq type '(try-starttls starttls))
123 'proto-stream-open-starttls) 125 'proto-stream-open-starttls)
124 ((memq type '(tls ssl)) 126 ((memq type '(tls ssl)) 'proto-stream-open-tls)
125 'proto-stream-open-tls) 127 ((eq type 'shell) 'proto-stream-open-shell)
126 ((eq type 'shell) 128 (t (error "Invalid connection type %s" type))))
127 'proto-stream-open-shell)
128 (t
129 (error "Invalid connection type %s" type))))
130 (result (funcall connection-function 129 (result (funcall connection-function
131 name buffer host service parameters))) 130 name buffer host service parameters)))
132 (if return-list 131 (if return-list
@@ -136,19 +135,18 @@ PARAMETERS should be a sequence of keywords and values:
136 :type (nth 3 result)) 135 :type (nth 3 result))
137 (car result)))))) 136 (car result))))))
138 137
139(defun proto-stream-open-default (name buffer host service parameters) 138(defun proto-stream-open-plain (name buffer host service parameters)
140 (let ((start (with-current-buffer buffer (point))) 139 (let ((start (with-current-buffer buffer (point)))
141 (stream (open-network-stream name buffer host service))) 140 (stream (open-network-stream name buffer host service)))
142 (list stream 141 (list stream
143 (proto-stream-get-response stream start 142 (proto-stream-get-response stream start
144 (plist-get parameters :end-of-command)) 143 (plist-get parameters :end-of-command))
145 nil 144 nil
146 'default))) 145 'plain)))
147 146
148(defun proto-stream-open-starttls (name buffer host service parameters) 147(defun proto-stream-open-starttls (name buffer host service parameters)
149 (let* ((start (with-current-buffer buffer (point))) 148 (let* ((start (with-current-buffer buffer (point)))
150 ;; This should be `starttls' or `try-starttls'. 149 (require-tls (eq (plist-get parameters :type) 'starttls))
151 (type (plist-get parameters :type))
152 (starttls-function (plist-get parameters :starttls-function)) 150 (starttls-function (plist-get parameters :starttls-function))
153 (success-string (plist-get parameters :success)) 151 (success-string (plist-get parameters :success))
154 (capability-command (plist-get parameters :capability-command)) 152 (capability-command (plist-get parameters :capability-command))
@@ -159,7 +157,7 @@ PARAMETERS should be a sequence of keywords and values:
159 (capabilities (when capability-command 157 (capabilities (when capability-command
160 (proto-stream-command stream 158 (proto-stream-command stream
161 capability-command eoc))) 159 capability-command eoc)))
162 (resulting-type 'default) 160 (resulting-type 'plain)
163 starttls-command) 161 starttls-command)
164 162
165 ;; If we have STARTTLS support, try to upgrade the connection. 163 ;; If we have STARTTLS support, try to upgrade the connection.
@@ -175,11 +173,11 @@ PARAMETERS should be a sequence of keywords and values:
175 (setq start (with-current-buffer buffer (point-max))) 173 (setq start (with-current-buffer buffer (point-max)))
176 (let* ((starttls-use-gnutls t) 174 (let* ((starttls-use-gnutls t)
177 (starttls-extra-arguments 175 (starttls-extra-arguments
178 (if (not (eq type 'starttls)) 176 (if require-tls
179 ;; For opportunistic TLS upgrades, we don't 177 starttls-extra-arguments
180 ;; really care about the identity of the peer. 178 ;; For opportunistic TLS upgrades, we don't really
181 (cons "--insecure" starttls-extra-arguments) 179 ;; care about the identity of the peer.
182 starttls-extra-arguments))) 180 (cons "--insecure" starttls-extra-arguments))))
183 (setq stream (starttls-open-stream name buffer host service))) 181 (setq stream (starttls-open-stream name buffer host service)))
184 (proto-stream-get-response stream start eoc)) 182 (proto-stream-get-response stream start eoc))
185 (when (string-match success-string 183 (when (string-match success-string
@@ -193,7 +191,7 @@ PARAMETERS should be a sequence of keywords and values:
193 (setq resulting-type 'tls) 191 (setq resulting-type 'tls)
194 ;; We didn't successfully negotiate STARTTLS; if TLS 192 ;; We didn't successfully negotiate STARTTLS; if TLS
195 ;; isn't demanded, reopen an unencrypted connection. 193 ;; isn't demanded, reopen an unencrypted connection.
196 (when (eq type 'try-starttls) 194 (unless require-tls
197 (setq stream (open-network-stream name buffer host service)) 195 (setq stream (open-network-stream name buffer host service))
198 (proto-stream-get-response stream start eoc))) 196 (proto-stream-get-response stream start eoc)))
199 ;; Re-get the capabilities, which may have now changed. 197 ;; Re-get the capabilities, which may have now changed.
@@ -201,8 +199,8 @@ PARAMETERS should be a sequence of keywords and values:
201 (proto-stream-command stream capability-command eoc)))) 199 (proto-stream-command stream capability-command eoc))))
202 200
203 ;; If TLS is mandatory, close the connection if it's unencrypted. 201 ;; If TLS is mandatory, close the connection if it's unencrypted.
204 (and (eq type 'starttls) 202 (and require-tls
205 (eq resulting-type 'default) 203 (eq resulting-type 'plain)
206 (delete-process stream)) 204 (delete-process stream))
207 ;; Return value: 205 ;; Return value:
208 (list stream greeting capabilities resulting-type))) 206 (list stream greeting capabilities resulting-type)))
@@ -237,7 +235,7 @@ PARAMETERS should be a sequence of keywords and values:
237 name buffer host service)) 235 name buffer host service))
238 (eoc (plist-get parameters :end-of-command))) 236 (eoc (plist-get parameters :end-of-command)))
239 (if (null stream) 237 (if (null stream)
240 (list nil nil nil 'default) 238 (list nil nil nil 'plain)
241 ;; If we're using tls.el, we have to delete the output from 239 ;; If we're using tls.el, we have to delete the output from
242 ;; openssl/gnutls-cli. 240 ;; openssl/gnutls-cli.
243 (unless (fboundp 'open-gnutls-stream) 241 (unless (fboundp 'open-gnutls-stream)
@@ -260,7 +258,7 @@ PARAMETERS should be a sequence of keywords and values:
260 (format-spec-make 258 (format-spec-make
261 ?s host 259 ?s host
262 ?p service)))) 260 ?p service))))
263 parameters 'default)) 261 parameters 'plain))
264 262
265(defun proto-stream-capability-open (start stream parameters stream-type) 263(defun proto-stream-capability-open (start stream parameters stream-type)
266 (let* ((capability-command (plist-get parameters :capability-command)) 264 (let* ((capability-command (plist-get parameters :capability-command))