Mercurial > emacs
changeset 93419:4482f387c2fe
(nntp-netcat-command): Rename from nntp-via-netcat-command.
(nntp-netcat-switches): Rename from nntp-via-netcat-switches.
(nntp-open-telnet, nntp-open-rlogin): Use with-current-buffer.
(nntp-service-to-port): New function.
(nntp-open-via-rlogin-and-netcat, nntp-open-via-telnet-and-telnet)
(nntp-open-telnet-stream, nntp-open-via-rlogin-and-telnet): Use it.
(nntp-open-netcat-stream): New function.
(nntp-open-via-rlogin-and-netcat): Don't use a pty.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sun, 30 Mar 2008 03:54:15 +0000 |
parents | 3f188601df78 |
children | 629d4147200e |
files | doc/misc/gnus.texi lisp/gnus/ChangeLog lisp/gnus/nntp.el |
diffstat | 3 files changed, 79 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/misc/gnus.texi Sun Mar 30 02:17:47 2008 +0000 +++ b/doc/misc/gnus.texi Sun Mar 30 03:54:15 2008 +0000 @@ -13144,7 +13144,7 @@ @lisp (nntp "outside" (nntp-pre-command "runsocks") - (nntp-open-connection-function nntp-open-via-netcat) + (nntp-open-connection-function nntp-open-netcat-stream) (nntp-address "the.news.server")) @end lisp @@ -13619,8 +13619,8 @@ (nntp-address "snews.bar.com")) @end lisp -@findex nntp-open-via-netcat -@item nntp-open-via-netcat +@findex nntp-open-netcat-stream +@item nntp-open-netcat-stream Opens a connection to an @acronym{NNTP} server using the @code{netcat} program. You might wonder why this function exists, since we have the default @code{nntp-open-network-stream} which would do the job. (One @@ -13631,7 +13631,7 @@ @lisp (nntp "socksified" (nntp-pre-command "runsocks") - (nntp-open-connection-function nntp-open-via-netcat) + (nntp-open-connection-function nntp-open-netcat-stream) (nntp-address "the.news.server")) @end lisp @@ -13640,7 +13640,7 @@ @findex nntp-open-telnet-stream @item nntp-open-telnet-stream -Like @code{nntp-open-via-netcat}, but uses @code{telnet} rather than +Like @code{nntp-open-netcat-stream}, but uses @code{telnet} rather than @code{netcat}. @code{telnet} is a bit less robust because of things like line-end-conversion, but sometimes netcat is simply not available. The previous example would turn into: @@ -13821,16 +13821,16 @@ server. This is @samp{\r\n} by default, but should be @samp{\n} when using a non native telnet connection function. -@item nntp-via-netcat-command -@vindex nntp-via-netcat-command +@item nntp-netcat-command +@vindex nntp-netcat-command Command to use when connecting to the @acronym{NNTP} server through @samp{netcat}. This is @emph{not} for an intermediate host. This is just for the real @acronym{NNTP} server. The default is @samp{nc}. -@item nntp-via-netcat-switches -@vindex nntp-via-netcat-switches -A list of switches to pass to @code{nntp-via-netcat-command}. The default +@item nntp-netcat-switches +@vindex nntp-netcat-switches +A list of switches to pass to @code{nntp-netcat-command}. The default is @samp{()}. @end table
--- a/lisp/gnus/ChangeLog Sun Mar 30 02:17:47 2008 +0000 +++ b/lisp/gnus/ChangeLog Sun Mar 30 03:54:15 2008 +0000 @@ -1,3 +1,14 @@ +2008-03-30 Stefan Monnier <monnier@iro.umontreal.ca> + + * nntp.el (nntp-netcat-command): Rename from nntp-via-netcat-command. + (nntp-netcat-switches): Rename from nntp-via-netcat-switches. + (nntp-open-telnet, nntp-open-rlogin): Use with-current-buffer. + (nntp-service-to-port): New function. + (nntp-open-via-rlogin-and-netcat, nntp-open-via-telnet-and-telnet) + (nntp-open-telnet-stream, nntp-open-via-rlogin-and-telnet): Use it. + (nntp-open-netcat-stream): New function. + (nntp-open-via-rlogin-and-netcat): Don't use a pty. + 2008-03-29 Stefan Monnier <monnier@iro.umontreal.ca> * message.el (message-make-in-reply-to): Use mm-with-multibyte-buffer.
--- a/lisp/gnus/nntp.el Sun Mar 30 02:17:47 2008 +0000 +++ b/lisp/gnus/nntp.el Sun Mar 30 03:54:15 2008 +0000 @@ -84,11 +84,12 @@ - `nntp-open-network-stream' (the default), - `nntp-open-ssl-stream', - `nntp-open-tls-stream', +- `nntp-open-netcat-stream'. - `nntp-open-telnet-stream'. Indirect connections: +- `nntp-open-via-rlogin-and-netcat', - `nntp-open-via-rlogin-and-telnet', -- `nntp-open-via-rlogin-and-netcat', - `nntp-open-via-telnet-and-telnet'.") (defvoo nntp-never-echoes-commands nil @@ -143,12 +144,13 @@ (defvoo nntp-via-telnet-switches '("-8") "*Switches given to the telnet command `nntp-via-telnet-command'.") -(defvoo nntp-via-netcat-command "nc" +(defvoo nntp-netcat-command "nc" "*Netcat command used to connect to the nntp server. -This command is used by the `nntp-open-via-rlogin-and-netcat' method.") +This command is used by the `nntp-open-netcat-stream' and +`nntp-open-via-rlogin-and-netcat' methods.") -(defvoo nntp-via-netcat-switches nil - "*Switches given to the netcat command `nntp-via-netcat-command'.") +(defvoo nntp-netcat-switches nil + "*Switches given to the netcat command `nntp-netcat-command'.") (defvoo nntp-via-user-name nil "*User name to log in on an intermediate host with. @@ -1801,9 +1803,21 @@ (defvoo nntp-telnet-passwd nil "Password to use to log in via telnet with.") +(defun nntp-service-to-port (svc) + (cond + ((integerp svc) (number-to-string svc)) + ((string-match "\\`[[:digit:]]\\'" svc) svc) + (t + (with-temp-buffer + (ignore-errors (insert-file-contents "/etc/services")) + (goto-char (point-min)) + (if (re-search-forward (concat "^" (regexp-quote svc) + "[ \t]+\\([[:digit:]]+\\)/tcp")) + (match-string 1) + svc))))) + (defun nntp-open-telnet (buffer) - (save-excursion - (set-buffer buffer) + (with-current-buffer buffer (erase-buffer) (let ((proc (apply 'start-process @@ -1859,8 +1873,7 @@ (apply 'start-process "nntpd" buffer nntp-rlogin-program nntp-address nntp-rlogin-parameters)))) - (save-excursion - (set-buffer buffer) + (with-current-buffer buffer (nntp-wait-for-string "^\r*20[01]") (beginning-of-line) (delete-region (point-min) (point)) @@ -1873,7 +1886,7 @@ (defun nntp-open-telnet-stream (buffer) "Open a nntp connection by telnet'ing the news server. -`nntp-open-via-netcat' is recommended in place of this function +`nntp-open-netcat-stream' is recommended in place of this function because it is more reliable. Please refer to the following variables to customize the connection: @@ -1886,9 +1899,7 @@ (let ((command `(,nntp-telnet-command ,@nntp-telnet-switches ,nntp-address - ,(if (integerp nntp-port-number) - (number-to-string nntp-port-number) - nntp-port-number))) + ,(nntp-service-to-port nntp-port-number))) proc) (and nntp-pre-command (push nntp-pre-command command)) @@ -1932,9 +1943,7 @@ (with-current-buffer buffer (nntp-wait-for-string "^r?telnet") (process-send-string proc (concat "open " nntp-address " " - (if (integerp nntp-port-number) - (number-to-string nntp-port-number) - nntp-port-number) + (nntp-service-to-port nntp-port-number) "\n")) (nntp-wait-for-string "^\r*20[01]") (beginning-of-line) @@ -1960,26 +1969,46 @@ - `nntp-via-rlogin-command-switches', - `nntp-via-user-name', - `nntp-via-address', -- `nntp-via-netcat-command', -- `nntp-via-netcat-switches', +- `nntp-netcat-command', +- `nntp-netcat-switches', - `nntp-address', -- `nntp-port-number', -- `nntp-end-of-line'." +- `nntp-port-number'." (let ((command `(,@(when nntp-pre-command (list nntp-pre-command)) ,nntp-via-rlogin-command - ,@(when nntp-via-rlogin-command-switches - nntp-via-rlogin-command-switches) + ,@nntp-via-rlogin-command-switches ,@(when nntp-via-user-name (list "-l" nntp-via-user-name)) ,nntp-via-address - ,nntp-via-netcat-command - ,@nntp-via-netcat-switches + ,nntp-netcat-command + ,@nntp-netcat-switches ,nntp-address - ,(if (integerp nntp-port-number) - (number-to-string nntp-port-number) - nntp-port-number)))) - (apply 'start-process "nntpd" buffer command))) + ,(nntp-service-to-port nntp-port-number)))) + ;; A non-nil connection type results in mightily odd behavior where + ;; (process-send-string proc "\^M") ends up sending a "\n" to the + ;; ssh process. --Stef + ;; Also a nil connection allow ssh-askpass to work under X11. + (let ((process-connection-type nil)) + (apply 'start-process "nntpd" buffer command)))) + +(defun nntp-open-netcat-stream (buffer) + "Open a connection to an nntp server through netcat. +I.e. use the `nc' command rather than Emacs's builtin networking code. + +Please refer to the following variables to customize the connection: +- `nntp-pre-command', +- `nntp-netcat-command', +- `nntp-netcat-switches', +- `nntp-address', +- `nntp-port-number'." + (let ((command `(,nntp-netcat-command + ,@nntp-netcat-switches + ,nntp-address + ,(nntp-service-to-port nntp-port-number)))) + (and nntp-pre-command (push nntp-pre-command command)) + (let ((process-connection-type nil)) ;See `nntp-open-via-rlogin-and-netcat'. + (apply 'start-process "nntpd" buffer command)))) + (defun nntp-open-via-telnet-and-telnet (buffer) "Open a connection to an nntp server through an intermediate host. @@ -2037,9 +2066,7 @@ ,nntp-telnet-command ,@nntp-telnet-switches ,nntp-address - ,(if (integerp nntp-port-number) - (number-to-string nntp-port-number) - nntp-port-number)))) + ,(nntp-service-to-port nntp-port-number)))) (process-send-string proc (concat (mapconcat 'identity real-telnet-command " ")