]> code.delx.au - gnu-emacs/blobdiff - lisp/url/url-gw.el
* vc-dav.el: Move here from url/vc-dav.el.
[gnu-emacs] / lisp / url / url-gw.el
index 608827d7ceecd284a7e22fd8b8daf25bdfbea4d0..17f7b77b173db378f5ab538eb2cc6fdd1278b6e4 100644 (file)
@@ -1,27 +1,27 @@
 ;;; url-gw.el --- Gateway munging for URL loading
+
+;; Copyright (C) 1997, 1998, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+
 ;; Author: Bill Perry <wmperry@gnu.org>
 ;; Keywords: comm, data, processes
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;; Copyright (c) 1997, 1998, 2004 Free Software Foundation, Inc.
-;;;
-;;; This file is part of GNU Emacs.
-;;;
-;;; 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 2, or (at your option)
-;;; any later version.
-;;;
-;;; GNU Emacs is distributed in the hope that it will be useful,
-;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-;;; 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, write to the
-;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;;; Boston, MA 02111-1307, USA.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; This file is part of GNU Emacs.
+
+;; 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
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+
 (eval-when-compile (require 'cl))
 (require 'url-vars)
 
@@ -32,7 +32,7 @@
 (autoload 'open-tls-stream "tls")
 
 (defgroup url-gateway nil
-  "URL gateway variables"
+  "URL gateway variables."
   :group 'url)
 
 (defcustom url-gateway-local-host-regexp nil
@@ -102,7 +102,7 @@ linked Emacs under SunOS 4.x"
   :group 'url-gateway)
 
 (defcustom url-gateway-nslookup-program "nslookup"
-  "*If non-NIL then a string naming nslookup program."
+  "*If non-nil then a string naming nslookup program."
   :type '(choice (const :tag "None" :value nil) string)
   :group 'url-gateway)
 
@@ -115,9 +115,8 @@ linked Emacs under SunOS 4.x"
       (let ((proc (start-process " *nslookup*" " *nslookup*"
                                 url-gateway-nslookup-program host))
            (res host))
-       (process-kill-without-query proc)
-       (save-excursion
-         (set-buffer (process-buffer proc))
+       (set-process-query-on-exit-flag proc nil)
+       (with-current-buffer (process-buffer proc)
          (while (memq (process-status proc) '(run open))
            (accept-process-output proc))
          (goto-char (point-min))
@@ -166,8 +165,7 @@ linked Emacs under SunOS 4.x"
 (defun url-open-telnet (name buffer host service)
   (if (not (stringp service))
       (setq service (int-to-string service)))
-  (save-excursion
-    (set-buffer (get-buffer-create buffer))
+  (with-current-buffer (get-buffer-create buffer)
     (erase-buffer)
     (let ((proc (start-process name buffer "telnet" "-8"))
          (case-fold-search t))
@@ -186,7 +184,7 @@ linked Emacs under SunOS 4.x"
         proc (concat
               (or url-gateway-telnet-password
                   (setq url-gateway-telnet-password
-                        (funcall url-passwd-entry-func "Password: ")))
+                        (read-passwd "Password: ")))
               "\n"))
        (erase-buffer)
        (url-wait-for-string url-gateway-prompt-pattern proc)
@@ -210,7 +208,8 @@ linked Emacs under SunOS 4.x"
 (defun url-open-stream (name buffer host service)
   "Open a stream to HOST, possibly via a gateway.
 Args per `open-network-stream'.
-Will not make a connexion if `url-gateway-unplugged' is non-nil."
+Will not make a connection if `url-gateway-unplugged' is non-nil.
+Might do a non-blocking connection; use `process-status' to check."
   (unless url-gateway-unplugged
     (let ((gw-method (if (and url-gateway-local-host-regexp
                              (not (eq 'tls url-gateway-method))
@@ -249,7 +248,11 @@ Will not make a connexion if `url-gateway-unplugged' is non-nil."
                         (ssl
                          (open-ssl-stream name buffer host service))
                         ((native)
-                         (open-network-stream name buffer host service))
+                         ;; Use non-blocking socket if we can.
+                         (make-network-process :name name :buffer buffer
+                                               :host host :service service
+                                               :nowait
+                                               (featurep 'make-network-process '(:nowait t))))
                         (socks
                          (socks-open-network-stream name buffer host service))
                         (telnet
@@ -259,10 +262,15 @@ Will not make a connexion if `url-gateway-unplugged' is non-nil."
                         (otherwise
                          (error "Bad setting of url-gateway-method: %s"
                                 url-gateway-method)))))
-       (error
-        (setq conn nil)))
+        ;; Ignoring errors here seems wrong.  E.g. it'll throw away the
+        ;; error signalled two lines above.  It was also found inconvenient
+        ;; during debugging.
+       ;; (error
+       ;;  (setq conn nil))
+       )
       conn)))
 
 (provide 'url-gw)
 
-;;; arch-tag: 1c4c0317-6d03-45b8-b3f3-838bd8f9d838
+;; arch-tag: 1c4c0317-6d03-45b8-b3f3-838bd8f9d838
+;;; url-gw.el ends here