all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* nntp over rlogin-and-netcat
@ 2006-12-11 20:15 Stefan Monnier
  2006-12-12  6:05 ` Katsumi Yamaoka
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Monnier @ 2006-12-11 20:15 UTC (permalink / raw)



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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: nntp over rlogin-and-netcat
  2006-12-11 20:15 nntp over rlogin-and-netcat Stefan Monnier
@ 2006-12-12  6:05 ` Katsumi Yamaoka
  0 siblings, 0 replies; 2+ messages in thread
From: Katsumi Yamaoka @ 2006-12-12  6:05 UTC (permalink / raw)
  Cc: bugs, emacs-devel

>>>>> In <jwvy7pe19r1.fsf-monnier+emacs@gnu.org> Stefan Monnier wrote:

> 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)).

Hmm, now I use nntp-open-via-rlogin-and-telnet and have no
problem.  The server spec for Gmane is:

(nntp "gmane"
      (nntp-address "news.gmane.org")
      (nntp-end-of-line "\n")
      (nntp-open-connection-function nntp-open-via-rlogin-and-telnet)
      (nntp-via-address "jpl.org")
      (nntp-via-rlogin-command "ssh")
      (nntp-via-rlogin-command-switches ("-C" "-t" "-e" "none")))

> 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 wrote just the same function in 12 Apr 2004 in the Gnus CVS
trunk (a.k.a. No Gnus).;-)  Though there is no function such as
`nntp-service-to-port'.  If you want to install it in Emacs, I
think a better way to make it easy to synch Gnus v5.11 and No
Gnus is to install the No Gnus version in which you add them in
Emacs.

Regards,

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-12-12  6:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-11 20:15 nntp over rlogin-and-netcat Stefan Monnier
2006-12-12  6:05 ` Katsumi Yamaoka

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.