emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

nntp over rlogin-and-netcat


From: Stefan Monnier
Subject: nntp over rlogin-and-netcat
Date: Mon, 11 Dec 2006 15:15:04 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.91 (gnu/linux)

I recently started to access a news server via an SSH tunnel.
I first tried to do it with nntp-open-via-rlogin-and-telnet, but it
couldn't post new messages (the problem seems to be that the server expects
a CR-LF-.-CR-LF byte-sequence, which didn't work when going through
tty code (which seems to turn all CR into LFs) and then through telnet
(which, did something very funny with LF)).

So I wrote the function nntp-open-via-rlogin-and-netcat below, which seems
much saner: rather than use telnet and then try to undo what telnet does,
using netcat gives us directly what we want.

I use it with the following entry in my select-methods:

       (nntp "news"
              (nntp-address "news")
              (nntp-open-connection-function nntp-open-via-rlogin-and-netcat)
              (nntp-via-rlogin-command "ssh")
              (nntp-via-address "iro"))


-- Stefan


--- orig/lisp/gnus/nntp.el
+++ mod/lisp/gnus/nntp.el
@@ -99,6 +99,13 @@
 (defvoo nntp-telnet-switches '("-8")
   "*Switches given to the telnet command `nntp-telnet-command'.")
 
+(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.")
+
+(defvoo nntp-netcat-switches '()
+  "*Switches given to the telnet command `nntp-netcat-command'.")
+
 (defvoo nntp-end-of-line "\r\n"
   "*String to use on the end of lines when talking to the NNTP server.
 This is \"\\r\\n\" by default, but should be \"\\n\" when
@@ -1818,6 +1831,53 @@
       (delete-region (point) (point-max)))
     proc))
 
+(defun nntp-service-to-port (svc)
+  (cond
+   ((integerp svc) (number-to-string svc))
+   ((string-match "\\`[[:digit:]]\\'" svc) svc)
+   (t
+    (with-temp-buffer
+      (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-via-rlogin-and-netcat (buffer)
+  "Open a connection to an nntp server through an intermediate host.
+First rlogin to the remote host, and then use netcat to connect to the real
+news server from there.
+
+Please refer to the following variables to customize the connection:
+- `nntp-pre-command',
+- `nntp-via-rlogin-command',
+- `nntp-via-rlogin-command-switches',
+- `nntp-via-user-name',
+- `nntp-via-address',
+- `nntp-netcat-command',
+- `nntp-netcat-switches',
+- `nntp-address',
+- `nntp-port-number',
+- `nntp-end-of-line'."
+  (let ((command `(,nntp-via-address
+                  ,nntp-netcat-command
+                  ,@nntp-netcat-switches
+                   ,nntp-address
+                   ,(nntp-service-to-port nntp-port-number)))
+       proc)
+    (when nntp-via-user-name
+      (setq command `("-l" ,nntp-via-user-name ,@command)))
+    (when nntp-via-rlogin-command-switches
+      (setq command (append nntp-via-rlogin-command-switches command)))
+    (push nntp-via-rlogin-command command)
+    (and nntp-pre-command
+        (push nntp-pre-command command))
+    ;; 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
+    (let ((process-connection-type nil))
+      (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.
 First telnet the remote host, and then telnet the real news server
@@ -1895,5 +1954,5 @@
 
 (provide 'nntp)
 
-;;; arch-tag: 8655466a-b1b5-4929-9c45-7b1b2e767271
+;; arch-tag: 8655466a-b1b5-4929-9c45-7b1b2e767271
 ;;; nntp.el ends here




reply via email to

[Prev in Thread] Current Thread [Next in Thread]