@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
(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
@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
@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:
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
- `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-telnet',
- `nntp-open-via-rlogin-and-netcat',
+- `nntp-open-via-rlogin-and-telnet',
- `nntp-open-via-telnet-and-telnet'.")
(defvoo nntp-never-echoes-commands nil
(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.
(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
(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))
(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:
(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))
(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)
- `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.
,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 " ")