]> code.delx.au - gnu-emacs/blobdiff - lisp/net/tramp-gw.el
Merge changes made in Gnus trunk.
[gnu-emacs] / lisp / net / tramp-gw.el
index 2cbb7ea377ff2308e10cf2f2bb83aea2aaca8fd3..a550d46b9b51c11c3bdc83b5d8ea285f58d24f4a 100644 (file)
@@ -1,16 +1,16 @@
-;;; -*- coding: iso-8859-1; -*- 
 ;;; tramp-gw.el --- Tramp utility functions for HTTP tunnels and SOCKS gateways
 
-;; Copyright (C) 2007 Free Software Foundation, Inc.
+;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 ;; Author: Michael Albinus <michael.albinus@gmx.de>
 ;; Keywords: comm, processes
+;; Package: tramp
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3 of the License, or
+;; the Free Software Foundation, either version 3 of the License, or
 ;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -19,8 +19,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, see
-;; <http://www.gnu.org/licenses/>.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
   (require 'cl)
   (require 'custom))
 
-;; Autoload the socks library.  It is used only when we access a SOCKS server.
-(autoload 'socks-open-network-stream "socks")
-(defvar socks-username (user-login-name))
-(defvar socks-server (list "Default server" "socks" 1080 5))
-
 ;; Avoid byte-compiler warnings if the byte-compiler supports this.
 ;; Currently, XEmacs supports this.
 (eval-when-compile
       (byte-compiler-options (warnings (- unused-vars)))))
 
 ;; Define HTTP tunnel method ...
-(defvar tramp-gw-tunnel-method "tunnel"
+;;;###tramp-autoload
+(defconst tramp-gw-tunnel-method "tunnel"
   "*Method to connect HTTP gateways.")
 
 ;; ... and port.
-(defvar tramp-gw-default-tunnel-port 8080
+(defconst tramp-gw-default-tunnel-port 8080
   "*Default port for HTTP gateways.")
 
 ;; Define SOCKS method ...
-(defvar tramp-gw-socks-method "socks"
+;;;###tramp-autoload
+(defconst tramp-gw-socks-method "socks"
   "*Method to connect SOCKS servers.")
 
 ;; ... and port.
-(defvar tramp-gw-default-socks-port 1080
+(defconst tramp-gw-default-socks-port 1080
   "*Default port for SOCKS servers.")
 
+;; Autoload the socks library.  It is used only when we access a SOCKS server.
+(autoload 'socks-open-network-stream "socks")
+(defvar socks-username (user-login-name))
+(defvar socks-server
+  (list "Default server" "socks" tramp-gw-default-socks-port 5))
+
 ;; Add a default for `tramp-default-user-alist'.  Default is the local user.
 (add-to-list 'tramp-default-user-alist
             `(,tramp-gw-tunnel-method nil ,(user-login-name)))
     (process-send-string
      (tramp-get-connection-property proc "process" nil) string)))
 
+;;;###tramp-autoload
 (defun tramp-gw-open-connection (vec gw-vec target-vec)
   "Open a remote connection to VEC (see `tramp-file-name' structure).
 Take GW-VEC as SOCKS or HTTP gateway, i.e. its method must be a
@@ -240,10 +243,9 @@ authentication is requested from proxy server, provide it."
        ;; Trap errors to be traced in the right trace buffer.  Often,
        ;; proxies have a timeout of 60".  We wait 65" in order to
        ;; receive an answer this case.
-       (condition-case nil
-           (let (tramp-verbose)
-             (tramp-wait-for-regexp proc 65 "\r?\n\r?\n"))
-         (error nil))
+       (ignore-errors
+         (let (tramp-verbose)
+           (tramp-wait-for-regexp proc 65 "\r?\n\r?\n")))
        ;; Check return code.
        (goto-char (point-min))
        (narrow-to-region
@@ -285,12 +287,11 @@ PROXY is an indication whether we need a Proxy-Authorization header
 or an Authorization header.  If PW-CACHE is non-nil, check for
 password in password cache.  This is done for the first try only."
 
-  ;; `tramp-current-*' must be set for `tramp-read-passwd' and
-  ;; `tramp-clear-passwd'.
+  ;; `tramp-current-*' must be set for `tramp-read-passwd'.
   (let ((tramp-current-method (tramp-file-name-method tramp-gw-gw-vector))
        (tramp-current-user (tramp-file-name-user tramp-gw-gw-vector))
        (tramp-current-host (tramp-file-name-host tramp-gw-gw-vector)))
-    (unless pw-cache (tramp-clear-passwd))
+    (unless pw-cache (tramp-clear-passwd tramp-gw-gw-vector))
     ;; We are already in the right buffer.
     (tramp-message
      tramp-gw-vector 5 "%s required"
@@ -308,10 +309,13 @@ password in password cache.  This is done for the first try only."
        "%s:%s"
        socks-username
        (tramp-read-passwd
-       proc
+       nil
        (format
         "Password for %s@[%s]: " socks-username (read (current-buffer)))))))))
 
+(add-hook 'tramp-unload-hook
+         (lambda ()
+           (unload-feature 'tramp-gw 'force)))
 
 (provide 'tramp-gw)