;;; socks.el --- A Socks v5 Client for Emacs
-;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002,
-;; 2007, 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 1996-2000, 2002, 2007-2012 Free Software Foundation, Inc.
;; Author: William M. Perry <wmperry@gnu.org>
;; Dave Love <fx@gnu.org>
(require 'wid-edit))
(require 'custom)
+;; FIXME this is bad practice, and who is it for anyway, since Emacs
+;; has split-string since at least 21.1.
(if (not (fboundp 'split-string))
(defun split-string (string &optional pattern)
"Return a list of substrings of STRING which are separated by PATTERN.
(declare-function socks-original-open-network-stream "socks") ; fset
+;; FIXME this is a terrible idea.
+;; It is not even compatible with the argument spec of open-network-stream
+;; in 24.1. If this is really necessary, open-network-stream
+;; could get a wrapper hook, or defer to open-network-stream-function.
+
(defvar socks-override-functions nil
- "*Whether to overwrite the open-network-stream function with the SOCKSified
+ "Whether to overwrite the open-network-stream function with the SOCKSified
version.")
+(require 'network-stream)
+
(if (fboundp 'socks-original-open-network-stream)
nil ; Do nothing, we've been here already
(defalias 'socks-original-open-network-stream
((= authtype socks-authentication-null)
(and socks-debug (message "No authentication necessary")))
((= authtype socks-authentication-failure)
- (error "No acceptable authentication methods found."))
+ (error "No acceptable authentication methods found"))
(t
(let* ((auth-type (gethash 'authtype info))
(auth-handler (assoc auth-type socks-authentication-methods))
((= atype socks-address-type-name)
(format "%c%s" (length address) address))
(t
- (error "Unkown address type: %d" atype))))
+ (error "Unknown address type: %d" atype))))
(info (gethash proc socks-connections))
request version)
(or info (error "socks-send-command called on non-SOCKS connection %S"
(error "Unsupported address type for HTTP: %d" atype)))
port)))
((equal version 4)
- (setq request (format
- "%c%c%c%c%s%s%c"
- version ; version
- command ; command
- (lsh port -8) ; port, high byte
- (- port (lsh (lsh port -8) 8)) ; port, low byte
- addr ; address
- (user-full-name) ; username
- 0 ; terminate username
- )))
+ (setq request (string-make-unibyte
+ (format
+ "%c%c%c%c%s%s%c"
+ version ; version
+ command ; command
+ (lsh port -8) ; port, high byte
+ (- port (lsh (lsh port -8) 8)) ; port, low byte
+ addr ; address
+ (user-full-name) ; username
+ 0 ; terminate username
+ ))))
((equal version 5)
- (setq request (format
- "%c%c%c%c%s%c%c"
- version ; version
- command ; command
- 0 ; reserved
- atype ; address type
- addr ; address
- (lsh port -8) ; port, high byte
- (- port (lsh (lsh port -8) 8)) ; port, low byte
- )))
+ (setq request (string-make-unibyte
+ (format
+ "%c%c%c%c%s%c%c"
+ version ; version
+ command ; command
+ 0 ; reserved
+ atype ; address type
+ addr ; address
+ (lsh port -8) ; port, high byte
+ (- port (lsh (lsh port -8) 8)) ; port, low byte
+ ))))
(t
(error "Unknown protocol version: %d" version)))
(process-send-string proc request)
\f
;; Replacement functions for open-network-stream, etc.
(defvar socks-noproxy nil
- "*List of regexps matching hosts that we should not socksify connections to")
+ "List of regexps matching hosts that we should not socksify connections to")
(defun socks-find-route (host service)
(let ((route socks-server)
\f
(defcustom socks-nslookup-program "nslookup"
- "*If non-NIL then a string naming the nslookup program."
+ "If non-NIL then a string naming the nslookup program."
:type '(choice (const :tag "None" :value nil) string)
:group 'socks)
(provide 'socks)
-;; arch-tag: 67aef0d9-f4f7-4056-89c3-b4c9bf93ce7f
;;; socks.el ends here